ixp12x0_io.c revision 1.1 1 /* $NetBSD: ixp12x0_io.c,v 1.1 2002/07/15 16:27:17 ichiro Exp $ */
2
3 /*
4 * Copyright (c) 2002
5 * Ichiro FUKUHARA <ichiro (at) ichiro.org>.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Ichiro FUKUHARA.
19 * 4. The name of the company nor the name of the author may be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 /*
37 * bus_space I/O functions for ixp12x0
38 */
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/queue.h>
43
44 #include <uvm/uvm.h>
45
46 #include <machine/bus.h>
47
48 #include <arm/ixp12x0/ixp12x0reg.h>
49 #include <arm/ixp12x0/ixp12x0var.h>
50
51 /* Proto types for all the bus_space structure functions */
52 bs_protos(ixp12x0);
53 bs_protos(ixp12x0_io);
54 bs_protos(ixp12x0_mem);
55 bs_protos(generic);
56 bs_protos(generic_armv4);
57 bs_protos(bs_notimpl);
58
59 struct bus_space ixp12x0_bs_tag = {
60 /* cookie */
61 (void *) 0,
62
63 /* mapping/unmapping */
64 NULL,
65 NULL,
66 ixp12x0_bs_subregion,
67
68 /* allocation/deallocation */
69 NULL,
70 NULL,
71
72 /* get kernel virtual address */
73 ixp12x0_bs_vaddr,
74
75 /* mmap bus space for userland */
76 ixp12x0_bs_mmap,
77
78 /* barrier */
79 ixp12x0_bs_barrier,
80
81 /* read (single) */
82 generic_bs_r_1,
83 generic_armv4_bs_r_2,
84 generic_bs_r_4,
85 bs_notimpl_bs_r_8,
86
87 /* read multiple */
88 generic_bs_rm_1,
89 generic_armv4_bs_rm_2,
90 generic_bs_rm_4,
91 bs_notimpl_bs_rm_8,
92
93 /* read region */
94 bs_notimpl_bs_rr_1,
95 generic_armv4_bs_rr_2,
96 generic_bs_rr_4,
97 bs_notimpl_bs_rr_8,
98
99 /* write (single) */
100 generic_bs_w_1,
101 generic_armv4_bs_w_2,
102 generic_bs_w_4,
103 bs_notimpl_bs_w_8,
104
105 /* write multiple */
106 generic_bs_wm_1,
107 generic_armv4_bs_wm_2,
108 generic_bs_wm_4,
109 bs_notimpl_bs_wm_8,
110
111 /* write region */
112 bs_notimpl_bs_wr_1,
113 generic_armv4_bs_wr_2,
114 bs_notimpl_bs_wr_4,
115 bs_notimpl_bs_wr_8,
116
117 /* set multiple */
118 bs_notimpl_bs_sm_1,
119 bs_notimpl_bs_sm_2,
120 bs_notimpl_bs_sm_4,
121 bs_notimpl_bs_sm_8,
122
123 /* set region */
124 bs_notimpl_bs_sr_1,
125 generic_armv4_bs_sr_2,
126 bs_notimpl_bs_sr_4,
127 bs_notimpl_bs_sr_8,
128
129 /* copy */
130 bs_notimpl_bs_c_1,
131 generic_armv4_bs_c_2,
132 bs_notimpl_bs_c_4,
133 bs_notimpl_bs_c_8,
134 };
135
136 void
137 ixp12x0_bs_init(bs, cookie)
138 bus_space_tag_t bs;
139 void *cookie;
140 {
141 *bs = ixp12x0_bs_tag;
142 bs->bs_cookie = cookie;
143 }
144
145 void
146 ixp12x0_io_bs_init(bs, cookie)
147 bus_space_tag_t bs;
148 void *cookie;
149 {
150 *bs = ixp12x0_bs_tag;
151 bs->bs_cookie = cookie;
152
153 bs->bs_map = ixp12x0_io_bs_map;
154 bs->bs_unmap = ixp12x0_io_bs_unmap;
155 bs->bs_alloc = ixp12x0_io_bs_alloc;
156 bs->bs_free = ixp12x0_io_bs_free;
157
158 bs->bs_vaddr = ixp12x0_io_bs_vaddr;
159 }
160 void
161 ixp12x0_mem_bs_init(bs, cookie)
162 bus_space_tag_t bs;
163 void *cookie;
164 {
165 *bs = ixp12x0_bs_tag;
166 bs->bs_cookie = cookie;
167
168 bs->bs_map = ixp12x0_mem_bs_map;
169 bs->bs_unmap = ixp12x0_mem_bs_unmap;
170 bs->bs_alloc = ixp12x0_mem_bs_alloc;
171 bs->bs_free = ixp12x0_mem_bs_free;
172
173 bs->bs_mmap = ixp12x0_mem_bs_mmap;
174 }
175
176 /* mem bus space functions */
177
178 int
179 ixp12x0_mem_bs_map(t, bpa, size, cacheable, bshp)
180 void *t;
181 bus_addr_t bpa;
182 bus_size_t size;
183 int cacheable;
184 bus_space_handle_t *bshp;
185 {
186 #if 0
187 struct ixp12x0_softc *sc = t;
188 #endif
189 paddr_t pa, endpa;
190 vaddr_t va;
191
192 if ((bpa + size) >= IXP12X0_PCI_MEM_SIZE)
193 return (EINVAL);
194 /*
195 * PCI MEM space is mapped same address as real memory
196 */
197
198 pa = trunc_page(bpa + IXP12X0_PCI_MEM_VBASE);
199 endpa = round_page((bpa + IXP12X0_PCI_MEM_VBASE) + size);
200
201 /* XXX use extent manager to check duplicate mapping */
202
203 va = uvm_km_valloc(kernel_map, endpa - pa);
204 if (va == 0)
205 return(ENOMEM);
206
207 /* Store the bus space handle */
208 *bshp = va + (bpa & PAGE_MASK);
209
210 for(; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
211 pmap_enter(pmap_kernel(), va, pa,
212 VM_PROT_READ | VM_PROT_WRITE, PMAP_WIRED);
213 }
214 pmap_update(pmap_kernel());
215
216 return(0);
217 }
218
219 void
220 ixp12x0_mem_bs_unmap(t, bsh, size)
221 void *t;
222 bus_space_handle_t bsh;
223 bus_size_t size;
224 {
225 vaddr_t startva, endva;
226
227 startva = trunc_page(bsh);
228 endva = round_page(bsh + size);
229
230 uvm_km_free(kernel_map, startva, endva - startva);
231 }
232
233 int
234 ixp12x0_mem_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
235 bpap, bshp)
236 void *t;
237 bus_addr_t rstart, rend;
238 bus_size_t size, alignment, boundary;
239 int cacheable;
240 bus_addr_t *bpap;
241 bus_space_handle_t *bshp;
242 {
243 panic("ixp12x0_mem_bs_alloc(): Help!\n");
244 }
245
246 void
247 ixp12x0_mem_bs_free(t, bsh, size)
248 void *t;
249 bus_space_handle_t bsh;
250 bus_size_t size;
251 {
252 panic("ixp12x0_mem_bs_free(): Help!\n");
253 }
254
255 paddr_t
256 ixp12x0_mem_bs_mmap(t, addr, off, prot, flags)
257 void *t;
258 bus_addr_t addr;
259 off_t off;
260 int prot;
261 int flags;
262 {
263 /* Not supported. */
264 return (-1);
265 }
266
267 /* I/O bus space functions */
268
269 int
270 ixp12x0_io_bs_map(t, bpa, size, cacheable, bshp)
271 void *t;
272 bus_addr_t bpa;
273 bus_size_t size;
274 int cacheable;
275 bus_space_handle_t *bshp;
276 {
277 #if 0
278 struct ixp12x0_softc *sc = t;
279 #endif
280 #if 0
281 if ((bpa + size) >= IXP12X0_PCI_IO_SIZE)
282 return (EINVAL);
283 #endif
284 /*
285 * PCI I/O space is mapped at virtual address of each evaluation board.
286 * Translate the bus address to the virtual address.
287 */
288 *bshp = bpa + IXP12X0_PCI_IO_VBASE;
289
290 return(0);
291 }
292
293 void
294 ixp12x0_io_bs_unmap(t, bsh, size)
295 void *t;
296 bus_space_handle_t bsh;
297 bus_size_t size;
298 {
299 /*
300 * Temporary implementation
301 */
302 }
303
304 int
305 ixp12x0_io_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
306 bpap, bshp)
307 void *t;
308 bus_addr_t rstart, rend;
309 bus_size_t size, alignment, boundary;
310 int cacheable;
311 bus_addr_t *bpap;
312 bus_space_handle_t *bshp;
313 {
314 panic("ixp12x0_io_bs_alloc(): Help!\n");
315 }
316
317 void
318 ixp12x0_io_bs_free(t, bsh, size)
319 void *t;
320 bus_space_handle_t bsh;
321 bus_size_t size;
322 {
323 panic("ixp12x0_io_bs_free(): Help!\n");
324 }
325
326 void *
327 ixp12x0_io_bs_vaddr(t, bsh)
328 void *t;
329 bus_space_handle_t bsh;
330 {
331 /* Not supported. */
332 return (NULL);
333 }
334
335
336 /* Common routines */
337
338 int
339 ixp12x0_bs_subregion(t, bsh, offset, size, nbshp)
340 void *t;
341 bus_space_handle_t bsh;
342 bus_size_t offset, size;
343 bus_space_handle_t *nbshp;
344 {
345
346 *nbshp = bsh + offset;
347 return (0);
348 }
349
350 void *
351 ixp12x0_bs_vaddr(t, bsh)
352 void *t;
353 bus_space_handle_t bsh;
354 {
355 return ((void *)bsh);
356 }
357
358 paddr_t
359 ixp12x0_bs_mmap(t, addr, off, prot, flags)
360 void *t;
361 bus_addr_t addr;
362 off_t off;
363 int prot;
364 int flags;
365 {
366 /* Not supported. */
367 return (-1);
368 }
369
370 void
371 ixp12x0_bs_barrier(t, bsh, offset, len, flags)
372 void *t;
373 bus_space_handle_t bsh;
374 bus_size_t offset, len;
375 int flags;
376 {
377 /* NULL */
378 }
379
380
381
382 /* End of ixp12x0_io.c */
383