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 #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_INVALID_DATA (~0)
127 #define BUS_SPACE_UNRESTRICTED (~0)
130 * Map a region of device bus space into CPU virtual address space.
133 int bus_space_map(bus_space_tag_t tag, bus_addr_t addr, bus_size_t size,
134 int flags, bus_space_handle_t *bshp);
137 * Unmap a region of device bus space.
140 void bus_space_unmap(bus_space_tag_t tag, bus_space_handle_t bsh,
144 * Get a new handle for a subregion of an already-mapped area of bus space.
147 static __inline int bus_space_subregion(bus_space_tag_t t,
148 bus_space_handle_t bsh,
149 bus_size_t offset, bus_size_t size,
150 bus_space_handle_t *nbshp);
153 bus_space_subregion(bus_space_tag_t t __unused, bus_space_handle_t bsh,
154 bus_size_t offset, bus_size_t size __unused,
155 bus_space_handle_t *nbshp)
158 *nbshp = bsh + offset;
163 * Allocate a region of memory that is accessible to devices in bus space.
166 int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
167 bus_addr_t rend, bus_size_t size, bus_size_t align,
168 bus_size_t boundary, int flags, bus_addr_t *addrp,
169 bus_space_handle_t *bshp);
172 * Free a region of bus space accessible memory.
175 static __inline void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
179 bus_space_free(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused,
180 bus_size_t size __unused)
186 * Read a 1, 2, 4, or 8 byte quantity from bus space
187 * described by tag/handle/offset.
189 static __inline u_int8_t bus_space_read_1(bus_space_tag_t tag,
190 bus_space_handle_t handle,
193 static __inline u_int16_t bus_space_read_2(bus_space_tag_t tag,
194 bus_space_handle_t handle,
197 static __inline u_int32_t bus_space_read_4(bus_space_tag_t tag,
198 bus_space_handle_t handle,
202 static __inline uint64_t bus_space_read_8(bus_space_tag_t tag,
203 bus_space_handle_t handle,
207 static __inline u_int8_t
208 bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle,
212 if (tag == X86_BUS_SPACE_IO)
213 return (inb(handle + offset));
214 return (*(volatile u_int8_t *)(handle + offset));
217 static __inline u_int16_t
218 bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle,
222 if (tag == X86_BUS_SPACE_IO)
223 return (inw(handle + offset));
224 return (*(volatile u_int16_t *)(handle + offset));
227 static __inline u_int32_t
228 bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle,
232 if (tag == X86_BUS_SPACE_IO)
233 return (inl(handle + offset));
234 return (*(volatile u_int32_t *)(handle + offset));
238 static __inline uint64_t
239 bus_space_read_8(bus_space_tag_t tag, bus_space_handle_t handle,
243 if (tag == X86_BUS_SPACE_IO) /* No 8 byte IO space access on x86 */
244 return (BUS_SPACE_INVALID_DATA);
245 return (*(volatile uint64_t *)(handle + offset));
250 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
251 * described by tag/handle/offset and copy into buffer provided.
253 static __inline void bus_space_read_multi_1(bus_space_tag_t tag,
254 bus_space_handle_t bsh,
255 bus_size_t offset, u_int8_t *addr,
258 static __inline void bus_space_read_multi_2(bus_space_tag_t tag,
259 bus_space_handle_t bsh,
260 bus_size_t offset, u_int16_t *addr,
263 static __inline void bus_space_read_multi_4(bus_space_tag_t tag,
264 bus_space_handle_t bsh,
265 bus_size_t offset, u_int32_t *addr,
269 bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
270 bus_size_t offset, u_int8_t *addr, size_t count)
273 if (tag == X86_BUS_SPACE_IO)
274 insb(bsh + offset, addr, count);
276 #ifdef __GNUCLIKE_ASM
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)
294 if (tag == X86_BUS_SPACE_IO)
295 insw(bsh + offset, addr, count);
297 #ifdef __GNUCLIKE_ASM
298 __asm __volatile(" \n\
300 1: movw (%2),%%ax \n\
303 "=D" (addr), "=c" (count) :
304 "r" (bsh + offset), "0" (addr), "1" (count) :
311 bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
312 bus_size_t offset, u_int32_t *addr, size_t count)
315 if (tag == X86_BUS_SPACE_IO)
316 insl(bsh + offset, addr, count);
318 #ifdef __GNUCLIKE_ASM
319 __asm __volatile(" \n\
321 1: movl (%2),%%eax \n\
324 "=D" (addr), "=c" (count) :
325 "r" (bsh + offset), "0" (addr), "1" (count) :
331 #if 0 /* Cause a link error for bus_space_read_multi_8 */
332 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
336 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
337 * described by tag/handle and starting at `offset' and copy into
340 static __inline void bus_space_read_region_1(bus_space_tag_t tag,
341 bus_space_handle_t bsh,
342 bus_size_t offset, u_int8_t *addr,
345 static __inline void bus_space_read_region_2(bus_space_tag_t tag,
346 bus_space_handle_t bsh,
347 bus_size_t offset, u_int16_t *addr,
350 static __inline void bus_space_read_region_4(bus_space_tag_t tag,
351 bus_space_handle_t bsh,
352 bus_size_t offset, u_int32_t *addr,
357 bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
358 bus_size_t offset, u_int8_t *addr, size_t count)
361 if (tag == X86_BUS_SPACE_IO) {
362 int _port_ = bsh + offset;
363 #ifdef __GNUCLIKE_ASM
364 __asm __volatile(" \n\
370 "=D" (addr), "=c" (count), "=d" (_port_) :
371 "0" (addr), "1" (count), "2" (_port_) :
372 "%eax", "memory", "cc");
375 bus_space_handle_t _port_ = bsh + offset;
376 #ifdef __GNUCLIKE_ASM
377 __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\
402 "=D" (addr), "=c" (count), "=d" (_port_) :
403 "0" (addr), "1" (count), "2" (_port_) :
404 "%eax", "memory", "cc");
407 bus_space_handle_t _port_ = bsh + offset;
408 #ifdef __GNUCLIKE_ASM
409 __asm __volatile(" \n\
413 "=D" (addr), "=c" (count), "=S" (_port_) :
414 "0" (addr), "1" (count), "2" (_port_) :
421 bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
422 bus_size_t offset, u_int32_t *addr, size_t count)
425 if (tag == X86_BUS_SPACE_IO) {
426 int _port_ = bsh + offset;
427 #ifdef __GNUCLIKE_ASM
428 __asm __volatile(" \n\
434 "=D" (addr), "=c" (count), "=d" (_port_) :
435 "0" (addr), "1" (count), "2" (_port_) :
436 "%eax", "memory", "cc");
439 bus_space_handle_t _port_ = bsh + offset;
440 #ifdef __GNUCLIKE_ASM
441 __asm __volatile(" \n\
445 "=D" (addr), "=c" (count), "=S" (_port_) :
446 "0" (addr), "1" (count), "2" (_port_) :
452 #if 0 /* Cause a link error for bus_space_read_region_8 */
453 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
457 * Write the 1, 2, 4, or 8 byte value `value' to bus space
458 * described by tag/handle/offset.
461 static __inline void bus_space_write_1(bus_space_tag_t tag,
462 bus_space_handle_t bsh,
463 bus_size_t offset, u_int8_t value);
465 static __inline void bus_space_write_2(bus_space_tag_t tag,
466 bus_space_handle_t bsh,
467 bus_size_t offset, u_int16_t value);
469 static __inline void bus_space_write_4(bus_space_tag_t tag,
470 bus_space_handle_t bsh,
471 bus_size_t offset, u_int32_t value);
474 static __inline void bus_space_write_8(bus_space_tag_t tag,
475 bus_space_handle_t bsh,
476 bus_size_t offset, uint64_t value);
480 bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsh,
481 bus_size_t offset, u_int8_t value)
484 if (tag == X86_BUS_SPACE_IO)
485 outb(bsh + offset, value);
487 *(volatile u_int8_t *)(bsh + offset) = value;
491 bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t bsh,
492 bus_size_t offset, u_int16_t value)
495 if (tag == X86_BUS_SPACE_IO)
496 outw(bsh + offset, value);
498 *(volatile u_int16_t *)(bsh + offset) = value;
502 bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh,
503 bus_size_t offset, u_int32_t value)
506 if (tag == X86_BUS_SPACE_IO)
507 outl(bsh + offset, value);
509 *(volatile u_int32_t *)(bsh + offset) = value;
514 bus_space_write_8(bus_space_tag_t tag, bus_space_handle_t bsh,
515 bus_size_t offset, uint64_t value)
518 if (tag == X86_BUS_SPACE_IO) /* No 8 byte IO space access on x86 */
521 *(volatile uint64_t *)(bsh + offset) = value;
526 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
527 * provided to bus space described by tag/handle/offset.
530 static __inline void bus_space_write_multi_1(bus_space_tag_t tag,
531 bus_space_handle_t bsh,
533 const u_int8_t *addr,
535 static __inline void bus_space_write_multi_2(bus_space_tag_t tag,
536 bus_space_handle_t bsh,
538 const u_int16_t *addr,
541 static __inline void bus_space_write_multi_4(bus_space_tag_t tag,
542 bus_space_handle_t bsh,
544 const u_int32_t *addr,
548 bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
549 bus_size_t offset, const u_int8_t *addr, size_t count)
552 if (tag == X86_BUS_SPACE_IO)
553 outsb(bsh + offset, addr, count);
555 #ifdef __GNUCLIKE_ASM
556 __asm __volatile(" \n\
561 "=S" (addr), "=c" (count) :
562 "r" (bsh + offset), "0" (addr), "1" (count) :
563 "%eax", "memory", "cc");
569 bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
570 bus_size_t offset, const u_int16_t *addr, size_t count)
573 if (tag == X86_BUS_SPACE_IO)
574 outsw(bsh + offset, addr, count);
576 #ifdef __GNUCLIKE_ASM
577 __asm __volatile(" \n\
582 "=S" (addr), "=c" (count) :
583 "r" (bsh + offset), "0" (addr), "1" (count) :
584 "%eax", "memory", "cc");
590 bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
591 bus_size_t offset, const u_int32_t *addr, size_t count)
594 if (tag == X86_BUS_SPACE_IO)
595 outsl(bsh + offset, addr, count);
597 #ifdef __GNUCLIKE_ASM
598 __asm __volatile(" \n\
603 "=S" (addr), "=c" (count) :
604 "r" (bsh + offset), "0" (addr), "1" (count) :
605 "%eax", "memory", "cc");
610 #if 0 /* Cause a link error for bus_space_write_multi_8 */
611 #define bus_space_write_multi_8(t, h, o, a, c) \
612 !!! bus_space_write_multi_8 unimplemented !!!
616 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
617 * to bus space described by tag/handle starting at `offset'.
620 static __inline void bus_space_write_region_1(bus_space_tag_t tag,
621 bus_space_handle_t bsh,
623 const u_int8_t *addr,
625 static __inline void bus_space_write_region_2(bus_space_tag_t tag,
626 bus_space_handle_t bsh,
628 const u_int16_t *addr,
630 static __inline void bus_space_write_region_4(bus_space_tag_t tag,
631 bus_space_handle_t bsh,
633 const u_int32_t *addr,
637 bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
638 bus_size_t offset, const u_int8_t *addr, size_t count)
641 if (tag == X86_BUS_SPACE_IO) {
642 int _port_ = bsh + offset;
643 #ifdef __GNUCLIKE_ASM
644 __asm __volatile(" \n\
650 "=d" (_port_), "=S" (addr), "=c" (count) :
651 "0" (_port_), "1" (addr), "2" (count) :
652 "%eax", "memory", "cc");
655 bus_space_handle_t _port_ = bsh + offset;
656 #ifdef __GNUCLIKE_ASM
657 __asm __volatile(" \n\
661 "=D" (_port_), "=S" (addr), "=c" (count) :
662 "0" (_port_), "1" (addr), "2" (count) :
669 bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
670 bus_size_t offset, const u_int16_t *addr, size_t count)
673 if (tag == X86_BUS_SPACE_IO) {
674 int _port_ = bsh + offset;
675 #ifdef __GNUCLIKE_ASM
676 __asm __volatile(" \n\
682 "=d" (_port_), "=S" (addr), "=c" (count) :
683 "0" (_port_), "1" (addr), "2" (count) :
684 "%eax", "memory", "cc");
687 bus_space_handle_t _port_ = bsh + offset;
688 #ifdef __GNUCLIKE_ASM
689 __asm __volatile(" \n\
693 "=D" (_port_), "=S" (addr), "=c" (count) :
694 "0" (_port_), "1" (addr), "2" (count) :
701 bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
702 bus_size_t offset, const u_int32_t *addr, size_t count)
705 if (tag == X86_BUS_SPACE_IO) {
706 int _port_ = bsh + offset;
707 #ifdef __GNUCLIKE_ASM
708 __asm __volatile(" \n\
714 "=d" (_port_), "=S" (addr), "=c" (count) :
715 "0" (_port_), "1" (addr), "2" (count) :
716 "%eax", "memory", "cc");
719 bus_space_handle_t _port_ = bsh + offset;
720 #ifdef __GNUCLIKE_ASM
721 __asm __volatile(" \n\
725 "=D" (_port_), "=S" (addr), "=c" (count) :
726 "0" (_port_), "1" (addr), "2" (count) :
732 #if 0 /* Cause a link error for bus_space_write_region_8 */
733 #define bus_space_write_region_8 \
734 !!! bus_space_write_region_8 unimplemented !!!
738 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
739 * by tag/handle/offset `count' times.
742 static __inline void bus_space_set_multi_1(bus_space_tag_t tag,
743 bus_space_handle_t bsh,
745 u_int8_t value, size_t count);
746 static __inline void bus_space_set_multi_2(bus_space_tag_t tag,
747 bus_space_handle_t bsh,
749 u_int16_t value, size_t count);
750 static __inline void bus_space_set_multi_4(bus_space_tag_t tag,
751 bus_space_handle_t bsh,
753 u_int32_t value, size_t count);
756 bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
757 bus_size_t offset, u_int8_t value, size_t count)
759 bus_space_handle_t addr = bsh + offset;
761 if (tag == X86_BUS_SPACE_IO)
766 *(volatile u_int8_t *)(addr) = value;
770 bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
771 bus_size_t offset, u_int16_t value, size_t count)
773 bus_space_handle_t addr = bsh + offset;
775 if (tag == X86_BUS_SPACE_IO)
780 *(volatile u_int16_t *)(addr) = value;
784 bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
785 bus_size_t offset, u_int32_t value, size_t count)
787 bus_space_handle_t addr = bsh + offset;
789 if (tag == X86_BUS_SPACE_IO)
794 *(volatile u_int32_t *)(addr) = value;
797 #if 0 /* Cause a link error for bus_space_set_multi_8 */
798 #define bus_space_set_multi_8 !!! bus_space_set_multi_8 unimplemented !!!
802 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
803 * by tag/handle starting at `offset'.
806 static __inline void bus_space_set_region_1(bus_space_tag_t tag,
807 bus_space_handle_t bsh,
808 bus_size_t offset, u_int8_t value,
810 static __inline void bus_space_set_region_2(bus_space_tag_t tag,
811 bus_space_handle_t bsh,
812 bus_size_t offset, u_int16_t value,
814 static __inline void bus_space_set_region_4(bus_space_tag_t tag,
815 bus_space_handle_t bsh,
816 bus_size_t offset, u_int32_t value,
820 bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
821 bus_size_t offset, u_int8_t value, size_t count)
823 bus_space_handle_t addr = bsh + offset;
825 if (tag == X86_BUS_SPACE_IO)
826 for (; count != 0; count--, addr++)
829 for (; count != 0; count--, addr++)
830 *(volatile u_int8_t *)(addr) = value;
834 bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
835 bus_size_t offset, u_int16_t value, size_t count)
837 bus_space_handle_t addr = bsh + offset;
839 if (tag == X86_BUS_SPACE_IO)
840 for (; count != 0; count--, addr += 2)
843 for (; count != 0; count--, addr += 2)
844 *(volatile u_int16_t *)(addr) = value;
848 bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
849 bus_size_t offset, u_int32_t value, size_t count)
851 bus_space_handle_t addr = bsh + offset;
853 if (tag == X86_BUS_SPACE_IO)
854 for (; count != 0; count--, addr += 4)
857 for (; count != 0; count--, addr += 4)
858 *(volatile u_int32_t *)(addr) = value;
861 #if 0 /* Cause a link error for bus_space_set_region_8 */
862 #define bus_space_set_region_8 !!! bus_space_set_region_8 unimplemented !!!
866 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
867 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
870 static __inline void bus_space_copy_region_1(bus_space_tag_t tag,
871 bus_space_handle_t bsh1,
873 bus_space_handle_t bsh2,
874 bus_size_t off2, size_t count);
876 static __inline void bus_space_copy_region_2(bus_space_tag_t tag,
877 bus_space_handle_t bsh1,
879 bus_space_handle_t bsh2,
880 bus_size_t off2, size_t count);
882 static __inline void bus_space_copy_region_4(bus_space_tag_t tag,
883 bus_space_handle_t bsh1,
885 bus_space_handle_t bsh2,
886 bus_size_t off2, size_t count);
889 bus_space_copy_region_1(bus_space_tag_t tag, bus_space_handle_t bsh1,
890 bus_size_t off1, bus_space_handle_t bsh2,
891 bus_size_t off2, size_t count)
893 bus_space_handle_t addr1 = bsh1 + off1;
894 bus_space_handle_t addr2 = bsh2 + off2;
896 if (tag == X86_BUS_SPACE_IO) {
897 if (addr1 >= addr2) {
898 /* src after dest: copy forward */
899 for (; count != 0; count--, addr1++, addr2++)
900 outb(addr2, inb(addr1));
902 /* dest after src: copy backwards */
903 for (addr1 += (count - 1), addr2 += (count - 1);
904 count != 0; count--, addr1--, addr2--)
905 outb(addr2, inb(addr1));
908 if (addr1 >= addr2) {
909 /* src after dest: copy forward */
910 for (; count != 0; count--, addr1++, addr2++)
911 *(volatile u_int8_t *)(addr2) =
912 *(volatile u_int8_t *)(addr1);
914 /* dest after src: copy backwards */
915 for (addr1 += (count - 1), addr2 += (count - 1);
916 count != 0; count--, addr1--, addr2--)
917 *(volatile u_int8_t *)(addr2) =
918 *(volatile u_int8_t *)(addr1);
924 bus_space_copy_region_2(bus_space_tag_t tag, bus_space_handle_t bsh1,
925 bus_size_t off1, bus_space_handle_t bsh2,
926 bus_size_t off2, size_t count)
928 bus_space_handle_t addr1 = bsh1 + off1;
929 bus_space_handle_t addr2 = bsh2 + off2;
931 if (tag == X86_BUS_SPACE_IO) {
932 if (addr1 >= addr2) {
933 /* src after dest: copy forward */
934 for (; count != 0; count--, addr1 += 2, addr2 += 2)
935 outw(addr2, inw(addr1));
937 /* dest after src: copy backwards */
938 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
939 count != 0; count--, addr1 -= 2, addr2 -= 2)
940 outw(addr2, inw(addr1));
943 if (addr1 >= addr2) {
944 /* src after dest: copy forward */
945 for (; count != 0; count--, addr1 += 2, addr2 += 2)
946 *(volatile u_int16_t *)(addr2) =
947 *(volatile u_int16_t *)(addr1);
949 /* dest after src: copy backwards */
950 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
951 count != 0; count--, addr1 -= 2, addr2 -= 2)
952 *(volatile u_int16_t *)(addr2) =
953 *(volatile u_int16_t *)(addr1);
959 bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsh1,
960 bus_size_t off1, bus_space_handle_t bsh2,
961 bus_size_t off2, size_t count)
963 bus_space_handle_t addr1 = bsh1 + off1;
964 bus_space_handle_t addr2 = bsh2 + off2;
966 if (tag == X86_BUS_SPACE_IO) {
967 if (addr1 >= addr2) {
968 /* src after dest: copy forward */
969 for (; count != 0; count--, addr1 += 4, addr2 += 4)
970 outl(addr2, inl(addr1));
972 /* dest after src: copy backwards */
973 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
974 count != 0; count--, addr1 -= 4, addr2 -= 4)
975 outl(addr2, inl(addr1));
978 if (addr1 >= addr2) {
979 /* src after dest: copy forward */
980 for (; count != 0; count--, addr1 += 4, addr2 += 4)
981 *(volatile u_int32_t *)(addr2) =
982 *(volatile u_int32_t *)(addr1);
984 /* dest after src: copy backwards */
985 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
986 count != 0; count--, addr1 -= 4, addr2 -= 4)
987 *(volatile u_int32_t *)(addr2) =
988 *(volatile u_int32_t *)(addr1);
993 #if 0 /* Cause a link error for bus_space_copy_8 */
994 #define bus_space_copy_region_8 !!! bus_space_copy_region_8 unimplemented !!!
998 * Bus read/write barrier methods.
1000 * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
1001 * bus_size_t offset, bus_size_t len, int flags);
1004 * Note that BUS_SPACE_BARRIER_WRITE doesn't do anything other than
1005 * prevent reordering by the compiler; all Intel x86 processors currently
1006 * retire operations outside the CPU in program order.
1008 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
1009 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
1011 static __inline void
1012 bus_space_barrier(bus_space_tag_t tag __unused, bus_space_handle_t bsh __unused,
1013 bus_size_t offset __unused, bus_size_t len __unused, int flags)
1015 #ifdef __GNUCLIKE_ASM
1016 if (flags & BUS_SPACE_BARRIER_READ)
1018 __asm __volatile("lock; addl $0,0(%%rsp)" : : : "memory");
1020 __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory");
1023 __compiler_membar();
1027 #ifdef BUS_SPACE_NO_LEGACY
1030 #define inb(a) compiler_error
1031 #define inw(a) compiler_error
1032 #define inl(a) compiler_error
1033 #define outb(a, b) compiler_error
1034 #define outw(a, b) compiler_error
1035 #define outl(a, b) compiler_error
1038 #include <machine/bus_dma.h>
1041 * Stream accesses are the same as normal accesses on x86; there are no
1042 * supported bus systems with an endianess different from the host one.
1044 #define bus_space_read_stream_1(t, h, o) bus_space_read_1((t), (h), (o))
1045 #define bus_space_read_stream_2(t, h, o) bus_space_read_2((t), (h), (o))
1046 #define bus_space_read_stream_4(t, h, o) bus_space_read_4((t), (h), (o))
1048 #define bus_space_read_multi_stream_1(t, h, o, a, c) \
1049 bus_space_read_multi_1((t), (h), (o), (a), (c))
1050 #define bus_space_read_multi_stream_2(t, h, o, a, c) \
1051 bus_space_read_multi_2((t), (h), (o), (a), (c))
1052 #define bus_space_read_multi_stream_4(t, h, o, a, c) \
1053 bus_space_read_multi_4((t), (h), (o), (a), (c))
1055 #define bus_space_write_stream_1(t, h, o, v) \
1056 bus_space_write_1((t), (h), (o), (v))
1057 #define bus_space_write_stream_2(t, h, o, v) \
1058 bus_space_write_2((t), (h), (o), (v))
1059 #define bus_space_write_stream_4(t, h, o, v) \
1060 bus_space_write_4((t), (h), (o), (v))
1062 #define bus_space_write_multi_stream_1(t, h, o, a, c) \
1063 bus_space_write_multi_1((t), (h), (o), (a), (c))
1064 #define bus_space_write_multi_stream_2(t, h, o, a, c) \
1065 bus_space_write_multi_2((t), (h), (o), (a), (c))
1066 #define bus_space_write_multi_stream_4(t, h, o, a, c) \
1067 bus_space_write_multi_4((t), (h), (o), (a), (c))
1069 #define bus_space_set_multi_stream_1(t, h, o, v, c) \
1070 bus_space_set_multi_1((t), (h), (o), (v), (c))
1071 #define bus_space_set_multi_stream_2(t, h, o, v, c) \
1072 bus_space_set_multi_2((t), (h), (o), (v), (c))
1073 #define bus_space_set_multi_stream_4(t, h, o, v, c) \
1074 bus_space_set_multi_4((t), (h), (o), (v), (c))
1076 #define bus_space_read_region_stream_1(t, h, o, a, c) \
1077 bus_space_read_region_1((t), (h), (o), (a), (c))
1078 #define bus_space_read_region_stream_2(t, h, o, a, c) \
1079 bus_space_read_region_2((t), (h), (o), (a), (c))
1080 #define bus_space_read_region_stream_4(t, h, o, a, c) \
1081 bus_space_read_region_4((t), (h), (o), (a), (c))
1083 #define bus_space_write_region_stream_1(t, h, o, a, c) \
1084 bus_space_write_region_1((t), (h), (o), (a), (c))
1085 #define bus_space_write_region_stream_2(t, h, o, a, c) \
1086 bus_space_write_region_2((t), (h), (o), (a), (c))
1087 #define bus_space_write_region_stream_4(t, h, o, a, c) \
1088 bus_space_write_region_4((t), (h), (o), (a), (c))
1090 #define bus_space_set_region_stream_1(t, h, o, v, c) \
1091 bus_space_set_region_1((t), (h), (o), (v), (c))
1092 #define bus_space_set_region_stream_2(t, h, o, v, c) \
1093 bus_space_set_region_2((t), (h), (o), (v), (c))
1094 #define bus_space_set_region_stream_4(t, h, o, v, c) \
1095 bus_space_set_region_4((t), (h), (o), (v), (c))
1097 #define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \
1098 bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
1099 #define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \
1100 bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c))
1101 #define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \
1102 bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c))
1104 #endif /* _X86_BUS_H_ */