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 /* $Id: bus.h,v 1.3 1998/05/06 01:45:47 gibbs Exp $ */
75 #include <machine/cpufunc.h>
78 * Values for the i386 bus space tag, not to be used directly by MI code.
80 #define I386_BUS_SPACE_IO 0 /* space is i/o space */
81 #define I386_BUS_SPACE_MEM 1 /* space is mem space */
84 * Bus address and size types
86 typedef u_int bus_addr_t;
87 typedef u_int bus_size_t;
89 #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF
90 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
91 #define BUS_SPACE_MAXSIZE (64 * 1024) /* Maximum supported size */
92 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF
93 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
94 #define BUS_SPACE_MAXADDR 0xFFFFFFFF
96 #define BUS_SPACE_UNRESTRICTED (~0)
99 * Access methods for bus resources and address space.
101 typedef int bus_space_tag_t;
102 typedef u_int bus_space_handle_t;
105 * Map a region of device bus space into CPU virtual address space.
108 #define BUS_SPACE_MAP_CACHEABLE 0x01
109 #define BUS_SPACE_MAP_LINEAR 0x02
111 int bus_space_map(bus_space_tag_t t, bus_addr_t addr, bus_size_t size,
112 int flags, bus_space_handle_t *bshp);
115 * Unmap a region of device bus space.
118 void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
122 * Get a new handle for a subregion of an already-mapped area of bus space.
125 int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
126 bus_size_t offset, bus_size_t size,
127 bus_space_handle_t *nbshp);
130 * Allocate a region of memory that is accessible to devices in bus space.
133 int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
134 bus_addr_t rend, bus_size_t size, bus_size_t align,
135 bus_size_t boundary, int flags, bus_addr_t *addrp,
136 bus_space_handle_t *bshp);
139 * Free a region of bus space accessible memory.
142 void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
145 #if defined(_I386_BUS_PIO_H_) || defined(_I386_BUS_MEMIO_H_)
148 * Read a 1, 2, 4, or 8 byte quantity from bus space
149 * described by tag/handle/offset.
151 static __inline u_int8_t bus_space_read_1(bus_space_tag_t tag,
152 bus_space_handle_t handle,
155 static __inline u_int16_t bus_space_read_2(bus_space_tag_t tag,
156 bus_space_handle_t handle,
159 static __inline u_int32_t bus_space_read_4(bus_space_tag_t tag,
160 bus_space_handle_t handle,
163 static __inline u_int8_t
164 bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle,
167 #if defined (_I386_BUS_PIO_H_)
168 #if defined (_I386_BUS_MEMIO_H_)
169 if (tag == I386_BUS_SPACE_IO)
171 return (inb(handle + offset));
173 #if defined (_I386_BUS_MEMIO_H_)
174 return (*(volatile u_int8_t *)(handle + offset));
178 static __inline u_int16_t
179 bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle,
182 #if defined(_I386_BUS_PIO_H_)
183 #if defined(_I386_BUS_MEMIO_H_)
184 if (tag == I386_BUS_SPACE_IO)
186 return (inw(handle + offset));
188 #if defined(_I386_BUS_MEMIO_H_)
189 return (*(volatile u_int16_t *)(handle + offset));
193 static __inline u_int32_t
194 bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle,
197 #if defined(_I386_BUS_PIO_H_)
198 #if defined(_I386_BUS_MEMIO_H_)
199 if (tag == I386_BUS_SPACE_IO)
201 return (inl(handle + offset));
203 #if defined(_I386_BUS_MEMIO_H_)
204 return (*(volatile u_int32_t *)(handle + offset));
208 #if 0 /* Cause a link error for bus_space_read_8 */
209 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
213 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
214 * described by tag/handle/offset and copy into buffer provided.
216 static __inline void bus_space_read_multi_1(bus_space_tag_t tag,
217 bus_space_handle_t bsh,
218 bus_size_t offset, u_int8_t *addr,
221 static __inline void bus_space_read_multi_2(bus_space_tag_t tag,
222 bus_space_handle_t bsh,
223 bus_size_t offset, u_int16_t *addr,
226 static __inline void bus_space_read_multi_4(bus_space_tag_t tag,
227 bus_space_handle_t bsh,
228 bus_size_t offset, u_int32_t *addr,
232 bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
233 bus_size_t offset, u_int8_t *addr, size_t count)
235 #if defined(_I386_BUS_PIO_H_)
236 #if defined(_I386_BUS_MEMIO_H_)
237 if (tag == I386_BUS_SPACE_IO)
239 insb(bsh + offset, addr, count);
241 #if defined(_I386_BUS_MEMIO_H_)
242 #if defined(_I386_BUS_PIO_H_)
246 int __x __asm__("%eax");
247 __asm __volatile(" \n\
249 1: movb (%1),%%al \n\
253 "r" (bsh + offset), "D" (addr), "c" (count) :
254 "%edi", "%ecx", "memory");
260 bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
261 bus_size_t offset, u_int16_t *addr, size_t count)
263 #if defined(_I386_BUS_PIO_H_)
264 #if defined(_I386_BUS_MEMIO_H_)
265 if (tag == I386_BUS_SPACE_IO)
267 insw(bsh + offset, addr, count);
269 #if defined(_I386_BUS_MEMIO_H_)
270 #if defined(_I386_BUS_PIO_H_)
274 int __x __asm__("%eax");
275 __asm __volatile(" \n\
277 1: movw (%1),%%ax \n\
281 "r" (bsh + offset), "D" (addr), "c" (count) :
282 "%edi", "%ecx", "memory");
288 bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
289 bus_size_t offset, u_int32_t *addr, size_t count)
291 #if defined(_I386_BUS_PIO_H_)
292 #if defined(_I386_BUS_MEMIO_H_)
293 if (tag == I386_BUS_SPACE_IO)
295 insl(bsh + offset, addr, count);
297 #if defined(_I386_BUS_MEMIO_H_)
298 #if defined(_I386_BUS_PIO_H_)
302 int __x __asm__("%eax");
303 __asm __volatile(" \n\
305 1: movl (%1),%%eax \n\
309 "r" (bsh + offset), "D" (addr), "c" (count) :
310 "%edi", "%ecx", "memory");
315 #if 0 /* Cause a link error for bus_space_read_multi_8 */
316 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
320 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
321 * described by tag/handle and starting at `offset' and copy into
324 static __inline void bus_space_read_region_1(bus_space_tag_t tag,
325 bus_space_handle_t bsh,
326 bus_size_t offset, u_int8_t *addr,
329 static __inline void bus_space_read_region_2(bus_space_tag_t tag,
330 bus_space_handle_t bsh,
331 bus_size_t offset, u_int16_t *addr,
334 static __inline void bus_space_read_region_4(bus_space_tag_t tag,
335 bus_space_handle_t bsh,
336 bus_size_t offset, u_int32_t *addr,
341 bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
342 bus_size_t offset, u_int8_t *addr, size_t count)
344 #if defined(_I386_BUS_PIO_H_)
345 #if defined(_I386_BUS_MEMIO_H_)
346 if (tag == I386_BUS_SPACE_IO)
349 int __x __asm__("%eax");
350 __asm __volatile(" \n\
357 "d" (bsh + offset), "D" (addr), "c" (count) :
358 "%edx", "%edi", "%ecx", "memory");
361 #if defined(_I386_BUS_MEMIO_H_)
362 #if defined(_I386_BUS_PIO_H_)
366 __asm __volatile(" \n\
371 "S" (bsh + offset), "D" (addr), "c" (count) :
372 "%esi", "%edi", "%ecx", "memory");
378 bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
379 bus_size_t offset, u_int16_t *addr, size_t count)
381 #if defined(_I386_BUS_PIO_H_)
382 #if defined(_I386_BUS_MEMIO_H_)
383 if (tag == I386_BUS_SPACE_IO)
386 int __x __asm__("%eax");
387 __asm __volatile(" \n\
394 "d" (bsh + offset), "D" (addr), "c" (count) :
395 "%edx", "%edi", "%ecx", "memory");
398 #if defined(_I386_BUS_MEMIO_H_)
399 #if defined(_I386_BUS_PIO_H_)
403 __asm __volatile(" \n\
408 "S" (bsh + offset), "D" (addr), "c" (count) :
409 "%esi", "%edi", "%ecx", "memory");
415 bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
416 bus_size_t offset, u_int32_t *addr, size_t count)
418 #if defined(_I386_BUS_PIO_H_)
419 #if defined(_I386_BUS_MEMIO_H_)
420 if (tag == I386_BUS_SPACE_IO)
423 int __x __asm__("%eax");
424 __asm __volatile(" \n\
431 "d" (bsh + offset), "D" (addr), "c" (count) :
432 "%edx", "%edi", "%ecx", "memory");
435 #if defined(_I386_BUS_MEMIO_H_)
436 #if defined(_I386_BUS_PIO_H_)
440 __asm __volatile(" \n\
445 "S" (bsh + offset), "D" (addr), "c" (count) :
446 "%esi", "%edi", "%ecx", "memory");
451 #if 0 /* Cause a link error for bus_space_read_region_8 */
452 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
456 * Write the 1, 2, 4, or 8 byte value `value' to bus space
457 * described by tag/handle/offset.
460 static __inline void bus_space_write_1(bus_space_tag_t tag,
461 bus_space_handle_t bsh,
462 bus_size_t offset, u_int8_t value);
464 static __inline void bus_space_write_2(bus_space_tag_t tag,
465 bus_space_handle_t bsh,
466 bus_size_t offset, u_int16_t value);
468 static __inline void bus_space_write_4(bus_space_tag_t tag,
469 bus_space_handle_t bsh,
470 bus_size_t offset, u_int32_t value);
473 bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsh,
474 bus_size_t offset, u_int8_t value)
476 #if defined(_I386_BUS_PIO_H_)
477 #if defined(_I386_BUS_MEMIO_H_)
478 if (tag == I386_BUS_SPACE_IO)
480 outb(bsh + offset, value);
482 #if defined(_I386_BUS_MEMIO_H_)
483 #if defined(_I386_BUS_PIO_H_)
486 *(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)
494 #if defined(_I386_BUS_PIO_H_)
495 #if defined(_I386_BUS_MEMIO_H_)
496 if (tag == I386_BUS_SPACE_IO)
498 outw(bsh + offset, value);
500 #if defined(_I386_BUS_MEMIO_H_)
501 #if defined(_I386_BUS_PIO_H_)
504 *(volatile u_int16_t *)(bsh + offset) = value;
509 bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh,
510 bus_size_t offset, u_int32_t value)
512 #if defined(_I386_BUS_PIO_H_)
513 #if defined(_I386_BUS_MEMIO_H_)
514 if (tag == I386_BUS_SPACE_IO)
516 outl(bsh + offset, value);
518 #if defined(_I386_BUS_MEMIO_H_)
519 #if defined(_I386_BUS_PIO_H_)
522 *(volatile u_int32_t *)(bsh + offset) = value;
526 #if 0 /* Cause a link error for bus_space_write_8 */
527 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
531 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
532 * provided to bus space described by tag/handle/offset.
535 static __inline void bus_space_write_multi_1(bus_space_tag_t tag,
536 bus_space_handle_t bsh,
538 const u_int8_t *addr,
540 static __inline void bus_space_write_multi_2(bus_space_tag_t tag,
541 bus_space_handle_t bsh,
543 const u_int16_t *addr,
546 static __inline void bus_space_write_multi_4(bus_space_tag_t tag,
547 bus_space_handle_t bsh,
549 const u_int32_t *addr,
553 bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
554 bus_size_t offset, const u_int8_t *addr, size_t count)
556 #if defined(_I386_BUS_PIO_H_)
557 #if defined(_I386_BUS_MEMIO_H_)
558 if (tag == I386_BUS_SPACE_IO)
560 outsb(bsh + offset, addr, count);
562 #if defined(_I386_BUS_MEMIO_H_)
563 #if defined(_I386_BUS_PIO_H_)
567 int __x __asm__("%eax");
568 __asm __volatile(" \n\
574 "r" (bsh + offset), "S" (addr), "c" (count) :
581 bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
582 bus_size_t offset, const u_int16_t *addr, size_t count)
584 #if defined(_I386_BUS_PIO_H_)
585 #if defined(_I386_BUS_MEMIO_H_)
586 if (tag == I386_BUS_SPACE_IO)
588 outsw(bsh + offset, addr, count);
590 #if defined(_I386_BUS_MEMIO_H_)
591 #if defined(_I386_BUS_PIO_H_)
595 int __x __asm__("%eax");
596 __asm __volatile(" \n\
602 "r" (bsh + offset), "S" (addr), "c" (count) :
609 bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
610 bus_size_t offset, const u_int32_t *addr, size_t count)
612 #if defined(_I386_BUS_PIO_H_)
613 #if defined(_I386_BUS_MEMIO_H_)
614 if (tag == I386_BUS_SPACE_IO)
616 outsl(bsh + offset, addr, count);
618 #if defined(_I386_BUS_MEMIO_H_)
619 #if defined(_I386_BUS_PIO_H_)
623 int __x __asm__("%eax");
624 __asm __volatile(" \n\
630 "r" (bsh + offset), "S" (addr), "c" (count) :
636 #if 0 /* Cause a link error for bus_space_write_multi_8 */
637 #define bus_space_write_multi_8(t, h, o, a, c) \
638 !!! bus_space_write_multi_8 unimplemented !!!
642 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
643 * to bus space described by tag/handle starting at `offset'.
646 static __inline void bus_space_write_region_1(bus_space_tag_t tag,
647 bus_space_handle_t bsh,
649 const u_int8_t *addr,
651 static __inline void bus_space_write_region_2(bus_space_tag_t tag,
652 bus_space_handle_t bsh,
654 const u_int16_t *addr,
656 static __inline void bus_space_write_region_4(bus_space_tag_t tag,
657 bus_space_handle_t bsh,
659 const u_int32_t *addr,
663 bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
664 bus_size_t offset, const u_int8_t *addr, size_t count)
666 #if defined(_I386_BUS_PIO_H_)
667 #if defined(_I386_BUS_MEMIO_H_)
668 if (tag == I386_BUS_SPACE_IO)
671 int __x __asm__("%eax");
672 __asm __volatile(" \n\
679 "d" (bsh + offset), "S" (addr), "c" (count) :
680 "%edx", "%esi", "%ecx", "memory");
683 #if defined(_I386_BUS_MEMIO_H_)
684 #if defined(_I386_BUS_PIO_H_)
688 __asm __volatile(" \n\
693 "D" (bsh + offset), "S" (addr), "c" (count) :
694 "%edi", "%esi", "%ecx", "memory");
700 bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
701 bus_size_t offset, const u_int16_t *addr, size_t count)
703 #if defined(_I386_BUS_PIO_H_)
704 #if defined(_I386_BUS_MEMIO_H_)
705 if (tag == I386_BUS_SPACE_IO)
708 int __x __asm__("%eax");
709 __asm __volatile(" \n\
716 "d" (bsh + offset), "S" (addr), "c" (count) :
717 "%edx", "%esi", "%ecx", "memory");
720 #if defined(_I386_BUS_MEMIO_H_)
721 #if defined(_I386_BUS_PIO_H_)
725 __asm __volatile(" \n\
730 "D" (bsh + offset), "S" (addr), "c" (count) :
731 "%edi", "%esi", "%ecx", "memory");
737 bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
738 bus_size_t offset, const u_int32_t *addr, size_t count)
740 #if defined(_I386_BUS_PIO_H_)
741 #if defined(_I386_BUS_MEMIO_H_)
742 if (tag == I386_BUS_SPACE_IO)
745 int __x __asm__("%eax");
746 __asm __volatile(" \n\
753 "d" (bsh + offset), "S" (addr), "c" (count) :
754 "%edx", "%esi", "%ecx", "memory");
757 #if defined(_I386_BUS_MEMIO_H_)
758 #if defined(_I386_BUS_PIO_H_)
762 __asm __volatile(" \n\
767 "D" (bsh + offset), "S" (addr), "c" (count) :
768 "%edi", "%esi", "%ecx", "memory");
773 #if 0 /* Cause a link error for bus_space_write_region_8 */
774 #define bus_space_write_region_8 \
775 !!! bus_space_write_region_8 unimplemented !!!
779 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
780 * by tag/handle/offset `count' times.
783 static __inline void bus_space_set_multi_1(bus_space_tag_t tag,
784 bus_space_handle_t bsh,
786 u_int8_t value, size_t count);
787 static __inline void bus_space_set_multi_2(bus_space_tag_t tag,
788 bus_space_handle_t bsh,
790 u_int16_t value, size_t count);
791 static __inline void bus_space_set_multi_4(bus_space_tag_t tag,
792 bus_space_handle_t bsh,
794 u_int32_t value, size_t count);
797 bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
798 bus_size_t offset, u_int8_t value, size_t count)
800 bus_addr_t addr = bsh + offset;
802 #if defined(_I386_BUS_PIO_H_)
803 #if defined(_I386_BUS_MEMIO_H_)
804 if (tag == I386_BUS_SPACE_IO)
809 #if defined(_I386_BUS_MEMIO_H_)
810 #if defined(_I386_BUS_PIO_H_)
814 *(volatile u_int8_t *)(addr) = value;
819 bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
820 bus_size_t offset, u_int16_t value, size_t count)
822 bus_addr_t addr = bsh + offset;
824 #if defined(_I386_BUS_PIO_H_)
825 #if defined(_I386_BUS_MEMIO_H_)
826 if (tag == I386_BUS_SPACE_IO)
831 #if defined(_I386_BUS_MEMIO_H_)
832 #if defined(_I386_BUS_PIO_H_)
836 *(volatile u_int16_t *)(addr) = value;
841 bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
842 bus_size_t offset, u_int32_t value, size_t count)
844 bus_addr_t addr = bsh + offset;
846 #if defined(_I386_BUS_PIO_H_)
847 #if defined(_I386_BUS_MEMIO_H_)
848 if (tag == I386_BUS_SPACE_IO)
853 #if defined(_I386_BUS_MEMIO_H_)
854 #if defined(_I386_BUS_PIO_H_)
858 *(volatile u_int32_t *)(addr) = value;
862 #if 0 /* Cause a link error for bus_space_set_multi_8 */
863 #define bus_space_set_multi_8 !!! bus_space_set_multi_8 unimplemented !!!
867 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
868 * by tag/handle starting at `offset'.
871 static __inline void bus_space_set_region_1(bus_space_tag_t tag,
872 bus_space_handle_t bsh,
873 bus_size_t offset, u_int8_t value,
875 static __inline void bus_space_set_region_2(bus_space_tag_t tag,
876 bus_space_handle_t bsh,
877 bus_size_t offset, u_int16_t value,
879 static __inline void bus_space_set_region_4(bus_space_tag_t tag,
880 bus_space_handle_t bsh,
881 bus_size_t offset, u_int32_t value,
885 bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
886 bus_size_t offset, u_int8_t value, size_t count)
888 bus_addr_t addr = bsh + offset;
890 #if defined(_I386_BUS_PIO_H_)
891 #if defined(_I386_BUS_MEMIO_H_)
892 if (tag == I386_BUS_SPACE_IO)
894 for (; count != 0; count--, addr++)
897 #if defined(_I386_BUS_MEMIO_H_)
898 #if defined(_I386_BUS_PIO_H_)
901 for (; count != 0; count--, addr++)
902 *(volatile u_int8_t *)(addr) = value;
907 bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
908 bus_size_t offset, u_int16_t value, size_t count)
910 bus_addr_t addr = bsh + offset;
912 #if defined(_I386_BUS_PIO_H_)
913 #if defined(_I386_BUS_MEMIO_H_)
914 if (tag == I386_BUS_SPACE_IO)
916 for (; count != 0; count--, addr += 2)
919 #if defined(_I386_BUS_MEMIO_H_)
920 #if defined(_I386_BUS_PIO_H_)
923 for (; count != 0; count--, addr += 2)
924 *(volatile u_int16_t *)(addr) = value;
929 bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
930 bus_size_t offset, u_int32_t value, size_t count)
932 bus_addr_t addr = bsh + offset;
934 #if defined(_I386_BUS_PIO_H_)
935 #if defined(_I386_BUS_MEMIO_H_)
936 if (tag == I386_BUS_SPACE_IO)
938 for (; count != 0; count--, addr += 4)
941 #if defined(_I386_BUS_MEMIO_H_)
942 #if defined(_I386_BUS_PIO_H_)
945 for (; count != 0; count--, addr += 4)
946 *(volatile u_int32_t *)(addr) = value;
950 #if 0 /* Cause a link error for bus_space_set_region_8 */
951 #define bus_space_set_region_8 !!! bus_space_set_region_8 unimplemented !!!
955 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
956 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
959 static __inline void bus_space_copy_region_1(bus_space_tag_t tag,
960 bus_space_handle_t bsh1,
962 bus_space_handle_t bsh2,
963 bus_size_t off2, size_t count);
965 static __inline void bus_space_copy_region_2(bus_space_tag_t tag,
966 bus_space_handle_t bsh1,
968 bus_space_handle_t bsh2,
969 bus_size_t off2, size_t count);
971 static __inline void bus_space_copy_region_4(bus_space_tag_t tag,
972 bus_space_handle_t bsh1,
974 bus_space_handle_t bsh2,
975 bus_size_t off2, size_t count);
978 bus_space_copy_region_1(bus_space_tag_t tag, bus_space_handle_t bsh1,
979 bus_size_t off1, bus_space_handle_t bsh2,
980 bus_size_t off2, size_t count)
982 bus_addr_t addr1 = bsh1 + off1;
983 bus_addr_t addr2 = bsh2 + off2;
985 #if defined(_I386_BUS_PIO_H_)
986 #if defined(_I386_BUS_MEMIO_H_)
987 if (tag == I386_BUS_SPACE_IO)
990 if (addr1 >= addr2) {
991 /* src after dest: copy forward */
992 for (; count != 0; count--, addr1++, addr2++)
993 outb(addr2, inb(addr1));
995 /* dest after src: copy backwards */
996 for (addr1 += (count - 1), addr2 += (count - 1);
997 count != 0; count--, addr1--, addr2--)
998 outb(addr2, inb(addr1));
1002 #if defined(_I386_BUS_MEMIO_H_)
1003 #if defined(_I386_BUS_PIO_H_)
1007 if (addr1 >= addr2) {
1008 /* src after dest: copy forward */
1009 for (; count != 0; count--, addr1++, addr2++)
1010 *(volatile u_int8_t *)(addr2) =
1011 *(volatile u_int8_t *)(addr1);
1013 /* dest after src: copy backwards */
1014 for (addr1 += (count - 1), addr2 += (count - 1);
1015 count != 0; count--, addr1--, addr2--)
1016 *(volatile u_int8_t *)(addr2) =
1017 *(volatile u_int8_t *)(addr1);
1023 static __inline void
1024 bus_space_copy_region_2(bus_space_tag_t tag, bus_space_handle_t bsh1,
1025 bus_size_t off1, bus_space_handle_t bsh2,
1026 bus_size_t off2, size_t count)
1028 bus_addr_t addr1 = bsh1 + off1;
1029 bus_addr_t addr2 = bsh2 + off2;
1031 #if defined(_I386_BUS_PIO_H_)
1032 #if defined(_I386_BUS_MEMIO_H_)
1033 if (tag == I386_BUS_SPACE_IO)
1036 if (addr1 >= addr2) {
1037 /* src after dest: copy forward */
1038 for (; count != 0; count--, addr1 += 2, addr2 += 2)
1039 outw(addr2, inw(addr1));
1041 /* dest after src: copy backwards */
1042 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
1043 count != 0; count--, addr1 -= 2, addr2 -= 2)
1044 outw(addr2, inw(addr1));
1048 #if defined(_I386_BUS_MEMIO_H_)
1049 #if defined(_I386_BUS_PIO_H_)
1053 if (addr1 >= addr2) {
1054 /* src after dest: copy forward */
1055 for (; count != 0; count--, addr1 += 2, addr2 += 2)
1056 *(volatile u_int16_t *)(addr2) =
1057 *(volatile u_int16_t *)(addr1);
1059 /* dest after src: copy backwards */
1060 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
1061 count != 0; count--, addr1 -= 2, addr2 -= 2)
1062 *(volatile u_int16_t *)(addr2) =
1063 *(volatile u_int16_t *)(addr1);
1069 static __inline void
1070 bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsh1,
1071 bus_size_t off1, bus_space_handle_t bsh2,
1072 bus_size_t off2, size_t count)
1074 bus_addr_t addr1 = bsh1 + off1;
1075 bus_addr_t addr2 = bsh2 + off2;
1077 #if defined(_I386_BUS_PIO_H_)
1078 #if defined(_I386_BUS_MEMIO_H_)
1079 if (tag == I386_BUS_SPACE_IO)
1082 if (addr1 >= addr2) {
1083 /* src after dest: copy forward */
1084 for (; count != 0; count--, addr1 += 4, addr2 += 4)
1085 outl(addr2, inl(addr1));
1087 /* dest after src: copy backwards */
1088 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
1089 count != 0; count--, addr1 -= 4, addr2 -= 4)
1090 outl(addr2, inl(addr1));
1094 #if defined(_I386_BUS_MEMIO_H_)
1095 #if defined(_I386_BUS_PIO_H_)
1099 if (addr1 >= addr2) {
1100 /* src after dest: copy forward */
1101 for (; count != 0; count--, addr1 += 4, addr2 += 4)
1102 *(volatile u_int32_t *)(addr2) =
1103 *(volatile u_int32_t *)(addr1);
1105 /* dest after src: copy backwards */
1106 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
1107 count != 0; count--, addr1 -= 4, addr2 -= 4)
1108 *(volatile u_int32_t *)(addr2) =
1109 *(volatile u_int32_t *)(addr1);
1115 #endif /* defined(_I386_BUS_PIO_H_) || defined(_I386_MEM_IO_H_) */
1117 #if 0 /* Cause a link error for bus_space_copy_8 */
1118 #define bus_space_copy_region_8 !!! bus_space_copy_region_8 unimplemented !!!
1122 * Bus read/write barrier methods.
1124 * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
1125 * bus_size_t offset, bus_size_t len, int flags);
1127 * Note: the i386 does not currently require barriers, but we must
1128 * provide the flags to MI code.
1130 #define bus_space_barrier(t, h, o, l, f) \
1131 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
1132 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
1133 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
1136 * Flags used in various bus DMA methods.
1138 #define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */
1139 #define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */
1140 #define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */
1141 #define BUS_DMAMEM_NOSYNC 0x04 /* map memory to not require sync */
1142 #define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */
1143 #define BUS_DMA_BUS2 0x20
1144 #define BUS_DMA_BUS3 0x40
1145 #define BUS_DMA_BUS4 0x80
1147 /* Forwards needed by prototypes below. */
1154 * Operations performed by bus_dmamap_sync().
1157 BUS_DMASYNC_PREREAD,
1158 BUS_DMASYNC_POSTREAD,
1159 BUS_DMASYNC_PREWRITE,
1160 BUS_DMASYNC_POSTWRITE
1166 * A machine-dependent opaque type describing the characteristics
1167 * of how to perform DMA mappings. This structure encapsultes
1168 * information concerning address and alignment restrictions, number
1169 * of S/G segments, amount of data per S/G segment, etc.
1171 typedef struct bus_dma_tag *bus_dma_tag_t;
1176 * DMA mapping instance information.
1178 typedef struct bus_dmamap *bus_dmamap_t;
1183 * Describes a single contiguous DMA transaction. Values
1184 * are suitable for programming into DMA registers.
1186 typedef struct bus_dma_segment {
1187 bus_addr_t ds_addr; /* DMA address */
1188 bus_size_t ds_len; /* length of transfer */
1189 } bus_dma_segment_t;
1192 * A function that returns 1 if the address cannot be accessed by
1193 * a device and 0 if it can be.
1195 typedef int bus_dma_filter_t(void *, bus_addr_t);
1198 * Allocate a device specific dma_tag encapsulating the constraints of
1199 * the parent tag in addition to other restrictions specified:
1201 * alignment: alignment for segments.
1202 * boundary: Boundary that segments cannot cross.
1203 * lowaddr: Low restricted address that cannot appear in a mapping.
1204 * highaddr: High restricted address that cannot appear in a mapping.
1205 * filtfunc: An optional function to further test if an address
1206 * within the range of lowaddr and highaddr cannot appear
1208 * filtfuncarg: An argument that will be passed to filtfunc in addition
1209 * to the address to test.
1210 * maxsize: Maximum mapping size supported by this tag.
1211 * nsegments: Number of discontinuities allowed in maps.
1212 * maxsegsz: Maximum size of a segment in the map.
1213 * flags: Bus DMA flags.
1214 * dmat: A pointer to set to a valid dma tag should the return
1215 * value of this function indicate success.
1217 /* XXX Should probably allow specification of alignment */
1218 int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignemnt,
1219 bus_size_t boundary, bus_addr_t lowaddr,
1220 bus_addr_t highaddr, bus_dma_filter_t *filtfunc,
1221 void *filtfuncarg, bus_size_t maxsize, int nsegments,
1222 bus_size_t maxsegsz, int flags, bus_dma_tag_t *dmat);
1224 int bus_dma_tag_destroy(bus_dma_tag_t dmat);
1227 * Allocate a handle for mapping from kva/uva/physical
1228 * address space into bus device space.
1230 int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp);
1233 * Destroy a handle for mapping from kva/uva/physical
1234 * address space into bus device space.
1236 int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map);
1239 * Allocate a piece of memory that can be efficiently mapped into
1240 * bus device space based on the constraints lited in the dma tag.
1241 * A dmamap to for use with dmamap_load is also allocated.
1243 int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
1244 bus_dmamap_t *mapp);
1247 * Free a piece of memory and it's allociated dmamap, that was allocated
1248 * via bus_dmamem_alloc.
1250 void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map);
1253 * A function that processes a successfully loaded dma map or an error
1254 * from a delayed load map.
1256 typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
1259 * Map the buffer buf into bus space using the dmamap map.
1261 int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
1262 bus_size_t buflen, bus_dmamap_callback_t *callback,
1263 void *callback_arg, int flags);
1266 * Perform a syncronization operation on the given map.
1268 void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t);
1269 #define bus_dmamap_sync(dmat, dmamap, op) \
1270 if ((dmamap) != NULL) \
1271 _bus_dmamap_sync(dmat, dmamap, op)
1274 * Release the mapping held by map.
1276 void _bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map);
1277 #define bus_dmamap_unload(dmat, dmamap) \
1278 if ((dmamap) != NULL) \
1279 _bus_dmamap_unload(dmat, dmamap)
1281 #endif /* _I386_BUS_H_ */