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.
82 #include <sys/systm.h>
85 #include <machine/_bus.h>
86 #include <machine/cpufunc.h>
88 #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF
89 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
90 #define BUS_SPACE_MAXSIZE 0xFFFFFFFF
91 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF
92 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
93 #define BUS_SPACE_MAXADDR 0xFFFFFFFF
95 #define BUS_SPACE_UNRESTRICTED (~0)
100 * address relocation table
102 #define BUS_SPACE_IAT_MAXSIZE 33
103 typedef bus_addr_t *bus_space_iat_t;
105 #define BUS_SPACE_IAT_SZ(IOTARRAY) (sizeof(IOTARRAY)/sizeof(bus_addr_t))
108 * Access methods for bus resources and address space.
115 #define _PASCAL_CALL (void)
117 #define _BUS_SPACE_CALL_FUNCS_TAB(NAME,TYPE,BWN) \
118 NAME##_space_read_##BWN, \
119 NAME##_space_read_multi_##BWN, \
120 NAME##_space_read_region_##BWN, \
121 NAME##_space_write_##BWN, \
122 NAME##_space_write_multi_##BWN, \
123 NAME##_space_write_region_##BWN, \
124 NAME##_space_set_multi_##BWN, \
125 NAME##_space_set_region_##BWN, \
126 NAME##_space_copy_region_##BWN
128 #define _BUS_SPACE_CALL_FUNCS_PROTO(NAME,TYPE,BWN) \
129 TYPE NAME##_space_read_##BWN _PASCAL_CALL; \
130 void NAME##_space_read_multi_##BWN _PASCAL_CALL; \
131 void NAME##_space_read_region_##BWN _PASCAL_CALL; \
132 void NAME##_space_write_##BWN _PASCAL_CALL; \
133 void NAME##_space_write_multi_##BWN _PASCAL_CALL; \
134 void NAME##_space_write_region_##BWN _PASCAL_CALL; \
135 void NAME##_space_set_multi_##BWN _PASCAL_CALL; \
136 void NAME##_space_set_region_##BWN _PASCAL_CALL; \
137 void NAME##_space_copy_region_##BWN _PASCAL_CALL;
139 #define _BUS_SPACE_CALL_FUNCS(NAME,TYPE,BWN) \
140 TYPE (* NAME##_read_##BWN) _PASCAL_CALL; \
141 void (* NAME##_read_multi_##BWN) _PASCAL_CALL; \
142 void (* NAME##_read_region_##BWN) _PASCAL_CALL; \
143 void (* NAME##_write_##BWN) _PASCAL_CALL; \
144 void (* NAME##_write_multi_##BWN) _PASCAL_CALL; \
145 void (* NAME##_write_region_##BWN) _PASCAL_CALL; \
146 void (* NAME##_set_multi_##BWN) _PASCAL_CALL; \
147 void (* NAME##_set_region_##BWN) _PASCAL_CALL; \
148 void (* NAME##_copy_region_##BWN) _PASCAL_CALL;
150 struct bus_space_access_methods {
151 /* 8 bits access methods */
152 _BUS_SPACE_CALL_FUNCS(bs,u_int8_t,1)
154 /* 16 bits access methods */
155 _BUS_SPACE_CALL_FUNCS(bs,u_int16_t,2)
157 /* 32 bits access methods */
158 _BUS_SPACE_CALL_FUNCS(bs,u_int32_t,4)
162 * Access methods for bus resources and address space.
164 struct bus_space_tag {
165 #define BUS_SPACE_TAG_IO 0
166 #define BUS_SPACE_TAG_MEM 1
167 u_int bs_tag; /* bus space flags */
169 struct bus_space_access_methods bs_da; /* direct access */
170 struct bus_space_access_methods bs_ra; /* relocate access */
172 struct bus_space_access_methods bs_ida; /* indexed direct access */
179 struct bus_space_handle {
183 bus_addr_t bsh_iat[BUS_SPACE_IAT_MAXSIZE];
187 struct resource **bsh_res;
190 struct bus_space_access_methods bsh_bam;
194 * Values for the pc98 bus space tag, not to be used directly by MI code.
196 extern struct bus_space_tag SBUS_io_space_tag;
197 extern struct bus_space_tag SBUS_mem_space_tag;
199 #define X86_BUS_SPACE_IO (&SBUS_io_space_tag)
200 #define X86_BUS_SPACE_MEM (&SBUS_mem_space_tag)
203 * Allocate/Free bus_space_handle
205 int i386_bus_space_handle_alloc(bus_space_tag_t t, bus_addr_t bpa,
206 bus_size_t size, bus_space_handle_t *bshp);
207 void i386_bus_space_handle_free(bus_space_tag_t t, bus_space_handle_t bsh,
211 * int bus_space_map (bus_space_tag_t t, bus_addr_t addr,
212 * bus_size_t size, int flag, bus_space_handle_t *bshp);
214 * Map a region of bus space.
217 int i386_memio_map(bus_space_tag_t t, bus_addr_t addr, bus_size_t size,
218 int flag, bus_space_handle_t *bshp);
220 #define bus_space_map(t, a, s, f, hp) \
221 i386_memio_map((t), (a), (s), (f), (hp))
224 * int bus_space_unmap (bus_space_tag_t t,
225 * bus_space_handle_t bsh, bus_size_t size);
227 * Unmap a region of bus space.
230 void i386_memio_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
233 #define bus_space_unmap(t, h, s) \
234 i386_memio_unmap((t), (h), (s))
237 * int bus_space_map_load (bus_space_tag_t t, bus_space_handle_t bsh,
238 * bus_size_t size, bus_space_iat_t iat, u_int flags);
240 * Load I/O address table of bus space.
243 int i386_memio_map_load(bus_space_tag_t t, bus_space_handle_t bsh,
244 bus_size_t size, bus_space_iat_t iat, u_int flags);
246 #define bus_space_map_load(t, h, s, iat, f) \
247 i386_memio_map_load((t), (h), (s), (iat), (f))
250 * int bus_space_subregion (bus_space_tag_t t,
251 * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
252 * bus_space_handle_t *nbshp);
254 * Get a new handle for a subregion of an already-mapped area of bus space.
257 int i386_memio_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
258 bus_size_t offset, bus_size_t size,
259 bus_space_handle_t *nbshp);
261 #define bus_space_subregion(t, h, o, s, nhp) \
262 i386_memio_subregion((t), (h), (o), (s), (nhp))
265 * int bus_space_free (bus_space_tag_t t,
266 * bus_space_handle_t bsh, bus_size_t size);
268 * Free a region of bus space.
271 void i386_memio_free(bus_space_tag_t t, bus_space_handle_t bsh,
274 #define bus_space_free(t, h, s) \
275 i386_memio_free((t), (h), (s))
278 * int bus_space_compare (bus_space_tag_t t1, bus_space_handle_t bsh1,
279 * bus_space_tag_t t2, bus_space_handle_t bsh2);
281 * Compare two resources.
283 int i386_memio_compare(bus_space_tag_t t1, bus_space_handle_t bsh1,
284 bus_space_tag_t t2, bus_space_handle_t bsh2);
286 #define bus_space_compare(t1, h1, t2, h2) \
287 i386_memio_compare((t1), (h1), (t2), (h2))
290 * Access methods for bus resources and address space.
292 #define _BUS_ACCESS_METHODS_PROTO(TYPE,BWN) \
293 static __inline TYPE bus_space_read_##BWN \
294 (bus_space_tag_t, bus_space_handle_t, bus_size_t offset); \
295 static __inline void bus_space_read_multi_##BWN \
296 (bus_space_tag_t, bus_space_handle_t, \
297 bus_size_t, TYPE *, size_t); \
298 static __inline void bus_space_read_region_##BWN \
299 (bus_space_tag_t, bus_space_handle_t, \
300 bus_size_t, TYPE *, size_t); \
301 static __inline void bus_space_write_##BWN \
302 (bus_space_tag_t, bus_space_handle_t, bus_size_t, TYPE); \
303 static __inline void bus_space_write_multi_##BWN \
304 (bus_space_tag_t, bus_space_handle_t, \
305 bus_size_t, const TYPE *, size_t); \
306 static __inline void bus_space_write_region_##BWN \
307 (bus_space_tag_t, bus_space_handle_t, \
308 bus_size_t, const TYPE *, size_t); \
309 static __inline void bus_space_set_multi_##BWN \
310 (bus_space_tag_t, bus_space_handle_t, bus_size_t, TYPE, size_t);\
311 static __inline void bus_space_set_region_##BWN \
312 (bus_space_tag_t, bus_space_handle_t, bus_size_t, TYPE, size_t);\
313 static __inline void bus_space_copy_region_##BWN \
314 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
315 bus_space_handle_t, bus_size_t, size_t);
317 _BUS_ACCESS_METHODS_PROTO(u_int8_t,1)
318 _BUS_ACCESS_METHODS_PROTO(u_int16_t,2)
319 _BUS_ACCESS_METHODS_PROTO(u_int32_t,4)
324 #define _BUS_SPACE_READ(TYPE,BWN) \
325 static __inline TYPE \
326 bus_space_read_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
329 register TYPE result; \
331 __asm __volatile("call *%2" \
334 :"o" (bsh->bsh_bam.bs_read_##BWN), \
342 _BUS_SPACE_READ(u_int8_t,1)
343 _BUS_SPACE_READ(u_int16_t,2)
344 _BUS_SPACE_READ(u_int32_t,4)
349 #define _BUS_SPACE_WRITE(TYPE,BWN) \
350 static __inline void \
351 bus_space_write_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
352 bus_size_t offset, TYPE val) \
355 __asm __volatile("call *%1" \
357 :"o" (bsh->bsh_bam.bs_write_##BWN), \
364 _BUS_SPACE_WRITE(u_int8_t,1)
365 _BUS_SPACE_WRITE(u_int16_t,2)
366 _BUS_SPACE_WRITE(u_int32_t,4)
371 #define _BUS_SPACE_READ_MULTI(TYPE,BWN) \
372 static __inline void \
373 bus_space_read_multi_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
374 bus_size_t offset, TYPE *buf, size_t cnt) \
377 __asm __volatile("call *%3" \
381 :"o" (bsh->bsh_bam.bs_read_multi_##BWN), \
389 _BUS_SPACE_READ_MULTI(u_int8_t,1)
390 _BUS_SPACE_READ_MULTI(u_int16_t,2)
391 _BUS_SPACE_READ_MULTI(u_int32_t,4)
396 #define _BUS_SPACE_WRITE_MULTI(TYPE,BWN) \
397 static __inline void \
398 bus_space_write_multi_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
399 bus_size_t offset, const TYPE *buf, size_t cnt) \
402 __asm __volatile("call *%3" \
406 :"o" (bsh->bsh_bam.bs_write_multi_##BWN), \
414 _BUS_SPACE_WRITE_MULTI(u_int8_t,1)
415 _BUS_SPACE_WRITE_MULTI(u_int16_t,2)
416 _BUS_SPACE_WRITE_MULTI(u_int32_t,4)
421 #define _BUS_SPACE_READ_REGION(TYPE,BWN) \
422 static __inline void \
423 bus_space_read_region_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
424 bus_size_t offset, TYPE *buf, size_t cnt) \
427 __asm __volatile("call *%3" \
431 :"o" (bsh->bsh_bam.bs_read_region_##BWN), \
439 _BUS_SPACE_READ_REGION(u_int8_t,1)
440 _BUS_SPACE_READ_REGION(u_int16_t,2)
441 _BUS_SPACE_READ_REGION(u_int32_t,4)
446 #define _BUS_SPACE_WRITE_REGION(TYPE,BWN) \
447 static __inline void \
448 bus_space_write_region_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
449 bus_size_t offset, const TYPE *buf, size_t cnt) \
452 __asm __volatile("call *%3" \
456 :"o" (bsh->bsh_bam.bs_write_region_##BWN), \
464 _BUS_SPACE_WRITE_REGION(u_int8_t,1)
465 _BUS_SPACE_WRITE_REGION(u_int16_t,2)
466 _BUS_SPACE_WRITE_REGION(u_int32_t,4)
471 #define _BUS_SPACE_SET_MULTI(TYPE,BWN) \
472 static __inline void \
473 bus_space_set_multi_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
474 bus_size_t offset, TYPE val, size_t cnt) \
477 __asm __volatile("call *%2" \
480 :"o" (bsh->bsh_bam.bs_set_multi_##BWN), \
488 _BUS_SPACE_SET_MULTI(u_int8_t,1)
489 _BUS_SPACE_SET_MULTI(u_int16_t,2)
490 _BUS_SPACE_SET_MULTI(u_int32_t,4)
495 #define _BUS_SPACE_SET_REGION(TYPE,BWN) \
496 static __inline void \
497 bus_space_set_region_##BWN (bus_space_tag_t tag, bus_space_handle_t bsh, \
498 bus_size_t offset, TYPE val, size_t cnt) \
501 __asm __volatile("call *%2" \
504 :"o" (bsh->bsh_bam.bs_set_region_##BWN), \
512 _BUS_SPACE_SET_REGION(u_int8_t,1)
513 _BUS_SPACE_SET_REGION(u_int16_t,2)
514 _BUS_SPACE_SET_REGION(u_int32_t,4)
519 #define _BUS_SPACE_COPY_REGION(BWN) \
520 static __inline void \
521 bus_space_copy_region_##BWN (bus_space_tag_t tag, bus_space_handle_t sbsh, \
522 bus_size_t src, bus_space_handle_t dbsh, bus_size_t dst, size_t cnt) \
525 if (dbsh->bsh_bam.bs_copy_region_1 != sbsh->bsh_bam.bs_copy_region_1) \
526 panic("bus_space_copy_region: funcs mismatch (ENOSUPPORT)");\
528 __asm __volatile("call *%3" \
532 :"o" (dbsh->bsh_bam.bs_copy_region_##BWN), \
541 _BUS_SPACE_COPY_REGION(1)
542 _BUS_SPACE_COPY_REGION(2)
543 _BUS_SPACE_COPY_REGION(4)
546 * Bus read/write barrier methods.
548 * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
549 * bus_size_t offset, bus_size_t len, int flags);
552 * Note that BUS_SPACE_BARRIER_WRITE doesn't do anything other than
553 * prevent reordering by the compiler; all Intel x86 processors currently
554 * retire operations outside the CPU in program order.
556 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
557 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
560 bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
561 bus_size_t offset, bus_size_t len, int flags)
563 if (flags & BUS_SPACE_BARRIER_READ)
564 __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory");
569 #ifdef BUS_SPACE_NO_LEGACY
572 #define inb(a) compiler_error
573 #define inw(a) compiler_error
574 #define inl(a) compiler_error
575 #define outb(a, b) compiler_error
576 #define outw(a, b) compiler_error
577 #define outl(a, b) compiler_error
580 #include <machine/bus_dma.h>
583 * Stream accesses are the same as normal accesses on i386/pc98; there are no
584 * supported bus systems with an endianess different from the host one.
586 #define bus_space_read_stream_1(t, h, o) bus_space_read_1((t), (h), (o))
587 #define bus_space_read_stream_2(t, h, o) bus_space_read_2((t), (h), (o))
588 #define bus_space_read_stream_4(t, h, o) bus_space_read_4((t), (h), (o))
590 #define bus_space_read_multi_stream_1(t, h, o, a, c) \
591 bus_space_read_multi_1((t), (h), (o), (a), (c))
592 #define bus_space_read_multi_stream_2(t, h, o, a, c) \
593 bus_space_read_multi_2((t), (h), (o), (a), (c))
594 #define bus_space_read_multi_stream_4(t, h, o, a, c) \
595 bus_space_read_multi_4((t), (h), (o), (a), (c))
597 #define bus_space_write_stream_1(t, h, o, v) \
598 bus_space_write_1((t), (h), (o), (v))
599 #define bus_space_write_stream_2(t, h, o, v) \
600 bus_space_write_2((t), (h), (o), (v))
601 #define bus_space_write_stream_4(t, h, o, v) \
602 bus_space_write_4((t), (h), (o), (v))
604 #define bus_space_write_multi_stream_1(t, h, o, a, c) \
605 bus_space_write_multi_1((t), (h), (o), (a), (c))
606 #define bus_space_write_multi_stream_2(t, h, o, a, c) \
607 bus_space_write_multi_2((t), (h), (o), (a), (c))
608 #define bus_space_write_multi_stream_4(t, h, o, a, c) \
609 bus_space_write_multi_4((t), (h), (o), (a), (c))
611 #define bus_space_set_multi_stream_1(t, h, o, v, c) \
612 bus_space_set_multi_1((t), (h), (o), (v), (c))
613 #define bus_space_set_multi_stream_2(t, h, o, v, c) \
614 bus_space_set_multi_2((t), (h), (o), (v), (c))
615 #define bus_space_set_multi_stream_4(t, h, o, v, c) \
616 bus_space_set_multi_4((t), (h), (o), (v), (c))
618 #define bus_space_read_region_stream_1(t, h, o, a, c) \
619 bus_space_read_region_1((t), (h), (o), (a), (c))
620 #define bus_space_read_region_stream_2(t, h, o, a, c) \
621 bus_space_read_region_2((t), (h), (o), (a), (c))
622 #define bus_space_read_region_stream_4(t, h, o, a, c) \
623 bus_space_read_region_4((t), (h), (o), (a), (c))
625 #define bus_space_write_region_stream_1(t, h, o, a, c) \
626 bus_space_write_region_1((t), (h), (o), (a), (c))
627 #define bus_space_write_region_stream_2(t, h, o, a, c) \
628 bus_space_write_region_2((t), (h), (o), (a), (c))
629 #define bus_space_write_region_stream_4(t, h, o, a, c) \
630 bus_space_write_region_4((t), (h), (o), (a), (c))
632 #define bus_space_set_region_stream_1(t, h, o, v, c) \
633 bus_space_set_region_1((t), (h), (o), (v), (c))
634 #define bus_space_set_region_stream_2(t, h, o, v, c) \
635 bus_space_set_region_2((t), (h), (o), (v), (c))
636 #define bus_space_set_region_stream_4(t, h, o, v, c) \
637 bus_space_set_region_4((t), (h), (o), (v), (c))
639 #define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \
640 bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
641 #define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \
642 bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c))
643 #define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \
644 bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c))
648 #endif /* _PC98_BUS_H_ */