]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - sys/sparc64/include/bus.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / sys / sparc64 / include / bus.h
1 /*-
2  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to The NetBSD Foundation
6  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
7  * NASA Ames Research Center.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 /*
31  * Copyright (c) 1997-1999 Eduardo E. Horvath. All rights reserved.
32  * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
33  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
34  *
35  * Redistribution and use in source and binary forms, with or without
36  * modification, are permitted provided that the following conditions
37  * are met:
38  * 1. Redistributions of source code must retain the above copyright
39  *    notice, this list of conditions and the following disclaimer.
40  * 2. Redistributions in binary form must reproduce the above copyright
41  *    notice, this list of conditions and the following disclaimer in the
42  *    documentation and/or other materials provided with the distribution.
43  * 3. All advertising materials mentioning features or use of this software
44  *    must display the following acknowledgement:
45  *      This product includes software developed by Christopher G. Demetriou
46  *      for the NetBSD Project.
47  * 4. The name of the author may not be used to endorse or promote products
48  *    derived from this software without specific prior written permission
49  *
50  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
51  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
54  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
55  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
59  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60  *
61  *      from: NetBSD: bus.h,v 1.58 2008/04/28 20:23:36 martin Exp
62  *      and
63  *      from: FreeBSD: src/sys/alpha/include/bus.h,v 1.9 2001/01/09
64  *
65  * $FreeBSD$
66  */
67
68 #ifndef _MACHINE_BUS_H_
69 #define _MACHINE_BUS_H_
70
71 #ifdef BUS_SPACE_DEBUG
72 #include <sys/ktr.h>
73 #endif
74
75 #include <machine/_bus.h>
76 #include <machine/cpufunc.h>
77
78 /*
79  * Nexus and SBus spaces are non-cached and big endian
80  * (except for RAM and PROM)
81  *
82  * PCI spaces are non-cached and little endian
83  */
84 #define NEXUS_BUS_SPACE         0
85 #define SBUS_BUS_SPACE          1
86 #define PCI_CONFIG_BUS_SPACE    2
87 #define PCI_IO_BUS_SPACE        3
88 #define PCI_MEMORY_BUS_SPACE    4
89 #define LAST_BUS_SPACE          5
90
91 extern const int bus_type_asi[];
92 extern const int bus_stream_asi[];
93
94 #define __BUS_SPACE_HAS_STREAM_METHODS  1
95
96 #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF
97 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
98 #define BUS_SPACE_MAXSIZE       0xFFFFFFFFFFFFFFFF
99 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF
100 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
101 #define BUS_SPACE_MAXADDR       0xFFFFFFFF
102
103 #define BUS_SPACE_UNRESTRICTED  (~0)
104
105 struct bus_space_tag {
106         void            *bst_cookie;
107         bus_space_tag_t bst_parent;
108         int             bst_type;
109
110         void            (*bst_bus_barrier)(bus_space_tag_t, bus_space_handle_t,
111                             bus_size_t, bus_size_t, int);
112 };
113
114 /*
115  * Bus space function prototypes.
116  */
117 static void bus_space_barrier(bus_space_tag_t, bus_space_handle_t, bus_size_t,
118     bus_size_t, int);
119 static int bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
120     bus_size_t, bus_size_t, bus_space_handle_t *);
121
122 /*
123  * Map a region of device bus space into CPU virtual address space.
124  */
125
126 static __inline int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
127     bus_size_t size, int flags, bus_space_handle_t *bshp);
128
129 static __inline int
130 bus_space_map(bus_space_tag_t t __unused, bus_addr_t addr,
131     bus_size_t size __unused, int flags __unused, bus_space_handle_t *bshp)
132 {
133
134         *bshp = addr;
135         return (0);
136 }
137
138 /*
139  * Unmap a region of device bus space.
140  */
141 static __inline void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
142     bus_size_t size);
143
144 static __inline void
145 bus_space_unmap(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused,
146     bus_size_t size __unused)
147 {
148
149 }
150
151 /* This macro finds the first "upstream" implementation of method `f' */
152 #define _BS_CALL(t,f)                                                   \
153         while (t->f == NULL)                                            \
154                 t = t->bst_parent;                                      \
155         return (*(t)->f)
156
157 static __inline void
158 bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
159     bus_size_t s, int f)
160 {
161
162         _BS_CALL(t, bst_bus_barrier)(t, h, o, s, f);
163 }
164
165 static __inline int
166 bus_space_subregion(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
167     bus_size_t s, bus_space_handle_t *hp)
168 {
169
170         *hp = h + o;
171         return (0);
172 }
173
174 /* flags for bus space map functions */
175 #define BUS_SPACE_MAP_CACHEABLE         0x0001
176 #define BUS_SPACE_MAP_LINEAR            0x0002
177 #define BUS_SPACE_MAP_READONLY          0x0004
178 #define BUS_SPACE_MAP_PREFETCHABLE      0x0008
179 /* placeholders for bus functions... */
180 #define BUS_SPACE_MAP_BUS1              0x0100
181 #define BUS_SPACE_MAP_BUS2              0x0200
182 #define BUS_SPACE_MAP_BUS3              0x0400
183 #define BUS_SPACE_MAP_BUS4              0x0800
184
185 /* flags for bus_space_barrier() */
186 #define BUS_SPACE_BARRIER_READ          0x01    /* force read barrier */
187 #define BUS_SPACE_BARRIER_WRITE         0x02    /* force write barrier */
188
189 #ifdef BUS_SPACE_DEBUG
190 #define KTR_BUS                         KTR_SPARE2
191 #define __BUS_DEBUG_ACCESS(h, o, desc, sz) do {                         \
192         CTR4(KTR_BUS, "bus space: %s %d: handle %#lx, offset %#lx",     \
193             (desc), (sz), (h), (o));                                    \
194 } while (0)
195 #else
196 #define __BUS_DEBUG_ACCESS(h, o, desc, sz)
197 #endif
198
199 static __inline uint8_t
200 bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
201 {
202
203         __BUS_DEBUG_ACCESS(h, o, "read", 1);
204         return (lduba_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
205 }
206
207 static __inline uint16_t
208 bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
209 {
210
211         __BUS_DEBUG_ACCESS(h, o, "read", 2);
212         return (lduha_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
213 }
214
215 static __inline uint32_t
216 bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
217 {
218
219         __BUS_DEBUG_ACCESS(h, o, "read", 4);
220         return (lduwa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
221 }
222
223 static __inline uint64_t
224 bus_space_read_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
225 {
226
227         __BUS_DEBUG_ACCESS(h, o, "read", 8);
228         return (ldxa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
229 }
230
231 static __inline void
232 bus_space_read_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
233     uint8_t *a, size_t c)
234 {
235
236         while (c-- > 0)
237                 *a++ = bus_space_read_1(t, h, o);
238 }
239
240 static __inline void
241 bus_space_read_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
242     uint16_t *a, size_t c)
243 {
244
245         while (c-- > 0)
246                 *a++ = bus_space_read_2(t, h, o);
247 }
248
249 static __inline void
250 bus_space_read_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
251     uint32_t *a, size_t c)
252 {
253
254         while (c-- > 0)
255                 *a++ = bus_space_read_4(t, h, o);
256 }
257
258 static __inline void
259 bus_space_read_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
260     uint64_t *a, size_t c)
261 {
262
263         while (c-- > 0)
264                 *a++ = bus_space_read_8(t, h, o);
265 }
266
267 static __inline void
268 bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
269     uint8_t v)
270 {
271
272         __BUS_DEBUG_ACCESS(h, o, "write", 1);
273         stba_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
274 }
275
276 static __inline void
277 bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
278     uint16_t v)
279 {
280
281         __BUS_DEBUG_ACCESS(h, o, "write", 2);
282         stha_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
283 }
284
285 static __inline void
286 bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
287     uint32_t v)
288 {
289
290         __BUS_DEBUG_ACCESS(h, o, "write", 4);
291         stwa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
292 }
293
294 static __inline void
295 bus_space_write_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
296     uint64_t v)
297 {
298
299         __BUS_DEBUG_ACCESS(h, o, "write", 8);
300         stxa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
301 }
302
303 static __inline void
304 bus_space_write_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
305     const uint8_t *a, size_t c)
306 {
307
308         while (c-- > 0)
309                 bus_space_write_1(t, h, o, *a++);
310 }
311
312 static __inline void
313 bus_space_write_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
314     const uint16_t *a, size_t c)
315 {
316
317         while (c-- > 0)
318                 bus_space_write_2(t, h, o, *a++);
319 }
320
321 static __inline void
322 bus_space_write_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
323     const uint32_t *a, size_t c)
324 {
325
326         while (c-- > 0)
327                 bus_space_write_4(t, h, o, *a++);
328 }
329
330 static __inline void
331 bus_space_write_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
332     const uint64_t *a, size_t c)
333 {
334
335         while (c-- > 0)
336                 bus_space_write_8(t, h, o, *a++);
337 }
338
339 static __inline void
340 bus_space_set_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
341     uint8_t v, size_t c)
342 {
343
344         while (c-- > 0)
345                 bus_space_write_1(t, h, o, v);
346 }
347
348 static __inline void
349 bus_space_set_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
350     uint16_t v, size_t c)
351 {
352
353         while (c-- > 0)
354                 bus_space_write_2(t, h, o, v);
355 }
356
357 static __inline void
358 bus_space_set_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
359     uint32_t v, size_t c)
360 {
361
362         while (c-- > 0)
363                 bus_space_write_4(t, h, o, v);
364 }
365
366 static __inline void
367 bus_space_set_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
368     uint64_t v, size_t c)
369 {
370
371         while (c-- > 0)
372                 bus_space_write_8(t, h, o, v);
373 }
374
375 static __inline void
376 bus_space_read_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
377     uint8_t *a, bus_size_t c)
378 {
379
380         for (; c; a++, c--, o++)
381                 *a = bus_space_read_1(t, h, o);
382 }
383
384 static __inline void
385 bus_space_read_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
386     uint16_t *a, bus_size_t c)
387 {
388
389         for (; c; a++, c--, o += 2)
390                 *a = bus_space_read_2(t, h, o);
391 }
392
393 static __inline void
394 bus_space_read_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
395     uint32_t *a, bus_size_t c)
396 {
397
398         for (; c; a++, c--, o += 4)
399                 *a = bus_space_read_4(t, h, o);
400 }
401
402 static __inline void
403 bus_space_read_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
404     uint64_t *a, bus_size_t c)
405 {
406
407         for (; c; a++, c--, o += 8)
408                 *a = bus_space_read_8(t, h, o);
409 }
410
411 static __inline void
412 bus_space_write_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
413     const uint8_t *a, bus_size_t c)
414 {
415
416         for (; c; a++, c--, o++)
417                 bus_space_write_1(t, h, o, *a);
418 }
419
420 static __inline void
421 bus_space_write_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
422     const uint16_t *a, bus_size_t c)
423 {
424
425         for (; c; a++, c--, o += 2)
426                 bus_space_write_2(t, h, o, *a);
427 }
428
429 static __inline void
430 bus_space_write_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
431     const uint32_t *a, bus_size_t c)
432 {
433
434         for (; c; a++, c--, o += 4)
435                 bus_space_write_4(t, h, o, *a);
436 }
437
438 static __inline void
439 bus_space_write_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
440     const uint64_t *a, bus_size_t c)
441 {
442
443         for (; c; a++, c--, o += 8)
444                 bus_space_write_8(t, h, o, *a);
445 }
446
447 static __inline void
448 bus_space_set_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
449     const uint8_t v, bus_size_t c)
450 {
451
452         for (; c; c--, o++)
453                 bus_space_write_1(t, h, o, v);
454 }
455
456 static __inline void
457 bus_space_set_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
458     const uint16_t v, bus_size_t c)
459 {
460
461         for (; c; c--, o += 2)
462                 bus_space_write_2(t, h, o, v);
463 }
464
465 static __inline void
466 bus_space_set_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
467     const uint32_t v, bus_size_t c)
468 {
469
470         for (; c; c--, o += 4)
471                 bus_space_write_4(t, h, o, v);
472 }
473
474 static __inline void
475 bus_space_set_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
476     const uint64_t v, bus_size_t c)
477 {
478
479         for (; c; c--, o += 8)
480                 bus_space_write_8(t, h, o, v);
481 }
482
483 static __inline void
484 bus_space_copy_region_1(bus_space_tag_t t, bus_space_handle_t h1,
485     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
486 {
487
488         for (; c; c--, o1++, o2++)
489             bus_space_write_1(t, h1, o1, bus_space_read_1(t, h2, o2));
490 }
491
492 static __inline void
493 bus_space_copy_region_2(bus_space_tag_t t, bus_space_handle_t h1,
494     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
495 {
496
497         for (; c; c--, o1 += 2, o2 += 2)
498             bus_space_write_2(t, h1, o1, bus_space_read_2(t, h2, o2));
499 }
500
501 static __inline void
502 bus_space_copy_region_4(bus_space_tag_t t, bus_space_handle_t h1,
503     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
504 {
505
506         for (; c; c--, o1 += 4, o2 += 4)
507             bus_space_write_4(t, h1, o1, bus_space_read_4(t, h2, o2));
508 }
509
510 static __inline void
511 bus_space_copy_region_8(bus_space_tag_t t, bus_space_handle_t h1,
512     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
513 {
514
515         for (; c; c--, o1 += 8, o2 += 8)
516             bus_space_write_8(t, h1, o1, bus_space_read_8(t, h2, o2));
517 }
518
519 static __inline uint8_t
520 bus_space_read_stream_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
521 {
522
523         __BUS_DEBUG_ACCESS(h, o, "read stream", 1);
524         return (lduba_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
525 }
526
527 static __inline uint16_t
528 bus_space_read_stream_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
529 {
530
531         __BUS_DEBUG_ACCESS(h, o, "read stream", 2);
532         return (lduha_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
533 }
534
535 static __inline uint32_t
536 bus_space_read_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
537 {
538
539         __BUS_DEBUG_ACCESS(h, o, "read stream", 4);
540         return (lduwa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
541 }
542
543 static __inline uint64_t
544 bus_space_read_stream_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
545 {
546
547         __BUS_DEBUG_ACCESS(h, o, "read stream", 8);
548         return (ldxa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
549 }
550
551 static __inline void
552 bus_space_read_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h,
553     bus_size_t o, uint8_t *a, size_t c)
554 {
555
556         while (c-- > 0)
557                 *a++ = bus_space_read_stream_1(t, h, o);
558 }
559
560 static __inline void
561 bus_space_read_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h,
562     bus_size_t o, uint16_t *a, size_t c)
563 {
564
565         while (c-- > 0)
566                 *a++ = bus_space_read_stream_2(t, h, o);
567 }
568
569 static __inline void
570 bus_space_read_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h,
571     bus_size_t o, uint32_t *a, size_t c)
572 {
573
574         while (c-- > 0)
575                 *a++ = bus_space_read_stream_4(t, h, o);
576 }
577
578 static __inline void
579 bus_space_read_multi_stream_8(bus_space_tag_t t, bus_space_handle_t h,
580     bus_size_t o, uint64_t *a, size_t c)
581 {
582
583         while (c-- > 0)
584                 *a++ = bus_space_read_stream_8(t, h, o);
585 }
586
587 static __inline void
588 bus_space_write_stream_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
589     uint8_t v)
590 {
591
592         __BUS_DEBUG_ACCESS(h, o, "write stream", 1);
593         stba_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
594 }
595
596 static __inline void
597 bus_space_write_stream_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
598     uint16_t v)
599 {
600
601         __BUS_DEBUG_ACCESS(h, o, "write stream", 2);
602         stha_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
603 }
604
605 static __inline void
606 bus_space_write_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
607     uint32_t v)
608 {
609
610         __BUS_DEBUG_ACCESS(h, o, "write stream", 4);
611         stwa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
612 }
613
614 static __inline void
615 bus_space_write_stream_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
616     uint64_t v)
617 {
618
619         __BUS_DEBUG_ACCESS(h, o, "write stream", 8);
620         stxa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
621 }
622
623 static __inline void
624 bus_space_write_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h,
625     bus_size_t o, const uint8_t *a, size_t c)
626 {
627
628         while (c-- > 0)
629                 bus_space_write_stream_1(t, h, o, *a++);
630 }
631
632 static __inline void
633 bus_space_write_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h,
634     bus_size_t o, const uint16_t *a, size_t c)
635 {
636
637         while (c-- > 0)
638                 bus_space_write_stream_2(t, h, o, *a++);
639 }
640
641 static __inline void
642 bus_space_write_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h,
643     bus_size_t o, const uint32_t *a, size_t c)
644 {
645
646         while (c-- > 0)
647                 bus_space_write_stream_4(t, h, o, *a++);
648 }
649
650 static __inline void
651 bus_space_write_multi_stream_8(bus_space_tag_t t, bus_space_handle_t h,
652     bus_size_t o, const uint64_t *a, size_t c)
653 {
654
655         while (c-- > 0)
656                 bus_space_write_stream_8(t, h, o, *a++);
657 }
658
659 static __inline void
660 bus_space_set_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h,
661     bus_size_t o, uint8_t v, size_t c)
662 {
663
664         while (c-- > 0)
665                 bus_space_write_stream_1(t, h, o, v);
666 }
667
668 static __inline void
669 bus_space_set_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h,
670     bus_size_t o, uint16_t v, size_t c)
671 {
672
673         while (c-- > 0)
674                 bus_space_write_stream_2(t, h, o, v);
675 }
676
677 static __inline void
678 bus_space_set_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h,
679     bus_size_t o, uint32_t v, size_t c)
680 {
681
682         while (c-- > 0)
683                 bus_space_write_stream_4(t, h, o, v);
684 }
685
686 static __inline void
687 bus_space_set_multi_stream_8(bus_space_tag_t t, bus_space_handle_t h,
688     bus_size_t o, uint64_t v, size_t c)
689 {
690
691         while (c-- > 0)
692                 bus_space_write_stream_8(t, h, o, v);
693 }
694
695 static __inline void
696 bus_space_read_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
697     bus_size_t o, uint8_t *a, bus_size_t c)
698 {
699
700         for (; c; a++, c--, o++)
701                 *a = bus_space_read_stream_1(t, h, o);
702 }
703
704 static __inline void
705 bus_space_read_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
706     bus_size_t o, uint16_t *a, bus_size_t c)
707 {
708
709         for (; c; a++, c--, o += 2)
710                 *a = bus_space_read_stream_2(t, h, o);
711 }
712
713 static __inline void
714 bus_space_read_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
715     bus_size_t o, uint32_t *a, bus_size_t c)
716 {
717
718         for (; c; a++, c--, o += 4)
719                 *a = bus_space_read_stream_4(t, h, o);
720 }
721
722 static __inline void
723 bus_space_read_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
724     bus_size_t o, uint64_t *a, bus_size_t c)
725 {
726
727         for (; c; a++, c--, o += 8)
728                 *a = bus_space_read_stream_8(t, h, o);
729 }
730
731 static __inline void
732 bus_space_write_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
733     bus_size_t o, const uint8_t *a, bus_size_t c)
734 {
735
736         for (; c; a++, c--, o++)
737                 bus_space_write_stream_1(t, h, o, *a);
738 }
739
740 static __inline void
741 bus_space_write_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
742     bus_size_t o, const uint16_t *a, bus_size_t c)
743 {
744
745         for (; c; a++, c--, o += 2)
746                 bus_space_write_stream_2(t, h, o, *a);
747 }
748
749 static __inline void
750 bus_space_write_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
751     bus_size_t o, const uint32_t *a, bus_size_t c)
752 {
753
754         for (; c; a++, c--, o += 4)
755                 bus_space_write_stream_4(t, h, o, *a);
756 }
757
758 static __inline void
759 bus_space_write_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
760     bus_size_t o, const uint64_t *a, bus_size_t c)
761 {
762
763         for (; c; a++, c--, o += 8)
764                 bus_space_write_stream_8(t, h, o, *a);
765 }
766
767 static __inline void
768 bus_space_set_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
769     bus_size_t o, const uint8_t v, bus_size_t c)
770 {
771
772         for (; c; c--, o++)
773                 bus_space_write_stream_1(t, h, o, v);
774 }
775
776 static __inline void
777 bus_space_set_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
778     bus_size_t o, const uint16_t v, bus_size_t c)
779 {
780
781         for (; c; c--, o += 2)
782                 bus_space_write_stream_2(t, h, o, v);
783 }
784
785 static __inline void
786 bus_space_set_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
787     bus_size_t o, const uint32_t v, bus_size_t c)
788 {
789
790         for (; c; c--, o += 4)
791                 bus_space_write_stream_4(t, h, o, v);
792 }
793
794 static __inline void
795 bus_space_set_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
796     bus_size_t o, const uint64_t v, bus_size_t c)
797 {
798
799         for (; c; c--, o += 8)
800                 bus_space_write_stream_8(t, h, o, v);
801 }
802
803 static __inline void
804 bus_space_copy_region_stream_1(bus_space_tag_t t, bus_space_handle_t h1,
805     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
806 {
807
808         for (; c; c--, o1++, o2++)
809             bus_space_write_stream_1(t, h1, o1, bus_space_read_stream_1(t, h2,
810                 o2));
811 }
812
813 static __inline void
814 bus_space_copy_region_stream_2(bus_space_tag_t t, bus_space_handle_t h1,
815     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
816 {
817
818         for (; c; c--, o1 += 2, o2 += 2)
819             bus_space_write_stream_2(t, h1, o1, bus_space_read_stream_2(t, h2,
820                 o2));
821 }
822
823 static __inline void
824 bus_space_copy_region_stream_4(bus_space_tag_t t, bus_space_handle_t h1,
825     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
826 {
827
828         for (; c; c--, o1 += 4, o2 += 4)
829             bus_space_write_stream_4(t, h1, o1, bus_space_read_stream_4(t, h2,
830                 o2));
831 }
832
833 static __inline void
834 bus_space_copy_region_stream_8(bus_space_tag_t t, bus_space_handle_t h1,
835     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
836 {
837
838         for (; c; c--, o1 += 8, o2 += 8)
839             bus_space_write_stream_8(t, h1, o1, bus_space_read_8(t, h2, o2));
840 }
841
842 static __inline int
843 bus_space_peek_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
844         uint8_t *a)
845 {
846
847         __BUS_DEBUG_ACCESS(h, o, "peek", 1);
848         return (fasword8(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
849 }
850
851 static __inline int
852 bus_space_peek_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
853         uint16_t *a)
854 {
855
856         __BUS_DEBUG_ACCESS(h, o, "peek", 2);
857         return (fasword16(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
858 }
859
860 static __inline int
861 bus_space_peek_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
862         uint32_t *a)
863 {
864
865         __BUS_DEBUG_ACCESS(h, o, "peek", 4);
866         return (fasword32(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
867 }
868
869 #include <machine/bus_dma.h>
870
871 #endif /* !_MACHINE_BUS_H_ */