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 /* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */
37 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
38 * All rights reserved.
40 * This code is derived from software contributed to The NetBSD Foundation
41 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
42 * NASA Ames Research Center.
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.
53 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
54 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
55 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
57 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
58 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
59 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
60 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
61 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
62 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
63 * POSSIBILITY OF SUCH DAMAGE.
67 * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
68 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
70 * Redistribution and use in source and binary forms, with or without
71 * modification, are permitted provided that the following conditions
73 * 1. Redistributions of source code must retain the above copyright
74 * notice, this list of conditions and the following disclaimer.
75 * 2. Redistributions in binary form must reproduce the above copyright
76 * notice, this list of conditions and the following disclaimer in the
77 * documentation and/or other materials provided with the distribution.
78 * 3. All advertising materials mentioning features or use of this software
79 * must display the following acknowledgement:
80 * This product includes software developed by Christopher G. Demetriou
81 * for the NetBSD Project.
82 * 4. The name of the author may not be used to endorse or promote products
83 * derived from this software without specific prior written permission
85 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
86 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
87 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
88 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
89 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
90 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
91 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
92 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
93 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
94 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
100 #include <machine/_bus.h>
101 #include <machine/cpufunc.h>
103 #ifndef __GNUCLIKE_ASM
105 # error "no assembler code for your compiler"
110 * Values for the x86 bus space tag, not to be used directly by MI code.
112 #define X86_BUS_SPACE_IO 0 /* space is i/o space */
113 #define X86_BUS_SPACE_MEM 1 /* space is mem space */
115 #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF
116 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
117 #define BUS_SPACE_MAXSIZE 0xFFFFFFFF
118 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF
119 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
120 #if defined(__amd64__) || defined(PAE)
121 #define BUS_SPACE_MAXADDR 0xFFFFFFFFFFFFFFFFULL
123 #define BUS_SPACE_MAXADDR 0xFFFFFFFF
126 #define BUS_SPACE_UNRESTRICTED (~0)
129 * Map a region of device bus space into CPU virtual address space.
132 static __inline int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
133 bus_size_t size, int flags,
134 bus_space_handle_t *bshp);
137 bus_space_map(bus_space_tag_t t __unused, bus_addr_t addr,
138 bus_size_t size __unused, int flags __unused,
139 bus_space_handle_t *bshp)
147 * Unmap a region of device bus space.
150 static __inline void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
154 bus_space_unmap(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused,
155 bus_size_t size __unused)
160 * Get a new handle for a subregion of an already-mapped area of bus space.
163 static __inline int bus_space_subregion(bus_space_tag_t t,
164 bus_space_handle_t bsh,
165 bus_size_t offset, bus_size_t size,
166 bus_space_handle_t *nbshp);
169 bus_space_subregion(bus_space_tag_t t __unused, bus_space_handle_t bsh,
170 bus_size_t offset, bus_size_t size __unused,
171 bus_space_handle_t *nbshp)
174 *nbshp = bsh + offset;
179 * Allocate a region of memory that is accessible to devices in bus space.
182 int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
183 bus_addr_t rend, bus_size_t size, bus_size_t align,
184 bus_size_t boundary, int flags, bus_addr_t *addrp,
185 bus_space_handle_t *bshp);
188 * Free a region of bus space accessible memory.
191 static __inline void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
195 bus_space_free(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused,
196 bus_size_t size __unused)
202 * Read a 1, 2, 4, or 8 byte quantity from bus space
203 * described by tag/handle/offset.
205 static __inline u_int8_t bus_space_read_1(bus_space_tag_t tag,
206 bus_space_handle_t handle,
209 static __inline u_int16_t bus_space_read_2(bus_space_tag_t tag,
210 bus_space_handle_t handle,
213 static __inline u_int32_t bus_space_read_4(bus_space_tag_t tag,
214 bus_space_handle_t handle,
217 static __inline u_int8_t
218 bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle,
222 if (tag == X86_BUS_SPACE_IO)
223 return (inb(handle + offset));
224 return (*(volatile u_int8_t *)(handle + offset));
227 static __inline u_int16_t
228 bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle,
232 if (tag == X86_BUS_SPACE_IO)
233 return (inw(handle + offset));
234 return (*(volatile u_int16_t *)(handle + offset));
237 static __inline u_int32_t
238 bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle,
242 if (tag == X86_BUS_SPACE_IO)
243 return (inl(handle + offset));
244 return (*(volatile u_int32_t *)(handle + offset));
247 #if 0 /* Cause a link error for bus_space_read_8 */
248 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
252 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
253 * described by tag/handle/offset and copy into buffer provided.
255 static __inline void bus_space_read_multi_1(bus_space_tag_t tag,
256 bus_space_handle_t bsh,
257 bus_size_t offset, u_int8_t *addr,
260 static __inline void bus_space_read_multi_2(bus_space_tag_t tag,
261 bus_space_handle_t bsh,
262 bus_size_t offset, u_int16_t *addr,
265 static __inline void bus_space_read_multi_4(bus_space_tag_t tag,
266 bus_space_handle_t bsh,
267 bus_size_t offset, u_int32_t *addr,
271 bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
272 bus_size_t offset, u_int8_t *addr, size_t count)
275 if (tag == X86_BUS_SPACE_IO)
276 insb(bsh + offset, addr, count);
278 #ifdef __GNUCLIKE_ASM
279 __asm __volatile(" \n\
281 1: movb (%2),%%al \n\
284 "=D" (addr), "=c" (count) :
285 "r" (bsh + offset), "0" (addr), "1" (count) :
292 bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
293 bus_size_t offset, u_int16_t *addr, size_t count)
296 if (tag == X86_BUS_SPACE_IO)
297 insw(bsh + offset, addr, count);
299 #ifdef __GNUCLIKE_ASM
300 __asm __volatile(" \n\
302 1: movw (%2),%%ax \n\
305 "=D" (addr), "=c" (count) :
306 "r" (bsh + offset), "0" (addr), "1" (count) :
313 bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
314 bus_size_t offset, u_int32_t *addr, size_t count)
317 if (tag == X86_BUS_SPACE_IO)
318 insl(bsh + offset, addr, count);
320 #ifdef __GNUCLIKE_ASM
321 __asm __volatile(" \n\
323 1: movl (%2),%%eax \n\
326 "=D" (addr), "=c" (count) :
327 "r" (bsh + offset), "0" (addr), "1" (count) :
333 #if 0 /* Cause a link error for bus_space_read_multi_8 */
334 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
338 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
339 * described by tag/handle and starting at `offset' and copy into
342 static __inline void bus_space_read_region_1(bus_space_tag_t tag,
343 bus_space_handle_t bsh,
344 bus_size_t offset, u_int8_t *addr,
347 static __inline void bus_space_read_region_2(bus_space_tag_t tag,
348 bus_space_handle_t bsh,
349 bus_size_t offset, u_int16_t *addr,
352 static __inline void bus_space_read_region_4(bus_space_tag_t tag,
353 bus_space_handle_t bsh,
354 bus_size_t offset, u_int32_t *addr,
359 bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
360 bus_size_t offset, u_int8_t *addr, size_t count)
363 if (tag == X86_BUS_SPACE_IO) {
364 int _port_ = bsh + offset;
365 #ifdef __GNUCLIKE_ASM
366 __asm __volatile(" \n\
372 "=D" (addr), "=c" (count), "=d" (_port_) :
373 "0" (addr), "1" (count), "2" (_port_) :
374 "%eax", "memory", "cc");
377 bus_space_handle_t _port_ = bsh + offset;
378 #ifdef __GNUCLIKE_ASM
379 __asm __volatile(" \n\
383 "=D" (addr), "=c" (count), "=S" (_port_) :
384 "0" (addr), "1" (count), "2" (_port_) :
391 bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
392 bus_size_t offset, u_int16_t *addr, size_t count)
395 if (tag == X86_BUS_SPACE_IO) {
396 int _port_ = bsh + offset;
397 #ifdef __GNUCLIKE_ASM
398 __asm __volatile(" \n\
404 "=D" (addr), "=c" (count), "=d" (_port_) :
405 "0" (addr), "1" (count), "2" (_port_) :
406 "%eax", "memory", "cc");
409 bus_space_handle_t _port_ = bsh + offset;
410 #ifdef __GNUCLIKE_ASM
411 __asm __volatile(" \n\
415 "=D" (addr), "=c" (count), "=S" (_port_) :
416 "0" (addr), "1" (count), "2" (_port_) :
423 bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
424 bus_size_t offset, u_int32_t *addr, size_t count)
427 if (tag == X86_BUS_SPACE_IO) {
428 int _port_ = bsh + offset;
429 #ifdef __GNUCLIKE_ASM
430 __asm __volatile(" \n\
436 "=D" (addr), "=c" (count), "=d" (_port_) :
437 "0" (addr), "1" (count), "2" (_port_) :
438 "%eax", "memory", "cc");
441 bus_space_handle_t _port_ = bsh + offset;
442 #ifdef __GNUCLIKE_ASM
443 __asm __volatile(" \n\
447 "=D" (addr), "=c" (count), "=S" (_port_) :
448 "0" (addr), "1" (count), "2" (_port_) :
454 #if 0 /* Cause a link error for bus_space_read_region_8 */
455 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
459 * Write the 1, 2, 4, or 8 byte value `value' to bus space
460 * described by tag/handle/offset.
463 static __inline void bus_space_write_1(bus_space_tag_t tag,
464 bus_space_handle_t bsh,
465 bus_size_t offset, u_int8_t value);
467 static __inline void bus_space_write_2(bus_space_tag_t tag,
468 bus_space_handle_t bsh,
469 bus_size_t offset, u_int16_t value);
471 static __inline void bus_space_write_4(bus_space_tag_t tag,
472 bus_space_handle_t bsh,
473 bus_size_t offset, u_int32_t value);
476 bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsh,
477 bus_size_t offset, u_int8_t value)
480 if (tag == X86_BUS_SPACE_IO)
481 outb(bsh + offset, value);
483 *(volatile u_int8_t *)(bsh + offset) = value;
487 bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t bsh,
488 bus_size_t offset, u_int16_t value)
491 if (tag == X86_BUS_SPACE_IO)
492 outw(bsh + offset, value);
494 *(volatile u_int16_t *)(bsh + offset) = value;
498 bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh,
499 bus_size_t offset, u_int32_t value)
502 if (tag == X86_BUS_SPACE_IO)
503 outl(bsh + offset, value);
505 *(volatile u_int32_t *)(bsh + offset) = value;
508 #if 0 /* Cause a link error for bus_space_write_8 */
509 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
513 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
514 * provided to bus space described by tag/handle/offset.
517 static __inline void bus_space_write_multi_1(bus_space_tag_t tag,
518 bus_space_handle_t bsh,
520 const u_int8_t *addr,
522 static __inline void bus_space_write_multi_2(bus_space_tag_t tag,
523 bus_space_handle_t bsh,
525 const u_int16_t *addr,
528 static __inline void bus_space_write_multi_4(bus_space_tag_t tag,
529 bus_space_handle_t bsh,
531 const u_int32_t *addr,
535 bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
536 bus_size_t offset, const u_int8_t *addr, size_t count)
539 if (tag == X86_BUS_SPACE_IO)
540 outsb(bsh + offset, addr, count);
542 #ifdef __GNUCLIKE_ASM
543 __asm __volatile(" \n\
548 "=S" (addr), "=c" (count) :
549 "r" (bsh + offset), "0" (addr), "1" (count) :
550 "%eax", "memory", "cc");
556 bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
557 bus_size_t offset, const u_int16_t *addr, size_t count)
560 if (tag == X86_BUS_SPACE_IO)
561 outsw(bsh + offset, addr, count);
563 #ifdef __GNUCLIKE_ASM
564 __asm __volatile(" \n\
569 "=S" (addr), "=c" (count) :
570 "r" (bsh + offset), "0" (addr), "1" (count) :
571 "%eax", "memory", "cc");
577 bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
578 bus_size_t offset, const u_int32_t *addr, size_t count)
581 if (tag == X86_BUS_SPACE_IO)
582 outsl(bsh + offset, addr, count);
584 #ifdef __GNUCLIKE_ASM
585 __asm __volatile(" \n\
590 "=S" (addr), "=c" (count) :
591 "r" (bsh + offset), "0" (addr), "1" (count) :
592 "%eax", "memory", "cc");
597 #if 0 /* Cause a link error for bus_space_write_multi_8 */
598 #define bus_space_write_multi_8(t, h, o, a, c) \
599 !!! bus_space_write_multi_8 unimplemented !!!
603 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
604 * to bus space described by tag/handle starting at `offset'.
607 static __inline void bus_space_write_region_1(bus_space_tag_t tag,
608 bus_space_handle_t bsh,
610 const u_int8_t *addr,
612 static __inline void bus_space_write_region_2(bus_space_tag_t tag,
613 bus_space_handle_t bsh,
615 const u_int16_t *addr,
617 static __inline void bus_space_write_region_4(bus_space_tag_t tag,
618 bus_space_handle_t bsh,
620 const u_int32_t *addr,
624 bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
625 bus_size_t offset, const u_int8_t *addr, size_t count)
628 if (tag == X86_BUS_SPACE_IO) {
629 int _port_ = bsh + offset;
630 #ifdef __GNUCLIKE_ASM
631 __asm __volatile(" \n\
637 "=d" (_port_), "=S" (addr), "=c" (count) :
638 "0" (_port_), "1" (addr), "2" (count) :
639 "%eax", "memory", "cc");
642 bus_space_handle_t _port_ = bsh + offset;
643 #ifdef __GNUCLIKE_ASM
644 __asm __volatile(" \n\
648 "=D" (_port_), "=S" (addr), "=c" (count) :
649 "0" (_port_), "1" (addr), "2" (count) :
656 bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
657 bus_size_t offset, const u_int16_t *addr, size_t count)
660 if (tag == X86_BUS_SPACE_IO) {
661 int _port_ = bsh + offset;
662 #ifdef __GNUCLIKE_ASM
663 __asm __volatile(" \n\
669 "=d" (_port_), "=S" (addr), "=c" (count) :
670 "0" (_port_), "1" (addr), "2" (count) :
671 "%eax", "memory", "cc");
674 bus_space_handle_t _port_ = bsh + offset;
675 #ifdef __GNUCLIKE_ASM
676 __asm __volatile(" \n\
680 "=D" (_port_), "=S" (addr), "=c" (count) :
681 "0" (_port_), "1" (addr), "2" (count) :
688 bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
689 bus_size_t offset, const u_int32_t *addr, size_t count)
692 if (tag == X86_BUS_SPACE_IO) {
693 int _port_ = bsh + offset;
694 #ifdef __GNUCLIKE_ASM
695 __asm __volatile(" \n\
701 "=d" (_port_), "=S" (addr), "=c" (count) :
702 "0" (_port_), "1" (addr), "2" (count) :
703 "%eax", "memory", "cc");
706 bus_space_handle_t _port_ = bsh + offset;
707 #ifdef __GNUCLIKE_ASM
708 __asm __volatile(" \n\
712 "=D" (_port_), "=S" (addr), "=c" (count) :
713 "0" (_port_), "1" (addr), "2" (count) :
719 #if 0 /* Cause a link error for bus_space_write_region_8 */
720 #define bus_space_write_region_8 \
721 !!! bus_space_write_region_8 unimplemented !!!
725 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
726 * by tag/handle/offset `count' times.
729 static __inline void bus_space_set_multi_1(bus_space_tag_t tag,
730 bus_space_handle_t bsh,
732 u_int8_t value, size_t count);
733 static __inline void bus_space_set_multi_2(bus_space_tag_t tag,
734 bus_space_handle_t bsh,
736 u_int16_t value, size_t count);
737 static __inline void bus_space_set_multi_4(bus_space_tag_t tag,
738 bus_space_handle_t bsh,
740 u_int32_t value, size_t count);
743 bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
744 bus_size_t offset, u_int8_t value, size_t count)
746 bus_space_handle_t addr = bsh + offset;
748 if (tag == X86_BUS_SPACE_IO)
753 *(volatile u_int8_t *)(addr) = value;
757 bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
758 bus_size_t offset, u_int16_t value, size_t count)
760 bus_space_handle_t addr = bsh + offset;
762 if (tag == X86_BUS_SPACE_IO)
767 *(volatile u_int16_t *)(addr) = value;
771 bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
772 bus_size_t offset, u_int32_t value, size_t count)
774 bus_space_handle_t addr = bsh + offset;
776 if (tag == X86_BUS_SPACE_IO)
781 *(volatile u_int32_t *)(addr) = value;
784 #if 0 /* Cause a link error for bus_space_set_multi_8 */
785 #define bus_space_set_multi_8 !!! bus_space_set_multi_8 unimplemented !!!
789 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
790 * by tag/handle starting at `offset'.
793 static __inline void bus_space_set_region_1(bus_space_tag_t tag,
794 bus_space_handle_t bsh,
795 bus_size_t offset, u_int8_t value,
797 static __inline void bus_space_set_region_2(bus_space_tag_t tag,
798 bus_space_handle_t bsh,
799 bus_size_t offset, u_int16_t value,
801 static __inline void bus_space_set_region_4(bus_space_tag_t tag,
802 bus_space_handle_t bsh,
803 bus_size_t offset, u_int32_t value,
807 bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
808 bus_size_t offset, u_int8_t value, size_t count)
810 bus_space_handle_t addr = bsh + offset;
812 if (tag == X86_BUS_SPACE_IO)
813 for (; count != 0; count--, addr++)
816 for (; count != 0; count--, addr++)
817 *(volatile u_int8_t *)(addr) = value;
821 bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
822 bus_size_t offset, u_int16_t value, size_t count)
824 bus_space_handle_t addr = bsh + offset;
826 if (tag == X86_BUS_SPACE_IO)
827 for (; count != 0; count--, addr += 2)
830 for (; count != 0; count--, addr += 2)
831 *(volatile u_int16_t *)(addr) = value;
835 bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
836 bus_size_t offset, u_int32_t value, size_t count)
838 bus_space_handle_t addr = bsh + offset;
840 if (tag == X86_BUS_SPACE_IO)
841 for (; count != 0; count--, addr += 4)
844 for (; count != 0; count--, addr += 4)
845 *(volatile u_int32_t *)(addr) = value;
848 #if 0 /* Cause a link error for bus_space_set_region_8 */
849 #define bus_space_set_region_8 !!! bus_space_set_region_8 unimplemented !!!
853 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
854 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
857 static __inline void bus_space_copy_region_1(bus_space_tag_t tag,
858 bus_space_handle_t bsh1,
860 bus_space_handle_t bsh2,
861 bus_size_t off2, size_t count);
863 static __inline void bus_space_copy_region_2(bus_space_tag_t tag,
864 bus_space_handle_t bsh1,
866 bus_space_handle_t bsh2,
867 bus_size_t off2, size_t count);
869 static __inline void bus_space_copy_region_4(bus_space_tag_t tag,
870 bus_space_handle_t bsh1,
872 bus_space_handle_t bsh2,
873 bus_size_t off2, size_t count);
876 bus_space_copy_region_1(bus_space_tag_t tag, bus_space_handle_t bsh1,
877 bus_size_t off1, bus_space_handle_t bsh2,
878 bus_size_t off2, size_t count)
880 bus_space_handle_t addr1 = bsh1 + off1;
881 bus_space_handle_t addr2 = bsh2 + off2;
883 if (tag == X86_BUS_SPACE_IO) {
884 if (addr1 >= addr2) {
885 /* src after dest: copy forward */
886 for (; count != 0; count--, addr1++, addr2++)
887 outb(addr2, inb(addr1));
889 /* dest after src: copy backwards */
890 for (addr1 += (count - 1), addr2 += (count - 1);
891 count != 0; count--, addr1--, addr2--)
892 outb(addr2, inb(addr1));
895 if (addr1 >= addr2) {
896 /* src after dest: copy forward */
897 for (; count != 0; count--, addr1++, addr2++)
898 *(volatile u_int8_t *)(addr2) =
899 *(volatile u_int8_t *)(addr1);
901 /* dest after src: copy backwards */
902 for (addr1 += (count - 1), addr2 += (count - 1);
903 count != 0; count--, addr1--, addr2--)
904 *(volatile u_int8_t *)(addr2) =
905 *(volatile u_int8_t *)(addr1);
911 bus_space_copy_region_2(bus_space_tag_t tag, bus_space_handle_t bsh1,
912 bus_size_t off1, bus_space_handle_t bsh2,
913 bus_size_t off2, size_t count)
915 bus_space_handle_t addr1 = bsh1 + off1;
916 bus_space_handle_t addr2 = bsh2 + off2;
918 if (tag == X86_BUS_SPACE_IO) {
919 if (addr1 >= addr2) {
920 /* src after dest: copy forward */
921 for (; count != 0; count--, addr1 += 2, addr2 += 2)
922 outw(addr2, inw(addr1));
924 /* dest after src: copy backwards */
925 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
926 count != 0; count--, addr1 -= 2, addr2 -= 2)
927 outw(addr2, inw(addr1));
930 if (addr1 >= addr2) {
931 /* src after dest: copy forward */
932 for (; count != 0; count--, addr1 += 2, addr2 += 2)
933 *(volatile u_int16_t *)(addr2) =
934 *(volatile u_int16_t *)(addr1);
936 /* dest after src: copy backwards */
937 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
938 count != 0; count--, addr1 -= 2, addr2 -= 2)
939 *(volatile u_int16_t *)(addr2) =
940 *(volatile u_int16_t *)(addr1);
946 bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsh1,
947 bus_size_t off1, bus_space_handle_t bsh2,
948 bus_size_t off2, size_t count)
950 bus_space_handle_t addr1 = bsh1 + off1;
951 bus_space_handle_t addr2 = bsh2 + off2;
953 if (tag == X86_BUS_SPACE_IO) {
954 if (addr1 >= addr2) {
955 /* src after dest: copy forward */
956 for (; count != 0; count--, addr1 += 4, addr2 += 4)
957 outl(addr2, inl(addr1));
959 /* dest after src: copy backwards */
960 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
961 count != 0; count--, addr1 -= 4, addr2 -= 4)
962 outl(addr2, inl(addr1));
965 if (addr1 >= addr2) {
966 /* src after dest: copy forward */
967 for (; count != 0; count--, addr1 += 4, addr2 += 4)
968 *(volatile u_int32_t *)(addr2) =
969 *(volatile u_int32_t *)(addr1);
971 /* dest after src: copy backwards */
972 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
973 count != 0; count--, addr1 -= 4, addr2 -= 4)
974 *(volatile u_int32_t *)(addr2) =
975 *(volatile u_int32_t *)(addr1);
980 #if 0 /* Cause a link error for bus_space_copy_8 */
981 #define bus_space_copy_region_8 !!! bus_space_copy_region_8 unimplemented !!!
985 * Bus read/write barrier methods.
987 * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
988 * bus_size_t offset, bus_size_t len, int flags);
991 * Note that BUS_SPACE_BARRIER_WRITE doesn't do anything other than
992 * prevent reordering by the compiler; all Intel x86 processors currently
993 * retire operations outside the CPU in program order.
995 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
996 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
999 bus_space_barrier(bus_space_tag_t tag __unused, bus_space_handle_t bsh __unused,
1000 bus_size_t offset __unused, bus_size_t len __unused, int flags)
1002 #ifdef __GNUCLIKE_ASM
1003 if (flags & BUS_SPACE_BARRIER_READ)
1005 __asm __volatile("lock; addl $0,0(%%rsp)" : : : "memory");
1007 __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory");
1010 __compiler_membar();
1014 #ifdef BUS_SPACE_NO_LEGACY
1017 #define inb(a) compiler_error
1018 #define inw(a) compiler_error
1019 #define inl(a) compiler_error
1020 #define outb(a, b) compiler_error
1021 #define outw(a, b) compiler_error
1022 #define outl(a, b) compiler_error
1025 #include <machine/bus_dma.h>
1028 * Stream accesses are the same as normal accesses on x86; there are no
1029 * supported bus systems with an endianess different from the host one.
1031 #define bus_space_read_stream_1(t, h, o) bus_space_read_1((t), (h), (o))
1032 #define bus_space_read_stream_2(t, h, o) bus_space_read_2((t), (h), (o))
1033 #define bus_space_read_stream_4(t, h, o) bus_space_read_4((t), (h), (o))
1035 #define bus_space_read_multi_stream_1(t, h, o, a, c) \
1036 bus_space_read_multi_1((t), (h), (o), (a), (c))
1037 #define bus_space_read_multi_stream_2(t, h, o, a, c) \
1038 bus_space_read_multi_2((t), (h), (o), (a), (c))
1039 #define bus_space_read_multi_stream_4(t, h, o, a, c) \
1040 bus_space_read_multi_4((t), (h), (o), (a), (c))
1042 #define bus_space_write_stream_1(t, h, o, v) \
1043 bus_space_write_1((t), (h), (o), (v))
1044 #define bus_space_write_stream_2(t, h, o, v) \
1045 bus_space_write_2((t), (h), (o), (v))
1046 #define bus_space_write_stream_4(t, h, o, v) \
1047 bus_space_write_4((t), (h), (o), (v))
1049 #define bus_space_write_multi_stream_1(t, h, o, a, c) \
1050 bus_space_write_multi_1((t), (h), (o), (a), (c))
1051 #define bus_space_write_multi_stream_2(t, h, o, a, c) \
1052 bus_space_write_multi_2((t), (h), (o), (a), (c))
1053 #define bus_space_write_multi_stream_4(t, h, o, a, c) \
1054 bus_space_write_multi_4((t), (h), (o), (a), (c))
1056 #define bus_space_set_multi_stream_1(t, h, o, v, c) \
1057 bus_space_set_multi_1((t), (h), (o), (v), (c))
1058 #define bus_space_set_multi_stream_2(t, h, o, v, c) \
1059 bus_space_set_multi_2((t), (h), (o), (v), (c))
1060 #define bus_space_set_multi_stream_4(t, h, o, v, c) \
1061 bus_space_set_multi_4((t), (h), (o), (v), (c))
1063 #define bus_space_read_region_stream_1(t, h, o, a, c) \
1064 bus_space_read_region_1((t), (h), (o), (a), (c))
1065 #define bus_space_read_region_stream_2(t, h, o, a, c) \
1066 bus_space_read_region_2((t), (h), (o), (a), (c))
1067 #define bus_space_read_region_stream_4(t, h, o, a, c) \
1068 bus_space_read_region_4((t), (h), (o), (a), (c))
1070 #define bus_space_write_region_stream_1(t, h, o, a, c) \
1071 bus_space_write_region_1((t), (h), (o), (a), (c))
1072 #define bus_space_write_region_stream_2(t, h, o, a, c) \
1073 bus_space_write_region_2((t), (h), (o), (a), (c))
1074 #define bus_space_write_region_stream_4(t, h, o, a, c) \
1075 bus_space_write_region_4((t), (h), (o), (a), (c))
1077 #define bus_space_set_region_stream_1(t, h, o, v, c) \
1078 bus_space_set_region_1((t), (h), (o), (v), (c))
1079 #define bus_space_set_region_stream_2(t, h, o, v, c) \
1080 bus_space_set_region_2((t), (h), (o), (v), (c))
1081 #define bus_space_set_region_stream_4(t, h, o, v, c) \
1082 bus_space_set_region_4((t), (h), (o), (v), (c))
1084 #define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \
1085 bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
1086 #define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \
1087 bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c))
1088 #define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \
1089 bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c))
1091 #endif /* _X86_BUS_H_ */