1 /* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */
4 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
41 * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
42 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed by Christopher G. Demetriou
55 * for the NetBSD Project.
56 * 4. The name of the author may not be used to endorse or promote products
57 * derived from this software without specific prior written permission
59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
60 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
61 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
63 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
64 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
65 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
66 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
68 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
70 /* $FreeBSD: src/sys/i386/include/bus_at386.h,v 1.8.2.3 2002/03/03 05:42:50 nyan Exp $ */
72 #ifndef _I386_BUS_AT386_H_
73 #define _I386_BUS_AT386_H_
75 #include <machine/cpufunc.h>
78 * To remain compatible with NetBSD's interface, default to both memio and
79 * pio when neither of them is defined.
81 #if !defined(_I386_BUS_PIO_H_) && !defined(_I386_BUS_MEMIO_H_)
82 #define _I386_BUS_PIO_H_
83 #define _I386_BUS_MEMIO_H_
87 * Values for the i386 bus space tag, not to be used directly by MI code.
89 #define I386_BUS_SPACE_IO 0 /* space is i/o space */
90 #define I386_BUS_SPACE_MEM 1 /* space is mem space */
93 * Bus address and size types
95 typedef u_int bus_addr_t;
96 typedef u_int bus_size_t;
98 #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF
99 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
100 #define BUS_SPACE_MAXSIZE (64 * 1024) /* Maximum supported size */
101 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF
102 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
103 #define BUS_SPACE_MAXADDR 0xFFFFFFFF
105 #define BUS_SPACE_UNRESTRICTED (~0)
108 * Access methods for bus resources and address space.
110 typedef int bus_space_tag_t;
111 typedef u_int bus_space_handle_t;
114 * Map a region of device bus space into CPU virtual address space.
117 #define BUS_SPACE_MAP_CACHEABLE 0x01
118 #define BUS_SPACE_MAP_LINEAR 0x02
120 int bus_space_map(bus_space_tag_t t, bus_addr_t addr, bus_size_t size,
121 int flags, bus_space_handle_t *bshp);
124 * Unmap a region of device bus space.
127 static __inline void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
131 bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size)
136 * Get a new handle for a subregion of an already-mapped area of bus space.
139 static __inline int bus_space_subregion(bus_space_tag_t t,
140 bus_space_handle_t bsh,
141 bus_size_t offset, bus_size_t size,
142 bus_space_handle_t *nbshp);
145 bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
146 bus_size_t offset, bus_size_t size,
147 bus_space_handle_t *nbshp)
150 *nbshp = bsh + offset;
155 * Allocate a region of memory that is accessible to devices in bus space.
158 int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
159 bus_addr_t rend, bus_size_t size, bus_size_t align,
160 bus_size_t boundary, int flags, bus_addr_t *addrp,
161 bus_space_handle_t *bshp);
164 * Free a region of bus space accessible memory.
167 static __inline void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
171 bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size)
176 #if defined(_I386_BUS_PIO_H_) || defined(_I386_BUS_MEMIO_H_)
179 * Read a 1, 2, 4, or 8 byte quantity from bus space
180 * described by tag/handle/offset.
182 static __inline u_int8_t bus_space_read_1(bus_space_tag_t tag,
183 bus_space_handle_t handle,
186 static __inline u_int16_t bus_space_read_2(bus_space_tag_t tag,
187 bus_space_handle_t handle,
190 static __inline u_int32_t bus_space_read_4(bus_space_tag_t tag,
191 bus_space_handle_t handle,
194 static __inline u_int8_t
195 bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle,
198 #if defined (_I386_BUS_PIO_H_)
199 #if defined (_I386_BUS_MEMIO_H_)
200 if (tag == I386_BUS_SPACE_IO)
202 return (inb(handle + offset));
204 #if defined (_I386_BUS_MEMIO_H_)
205 return (*(volatile u_int8_t *)(handle + offset));
209 static __inline u_int16_t
210 bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle,
213 #if defined(_I386_BUS_PIO_H_)
214 #if defined(_I386_BUS_MEMIO_H_)
215 if (tag == I386_BUS_SPACE_IO)
217 return (inw(handle + offset));
219 #if defined(_I386_BUS_MEMIO_H_)
220 return (*(volatile u_int16_t *)(handle + offset));
224 static __inline u_int32_t
225 bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle,
228 #if defined(_I386_BUS_PIO_H_)
229 #if defined(_I386_BUS_MEMIO_H_)
230 if (tag == I386_BUS_SPACE_IO)
232 return (inl(handle + offset));
234 #if defined(_I386_BUS_MEMIO_H_)
235 return (*(volatile u_int32_t *)(handle + offset));
239 #if 0 /* Cause a link error for bus_space_read_8 */
240 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
244 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
245 * described by tag/handle/offset and copy into buffer provided.
247 static __inline void bus_space_read_multi_1(bus_space_tag_t tag,
248 bus_space_handle_t bsh,
249 bus_size_t offset, u_int8_t *addr,
252 static __inline void bus_space_read_multi_2(bus_space_tag_t tag,
253 bus_space_handle_t bsh,
254 bus_size_t offset, u_int16_t *addr,
257 static __inline void bus_space_read_multi_4(bus_space_tag_t tag,
258 bus_space_handle_t bsh,
259 bus_size_t offset, u_int32_t *addr,
263 bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
264 bus_size_t offset, u_int8_t *addr, size_t count)
266 #if defined(_I386_BUS_PIO_H_)
267 #if defined(_I386_BUS_MEMIO_H_)
268 if (tag == I386_BUS_SPACE_IO)
270 insb(bsh + offset, addr, count);
272 #if defined(_I386_BUS_MEMIO_H_)
273 #if defined(_I386_BUS_PIO_H_)
277 __asm __volatile(" \n\
279 1: movb (%2),%%al \n\
282 "=D" (addr), "=c" (count) :
283 "r" (bsh + offset), "0" (addr), "1" (count) :
290 bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
291 bus_size_t offset, u_int16_t *addr, size_t count)
293 #if defined(_I386_BUS_PIO_H_)
294 #if defined(_I386_BUS_MEMIO_H_)
295 if (tag == I386_BUS_SPACE_IO)
297 insw(bsh + offset, addr, count);
299 #if defined(_I386_BUS_MEMIO_H_)
300 #if defined(_I386_BUS_PIO_H_)
304 __asm __volatile(" \n\
306 1: movw (%2),%%ax \n\
309 "=D" (addr), "=c" (count) :
310 "r" (bsh + offset), "0" (addr), "1" (count) :
317 bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
318 bus_size_t offset, u_int32_t *addr, size_t count)
320 #if defined(_I386_BUS_PIO_H_)
321 #if defined(_I386_BUS_MEMIO_H_)
322 if (tag == I386_BUS_SPACE_IO)
324 insl(bsh + offset, addr, count);
326 #if defined(_I386_BUS_MEMIO_H_)
327 #if defined(_I386_BUS_PIO_H_)
331 __asm __volatile(" \n\
333 1: movl (%2),%%eax \n\
336 "=D" (addr), "=c" (count) :
337 "r" (bsh + offset), "0" (addr), "1" (count) :
343 #if 0 /* Cause a link error for bus_space_read_multi_8 */
344 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
348 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
349 * described by tag/handle and starting at `offset' and copy into
352 static __inline void bus_space_read_region_1(bus_space_tag_t tag,
353 bus_space_handle_t bsh,
354 bus_size_t offset, u_int8_t *addr,
357 static __inline void bus_space_read_region_2(bus_space_tag_t tag,
358 bus_space_handle_t bsh,
359 bus_size_t offset, u_int16_t *addr,
362 static __inline void bus_space_read_region_4(bus_space_tag_t tag,
363 bus_space_handle_t bsh,
364 bus_size_t offset, u_int32_t *addr,
369 bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
370 bus_size_t offset, u_int8_t *addr, size_t count)
372 #if defined(_I386_BUS_PIO_H_)
373 #if defined(_I386_BUS_MEMIO_H_)
374 if (tag == I386_BUS_SPACE_IO)
377 int _port_ = bsh + offset; \
378 __asm __volatile(" \n\
384 "=D" (addr), "=c" (count), "=d" (_port_) :
385 "0" (addr), "1" (count), "2" (_port_) :
386 "%eax", "memory", "cc");
389 #if defined(_I386_BUS_MEMIO_H_)
390 #if defined(_I386_BUS_PIO_H_)
394 int _port_ = bsh + offset; \
395 __asm __volatile(" \n\
399 "=D" (addr), "=c" (count), "=S" (_port_) :
400 "0" (addr), "1" (count), "2" (_port_) :
407 bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
408 bus_size_t offset, u_int16_t *addr, size_t count)
410 #if defined(_I386_BUS_PIO_H_)
411 #if defined(_I386_BUS_MEMIO_H_)
412 if (tag == I386_BUS_SPACE_IO)
415 int _port_ = bsh + offset; \
416 __asm __volatile(" \n\
422 "=D" (addr), "=c" (count), "=d" (_port_) :
423 "0" (addr), "1" (count), "2" (_port_) :
424 "%eax", "memory", "cc");
427 #if defined(_I386_BUS_MEMIO_H_)
428 #if defined(_I386_BUS_PIO_H_)
432 int _port_ = bsh + offset; \
433 __asm __volatile(" \n\
437 "=D" (addr), "=c" (count), "=S" (_port_) :
438 "0" (addr), "1" (count), "2" (_port_) :
445 bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
446 bus_size_t offset, u_int32_t *addr, size_t count)
448 #if defined(_I386_BUS_PIO_H_)
449 #if defined(_I386_BUS_MEMIO_H_)
450 if (tag == I386_BUS_SPACE_IO)
453 int _port_ = bsh + offset; \
454 __asm __volatile(" \n\
460 "=D" (addr), "=c" (count), "=d" (_port_) :
461 "0" (addr), "1" (count), "2" (_port_) :
462 "%eax", "memory", "cc");
465 #if defined(_I386_BUS_MEMIO_H_)
466 #if defined(_I386_BUS_PIO_H_)
470 int _port_ = bsh + offset; \
471 __asm __volatile(" \n\
475 "=D" (addr), "=c" (count), "=S" (_port_) :
476 "0" (addr), "1" (count), "2" (_port_) :
482 #if 0 /* Cause a link error for bus_space_read_region_8 */
483 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
487 * Write the 1, 2, 4, or 8 byte value `value' to bus space
488 * described by tag/handle/offset.
491 static __inline void bus_space_write_1(bus_space_tag_t tag,
492 bus_space_handle_t bsh,
493 bus_size_t offset, u_int8_t value);
495 static __inline void bus_space_write_2(bus_space_tag_t tag,
496 bus_space_handle_t bsh,
497 bus_size_t offset, u_int16_t value);
499 static __inline void bus_space_write_4(bus_space_tag_t tag,
500 bus_space_handle_t bsh,
501 bus_size_t offset, u_int32_t value);
504 bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsh,
505 bus_size_t offset, u_int8_t value)
507 #if defined(_I386_BUS_PIO_H_)
508 #if defined(_I386_BUS_MEMIO_H_)
509 if (tag == I386_BUS_SPACE_IO)
511 outb(bsh + offset, value);
513 #if defined(_I386_BUS_MEMIO_H_)
514 #if defined(_I386_BUS_PIO_H_)
517 *(volatile u_int8_t *)(bsh + offset) = value;
522 bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t bsh,
523 bus_size_t offset, u_int16_t value)
525 #if defined(_I386_BUS_PIO_H_)
526 #if defined(_I386_BUS_MEMIO_H_)
527 if (tag == I386_BUS_SPACE_IO)
529 outw(bsh + offset, value);
531 #if defined(_I386_BUS_MEMIO_H_)
532 #if defined(_I386_BUS_PIO_H_)
535 *(volatile u_int16_t *)(bsh + offset) = value;
540 bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh,
541 bus_size_t offset, u_int32_t value)
543 #if defined(_I386_BUS_PIO_H_)
544 #if defined(_I386_BUS_MEMIO_H_)
545 if (tag == I386_BUS_SPACE_IO)
547 outl(bsh + offset, value);
549 #if defined(_I386_BUS_MEMIO_H_)
550 #if defined(_I386_BUS_PIO_H_)
553 *(volatile u_int32_t *)(bsh + offset) = value;
557 #if 0 /* Cause a link error for bus_space_write_8 */
558 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
562 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
563 * provided to bus space described by tag/handle/offset.
566 static __inline void bus_space_write_multi_1(bus_space_tag_t tag,
567 bus_space_handle_t bsh,
569 const u_int8_t *addr,
571 static __inline void bus_space_write_multi_2(bus_space_tag_t tag,
572 bus_space_handle_t bsh,
574 const u_int16_t *addr,
577 static __inline void bus_space_write_multi_4(bus_space_tag_t tag,
578 bus_space_handle_t bsh,
580 const u_int32_t *addr,
584 bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
585 bus_size_t offset, const u_int8_t *addr, size_t count)
587 #if defined(_I386_BUS_PIO_H_)
588 #if defined(_I386_BUS_MEMIO_H_)
589 if (tag == I386_BUS_SPACE_IO)
591 outsb(bsh + offset, addr, count);
593 #if defined(_I386_BUS_MEMIO_H_)
594 #if defined(_I386_BUS_PIO_H_)
598 __asm __volatile(" \n\
603 "=S" (addr), "=c" (count) :
604 "r" (bsh + offset), "0" (addr), "1" (count) :
605 "%eax", "memory", "cc");
611 bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
612 bus_size_t offset, const u_int16_t *addr, size_t count)
614 #if defined(_I386_BUS_PIO_H_)
615 #if defined(_I386_BUS_MEMIO_H_)
616 if (tag == I386_BUS_SPACE_IO)
618 outsw(bsh + offset, addr, count);
620 #if defined(_I386_BUS_MEMIO_H_)
621 #if defined(_I386_BUS_PIO_H_)
625 __asm __volatile(" \n\
630 "=S" (addr), "=c" (count) :
631 "r" (bsh + offset), "0" (addr), "1" (count) :
632 "%eax", "memory", "cc");
638 bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
639 bus_size_t offset, const u_int32_t *addr, size_t count)
641 #if defined(_I386_BUS_PIO_H_)
642 #if defined(_I386_BUS_MEMIO_H_)
643 if (tag == I386_BUS_SPACE_IO)
645 outsl(bsh + offset, addr, count);
647 #if defined(_I386_BUS_MEMIO_H_)
648 #if defined(_I386_BUS_PIO_H_)
652 __asm __volatile(" \n\
657 "=S" (addr), "=c" (count) :
658 "r" (bsh + offset), "0" (addr), "1" (count) :
659 "%eax", "memory", "cc");
664 #if 0 /* Cause a link error for bus_space_write_multi_8 */
665 #define bus_space_write_multi_8(t, h, o, a, c) \
666 !!! bus_space_write_multi_8 unimplemented !!!
670 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
671 * to bus space described by tag/handle starting at `offset'.
674 static __inline void bus_space_write_region_1(bus_space_tag_t tag,
675 bus_space_handle_t bsh,
677 const u_int8_t *addr,
679 static __inline void bus_space_write_region_2(bus_space_tag_t tag,
680 bus_space_handle_t bsh,
682 const u_int16_t *addr,
684 static __inline void bus_space_write_region_4(bus_space_tag_t tag,
685 bus_space_handle_t bsh,
687 const u_int32_t *addr,
691 bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
692 bus_size_t offset, const u_int8_t *addr, size_t count)
694 #if defined(_I386_BUS_PIO_H_)
695 #if defined(_I386_BUS_MEMIO_H_)
696 if (tag == I386_BUS_SPACE_IO)
699 int _port_ = bsh + offset; \
700 __asm __volatile(" \n\
706 "=d" (_port_), "=S" (addr), "=c" (count) :
707 "0" (_port_), "1" (addr), "2" (count) :
708 "%eax", "memory", "cc");
711 #if defined(_I386_BUS_MEMIO_H_)
712 #if defined(_I386_BUS_PIO_H_)
716 int _port_ = bsh + offset; \
717 __asm __volatile(" \n\
721 "=D" (_port_), "=S" (addr), "=c" (count) :
722 "0" (_port_), "1" (addr), "2" (count) :
729 bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
730 bus_size_t offset, const u_int16_t *addr, size_t count)
732 #if defined(_I386_BUS_PIO_H_)
733 #if defined(_I386_BUS_MEMIO_H_)
734 if (tag == I386_BUS_SPACE_IO)
737 int _port_ = bsh + offset; \
738 __asm __volatile(" \n\
744 "=d" (_port_), "=S" (addr), "=c" (count) :
745 "0" (_port_), "1" (addr), "2" (count) :
746 "%eax", "memory", "cc");
749 #if defined(_I386_BUS_MEMIO_H_)
750 #if defined(_I386_BUS_PIO_H_)
754 int _port_ = bsh + offset; \
755 __asm __volatile(" \n\
759 "=D" (_port_), "=S" (addr), "=c" (count) :
760 "0" (_port_), "1" (addr), "2" (count) :
767 bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
768 bus_size_t offset, const u_int32_t *addr, size_t count)
770 #if defined(_I386_BUS_PIO_H_)
771 #if defined(_I386_BUS_MEMIO_H_)
772 if (tag == I386_BUS_SPACE_IO)
775 int _port_ = bsh + offset; \
776 __asm __volatile(" \n\
782 "=d" (_port_), "=S" (addr), "=c" (count) :
783 "0" (_port_), "1" (addr), "2" (count) :
784 "%eax", "memory", "cc");
787 #if defined(_I386_BUS_MEMIO_H_)
788 #if defined(_I386_BUS_PIO_H_)
792 int _port_ = bsh + offset; \
793 __asm __volatile(" \n\
797 "=D" (_port_), "=S" (addr), "=c" (count) :
798 "0" (_port_), "1" (addr), "2" (count) :
804 #if 0 /* Cause a link error for bus_space_write_region_8 */
805 #define bus_space_write_region_8 \
806 !!! bus_space_write_region_8 unimplemented !!!
810 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
811 * by tag/handle/offset `count' times.
814 static __inline void bus_space_set_multi_1(bus_space_tag_t tag,
815 bus_space_handle_t bsh,
817 u_int8_t value, size_t count);
818 static __inline void bus_space_set_multi_2(bus_space_tag_t tag,
819 bus_space_handle_t bsh,
821 u_int16_t value, size_t count);
822 static __inline void bus_space_set_multi_4(bus_space_tag_t tag,
823 bus_space_handle_t bsh,
825 u_int32_t value, size_t count);
828 bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
829 bus_size_t offset, u_int8_t value, size_t count)
831 bus_addr_t addr = bsh + offset;
833 #if defined(_I386_BUS_PIO_H_)
834 #if defined(_I386_BUS_MEMIO_H_)
835 if (tag == I386_BUS_SPACE_IO)
840 #if defined(_I386_BUS_MEMIO_H_)
841 #if defined(_I386_BUS_PIO_H_)
845 *(volatile u_int8_t *)(addr) = value;
850 bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
851 bus_size_t offset, u_int16_t value, size_t count)
853 bus_addr_t addr = bsh + offset;
855 #if defined(_I386_BUS_PIO_H_)
856 #if defined(_I386_BUS_MEMIO_H_)
857 if (tag == I386_BUS_SPACE_IO)
862 #if defined(_I386_BUS_MEMIO_H_)
863 #if defined(_I386_BUS_PIO_H_)
867 *(volatile u_int16_t *)(addr) = value;
872 bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
873 bus_size_t offset, u_int32_t value, size_t count)
875 bus_addr_t addr = bsh + offset;
877 #if defined(_I386_BUS_PIO_H_)
878 #if defined(_I386_BUS_MEMIO_H_)
879 if (tag == I386_BUS_SPACE_IO)
884 #if defined(_I386_BUS_MEMIO_H_)
885 #if defined(_I386_BUS_PIO_H_)
889 *(volatile u_int32_t *)(addr) = value;
893 #if 0 /* Cause a link error for bus_space_set_multi_8 */
894 #define bus_space_set_multi_8 !!! bus_space_set_multi_8 unimplemented !!!
898 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
899 * by tag/handle starting at `offset'.
902 static __inline void bus_space_set_region_1(bus_space_tag_t tag,
903 bus_space_handle_t bsh,
904 bus_size_t offset, u_int8_t value,
906 static __inline void bus_space_set_region_2(bus_space_tag_t tag,
907 bus_space_handle_t bsh,
908 bus_size_t offset, u_int16_t value,
910 static __inline void bus_space_set_region_4(bus_space_tag_t tag,
911 bus_space_handle_t bsh,
912 bus_size_t offset, u_int32_t value,
916 bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
917 bus_size_t offset, u_int8_t value, size_t count)
919 bus_addr_t addr = bsh + offset;
921 #if defined(_I386_BUS_PIO_H_)
922 #if defined(_I386_BUS_MEMIO_H_)
923 if (tag == I386_BUS_SPACE_IO)
925 for (; count != 0; count--, addr++)
928 #if defined(_I386_BUS_MEMIO_H_)
929 #if defined(_I386_BUS_PIO_H_)
932 for (; count != 0; count--, addr++)
933 *(volatile u_int8_t *)(addr) = value;
938 bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
939 bus_size_t offset, u_int16_t value, size_t count)
941 bus_addr_t addr = bsh + offset;
943 #if defined(_I386_BUS_PIO_H_)
944 #if defined(_I386_BUS_MEMIO_H_)
945 if (tag == I386_BUS_SPACE_IO)
947 for (; count != 0; count--, addr += 2)
950 #if defined(_I386_BUS_MEMIO_H_)
951 #if defined(_I386_BUS_PIO_H_)
954 for (; count != 0; count--, addr += 2)
955 *(volatile u_int16_t *)(addr) = value;
960 bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
961 bus_size_t offset, u_int32_t value, size_t count)
963 bus_addr_t addr = bsh + offset;
965 #if defined(_I386_BUS_PIO_H_)
966 #if defined(_I386_BUS_MEMIO_H_)
967 if (tag == I386_BUS_SPACE_IO)
969 for (; count != 0; count--, addr += 4)
972 #if defined(_I386_BUS_MEMIO_H_)
973 #if defined(_I386_BUS_PIO_H_)
976 for (; count != 0; count--, addr += 4)
977 *(volatile u_int32_t *)(addr) = value;
981 #if 0 /* Cause a link error for bus_space_set_region_8 */
982 #define bus_space_set_region_8 !!! bus_space_set_region_8 unimplemented !!!
986 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
987 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
990 static __inline void bus_space_copy_region_1(bus_space_tag_t tag,
991 bus_space_handle_t bsh1,
993 bus_space_handle_t bsh2,
994 bus_size_t off2, size_t count);
996 static __inline void bus_space_copy_region_2(bus_space_tag_t tag,
997 bus_space_handle_t bsh1,
999 bus_space_handle_t bsh2,
1000 bus_size_t off2, size_t count);
1002 static __inline void bus_space_copy_region_4(bus_space_tag_t tag,
1003 bus_space_handle_t bsh1,
1005 bus_space_handle_t bsh2,
1006 bus_size_t off2, size_t count);
1008 static __inline void
1009 bus_space_copy_region_1(bus_space_tag_t tag, bus_space_handle_t bsh1,
1010 bus_size_t off1, bus_space_handle_t bsh2,
1011 bus_size_t off2, size_t count)
1013 bus_addr_t addr1 = bsh1 + off1;
1014 bus_addr_t addr2 = bsh2 + off2;
1016 #if defined(_I386_BUS_PIO_H_)
1017 #if defined(_I386_BUS_MEMIO_H_)
1018 if (tag == I386_BUS_SPACE_IO)
1021 if (addr1 >= addr2) {
1022 /* src after dest: copy forward */
1023 for (; count != 0; count--, addr1++, addr2++)
1024 outb(addr2, inb(addr1));
1026 /* dest after src: copy backwards */
1027 for (addr1 += (count - 1), addr2 += (count - 1);
1028 count != 0; count--, addr1--, addr2--)
1029 outb(addr2, inb(addr1));
1033 #if defined(_I386_BUS_MEMIO_H_)
1034 #if defined(_I386_BUS_PIO_H_)
1038 if (addr1 >= addr2) {
1039 /* src after dest: copy forward */
1040 for (; count != 0; count--, addr1++, addr2++)
1041 *(volatile u_int8_t *)(addr2) =
1042 *(volatile u_int8_t *)(addr1);
1044 /* dest after src: copy backwards */
1045 for (addr1 += (count - 1), addr2 += (count - 1);
1046 count != 0; count--, addr1--, addr2--)
1047 *(volatile u_int8_t *)(addr2) =
1048 *(volatile u_int8_t *)(addr1);
1054 static __inline void
1055 bus_space_copy_region_2(bus_space_tag_t tag, bus_space_handle_t bsh1,
1056 bus_size_t off1, bus_space_handle_t bsh2,
1057 bus_size_t off2, size_t count)
1059 bus_addr_t addr1 = bsh1 + off1;
1060 bus_addr_t addr2 = bsh2 + off2;
1062 #if defined(_I386_BUS_PIO_H_)
1063 #if defined(_I386_BUS_MEMIO_H_)
1064 if (tag == I386_BUS_SPACE_IO)
1067 if (addr1 >= addr2) {
1068 /* src after dest: copy forward */
1069 for (; count != 0; count--, addr1 += 2, addr2 += 2)
1070 outw(addr2, inw(addr1));
1072 /* dest after src: copy backwards */
1073 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
1074 count != 0; count--, addr1 -= 2, addr2 -= 2)
1075 outw(addr2, inw(addr1));
1079 #if defined(_I386_BUS_MEMIO_H_)
1080 #if defined(_I386_BUS_PIO_H_)
1084 if (addr1 >= addr2) {
1085 /* src after dest: copy forward */
1086 for (; count != 0; count--, addr1 += 2, addr2 += 2)
1087 *(volatile u_int16_t *)(addr2) =
1088 *(volatile u_int16_t *)(addr1);
1090 /* dest after src: copy backwards */
1091 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
1092 count != 0; count--, addr1 -= 2, addr2 -= 2)
1093 *(volatile u_int16_t *)(addr2) =
1094 *(volatile u_int16_t *)(addr1);
1100 static __inline void
1101 bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsh1,
1102 bus_size_t off1, bus_space_handle_t bsh2,
1103 bus_size_t off2, size_t count)
1105 bus_addr_t addr1 = bsh1 + off1;
1106 bus_addr_t addr2 = bsh2 + off2;
1108 #if defined(_I386_BUS_PIO_H_)
1109 #if defined(_I386_BUS_MEMIO_H_)
1110 if (tag == I386_BUS_SPACE_IO)
1113 if (addr1 >= addr2) {
1114 /* src after dest: copy forward */
1115 for (; count != 0; count--, addr1 += 4, addr2 += 4)
1116 outl(addr2, inl(addr1));
1118 /* dest after src: copy backwards */
1119 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
1120 count != 0; count--, addr1 -= 4, addr2 -= 4)
1121 outl(addr2, inl(addr1));
1125 #if defined(_I386_BUS_MEMIO_H_)
1126 #if defined(_I386_BUS_PIO_H_)
1130 if (addr1 >= addr2) {
1131 /* src after dest: copy forward */
1132 for (; count != 0; count--, addr1 += 4, addr2 += 4)
1133 *(volatile u_int32_t *)(addr2) =
1134 *(volatile u_int32_t *)(addr1);
1136 /* dest after src: copy backwards */
1137 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
1138 count != 0; count--, addr1 -= 4, addr2 -= 4)
1139 *(volatile u_int32_t *)(addr2) =
1140 *(volatile u_int32_t *)(addr1);
1146 #endif /* defined(_I386_BUS_PIO_H_) || defined(_I386_MEM_IO_H_) */
1148 #if 0 /* Cause a link error for bus_space_copy_8 */
1149 #define bus_space_copy_region_8 !!! bus_space_copy_region_8 unimplemented !!!
1153 * Bus read/write barrier methods.
1155 * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
1156 * bus_size_t offset, bus_size_t len, int flags);
1158 * Note: the i386 does not currently require barriers, but we must
1159 * provide the flags to MI code.
1161 #define bus_space_barrier(t, h, o, l, f) \
1162 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
1163 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
1164 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
1166 #endif /* _I386_BUS_AT386_H_ */