1 /* $NetBSD: isa_io.c,v 1.6 2009/03/14 15:36:05 dsl Exp $ */
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 */
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
= {
69 NULL
, /* initialized below */
71 /* mapping/unmapping */
76 /* allocation/deallocation */
80 /* get kernel virtual address */
83 /* mmap bus space for userland */
84 bs_notimpl_bs_mmap
, /* XXX possible even? XXX */
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
= {
150 NULL
, /* initialized below */
152 /* mapping/unmapping */
157 /* allocation/deallocation */
161 /* get kernel virtual address */
164 /* mmap bus space for userland */
165 bs_notimpl_bs_mmap
, /* XXX open for now ... XXX */
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
;
232 isa_bs_mallocok(void)
237 /* bus space functions */
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!
261 isa_io_data_vaddr(void)
263 return (vm_offset_t
)isa_io_bs_tag
.bs_cookie
;
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
)
278 if (t
== isa_io_bs_tag
.bs_cookie
)
283 err
= extent_alloc_region(ex
, bpa
, size
,
284 EX_NOWAIT
|(malloc_safe
? EX_MALLOCOK
: 0));
288 *bshp
= bpa
+ (bus_addr_t
)t
;
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
;
306 isa_bs_alloc(t
, rstart
, rend
, size
, alignment
, boundary
, cacheable
,
309 bus_addr_t rstart
, rend
;
310 bus_size_t size
, alignment
, boundary
;
313 bus_space_handle_t
*bshp
;
319 if (t
== isa_io_bs_tag
.bs_cookie
)
324 err
= extent_alloc_subregion(ex
, rstart
, rend
, size
, alignment
,
325 boundary
, (EX_FAST
|EX_NOWAIT
|(malloc_safe
? EX_MALLOCOK
: 0)),
331 *bshp
= *bpap
= bpa
+ (bus_addr_t
)t
;
336 isa_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
340 if (t
== isa_io_bs_tag
.bs_cookie
)
345 extent_free(ex
, bsh
- (bus_addr_t
)t
, size
,
346 EX_NOWAIT
|(malloc_safe
? EX_MALLOCOK
: 0));
350 isa_bs_vaddr(void *t
, bus_space_handle_t bsh
)
353 return ((void *)bsh
);
357 isa_bs_barrier(void *t
, bus_space_handle_t bsh
, bus_size_t offset
, bus_size_t len
, int flags
)