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 $ */
71 /* $DragonFly: src/sys/i386/include/Attic/bus_at386.h,v 1.5 2003/08/07 21:17:22 dillon Exp $ */
73 #ifndef _I386_BUS_AT386_H_
74 #define _I386_BUS_AT386_H_
79 * To remain compatible with NetBSD's interface, default to both memio and
80 * pio when neither of them is defined.
82 #if !defined(_I386_BUS_PIO_H_) && !defined(_I386_BUS_MEMIO_H_)
83 #define _I386_BUS_PIO_H_
84 #define _I386_BUS_MEMIO_H_
88 * Values for the i386 bus space tag, not to be used directly by MI code.
90 #define I386_BUS_SPACE_IO 0 /* space is i/o space */
91 #define I386_BUS_SPACE_MEM 1 /* space is mem space */
94 * Bus address and size types
96 typedef u_int bus_addr_t;
97 typedef u_int bus_size_t;
99 #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF
100 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
101 #define BUS_SPACE_MAXSIZE (64 * 1024) /* Maximum supported size */
102 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF
103 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
104 #define BUS_SPACE_MAXADDR 0xFFFFFFFF
106 #define BUS_SPACE_UNRESTRICTED (~0)
109 * Access methods for bus resources and address space.
111 typedef int bus_space_tag_t;
112 typedef u_int bus_space_handle_t;
115 * Map a region of device bus space into CPU virtual address space.
118 #define BUS_SPACE_MAP_CACHEABLE 0x01
119 #define BUS_SPACE_MAP_LINEAR 0x02
121 int bus_space_map(bus_space_tag_t t, bus_addr_t addr, bus_size_t size,
122 int flags, bus_space_handle_t *bshp);
125 * Unmap a region of device bus space.
128 static __inline void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
132 bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size)
137 * Get a new handle for a subregion of an already-mapped area of bus space.
140 static __inline int bus_space_subregion(bus_space_tag_t t,
141 bus_space_handle_t bsh,
142 bus_size_t offset, bus_size_t size,
143 bus_space_handle_t *nbshp);
146 bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
147 bus_size_t offset, bus_size_t size,
148 bus_space_handle_t *nbshp)
151 *nbshp = bsh + offset;
156 * Allocate a region of memory that is accessible to devices in bus space.
159 int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
160 bus_addr_t rend, bus_size_t size, bus_size_t align,
161 bus_size_t boundary, int flags, bus_addr_t *addrp,
162 bus_space_handle_t *bshp);
165 * Free a region of bus space accessible memory.
168 static __inline void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
172 bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size)
177 #if defined(_I386_BUS_PIO_H_) || defined(_I386_BUS_MEMIO_H_)
180 * Read a 1, 2, 4, or 8 byte quantity from bus space
181 * described by tag/handle/offset.
183 static __inline u_int8_t bus_space_read_1(bus_space_tag_t tag,
184 bus_space_handle_t handle,
187 static __inline u_int16_t bus_space_read_2(bus_space_tag_t tag,
188 bus_space_handle_t handle,
191 static __inline u_int32_t bus_space_read_4(bus_space_tag_t tag,
192 bus_space_handle_t handle,
195 static __inline u_int8_t
196 bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle,
199 #if defined (_I386_BUS_PIO_H_)
200 #if defined (_I386_BUS_MEMIO_H_)
201 if (tag == I386_BUS_SPACE_IO)
203 return (inb(handle + offset));
205 #if defined (_I386_BUS_MEMIO_H_)
206 return (*(volatile u_int8_t *)(handle + offset));
210 static __inline u_int16_t
211 bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle,
214 #if defined(_I386_BUS_PIO_H_)
215 #if defined(_I386_BUS_MEMIO_H_)
216 if (tag == I386_BUS_SPACE_IO)
218 return (inw(handle + offset));
220 #if defined(_I386_BUS_MEMIO_H_)
221 return (*(volatile u_int16_t *)(handle + offset));
225 static __inline u_int32_t
226 bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle,
229 #if defined(_I386_BUS_PIO_H_)
230 #if defined(_I386_BUS_MEMIO_H_)
231 if (tag == I386_BUS_SPACE_IO)
233 return (inl(handle + offset));
235 #if defined(_I386_BUS_MEMIO_H_)
236 return (*(volatile u_int32_t *)(handle + offset));
240 #if 0 /* Cause a link error for bus_space_read_8 */
241 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
245 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
246 * described by tag/handle/offset and copy into buffer provided.
248 static __inline void bus_space_read_multi_1(bus_space_tag_t tag,
249 bus_space_handle_t bsh,
250 bus_size_t offset, u_int8_t *addr,
253 static __inline void bus_space_read_multi_2(bus_space_tag_t tag,
254 bus_space_handle_t bsh,
255 bus_size_t offset, u_int16_t *addr,
258 static __inline void bus_space_read_multi_4(bus_space_tag_t tag,
259 bus_space_handle_t bsh,
260 bus_size_t offset, u_int32_t *addr,
264 bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
265 bus_size_t offset, u_int8_t *addr, size_t count)
267 #if defined(_I386_BUS_PIO_H_)
268 #if defined(_I386_BUS_MEMIO_H_)
269 if (tag == I386_BUS_SPACE_IO)
271 insb(bsh + offset, addr, count);
273 #if defined(_I386_BUS_MEMIO_H_)
274 #if defined(_I386_BUS_PIO_H_)
278 __asm __volatile(" \n\
280 1: movb (%2),%%al \n\
283 "=D" (addr), "=c" (count) :
284 "r" (bsh + offset), "0" (addr), "1" (count) :
291 bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
292 bus_size_t offset, u_int16_t *addr, size_t count)
294 #if defined(_I386_BUS_PIO_H_)
295 #if defined(_I386_BUS_MEMIO_H_)
296 if (tag == I386_BUS_SPACE_IO)
298 insw(bsh + offset, addr, count);
300 #if defined(_I386_BUS_MEMIO_H_)
301 #if defined(_I386_BUS_PIO_H_)
305 __asm __volatile(" \n\
307 1: movw (%2),%%ax \n\
310 "=D" (addr), "=c" (count) :
311 "r" (bsh + offset), "0" (addr), "1" (count) :
318 bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
319 bus_size_t offset, u_int32_t *addr, size_t count)
321 #if defined(_I386_BUS_PIO_H_)
322 #if defined(_I386_BUS_MEMIO_H_)
323 if (tag == I386_BUS_SPACE_IO)
325 insl(bsh + offset, addr, count);
327 #if defined(_I386_BUS_MEMIO_H_)
328 #if defined(_I386_BUS_PIO_H_)
332 __asm __volatile(" \n\
334 1: movl (%2),%%eax \n\
337 "=D" (addr), "=c" (count) :
338 "r" (bsh + offset), "0" (addr), "1" (count) :
344 #if 0 /* Cause a link error for bus_space_read_multi_8 */
345 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
349 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
350 * described by tag/handle and starting at `offset' and copy into
353 static __inline void bus_space_read_region_1(bus_space_tag_t tag,
354 bus_space_handle_t bsh,
355 bus_size_t offset, u_int8_t *addr,
358 static __inline void bus_space_read_region_2(bus_space_tag_t tag,
359 bus_space_handle_t bsh,
360 bus_size_t offset, u_int16_t *addr,
363 static __inline void bus_space_read_region_4(bus_space_tag_t tag,
364 bus_space_handle_t bsh,
365 bus_size_t offset, u_int32_t *addr,
370 bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
371 bus_size_t offset, u_int8_t *addr, size_t count)
373 #if defined(_I386_BUS_PIO_H_)
374 #if defined(_I386_BUS_MEMIO_H_)
375 if (tag == I386_BUS_SPACE_IO)
378 int _port_ = bsh + offset; \
379 __asm __volatile(" \n\
385 "=D" (addr), "=c" (count), "=d" (_port_) :
386 "0" (addr), "1" (count), "2" (_port_) :
387 "%eax", "memory", "cc");
390 #if defined(_I386_BUS_MEMIO_H_)
391 #if defined(_I386_BUS_PIO_H_)
395 int _port_ = bsh + offset; \
396 __asm __volatile(" \n\
400 "=D" (addr), "=c" (count), "=S" (_port_) :
401 "0" (addr), "1" (count), "2" (_port_) :
408 bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
409 bus_size_t offset, u_int16_t *addr, size_t count)
411 #if defined(_I386_BUS_PIO_H_)
412 #if defined(_I386_BUS_MEMIO_H_)
413 if (tag == I386_BUS_SPACE_IO)
416 int _port_ = bsh + offset; \
417 __asm __volatile(" \n\
423 "=D" (addr), "=c" (count), "=d" (_port_) :
424 "0" (addr), "1" (count), "2" (_port_) :
425 "%eax", "memory", "cc");
428 #if defined(_I386_BUS_MEMIO_H_)
429 #if defined(_I386_BUS_PIO_H_)
433 int _port_ = bsh + offset; \
434 __asm __volatile(" \n\
438 "=D" (addr), "=c" (count), "=S" (_port_) :
439 "0" (addr), "1" (count), "2" (_port_) :
446 bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
447 bus_size_t offset, u_int32_t *addr, size_t count)
449 #if defined(_I386_BUS_PIO_H_)
450 #if defined(_I386_BUS_MEMIO_H_)
451 if (tag == I386_BUS_SPACE_IO)
454 int _port_ = bsh + offset; \
455 __asm __volatile(" \n\
461 "=D" (addr), "=c" (count), "=d" (_port_) :
462 "0" (addr), "1" (count), "2" (_port_) :
463 "%eax", "memory", "cc");
466 #if defined(_I386_BUS_MEMIO_H_)
467 #if defined(_I386_BUS_PIO_H_)
471 int _port_ = bsh + offset; \
472 __asm __volatile(" \n\
476 "=D" (addr), "=c" (count), "=S" (_port_) :
477 "0" (addr), "1" (count), "2" (_port_) :
483 #if 0 /* Cause a link error for bus_space_read_region_8 */
484 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
488 * Write the 1, 2, 4, or 8 byte value `value' to bus space
489 * described by tag/handle/offset.
492 static __inline void bus_space_write_1(bus_space_tag_t tag,
493 bus_space_handle_t bsh,
494 bus_size_t offset, u_int8_t value);
496 static __inline void bus_space_write_2(bus_space_tag_t tag,
497 bus_space_handle_t bsh,
498 bus_size_t offset, u_int16_t value);
500 static __inline void bus_space_write_4(bus_space_tag_t tag,
501 bus_space_handle_t bsh,
502 bus_size_t offset, u_int32_t value);
505 bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsh,
506 bus_size_t offset, u_int8_t value)
508 #if defined(_I386_BUS_PIO_H_)
509 #if defined(_I386_BUS_MEMIO_H_)
510 if (tag == I386_BUS_SPACE_IO)
512 outb(bsh + offset, value);
514 #if defined(_I386_BUS_MEMIO_H_)
515 #if defined(_I386_BUS_PIO_H_)
518 *(volatile u_int8_t *)(bsh + offset) = value;
523 bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t bsh,
524 bus_size_t offset, u_int16_t value)
526 #if defined(_I386_BUS_PIO_H_)
527 #if defined(_I386_BUS_MEMIO_H_)
528 if (tag == I386_BUS_SPACE_IO)
530 outw(bsh + offset, value);
532 #if defined(_I386_BUS_MEMIO_H_)
533 #if defined(_I386_BUS_PIO_H_)
536 *(volatile u_int16_t *)(bsh + offset) = value;
541 bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh,
542 bus_size_t offset, u_int32_t value)
544 #if defined(_I386_BUS_PIO_H_)
545 #if defined(_I386_BUS_MEMIO_H_)
546 if (tag == I386_BUS_SPACE_IO)
548 outl(bsh + offset, value);
550 #if defined(_I386_BUS_MEMIO_H_)
551 #if defined(_I386_BUS_PIO_H_)
554 *(volatile u_int32_t *)(bsh + offset) = value;
558 #if 0 /* Cause a link error for bus_space_write_8 */
559 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
563 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
564 * provided to bus space described by tag/handle/offset.
567 static __inline void bus_space_write_multi_1(bus_space_tag_t tag,
568 bus_space_handle_t bsh,
570 const u_int8_t *addr,
572 static __inline void bus_space_write_multi_2(bus_space_tag_t tag,
573 bus_space_handle_t bsh,
575 const u_int16_t *addr,
578 static __inline void bus_space_write_multi_4(bus_space_tag_t tag,
579 bus_space_handle_t bsh,
581 const u_int32_t *addr,
585 bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
586 bus_size_t offset, const u_int8_t *addr, size_t count)
588 #if defined(_I386_BUS_PIO_H_)
589 #if defined(_I386_BUS_MEMIO_H_)
590 if (tag == I386_BUS_SPACE_IO)
592 outsb(bsh + offset, addr, count);
594 #if defined(_I386_BUS_MEMIO_H_)
595 #if defined(_I386_BUS_PIO_H_)
599 __asm __volatile(" \n\
604 "=S" (addr), "=c" (count) :
605 "r" (bsh + offset), "0" (addr), "1" (count) :
606 "%eax", "memory", "cc");
612 bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
613 bus_size_t offset, const u_int16_t *addr, size_t count)
615 #if defined(_I386_BUS_PIO_H_)
616 #if defined(_I386_BUS_MEMIO_H_)
617 if (tag == I386_BUS_SPACE_IO)
619 outsw(bsh + offset, addr, count);
621 #if defined(_I386_BUS_MEMIO_H_)
622 #if defined(_I386_BUS_PIO_H_)
626 __asm __volatile(" \n\
631 "=S" (addr), "=c" (count) :
632 "r" (bsh + offset), "0" (addr), "1" (count) :
633 "%eax", "memory", "cc");
639 bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
640 bus_size_t offset, const u_int32_t *addr, size_t count)
642 #if defined(_I386_BUS_PIO_H_)
643 #if defined(_I386_BUS_MEMIO_H_)
644 if (tag == I386_BUS_SPACE_IO)
646 outsl(bsh + offset, addr, count);
648 #if defined(_I386_BUS_MEMIO_H_)
649 #if defined(_I386_BUS_PIO_H_)
653 __asm __volatile(" \n\
658 "=S" (addr), "=c" (count) :
659 "r" (bsh + offset), "0" (addr), "1" (count) :
660 "%eax", "memory", "cc");
665 #if 0 /* Cause a link error for bus_space_write_multi_8 */
666 #define bus_space_write_multi_8(t, h, o, a, c) \
667 !!! bus_space_write_multi_8 unimplemented !!!
671 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
672 * to bus space described by tag/handle starting at `offset'.
675 static __inline void bus_space_write_region_1(bus_space_tag_t tag,
676 bus_space_handle_t bsh,
678 const u_int8_t *addr,
680 static __inline void bus_space_write_region_2(bus_space_tag_t tag,
681 bus_space_handle_t bsh,
683 const u_int16_t *addr,
685 static __inline void bus_space_write_region_4(bus_space_tag_t tag,
686 bus_space_handle_t bsh,
688 const u_int32_t *addr,
692 bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
693 bus_size_t offset, const u_int8_t *addr, size_t count)
695 #if defined(_I386_BUS_PIO_H_)
696 #if defined(_I386_BUS_MEMIO_H_)
697 if (tag == I386_BUS_SPACE_IO)
700 int _port_ = bsh + offset; \
701 __asm __volatile(" \n\
707 "=d" (_port_), "=S" (addr), "=c" (count) :
708 "0" (_port_), "1" (addr), "2" (count) :
709 "%eax", "memory", "cc");
712 #if defined(_I386_BUS_MEMIO_H_)
713 #if defined(_I386_BUS_PIO_H_)
717 int _port_ = bsh + offset; \
718 __asm __volatile(" \n\
722 "=D" (_port_), "=S" (addr), "=c" (count) :
723 "0" (_port_), "1" (addr), "2" (count) :
730 bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
731 bus_size_t offset, const u_int16_t *addr, size_t count)
733 #if defined(_I386_BUS_PIO_H_)
734 #if defined(_I386_BUS_MEMIO_H_)
735 if (tag == I386_BUS_SPACE_IO)
738 int _port_ = bsh + offset; \
739 __asm __volatile(" \n\
745 "=d" (_port_), "=S" (addr), "=c" (count) :
746 "0" (_port_), "1" (addr), "2" (count) :
747 "%eax", "memory", "cc");
750 #if defined(_I386_BUS_MEMIO_H_)
751 #if defined(_I386_BUS_PIO_H_)
755 int _port_ = bsh + offset; \
756 __asm __volatile(" \n\
760 "=D" (_port_), "=S" (addr), "=c" (count) :
761 "0" (_port_), "1" (addr), "2" (count) :
768 bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
769 bus_size_t offset, const u_int32_t *addr, size_t count)
771 #if defined(_I386_BUS_PIO_H_)
772 #if defined(_I386_BUS_MEMIO_H_)
773 if (tag == I386_BUS_SPACE_IO)
776 int _port_ = bsh + offset; \
777 __asm __volatile(" \n\
783 "=d" (_port_), "=S" (addr), "=c" (count) :
784 "0" (_port_), "1" (addr), "2" (count) :
785 "%eax", "memory", "cc");
788 #if defined(_I386_BUS_MEMIO_H_)
789 #if defined(_I386_BUS_PIO_H_)
793 int _port_ = bsh + offset; \
794 __asm __volatile(" \n\
798 "=D" (_port_), "=S" (addr), "=c" (count) :
799 "0" (_port_), "1" (addr), "2" (count) :
805 #if 0 /* Cause a link error for bus_space_write_region_8 */
806 #define bus_space_write_region_8 \
807 !!! bus_space_write_region_8 unimplemented !!!
811 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
812 * by tag/handle/offset `count' times.
815 static __inline void bus_space_set_multi_1(bus_space_tag_t tag,
816 bus_space_handle_t bsh,
818 u_int8_t value, size_t count);
819 static __inline void bus_space_set_multi_2(bus_space_tag_t tag,
820 bus_space_handle_t bsh,
822 u_int16_t value, size_t count);
823 static __inline void bus_space_set_multi_4(bus_space_tag_t tag,
824 bus_space_handle_t bsh,
826 u_int32_t value, size_t count);
829 bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
830 bus_size_t offset, u_int8_t value, size_t count)
832 bus_addr_t addr = bsh + offset;
834 #if defined(_I386_BUS_PIO_H_)
835 #if defined(_I386_BUS_MEMIO_H_)
836 if (tag == I386_BUS_SPACE_IO)
841 #if defined(_I386_BUS_MEMIO_H_)
842 #if defined(_I386_BUS_PIO_H_)
846 *(volatile u_int8_t *)(addr) = value;
851 bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
852 bus_size_t offset, u_int16_t value, size_t count)
854 bus_addr_t addr = bsh + offset;
856 #if defined(_I386_BUS_PIO_H_)
857 #if defined(_I386_BUS_MEMIO_H_)
858 if (tag == I386_BUS_SPACE_IO)
863 #if defined(_I386_BUS_MEMIO_H_)
864 #if defined(_I386_BUS_PIO_H_)
868 *(volatile u_int16_t *)(addr) = value;
873 bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
874 bus_size_t offset, u_int32_t value, size_t count)
876 bus_addr_t addr = bsh + offset;
878 #if defined(_I386_BUS_PIO_H_)
879 #if defined(_I386_BUS_MEMIO_H_)
880 if (tag == I386_BUS_SPACE_IO)
885 #if defined(_I386_BUS_MEMIO_H_)
886 #if defined(_I386_BUS_PIO_H_)
890 *(volatile u_int32_t *)(addr) = value;
894 #if 0 /* Cause a link error for bus_space_set_multi_8 */
895 #define bus_space_set_multi_8 !!! bus_space_set_multi_8 unimplemented !!!
899 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
900 * by tag/handle starting at `offset'.
903 static __inline void bus_space_set_region_1(bus_space_tag_t tag,
904 bus_space_handle_t bsh,
905 bus_size_t offset, u_int8_t value,
907 static __inline void bus_space_set_region_2(bus_space_tag_t tag,
908 bus_space_handle_t bsh,
909 bus_size_t offset, u_int16_t value,
911 static __inline void bus_space_set_region_4(bus_space_tag_t tag,
912 bus_space_handle_t bsh,
913 bus_size_t offset, u_int32_t value,
917 bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
918 bus_size_t offset, u_int8_t value, size_t count)
920 bus_addr_t addr = bsh + offset;
922 #if defined(_I386_BUS_PIO_H_)
923 #if defined(_I386_BUS_MEMIO_H_)
924 if (tag == I386_BUS_SPACE_IO)
926 for (; count != 0; count--, addr++)
929 #if defined(_I386_BUS_MEMIO_H_)
930 #if defined(_I386_BUS_PIO_H_)
933 for (; count != 0; count--, addr++)
934 *(volatile u_int8_t *)(addr) = value;
939 bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
940 bus_size_t offset, u_int16_t value, size_t count)
942 bus_addr_t addr = bsh + offset;
944 #if defined(_I386_BUS_PIO_H_)
945 #if defined(_I386_BUS_MEMIO_H_)
946 if (tag == I386_BUS_SPACE_IO)
948 for (; count != 0; count--, addr += 2)
951 #if defined(_I386_BUS_MEMIO_H_)
952 #if defined(_I386_BUS_PIO_H_)
955 for (; count != 0; count--, addr += 2)
956 *(volatile u_int16_t *)(addr) = value;
961 bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
962 bus_size_t offset, u_int32_t value, size_t count)
964 bus_addr_t addr = bsh + offset;
966 #if defined(_I386_BUS_PIO_H_)
967 #if defined(_I386_BUS_MEMIO_H_)
968 if (tag == I386_BUS_SPACE_IO)
970 for (; count != 0; count--, addr += 4)
973 #if defined(_I386_BUS_MEMIO_H_)
974 #if defined(_I386_BUS_PIO_H_)
977 for (; count != 0; count--, addr += 4)
978 *(volatile u_int32_t *)(addr) = value;
982 #if 0 /* Cause a link error for bus_space_set_region_8 */
983 #define bus_space_set_region_8 !!! bus_space_set_region_8 unimplemented !!!
987 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
988 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
991 static __inline void bus_space_copy_region_1(bus_space_tag_t tag,
992 bus_space_handle_t bsh1,
994 bus_space_handle_t bsh2,
995 bus_size_t off2, size_t count);
997 static __inline void bus_space_copy_region_2(bus_space_tag_t tag,
998 bus_space_handle_t bsh1,
1000 bus_space_handle_t bsh2,
1001 bus_size_t off2, size_t count);
1003 static __inline void bus_space_copy_region_4(bus_space_tag_t tag,
1004 bus_space_handle_t bsh1,
1006 bus_space_handle_t bsh2,
1007 bus_size_t off2, size_t count);
1009 static __inline void
1010 bus_space_copy_region_1(bus_space_tag_t tag, bus_space_handle_t bsh1,
1011 bus_size_t off1, bus_space_handle_t bsh2,
1012 bus_size_t off2, size_t count)
1014 bus_addr_t addr1 = bsh1 + off1;
1015 bus_addr_t addr2 = bsh2 + off2;
1017 #if defined(_I386_BUS_PIO_H_)
1018 #if defined(_I386_BUS_MEMIO_H_)
1019 if (tag == I386_BUS_SPACE_IO)
1022 if (addr1 >= addr2) {
1023 /* src after dest: copy forward */
1024 for (; count != 0; count--, addr1++, addr2++)
1025 outb(addr2, inb(addr1));
1027 /* dest after src: copy backwards */
1028 for (addr1 += (count - 1), addr2 += (count - 1);
1029 count != 0; count--, addr1--, addr2--)
1030 outb(addr2, inb(addr1));
1034 #if defined(_I386_BUS_MEMIO_H_)
1035 #if defined(_I386_BUS_PIO_H_)
1039 if (addr1 >= addr2) {
1040 /* src after dest: copy forward */
1041 for (; count != 0; count--, addr1++, addr2++)
1042 *(volatile u_int8_t *)(addr2) =
1043 *(volatile u_int8_t *)(addr1);
1045 /* dest after src: copy backwards */
1046 for (addr1 += (count - 1), addr2 += (count - 1);
1047 count != 0; count--, addr1--, addr2--)
1048 *(volatile u_int8_t *)(addr2) =
1049 *(volatile u_int8_t *)(addr1);
1055 static __inline void
1056 bus_space_copy_region_2(bus_space_tag_t tag, bus_space_handle_t bsh1,
1057 bus_size_t off1, bus_space_handle_t bsh2,
1058 bus_size_t off2, size_t count)
1060 bus_addr_t addr1 = bsh1 + off1;
1061 bus_addr_t addr2 = bsh2 + off2;
1063 #if defined(_I386_BUS_PIO_H_)
1064 #if defined(_I386_BUS_MEMIO_H_)
1065 if (tag == I386_BUS_SPACE_IO)
1068 if (addr1 >= addr2) {
1069 /* src after dest: copy forward */
1070 for (; count != 0; count--, addr1 += 2, addr2 += 2)
1071 outw(addr2, inw(addr1));
1073 /* dest after src: copy backwards */
1074 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
1075 count != 0; count--, addr1 -= 2, addr2 -= 2)
1076 outw(addr2, inw(addr1));
1080 #if defined(_I386_BUS_MEMIO_H_)
1081 #if defined(_I386_BUS_PIO_H_)
1085 if (addr1 >= addr2) {
1086 /* src after dest: copy forward */
1087 for (; count != 0; count--, addr1 += 2, addr2 += 2)
1088 *(volatile u_int16_t *)(addr2) =
1089 *(volatile u_int16_t *)(addr1);
1091 /* dest after src: copy backwards */
1092 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
1093 count != 0; count--, addr1 -= 2, addr2 -= 2)
1094 *(volatile u_int16_t *)(addr2) =
1095 *(volatile u_int16_t *)(addr1);
1101 static __inline void
1102 bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsh1,
1103 bus_size_t off1, bus_space_handle_t bsh2,
1104 bus_size_t off2, size_t count)
1106 bus_addr_t addr1 = bsh1 + off1;
1107 bus_addr_t addr2 = bsh2 + off2;
1109 #if defined(_I386_BUS_PIO_H_)
1110 #if defined(_I386_BUS_MEMIO_H_)
1111 if (tag == I386_BUS_SPACE_IO)
1114 if (addr1 >= addr2) {
1115 /* src after dest: copy forward */
1116 for (; count != 0; count--, addr1 += 4, addr2 += 4)
1117 outl(addr2, inl(addr1));
1119 /* dest after src: copy backwards */
1120 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
1121 count != 0; count--, addr1 -= 4, addr2 -= 4)
1122 outl(addr2, inl(addr1));
1126 #if defined(_I386_BUS_MEMIO_H_)
1127 #if defined(_I386_BUS_PIO_H_)
1131 if (addr1 >= addr2) {
1132 /* src after dest: copy forward */
1133 for (; count != 0; count--, addr1 += 4, addr2 += 4)
1134 *(volatile u_int32_t *)(addr2) =
1135 *(volatile u_int32_t *)(addr1);
1137 /* dest after src: copy backwards */
1138 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
1139 count != 0; count--, addr1 -= 4, addr2 -= 4)
1140 *(volatile u_int32_t *)(addr2) =
1141 *(volatile u_int32_t *)(addr1);
1147 #endif /* defined(_I386_BUS_PIO_H_) || defined(_I386_MEM_IO_H_) */
1149 #if 0 /* Cause a link error for bus_space_copy_8 */
1150 #define bus_space_copy_region_8 !!! bus_space_copy_region_8 unimplemented !!!
1154 * Bus read/write barrier methods.
1156 * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
1157 * bus_size_t offset, bus_size_t len, int flags);
1159 * Note that BUS_SPACE_BARRIER_WRITE doesn't do anything other than
1160 * prevent reordering by the compiler; all Intel x86 processors currently
1161 * retire operations outside the CPU in program order.
1163 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
1164 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
1166 static __inline void
1167 bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
1168 bus_size_t offset, bus_size_t len, int flags)
1170 if (flags & BUS_SPACE_BARRIER_READ)
1171 __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory");
1173 __asm __volatile("" : : : "memory");
1176 #endif /* _I386_BUS_AT386_H_ */