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