footbridge_io.c revision 1.11 1 1.11 chris /* $NetBSD: footbridge_io.c,v 1.11 2005/07/30 15:14:29 chris Exp $ */
2 1.1 chris
3 1.1 chris /*
4 1.1 chris * Copyright (c) 1997 Causality Limited
5 1.1 chris * Copyright (c) 1997 Mark Brinicombe.
6 1.1 chris * All rights reserved.
7 1.1 chris *
8 1.1 chris * Redistribution and use in source and binary forms, with or without
9 1.1 chris * modification, are permitted provided that the following conditions
10 1.1 chris * are met:
11 1.1 chris * 1. Redistributions of source code must retain the above copyright
12 1.1 chris * notice, this list of conditions and the following disclaimer.
13 1.1 chris * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 chris * notice, this list of conditions and the following disclaimer in the
15 1.1 chris * documentation and/or other materials provided with the distribution.
16 1.1 chris * 3. All advertising materials mentioning features or use of this software
17 1.1 chris * must display the following acknowledgement:
18 1.1 chris * This product includes software developed by Mark Brinicombe
19 1.1 chris * for the NetBSD Project.
20 1.1 chris * 4. The name of the company nor the name of the author may be used to
21 1.1 chris * endorse or promote products derived from this software without specific
22 1.1 chris * prior written permission.
23 1.1 chris *
24 1.1 chris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 1.1 chris * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 1.1 chris * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 1.1 chris * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 1.1 chris * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 1.1 chris * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 1.1 chris * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.1 chris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.1 chris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1 chris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1 chris * SUCH DAMAGE.
35 1.1 chris */
36 1.1 chris
37 1.1 chris /*
38 1.1 chris * bus_space I/O functions for footbridge
39 1.1 chris */
40 1.8 chris
41 1.8 chris #include <sys/cdefs.h>
42 1.11 chris __KERNEL_RCSID(0, "$NetBSD: footbridge_io.c,v 1.11 2005/07/30 15:14:29 chris Exp $");
43 1.1 chris
44 1.1 chris #include <sys/param.h>
45 1.1 chris #include <sys/systm.h>
46 1.1 chris #include <machine/bus.h>
47 1.5 chris #include <arm/footbridge/footbridge.h>
48 1.1 chris #include <arm/footbridge/dc21285mem.h>
49 1.1 chris #include <uvm/uvm_extern.h>
50 1.1 chris
51 1.1 chris /* Proto types for all the bus_space structure functions */
52 1.1 chris
53 1.1 chris bs_protos(footbridge);
54 1.6 thorpej bs_protos(generic);
55 1.6 thorpej bs_protos(generic_armv4);
56 1.1 chris bs_protos(bs_notimpl);
57 1.1 chris bs_map_proto(footbridge_mem);
58 1.1 chris bs_unmap_proto(footbridge_mem);
59 1.1 chris
60 1.1 chris /* Declare the footbridge bus space tag */
61 1.1 chris
62 1.1 chris struct bus_space footbridge_bs_tag = {
63 1.1 chris /* cookie */
64 1.1 chris (void *) 0, /* Base address */
65 1.1 chris
66 1.1 chris /* mapping/unmapping */
67 1.1 chris footbridge_bs_map,
68 1.1 chris footbridge_bs_unmap,
69 1.1 chris footbridge_bs_subregion,
70 1.1 chris
71 1.1 chris /* allocation/deallocation */
72 1.1 chris footbridge_bs_alloc,
73 1.1 chris footbridge_bs_free,
74 1.1 chris
75 1.1 chris /* get kernel virtual address */
76 1.1 chris footbridge_bs_vaddr,
77 1.1 chris
78 1.4 chris /* Mmap bus space for user */
79 1.4 chris bs_notimpl_bs_mmap,
80 1.4 chris
81 1.1 chris /* barrier */
82 1.1 chris footbridge_bs_barrier,
83 1.1 chris
84 1.1 chris /* read (single) */
85 1.6 thorpej generic_bs_r_1,
86 1.6 thorpej generic_armv4_bs_r_2,
87 1.6 thorpej generic_bs_r_4,
88 1.1 chris bs_notimpl_bs_r_8,
89 1.1 chris
90 1.1 chris /* read multiple */
91 1.6 thorpej generic_bs_rm_1,
92 1.6 thorpej generic_armv4_bs_rm_2,
93 1.6 thorpej generic_bs_rm_4,
94 1.1 chris bs_notimpl_bs_rm_8,
95 1.1 chris
96 1.1 chris /* read region */
97 1.1 chris bs_notimpl_bs_rr_1,
98 1.6 thorpej generic_armv4_bs_rr_2,
99 1.6 thorpej generic_bs_rr_4,
100 1.1 chris bs_notimpl_bs_rr_8,
101 1.1 chris
102 1.1 chris /* write (single) */
103 1.6 thorpej generic_bs_w_1,
104 1.6 thorpej generic_armv4_bs_w_2,
105 1.6 thorpej generic_bs_w_4,
106 1.1 chris bs_notimpl_bs_w_8,
107 1.1 chris
108 1.1 chris /* write multiple */
109 1.6 thorpej generic_bs_wm_1,
110 1.6 thorpej generic_armv4_bs_wm_2,
111 1.6 thorpej generic_bs_wm_4,
112 1.1 chris bs_notimpl_bs_wm_8,
113 1.1 chris
114 1.1 chris /* write region */
115 1.1 chris bs_notimpl_bs_wr_1,
116 1.6 thorpej generic_armv4_bs_wr_2,
117 1.6 thorpej generic_bs_wr_4,
118 1.1 chris bs_notimpl_bs_wr_8,
119 1.1 chris
120 1.1 chris /* set multiple */
121 1.1 chris bs_notimpl_bs_sm_1,
122 1.1 chris bs_notimpl_bs_sm_2,
123 1.1 chris bs_notimpl_bs_sm_4,
124 1.1 chris bs_notimpl_bs_sm_8,
125 1.1 chris
126 1.1 chris /* set region */
127 1.1 chris bs_notimpl_bs_sr_1,
128 1.6 thorpej generic_armv4_bs_sr_2,
129 1.1 chris bs_notimpl_bs_sr_4,
130 1.1 chris bs_notimpl_bs_sr_8,
131 1.1 chris
132 1.1 chris /* copy */
133 1.1 chris bs_notimpl_bs_c_1,
134 1.6 thorpej generic_armv4_bs_c_2,
135 1.1 chris bs_notimpl_bs_c_4,
136 1.1 chris bs_notimpl_bs_c_8,
137 1.1 chris };
138 1.1 chris
139 1.1 chris void footbridge_create_io_bs_tag(t, cookie)
140 1.1 chris struct bus_space *t;
141 1.1 chris void *cookie;
142 1.1 chris {
143 1.1 chris *t = footbridge_bs_tag;
144 1.1 chris t->bs_cookie = cookie;
145 1.1 chris }
146 1.1 chris
147 1.1 chris void footbridge_create_mem_bs_tag(t, cookie)
148 1.1 chris struct bus_space *t;
149 1.1 chris void *cookie;
150 1.1 chris {
151 1.1 chris *t = footbridge_bs_tag;
152 1.1 chris t->bs_map = footbridge_mem_bs_map;
153 1.1 chris t->bs_unmap = footbridge_mem_bs_unmap;
154 1.1 chris t->bs_cookie = cookie;
155 1.1 chris }
156 1.1 chris
157 1.1 chris /* bus space functions */
158 1.1 chris
159 1.1 chris int
160 1.1 chris footbridge_bs_map(t, bpa, size, cacheable, bshp)
161 1.1 chris void *t;
162 1.1 chris bus_addr_t bpa;
163 1.1 chris bus_size_t size;
164 1.1 chris int cacheable;
165 1.1 chris bus_space_handle_t *bshp;
166 1.1 chris {
167 1.1 chris /*
168 1.1 chris * The whole 64K of PCI space is always completely mapped during
169 1.1 chris * boot.
170 1.1 chris *
171 1.1 chris * Eventually this function will do the mapping check overlapping /
172 1.1 chris * multiple mappings.
173 1.1 chris */
174 1.1 chris
175 1.1 chris /* The cookie is the base address for the I/O area */
176 1.1 chris *bshp = bpa + (bus_addr_t)t;
177 1.1 chris return(0);
178 1.1 chris }
179 1.1 chris
180 1.1 chris int
181 1.11 chris footbridge_mem_bs_map(t, bpa, size, flags, bshp)
182 1.1 chris void *t;
183 1.1 chris bus_addr_t bpa;
184 1.1 chris bus_size_t size;
185 1.11 chris int flags;
186 1.1 chris bus_space_handle_t *bshp;
187 1.1 chris {
188 1.11 chris bus_addr_t startpa, endpa, pa;
189 1.1 chris vaddr_t va;
190 1.1 chris
191 1.1 chris /* Round the allocation to page boundries */
192 1.1 chris startpa = trunc_page(bpa);
193 1.1 chris endpa = round_page(bpa + size);
194 1.1 chris
195 1.1 chris /*
196 1.1 chris * Check for mappings below 1MB as we have this space already
197 1.1 chris * mapped. In practice it is only the VGA hole that takes
198 1.1 chris * advantage of this.
199 1.1 chris */
200 1.1 chris if (endpa < DC21285_PCI_ISA_MEM_VSIZE) {
201 1.1 chris /* Store the bus space handle */
202 1.1 chris *bshp = DC21285_PCI_ISA_MEM_VBASE + bpa;
203 1.1 chris return 0;
204 1.1 chris }
205 1.1 chris
206 1.1 chris /*
207 1.1 chris * Eventually this function will do the mapping check for overlapping /
208 1.1 chris * multiple mappings
209 1.1 chris */
210 1.1 chris
211 1.10 yamt va = uvm_km_alloc(kernel_map, endpa - startpa, 0, UVM_KMF_VAONLY);
212 1.1 chris if (va == 0)
213 1.1 chris return ENOMEM;
214 1.1 chris
215 1.1 chris /* Store the bus space handle */
216 1.1 chris *bshp = va + (bpa & PGOFSET);
217 1.1 chris
218 1.1 chris /* Now map the pages */
219 1.1 chris /* The cookie is the physical base address for the I/O area */
220 1.11 chris for (pa = startpa; pa < endpa; pa+=PAGE_SIZE, va += PAGE_SIZE)
221 1.11 chris {
222 1.11 chris pmap_enter(pmap_kernel(), va, (bus_addr_t)t + pa, VM_PROT_READ | VM_PROT_WRITE,
223 1.11 chris VM_PROT_READ | VM_PROT_WRITE| PMAP_WIRED);
224 1.11 chris if ((flags & BUS_SPACE_MAP_CACHEABLE) == 0) {
225 1.11 chris pt_entry_t *pte;
226 1.11 chris pte = vtopte(va);
227 1.11 chris *pte &= ~L2_S_CACHE_MASK;
228 1.11 chris PTE_SYNC(pte);
229 1.11 chris }
230 1.11 chris }
231 1.3 chris pmap_update(pmap_kernel());
232 1.1 chris
233 1.1 chris /* if (bpa >= DC21285_PCI_MEM_VSIZE && bpa != DC21285_ARMCSR_VBASE)
234 1.7 provos panic("footbridge_bs_map: Address out of range (%08lx)", bpa);
235 1.1 chris */
236 1.1 chris return(0);
237 1.1 chris }
238 1.1 chris
239 1.1 chris int
240 1.1 chris footbridge_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
241 1.1 chris bpap, bshp)
242 1.1 chris void *t;
243 1.1 chris bus_addr_t rstart, rend;
244 1.1 chris bus_size_t size, alignment, boundary;
245 1.1 chris int cacheable;
246 1.1 chris bus_addr_t *bpap;
247 1.1 chris bus_space_handle_t *bshp;
248 1.1 chris {
249 1.7 provos panic("footbridge_alloc(): Help!");
250 1.1 chris }
251 1.1 chris
252 1.1 chris
253 1.1 chris void
254 1.1 chris footbridge_bs_unmap(t, bsh, size)
255 1.1 chris void *t;
256 1.1 chris bus_space_handle_t bsh;
257 1.1 chris bus_size_t size;
258 1.1 chris {
259 1.1 chris /*
260 1.1 chris * Temporary implementation
261 1.1 chris */
262 1.1 chris }
263 1.1 chris
264 1.1 chris void
265 1.1 chris footbridge_mem_bs_unmap(t, bsh, size)
266 1.1 chris void *t;
267 1.1 chris bus_space_handle_t bsh;
268 1.1 chris bus_size_t size;
269 1.1 chris {
270 1.1 chris vaddr_t startva, endva;
271 1.1 chris
272 1.1 chris /*
273 1.1 chris * Check for mappings below 1MB as we have this space permenantly
274 1.1 chris * mapped. In practice it is only the VGA hole that takes
275 1.1 chris * advantage of this.
276 1.1 chris */
277 1.1 chris if (bsh >= DC21285_PCI_ISA_MEM_VBASE
278 1.1 chris && bsh < (DC21285_PCI_ISA_MEM_VBASE + DC21285_PCI_ISA_MEM_VSIZE)) {
279 1.1 chris return;
280 1.1 chris }
281 1.1 chris
282 1.1 chris startva = trunc_page(bsh);
283 1.1 chris endva = round_page(bsh + size);
284 1.1 chris
285 1.10 yamt pmap_remove(pmap_kernel(), startva, endva);
286 1.10 yamt pmap_update(pmap_kernel());
287 1.10 yamt uvm_km_free(kernel_map, startva, endva - startva, UVM_KMF_VAONLY);
288 1.1 chris }
289 1.1 chris
290 1.1 chris void
291 1.1 chris footbridge_bs_free(t, bsh, size)
292 1.1 chris void *t;
293 1.1 chris bus_space_handle_t bsh;
294 1.1 chris bus_size_t size;
295 1.1 chris {
296 1.1 chris
297 1.7 provos panic("footbridge_free(): Help!");
298 1.1 chris /* footbridge_bs_unmap() does all that we need to do. */
299 1.1 chris /* footbridge_bs_unmap(t, bsh, size);*/
300 1.1 chris }
301 1.1 chris
302 1.1 chris int
303 1.1 chris footbridge_bs_subregion(t, bsh, offset, size, nbshp)
304 1.1 chris void *t;
305 1.1 chris bus_space_handle_t bsh;
306 1.1 chris bus_size_t offset, size;
307 1.1 chris bus_space_handle_t *nbshp;
308 1.1 chris {
309 1.1 chris
310 1.1 chris *nbshp = bsh + (offset << ((int)t));
311 1.1 chris return (0);
312 1.1 chris }
313 1.1 chris
314 1.1 chris void *
315 1.1 chris footbridge_bs_vaddr(t, bsh)
316 1.1 chris void *t;
317 1.1 chris bus_space_handle_t bsh;
318 1.1 chris {
319 1.1 chris
320 1.1 chris return ((void *)bsh);
321 1.1 chris }
322 1.1 chris
323 1.1 chris void
324 1.1 chris footbridge_bs_barrier(t, bsh, offset, len, flags)
325 1.1 chris void *t;
326 1.1 chris bus_space_handle_t bsh;
327 1.1 chris bus_size_t offset, len;
328 1.1 chris int flags;
329 1.1 chris {
330 1.1 chris }
331