2 * SPDX-License-Identifier: BSD-3-Clause AND BSD-2-Clause-NetBSDE
4 * Copyright (c) KATO Takenori, 1999.
6 * All rights reserved. Unpublished rights reserved under the copyright
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer as
15 * the first lines of this file unmodified.
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. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 /* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */
39 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
40 * All rights reserved.
42 * This code is derived from software contributed to The NetBSD Foundation
43 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
44 * NASA Ames Research Center.
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
55 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
56 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
57 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
59 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
61 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
62 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
65 * POSSIBILITY OF SUCH DAMAGE.
69 * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
70 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
75 * 1. Redistributions of source code must retain the above copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright
78 * notice, this list of conditions and the following disclaimer in the
79 * documentation and/or other materials provided with the distribution.
80 * 3. All advertising materials mentioning features or use of this software
81 * must display the following acknowledgement:
82 * This product includes software developed by Christopher G. Demetriou
83 * for the NetBSD Project.
84 * 4. The name of the author may not be used to endorse or promote products
85 * derived from this software without specific prior written permission
87 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
88 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
90 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
91 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
92 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
93 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
94 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
95 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
96 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
102 #include <machine/_bus.h>
103 #include <machine/cpufunc.h>
105 #ifndef __GNUCLIKE_ASM
106 #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 #if defined(__amd64__)
118 #define BUS_SPACE_MAXSIZE 0xFFFFFFFFFFFFFFFFULL
120 #define BUS_SPACE_MAXSIZE 0xFFFFFFFF
122 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF
123 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
124 #if defined(__amd64__) || defined(PAE)
125 #define BUS_SPACE_MAXADDR_48BIT 0xFFFFFFFFFFFFULL
126 #define BUS_SPACE_MAXADDR 0xFFFFFFFFFFFFFFFFULL
128 #define BUS_SPACE_MAXADDR 0xFFFFFFFF
131 #define BUS_SPACE_INVALID_DATA (~0)
132 #define BUS_SPACE_UNRESTRICTED (~0)
135 * Map a region of device bus space into CPU virtual address space.
138 int bus_space_map(bus_space_tag_t tag, bus_addr_t addr, bus_size_t size,
139 int flags, bus_space_handle_t *bshp);
142 * Unmap a region of device bus space.
145 void bus_space_unmap(bus_space_tag_t tag, bus_space_handle_t bsh,
149 * Get a new handle for a subregion of an already-mapped area of bus space.
152 static __inline int bus_space_subregion(bus_space_tag_t t,
153 bus_space_handle_t bsh,
154 bus_size_t offset, bus_size_t size,
155 bus_space_handle_t *nbshp);
158 bus_space_subregion(bus_space_tag_t t __unused, bus_space_handle_t bsh,
159 bus_size_t offset, bus_size_t size __unused,
160 bus_space_handle_t *nbshp)
163 *nbshp = bsh + offset;
168 * Allocate a region of memory that is accessible to devices in bus space.
171 int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
172 bus_addr_t rend, bus_size_t size, bus_size_t align,
173 bus_size_t boundary, int flags, bus_addr_t *addrp,
174 bus_space_handle_t *bshp);
177 * Free a region of bus space accessible memory.
180 static __inline void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
184 bus_space_free(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused,
185 bus_size_t size __unused)
191 * Read a 1, 2, 4, or 8 byte quantity from bus space
192 * described by tag/handle/offset.
194 static __inline u_int8_t bus_space_read_1(bus_space_tag_t tag,
195 bus_space_handle_t handle,
198 static __inline u_int16_t bus_space_read_2(bus_space_tag_t tag,
199 bus_space_handle_t handle,
202 static __inline u_int32_t bus_space_read_4(bus_space_tag_t tag,
203 bus_space_handle_t handle,
207 static __inline uint64_t bus_space_read_8(bus_space_tag_t tag,
208 bus_space_handle_t handle,
212 static __inline u_int8_t
213 bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle,
217 if (tag == X86_BUS_SPACE_IO)
218 return (inb(handle + offset));
219 return (*(volatile u_int8_t *)(handle + offset));
222 static __inline u_int16_t
223 bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle,
227 if (tag == X86_BUS_SPACE_IO)
228 return (inw(handle + offset));
229 return (*(volatile u_int16_t *)(handle + offset));
232 static __inline u_int32_t
233 bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle,
237 if (tag == X86_BUS_SPACE_IO)
238 return (inl(handle + offset));
239 return (*(volatile u_int32_t *)(handle + offset));
243 static __inline uint64_t
244 bus_space_read_8(bus_space_tag_t tag, bus_space_handle_t handle,
248 if (tag == X86_BUS_SPACE_IO) /* No 8 byte IO space access on x86 */
249 return (BUS_SPACE_INVALID_DATA);
250 return (*(volatile uint64_t *)(handle + offset));
255 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
256 * described by tag/handle/offset and copy into buffer provided.
258 static __inline void bus_space_read_multi_1(bus_space_tag_t tag,
259 bus_space_handle_t bsh,
260 bus_size_t offset, u_int8_t *addr,
263 static __inline void bus_space_read_multi_2(bus_space_tag_t tag,
264 bus_space_handle_t bsh,
265 bus_size_t offset, u_int16_t *addr,
268 static __inline void bus_space_read_multi_4(bus_space_tag_t tag,
269 bus_space_handle_t bsh,
270 bus_size_t offset, u_int32_t *addr,
274 bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
275 bus_size_t offset, u_int8_t *addr, size_t count)
278 if (tag == X86_BUS_SPACE_IO)
279 insb(bsh + offset, addr, count);
281 #ifdef __GNUCLIKE_ASM
282 __asm __volatile(" \n\
283 1: movb (%2),%%al \n\
286 "=D" (addr), "=c" (count) :
287 "r" (bsh + offset), "0" (addr), "1" (count) :
294 bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
295 bus_size_t offset, u_int16_t *addr, size_t count)
298 if (tag == X86_BUS_SPACE_IO)
299 insw(bsh + offset, addr, count);
301 #ifdef __GNUCLIKE_ASM
302 __asm __volatile(" \n\
303 1: movw (%2),%%ax \n\
306 "=D" (addr), "=c" (count) :
307 "r" (bsh + offset), "0" (addr), "1" (count) :
314 bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
315 bus_size_t offset, u_int32_t *addr, size_t count)
318 if (tag == X86_BUS_SPACE_IO)
319 insl(bsh + offset, addr, count);
321 #ifdef __GNUCLIKE_ASM
322 __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\
371 "=D" (addr), "=c" (count), "=d" (_port_) :
372 "0" (addr), "1" (count), "2" (_port_) :
373 "%eax", "memory", "cc");
376 bus_space_handle_t _port_ = bsh + offset;
377 #ifdef __GNUCLIKE_ASM
378 __asm __volatile(" \n\
381 "=D" (addr), "=c" (count), "=S" (_port_) :
382 "0" (addr), "1" (count), "2" (_port_) :
389 bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
390 bus_size_t offset, u_int16_t *addr, size_t count)
393 if (tag == X86_BUS_SPACE_IO) {
394 int _port_ = bsh + offset;
395 #ifdef __GNUCLIKE_ASM
396 __asm __volatile(" \n\
401 "=D" (addr), "=c" (count), "=d" (_port_) :
402 "0" (addr), "1" (count), "2" (_port_) :
403 "%eax", "memory", "cc");
406 bus_space_handle_t _port_ = bsh + offset;
407 #ifdef __GNUCLIKE_ASM
408 __asm __volatile(" \n\
411 "=D" (addr), "=c" (count), "=S" (_port_) :
412 "0" (addr), "1" (count), "2" (_port_) :
419 bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
420 bus_size_t offset, u_int32_t *addr, size_t count)
423 if (tag == X86_BUS_SPACE_IO) {
424 int _port_ = bsh + offset;
425 #ifdef __GNUCLIKE_ASM
426 __asm __volatile(" \n\
431 "=D" (addr), "=c" (count), "=d" (_port_) :
432 "0" (addr), "1" (count), "2" (_port_) :
433 "%eax", "memory", "cc");
436 bus_space_handle_t _port_ = bsh + offset;
437 #ifdef __GNUCLIKE_ASM
438 __asm __volatile(" \n\
441 "=D" (addr), "=c" (count), "=S" (_port_) :
442 "0" (addr), "1" (count), "2" (_port_) :
448 #if 0 /* Cause a link error for bus_space_read_region_8 */
449 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
453 * Write the 1, 2, 4, or 8 byte value `value' to bus space
454 * described by tag/handle/offset.
457 static __inline void bus_space_write_1(bus_space_tag_t tag,
458 bus_space_handle_t bsh,
459 bus_size_t offset, u_int8_t value);
461 static __inline void bus_space_write_2(bus_space_tag_t tag,
462 bus_space_handle_t bsh,
463 bus_size_t offset, u_int16_t value);
465 static __inline void bus_space_write_4(bus_space_tag_t tag,
466 bus_space_handle_t bsh,
467 bus_size_t offset, u_int32_t value);
470 static __inline void bus_space_write_8(bus_space_tag_t tag,
471 bus_space_handle_t bsh,
472 bus_size_t offset, uint64_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;
510 bus_space_write_8(bus_space_tag_t tag, bus_space_handle_t bsh,
511 bus_size_t offset, uint64_t value)
514 if (tag == X86_BUS_SPACE_IO) /* No 8 byte IO space access on x86 */
517 *(volatile uint64_t *)(bsh + offset) = value;
522 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
523 * provided to bus space described by tag/handle/offset.
526 static __inline void bus_space_write_multi_1(bus_space_tag_t tag,
527 bus_space_handle_t bsh,
529 const u_int8_t *addr,
531 static __inline void bus_space_write_multi_2(bus_space_tag_t tag,
532 bus_space_handle_t bsh,
534 const u_int16_t *addr,
537 static __inline void bus_space_write_multi_4(bus_space_tag_t tag,
538 bus_space_handle_t bsh,
540 const u_int32_t *addr,
544 bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
545 bus_size_t offset, const u_int8_t *addr, size_t count)
548 if (tag == X86_BUS_SPACE_IO)
549 outsb(bsh + offset, addr, count);
551 #ifdef __GNUCLIKE_ASM
552 __asm __volatile(" \n\
556 "=S" (addr), "=c" (count) :
557 "r" (bsh + offset), "0" (addr), "1" (count) :
558 "%eax", "memory", "cc");
564 bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
565 bus_size_t offset, const u_int16_t *addr, size_t count)
568 if (tag == X86_BUS_SPACE_IO)
569 outsw(bsh + offset, addr, count);
571 #ifdef __GNUCLIKE_ASM
572 __asm __volatile(" \n\
576 "=S" (addr), "=c" (count) :
577 "r" (bsh + offset), "0" (addr), "1" (count) :
578 "%eax", "memory", "cc");
584 bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
585 bus_size_t offset, const u_int32_t *addr, size_t count)
588 if (tag == X86_BUS_SPACE_IO)
589 outsl(bsh + offset, addr, count);
591 #ifdef __GNUCLIKE_ASM
592 __asm __volatile(" \n\
596 "=S" (addr), "=c" (count) :
597 "r" (bsh + offset), "0" (addr), "1" (count) :
598 "%eax", "memory", "cc");
603 #if 0 /* Cause a link error for bus_space_write_multi_8 */
604 #define bus_space_write_multi_8(t, h, o, a, c) \
605 !!! bus_space_write_multi_8 unimplemented !!!
609 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
610 * to bus space described by tag/handle starting at `offset'.
613 static __inline void bus_space_write_region_1(bus_space_tag_t tag,
614 bus_space_handle_t bsh,
616 const u_int8_t *addr,
618 static __inline void bus_space_write_region_2(bus_space_tag_t tag,
619 bus_space_handle_t bsh,
621 const u_int16_t *addr,
623 static __inline void bus_space_write_region_4(bus_space_tag_t tag,
624 bus_space_handle_t bsh,
626 const u_int32_t *addr,
630 bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
631 bus_size_t offset, const u_int8_t *addr, size_t count)
634 if (tag == X86_BUS_SPACE_IO) {
635 int _port_ = bsh + offset;
636 #ifdef __GNUCLIKE_ASM
637 __asm __volatile(" \n\
642 "=d" (_port_), "=S" (addr), "=c" (count) :
643 "0" (_port_), "1" (addr), "2" (count) :
644 "%eax", "memory", "cc");
647 bus_space_handle_t _port_ = bsh + offset;
648 #ifdef __GNUCLIKE_ASM
649 __asm __volatile(" \n\
652 "=D" (_port_), "=S" (addr), "=c" (count) :
653 "0" (_port_), "1" (addr), "2" (count) :
660 bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
661 bus_size_t offset, const u_int16_t *addr, size_t count)
664 if (tag == X86_BUS_SPACE_IO) {
665 int _port_ = bsh + offset;
666 #ifdef __GNUCLIKE_ASM
667 __asm __volatile(" \n\
672 "=d" (_port_), "=S" (addr), "=c" (count) :
673 "0" (_port_), "1" (addr), "2" (count) :
674 "%eax", "memory", "cc");
677 bus_space_handle_t _port_ = bsh + offset;
678 #ifdef __GNUCLIKE_ASM
679 __asm __volatile(" \n\
682 "=D" (_port_), "=S" (addr), "=c" (count) :
683 "0" (_port_), "1" (addr), "2" (count) :
690 bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
691 bus_size_t offset, const u_int32_t *addr, size_t count)
694 if (tag == X86_BUS_SPACE_IO) {
695 int _port_ = bsh + offset;
696 #ifdef __GNUCLIKE_ASM
697 __asm __volatile(" \n\
702 "=d" (_port_), "=S" (addr), "=c" (count) :
703 "0" (_port_), "1" (addr), "2" (count) :
704 "%eax", "memory", "cc");
707 bus_space_handle_t _port_ = bsh + offset;
708 #ifdef __GNUCLIKE_ASM
709 __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_ */