ixp12x0_io.c revision 1.7 1 /* $NetBSD: ixp12x0_io.c,v 1.7 2003/03/25 06:12:46 igy Exp $ */
2
3 /*
4 * Copyright (c) 2002, 2003
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 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: ixp12x0_io.c,v 1.7 2003/03/25 06:12:46 igy Exp $");
38
39 /*
40 * bus_space I/O functions for ixp12x0
41 */
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/queue.h>
46
47 #include <uvm/uvm.h>
48
49 #include <machine/bus.h>
50
51 #include <arm/ixp12x0/ixp12x0reg.h>
52 #include <arm/ixp12x0/ixp12x0var.h>
53
54 /* Proto types for all the bus_space structure functions */
55 bs_protos(ixp12x0);
56 bs_protos(ixp12x0_io);
57 bs_protos(ixp12x0_mem);
58 bs_protos(generic);
59 bs_protos(generic_armv4);
60 bs_protos(bs_notimpl);
61
62 struct bus_space ixp12x0_bs_tag = {
63 /* cookie */
64 (void *) 0,
65
66 /* mapping/unmapping */
67 NULL,
68 NULL,
69 ixp12x0_bs_subregion,
70
71 /* allocation/deallocation */
72 NULL,
73 NULL,
74
75 /* get kernel virtual address */
76 ixp12x0_bs_vaddr,
77
78 /* mmap bus space for userland */
79 ixp12x0_bs_mmap,
80
81 /* barrier */
82 ixp12x0_bs_barrier,
83
84 /* read (single) */
85 generic_bs_r_1,
86 generic_armv4_bs_r_2,
87 generic_bs_r_4,
88 bs_notimpl_bs_r_8,
89
90 /* read multiple */
91 generic_bs_rm_1,
92 generic_armv4_bs_rm_2,
93 generic_bs_rm_4,
94 bs_notimpl_bs_rm_8,
95
96 /* read region */
97 bs_notimpl_bs_rr_1,
98 generic_armv4_bs_rr_2,
99 generic_bs_rr_4,
100 bs_notimpl_bs_rr_8,
101
102 /* write (single) */
103 generic_bs_w_1,
104 generic_armv4_bs_w_2,
105 generic_bs_w_4,
106 bs_notimpl_bs_w_8,
107
108 /* write multiple */
109 generic_bs_wm_1,
110 generic_armv4_bs_wm_2,
111 generic_bs_wm_4,
112 bs_notimpl_bs_wm_8,
113
114 /* write region */
115 bs_notimpl_bs_wr_1,
116 generic_armv4_bs_wr_2,
117 generic_bs_wr_4,
118 bs_notimpl_bs_wr_8,
119
120 /* set multiple */
121 bs_notimpl_bs_sm_1,
122 bs_notimpl_bs_sm_2,
123 bs_notimpl_bs_sm_4,
124 bs_notimpl_bs_sm_8,
125
126 /* set region */
127 bs_notimpl_bs_sr_1,
128 generic_armv4_bs_sr_2,
129 generic_bs_sr_4,
130 bs_notimpl_bs_sr_8,
131
132 /* copy */
133 bs_notimpl_bs_c_1,
134 generic_armv4_bs_c_2,
135 bs_notimpl_bs_c_4,
136 bs_notimpl_bs_c_8,
137 };
138
139 void
140 ixp12x0_bs_init(bs, cookie)
141 bus_space_tag_t bs;
142 void *cookie;
143 {
144 *bs = ixp12x0_bs_tag;
145 bs->bs_cookie = cookie;
146 }
147
148 void
149 ixp12x0_io_bs_init(bs, cookie)
150 bus_space_tag_t bs;
151 void *cookie;
152 {
153 *bs = ixp12x0_bs_tag;
154 bs->bs_cookie = cookie;
155
156 bs->bs_map = ixp12x0_io_bs_map;
157 bs->bs_unmap = ixp12x0_io_bs_unmap;
158 bs->bs_alloc = ixp12x0_io_bs_alloc;
159 bs->bs_free = ixp12x0_io_bs_free;
160
161 bs->bs_vaddr = ixp12x0_io_bs_vaddr;
162 }
163 void
164 ixp12x0_mem_bs_init(bs, cookie)
165 bus_space_tag_t bs;
166 void *cookie;
167 {
168 *bs = ixp12x0_bs_tag;
169 bs->bs_cookie = cookie;
170
171 bs->bs_map = ixp12x0_mem_bs_map;
172 bs->bs_unmap = ixp12x0_mem_bs_unmap;
173 bs->bs_alloc = ixp12x0_mem_bs_alloc;
174 bs->bs_free = ixp12x0_mem_bs_free;
175
176 bs->bs_mmap = ixp12x0_mem_bs_mmap;
177 }
178
179 /* mem bus space functions */
180
181 int
182 ixp12x0_mem_bs_map(t, bpa, size, cacheable, bshp)
183 void *t;
184 bus_addr_t bpa;
185 bus_size_t size;
186 int cacheable;
187 bus_space_handle_t *bshp;
188 {
189 paddr_t pa, endpa;
190 vaddr_t va;
191
192 if ((bpa + size) >= IXP12X0_PCI_MEM_VBASE + IXP12X0_PCI_MEM_SIZE)
193 return (EINVAL);
194 /*
195 * PCI MEM space is mapped same address as real memory
196 * see. PCI_ADDR_EXT
197 */
198 pa = trunc_page(bpa);
199 endpa = round_page(bpa + size);
200
201 /* Get some VM. */
202 va = uvm_km_valloc(kernel_map, endpa - pa);
203 if (va == 0)
204 return(ENOMEM);
205
206 /* Store the bus space handle */
207 *bshp = va + (bpa & PAGE_MASK);
208
209 /* Now map the pages */
210 for(; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
211 pmap_enter(pmap_kernel(), va, pa,
212 VM_PROT_READ | VM_PROT_WRITE,
213 VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
214 }
215 pmap_update(pmap_kernel());
216
217 return(0);
218 }
219
220 void
221 ixp12x0_mem_bs_unmap(t, bsh, size)
222 void *t;
223 bus_space_handle_t bsh;
224 bus_size_t size;
225 {
226 vaddr_t startva, endva;
227
228 startva = trunc_page(bsh);
229 endva = round_page(bsh + size);
230
231 uvm_km_free(kernel_map, startva, endva - startva);
232 }
233
234 int
235 ixp12x0_mem_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
236 bpap, bshp)
237 void *t;
238 bus_addr_t rstart, rend;
239 bus_size_t size, alignment, boundary;
240 int cacheable;
241 bus_addr_t *bpap;
242 bus_space_handle_t *bshp;
243 {
244 panic("ixp12x0_mem_bs_alloc(): Help!");
245 }
246
247 void
248 ixp12x0_mem_bs_free(t, bsh, size)
249 void *t;
250 bus_space_handle_t bsh;
251 bus_size_t size;
252 {
253 panic("ixp12x0_mem_bs_free(): Help!");
254 }
255
256 paddr_t
257 ixp12x0_mem_bs_mmap(t, addr, off, prot, flags)
258 void *t;
259 bus_addr_t addr;
260 off_t off;
261 int prot;
262 int flags;
263 {
264 /* Not supported. */
265 return (-1);
266 }
267
268 /* I/O bus space functions */
269
270 int
271 ixp12x0_io_bs_map(t, bpa, size, cacheable, bshp)
272 void *t;
273 bus_addr_t bpa;
274 bus_size_t size;
275 int cacheable;
276 bus_space_handle_t *bshp;
277 {
278 if ((bpa + size) >= IXP12X0_PCI_IO_SIZE)
279 return (EINVAL);
280
281 /*
282 * PCI I/O space is mapped at virtual address of each evaluation board.
283 * Translate the bus address(0x0) to the virtual address(0x54000000).
284 */
285 *bshp = bpa + IXP12X0_PCI_IO_VBASE;
286
287 return(0);
288 }
289
290 void
291 ixp12x0_io_bs_unmap(t, bsh, size)
292 void *t;
293 bus_space_handle_t bsh;
294 bus_size_t size;
295 {
296 /*
297 * Temporary implementation
298 */
299 }
300
301 int
302 ixp12x0_io_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
303 bpap, bshp)
304 void *t;
305 bus_addr_t rstart, rend;
306 bus_size_t size, alignment, boundary;
307 int cacheable;
308 bus_addr_t *bpap;
309 bus_space_handle_t *bshp;
310 {
311 panic("ixp12x0_io_bs_alloc(): Help!");
312 }
313
314 void
315 ixp12x0_io_bs_free(t, bsh, size)
316 void *t;
317 bus_space_handle_t bsh;
318 bus_size_t size;
319 {
320 panic("ixp12x0_io_bs_free(): Help!");
321 }
322
323 void *
324 ixp12x0_io_bs_vaddr(t, bsh)
325 void *t;
326 bus_space_handle_t bsh;
327 {
328 /* Not supported. */
329 return (NULL);
330 }
331
332
333 /* Common routines */
334
335 int
336 ixp12x0_bs_subregion(t, bsh, offset, size, nbshp)
337 void *t;
338 bus_space_handle_t bsh;
339 bus_size_t offset, size;
340 bus_space_handle_t *nbshp;
341 {
342
343 *nbshp = bsh + offset;
344 return (0);
345 }
346
347 void *
348 ixp12x0_bs_vaddr(t, bsh)
349 void *t;
350 bus_space_handle_t bsh;
351 {
352 return ((void *)bsh);
353 }
354
355 paddr_t
356 ixp12x0_bs_mmap(t, addr, off, prot, flags)
357 void *t;
358 bus_addr_t addr;
359 off_t off;
360 int prot;
361 int flags;
362 {
363 /* Not supported. */
364 return (-1);
365 }
366
367 void
368 ixp12x0_bs_barrier(t, bsh, offset, len, flags)
369 void *t;
370 bus_space_handle_t bsh;
371 bus_size_t offset, len;
372 int flags;
373 {
374 /* NULL */
375 }
376
377
378
379 /* End of ixp12x0_io.c */
380