No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / evbarm / tsarm / isa / isa_io.c
blob5a01c2743eab91d47982c1bdef4d7a93564181d5
1 /* $NetBSD: isa_io.c,v 1.6 2009/03/14 15:36:05 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.6 2009/03/14 15:36:05 dsl Exp $");
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/malloc.h>
46 #include <sys/extent.h>
47 #include <machine/bus.h>
48 #include <machine/pio.h>
49 #include <machine/isa_machdep.h>
51 /* Proto types for all the bus_space structure functions */
53 bs_protos(isa);
54 bs_protos(bs_notimpl);
55 void isa_bs_mallocok(void);
58 * Declare the isa bus space tags
59 * The IO and MEM structs are identical, except for the cookies,
60 * which contain the address space bases.
64 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
65 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF 16 BIT ISA/IO!
67 struct bus_space isa_io_bs_tag = {
68 /* cookie */
69 NULL, /* initialized below */
71 /* mapping/unmapping */
72 isa_bs_map,
73 isa_bs_unmap,
74 isa_bs_subregion,
76 /* allocation/deallocation */
77 isa_bs_alloc,
78 isa_bs_free,
80 /* get kernel virtual address */
81 isa_bs_vaddr,
83 /* mmap bus space for userland */
84 bs_notimpl_bs_mmap, /* XXX possible even? XXX */
86 /* barrier */
87 isa_bs_barrier,
89 /* read (single) */
90 isa_bs_r_1,
91 isa_bs_r_2,
92 isa_bs_r_4,
93 bs_notimpl_bs_r_8,
95 /* read multiple */
96 isa_bs_rm_1,
97 isa_bs_rm_2,
98 isa_bs_rm_4,
99 bs_notimpl_bs_rm_8,
101 /* read region */
102 isa_bs_rr_1,
103 isa_bs_rr_2,
104 isa_bs_rr_4,
105 bs_notimpl_bs_rr_8,
107 /* write (single) */
108 isa_bs_w_1,
109 isa_bs_w_2,
110 isa_bs_w_4,
111 bs_notimpl_bs_w_8,
113 /* write multiple */
114 isa_bs_wm_1,
115 isa_bs_wm_2,
116 isa_bs_wm_4,
117 bs_notimpl_bs_wm_8,
119 /* write region */
120 isa_bs_wr_1,
121 isa_bs_wr_2,
122 isa_bs_wr_4,
123 bs_notimpl_bs_wr_8,
125 /* set multiple */
126 bs_notimpl_bs_sm_1,
127 bs_notimpl_bs_sm_2,
128 bs_notimpl_bs_sm_4,
129 bs_notimpl_bs_sm_8,
131 /* set region */
132 bs_notimpl_bs_sr_1,
133 isa_bs_sr_2,
134 bs_notimpl_bs_sr_4,
135 bs_notimpl_bs_sr_8,
137 /* copy */
138 bs_notimpl_bs_c_1,
139 bs_notimpl_bs_c_2,
140 bs_notimpl_bs_c_4,
141 bs_notimpl_bs_c_8,
145 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
146 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/MEMORY!
148 struct bus_space isa_mem_bs_tag = {
149 /* cookie */
150 NULL, /* initialized below */
152 /* mapping/unmapping */
153 isa_bs_map,
154 isa_bs_unmap,
155 isa_bs_subregion,
157 /* allocation/deallocation */
158 isa_bs_alloc,
159 isa_bs_free,
161 /* get kernel virtual address */
162 isa_bs_vaddr,
164 /* mmap bus space for userland */
165 bs_notimpl_bs_mmap, /* XXX open for now ... XXX */
167 /* barrier */
168 isa_bs_barrier,
170 /* read (single) */
171 isa_bs_r_1,
172 isa_bs_r_2,
173 isa_bs_r_4,
174 bs_notimpl_bs_r_8,
176 /* read multiple */
177 isa_bs_rm_1,
178 isa_bs_rm_2,
179 isa_bs_rm_4,
180 bs_notimpl_bs_rm_8,
182 /* read region */
183 isa_bs_rr_1,
184 isa_bs_rr_2,
185 isa_bs_rr_4,
186 bs_notimpl_bs_rr_8,
188 /* write (single) */
189 isa_bs_w_1,
190 isa_bs_w_2,
191 isa_bs_w_4,
192 bs_notimpl_bs_w_8,
194 /* write multiple */
195 isa_bs_wm_1,
196 isa_bs_wm_2,
197 isa_bs_wm_4,
198 bs_notimpl_bs_wm_8,
200 /* write region */
201 isa_bs_wr_1,
202 isa_bs_wr_2,
203 isa_bs_wr_4,
204 bs_notimpl_bs_wr_8,
206 /* set multiple */
207 bs_notimpl_bs_sm_1,
208 bs_notimpl_bs_sm_2,
209 bs_notimpl_bs_sm_4,
210 bs_notimpl_bs_sm_8,
212 /* set region */
213 bs_notimpl_bs_sr_1,
214 isa_bs_sr_2,
215 bs_notimpl_bs_sr_4,
216 bs_notimpl_bs_sr_8,
218 /* copy */
219 bs_notimpl_bs_c_1,
220 bs_notimpl_bs_c_2,
221 bs_notimpl_bs_c_4,
222 bs_notimpl_bs_c_8,
225 static long isaio_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)];
226 static long isamem_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8) / sizeof(long)];
227 static int malloc_safe = 0;
228 struct extent *isaio_ex;
229 struct extent *isamem_ex;
231 void
232 isa_bs_mallocok(void)
234 malloc_safe = 1;
237 /* bus space functions */
239 void
240 isa_io_init(vm_offset_t isa_io_addr, vm_offset_t isa_mem_addr)
242 isa_io_bs_tag.bs_cookie = (void *)isa_io_addr;
243 isa_mem_bs_tag.bs_cookie = (void *)isa_mem_addr;
245 isaio_ex = extent_create("isaio", 0x0, 0xffff, M_DEVBUF,
246 (void *)isaio_ex_storage, sizeof(isaio_ex_storage),
247 EX_NOWAIT|EX_NOCOALESCE);
248 isamem_ex = extent_create("isamem", 0x0, 0xfffff, M_DEVBUF,
249 (void *)isamem_ex_storage, sizeof(isamem_ex_storage),
250 EX_NOWAIT|EX_NOCOALESCE);
251 if (isaio_ex == NULL || isamem_ex == NULL)
252 panic("isa_io_init(): can't alloc extent maps");
256 * break the abstraction: sometimes, other parts of the system
257 * (e.g. X servers) need to map ISA space directly. use these
258 * functions sparingly!
260 vm_offset_t
261 isa_io_data_vaddr(void)
263 return (vm_offset_t)isa_io_bs_tag.bs_cookie;
266 vm_offset_t
267 isa_mem_data_vaddr(void)
269 return (vm_offset_t)isa_mem_bs_tag.bs_cookie;
273 isa_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable, bus_space_handle_t *bshp)
275 struct extent *ex;
276 int err;
278 if (t == isa_io_bs_tag.bs_cookie)
279 ex = isaio_ex;
280 else
281 ex = isamem_ex;
283 err = extent_alloc_region(ex, bpa, size,
284 EX_NOWAIT|(malloc_safe ? EX_MALLOCOK : 0));
285 if (err)
286 return err;
288 *bshp = bpa + (bus_addr_t)t;
289 return(0);
292 void
293 isa_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
295 isa_bs_free(t, bsh, size);
299 isa_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
301 *nbshp = bsh + offset;
302 return(0);
306 isa_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
307 bpap, bshp)
308 void *t;
309 bus_addr_t rstart, rend;
310 bus_size_t size, alignment, boundary;
311 int cacheable;
312 bus_addr_t *bpap;
313 bus_space_handle_t *bshp;
315 struct extent *ex;
316 u_long bpa;
317 int err;
319 if (t == isa_io_bs_tag.bs_cookie)
320 ex = isaio_ex;
321 else
322 ex = isamem_ex;
324 err = extent_alloc_subregion(ex, rstart, rend, size, alignment,
325 boundary, (EX_FAST|EX_NOWAIT|(malloc_safe ? EX_MALLOCOK : 0)),
326 &bpa);
328 if (err)
329 return err;
331 *bshp = *bpap = bpa + (bus_addr_t)t;
332 return 0;
335 void
336 isa_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
338 struct extent *ex;
340 if (t == isa_io_bs_tag.bs_cookie)
341 ex = isaio_ex;
342 else
343 ex = isamem_ex;
345 extent_free(ex, bsh - (bus_addr_t)t, size,
346 EX_NOWAIT|(malloc_safe ? EX_MALLOCOK : 0));
349 void *
350 isa_bs_vaddr(void *t, bus_space_handle_t bsh)
353 return ((void *)bsh);
356 void
357 isa_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags)
359 /* just return */