1 /* $NetBSD: gemini_space.c,v 1.4 2014/02/22 20:33:00 matt Exp $ */ 2 3 /* adapted from: 4 * NetBSD: pxa2x0_space.c,v 1.8 2005/11/24 13:08:32 yamt Exp 5 */ 6 7 /* 8 * Copyright (c) 2001, 2002 Wasabi Systems, Inc. 9 * All rights reserved. 10 * 11 * Written by Jason R. Thorpe for Wasabi Systems, Inc. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. All advertising materials mentioning features or use of this software 22 * must display the following acknowledgement: 23 * This product includes software developed for the NetBSD Project by 24 * Wasabi Systems, Inc. 25 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 26 * or promote products derived from this software without specific prior 27 * written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 32 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 33 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 39 * POSSIBILITY OF SUCH DAMAGE. 40 */ 41 /* 42 * Copyright (c) 1997 Mark Brinicombe. 43 * Copyright (c) 1997 Causality Limited. 44 * All rights reserved. 45 * 46 * This code is derived from software contributed to The NetBSD Foundation 47 * by Ichiro FUKUHARA. 48 * 49 * Redistribution and use in source and binary forms, with or without 50 * modification, are permitted provided that the following conditions 51 * are met: 52 * 1. Redistributions of source code must retain the above copyright 53 * notice, this list of conditions and the following disclaimer. 54 * 2. Redistributions in binary form must reproduce the above copyright 55 * notice, this list of conditions and the following disclaimer in the 56 * documentation and/or other materials provided with the distribution. 57 * 3. All advertising materials mentioning features or use of this software 58 * must display the following acknowledgement: 59 * This product includes software developed by Mark Brinicombe. 60 * 4. The name of the company nor the name of the author may be used to 61 * endorse or promote products derived from this software without specific 62 * prior written permission. 63 * 64 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 65 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 66 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 67 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 68 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 69 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 70 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 71 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 72 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 73 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 74 * SUCH DAMAGE. 75 */ 76 77 /* 78 * bus_space functions for Gemini processor. 79 */ 80 81 #include <sys/cdefs.h> 82 __KERNEL_RCSID(0, "$NetBSD: gemini_space.c,v 1.4 2014/02/22 20:33:00 matt Exp $"); 83 84 #include <sys/param.h> 85 #include <sys/systm.h> 86 87 #include <uvm/uvm_extern.h> 88 89 #include <sys/bus.h> 90 91 /* Prototypes for all the bus_space structure functions */ 92 bs_protos(gemini); 93 bs_protos(generic); 94 bs_protos(generic_armv4); 95 bs_protos(bs_notimpl); 96 97 struct bus_space gemini_bs_tag = { 98 /* cookie */ 99 (void *) 0, 100 101 /* mapping/unmapping */ 102 gemini_bs_map, 103 gemini_bs_unmap, 104 gemini_bs_subregion, 105 106 /* allocation/deallocation */ 107 gemini_bs_alloc, /* not implemented */ 108 gemini_bs_free, /* not implemented */ 109 110 /* get kernel virtual address */ 111 gemini_bs_vaddr, 112 113 /* mmap */ 114 bs_notimpl_bs_mmap, 115 116 /* barrier */ 117 gemini_bs_barrier, 118 119 /* read (single) */ 120 generic_bs_r_1, 121 generic_armv4_bs_r_2, 122 generic_bs_r_4, 123 bs_notimpl_bs_r_8, 124 125 /* read multiple */ 126 generic_bs_rm_1, 127 generic_armv4_bs_rm_2, 128 generic_bs_rm_4, 129 bs_notimpl_bs_rm_8, 130 131 /* read region */ 132 generic_bs_rr_1, 133 generic_armv4_bs_rr_2, 134 generic_bs_rr_4, 135 bs_notimpl_bs_rr_8, 136 137 /* write (single) */ 138 generic_bs_w_1, 139 generic_armv4_bs_w_2, 140 generic_bs_w_4, 141 bs_notimpl_bs_w_8, 142 143 /* write multiple */ 144 generic_bs_wm_1, 145 generic_armv4_bs_wm_2, 146 generic_bs_wm_4, 147 bs_notimpl_bs_wm_8, 148 149 /* write region */ 150 generic_bs_wr_1, 151 generic_armv4_bs_wr_2, 152 generic_bs_wr_4, 153 bs_notimpl_bs_wr_8, 154 155 /* set multiple */ 156 bs_notimpl_bs_sm_1, 157 bs_notimpl_bs_sm_2, 158 bs_notimpl_bs_sm_4, 159 bs_notimpl_bs_sm_8, 160 161 /* set region */ 162 generic_bs_sr_1, 163 generic_armv4_bs_sr_2, 164 bs_notimpl_bs_sr_4, 165 bs_notimpl_bs_sr_8, 166 167 /* copy */ 168 bs_notimpl_bs_c_1, 169 generic_armv4_bs_c_2, 170 bs_notimpl_bs_c_4, 171 bs_notimpl_bs_c_8, 172 }; 173 174 int 175 gemini_bs_map(void *t, bus_addr_t bpa, bus_size_t size, 176 int flag, bus_space_handle_t *bshp) 177 { 178 const struct pmap_devmap *pd; 179 180 if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) { 181 /* Device was statically mapped. */ 182 *bshp = pd->pd_va + (bpa - pd->pd_pa); 183 return 0; 184 } 185 186 paddr_t startpa = trunc_page(bpa); 187 paddr_t endpa = round_page(bpa + size); 188 189 /* XXX use extent manager to check duplicate mapping */ 190 191 vaddr_t va = uvm_km_alloc(kernel_map, endpa - startpa, 0, 192 UVM_KMF_VAONLY | UVM_KMF_NOWAIT); 193 if (! va) 194 return(ENOMEM); 195 196 *bshp = (bus_space_handle_t)(va + (bpa - startpa)); 197 198 const int pmapflags = 199 (flag & (BUS_SPACE_MAP_CACHEABLE|BUS_SPACE_MAP_PREFETCHABLE)) 200 ? 0 201 : PMAP_NOCACHE; 202 for (paddr_t pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { 203 pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, pmapflags); 204 } 205 pmap_update(pmap_kernel()); 206 207 return(0); 208 } 209 210 void 211 gemini_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size) 212 { 213 vaddr_t va; 214 vsize_t sz; 215 216 if (pmap_devmap_find_va(bsh, size) != NULL) { 217 /* Device was statically mapped; nothing to do. */ 218 return; 219 } 220 221 va = trunc_page(bsh); 222 sz = round_page(bsh + size) - va; 223 224 pmap_kremove(va, sz); 225 pmap_update(pmap_kernel()); 226 uvm_km_free(kernel_map, va, sz, UVM_KMF_VAONLY); 227 } 228 229 230 int 231 gemini_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, 232 bus_size_t size, bus_space_handle_t *nbshp) 233 { 234 235 *nbshp = bsh + offset; 236 return (0); 237 } 238 239 void 240 gemini_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, 241 bus_size_t len, int flags) 242 { 243 244 /* Nothing to do. */ 245 } 246 247 void * 248 gemini_bs_vaddr(void *t, bus_space_handle_t bsh) 249 { 250 251 return ((void *)bsh); 252 } 253 254 255 int 256 gemini_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, 257 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags, 258 bus_addr_t *bpap, bus_space_handle_t *bshp) 259 { 260 261 panic("gemini_io_bs_alloc(): not implemented\n"); 262 } 263 264 void 265 gemini_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size) 266 { 267 268 panic("gemini_io_bs_free(): not implemented\n"); 269 } 270 271