No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / sparc64 / include / bus.h
blobb268ae71104cff9d30b12e9161948540200795e5
1 /* $NetBSD: bus.h,v 1.60 2009/12/04 12:22:16 nakayama Exp $ */
3 /*-
4 * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
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
13 * are met:
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
40 * are met:
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.
65 #ifndef _SPARC_BUS_H_
66 #define _SPARC_BUS_H_
68 #include <machine/types.h>
69 #include <machine/ctlreg.h>
72 * Debug hooks
75 #define BSDB_ACCESS 0x01
76 #define BSDB_MAP 0x02
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
86 enum bus_type {
87 UPA_BUS_SPACE,
88 SBUS_BUS_SPACE,
89 PCI_CONFIG_BUS_SPACE,
90 PCI_IO_BUS_SPACE,
91 PCI_MEMORY_BUS_SPACE,
92 LAST_BUS_SPACE
93 };
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 {
103 uint64_t _ptr;
104 uint8_t _asi;
105 uint8_t _sasi;
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) \
115 do { \
116 (hp)->_ptr = (uint64_t)(promaddr); \
117 (hp)->_asi = ASI_PRIMARY; \
118 (hp)->_sasi = ASI_PRIMARY; \
119 } while (0)
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 {
132 void *cookie;
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;
140 int nranges;
142 int type;
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,
149 bus_size_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,
155 bus_size_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,
162 int, int);
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 *,
171 int, bus_addr_t *);
173 #if 0
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) \
184 t = t->parent; \
185 return (*(t)->sparc_##name)(t, args); \
188 #endif
191 * Bus space function prototypes.
193 static int bus_space_alloc(
194 bus_space_tag_t,
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 */
200 int, /* flags */
201 bus_addr_t *,
202 bus_space_handle_t *);
203 static void bus_space_free(
204 bus_space_tag_t,
205 bus_space_handle_t,
206 bus_size_t);
207 static int bus_space_map(
208 bus_space_tag_t,
209 bus_addr_t,
210 bus_size_t,
211 int, /*flags*/
212 bus_space_handle_t *);
213 static int bus_space_unmap(
214 bus_space_tag_t,
215 bus_space_handle_t,
216 bus_size_t);
217 static int bus_space_subregion(
218 bus_space_tag_t,
219 bus_space_handle_t,
220 bus_size_t,
221 bus_size_t,
222 bus_space_handle_t *);
223 static void bus_space_barrier(
224 bus_space_tag_t,
225 bus_space_handle_t,
226 bus_size_t,
227 bus_size_t,
228 int);
229 static paddr_t bus_space_mmap(
230 bus_space_tag_t,
231 bus_addr_t, /*addr*/
232 off_t, /*offset*/
233 int, /*prot*/
234 int); /*flags*/
235 static void *bus_intr_establish(
236 bus_space_tag_t,
237 int, /*bus-specific intr*/
238 int, /*device class level,
239 see machine/intr.h*/
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) \
247 t = t->parent; \
248 return (*(t)->f)
250 static __inline int
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);
258 static __inline void
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);
264 static __inline int
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);
271 static __inline int
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);
277 static __inline int
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 */
316 static __inline void
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");
332 else
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))
356 #else
357 #define bus_space_read_1(t, h, o) ({ \
358 uint8_t __bv = \
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, \
362 (long long)(o), \
363 (h)._asi, (uint32_t) __bv); \
364 __bv; })
366 #define bus_space_read_2(t, h, o) ({ \
367 uint16_t __bv = \
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, \
371 (long long)(o), \
372 (h)._asi, (uint32_t)__bv); \
373 __bv; })
375 #define bus_space_read_4(t, h, o) ({ \
376 uint32_t __bv = \
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, \
380 (long long)(o), \
381 (h)._asi, __bv); \
382 __bv; })
384 #define bus_space_read_8(t, h, o) ({ \
385 uint64_t __bv = \
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, \
389 (long long)(o), \
390 (h)._asi, (long long)__bv); \
391 __bv; })
392 #endif
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.
402 static __inline void
403 bus_space_read_multi_1(bus_space_tag_t, bus_space_handle_t,
404 bus_size_t, uint8_t *, size_t);
405 static __inline void
406 bus_space_read_multi_2(bus_space_tag_t, bus_space_handle_t,
407 bus_size_t, uint16_t *, size_t);
408 static __inline void
409 bus_space_read_multi_4(bus_space_tag_t, bus_space_handle_t,
410 bus_size_t, uint32_t *, size_t);
411 static __inline void
412 bus_space_read_multi_8(bus_space_tag_t, bus_space_handle_t,
413 bus_size_t, uint64_t *, size_t);
415 static __inline void
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)
419 while (c-- > 0)
420 *a++ = bus_space_read_1(t, h, o);
423 static __inline void
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)
427 while (c-- > 0)
428 *a++ = bus_space_read_2(t, h, o);
431 static __inline void
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)
435 while (c-- > 0)
436 *a++ = bus_space_read_4(t, h, o);
439 static __inline void
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)
443 while (c-- > 0)
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,
450 * uintN_t value);
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)))))
467 #else
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, \
471 (long long)(o), \
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, \
478 (long long)(o), \
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, \
485 (long long)(o), \
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, \
492 (long long)(o), \
493 (h)._asi, (long long) v); \
494 ((void)(stxa((h)._ptr + (o), (h)._asi, (v)))); })
495 #endif
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.
505 static __inline void
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);
509 static __inline void
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);
513 static __inline void
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);
517 static __inline void
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);
522 static __inline void
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)
527 while (c-- > 0)
528 bus_space_write_1(t, h, o, *a++);
531 static __inline void
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)
536 while (c-- > 0)
537 bus_space_write_2(t, h, o, *a++);
540 static __inline void
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)
545 while (c-- > 0)
546 bus_space_write_4(t, h, o, *a++);
549 static __inline void
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)
554 while (c-- > 0)
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,
561 * size_t count);
563 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
564 * by tag/handle/offset `count' times.
567 static __inline void
568 bus_space_set_multi_1(bus_space_tag_t t,
569 bus_space_handle_t h, bus_size_t o, uint8_t v,
570 size_t c);
571 static __inline void
572 bus_space_set_multi_2(bus_space_tag_t t,
573 bus_space_handle_t h, bus_size_t o, uint16_t v,
574 size_t c);
575 static __inline void
576 bus_space_set_multi_4(bus_space_tag_t t,
577 bus_space_handle_t h, bus_size_t o, uint32_t v,
578 size_t c);
579 static __inline void
580 bus_space_set_multi_8(bus_space_tag_t t,
581 bus_space_handle_t h, bus_size_t o, uint64_t v,
582 size_t c);
584 static __inline void
585 bus_space_set_multi_1(bus_space_tag_t t,
586 bus_space_handle_t h, bus_size_t o, uint8_t v,
587 size_t c)
589 while (c-- > 0)
590 bus_space_write_1(t, h, o, v);
593 static __inline void
594 bus_space_set_multi_2(bus_space_tag_t t,
595 bus_space_handle_t h, bus_size_t o, uint16_t v,
596 size_t c)
598 while (c-- > 0)
599 bus_space_write_2(t, h, o, v);
602 static __inline void
603 bus_space_set_multi_4(bus_space_tag_t t,
604 bus_space_handle_t h, bus_size_t o, uint32_t v,
605 size_t c)
607 while (c-- > 0)
608 bus_space_write_4(t, h, o, v);
611 static __inline void
612 bus_space_set_multi_8(bus_space_tag_t t,
613 bus_space_handle_t h, bus_size_t o, uint64_t v,
614 size_t c)
616 while (c-- > 0)
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,
627 bus_space_handle_t,
628 bus_size_t,
629 uint8_t *,
630 bus_size_t);
631 static void bus_space_read_region_2(bus_space_tag_t,
632 bus_space_handle_t,
633 bus_size_t,
634 uint16_t *,
635 bus_size_t);
636 static void bus_space_read_region_4(bus_space_tag_t,
637 bus_space_handle_t,
638 bus_size_t,
639 uint32_t *,
640 bus_size_t);
641 static void bus_space_read_region_8(bus_space_tag_t,
642 bus_space_handle_t,
643 bus_size_t,
644 uint64_t *,
645 bus_size_t);
647 static __inline void
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);
654 static __inline void
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);
661 static __inline void
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);
668 static __inline void
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,
683 bus_space_handle_t,
684 bus_size_t,
685 const uint8_t *,
686 bus_size_t);
687 static void bus_space_write_region_2(bus_space_tag_t,
688 bus_space_handle_t,
689 bus_size_t,
690 const uint16_t *,
691 bus_size_t);
692 static void bus_space_write_region_4(bus_space_tag_t,
693 bus_space_handle_t,
694 bus_size_t,
695 const uint32_t *,
696 bus_size_t);
697 static void bus_space_write_region_8(bus_space_tag_t,
698 bus_space_handle_t,
699 bus_size_t,
700 const uint64_t *,
701 bus_size_t);
703 static __inline void
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);
711 static __inline void
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);
719 static __inline void
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);
727 static __inline void
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,
743 bus_space_handle_t,
744 bus_size_t,
745 const uint8_t,
746 bus_size_t);
747 static void bus_space_set_region_2(bus_space_tag_t,
748 bus_space_handle_t,
749 bus_size_t,
750 const uint16_t,
751 bus_size_t);
752 static void bus_space_set_region_4(bus_space_tag_t,
753 bus_space_handle_t,
754 bus_size_t,
755 const uint32_t,
756 bus_size_t);
757 static void bus_space_set_region_8(bus_space_tag_t,
758 bus_space_handle_t,
759 bus_size_t,
760 const uint64_t,
761 bus_size_t);
763 static __inline void
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)
767 for (; c; c--, o++)
768 bus_space_write_1(t, h, o, v);
771 static __inline void
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)
775 for (; c; c--, o+=2)
776 bus_space_write_2(t, h, o, v);
779 static __inline void
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)
783 for (; c; c--, o+=4)
784 bus_space_write_4(t, h, o, v);
787 static __inline void
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)
791 for (; c; c--, o+=8)
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,
800 * bus_size_t count);
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,
806 bus_space_handle_t,
807 bus_size_t,
808 bus_space_handle_t,
809 bus_size_t,
810 bus_size_t);
811 static void bus_space_copy_region_2(bus_space_tag_t,
812 bus_space_handle_t,
813 bus_size_t,
814 bus_space_handle_t,
815 bus_size_t,
816 bus_size_t);
817 static void bus_space_copy_region_4(bus_space_tag_t,
818 bus_space_handle_t,
819 bus_size_t,
820 bus_space_handle_t,
821 bus_size_t,
822 bus_size_t);
823 static void bus_space_copy_region_8(bus_space_tag_t,
824 bus_space_handle_t,
825 bus_size_t,
826 bus_space_handle_t,
827 bus_size_t,
828 bus_size_t);
831 static __inline void
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));
839 static __inline void
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));
847 static __inline void
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));
855 static __inline void
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))
882 #else
883 #define bus_space_read_stream_1(t, h, o) ({ \
884 uint8_t __bv = \
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, \
888 (long long)(o), \
889 (h)._sasi, (uint32_t) __bv); \
890 __bv; })
892 #define bus_space_read_stream_2(t, h, o) ({ \
893 uint16_t __bv = \
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, \
897 (long long)(o), \
898 (h)._sasi, (uint32_t)__bv); \
899 __bv; })
901 #define bus_space_read_stream_4(t, h, o) ({ \
902 uint32_t __bv = \
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, \
906 (long long)(o), \
907 (h)._sasi, __bv); \
908 __bv; })
910 #define bus_space_read_stream_8(t, h, o) ({ \
911 uint64_t __bv = \
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, \
915 (long long)(o), \
916 (h)._sasi, (long long)__bv); \
917 __bv; })
918 #endif
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.
928 static __inline void
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);
932 static __inline void
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);
936 static __inline void
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);
940 static __inline void
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);
945 static __inline void
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)
950 while (c-- > 0)
951 *a++ = bus_space_read_stream_1(t, h, o);
954 static __inline void
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)
959 while (c-- > 0)
960 *a++ = bus_space_read_stream_2(t, h, o);
963 static __inline void
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)
968 while (c-- > 0)
969 *a++ = bus_space_read_stream_4(t, h, o);
972 static __inline void
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)
977 while (c-- > 0)
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,
984 * uintN_t value);
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)))))
1001 #else
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, \
1005 (long long)(o), \
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, \
1012 (long long)(o), \
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, \
1019 (long long)(o), \
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, \
1026 (long long)(o), \
1027 (h)._sasi, (long long) v); \
1028 ((void)(stxa((h)._ptr + (o), (h)._sasi, (v)))); })
1029 #endif
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)
1061 while (c-- > 0)
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)
1070 while (c-- > 0)
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)
1079 while (c-- > 0)
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)
1088 while (c-- > 0)
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,
1095 * size_t count);
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,
1104 size_t c);
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,
1108 size_t c);
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,
1112 size_t c);
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,
1116 size_t c);
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,
1121 size_t c)
1123 while (c-- > 0)
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,
1130 size_t c)
1132 while (c-- > 0)
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,
1139 size_t c)
1141 while (c-- > 0)
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,
1148 size_t c)
1150 while (c-- > 0)
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,
1161 bus_space_handle_t,
1162 bus_size_t,
1163 uint8_t *,
1164 bus_size_t);
1165 static void bus_space_read_region_stream_2(bus_space_tag_t,
1166 bus_space_handle_t,
1167 bus_size_t,
1168 uint16_t *,
1169 bus_size_t);
1170 static void bus_space_read_region_stream_4(bus_space_tag_t,
1171 bus_space_handle_t,
1172 bus_size_t,
1173 uint32_t *,
1174 bus_size_t);
1175 static void bus_space_read_region_stream_8(bus_space_tag_t,
1176 bus_space_handle_t,
1177 bus_size_t,
1178 uint64_t *,
1179 bus_size_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,
1217 bus_space_handle_t,
1218 bus_size_t,
1219 const uint8_t *,
1220 bus_size_t);
1221 static void bus_space_write_region_stream_2(bus_space_tag_t,
1222 bus_space_handle_t,
1223 bus_size_t,
1224 const uint16_t *,
1225 bus_size_t);
1226 static void bus_space_write_region_stream_4(bus_space_tag_t,
1227 bus_space_handle_t,
1228 bus_size_t,
1229 const uint32_t *,
1230 bus_size_t);
1231 static void bus_space_write_region_stream_8(bus_space_tag_t,
1232 bus_space_handle_t,
1233 bus_size_t,
1234 const uint64_t *,
1235 bus_size_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,
1277 bus_space_handle_t,
1278 bus_size_t,
1279 const uint8_t,
1280 bus_size_t);
1281 static void bus_space_set_region_stream_2(bus_space_tag_t,
1282 bus_space_handle_t,
1283 bus_size_t,
1284 const uint16_t,
1285 bus_size_t);
1286 static void bus_space_set_region_stream_4(bus_space_tag_t,
1287 bus_space_handle_t,
1288 bus_size_t,
1289 const uint32_t,
1290 bus_size_t);
1291 static void bus_space_set_region_stream_8(bus_space_tag_t,
1292 bus_space_handle_t,
1293 bus_size_t,
1294 const uint64_t,
1295 bus_size_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)
1301 for (; c; c--, o++)
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,
1340 bus_space_handle_t,
1341 bus_size_t,
1342 bus_space_handle_t,
1343 bus_size_t,
1344 bus_size_t);
1345 static void bus_space_copy_region_stream_2(bus_space_tag_t,
1346 bus_space_handle_t,
1347 bus_size_t,
1348 bus_space_handle_t,
1349 bus_size_t,
1350 bus_size_t);
1351 static void bus_space_copy_region_stream_4(bus_space_tag_t,
1352 bus_space_handle_t,
1353 bus_size_t,
1354 bus_space_handle_t,
1355 bus_size_t,
1356 bus_size_t);
1357 static void bus_space_copy_region_stream_8(bus_space_tag_t,
1358 bus_space_handle_t,
1359 bus_size_t,
1360 bus_space_handle_t,
1361 bus_size_t,
1362 bus_size_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. */
1420 struct mbuf;
1421 struct uio;
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)
1437 * bus_dma_segment_t
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;
1453 * bus_dma_tag_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,
1473 struct uio *, int);
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)
1526 * bus_dmamap_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,
1569 struct uio *, int);
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,
1574 bus_size_t, int);
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,
1580 int nsegs);
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,
1584 size_t size);
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_ */