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