]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/pc98/include/bus.h
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / pc98 / include / bus.h
1 /*-
2  * Copyright (c) KATO Takenori, 1999.
3  *
4  * All rights reserved.  Unpublished rights reserved under the copyright
5  * laws of Japan.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
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.
19  * 
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.
30  *
31  * $FreeBSD$
32  */
33
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 $    */
36
37 /*-
38  * [NetBSD for NEC PC-98 series]
39  *  Copyright (c) 1997, 1998
40  *      NetBSD/pc98 porting staff. All rights reserved.
41  *
42  * [Ported for FreeBSD]
43  *  Copyright (c) 2001
44  *      TAKAHASHI Yoshihiro. All rights reserved.
45  *
46  *  Redistribution and use in source and binary forms, with or without
47  *  modification, are permitted provided that the following conditions
48  *  are met:
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.
56  * 
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.
68  */
69
70 /*
71  * Copyright (c) 1997, 1998
72  *      Naofumi HONDA.  All rights reserved.
73  *
74  * This module support generic bus address relocation mechanism.
75  * To reduce a function call overhead, we employ pascal call methods.
76  */
77
78 #ifndef _PC98_BUS_H_
79 #define _PC98_BUS_H_
80
81 #include <sys/systm.h>
82
83 #include <machine/_bus.h>
84 #include <machine/cpufunc.h>
85
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
92
93 #define BUS_SPACE_UNRESTRICTED  (~0)
94
95 /*
96  * address relocation table
97  */
98 #define BUS_SPACE_IAT_MAXSIZE   33
99 typedef bus_addr_t *bus_space_iat_t;
100
101 #define BUS_SPACE_IAT_SZ(IOTARRAY) (sizeof(IOTARRAY)/sizeof(bus_addr_t))
102
103 /*
104  * Access methods for bus resources and address space.
105  */
106 struct resource;
107
108 /*
109  * bus space tag
110  */
111 #define _PASCAL_CALL    (void)
112
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
123
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;
134
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; 
145
146 struct bus_space_access_methods {
147         /* 8 bits access methods */
148         _BUS_SPACE_CALL_FUNCS(bs,u_int8_t,1)
149
150         /* 16 bits access methods */
151         _BUS_SPACE_CALL_FUNCS(bs,u_int16_t,2)
152
153         /* 32 bits access methods */
154         _BUS_SPACE_CALL_FUNCS(bs,u_int32_t,4)
155 };
156
157 /*
158  * Access methods for bus resources and address space.
159  */
160 struct bus_space_tag {
161 #define BUS_SPACE_IO    0
162 #define BUS_SPACE_MEM   1
163         u_int   bs_tag;                 /* bus space flags */
164
165         struct bus_space_access_methods bs_da;  /* direct access */
166         struct bus_space_access_methods bs_ra;  /* relocate access */
167 #if     0
168         struct bus_space_access_methods bs_ida; /* indexed direct access */
169 #endif
170 };
171
172 /*
173  * bus space handle
174  */
175 struct bus_space_handle {
176         bus_addr_t      bsh_base;
177         size_t          bsh_sz;
178
179         bus_addr_t      bsh_iat[BUS_SPACE_IAT_MAXSIZE];
180         size_t          bsh_maxiatsz;
181         size_t          bsh_iatsz;
182
183         struct resource **bsh_res;
184         size_t          bsh_ressz;
185
186         struct bus_space_access_methods bsh_bam;
187 };
188
189 /*
190  * Values for the pc98 bus space tag, not to be used directly by MI code.
191  */
192 extern struct bus_space_tag SBUS_io_space_tag;
193 extern struct bus_space_tag SBUS_mem_space_tag;
194
195 #define I386_BUS_SPACE_IO       (&SBUS_io_space_tag)
196 #define I386_BUS_SPACE_MEM      (&SBUS_mem_space_tag)
197
198 /*
199  * Allocate/Free bus_space_handle
200  */
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,
204                                 size_t size);
205
206 /*
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);
209  *
210  * Map a region of bus space.
211  */
212
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);
215
216 #define bus_space_map(t, a, s, f, hp)                                   \
217         i386_memio_map((t), (a), (s), (f), (hp))
218
219 /*
220  *      int bus_space_unmap (bus_space_tag_t t,
221  *          bus_space_handle_t bsh, bus_size_t size);
222  *
223  * Unmap a region of bus space.
224  */
225
226 void i386_memio_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
227                        bus_size_t size);
228
229 #define bus_space_unmap(t, h, s)                                        \
230         i386_memio_unmap((t), (h), (s))
231
232 /*
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);
235  *
236  * Load I/O address table of bus space.
237  */
238
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);
241
242 #define bus_space_map_load(t, h, s, iat, f)                             \
243         i386_memio_map_load((t), (h), (s), (iat), (f))
244
245 /*
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);
249  *
250  * Get a new handle for a subregion of an already-mapped area of bus space.
251  */
252
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);
256
257 #define bus_space_subregion(t, h, o, s, nhp)                            \
258         i386_memio_subregion((t), (h), (o), (s), (nhp))
259
260 /*
261  *      int bus_space_free (bus_space_tag_t t,
262  *          bus_space_handle_t bsh, bus_size_t size);
263  *
264  * Free a region of bus space.
265  */
266
267 void i386_memio_free(bus_space_tag_t t, bus_space_handle_t bsh,
268                      bus_size_t size);
269
270 #define bus_space_free(t, h, s)                                         \
271         i386_memio_free((t), (h), (s))
272
273 /*
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);
276  *
277  * Compare two resources.
278  */
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);
281
282 #define bus_space_compare(t1, h1, t2, h2)                               \
283         i386_memio_compare((t1), (h1), (t2), (h2))
284
285 /*
286  * Access methods for bus resources and address space.
287  */
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);
312
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)
316
317 /*
318  * read methods
319  */
320 #define _BUS_SPACE_READ(TYPE,BWN)                               \
321 static __inline TYPE                                            \
322 bus_space_read_##BWN (tag, bsh, offset)                         \
323         bus_space_tag_t tag;                                    \
324         bus_space_handle_t bsh;                                 \
325         bus_size_t offset;                                      \
326 {                                                               \
327         register TYPE result;                                   \
328                                                                 \
329         __asm __volatile("call *%2"                             \
330                         :"=a" (result),                         \
331                          "=d" (offset)                          \
332                         :"o" (bsh->bsh_bam.bs_read_##BWN),      \
333                          "b" (bsh),                             \
334                          "1" (offset)                           \
335                         );                                      \
336                                                                 \
337         return result;                                          \
338 }
339
340 _BUS_SPACE_READ(u_int8_t,1)
341 _BUS_SPACE_READ(u_int16_t,2)
342 _BUS_SPACE_READ(u_int32_t,4)
343
344 /*
345  * write methods
346  */
347 #define _BUS_SPACE_WRITE(TYPE,BWN)                              \
348 static __inline void                                            \
349 bus_space_write_##BWN (tag, bsh, offset, val)                   \
350         bus_space_tag_t tag;                                    \
351         bus_space_handle_t bsh;                                 \
352         bus_size_t offset;                                      \
353         TYPE val;                                               \
354 {                                                               \
355                                                                 \
356         __asm __volatile("call *%1"                             \
357                         :"=d" (offset)                          \
358                         :"o" (bsh->bsh_bam.bs_write_##BWN),     \
359                          "a" (val),                             \
360                          "b" (bsh),                             \
361                          "0" (offset)                           \
362                         );                                      \
363 }                                                               
364
365 _BUS_SPACE_WRITE(u_int8_t,1)
366 _BUS_SPACE_WRITE(u_int16_t,2)
367 _BUS_SPACE_WRITE(u_int32_t,4)
368
369 /*
370  * multi read
371  */
372 #define _BUS_SPACE_READ_MULTI(TYPE,BWN)                                 \
373 static __inline void                                                    \
374 bus_space_read_multi_##BWN (tag, bsh, offset, buf, cnt)                 \
375         bus_space_tag_t tag;                                            \
376         bus_space_handle_t bsh;                                         \
377         bus_size_t offset;                                              \
378         TYPE *buf;                                                      \
379         size_t cnt;                                                     \
380 {                                                                       \
381                                                                         \
382         __asm __volatile("call *%3"                                     \
383                         :"=c" (cnt),                                    \
384                          "=d" (offset),                                 \
385                          "=D" (buf)                                     \
386                         :"o" (bsh->bsh_bam.bs_read_multi_##BWN),        \
387                          "b" (bsh),                                     \
388                          "0" (cnt),                                     \
389                          "1" (offset),                                  \
390                          "2" (buf)                                      \
391                         :"memory");                                     \
392 }
393
394 _BUS_SPACE_READ_MULTI(u_int8_t,1)
395 _BUS_SPACE_READ_MULTI(u_int16_t,2)
396 _BUS_SPACE_READ_MULTI(u_int32_t,4)
397
398 /*
399  * multi write
400  */
401 #define _BUS_SPACE_WRITE_MULTI(TYPE,BWN)                                \
402 static __inline void                                                    \
403 bus_space_write_multi_##BWN (tag, bsh, offset, buf, cnt)                \
404         bus_space_tag_t tag;                                            \
405         bus_space_handle_t bsh;                                         \
406         bus_size_t offset;                                              \
407         const TYPE *buf;                                                \
408         size_t cnt;                                                     \
409 {                                                                       \
410                                                                         \
411         __asm __volatile("call *%3"                                     \
412                         :"=c" (cnt),                                    \
413                          "=d" (offset),                                 \
414                          "=S" (buf)                                     \
415                         :"o" (bsh->bsh_bam.bs_write_multi_##BWN),       \
416                          "b" (bsh),                                     \
417                          "0" (cnt),                                     \
418                          "1" (offset),                                  \
419                          "2" (buf)                                      \
420                         );                                              \
421 }
422
423 _BUS_SPACE_WRITE_MULTI(u_int8_t,1)
424 _BUS_SPACE_WRITE_MULTI(u_int16_t,2)
425 _BUS_SPACE_WRITE_MULTI(u_int32_t,4)
426
427 /*
428  * region read
429  */
430 #define _BUS_SPACE_READ_REGION(TYPE,BWN)                                \
431 static __inline void                                                    \
432 bus_space_read_region_##BWN (tag, bsh, offset, buf, cnt)                \
433         bus_space_tag_t tag;                                            \
434         bus_space_handle_t bsh;                                         \
435         bus_size_t offset;                                              \
436         TYPE *buf;                                              \
437         size_t cnt;                                                     \
438 {                                                                       \
439                                                                         \
440         __asm __volatile("call *%3"                                     \
441                         :"=c" (cnt),                                    \
442                          "=d" (offset),                                 \
443                          "=D" (buf)                                     \
444                         :"o" (bsh->bsh_bam.bs_read_region_##BWN),       \
445                          "b" (bsh),                                     \
446                          "0" (cnt),                                     \
447                          "1" (offset),                                  \
448                          "2" (buf)                                      \
449                         :"memory");                                     \
450 }
451
452 _BUS_SPACE_READ_REGION(u_int8_t,1)
453 _BUS_SPACE_READ_REGION(u_int16_t,2)
454 _BUS_SPACE_READ_REGION(u_int32_t,4)
455
456 /*
457  * region write
458  */
459 #define _BUS_SPACE_WRITE_REGION(TYPE,BWN)                               \
460 static __inline void                                                    \
461 bus_space_write_region_##BWN (tag, bsh, offset, buf, cnt)               \
462         bus_space_tag_t tag;                                            \
463         bus_space_handle_t bsh;                                         \
464         bus_size_t offset;                                              \
465         const TYPE *buf;                                                \
466         size_t cnt;                                                     \
467 {                                                                       \
468                                                                         \
469         __asm __volatile("call *%3"                                     \
470                         :"=c" (cnt),                                    \
471                          "=d" (offset),                                 \
472                          "=S" (buf)                                     \
473                         :"o" (bsh->bsh_bam.bs_write_region_##BWN),      \
474                          "b" (bsh),                                     \
475                          "0" (cnt),                                     \
476                          "1" (offset),                                  \
477                          "2" (buf)                                      \
478                         );                                              \
479 }
480
481 _BUS_SPACE_WRITE_REGION(u_int8_t,1)
482 _BUS_SPACE_WRITE_REGION(u_int16_t,2)
483 _BUS_SPACE_WRITE_REGION(u_int32_t,4)
484
485 /*
486  * multi set
487  */
488 #define _BUS_SPACE_SET_MULTI(TYPE,BWN)                                  \
489 static __inline void                                                    \
490 bus_space_set_multi_##BWN (tag, bsh, offset, val, cnt)                  \
491         bus_space_tag_t tag;                                            \
492         bus_space_handle_t bsh;                                         \
493         bus_size_t offset;                                              \
494         TYPE val;                                                       \
495         size_t cnt;                                                     \
496 {                                                                       \
497                                                                         \
498         __asm __volatile("call *%2"                                     \
499                         :"=c" (cnt),                                    \
500                          "=d" (offset)                                  \
501                         :"o" (bsh->bsh_bam.bs_set_multi_##BWN),         \
502                          "a" (val),                                     \
503                          "b" (bsh),                                     \
504                          "0" (cnt),                                     \
505                          "1" (offset)                                   \
506                         );                                              \
507 }
508
509 _BUS_SPACE_SET_MULTI(u_int8_t,1)
510 _BUS_SPACE_SET_MULTI(u_int16_t,2)
511 _BUS_SPACE_SET_MULTI(u_int32_t,4)
512
513 /*
514  * region set
515  */
516 #define _BUS_SPACE_SET_REGION(TYPE,BWN)                                 \
517 static __inline void                                                    \
518 bus_space_set_region_##BWN (tag, bsh, offset, val, cnt)                 \
519         bus_space_tag_t tag;                                            \
520         bus_space_handle_t bsh;                                         \
521         bus_size_t offset;                                              \
522         TYPE val;                                                       \
523         size_t cnt;                                                     \
524 {                                                                       \
525                                                                         \
526         __asm __volatile("call *%2"                                     \
527                         :"=c" (cnt),                                    \
528                          "=d" (offset)                                  \
529                         :"o" (bsh->bsh_bam.bs_set_region_##BWN),        \
530                          "a" (val),                                     \
531                          "b" (bsh),                                     \
532                          "0" (cnt),                                     \
533                          "1" (offset)                                   \
534                         );                                              \
535 }
536
537 _BUS_SPACE_SET_REGION(u_int8_t,1)
538 _BUS_SPACE_SET_REGION(u_int16_t,2)
539 _BUS_SPACE_SET_REGION(u_int32_t,4)
540
541 /*
542  * copy
543  */
544 #define _BUS_SPACE_COPY_REGION(BWN)                                     \
545 static __inline void                                                    \
546 bus_space_copy_region_##BWN (tag, sbsh, src, dbsh, dst, cnt)            \
547         bus_space_tag_t tag;                                            \
548         bus_space_handle_t sbsh;                                        \
549         bus_size_t src;                                                 \
550         bus_space_handle_t dbsh;                                        \
551         bus_size_t dst;                                                 \
552         size_t cnt;                                                     \
553 {                                                                       \
554                                                                         \
555         if (dbsh->bsh_bam.bs_copy_region_1 != sbsh->bsh_bam.bs_copy_region_1) \
556                 panic("bus_space_copy_region: funcs mismatch (ENOSUPPORT)");\
557                                                                         \
558         __asm __volatile("call *%3"                                     \
559                         :"=c" (cnt),                                    \
560                          "=S" (src),                                    \
561                          "=D" (dst)                                     \
562                         :"o" (dbsh->bsh_bam.bs_copy_region_##BWN),      \
563                          "a" (sbsh),                                    \
564                          "b" (dbsh),                                    \
565                          "0" (cnt),                                     \
566                          "1" (src),                                     \
567                          "2" (dst)                                      \
568                         );                                              \
569 }
570
571 _BUS_SPACE_COPY_REGION(1)
572 _BUS_SPACE_COPY_REGION(2)
573 _BUS_SPACE_COPY_REGION(4)
574
575 /*
576  * Bus read/write barrier methods.
577  *
578  *      void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
579  *                             bus_size_t offset, bus_size_t len, int flags);
580  *
581  *
582  * Note that BUS_SPACE_BARRIER_WRITE doesn't do anything other than
583  * prevent reordering by the compiler; all Intel x86 processors currently
584  * retire operations outside the CPU in program order.
585  */
586 #define BUS_SPACE_BARRIER_READ  0x01            /* force read barrier */
587 #define BUS_SPACE_BARRIER_WRITE 0x02            /* force write barrier */
588
589 static __inline void
590 bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
591                   bus_size_t offset, bus_size_t len, int flags)
592 {
593         if (flags & BUS_SPACE_BARRIER_READ)
594                 __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory");
595         else
596                 __asm __volatile("" : : : "memory");
597 }
598
599 #ifdef BUS_SPACE_NO_LEGACY
600 #undef inb
601 #undef outb
602 #define inb(a) compiler_error
603 #define inw(a) compiler_error
604 #define inl(a) compiler_error
605 #define outb(a, b) compiler_error
606 #define outw(a, b) compiler_error
607 #define outl(a, b) compiler_error
608 #endif
609
610 #include <machine/bus_dma.h>
611
612 /*
613  * Stream accesses are the same as normal accesses on i386/pc98; there are no
614  * supported bus systems with an endianess different from the host one.
615  */
616 #define bus_space_read_stream_1(t, h, o)        bus_space_read_1((t), (h), (o))
617 #define bus_space_read_stream_2(t, h, o)        bus_space_read_2((t), (h), (o))
618 #define bus_space_read_stream_4(t, h, o)        bus_space_read_4((t), (h), (o))
619
620 #define bus_space_read_multi_stream_1(t, h, o, a, c) \
621         bus_space_read_multi_1((t), (h), (o), (a), (c))
622 #define bus_space_read_multi_stream_2(t, h, o, a, c) \
623         bus_space_read_multi_2((t), (h), (o), (a), (c))
624 #define bus_space_read_multi_stream_4(t, h, o, a, c) \
625         bus_space_read_multi_4((t), (h), (o), (a), (c))
626
627 #define bus_space_write_stream_1(t, h, o, v) \
628         bus_space_write_1((t), (h), (o), (v))
629 #define bus_space_write_stream_2(t, h, o, v) \
630         bus_space_write_2((t), (h), (o), (v))
631 #define bus_space_write_stream_4(t, h, o, v) \
632         bus_space_write_4((t), (h), (o), (v))
633
634 #define bus_space_write_multi_stream_1(t, h, o, a, c) \
635         bus_space_write_multi_1((t), (h), (o), (a), (c))
636 #define bus_space_write_multi_stream_2(t, h, o, a, c) \
637         bus_space_write_multi_2((t), (h), (o), (a), (c))
638 #define bus_space_write_multi_stream_4(t, h, o, a, c) \
639         bus_space_write_multi_4((t), (h), (o), (a), (c))
640
641 #define bus_space_set_multi_stream_1(t, h, o, v, c) \
642         bus_space_set_multi_1((t), (h), (o), (v), (c))
643 #define bus_space_set_multi_stream_2(t, h, o, v, c) \
644         bus_space_set_multi_2((t), (h), (o), (v), (c))
645 #define bus_space_set_multi_stream_4(t, h, o, v, c) \
646         bus_space_set_multi_4((t), (h), (o), (v), (c))
647
648 #define bus_space_read_region_stream_1(t, h, o, a, c) \
649         bus_space_read_region_1((t), (h), (o), (a), (c))
650 #define bus_space_read_region_stream_2(t, h, o, a, c) \
651         bus_space_read_region_2((t), (h), (o), (a), (c))
652 #define bus_space_read_region_stream_4(t, h, o, a, c) \
653         bus_space_read_region_4((t), (h), (o), (a), (c))
654
655 #define bus_space_write_region_stream_1(t, h, o, a, c) \
656         bus_space_write_region_1((t), (h), (o), (a), (c))
657 #define bus_space_write_region_stream_2(t, h, o, a, c) \
658         bus_space_write_region_2((t), (h), (o), (a), (c))
659 #define bus_space_write_region_stream_4(t, h, o, a, c) \
660         bus_space_write_region_4((t), (h), (o), (a), (c))
661
662 #define bus_space_set_region_stream_1(t, h, o, v, c) \
663         bus_space_set_region_1((t), (h), (o), (v), (c))
664 #define bus_space_set_region_stream_2(t, h, o, v, c) \
665         bus_space_set_region_2((t), (h), (o), (v), (c))
666 #define bus_space_set_region_stream_4(t, h, o, v, c) \
667         bus_space_set_region_4((t), (h), (o), (v), (c))
668
669 #define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \
670         bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
671 #define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \
672         bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c))
673 #define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \
674         bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c))
675
676 #endif /* _PC98_BUS_H_ */