Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / shark / isa / isa_io.c
blob71fdc0fda8513196274e859d6af75f51f8fb21ce
1 /* $NetBSD: isa_io.c,v 1.9 2009/03/14 15:36:13 dsl Exp $ */
3 /*
4 * Copyright 1997
5 * Digital Equipment Corporation. All rights reserved.
7 * This software is furnished under license and may be used and
8 * copied only in accordance with the following terms and conditions.
9 * Subject to these conditions, you may download, copy, install,
10 * use, modify and distribute this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
13 * 1) Any source code used, modified or distributed must reproduce
14 * and retain this copyright notice and list of conditions as
15 * they appear in the source file.
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Digital Equipment Corporation. Neither the "Digital Equipment
19 * Corporation" name nor any trademark or logo of Digital Equipment
20 * Corporation may be used to endorse or promote products derived
21 * from this software without the prior written permission of
22 * Digital Equipment Corporation.
24 * 3) This software is provided "AS-IS" and any express or implied
25 * warranties, including but not limited to, any implied warranties
26 * of merchantability, fitness for a particular purpose, or
27 * non-infringement are disclaimed. In no event shall DIGITAL be
28 * liable for any damages whatsoever, and in particular, DIGITAL
29 * shall not be liable for special, indirect, consequential, or
30 * incidental damages or damages for lost profits, loss of
31 * revenue or loss of use, whether such damages arise in contract,
32 * negligence, tort, under statute, in equity, at law or otherwise,
33 * even if advised of the possibility of such damage.
37 * bus_space I/O functions for isa
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: isa_io.c,v 1.9 2009/03/14 15:36:13 dsl Exp $");
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <machine/bus.h>
46 #include <machine/pio.h>
47 #include <machine/isa_machdep.h>
48 #include <machine/ofw.h>
49 #include "igsfb_ofbus.h"
51 #if NIGSFB_OFBUS > 0
52 extern vaddr_t igsfb_mem_vaddr, igsfb_mmio_vaddr;
53 extern paddr_t igsfb_mem_paddr;
54 #endif
56 /* Proto types for all the bus_space structure functions */
58 bs_protos(isa);
59 bs_protos(bs_notimpl);
62 * Declare the isa bus space tags
63 * The IO and MEM structs are identical, except for the cookies,
64 * which contain the address space bases.
68 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
69 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/IO!
71 struct bus_space isa_io_bs_tag = {
72 /* cookie */
73 NULL, /* initialized below */
75 /* mapping/unmapping */
76 isa_bs_map,
77 isa_bs_unmap,
78 isa_bs_subregion,
80 /* allocation/deallocation */
81 isa_bs_alloc,
82 isa_bs_free,
84 /* get kernel virtual address */
85 isa_bs_vaddr,
87 /* mmap bus space for userland */
88 isa_bs_mmap,
90 /* barrier */
91 isa_bs_barrier,
93 /* read (single) */
94 isa_bs_r_1,
95 isa_bs_r_2,
96 isa_bs_r_4,
97 bs_notimpl_bs_r_8,
99 /* read multiple */
100 isa_bs_rm_1,
101 isa_bs_rm_2,
102 isa_bs_rm_4,
103 bs_notimpl_bs_rm_8,
105 /* read region */
106 isa_bs_rr_1,
107 isa_bs_rr_2,
108 isa_bs_rr_4,
109 bs_notimpl_bs_rr_8,
111 /* write (single) */
112 isa_bs_w_1,
113 isa_bs_w_2,
114 isa_bs_w_4,
115 bs_notimpl_bs_w_8,
117 /* write multiple */
118 isa_bs_wm_1,
119 isa_bs_wm_2,
120 isa_bs_wm_4,
121 bs_notimpl_bs_wm_8,
123 /* write region */
124 isa_bs_wr_1,
125 isa_bs_wr_2,
126 isa_bs_wr_4,
127 bs_notimpl_bs_wr_8,
129 /* set multiple */
130 bs_notimpl_bs_sm_1,
131 bs_notimpl_bs_sm_2,
132 bs_notimpl_bs_sm_4,
133 bs_notimpl_bs_sm_8,
135 /* set region */
136 bs_notimpl_bs_sr_1,
137 isa_bs_sr_2,
138 bs_notimpl_bs_sr_4,
139 bs_notimpl_bs_sr_8,
141 /* copy */
142 bs_notimpl_bs_c_1,
143 isa_bs_c_2,
144 bs_notimpl_bs_c_4,
145 bs_notimpl_bs_c_8,
147 /* stream methods are identical to regular read/write here */
148 /* read stream single */
149 isa_bs_r_1,
150 isa_bs_r_2,
151 isa_bs_r_4,
152 bs_notimpl_bs_r_8,
154 /* read stream multiple */
155 isa_bs_rm_1,
156 isa_bs_rm_2,
157 isa_bs_rm_4,
158 bs_notimpl_bs_rm_8,
160 /* read region stream */
161 isa_bs_rr_1,
162 isa_bs_rr_2,
163 isa_bs_rr_4,
164 bs_notimpl_bs_rr_8,
166 /* write stream single */
167 isa_bs_w_1,
168 isa_bs_w_2,
169 isa_bs_w_4,
170 bs_notimpl_bs_w_8,
172 /* write stream multiple */
173 isa_bs_wm_1,
174 isa_bs_wm_2,
175 isa_bs_wm_4,
176 bs_notimpl_bs_wm_8,
178 /* write region stream */
179 isa_bs_wr_1,
180 isa_bs_wr_2,
181 isa_bs_wr_4,
182 bs_notimpl_bs_wr_8,
187 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
188 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/MEMORY!
190 struct bus_space isa_mem_bs_tag = {
191 /* cookie */
192 NULL, /* initialized below */
194 /* mapping/unmapping */
195 isa_bs_map,
196 isa_bs_unmap,
197 isa_bs_subregion,
199 /* allocation/deallocation */
200 isa_bs_alloc,
201 isa_bs_free,
203 /* get kernel virtual address */
204 isa_bs_vaddr,
206 /* mmap bus space for userland */
207 isa_bs_mmap,
209 /* barrier */
210 isa_bs_barrier,
212 /* read (single) */
213 isa_bs_r_1,
214 isa_bs_r_2,
215 isa_bs_r_4,
216 bs_notimpl_bs_r_8,
218 /* read multiple */
219 isa_bs_rm_1,
220 isa_bs_rm_2,
221 isa_bs_rm_4,
222 bs_notimpl_bs_rm_8,
224 /* read region */
225 isa_bs_rr_1,
226 isa_bs_rr_2,
227 isa_bs_rr_4,
228 bs_notimpl_bs_rr_8,
230 /* write (single) */
231 isa_bs_w_1,
232 isa_bs_w_2,
233 isa_bs_w_4,
234 bs_notimpl_bs_w_8,
236 /* write multiple */
237 isa_bs_wm_1,
238 isa_bs_wm_2,
239 isa_bs_wm_4,
240 bs_notimpl_bs_wm_8,
242 /* write region */
243 isa_bs_wr_1,
244 isa_bs_wr_2,
245 isa_bs_wr_4,
246 bs_notimpl_bs_wr_8,
248 /* set multiple */
249 bs_notimpl_bs_sm_1,
250 bs_notimpl_bs_sm_2,
251 bs_notimpl_bs_sm_4,
252 bs_notimpl_bs_sm_8,
254 /* set region */
255 bs_notimpl_bs_sr_1,
256 isa_bs_sr_2,
257 bs_notimpl_bs_sr_4,
258 bs_notimpl_bs_sr_8,
260 /* copy */
261 bs_notimpl_bs_c_1,
262 isa_bs_c_2,
263 bs_notimpl_bs_c_4,
264 bs_notimpl_bs_c_8,
266 /* stream methods are identical to regular read/write here */
267 /* read stream single */
268 isa_bs_r_1,
269 isa_bs_r_2,
270 isa_bs_r_4,
271 bs_notimpl_bs_r_8,
273 /* read stream multiple */
274 isa_bs_rm_1,
275 isa_bs_rm_2,
276 isa_bs_rm_4,
277 bs_notimpl_bs_rm_8,
279 /* read region stream */
280 isa_bs_rr_1,
281 isa_bs_rr_2,
282 isa_bs_rr_4,
283 bs_notimpl_bs_rr_8,
285 /* write stream single */
286 isa_bs_w_1,
287 isa_bs_w_2,
288 isa_bs_w_4,
289 bs_notimpl_bs_w_8,
291 /* write stream multiple */
292 isa_bs_wm_1,
293 isa_bs_wm_2,
294 isa_bs_wm_4,
295 bs_notimpl_bs_wm_8,
297 /* write region stream */
298 isa_bs_wr_1,
299 isa_bs_wr_2,
300 isa_bs_wr_4,
301 bs_notimpl_bs_wr_8,
304 /* bus space functions */
306 void
307 isa_io_init(vaddr_t isa_io_addr, vaddr_t isa_mem_addr)
309 isa_io_bs_tag.bs_cookie = (void *)isa_io_addr;
310 isa_mem_bs_tag.bs_cookie = (void *)isa_mem_addr;
314 * break the abstraction: sometimes, other parts of the system
315 * (e.g. X servers) need to map ISA space directly. use these
316 * functions sparingly!
318 vaddr_t
319 isa_io_data_vaddr(void)
321 return (vaddr_t)isa_io_bs_tag.bs_cookie;
324 vaddr_t
325 isa_mem_data_vaddr(void)
327 return (vaddr_t)isa_mem_bs_tag.bs_cookie;
331 isa_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable, bus_space_handle_t *bshp)
333 *bshp = bpa + (bus_addr_t)t;
334 return(0);
337 void
338 isa_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
340 /* Nothing to do. */
343 paddr_t
344 isa_bs_mmap(void *cookie, bus_addr_t addr, off_t off, int prot,
345 int flags)
347 paddr_t paddr, ret;
349 #ifdef OFISA_DEBUG
350 printf("mmap %08x %08x %08x", (uint32_t)cookie, (uint32_t)addr, (uint32_t)off);
351 #endif
352 #if NIGSFB_OFBUS > 0
353 if ((vaddr_t)cookie == igsfb_mem_vaddr) {
354 paddr = igsfb_mem_paddr;
355 } else
356 #endif
357 paddr = ofw_gettranslation((vaddr_t)cookie);
359 if (paddr == -1) {
360 #ifdef OFISA_DEBUG
361 printf(" no translation\n");
362 #endif
363 return -1;
365 ret = paddr + addr + off;
366 #ifdef OFISA_DEBUG
367 printf(" -> %08x %08x\n", (uint32_t)paddr, (uint32_t)ret);
368 #endif
369 return arm_btop(ret);
373 isa_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
375 /* printf("isa_subregion(tag=%p, bsh=%lx, off=%lx, sz=%lx)\n",
376 t, bsh, offset, size);*/
377 *nbshp = bsh + offset;
378 return(0);
382 isa_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
383 bpap, bshp)
384 void *t;
385 bus_addr_t rstart, rend;
386 bus_size_t size, alignment, boundary;
387 int cacheable;
388 bus_addr_t *bpap;
389 bus_space_handle_t *bshp;
391 panic("isa_alloc(): Help!");
394 void
395 isa_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
397 panic("isa_free(): Help!");
400 void *
401 isa_bs_vaddr(void *t, bus_space_handle_t bsh)
404 return ((void *)bsh);
407 void
408 isa_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags)
410 /* just return */