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