2 * Copyright (c) KATO Takenori, 1999.
4 * All rights reserved. Unpublished rights reserved under the copyright
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer as
13 * the first lines of this file unmodified.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 /* $NecBSD: busio.h,v 3.25.4.2.2.1 2000/06/12 03:53:08 honda Exp $ */
35 /* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */
38 * [NetBSD for NEC PC-98 series]
39 * Copyright (c) 1997, 1998
40 * NetBSD/pc98 porting staff. All rights reserved.
42 * [Ported for FreeBSD]
44 * TAKAHASHI Yoshihiro. All rights reserved.
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. The name of the author may not be used to endorse or promote products
55 * derived from this software without specific prior written permission.
57 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
59 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
60 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
61 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
62 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
63 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
65 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
66 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
67 * POSSIBILITY OF SUCH DAMAGE.
71 * Copyright (c) 1997, 1998
72 * Naofumi HONDA. All rights reserved.
74 * This module support generic bus address relocation mechanism.
75 * To reduce a function call overhead, we employ pascal call methods.
81 #include <sys/systm.h>
83 #include <machine/_bus.h>
84 #include <machine/cpufunc.h>
86 #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF
87 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
88 #define BUS_SPACE_MAXSIZE 0xFFFFFFFF
89 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF
90 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
91 #define BUS_SPACE_MAXADDR 0xFFFFFFFF
93 #define BUS_SPACE_UNRESTRICTED (~0)
96 * address relocation table
98 #define BUS_SPACE_IAT_MAXSIZE 33
99 typedef bus_addr_t *bus_space_iat_t;
101 #define BUS_SPACE_IAT_SZ(IOTARRAY) (sizeof(IOTARRAY)/sizeof(bus_addr_t))
104 * Access methods for bus resources and address space.
111 #define _PASCAL_CALL (void)
113 #define _BUS_SPACE_CALL_FUNCS_TAB(NAME,TYPE,BWN) \
114 NAME##_space_read_##BWN, \
115 NAME##_space_read_multi_##BWN, \
116 NAME##_space_read_region_##BWN, \
117 NAME##_space_write_##BWN, \
118 NAME##_space_write_multi_##BWN, \
119 NAME##_space_write_region_##BWN, \
120 NAME##_space_set_multi_##BWN, \
121 NAME##_space_set_region_##BWN, \
122 NAME##_space_copy_region_##BWN
124 #define _BUS_SPACE_CALL_FUNCS_PROTO(NAME,TYPE,BWN) \
125 TYPE NAME##_space_read_##BWN _PASCAL_CALL; \
126 void NAME##_space_read_multi_##BWN _PASCAL_CALL; \
127 void NAME##_space_read_region_##BWN _PASCAL_CALL; \
128 void NAME##_space_write_##BWN _PASCAL_CALL; \
129 void NAME##_space_write_multi_##BWN _PASCAL_CALL; \
130 void NAME##_space_write_region_##BWN _PASCAL_CALL; \
131 void NAME##_space_set_multi_##BWN _PASCAL_CALL; \
132 void NAME##_space_set_region_##BWN _PASCAL_CALL; \
133 void NAME##_space_copy_region_##BWN _PASCAL_CALL;
135 #define _BUS_SPACE_CALL_FUNCS(NAME,TYPE,BWN) \
136 TYPE (* NAME##_read_##BWN) _PASCAL_CALL; \
137 void (* NAME##_read_multi_##BWN) _PASCAL_CALL; \
138 void (* NAME##_read_region_##BWN) _PASCAL_CALL; \
139 void (* NAME##_write_##BWN) _PASCAL_CALL; \
140 void (* NAME##_write_multi_##BWN) _PASCAL_CALL; \
141 void (* NAME##_write_region_##BWN) _PASCAL_CALL; \
142 void (* NAME##_set_multi_##BWN) _PASCAL_CALL; \
143 void (* NAME##_set_region_##BWN) _PASCAL_CALL; \
144 void (* NAME##_copy_region_##BWN) _PASCAL_CALL;
146 struct bus_space_access_methods {
147 /* 8 bits access methods */
148 _BUS_SPACE_CALL_FUNCS(bs,u_int8_t,1)
150 /* 16 bits access methods */
151 _BUS_SPACE_CALL_FUNCS(bs,u_int16_t,2)
153 /* 32 bits access methods */
154 _BUS_SPACE_CALL_FUNCS(bs,u_int32_t,4)
158 * Access methods for bus resources and address space.
160 struct bus_space_tag {
161 #define BUS_SPACE_TAG_IO 0
162 #define BUS_SPACE_TAG_MEM 1
163 u_int bs_tag; /* bus space flags */
165 struct bus_space_access_methods bs_da; /* direct access */
166 struct bus_space_access_methods bs_ra; /* relocate access */
168 struct bus_space_access_methods bs_ida; /* indexed direct access */
175 struct bus_space_handle {
179 bus_addr_t bsh_iat[BUS_SPACE_IAT_MAXSIZE];
183 struct resource **bsh_res;
186 struct bus_space_access_methods bsh_bam;
190 * Values for the pc98 bus space tag, not to be used directly by MI code.
192 extern struct bus_space_tag SBUS_io_space_tag;
193 extern struct bus_space_tag SBUS_mem_space_tag;
195 #define X86_BUS_SPACE_IO (&SBUS_io_space_tag)
196 #define X86_BUS_SPACE_MEM (&SBUS_mem_space_tag)
199 * Allocate/Free bus_space_handle
201 int i386_bus_space_handle_alloc(bus_space_tag_t t, bus_addr_t bpa,
202 bus_size_t size, bus_space_handle_t *bshp);
203 void i386_bus_space_handle_free(bus_space_tag_t t, bus_space_handle_t bsh,
207 * int bus_space_map (bus_space_tag_t t, bus_addr_t addr,
208 * bus_size_t size, int flag, bus_space_handle_t *bshp);
210 * Map a region of bus space.
213 int i386_memio_map(bus_space_tag_t t, bus_addr_t addr, bus_size_t size,
214 int flag, bus_space_handle_t *bshp);
216 #define bus_space_map(t, a, s, f, hp) \
217 i386_memio_map((t), (a), (s), (f), (hp))
220 * int bus_space_unmap (bus_space_tag_t t,
221 * bus_space_handle_t bsh, bus_size_t size);
223 * Unmap a region of bus space.
226 void i386_memio_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
229 #define bus_space_unmap(t, h, s) \
230 i386_memio_unmap((t), (h), (s))
233 * int bus_space_map_load (bus_space_tag_t t, bus_space_handle_t bsh,
234 * bus_size_t size, bus_space_iat_t iat, u_int flags);
236 * Load I/O address table of bus space.
239 int i386_memio_map_load(bus_space_tag_t t, bus_space_handle_t bsh,
240 bus_size_t size, bus_space_iat_t iat, u_int flags);
242 #define bus_space_map_load(t, h, s, iat, f) \
243 i386_memio_map_load((t), (h), (s), (iat), (f))
246 * int bus_space_subregion (bus_space_tag_t t,
247 * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
248 * bus_space_handle_t *nbshp);
250 * Get a new handle for a subregion of an already-mapped area of bus space.
253 int i386_memio_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
254 bus_size_t offset, bus_size_t size,
255 bus_space_handle_t *nbshp);
257 #define bus_space_subregion(t, h, o, s, nhp) \
258 i386_memio_subregion((t), (h), (o), (s), (nhp))
261 * int bus_space_free (bus_space_tag_t t,
262 * bus_space_handle_t bsh, bus_size_t size);
264 * Free a region of bus space.
267 void i386_memio_free(bus_space_tag_t t, bus_space_handle_t bsh,
270 #define bus_space_free(t, h, s) \
271 i386_memio_free((t), (h), (s))
274 * int bus_space_compare (bus_space_tag_t t1, bus_space_handle_t bsh1,
275 * bus_space_tag_t t2, bus_space_handle_t bsh2);
277 * Compare two resources.
279 int i386_memio_compare(bus_space_tag_t t1, bus_space_handle_t bsh1,
280 bus_space_tag_t t2, bus_space_handle_t bsh2);
282 #define bus_space_compare(t1, h1, t2, h2) \
283 i386_memio_compare((t1), (h1), (t2), (h2))
286 * Access methods for bus resources and address space.
288 #define _BUS_ACCESS_METHODS_PROTO(TYPE,BWN) \
289 static __inline TYPE bus_space_read_##BWN \
290 (bus_space_tag_t, bus_space_handle_t, bus_size_t offset); \
291 static __inline void bus_space_read_multi_##BWN \
292 (bus_space_tag_t, bus_space_handle_t, \
293 bus_size_t, TYPE *, size_t); \
294 static __inline void bus_space_read_region_##BWN \
295 (bus_space_tag_t, bus_space_handle_t, \
296 bus_size_t, TYPE *, size_t); \
297 static __inline void bus_space_write_##BWN \
298 (bus_space_tag_t, bus_space_handle_t, bus_size_t, TYPE); \
299 static __inline void bus_space_write_multi_##BWN \
300 (bus_space_tag_t, bus_space_handle_t, \
301 bus_size_t, const TYPE *, size_t); \
302 static __inline void bus_space_write_region_##BWN \
303 (bus_space_tag_t, bus_space_handle_t, \
304 bus_size_t, const TYPE *, size_t); \
305 static __inline void bus_space_set_multi_##BWN \
306 (bus_space_tag_t, bus_space_handle_t, bus_size_t, TYPE, size_t);\
307 static __inline void bus_space_set_region_##BWN \
308 (bus_space_tag_t, bus_space_handle_t, bus_size_t, TYPE, size_t);\
309 static __inline void bus_space_copy_region_##BWN \
310 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
311 bus_space_handle_t, bus_size_t, size_t);
313 _BUS_ACCESS_METHODS_PROTO(u_int8_t,1)
314 _BUS_ACCESS_METHODS_PROTO(u_int16_t,2)
315 _BUS_ACCESS_METHODS_PROTO(u_int32_t,4)
320 #define _BUS_SPACE_READ(TYPE,BWN) \
321 static __inline TYPE \
322 bus_space_read_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
325 register TYPE result; \
327 __asm __volatile("call *%2" \
330 :"o" (bsh->bsh_bam.bs_read_##BWN), \
338 _BUS_SPACE_READ(u_int8_t,1)
339 _BUS_SPACE_READ(u_int16_t,2)
340 _BUS_SPACE_READ(u_int32_t,4)
345 #define _BUS_SPACE_WRITE(TYPE,BWN) \
346 static __inline void \
347 bus_space_write_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
348 bus_size_t offset, TYPE val) \
351 __asm __volatile("call *%1" \
353 :"o" (bsh->bsh_bam.bs_write_##BWN), \
360 _BUS_SPACE_WRITE(u_int8_t,1)
361 _BUS_SPACE_WRITE(u_int16_t,2)
362 _BUS_SPACE_WRITE(u_int32_t,4)
367 #define _BUS_SPACE_READ_MULTI(TYPE,BWN) \
368 static __inline void \
369 bus_space_read_multi_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
370 bus_size_t offset, TYPE *buf, size_t cnt) \
373 __asm __volatile("call *%3" \
377 :"o" (bsh->bsh_bam.bs_read_multi_##BWN), \
385 _BUS_SPACE_READ_MULTI(u_int8_t,1)
386 _BUS_SPACE_READ_MULTI(u_int16_t,2)
387 _BUS_SPACE_READ_MULTI(u_int32_t,4)
392 #define _BUS_SPACE_WRITE_MULTI(TYPE,BWN) \
393 static __inline void \
394 bus_space_write_multi_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
395 bus_size_t offset, const TYPE *buf, size_t cnt) \
398 __asm __volatile("call *%3" \
402 :"o" (bsh->bsh_bam.bs_write_multi_##BWN), \
410 _BUS_SPACE_WRITE_MULTI(u_int8_t,1)
411 _BUS_SPACE_WRITE_MULTI(u_int16_t,2)
412 _BUS_SPACE_WRITE_MULTI(u_int32_t,4)
417 #define _BUS_SPACE_READ_REGION(TYPE,BWN) \
418 static __inline void \
419 bus_space_read_region_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
420 bus_size_t offset, TYPE *buf, size_t cnt) \
423 __asm __volatile("call *%3" \
427 :"o" (bsh->bsh_bam.bs_read_region_##BWN), \
435 _BUS_SPACE_READ_REGION(u_int8_t,1)
436 _BUS_SPACE_READ_REGION(u_int16_t,2)
437 _BUS_SPACE_READ_REGION(u_int32_t,4)
442 #define _BUS_SPACE_WRITE_REGION(TYPE,BWN) \
443 static __inline void \
444 bus_space_write_region_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
445 bus_size_t offset, const TYPE *buf, size_t cnt) \
448 __asm __volatile("call *%3" \
452 :"o" (bsh->bsh_bam.bs_write_region_##BWN), \
460 _BUS_SPACE_WRITE_REGION(u_int8_t,1)
461 _BUS_SPACE_WRITE_REGION(u_int16_t,2)
462 _BUS_SPACE_WRITE_REGION(u_int32_t,4)
467 #define _BUS_SPACE_SET_MULTI(TYPE,BWN) \
468 static __inline void \
469 bus_space_set_multi_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
470 bus_size_t offset, TYPE val, size_t cnt) \
473 __asm __volatile("call *%2" \
476 :"o" (bsh->bsh_bam.bs_set_multi_##BWN), \
484 _BUS_SPACE_SET_MULTI(u_int8_t,1)
485 _BUS_SPACE_SET_MULTI(u_int16_t,2)
486 _BUS_SPACE_SET_MULTI(u_int32_t,4)
491 #define _BUS_SPACE_SET_REGION(TYPE,BWN) \
492 static __inline void \
493 bus_space_set_region_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
494 bus_size_t offset, TYPE val, size_t cnt) \
497 __asm __volatile("call *%2" \
500 :"o" (bsh->bsh_bam.bs_set_region_##BWN), \
508 _BUS_SPACE_SET_REGION(u_int8_t,1)
509 _BUS_SPACE_SET_REGION(u_int16_t,2)
510 _BUS_SPACE_SET_REGION(u_int32_t,4)
515 #define _BUS_SPACE_COPY_REGION(BWN) \
516 static __inline void \
517 bus_space_copy_region_##BWN (bus_space_tag_t tag, bus_space_handle_t sbsh, \
518 bus_size_t src, bus_space_handle_t dbsh, bus_size_t dst, size_t cnt) \
521 if (dbsh->bsh_bam.bs_copy_region_1 != sbsh->bsh_bam.bs_copy_region_1) \
522 panic("bus_space_copy_region: funcs mismatch (ENOSUPPORT)");\
524 __asm __volatile("call *%3" \
528 :"o" (dbsh->bsh_bam.bs_copy_region_##BWN), \
537 _BUS_SPACE_COPY_REGION(1)
538 _BUS_SPACE_COPY_REGION(2)
539 _BUS_SPACE_COPY_REGION(4)
542 * Bus read/write barrier methods.
544 * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
545 * bus_size_t offset, bus_size_t len, int flags);
548 * Note that BUS_SPACE_BARRIER_WRITE doesn't do anything other than
549 * prevent reordering by the compiler; all Intel x86 processors currently
550 * retire operations outside the CPU in program order.
552 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
553 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
556 bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
557 bus_size_t offset, bus_size_t len, int flags)
559 if (flags & BUS_SPACE_BARRIER_READ)
560 __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory");
565 #ifdef BUS_SPACE_NO_LEGACY
568 #define inb(a) compiler_error
569 #define inw(a) compiler_error
570 #define inl(a) compiler_error
571 #define outb(a, b) compiler_error
572 #define outw(a, b) compiler_error
573 #define outl(a, b) compiler_error
576 #include <machine/bus_dma.h>
579 * Stream accesses are the same as normal accesses on i386/pc98; there are no
580 * supported bus systems with an endianess different from the host one.
582 #define bus_space_read_stream_1(t, h, o) bus_space_read_1((t), (h), (o))
583 #define bus_space_read_stream_2(t, h, o) bus_space_read_2((t), (h), (o))
584 #define bus_space_read_stream_4(t, h, o) bus_space_read_4((t), (h), (o))
586 #define bus_space_read_multi_stream_1(t, h, o, a, c) \
587 bus_space_read_multi_1((t), (h), (o), (a), (c))
588 #define bus_space_read_multi_stream_2(t, h, o, a, c) \
589 bus_space_read_multi_2((t), (h), (o), (a), (c))
590 #define bus_space_read_multi_stream_4(t, h, o, a, c) \
591 bus_space_read_multi_4((t), (h), (o), (a), (c))
593 #define bus_space_write_stream_1(t, h, o, v) \
594 bus_space_write_1((t), (h), (o), (v))
595 #define bus_space_write_stream_2(t, h, o, v) \
596 bus_space_write_2((t), (h), (o), (v))
597 #define bus_space_write_stream_4(t, h, o, v) \
598 bus_space_write_4((t), (h), (o), (v))
600 #define bus_space_write_multi_stream_1(t, h, o, a, c) \
601 bus_space_write_multi_1((t), (h), (o), (a), (c))
602 #define bus_space_write_multi_stream_2(t, h, o, a, c) \
603 bus_space_write_multi_2((t), (h), (o), (a), (c))
604 #define bus_space_write_multi_stream_4(t, h, o, a, c) \
605 bus_space_write_multi_4((t), (h), (o), (a), (c))
607 #define bus_space_set_multi_stream_1(t, h, o, v, c) \
608 bus_space_set_multi_1((t), (h), (o), (v), (c))
609 #define bus_space_set_multi_stream_2(t, h, o, v, c) \
610 bus_space_set_multi_2((t), (h), (o), (v), (c))
611 #define bus_space_set_multi_stream_4(t, h, o, v, c) \
612 bus_space_set_multi_4((t), (h), (o), (v), (c))
614 #define bus_space_read_region_stream_1(t, h, o, a, c) \
615 bus_space_read_region_1((t), (h), (o), (a), (c))
616 #define bus_space_read_region_stream_2(t, h, o, a, c) \
617 bus_space_read_region_2((t), (h), (o), (a), (c))
618 #define bus_space_read_region_stream_4(t, h, o, a, c) \
619 bus_space_read_region_4((t), (h), (o), (a), (c))
621 #define bus_space_write_region_stream_1(t, h, o, a, c) \
622 bus_space_write_region_1((t), (h), (o), (a), (c))
623 #define bus_space_write_region_stream_2(t, h, o, a, c) \
624 bus_space_write_region_2((t), (h), (o), (a), (c))
625 #define bus_space_write_region_stream_4(t, h, o, a, c) \
626 bus_space_write_region_4((t), (h), (o), (a), (c))
628 #define bus_space_set_region_stream_1(t, h, o, v, c) \
629 bus_space_set_region_1((t), (h), (o), (v), (c))
630 #define bus_space_set_region_stream_2(t, h, o, v, c) \
631 bus_space_set_region_2((t), (h), (o), (v), (c))
632 #define bus_space_set_region_stream_4(t, h, o, v, c) \
633 bus_space_set_region_4((t), (h), (o), (v), (c))
635 #define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \
636 bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
637 #define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \
638 bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c))
639 #define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \
640 bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c))
642 #endif /* _PC98_BUS_H_ */