1 /* $NetBSD: mainbus_io.c,v 1.12 2002/09/27 15:35:48 provos Exp $ */ 2 3 /* 4 * Copyright (c) 1997 Mark Brinicombe. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Mark Brinicombe. 18 * 4. The name of the company nor the name of the author may be used to 19 * endorse or promote products derived from this software without specific 20 * prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 /* 36 * bus_space I/O functions for mainbus 37 */ 38 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/queue.h> 42 43 #include <uvm/uvm.h> 44 45 #include <machine/bus.h> 46 #include <machine/pmap.h> 47 48 /* Proto types for all the bus_space structure functions */ 49 50 bs_protos(mainbus); 51 bs_protos(bs_notimpl); 52 53 /* Declare the mainbus bus space tag */ 54 55 struct bus_space mainbus_bs_tag = { 56 /* cookie */ 57 NULL, 58 59 /* mapping/unmapping */ 60 mainbus_bs_map, 61 mainbus_bs_unmap, 62 mainbus_bs_subregion, 63 64 /* allocation/deallocation */ 65 mainbus_bs_alloc, 66 mainbus_bs_free, 67 68 /* get kernel virtual address */ 69 0, /* there is no linear mapping */ 70 71 /* Mmap bus space for user */ 72 mainbus_bs_mmap, 73 74 /* barrier */ 75 mainbus_bs_barrier, 76 77 /* read (single) */ 78 mainbus_bs_r_1, 79 mainbus_bs_r_2, 80 mainbus_bs_r_4, 81 bs_notimpl_bs_r_8, 82 83 /* read multiple */ 84 bs_notimpl_bs_rm_1, 85 mainbus_bs_rm_2, 86 bs_notimpl_bs_rm_4, 87 bs_notimpl_bs_rm_8, 88 89 /* read region */ 90 bs_notimpl_bs_rr_1, 91 bs_notimpl_bs_rr_2, 92 bs_notimpl_bs_rr_4, 93 bs_notimpl_bs_rr_8, 94 95 /* write (single) */ 96 mainbus_bs_w_1, 97 mainbus_bs_w_2, 98 mainbus_bs_w_4, 99 bs_notimpl_bs_w_8, 100 101 /* write multiple */ 102 mainbus_bs_wm_1, 103 mainbus_bs_wm_2, 104 bs_notimpl_bs_wm_4, 105 bs_notimpl_bs_wm_8, 106 107 /* write region */ 108 bs_notimpl_bs_wr_1, 109 bs_notimpl_bs_wr_2, 110 bs_notimpl_bs_wr_4, 111 bs_notimpl_bs_wr_8, 112 113 bs_notimpl_bs_sm_1, 114 bs_notimpl_bs_sm_2, 115 bs_notimpl_bs_sm_4, 116 bs_notimpl_bs_sm_8, 117 118 /* set region */ 119 bs_notimpl_bs_sr_1, 120 bs_notimpl_bs_sr_2, 121 bs_notimpl_bs_sr_4, 122 bs_notimpl_bs_sr_8, 123 124 /* copy */ 125 bs_notimpl_bs_c_1, 126 bs_notimpl_bs_c_2, 127 bs_notimpl_bs_c_4, 128 bs_notimpl_bs_c_8, 129 }; 130 131 /* bus space functions */ 132 133 int 134 mainbus_bs_map(t, bpa, size, cacheable, bshp) 135 void *t; 136 bus_addr_t bpa; 137 bus_size_t size; 138 int cacheable; 139 bus_space_handle_t *bshp; 140 { 141 u_long startpa, endpa, pa; 142 vaddr_t va; 143 pt_entry_t *pte; 144 145 if ((u_long)bpa > (u_long)KERNEL_BASE) { 146 /* XXX This is a temporary hack to aid transition. */ 147 *bshp = bpa; 148 return(0); 149 } 150 151 startpa = trunc_page(bpa); 152 endpa = round_page(bpa + size); 153 154 /* XXX use extent manager to check duplicate mapping */ 155 156 va = uvm_km_valloc(kernel_map, endpa - startpa); 157 if (! va) 158 return(ENOMEM); 159 160 *bshp = (bus_space_handle_t)(va + (bpa - startpa)); 161 162 for(pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { 163 pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE); 164 pte = vtopte(va); 165 if (cacheable == 0) { 166 *pte &= ~L2_S_CACHE_MASK; 167 PTE_SYNC(pte); 168 } 169 } 170 pmap_update(pmap_kernel()); 171 172 return(0); 173 } 174 175 int 176 mainbus_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable, 177 bpap, bshp) 178 void *t; 179 bus_addr_t rstart, rend; 180 bus_size_t size, alignment, boundary; 181 int cacheable; 182 bus_addr_t *bpap; 183 bus_space_handle_t *bshp; 184 { 185 panic("mainbus_bs_alloc(): Help!"); 186 } 187 188 189 void 190 mainbus_bs_unmap(t, bsh, size) 191 void *t; 192 bus_space_handle_t bsh; 193 bus_size_t size; 194 { 195 /* 196 * Temporary implementation 197 */ 198 } 199 200 void 201 mainbus_bs_free(t, bsh, size) 202 void *t; 203 bus_space_handle_t bsh; 204 bus_size_t size; 205 { 206 207 panic("mainbus_bs_free(): Help!"); 208 /* mainbus_bs_unmap() does all that we need to do. */ 209 /* mainbus_bs_unmap(t, bsh, size);*/ 210 } 211 212 int 213 mainbus_bs_subregion(t, bsh, offset, size, nbshp) 214 void *t; 215 bus_space_handle_t bsh; 216 bus_size_t offset, size; 217 bus_space_handle_t *nbshp; 218 { 219 220 *nbshp = bsh + offset; 221 return (0); 222 } 223 224 paddr_t 225 mainbus_bs_mmap(t, paddr, offset, prot, flags) 226 void *t; 227 bus_addr_t paddr; 228 off_t offset; 229 int prot; 230 int flags; 231 { 232 /* 233 * mmap from address `paddr+offset' for one page 234 */ 235 return (arm_btop((paddr + offset))); 236 } 237 238 void 239 mainbus_bs_barrier(t, bsh, offset, len, flags) 240 void *t; 241 bus_space_handle_t bsh; 242 bus_size_t offset, len; 243 int flags; 244 { 245 } 246 247 /* End of mainbus_io.c */ 248