1 /* $NetBSD: bus.h,v 1.60 2009/12/04 12:22:16 nakayama Exp $ */
4 * Copyright (c) 1996, 1997, 1998, 2001 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.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1997-1999, 2001 Eduardo E. Horvath. All rights reserved.
35 * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
36 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by Christopher G. Demetriou
49 * for the NetBSD Project.
50 * 4. The name of the author may not be used to endorse or promote products
51 * derived from this software without specific prior written permission
53 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
54 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
57 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
58 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
62 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 #include <machine/types.h>
69 #include <machine/ctlreg.h>
75 #define BSDB_ACCESS 0x01
77 extern int bus_space_debug
;
80 * UPA and SBUS spaces are non-cached and big endian
81 * (except for RAM and PROM)
83 * PCI spaces are non-cached and little endian
94 /* For backwards compatibility */
95 #define SPARC_BUS_SPACE UPA_BUS_SPACE
97 #define __BUS_SPACE_HAS_STREAM_METHODS 1
100 * Bus address and size types
102 typedef struct _bus_space_handle
{
106 } bus_space_handle_t
;
107 typedef enum bus_type bus_type_t
;
108 typedef uint64_t bus_addr_t
;
109 typedef uint64_t bus_size_t
;
112 * XXXX -- convert prom virtual address to bus_space_handle_t
114 #define sparc_promaddr_to_handle(tag, promaddr, hp) \
116 (hp)->_ptr = (uint64_t)(promaddr); \
117 (hp)->_asi = ASI_PRIMARY; \
118 (hp)->_sasi = ASI_PRIMARY; \
121 /* For buses which have an iospace. */
122 #define BUS_ADDR_IOSPACE(x) ((x)>>32)
123 #define BUS_ADDR_PADDR(x) ((x)&0xffffffff)
124 #define BUS_ADDR(io, pa) ((((bus_addr_t)io)<<32)|(pa))
127 * Access methods for bus resources and address space.
129 typedef struct sparc_bus_space_tag
*bus_space_tag_t
;
131 struct sparc_bus_space_tag
{
133 bus_space_tag_t parent
;
135 * Windows onto the parent bus that this tag maps. If ranges
136 * is non-NULL, the address will be translated, and recursively
137 * mapped via the parent tag.
139 struct openprom_range
*ranges
;
144 int (*sparc_bus_alloc
)(bus_space_tag_t
, bus_addr_t
,
145 bus_addr_t
, bus_size_t
, bus_size_t
, bus_size_t
, int,
146 bus_addr_t
*, bus_space_handle_t
*);
148 void (*sparc_bus_free
)(bus_space_tag_t
, bus_space_handle_t
,
151 int (*sparc_bus_map
)(bus_space_tag_t
, bus_addr_t
, bus_size_t
,
152 int, vaddr_t
, bus_space_handle_t
*);
154 int (*sparc_bus_unmap
)(bus_space_tag_t
, bus_space_handle_t
,
157 int (*sparc_bus_subregion
)(bus_space_tag_t
,
158 bus_space_handle_t
, bus_size_t
, bus_size_t
,
159 bus_space_handle_t
*);
161 paddr_t (*sparc_bus_mmap
)(bus_space_tag_t
, bus_addr_t
, off_t
,
164 void *(*sparc_intr_establish
)(bus_space_tag_t
, int, int,
165 int (*)(void *), void *, void (*)(void));
169 bus_space_tag_t
bus_space_tag_alloc(bus_space_tag_t
, void *);
170 int bus_space_translate_address_generic(struct openprom_range
*,
175 * The following macro could be used to generate the bus_space*() functions
176 * but it uses a gcc extension and is ANSI-only.
177 #define PROTO_bus_space_xxx (bus_space_tag_t t, ...)
178 #define RETURNTYPE_bus_space_xxx void *
179 #define BUSFUN(name, returntype, t, args...) \
180 static __inline RETURNTYPE_##name \
181 bus_##name PROTO_##name \
183 while (t->sparc_##name == NULL) \
185 return (*(t)->sparc_##name)(t, args); \
191 * Bus space function prototypes.
193 static int bus_space_alloc(
195 bus_addr_t
, /* reg start */
196 bus_addr_t
, /* reg end */
197 bus_size_t
, /* size */
198 bus_size_t
, /* alignment */
199 bus_size_t
, /* boundary */
202 bus_space_handle_t
*);
203 static void bus_space_free(
207 static int bus_space_map(
212 bus_space_handle_t
*);
213 static int bus_space_unmap(
217 static int bus_space_subregion(
222 bus_space_handle_t
*);
223 static void bus_space_barrier(
229 static paddr_t
bus_space_mmap(
235 static void *bus_intr_establish(
237 int, /*bus-specific intr*/
238 int, /*device class level,
240 int (*)(void *), /*handler*/
241 void *); /*handler arg*/
244 /* This macro finds the first "upstream" implementation of method `f' */
245 #define _BS_CALL(t,f) \
246 while (t->f == NULL) \
251 bus_space_alloc(bus_space_tag_t t
, bus_addr_t rs
, bus_addr_t re
, bus_size_t s
,
252 bus_size_t a
, bus_size_t b
, int f
, bus_addr_t
*ap
,
253 bus_space_handle_t
*hp
)
255 _BS_CALL(t
, sparc_bus_alloc
)(t
, rs
, re
, s
, a
, b
, f
, ap
, hp
);
259 bus_space_free(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t s
)
261 _BS_CALL(t
, sparc_bus_free
)(t
, h
, s
);
265 bus_space_map(bus_space_tag_t t
, bus_addr_t a
, bus_size_t s
, int f
,
266 bus_space_handle_t
*hp
)
268 _BS_CALL(t
, sparc_bus_map
)(t
, a
, s
, f
, 0, hp
);
272 bus_space_unmap(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t s
)
274 _BS_CALL(t
, sparc_bus_unmap
)(t
, h
, s
);
278 bus_space_subregion(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
279 bus_size_t s
, bus_space_handle_t
*hp
)
281 _BS_CALL(t
, sparc_bus_subregion
)(t
, h
, o
, s
, hp
);
284 static __inline paddr_t
285 bus_space_mmap(bus_space_tag_t t
, bus_addr_t a
, off_t o
, int p
, int f
)
287 _BS_CALL(t
, sparc_bus_mmap
)(t
, a
, o
, p
, f
);
290 static __inline
void *
291 bus_intr_establish(bus_space_tag_t t
, int p
, int l
, int (*h
)(void *), void *a
)
293 _BS_CALL(t
, sparc_intr_establish
)(t
, p
, l
, h
, a
, NULL
);
296 /* XXXX Things get complicated if we use unmapped register accesses. */
297 #define bus_space_vaddr(t, h) (PHYS_ASI((h)._asi) ? \
298 NULL : (void *)(vaddr_t)((h)._ptr))
300 /* flags for bus space map functions */
301 #define BUS_SPACE_MAP_CACHEABLE 0x0001
302 #define BUS_SPACE_MAP_LINEAR 0x0002
303 #define BUS_SPACE_MAP_READONLY 0x0004
304 #define BUS_SPACE_MAP_PREFETCHABLE 0x0008
305 #define BUS_SPACE_MAP_BUS1 0x0100
306 #define BUS_SPACE_MAP_BUS2 0x0200
307 #define BUS_SPACE_MAP_BUS3 0x0400
308 #define BUS_SPACE_MAP_BUS4 0x0800
309 /* sparc uses this, it's not supposed to do anything on sparc64 */
310 #define BUS_SPACE_MAP_LARGE 0
312 /* flags for bus_space_barrier() */
313 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
314 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
317 bus_space_barrier(bus_space_tag_t t
, bus_space_handle_t h
,
318 bus_size_t o
, bus_size_t s
, int f
)
321 * We have a bit of a problem with the bus_space_barrier()
322 * interface. It defines a read barrier and a write barrier
323 * which really don't map to the 7 different types of memory
324 * barriers in the SPARC v9 instruction set.
326 if (f
== BUS_SPACE_BARRIER_READ
)
327 /* A load followed by a load to the same location? */
328 __asm
volatile("membar #Lookaside");
329 else if (f
== BUS_SPACE_BARRIER_WRITE
)
330 /* A store followed by a store? */
331 __asm
volatile("membar #StoreStore");
333 /* A store followed by a load? */
334 __asm
volatile("membar #StoreLoad|#MemIssue|#Lookaside");
338 * uintN_t bus_space_read_N(bus_space_tag_t tag,
339 * bus_space_handle_t bsh, bus_size_t offset);
341 * Read a 1, 2, 4, or 8 byte quantity from bus space
342 * described by tag/handle/offset.
344 #ifndef BUS_SPACE_DEBUG
345 #define bus_space_read_1(t, h, o) \
346 (0 ? (t)->type : lduba((h)._ptr + (o), (h)._asi))
348 #define bus_space_read_2(t, h, o) \
349 (0 ? (t)->type : lduha((h)._ptr + (o), (h)._asi))
351 #define bus_space_read_4(t, h, o) \
352 (0 ? (t)->type : lda((h)._ptr + (o), (h)._asi))
354 #define bus_space_read_8(t, h, o) \
355 (0 ? (t)->type : ldxa((h)._ptr + (o), (h)._asi))
357 #define bus_space_read_1(t, h, o) ({ \
359 lduba((h)._ptr + (o), (h)._asi); \
360 if (bus_space_debug & BSDB_ACCESS) \
361 printf("bsr1(%llx + %llx, %x) -> %x\n", (long long)(h)._ptr, \
363 (h)._asi, (uint32_t) __bv); \
366 #define bus_space_read_2(t, h, o) ({ \
368 lduha((h)._ptr + (o), (h)._asi); \
369 if (bus_space_debug & BSDB_ACCESS) \
370 printf("bsr2(%llx + %llx, %x) -> %x\n", (long long)(h)._ptr, \
372 (h)._asi, (uint32_t)__bv); \
375 #define bus_space_read_4(t, h, o) ({ \
377 lda((h)._ptr + (o), (h)._asi); \
378 if (bus_space_debug & BSDB_ACCESS) \
379 printf("bsr4(%llx + %llx, %x) -> %x\n", (long long)(h)._ptr, \
384 #define bus_space_read_8(t, h, o) ({ \
386 ldxa((h)._ptr + (o), (h)._asi); \
387 if (bus_space_debug & BSDB_ACCESS) \
388 printf("bsr8(%llx + %llx, %x) -> %llx\n", (long long)(h)._ptr, \
390 (h)._asi, (long long)__bv); \
394 * void bus_space_read_multi_N(bus_space_tag_t tag,
395 * bus_space_handle_t bsh, bus_size_t offset,
396 * uintN_t *addr, size_t count);
398 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
399 * described by tag/handle/offset and copy into buffer provided.
403 bus_space_read_multi_1(bus_space_tag_t
, bus_space_handle_t
,
404 bus_size_t
, uint8_t *, size_t);
406 bus_space_read_multi_2(bus_space_tag_t
, bus_space_handle_t
,
407 bus_size_t
, uint16_t *, size_t);
409 bus_space_read_multi_4(bus_space_tag_t
, bus_space_handle_t
,
410 bus_size_t
, uint32_t *, size_t);
412 bus_space_read_multi_8(bus_space_tag_t
, bus_space_handle_t
,
413 bus_size_t
, uint64_t *, size_t);
416 bus_space_read_multi_1(bus_space_tag_t t
, bus_space_handle_t h
,
417 bus_size_t o
, uint8_t * a
, size_t c
)
420 *a
++ = bus_space_read_1(t
, h
, o
);
424 bus_space_read_multi_2(bus_space_tag_t t
, bus_space_handle_t h
,
425 bus_size_t o
, uint16_t * a
, size_t c
)
428 *a
++ = bus_space_read_2(t
, h
, o
);
432 bus_space_read_multi_4(bus_space_tag_t t
, bus_space_handle_t h
,
433 bus_size_t o
, uint32_t * a
, size_t c
)
436 *a
++ = bus_space_read_4(t
, h
, o
);
440 bus_space_read_multi_8(bus_space_tag_t t
, bus_space_handle_t h
,
441 bus_size_t o
, uint64_t * a
, size_t c
)
444 *a
++ = bus_space_read_8(t
, h
, o
);
448 * void bus_space_write_N(bus_space_tag_t tag,
449 * bus_space_handle_t bsh, bus_size_t offset,
452 * Write the 1, 2, 4, or 8 byte value `value' to bus space
453 * described by tag/handle/offset.
455 #ifndef BUS_SPACE_DEBUG
456 #define bus_space_write_1(t, h, o, v) \
457 (0 ? (t)->type : ((void)(stba((h)._ptr + (o), (h)._asi, (v)))))
459 #define bus_space_write_2(t, h, o, v) \
460 (0 ? (t)->type : ((void)(stha((h)._ptr + (o), (h)._asi, (v)))))
462 #define bus_space_write_4(t, h, o, v) \
463 (0 ? (t)->type : ((void)(sta((h)._ptr + (o), (h)._asi, (v)))))
465 #define bus_space_write_8(t, h, o, v) \
466 (0 ? (t)->type : ((void)(stxa((h)._ptr + (o), (h)._asi, (v)))))
468 #define bus_space_write_1(t, h, o, v) ({ \
469 if (bus_space_debug & BSDB_ACCESS) \
470 printf("bsw1(%llx + %llx, %x) <- %x\n", (long long)(h)._ptr, \
472 (h)._asi, (uint32_t) v); \
473 ((void)(stba((h)._ptr + (o), (h)._asi, (v)))); })
475 #define bus_space_write_2(t, h, o, v) ({ \
476 if (bus_space_debug & BSDB_ACCESS) \
477 printf("bsw2(%llx + %llx, %x) <- %x\n", (long long)(h)._ptr, \
479 (h)._asi, (uint32_t) v); \
480 ((void)(stha((h)._ptr + (o), (h)._asi, (v)))); })
482 #define bus_space_write_4(t, h, o, v) ({ \
483 if (bus_space_debug & BSDB_ACCESS) \
484 printf("bsw4(%llx + %llx, %x) <- %x\n", (long long)(h)._ptr, \
486 (h)._asi, (uint32_t) v); \
487 ((void)(sta((h)._ptr + (o), (h)._asi, (v)))); })
489 #define bus_space_write_8(t, h, o, v) ({ \
490 if (bus_space_debug & BSDB_ACCESS) \
491 printf("bsw8(%llx + %llx, %x) <- %llx\n", (long long)(h)._ptr, \
493 (h)._asi, (long long) v); \
494 ((void)(stxa((h)._ptr + (o), (h)._asi, (v)))); })
497 * void bus_space_write_multi_N(bus_space_tag_t tag,
498 * bus_space_handle_t bsh, bus_size_t offset,
499 * const uintN_t *addr, size_t count);
501 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
502 * provided to bus space described by tag/handle/offset.
506 bus_space_write_multi_1(bus_space_tag_t tag
,
507 bus_space_handle_t bsh
, bus_size_t offset
,
508 const uint8_t *addr
, size_t count
);
510 bus_space_write_multi_2(bus_space_tag_t tag
,
511 bus_space_handle_t bsh
, bus_size_t offset
,
512 const uint16_t *addr
, size_t count
);
514 bus_space_write_multi_4(bus_space_tag_t tag
,
515 bus_space_handle_t bsh
, bus_size_t offset
,
516 const uint32_t *addr
, size_t count
);
518 bus_space_write_multi_8(bus_space_tag_t tag
,
519 bus_space_handle_t bsh
, bus_size_t offset
,
520 const uint64_t *addr
, size_t count
);
523 bus_space_write_multi_1(bus_space_tag_t t
,
524 bus_space_handle_t h
, bus_size_t o
,
525 const uint8_t *a
, size_t c
)
528 bus_space_write_1(t
, h
, o
, *a
++);
532 bus_space_write_multi_2(bus_space_tag_t t
,
533 bus_space_handle_t h
, bus_size_t o
,
534 const uint16_t *a
, size_t c
)
537 bus_space_write_2(t
, h
, o
, *a
++);
541 bus_space_write_multi_4(bus_space_tag_t t
,
542 bus_space_handle_t h
, bus_size_t o
,
543 const uint32_t *a
, size_t c
)
546 bus_space_write_4(t
, h
, o
, *a
++);
550 bus_space_write_multi_8(bus_space_tag_t t
,
551 bus_space_handle_t h
, bus_size_t o
,
552 const uint64_t *a
, size_t c
)
555 bus_space_write_8(t
, h
, o
, *a
++);
559 * void bus_space_set_multi_N(bus_space_tag_t tag,
560 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
563 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
564 * by tag/handle/offset `count' times.
568 bus_space_set_multi_1(bus_space_tag_t t
,
569 bus_space_handle_t h
, bus_size_t o
, uint8_t v
,
572 bus_space_set_multi_2(bus_space_tag_t t
,
573 bus_space_handle_t h
, bus_size_t o
, uint16_t v
,
576 bus_space_set_multi_4(bus_space_tag_t t
,
577 bus_space_handle_t h
, bus_size_t o
, uint32_t v
,
580 bus_space_set_multi_8(bus_space_tag_t t
,
581 bus_space_handle_t h
, bus_size_t o
, uint64_t v
,
585 bus_space_set_multi_1(bus_space_tag_t t
,
586 bus_space_handle_t h
, bus_size_t o
, uint8_t v
,
590 bus_space_write_1(t
, h
, o
, v
);
594 bus_space_set_multi_2(bus_space_tag_t t
,
595 bus_space_handle_t h
, bus_size_t o
, uint16_t v
,
599 bus_space_write_2(t
, h
, o
, v
);
603 bus_space_set_multi_4(bus_space_tag_t t
,
604 bus_space_handle_t h
, bus_size_t o
, uint32_t v
,
608 bus_space_write_4(t
, h
, o
, v
);
612 bus_space_set_multi_8(bus_space_tag_t t
,
613 bus_space_handle_t h
, bus_size_t o
, uint64_t v
,
617 bus_space_write_8(t
, h
, o
, v
);
621 * void bus_space_read_region_N(bus_space_tag_t tag,
622 * bus_space_handle_t bsh, bus_size_t off,
623 * uintN_t *addr, bus_size_t count);
626 static void bus_space_read_region_1(bus_space_tag_t
,
631 static void bus_space_read_region_2(bus_space_tag_t
,
636 static void bus_space_read_region_4(bus_space_tag_t
,
641 static void bus_space_read_region_8(bus_space_tag_t
,
648 bus_space_read_region_1(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
649 uint8_t *a
, bus_size_t c
)
651 for (; c
; a
++, c
--, o
++)
652 *a
= bus_space_read_1(t
, h
, o
);
655 bus_space_read_region_2(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
656 uint16_t *a
, bus_size_t c
)
658 for (; c
; a
++, c
--, o
+=2)
659 *a
= bus_space_read_2(t
, h
, o
);
662 bus_space_read_region_4(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
663 uint32_t *a
, bus_size_t c
)
665 for (; c
; a
++, c
--, o
+=4)
666 *a
= bus_space_read_4(t
, h
, o
);
669 bus_space_read_region_8(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
670 uint64_t *a
, bus_size_t c
)
672 for (; c
; a
++, c
--, o
+=8)
673 *a
= bus_space_read_8(t
, h
, o
);
677 * void bus_space_write_region_N(bus_space_tag_t tag,
678 * bus_space_handle_t bsh, bus_size_t off,
679 * uintN_t *addr, bus_size_t count);
682 static void bus_space_write_region_1(bus_space_tag_t
,
687 static void bus_space_write_region_2(bus_space_tag_t
,
692 static void bus_space_write_region_4(bus_space_tag_t
,
697 static void bus_space_write_region_8(bus_space_tag_t
,
704 bus_space_write_region_1(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
705 const uint8_t *a
, bus_size_t c
)
707 for (; c
; a
++, c
--, o
++)
708 bus_space_write_1(t
, h
, o
, *a
);
712 bus_space_write_region_2(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
713 const uint16_t *a
, bus_size_t c
)
715 for (; c
; a
++, c
--, o
+=2)
716 bus_space_write_2(t
, h
, o
, *a
);
720 bus_space_write_region_4(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
721 const uint32_t *a
, bus_size_t c
)
723 for (; c
; a
++, c
--, o
+=4)
724 bus_space_write_4(t
, h
, o
, *a
);
728 bus_space_write_region_8(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
729 const uint64_t *a
, bus_size_t c
)
731 for (; c
; a
++, c
--, o
+=8)
732 bus_space_write_8(t
, h
, o
, *a
);
737 * void bus_space_set_region_N(bus_space_tag_t tag,
738 * bus_space_handle_t bsh, bus_size_t off,
739 * uintN_t *addr, bus_size_t count);
742 static void bus_space_set_region_1(bus_space_tag_t
,
747 static void bus_space_set_region_2(bus_space_tag_t
,
752 static void bus_space_set_region_4(bus_space_tag_t
,
757 static void bus_space_set_region_8(bus_space_tag_t
,
764 bus_space_set_region_1(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
765 const uint8_t v
, bus_size_t c
)
768 bus_space_write_1(t
, h
, o
, v
);
772 bus_space_set_region_2(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
773 const uint16_t v
, bus_size_t c
)
776 bus_space_write_2(t
, h
, o
, v
);
780 bus_space_set_region_4(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
781 const uint32_t v
, bus_size_t c
)
784 bus_space_write_4(t
, h
, o
, v
);
788 bus_space_set_region_8(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
789 const uint64_t v
, bus_size_t c
)
792 bus_space_write_8(t
, h
, o
, v
);
797 * void bus_space_copy_region_N(bus_space_tag_t tag,
798 * bus_space_handle_t bsh1, bus_size_t off1,
799 * bus_space_handle_t bsh2, bus_size_t off2,
802 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
803 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
805 static void bus_space_copy_region_1(bus_space_tag_t
,
811 static void bus_space_copy_region_2(bus_space_tag_t
,
817 static void bus_space_copy_region_4(bus_space_tag_t
,
823 static void bus_space_copy_region_8(bus_space_tag_t
,
832 bus_space_copy_region_1(bus_space_tag_t t
, bus_space_handle_t h1
, bus_size_t o1
,
833 bus_space_handle_t h2
, bus_size_t o2
, bus_size_t c
)
835 for (; c
; c
--, o1
++, o2
++)
836 bus_space_write_1(t
, h1
, o1
, bus_space_read_1(t
, h2
, o2
));
840 bus_space_copy_region_2(bus_space_tag_t t
, bus_space_handle_t h1
, bus_size_t o1
,
841 bus_space_handle_t h2
, bus_size_t o2
, bus_size_t c
)
843 for (; c
; c
--, o1
+=2, o2
+=2)
844 bus_space_write_2(t
, h1
, o1
, bus_space_read_2(t
, h2
, o2
));
848 bus_space_copy_region_4(bus_space_tag_t t
, bus_space_handle_t h1
, bus_size_t o1
,
849 bus_space_handle_t h2
, bus_size_t o2
, bus_size_t c
)
851 for (; c
; c
--, o1
+=4, o2
+=4)
852 bus_space_write_4(t
, h1
, o1
, bus_space_read_4(t
, h2
, o2
));
856 bus_space_copy_region_8(bus_space_tag_t t
, bus_space_handle_t h1
, bus_size_t o1
,
857 bus_space_handle_t h2
, bus_size_t o2
, bus_size_t c
)
859 for (; c
; c
--, o1
+=8, o2
+=8)
860 bus_space_write_8(t
, h1
, o1
, bus_space_read_8(t
, h2
, o2
));
864 * uintN_t bus_space_read_stream_N(bus_space_tag_t tag,
865 * bus_space_handle_t bsh, bus_size_t offset);
867 * Read a 1, 2, 4, or 8 byte quantity from bus space
868 * described by tag/handle/offset.
870 #ifndef BUS_SPACE_DEBUG
871 #define bus_space_read_stream_1(t, h, o) \
872 (0 ? (t)->type : lduba((h)._ptr + (o), (h)._sasi))
874 #define bus_space_read_stream_2(t, h, o) \
875 (0 ? (t)->type : lduha((h)._ptr + (o), (h)._sasi))
877 #define bus_space_read_stream_4(t, h, o) \
878 (0 ? (t)->type : lda((h)._ptr + (o), (h)._sasi))
880 #define bus_space_read_stream_8(t, h, o) \
881 (0 ? (t)->type : ldxa((h)._ptr + (o), (h)._sasi))
883 #define bus_space_read_stream_1(t, h, o) ({ \
885 lduba((h)._ptr + (o), (h)._sasi); \
886 if (bus_space_debug & BSDB_ACCESS) \
887 printf("bsr1(%llx + %llx, %x) -> %x\n", (long long)(h)._ptr, \
889 (h)._sasi, (uint32_t) __bv); \
892 #define bus_space_read_stream_2(t, h, o) ({ \
894 lduha((h)._ptr + (o), (h)._sasi); \
895 if (bus_space_debug & BSDB_ACCESS) \
896 printf("bsr2(%llx + %llx, %x) -> %x\n", (long long)(h)._ptr, \
898 (h)._sasi, (uint32_t)__bv); \
901 #define bus_space_read_stream_4(t, h, o) ({ \
903 lda((h)._ptr + (o), (h)._sasi); \
904 if (bus_space_debug & BSDB_ACCESS) \
905 printf("bsr4(%llx + %llx, %x) -> %x\n", (long long)(h)._ptr, \
910 #define bus_space_read_stream_8(t, h, o) ({ \
912 ldxa((h)._ptr + (o), (h)._sasi); \
913 if (bus_space_debug & BSDB_ACCESS) \
914 printf("bsr8(%llx + %llx, %x) -> %llx\n", (long long)(h)._ptr, \
916 (h)._sasi, (long long)__bv); \
920 * void bus_space_read_multi_stream_N(bus_space_tag_t tag,
921 * bus_space_handle_t bsh, bus_size_t offset,
922 * uintN_t *addr, size_t count);
924 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
925 * described by tag/handle/offset and copy into buffer provided.
929 bus_space_read_multi_stream_1(bus_space_tag_t t
,
930 bus_space_handle_t h
, bus_size_t o
,
931 uint8_t *a
, size_t c
);
933 bus_space_read_multi_stream_2(bus_space_tag_t t
,
934 bus_space_handle_t h
, bus_size_t o
,
935 uint16_t *a
, size_t c
);
937 bus_space_read_multi_stream_4(bus_space_tag_t t
,
938 bus_space_handle_t h
, bus_size_t o
,
939 uint32_t *a
, size_t c
);
941 bus_space_read_multi_stream_8(bus_space_tag_t t
,
942 bus_space_handle_t h
, bus_size_t o
,
943 uint64_t *a
, size_t c
);
946 bus_space_read_multi_stream_1(bus_space_tag_t t
,
947 bus_space_handle_t h
, bus_size_t o
,
948 uint8_t *a
, size_t c
)
951 *a
++ = bus_space_read_stream_1(t
, h
, o
);
955 bus_space_read_multi_stream_2(bus_space_tag_t t
,
956 bus_space_handle_t h
, bus_size_t o
,
957 uint16_t *a
, size_t c
)
960 *a
++ = bus_space_read_stream_2(t
, h
, o
);
964 bus_space_read_multi_stream_4(bus_space_tag_t t
,
965 bus_space_handle_t h
, bus_size_t o
,
966 uint32_t *a
, size_t c
)
969 *a
++ = bus_space_read_stream_4(t
, h
, o
);
973 bus_space_read_multi_stream_8(bus_space_tag_t t
,
974 bus_space_handle_t h
, bus_size_t o
,
975 uint64_t *a
, size_t c
)
978 *a
++ = bus_space_read_stream_8(t
, h
, o
);
982 * void bus_space_write_stream_N(bus_space_tag_t tag,
983 * bus_space_handle_t bsh, bus_size_t offset,
986 * Write the 1, 2, 4, or 8 byte value `value' to bus space
987 * described by tag/handle/offset.
989 #ifndef BUS_SPACE_DEBUG
990 #define bus_space_write_stream_1(t, h, o, v) \
991 (0 ? (t)->type : ((void)(stba((h)._ptr + (o), (h)._sasi, (v)))))
993 #define bus_space_write_stream_2(t, h, o, v) \
994 (0 ? (t)->type : ((void)(stha((h)._ptr + (o), (h)._sasi, (v)))))
996 #define bus_space_write_stream_4(t, h, o, v) \
997 (0 ? (t)->type : ((void)(sta((h)._ptr + (o), (h)._sasi, (v)))))
999 #define bus_space_write_stream_8(t, h, o, v) \
1000 (0 ? (t)->type : ((void)(stxa((h)._ptr + (o), (h)._sasi, (v)))))
1002 #define bus_space_write_stream_1(t, h, o, v) ({ \
1003 if (bus_space_debug & BSDB_ACCESS) \
1004 printf("bsw1(%llx + %llx, %x) <- %x\n", (long long)(h)._ptr, \
1006 (h)._sasi, (uint32_t) v); \
1007 ((void)(stba((h)._ptr + (o), (h)._sasi, (v)))); })
1009 #define bus_space_write_stream_2(t, h, o, v) ({ \
1010 if (bus_space_debug & BSDB_ACCESS) \
1011 printf("bsw2(%llx + %llx, %x) <- %x\n", (long long)(h)._ptr, \
1013 (h)._sasi, (uint32_t) v); \
1014 ((void)(stha((h)._ptr + (o), (h)._sasi, (v)))); })
1016 #define bus_space_write_stream_4(t, h, o, v) ({ \
1017 if (bus_space_debug & BSDB_ACCESS) \
1018 printf("bsw4(%llx + %llx, %x) <- %x\n", (long long)(h)._ptr, \
1020 (h)._sasi, (uint32_t) v); \
1021 ((void)(sta((h)._ptr + (o), (h)._sasi, (v)))); })
1023 #define bus_space_write_stream_8(t, h, o, v) ({ \
1024 if (bus_space_debug & BSDB_ACCESS) \
1025 printf("bsw8(%llx + %llx, %x) <- %llx\n", (long long)(h)._ptr, \
1027 (h)._sasi, (long long) v); \
1028 ((void)(stxa((h)._ptr + (o), (h)._sasi, (v)))); })
1031 * void bus_space_write_multi_stream_N(bus_space_tag_t tag,
1032 * bus_space_handle_t bsh, bus_size_t offset,
1033 * const uintN_t *addr, size_t count);
1035 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
1036 * provided to bus space described by tag/handle/offset.
1039 static __inline
void
1040 bus_space_write_multi_stream_1(bus_space_tag_t t
,
1041 bus_space_handle_t h
, bus_size_t o
,
1042 const uint8_t *a
, size_t c
);
1043 static __inline
void
1044 bus_space_write_multi_stream_2(bus_space_tag_t t
,
1045 bus_space_handle_t h
, bus_size_t o
,
1046 const uint16_t *a
, size_t c
);
1047 static __inline
void
1048 bus_space_write_multi_stream_4(bus_space_tag_t t
,
1049 bus_space_handle_t h
, bus_size_t o
,
1050 const uint32_t *a
, size_t c
);
1051 static __inline
void
1052 bus_space_write_multi_stream_8(bus_space_tag_t t
,
1053 bus_space_handle_t h
, bus_size_t o
,
1054 const uint64_t *a
, size_t c
);
1056 static __inline
void
1057 bus_space_write_multi_stream_1(bus_space_tag_t t
,
1058 bus_space_handle_t h
, bus_size_t o
,
1059 const uint8_t *a
, size_t c
)
1062 bus_space_write_stream_1(t
, h
, o
, *a
++);
1065 static __inline
void
1066 bus_space_write_multi_stream_2(bus_space_tag_t t
,
1067 bus_space_handle_t h
, bus_size_t o
,
1068 const uint16_t *a
, size_t c
)
1071 bus_space_write_stream_2(t
, h
, o
, *a
++);
1074 static __inline
void
1075 bus_space_write_multi_stream_4(bus_space_tag_t t
,
1076 bus_space_handle_t h
, bus_size_t o
,
1077 const uint32_t *a
, size_t c
)
1080 bus_space_write_stream_4(t
, h
, o
, *a
++);
1083 static __inline
void
1084 bus_space_write_multi_stream_8(bus_space_tag_t t
,
1085 bus_space_handle_t h
, bus_size_t o
,
1086 const uint64_t *a
, size_t c
)
1089 bus_space_write_stream_8(t
, h
, o
, *a
++);
1093 * void bus_space_set_multi_stream_N(bus_space_tag_t tag,
1094 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
1097 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
1098 * by tag/handle/offset `count' times.
1101 static __inline
void
1102 bus_space_set_multi_stream_1(bus_space_tag_t t
,
1103 bus_space_handle_t h
, bus_size_t o
, uint8_t v
,
1105 static __inline
void
1106 bus_space_set_multi_stream_2(bus_space_tag_t t
,
1107 bus_space_handle_t h
, bus_size_t o
, uint16_t v
,
1109 static __inline
void
1110 bus_space_set_multi_stream_4(bus_space_tag_t t
,
1111 bus_space_handle_t h
, bus_size_t o
, uint32_t v
,
1113 static __inline
void
1114 bus_space_set_multi_stream_8(bus_space_tag_t t
,
1115 bus_space_handle_t h
, bus_size_t o
, uint64_t v
,
1118 static __inline
void
1119 bus_space_set_multi_stream_1(bus_space_tag_t t
,
1120 bus_space_handle_t h
, bus_size_t o
, uint8_t v
,
1124 bus_space_write_stream_1(t
, h
, o
, v
);
1127 static __inline
void
1128 bus_space_set_multi_stream_2(bus_space_tag_t t
,
1129 bus_space_handle_t h
, bus_size_t o
, uint16_t v
,
1133 bus_space_write_stream_2(t
, h
, o
, v
);
1136 static __inline
void
1137 bus_space_set_multi_stream_4(bus_space_tag_t t
,
1138 bus_space_handle_t h
, bus_size_t o
, uint32_t v
,
1142 bus_space_write_stream_4(t
, h
, o
, v
);
1145 static __inline
void
1146 bus_space_set_multi_stream_8(bus_space_tag_t t
,
1147 bus_space_handle_t h
, bus_size_t o
, uint64_t v
,
1151 bus_space_write_stream_8(t
, h
, o
, v
);
1155 * void bus_space_read_region_stream_N(bus_space_tag_t tag,
1156 * bus_space_handle_t bsh, bus_size_t off,
1157 * uintN_t *addr, bus_size_t count);
1160 static void bus_space_read_region_stream_1(bus_space_tag_t
,
1165 static void bus_space_read_region_stream_2(bus_space_tag_t
,
1170 static void bus_space_read_region_stream_4(bus_space_tag_t
,
1175 static void bus_space_read_region_stream_8(bus_space_tag_t
,
1181 static __inline
void
1182 bus_space_read_region_stream_1(bus_space_tag_t t
, bus_space_handle_t h
,
1183 bus_size_t o
, uint8_t *a
, bus_size_t c
)
1185 for (; c
; a
++, c
--, o
++)
1186 *a
= bus_space_read_stream_1(t
, h
, o
);
1188 static __inline
void
1189 bus_space_read_region_stream_2(bus_space_tag_t t
, bus_space_handle_t h
,
1190 bus_size_t o
, uint16_t *a
, bus_size_t c
)
1192 for (; c
; a
++, c
--, o
+=2)
1193 *a
= bus_space_read_stream_2(t
, h
, o
);
1195 static __inline
void
1196 bus_space_read_region_stream_4(bus_space_tag_t t
, bus_space_handle_t h
,
1197 bus_size_t o
, uint32_t *a
, bus_size_t c
)
1199 for (; c
; a
++, c
--, o
+=4)
1200 *a
= bus_space_read_stream_4(t
, h
, o
);
1202 static __inline
void
1203 bus_space_read_region_stream_8(bus_space_tag_t t
, bus_space_handle_t h
,
1204 bus_size_t o
, uint64_t *a
, bus_size_t c
)
1206 for (; c
; a
++, c
--, o
+=8)
1207 *a
= bus_space_read_stream_8(t
, h
, o
);
1211 * void bus_space_write_region_stream_N(bus_space_tag_t tag,
1212 * bus_space_handle_t bsh, bus_size_t off,
1213 * uintN_t *addr, bus_size_t count);
1216 static void bus_space_write_region_stream_1(bus_space_tag_t
,
1221 static void bus_space_write_region_stream_2(bus_space_tag_t
,
1226 static void bus_space_write_region_stream_4(bus_space_tag_t
,
1231 static void bus_space_write_region_stream_8(bus_space_tag_t
,
1237 static __inline
void
1238 bus_space_write_region_stream_1(bus_space_tag_t t
, bus_space_handle_t h
,
1239 bus_size_t o
, const uint8_t *a
, bus_size_t c
)
1241 for (; c
; a
++, c
--, o
++)
1242 bus_space_write_stream_1(t
, h
, o
, *a
);
1245 static __inline
void
1246 bus_space_write_region_stream_2(bus_space_tag_t t
, bus_space_handle_t h
,
1247 bus_size_t o
, const uint16_t *a
, bus_size_t c
)
1249 for (; c
; a
++, c
--, o
+=2)
1250 bus_space_write_stream_2(t
, h
, o
, *a
);
1253 static __inline
void
1254 bus_space_write_region_stream_4(bus_space_tag_t t
, bus_space_handle_t h
,
1255 bus_size_t o
, const uint32_t *a
, bus_size_t c
)
1257 for (; c
; a
++, c
--, o
+=4)
1258 bus_space_write_stream_4(t
, h
, o
, *a
);
1261 static __inline
void
1262 bus_space_write_region_stream_8(bus_space_tag_t t
, bus_space_handle_t h
,
1263 bus_size_t o
, const uint64_t *a
, bus_size_t c
)
1265 for (; c
; a
++, c
--, o
+=8)
1266 bus_space_write_stream_8(t
, h
, o
, *a
);
1271 * void bus_space_set_region_stream_N(bus_space_tag_t tag,
1272 * bus_space_handle_t bsh, bus_size_t off,
1273 * uintN_t *addr, bus_size_t count);
1276 static void bus_space_set_region_stream_1(bus_space_tag_t
,
1281 static void bus_space_set_region_stream_2(bus_space_tag_t
,
1286 static void bus_space_set_region_stream_4(bus_space_tag_t
,
1291 static void bus_space_set_region_stream_8(bus_space_tag_t
,
1297 static __inline
void
1298 bus_space_set_region_stream_1(bus_space_tag_t t
, bus_space_handle_t h
,
1299 bus_size_t o
, const uint8_t v
, bus_size_t c
)
1302 bus_space_write_stream_1(t
, h
, o
, v
);
1305 static __inline
void
1306 bus_space_set_region_stream_2(bus_space_tag_t t
, bus_space_handle_t h
,
1307 bus_size_t o
, const uint16_t v
, bus_size_t c
)
1309 for (; c
; c
--, o
+=2)
1310 bus_space_write_stream_2(t
, h
, o
, v
);
1313 static __inline
void
1314 bus_space_set_region_stream_4(bus_space_tag_t t
, bus_space_handle_t h
,
1315 bus_size_t o
, const uint32_t v
, bus_size_t c
)
1317 for (; c
; c
--, o
+=4)
1318 bus_space_write_stream_4(t
, h
, o
, v
);
1321 static __inline
void
1322 bus_space_set_region_stream_8(bus_space_tag_t t
, bus_space_handle_t h
,
1323 bus_size_t o
, const uint64_t v
, bus_size_t c
)
1325 for (; c
; c
--, o
+=8)
1326 bus_space_write_stream_8(t
, h
, o
, v
);
1331 * void bus_space_copy_region_stream_N(bus_space_tag_t tag,
1332 * bus_space_handle_t bsh1, bus_size_t off1,
1333 * bus_space_handle_t bsh2, bus_size_t off2,
1334 * bus_size_t count);
1336 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
1337 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
1339 static void bus_space_copy_region_stream_1(bus_space_tag_t
,
1345 static void bus_space_copy_region_stream_2(bus_space_tag_t
,
1351 static void bus_space_copy_region_stream_4(bus_space_tag_t
,
1357 static void bus_space_copy_region_stream_8(bus_space_tag_t
,
1365 static __inline
void
1366 bus_space_copy_region_stream_1(bus_space_tag_t t
, bus_space_handle_t h1
,
1367 bus_size_t o1
, bus_space_handle_t h2
, bus_size_t o2
, bus_size_t c
)
1369 for (; c
; c
--, o1
++, o2
++)
1370 bus_space_write_stream_1(t
, h1
, o1
, bus_space_read_stream_1(t
, h2
, o2
));
1373 static __inline
void
1374 bus_space_copy_region_stream_2(bus_space_tag_t t
, bus_space_handle_t h1
,
1375 bus_size_t o1
, bus_space_handle_t h2
, bus_size_t o2
, bus_size_t c
)
1377 for (; c
; c
--, o1
+=2, o2
+=2)
1378 bus_space_write_stream_2(t
, h1
, o1
, bus_space_read_stream_2(t
, h2
, o2
));
1381 static __inline
void
1382 bus_space_copy_region_stream_4(bus_space_tag_t t
, bus_space_handle_t h1
,
1383 bus_size_t o1
, bus_space_handle_t h2
, bus_size_t o2
, bus_size_t c
)
1385 for (; c
; c
--, o1
+=4, o2
+=4)
1386 bus_space_write_stream_4(t
, h1
, o1
, bus_space_read_stream_4(t
, h2
, o2
));
1389 static __inline
void
1390 bus_space_copy_region_stream_8(bus_space_tag_t t
, bus_space_handle_t h1
,
1391 bus_size_t o1
, bus_space_handle_t h2
, bus_size_t o2
, bus_size_t c
)
1393 for (; c
; c
--, o1
+=8, o2
+=8)
1394 bus_space_write_stream_8(t
, h1
, o1
, bus_space_read_8(t
, h2
, o2
));
1398 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
1401 * Flags used in various bus DMA methods.
1403 #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
1404 #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
1405 #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
1406 #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
1407 #define BUS_DMA_NOWRITE 0x008 /* I suppose the following two should default on */
1408 #define BUS_DMA_BUS1 0x010
1409 #define BUS_DMA_BUS2 0x020
1410 #define BUS_DMA_BUS3 0x040
1411 #define BUS_DMA_BUS4 0x080
1412 #define BUS_DMA_STREAMING 0x100 /* hint: sequential, unidirectional */
1413 #define BUS_DMA_READ 0x200 /* mapping is device -> memory only */
1414 #define BUS_DMA_WRITE 0x400 /* mapping is memory -> device only */
1415 #define BUS_DMA_NOCACHE 0x800 /* hint: map non-cached memory */
1417 #define BUS_DMA_DVMA BUS_DMA_BUS2 /* Don't bother with alignment */
1419 /* Forwards needed by prototypes below. */
1424 * Operations performed by bus_dmamap_sync().
1426 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
1427 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
1428 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
1429 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
1431 typedef struct sparc_bus_dma_tag
*bus_dma_tag_t
;
1432 typedef struct sparc_bus_dmamap
*bus_dmamap_t
;
1434 #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0)
1439 * Describes a single contiguous DMA transaction. Values
1440 * are suitable for programming into DMA registers.
1442 struct sparc_bus_dma_segment
{
1443 bus_addr_t ds_addr
; /* DVMA address */
1444 bus_size_t ds_len
; /* length of transfer */
1445 bus_size_t _ds_boundary
; /* don't cross this */
1446 bus_size_t _ds_align
; /* align to this */
1447 void *_ds_mlist
; /* XXX - dmamap_alloc'ed pages */
1449 typedef struct sparc_bus_dma_segment bus_dma_segment_t
;
1455 * A machine-dependent opaque type describing the implementation of
1456 * DMA for a given bus.
1458 struct sparc_bus_dma_tag
{
1459 void *_cookie
; /* cookie used in the guts */
1460 struct sparc_bus_dma_tag
* _parent
;
1463 * DMA mapping methods.
1465 int (*_dmamap_create
)(bus_dma_tag_t
, bus_size_t
, int,
1466 bus_size_t
, bus_size_t
, int, bus_dmamap_t
*);
1467 void (*_dmamap_destroy
)(bus_dma_tag_t
, bus_dmamap_t
);
1468 int (*_dmamap_load
)(bus_dma_tag_t
, bus_dmamap_t
, void *,
1469 bus_size_t
, struct proc
*, int);
1470 int (*_dmamap_load_mbuf
)(bus_dma_tag_t
, bus_dmamap_t
,
1471 struct mbuf
*, int);
1472 int (*_dmamap_load_uio
)(bus_dma_tag_t
, bus_dmamap_t
,
1474 int (*_dmamap_load_raw
)(bus_dma_tag_t
, bus_dmamap_t
,
1475 bus_dma_segment_t
*, int, bus_size_t
, int);
1476 void (*_dmamap_unload
)(bus_dma_tag_t
, bus_dmamap_t
);
1477 void (*_dmamap_sync
)(bus_dma_tag_t
, bus_dmamap_t
,
1478 bus_addr_t
, bus_size_t
, int);
1481 * DMA memory utility functions.
1483 int (*_dmamem_alloc
)(bus_dma_tag_t
, bus_size_t
, bus_size_t
,
1484 bus_size_t
, bus_dma_segment_t
*, int, int *, int);
1485 void (*_dmamem_free
)(bus_dma_tag_t
, bus_dma_segment_t
*, int);
1486 int (*_dmamem_map
)(bus_dma_tag_t
, bus_dma_segment_t
*,
1487 int, size_t, void **, int);
1488 void (*_dmamem_unmap
)(bus_dma_tag_t
, void *, size_t);
1489 paddr_t (*_dmamem_mmap
)(bus_dma_tag_t
, bus_dma_segment_t
*,
1490 int, off_t
, int, int);
1493 #define bus_dmamap_create(t, s, n, m, b, f, p) \
1494 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
1495 #define bus_dmamap_destroy(t, p) \
1496 (*(t)->_dmamap_destroy)((t), (p))
1497 #define bus_dmamap_load(t, m, b, s, p, f) \
1498 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
1499 #define bus_dmamap_load_mbuf(t, m, b, f) \
1500 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
1501 #define bus_dmamap_load_uio(t, m, u, f) \
1502 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
1503 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
1504 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
1505 #define bus_dmamap_unload(t, p) \
1506 (*(t)->_dmamap_unload)((t), (p))
1507 #define bus_dmamap_sync(t, p, o, l, ops) \
1508 (void)((t)->_dmamap_sync ? \
1509 (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) : (void)0)
1511 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
1512 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
1513 #define bus_dmamem_free(t, sg, n) \
1514 (*(t)->_dmamem_free)((t), (sg), (n))
1515 #define bus_dmamem_map(t, sg, n, s, k, f) \
1516 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
1517 #define bus_dmamem_unmap(t, k, s) \
1518 (*(t)->_dmamem_unmap)((t), (k), (s))
1519 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
1520 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
1522 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
1523 #define bus_dmatag_destroy(t)
1528 * Describes a DMA mapping.
1530 struct sparc_bus_dmamap
{
1532 * PRIVATE MEMBERS: not for use by machine-independent code.
1534 bus_addr_t _dm_dvmastart
; /* start and size of allocated */
1535 bus_size_t _dm_dvmasize
; /* DVMA segment for this map. */
1537 bus_size_t _dm_size
; /* largest DMA transfer mappable */
1538 bus_size_t _dm_maxmaxsegsz
; /* fixed largest possible segment */
1539 bus_size_t _dm_boundary
; /* don't cross this */
1540 int _dm_segcnt
; /* number of segs this map can map */
1541 int _dm_flags
; /* misc. flags */
1542 #define _DM_TYPE_LOAD 0
1543 #define _DM_TYPE_SEGS 1
1544 #define _DM_TYPE_UIO 2
1545 #define _DM_TYPE_MBUF 3
1546 int _dm_type
; /* type of mapping: raw, uio, mbuf, etc */
1547 void *_dm_source
; /* source mbuf, uio, etc. needed for unload */
1549 void *_dm_cookie
; /* cookie for bus-specific functions */
1552 * PUBLIC MEMBERS: these are used by machine-independent code.
1554 bus_size_t dm_maxsegsz
; /* largest possible segment */
1555 bus_size_t dm_mapsize
; /* size of the mapping */
1556 int dm_nsegs
; /* # valid segments in mapping */
1557 bus_dma_segment_t dm_segs
[1]; /* segments; variable length */
1560 #ifdef _SPARC_BUS_DMA_PRIVATE
1561 int _bus_dmamap_create(bus_dma_tag_t
, bus_size_t
, int, bus_size_t
,
1562 bus_size_t
, int, bus_dmamap_t
*);
1563 void _bus_dmamap_destroy(bus_dma_tag_t
, bus_dmamap_t
);
1564 int _bus_dmamap_load(bus_dma_tag_t
, bus_dmamap_t
, void *,
1565 bus_size_t
, struct proc
*, int);
1566 int _bus_dmamap_load_mbuf(bus_dma_tag_t
, bus_dmamap_t
,
1567 struct mbuf
*, int);
1568 int _bus_dmamap_load_uio(bus_dma_tag_t
, bus_dmamap_t
,
1570 int _bus_dmamap_load_raw(bus_dma_tag_t
, bus_dmamap_t
,
1571 bus_dma_segment_t
*, int, bus_size_t
, int);
1572 void _bus_dmamap_unload(bus_dma_tag_t
, bus_dmamap_t
);
1573 void _bus_dmamap_sync(bus_dma_tag_t
, bus_dmamap_t
, bus_addr_t
,
1576 int _bus_dmamem_alloc(bus_dma_tag_t tag
, bus_size_t size
,
1577 bus_size_t alignment
, bus_size_t boundary
,
1578 bus_dma_segment_t
*segs
, int nsegs
, int *rsegs
, int flags
);
1579 void _bus_dmamem_free(bus_dma_tag_t tag
, bus_dma_segment_t
*segs
,
1581 int _bus_dmamem_map(bus_dma_tag_t tag
, bus_dma_segment_t
*segs
,
1582 int nsegs
, size_t size
, void **kvap
, int flags
);
1583 void _bus_dmamem_unmap(bus_dma_tag_t tag
, void *kva
,
1585 paddr_t
_bus_dmamem_mmap(bus_dma_tag_t tag
, bus_dma_segment_t
*segs
,
1586 int nsegs
, off_t off
, int prot
, int flags
);
1588 int _bus_dmamem_alloc_range(bus_dma_tag_t tag
, bus_size_t size
,
1589 bus_size_t alignment
, bus_size_t boundary
,
1590 bus_dma_segment_t
*segs
, int nsegs
, int *rsegs
, int flags
,
1591 vaddr_t low
, vaddr_t high
);
1592 #endif /* _SPARC_BUS_DMA_PRIVATE */
1594 #endif /* _SPARC_BUS_H_ */