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