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.
72 #ifndef _I386_BUS_AT386_H_
73 #define _I386_BUS_AT386_H_
75 #include <machine/cpufunc.h>
78 * To remain compatible with NetBSD's interface, default to both memio and
79 * pio when neither of them is defined.
81 #if !defined(_I386_BUS_PIO_H_) && !defined(_I386_BUS_MEMIO_H_)
82 #define _I386_BUS_PIO_H_
83 #define _I386_BUS_MEMIO_H_
87 * Values for the i386 bus space tag, not to be used directly by MI code.
89 #define I386_BUS_SPACE_IO 0 /* space is i/o space */
90 #define I386_BUS_SPACE_MEM 1 /* space is mem space */
93 * Bus address and size types
95 typedef u_int bus_addr_t;
96 typedef u_int bus_size_t;
98 #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF
99 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
100 #define BUS_SPACE_MAXSIZE (64 * 1024) /* Maximum supported size */
101 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF
102 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
103 #define BUS_SPACE_MAXADDR 0xFFFFFFFF
105 #define BUS_SPACE_UNRESTRICTED (~0)
108 * Access methods for bus resources and address space.
110 typedef int bus_space_tag_t;
111 typedef u_int bus_space_handle_t;
114 * Map a region of device bus space into CPU virtual address space.
117 #define BUS_SPACE_MAP_CACHEABLE 0x01
118 #define BUS_SPACE_MAP_LINEAR 0x02
120 int bus_space_map(bus_space_tag_t t, bus_addr_t addr, bus_size_t size,
121 int flags, bus_space_handle_t *bshp);
124 * Unmap a region of device bus space.
127 void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
131 * Get a new handle for a subregion of an already-mapped area of bus space.
134 int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
135 bus_size_t offset, bus_size_t size,
136 bus_space_handle_t *nbshp);
139 * Allocate a region of memory that is accessible to devices in bus space.
142 int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
143 bus_addr_t rend, bus_size_t size, bus_size_t align,
144 bus_size_t boundary, int flags, bus_addr_t *addrp,
145 bus_space_handle_t *bshp);
148 * Free a region of bus space accessible memory.
151 void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
154 #if defined(_I386_BUS_PIO_H_) || defined(_I386_BUS_MEMIO_H_)
157 * Read a 1, 2, 4, or 8 byte quantity from bus space
158 * described by tag/handle/offset.
160 static __inline u_int8_t bus_space_read_1(bus_space_tag_t tag,
161 bus_space_handle_t handle,
164 static __inline u_int16_t bus_space_read_2(bus_space_tag_t tag,
165 bus_space_handle_t handle,
168 static __inline u_int32_t bus_space_read_4(bus_space_tag_t tag,
169 bus_space_handle_t handle,
172 static __inline u_int8_t
173 bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle,
176 #if defined (_I386_BUS_PIO_H_)
177 #if defined (_I386_BUS_MEMIO_H_)
178 if (tag == I386_BUS_SPACE_IO)
180 return (inb(handle + offset));
182 #if defined (_I386_BUS_MEMIO_H_)
183 return (*(volatile u_int8_t *)(handle + offset));
187 static __inline u_int16_t
188 bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle,
191 #if defined(_I386_BUS_PIO_H_)
192 #if defined(_I386_BUS_MEMIO_H_)
193 if (tag == I386_BUS_SPACE_IO)
195 return (inw(handle + offset));
197 #if defined(_I386_BUS_MEMIO_H_)
198 return (*(volatile u_int16_t *)(handle + offset));
202 static __inline u_int32_t
203 bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle,
206 #if defined(_I386_BUS_PIO_H_)
207 #if defined(_I386_BUS_MEMIO_H_)
208 if (tag == I386_BUS_SPACE_IO)
210 return (inl(handle + offset));
212 #if defined(_I386_BUS_MEMIO_H_)
213 return (*(volatile u_int32_t *)(handle + offset));
217 #if 0 /* Cause a link error for bus_space_read_8 */
218 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
222 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
223 * described by tag/handle/offset and copy into buffer provided.
225 static __inline void bus_space_read_multi_1(bus_space_tag_t tag,
226 bus_space_handle_t bsh,
227 bus_size_t offset, u_int8_t *addr,
230 static __inline void bus_space_read_multi_2(bus_space_tag_t tag,
231 bus_space_handle_t bsh,
232 bus_size_t offset, u_int16_t *addr,
235 static __inline void bus_space_read_multi_4(bus_space_tag_t tag,
236 bus_space_handle_t bsh,
237 bus_size_t offset, u_int32_t *addr,
241 bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
242 bus_size_t offset, u_int8_t *addr, size_t count)
244 #if defined(_I386_BUS_PIO_H_)
245 #if defined(_I386_BUS_MEMIO_H_)
246 if (tag == I386_BUS_SPACE_IO)
248 insb(bsh + offset, addr, count);
250 #if defined(_I386_BUS_MEMIO_H_)
251 #if defined(_I386_BUS_PIO_H_)
255 __asm __volatile(" \n\
257 1: movb (%2),%%al \n\
260 "=D" (addr), "=c" (count) :
261 "r" (bsh + offset), "0" (addr), "1" (count) :
268 bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
269 bus_size_t offset, u_int16_t *addr, size_t count)
271 #if defined(_I386_BUS_PIO_H_)
272 #if defined(_I386_BUS_MEMIO_H_)
273 if (tag == I386_BUS_SPACE_IO)
275 insw(bsh + offset, addr, count);
277 #if defined(_I386_BUS_MEMIO_H_)
278 #if defined(_I386_BUS_PIO_H_)
282 __asm __volatile(" \n\
284 1: movw (%2),%%ax \n\
287 "=D" (addr), "=c" (count) :
288 "r" (bsh + offset), "0" (addr), "1" (count) :
295 bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
296 bus_size_t offset, u_int32_t *addr, size_t count)
298 #if defined(_I386_BUS_PIO_H_)
299 #if defined(_I386_BUS_MEMIO_H_)
300 if (tag == I386_BUS_SPACE_IO)
302 insl(bsh + offset, addr, count);
304 #if defined(_I386_BUS_MEMIO_H_)
305 #if defined(_I386_BUS_PIO_H_)
309 __asm __volatile(" \n\
311 1: movl (%2),%%eax \n\
314 "=D" (addr), "=c" (count) :
315 "r" (bsh + offset), "0" (addr), "1" (count) :
321 #if 0 /* Cause a link error for bus_space_read_multi_8 */
322 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
326 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
327 * described by tag/handle and starting at `offset' and copy into
330 static __inline void bus_space_read_region_1(bus_space_tag_t tag,
331 bus_space_handle_t bsh,
332 bus_size_t offset, u_int8_t *addr,
335 static __inline void bus_space_read_region_2(bus_space_tag_t tag,
336 bus_space_handle_t bsh,
337 bus_size_t offset, u_int16_t *addr,
340 static __inline void bus_space_read_region_4(bus_space_tag_t tag,
341 bus_space_handle_t bsh,
342 bus_size_t offset, u_int32_t *addr,
347 bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
348 bus_size_t offset, u_int8_t *addr, size_t count)
350 #if defined(_I386_BUS_PIO_H_)
351 #if defined(_I386_BUS_MEMIO_H_)
352 if (tag == I386_BUS_SPACE_IO)
355 int _port_ = bsh + offset; \
356 __asm __volatile(" \n\
362 "=D" (addr), "=c" (count), "=d" (_port_) :
363 "0" (addr), "1" (count), "2" (_port_) :
364 "%eax", "memory", "cc");
367 #if defined(_I386_BUS_MEMIO_H_)
368 #if defined(_I386_BUS_PIO_H_)
372 int _port_ = bsh + offset; \
373 __asm __volatile(" \n\
377 "=D" (addr), "=c" (count), "=S" (_port_) :
378 "0" (addr), "1" (count), "2" (_port_) :
385 bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
386 bus_size_t offset, u_int16_t *addr, size_t count)
388 #if defined(_I386_BUS_PIO_H_)
389 #if defined(_I386_BUS_MEMIO_H_)
390 if (tag == I386_BUS_SPACE_IO)
393 int _port_ = bsh + offset; \
394 __asm __volatile(" \n\
400 "=D" (addr), "=c" (count), "=d" (_port_) :
401 "0" (addr), "1" (count), "2" (_port_) :
402 "%eax", "memory", "cc");
405 #if defined(_I386_BUS_MEMIO_H_)
406 #if defined(_I386_BUS_PIO_H_)
410 int _port_ = bsh + offset; \
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)
426 #if defined(_I386_BUS_PIO_H_)
427 #if defined(_I386_BUS_MEMIO_H_)
428 if (tag == I386_BUS_SPACE_IO)
431 int _port_ = bsh + offset; \
432 __asm __volatile(" \n\
438 "=D" (addr), "=c" (count), "=d" (_port_) :
439 "0" (addr), "1" (count), "2" (_port_) :
440 "%eax", "memory", "cc");
443 #if defined(_I386_BUS_MEMIO_H_)
444 #if defined(_I386_BUS_PIO_H_)
448 int _port_ = bsh + offset; \
449 __asm __volatile(" \n\
453 "=D" (addr), "=c" (count), "=S" (_port_) :
454 "0" (addr), "1" (count), "2" (_port_) :
460 #if 0 /* Cause a link error for bus_space_read_region_8 */
461 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
465 * Write the 1, 2, 4, or 8 byte value `value' to bus space
466 * described by tag/handle/offset.
469 static __inline void bus_space_write_1(bus_space_tag_t tag,
470 bus_space_handle_t bsh,
471 bus_size_t offset, u_int8_t value);
473 static __inline void bus_space_write_2(bus_space_tag_t tag,
474 bus_space_handle_t bsh,
475 bus_size_t offset, u_int16_t value);
477 static __inline void bus_space_write_4(bus_space_tag_t tag,
478 bus_space_handle_t bsh,
479 bus_size_t offset, u_int32_t value);
482 bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsh,
483 bus_size_t offset, u_int8_t value)
485 #if defined(_I386_BUS_PIO_H_)
486 #if defined(_I386_BUS_MEMIO_H_)
487 if (tag == I386_BUS_SPACE_IO)
489 outb(bsh + offset, value);
491 #if defined(_I386_BUS_MEMIO_H_)
492 #if defined(_I386_BUS_PIO_H_)
495 *(volatile u_int8_t *)(bsh + offset) = value;
500 bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t bsh,
501 bus_size_t offset, u_int16_t value)
503 #if defined(_I386_BUS_PIO_H_)
504 #if defined(_I386_BUS_MEMIO_H_)
505 if (tag == I386_BUS_SPACE_IO)
507 outw(bsh + offset, value);
509 #if defined(_I386_BUS_MEMIO_H_)
510 #if defined(_I386_BUS_PIO_H_)
513 *(volatile u_int16_t *)(bsh + offset) = value;
518 bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh,
519 bus_size_t offset, u_int32_t value)
521 #if defined(_I386_BUS_PIO_H_)
522 #if defined(_I386_BUS_MEMIO_H_)
523 if (tag == I386_BUS_SPACE_IO)
525 outl(bsh + offset, value);
527 #if defined(_I386_BUS_MEMIO_H_)
528 #if defined(_I386_BUS_PIO_H_)
531 *(volatile u_int32_t *)(bsh + offset) = value;
535 #if 0 /* Cause a link error for bus_space_write_8 */
536 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
540 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
541 * provided to bus space described by tag/handle/offset.
544 static __inline void bus_space_write_multi_1(bus_space_tag_t tag,
545 bus_space_handle_t bsh,
547 const u_int8_t *addr,
549 static __inline void bus_space_write_multi_2(bus_space_tag_t tag,
550 bus_space_handle_t bsh,
552 const u_int16_t *addr,
555 static __inline void bus_space_write_multi_4(bus_space_tag_t tag,
556 bus_space_handle_t bsh,
558 const u_int32_t *addr,
562 bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
563 bus_size_t offset, const u_int8_t *addr, size_t count)
565 #if defined(_I386_BUS_PIO_H_)
566 #if defined(_I386_BUS_MEMIO_H_)
567 if (tag == I386_BUS_SPACE_IO)
569 outsb(bsh + offset, addr, count);
571 #if defined(_I386_BUS_MEMIO_H_)
572 #if defined(_I386_BUS_PIO_H_)
576 __asm __volatile(" \n\
581 "=S" (addr), "=c" (count) :
582 "r" (bsh + offset), "0" (addr), "1" (count) :
583 "%eax", "memory", "cc");
589 bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
590 bus_size_t offset, const u_int16_t *addr, size_t count)
592 #if defined(_I386_BUS_PIO_H_)
593 #if defined(_I386_BUS_MEMIO_H_)
594 if (tag == I386_BUS_SPACE_IO)
596 outsw(bsh + offset, addr, count);
598 #if defined(_I386_BUS_MEMIO_H_)
599 #if defined(_I386_BUS_PIO_H_)
603 __asm __volatile(" \n\
608 "=S" (addr), "=c" (count) :
609 "r" (bsh + offset), "0" (addr), "1" (count) :
610 "%eax", "memory", "cc");
616 bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
617 bus_size_t offset, const u_int32_t *addr, size_t count)
619 #if defined(_I386_BUS_PIO_H_)
620 #if defined(_I386_BUS_MEMIO_H_)
621 if (tag == I386_BUS_SPACE_IO)
623 outsl(bsh + offset, addr, count);
625 #if defined(_I386_BUS_MEMIO_H_)
626 #if defined(_I386_BUS_PIO_H_)
630 __asm __volatile(" \n\
635 "=S" (addr), "=c" (count) :
636 "r" (bsh + offset), "0" (addr), "1" (count) :
637 "%eax", "memory", "cc");
642 #if 0 /* Cause a link error for bus_space_write_multi_8 */
643 #define bus_space_write_multi_8(t, h, o, a, c) \
644 !!! bus_space_write_multi_8 unimplemented !!!
648 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
649 * to bus space described by tag/handle starting at `offset'.
652 static __inline void bus_space_write_region_1(bus_space_tag_t tag,
653 bus_space_handle_t bsh,
655 const u_int8_t *addr,
657 static __inline void bus_space_write_region_2(bus_space_tag_t tag,
658 bus_space_handle_t bsh,
660 const u_int16_t *addr,
662 static __inline void bus_space_write_region_4(bus_space_tag_t tag,
663 bus_space_handle_t bsh,
665 const u_int32_t *addr,
669 bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
670 bus_size_t offset, const u_int8_t *addr, size_t count)
672 #if defined(_I386_BUS_PIO_H_)
673 #if defined(_I386_BUS_MEMIO_H_)
674 if (tag == I386_BUS_SPACE_IO)
677 int _port_ = bsh + offset; \
678 __asm __volatile(" \n\
684 "=d" (_port_), "=S" (addr), "=c" (count) :
685 "0" (_port_), "1" (addr), "2" (count) :
686 "%eax", "memory", "cc");
689 #if defined(_I386_BUS_MEMIO_H_)
690 #if defined(_I386_BUS_PIO_H_)
694 int _port_ = bsh + offset; \
695 __asm __volatile(" \n\
699 "=D" (_port_), "=S" (addr), "=c" (count) :
700 "0" (_port_), "1" (addr), "2" (count) :
707 bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
708 bus_size_t offset, const u_int16_t *addr, size_t count)
710 #if defined(_I386_BUS_PIO_H_)
711 #if defined(_I386_BUS_MEMIO_H_)
712 if (tag == I386_BUS_SPACE_IO)
715 int _port_ = bsh + offset; \
716 __asm __volatile(" \n\
722 "=d" (_port_), "=S" (addr), "=c" (count) :
723 "0" (_port_), "1" (addr), "2" (count) :
724 "%eax", "memory", "cc");
727 #if defined(_I386_BUS_MEMIO_H_)
728 #if defined(_I386_BUS_PIO_H_)
732 int _port_ = bsh + offset; \
733 __asm __volatile(" \n\
737 "=D" (_port_), "=S" (addr), "=c" (count) :
738 "0" (_port_), "1" (addr), "2" (count) :
745 bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
746 bus_size_t offset, const u_int32_t *addr, size_t count)
748 #if defined(_I386_BUS_PIO_H_)
749 #if defined(_I386_BUS_MEMIO_H_)
750 if (tag == I386_BUS_SPACE_IO)
753 int _port_ = bsh + offset; \
754 __asm __volatile(" \n\
760 "=d" (_port_), "=S" (addr), "=c" (count) :
761 "0" (_port_), "1" (addr), "2" (count) :
762 "%eax", "memory", "cc");
765 #if defined(_I386_BUS_MEMIO_H_)
766 #if defined(_I386_BUS_PIO_H_)
770 int _port_ = bsh + offset; \
771 __asm __volatile(" \n\
775 "=D" (_port_), "=S" (addr), "=c" (count) :
776 "0" (_port_), "1" (addr), "2" (count) :
782 #if 0 /* Cause a link error for bus_space_write_region_8 */
783 #define bus_space_write_region_8 \
784 !!! bus_space_write_region_8 unimplemented !!!
788 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
789 * by tag/handle/offset `count' times.
792 static __inline void bus_space_set_multi_1(bus_space_tag_t tag,
793 bus_space_handle_t bsh,
795 u_int8_t value, size_t count);
796 static __inline void bus_space_set_multi_2(bus_space_tag_t tag,
797 bus_space_handle_t bsh,
799 u_int16_t value, size_t count);
800 static __inline void bus_space_set_multi_4(bus_space_tag_t tag,
801 bus_space_handle_t bsh,
803 u_int32_t value, size_t count);
806 bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
807 bus_size_t offset, u_int8_t value, size_t count)
809 bus_addr_t addr = bsh + offset;
811 #if defined(_I386_BUS_PIO_H_)
812 #if defined(_I386_BUS_MEMIO_H_)
813 if (tag == I386_BUS_SPACE_IO)
818 #if defined(_I386_BUS_MEMIO_H_)
819 #if defined(_I386_BUS_PIO_H_)
823 *(volatile u_int8_t *)(addr) = value;
828 bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
829 bus_size_t offset, u_int16_t value, size_t count)
831 bus_addr_t addr = bsh + offset;
833 #if defined(_I386_BUS_PIO_H_)
834 #if defined(_I386_BUS_MEMIO_H_)
835 if (tag == I386_BUS_SPACE_IO)
840 #if defined(_I386_BUS_MEMIO_H_)
841 #if defined(_I386_BUS_PIO_H_)
845 *(volatile u_int16_t *)(addr) = value;
850 bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
851 bus_size_t offset, u_int32_t value, size_t count)
853 bus_addr_t addr = bsh + offset;
855 #if defined(_I386_BUS_PIO_H_)
856 #if defined(_I386_BUS_MEMIO_H_)
857 if (tag == I386_BUS_SPACE_IO)
862 #if defined(_I386_BUS_MEMIO_H_)
863 #if defined(_I386_BUS_PIO_H_)
867 *(volatile u_int32_t *)(addr) = value;
871 #if 0 /* Cause a link error for bus_space_set_multi_8 */
872 #define bus_space_set_multi_8 !!! bus_space_set_multi_8 unimplemented !!!
876 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
877 * by tag/handle starting at `offset'.
880 static __inline void bus_space_set_region_1(bus_space_tag_t tag,
881 bus_space_handle_t bsh,
882 bus_size_t offset, u_int8_t value,
884 static __inline void bus_space_set_region_2(bus_space_tag_t tag,
885 bus_space_handle_t bsh,
886 bus_size_t offset, u_int16_t value,
888 static __inline void bus_space_set_region_4(bus_space_tag_t tag,
889 bus_space_handle_t bsh,
890 bus_size_t offset, u_int32_t value,
894 bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
895 bus_size_t offset, u_int8_t value, size_t count)
897 bus_addr_t addr = bsh + offset;
899 #if defined(_I386_BUS_PIO_H_)
900 #if defined(_I386_BUS_MEMIO_H_)
901 if (tag == I386_BUS_SPACE_IO)
903 for (; count != 0; count--, addr++)
906 #if defined(_I386_BUS_MEMIO_H_)
907 #if defined(_I386_BUS_PIO_H_)
910 for (; count != 0; count--, addr++)
911 *(volatile u_int8_t *)(addr) = value;
916 bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
917 bus_size_t offset, u_int16_t value, size_t count)
919 bus_addr_t addr = bsh + offset;
921 #if defined(_I386_BUS_PIO_H_)
922 #if defined(_I386_BUS_MEMIO_H_)
923 if (tag == I386_BUS_SPACE_IO)
925 for (; count != 0; count--, addr += 2)
928 #if defined(_I386_BUS_MEMIO_H_)
929 #if defined(_I386_BUS_PIO_H_)
932 for (; count != 0; count--, addr += 2)
933 *(volatile u_int16_t *)(addr) = value;
938 bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
939 bus_size_t offset, u_int32_t value, size_t count)
941 bus_addr_t addr = bsh + offset;
943 #if defined(_I386_BUS_PIO_H_)
944 #if defined(_I386_BUS_MEMIO_H_)
945 if (tag == I386_BUS_SPACE_IO)
947 for (; count != 0; count--, addr += 4)
950 #if defined(_I386_BUS_MEMIO_H_)
951 #if defined(_I386_BUS_PIO_H_)
954 for (; count != 0; count--, addr += 4)
955 *(volatile u_int32_t *)(addr) = value;
959 #if 0 /* Cause a link error for bus_space_set_region_8 */
960 #define bus_space_set_region_8 !!! bus_space_set_region_8 unimplemented !!!
964 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
965 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
968 static __inline void bus_space_copy_region_1(bus_space_tag_t tag,
969 bus_space_handle_t bsh1,
971 bus_space_handle_t bsh2,
972 bus_size_t off2, size_t count);
974 static __inline void bus_space_copy_region_2(bus_space_tag_t tag,
975 bus_space_handle_t bsh1,
977 bus_space_handle_t bsh2,
978 bus_size_t off2, size_t count);
980 static __inline void bus_space_copy_region_4(bus_space_tag_t tag,
981 bus_space_handle_t bsh1,
983 bus_space_handle_t bsh2,
984 bus_size_t off2, size_t count);
987 bus_space_copy_region_1(bus_space_tag_t tag, bus_space_handle_t bsh1,
988 bus_size_t off1, bus_space_handle_t bsh2,
989 bus_size_t off2, size_t count)
991 bus_addr_t addr1 = bsh1 + off1;
992 bus_addr_t addr2 = bsh2 + off2;
994 #if defined(_I386_BUS_PIO_H_)
995 #if defined(_I386_BUS_MEMIO_H_)
996 if (tag == I386_BUS_SPACE_IO)
999 if (addr1 >= addr2) {
1000 /* src after dest: copy forward */
1001 for (; count != 0; count--, addr1++, addr2++)
1002 outb(addr2, inb(addr1));
1004 /* dest after src: copy backwards */
1005 for (addr1 += (count - 1), addr2 += (count - 1);
1006 count != 0; count--, addr1--, addr2--)
1007 outb(addr2, inb(addr1));
1011 #if defined(_I386_BUS_MEMIO_H_)
1012 #if defined(_I386_BUS_PIO_H_)
1016 if (addr1 >= addr2) {
1017 /* src after dest: copy forward */
1018 for (; count != 0; count--, addr1++, addr2++)
1019 *(volatile u_int8_t *)(addr2) =
1020 *(volatile u_int8_t *)(addr1);
1022 /* dest after src: copy backwards */
1023 for (addr1 += (count - 1), addr2 += (count - 1);
1024 count != 0; count--, addr1--, addr2--)
1025 *(volatile u_int8_t *)(addr2) =
1026 *(volatile u_int8_t *)(addr1);
1032 static __inline void
1033 bus_space_copy_region_2(bus_space_tag_t tag, bus_space_handle_t bsh1,
1034 bus_size_t off1, bus_space_handle_t bsh2,
1035 bus_size_t off2, size_t count)
1037 bus_addr_t addr1 = bsh1 + off1;
1038 bus_addr_t addr2 = bsh2 + off2;
1040 #if defined(_I386_BUS_PIO_H_)
1041 #if defined(_I386_BUS_MEMIO_H_)
1042 if (tag == I386_BUS_SPACE_IO)
1045 if (addr1 >= addr2) {
1046 /* src after dest: copy forward */
1047 for (; count != 0; count--, addr1 += 2, addr2 += 2)
1048 outw(addr2, inw(addr1));
1050 /* dest after src: copy backwards */
1051 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
1052 count != 0; count--, addr1 -= 2, addr2 -= 2)
1053 outw(addr2, inw(addr1));
1057 #if defined(_I386_BUS_MEMIO_H_)
1058 #if defined(_I386_BUS_PIO_H_)
1062 if (addr1 >= addr2) {
1063 /* src after dest: copy forward */
1064 for (; count != 0; count--, addr1 += 2, addr2 += 2)
1065 *(volatile u_int16_t *)(addr2) =
1066 *(volatile u_int16_t *)(addr1);
1068 /* dest after src: copy backwards */
1069 for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
1070 count != 0; count--, addr1 -= 2, addr2 -= 2)
1071 *(volatile u_int16_t *)(addr2) =
1072 *(volatile u_int16_t *)(addr1);
1078 static __inline void
1079 bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsh1,
1080 bus_size_t off1, bus_space_handle_t bsh2,
1081 bus_size_t off2, size_t count)
1083 bus_addr_t addr1 = bsh1 + off1;
1084 bus_addr_t addr2 = bsh2 + off2;
1086 #if defined(_I386_BUS_PIO_H_)
1087 #if defined(_I386_BUS_MEMIO_H_)
1088 if (tag == I386_BUS_SPACE_IO)
1091 if (addr1 >= addr2) {
1092 /* src after dest: copy forward */
1093 for (; count != 0; count--, addr1 += 4, addr2 += 4)
1094 outl(addr2, inl(addr1));
1096 /* dest after src: copy backwards */
1097 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
1098 count != 0; count--, addr1 -= 4, addr2 -= 4)
1099 outl(addr2, inl(addr1));
1103 #if defined(_I386_BUS_MEMIO_H_)
1104 #if defined(_I386_BUS_PIO_H_)
1108 if (addr1 >= addr2) {
1109 /* src after dest: copy forward */
1110 for (; count != 0; count--, addr1 += 4, addr2 += 4)
1111 *(volatile u_int32_t *)(addr2) =
1112 *(volatile u_int32_t *)(addr1);
1114 /* dest after src: copy backwards */
1115 for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
1116 count != 0; count--, addr1 -= 4, addr2 -= 4)
1117 *(volatile u_int32_t *)(addr2) =
1118 *(volatile u_int32_t *)(addr1);
1124 #endif /* defined(_I386_BUS_PIO_H_) || defined(_I386_MEM_IO_H_) */
1126 #if 0 /* Cause a link error for bus_space_copy_8 */
1127 #define bus_space_copy_region_8 !!! bus_space_copy_region_8 unimplemented !!!
1131 * Bus read/write barrier methods.
1133 * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
1134 * bus_size_t offset, bus_size_t len, int flags);
1137 * Note that BUS_SPACE_BARRIER_WRITE doesn't do anything other than
1138 * prevent reordering by the compiler; all Intel x86 processors currently
1139 * retire operations outside the CPU in program order.
1141 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
1142 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
1144 static __inline void
1145 bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
1146 bus_size_t offset, bus_size_t len, int flags)
1148 if (flags & BUS_SPACE_BARRIER_READ)
1149 __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory");
1151 __asm __volatile("" : : : "memory");
1155 * Flags used in various bus DMA methods.
1157 #define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */
1158 #define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */
1159 #define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */
1160 #define BUS_DMAMEM_NOSYNC 0x04 /* map memory to not require sync */
1161 #define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */
1162 #define BUS_DMA_BUS2 0x20
1163 #define BUS_DMA_BUS3 0x40
1164 #define BUS_DMA_BUS4 0x80
1166 /* Forwards needed by prototypes below. */
1173 * Operations performed by bus_dmamap_sync().
1176 BUS_DMASYNC_PREREAD,
1177 BUS_DMASYNC_POSTREAD,
1178 BUS_DMASYNC_PREWRITE,
1179 BUS_DMASYNC_POSTWRITE
1185 * A machine-dependent opaque type describing the characteristics
1186 * of how to perform DMA mappings. This structure encapsultes
1187 * information concerning address and alignment restrictions, number
1188 * of S/G segments, amount of data per S/G segment, etc.
1190 typedef struct bus_dma_tag *bus_dma_tag_t;
1195 * DMA mapping instance information.
1197 typedef struct bus_dmamap *bus_dmamap_t;
1202 * Describes a single contiguous DMA transaction. Values
1203 * are suitable for programming into DMA registers.
1205 typedef struct bus_dma_segment {
1206 bus_addr_t ds_addr; /* DMA address */
1207 bus_size_t ds_len; /* length of transfer */
1208 } bus_dma_segment_t;
1211 * A function that returns 1 if the address cannot be accessed by
1212 * a device and 0 if it can be.
1214 typedef int bus_dma_filter_t(void *, bus_addr_t);
1217 * Allocate a device specific dma_tag encapsulating the constraints of
1218 * the parent tag in addition to other restrictions specified:
1220 * alignment: alignment for segments.
1221 * boundary: Boundary that segments cannot cross.
1222 * lowaddr: Low restricted address that cannot appear in a mapping.
1223 * highaddr: High restricted address that cannot appear in a mapping.
1224 * filtfunc: An optional function to further test if an address
1225 * within the range of lowaddr and highaddr cannot appear
1227 * filtfuncarg: An argument that will be passed to filtfunc in addition
1228 * to the address to test.
1229 * maxsize: Maximum mapping size supported by this tag.
1230 * nsegments: Number of discontinuities allowed in maps.
1231 * maxsegsz: Maximum size of a segment in the map.
1232 * flags: Bus DMA flags.
1233 * dmat: A pointer to set to a valid dma tag should the return
1234 * value of this function indicate success.
1236 /* XXX Should probably allow specification of alignment */
1237 int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment,
1238 bus_size_t boundary, bus_addr_t lowaddr,
1239 bus_addr_t highaddr, bus_dma_filter_t *filtfunc,
1240 void *filtfuncarg, bus_size_t maxsize, int nsegments,
1241 bus_size_t maxsegsz, int flags, bus_dma_tag_t *dmat);
1243 int bus_dma_tag_destroy(bus_dma_tag_t dmat);
1246 * Allocate a handle for mapping from kva/uva/physical
1247 * address space into bus device space.
1249 int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp);
1252 * Destroy a handle for mapping from kva/uva/physical
1253 * address space into bus device space.
1255 int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map);
1258 * Allocate a piece of memory that can be efficiently mapped into
1259 * bus device space based on the constraints lited in the dma tag.
1260 * A dmamap to for use with dmamap_load is also allocated.
1262 int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
1263 bus_dmamap_t *mapp);
1266 * Free a piece of memory and it's allociated dmamap, that was allocated
1267 * via bus_dmamem_alloc.
1269 void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map);
1272 * A function that processes a successfully loaded dma map or an error
1273 * from a delayed load map.
1275 typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
1278 * Map the buffer buf into bus space using the dmamap map.
1280 int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
1281 bus_size_t buflen, bus_dmamap_callback_t *callback,
1282 void *callback_arg, int flags);
1285 * Perform a syncronization operation on the given map.
1287 void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t);
1288 #define bus_dmamap_sync(dmat, dmamap, op) \
1289 if ((dmamap) != NULL) \
1290 _bus_dmamap_sync(dmat, dmamap, op)
1293 * Release the mapping held by map.
1295 void _bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map);
1296 #define bus_dmamap_unload(dmat, dmamap) \
1297 if ((dmamap) != NULL) \
1298 _bus_dmamap_unload(dmat, dmamap)
1300 #endif /* _I386_BUS_AT386_H_ */