obio_space.c revision 1.9
1/* $NetBSD: obio_space.c,v 1.9 2003/06/15 18:43:50 thorpej Exp $ */ 2 3/* 4 * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38/* 39 * bus_space functions for IQ80310 on-board devices 40 */ 41 42#include <sys/param.h> 43#include <sys/systm.h> 44 45#include <uvm/uvm_extern.h> 46 47#include <machine/bus.h> 48 49/* Prototypes for all the bus_space structure functions */ 50bs_protos(obio); 51bs_protos(generic); 52bs_protos(bs_notimpl); 53 54/* 55 * The obio bus space tag. This is constant for all instances, so 56 * we never have to explicitly "create" it. 57 */ 58struct bus_space obio_bs_tag = { 59 /* cookie */ 60 (void *) 0, 61 62 /* mapping/unmapping */ 63 obio_bs_map, 64 obio_bs_unmap, 65 obio_bs_subregion, 66 67 /* allocation/deallocation */ 68 obio_bs_alloc, 69 obio_bs_free, 70 71 /* get kernel virtual address */ 72 obio_bs_vaddr, 73 74 /* mmap */ 75 bs_notimpl_bs_mmap, 76 77 /* barrier */ 78 obio_bs_barrier, 79 80 /* read (single) */ 81 generic_bs_r_1, 82 bs_notimpl_bs_r_2, 83 generic_bs_r_4, 84 bs_notimpl_bs_r_8, 85 86 /* read multiple */ 87 generic_bs_rm_1, 88 bs_notimpl_bs_rm_2, 89 bs_notimpl_bs_rm_4, 90 bs_notimpl_bs_rm_8, 91 92 /* read region */ 93 generic_bs_rr_1, 94 bs_notimpl_bs_rr_2, 95 bs_notimpl_bs_rr_4, 96 bs_notimpl_bs_rr_8, 97 98 /* write (single) */ 99 generic_bs_w_1, 100 bs_notimpl_bs_w_2, 101 generic_bs_w_4, 102 bs_notimpl_bs_w_8, 103 104 /* write multiple */ 105 generic_bs_wm_1, 106 bs_notimpl_bs_wm_2, 107 bs_notimpl_bs_wm_4, 108 bs_notimpl_bs_wm_8, 109 110 /* write region */ 111 bs_notimpl_bs_wr_1, 112 bs_notimpl_bs_wr_2, 113 bs_notimpl_bs_wr_4, 114 bs_notimpl_bs_wr_8, 115 116 /* set multiple */ 117 bs_notimpl_bs_sm_1, 118 bs_notimpl_bs_sm_2, 119 bs_notimpl_bs_sm_4, 120 bs_notimpl_bs_sm_8, 121 122 /* set region */ 123 bs_notimpl_bs_sr_1, 124 bs_notimpl_bs_sr_2, 125 bs_notimpl_bs_sr_4, 126 bs_notimpl_bs_sr_8, 127 128 /* copy */ 129 bs_notimpl_bs_c_1, 130 bs_notimpl_bs_c_2, 131 bs_notimpl_bs_c_4, 132 bs_notimpl_bs_c_8, 133}; 134 135int 136obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags, 137 bus_space_handle_t *bshp) 138{ 139 const struct pmap_devmap *pd; 140 paddr_t startpa, endpa, pa, offset; 141 vaddr_t va; 142 pt_entry_t *pte; 143 144 if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) { 145 /* Device was statically mapped. */ 146 *bshp = pd->pd_va + (bpa - pd->pd_pa); 147 return (0); 148 } 149 150 endpa = round_page(bpa + size); 151 offset = bpa & PAGE_MASK; 152 startpa = trunc_page(bpa); 153 154 va = uvm_km_valloc(kernel_map, endpa - startpa); 155 if (va == 0) 156 return(ENOMEM); 157 158 *bshp = va + offset; 159 160 for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { 161 pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE); 162 pte = vtopte(va); 163 *pte &= ~L2_S_CACHE_MASK; 164 PTE_SYNC(pte); 165 } 166 pmap_update(pmap_kernel()); 167 168 return (0); 169} 170 171int 172obio_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size, 173 bus_size_t alignment, bus_size_t boundary, int flags, bus_addr_t *bpap, 174 bus_space_handle_t *bshp) 175{ 176 177 panic("obio_bs_alloc(): not implemented"); 178} 179 180 181void 182obio_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size) 183{ 184 vaddr_t va, endva; 185 186 if (pmap_devmap_find_va(bsh, size) != NULL) { 187 /* Device was statically mapped; nothing to do. */ 188 return; 189 } 190 191 endva = round_page(bsh + size); 192 va = trunc_page(bsh); 193 194 pmap_kremove(va, endva - va); 195 uvm_km_free(kernel_map, va, endva - va); 196} 197 198void 199obio_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size) 200{ 201 202 panic("obio_bs_free(): not implemented"); 203} 204 205int 206obio_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, 207 bus_size_t size, bus_space_handle_t *nbshp) 208{ 209 210 *nbshp = bsh + offset; 211 return (0); 212} 213 214void * 215obio_bs_vaddr(void *t, bus_space_handle_t bsh) 216{ 217 218 return ((void *)bsh); 219} 220 221void 222obio_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, 223 bus_size_t len, int flags) 224{ 225 226 /* Nothing to do. */ 227} 228