]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sparc64/include/bus.h
Update from svn-1.8.14 to 1.9.2.
[FreeBSD/FreeBSD.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         int             bst_type;
108 };
109
110 /*
111  * Bus space function prototypes.
112  */
113 static void bus_space_barrier(bus_space_tag_t, bus_space_handle_t, bus_size_t,
114     bus_size_t, int);
115 static int bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
116     bus_size_t, bus_size_t, bus_space_handle_t *);
117
118 /*
119  * Map a region of device bus space into CPU virtual address space.
120  */
121 int bus_space_map(bus_space_tag_t tag, bus_addr_t address, bus_size_t size,
122     int flags, bus_space_handle_t *handlep);
123
124 /*
125  * Unmap a region of device bus space.
126  */
127 void bus_space_unmap(bus_space_tag_t tag, bus_space_handle_t handle,
128     bus_size_t size);
129
130 static __inline void
131 bus_space_barrier(bus_space_tag_t t __unused, bus_space_handle_t h __unused,
132     bus_size_t o __unused, bus_size_t s __unused, int f __unused)
133 {
134
135         /*
136          * We have lots of alternatives depending on whether we're
137          * synchronizing loads with loads, loads with stores, stores
138          * with loads, or stores with stores.  The only ones that seem
139          * generic are #Sync and #MemIssue.  We use #Sync for safety.
140          */
141         membar(Sync);
142 }
143
144 static __inline int
145 bus_space_subregion(bus_space_tag_t t __unused, bus_space_handle_t h,
146     bus_size_t o __unused, bus_size_t s __unused, bus_space_handle_t *hp)
147 {
148
149         *hp = h + o;
150         return (0);
151 }
152
153 /* flags for bus space map functions */
154 #define BUS_SPACE_MAP_CACHEABLE         0x0001
155 #define BUS_SPACE_MAP_LINEAR            0x0002
156 #define BUS_SPACE_MAP_READONLY          0x0004
157 #define BUS_SPACE_MAP_PREFETCHABLE      0x0008
158 /* placeholders for bus functions... */
159 #define BUS_SPACE_MAP_BUS1              0x0100
160 #define BUS_SPACE_MAP_BUS2              0x0200
161 #define BUS_SPACE_MAP_BUS3              0x0400
162 #define BUS_SPACE_MAP_BUS4              0x0800
163
164 /* flags for bus_space_barrier() */
165 #define BUS_SPACE_BARRIER_READ          0x01    /* force read barrier */
166 #define BUS_SPACE_BARRIER_WRITE         0x02    /* force write barrier */
167
168 #ifdef BUS_SPACE_DEBUG
169 #define KTR_BUS                         KTR_SPARE2
170 #define __BUS_DEBUG_ACCESS(h, o, desc, sz) do {                         \
171         CTR4(KTR_BUS, "bus space: %s %d: handle %#lx, offset %#lx",     \
172             (desc), (sz), (h), (o));                                    \
173 } while (0)
174 #else
175 #define __BUS_DEBUG_ACCESS(h, o, desc, sz)
176 #endif
177
178 static __inline uint8_t
179 bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
180 {
181
182         __BUS_DEBUG_ACCESS(h, o, "read", 1);
183         return (lduba_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
184 }
185
186 static __inline uint16_t
187 bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
188 {
189
190         __BUS_DEBUG_ACCESS(h, o, "read", 2);
191         return (lduha_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
192 }
193
194 static __inline uint32_t
195 bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
196 {
197
198         __BUS_DEBUG_ACCESS(h, o, "read", 4);
199         return (lduwa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
200 }
201
202 static __inline uint64_t
203 bus_space_read_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
204 {
205
206         __BUS_DEBUG_ACCESS(h, o, "read", 8);
207         return (ldxa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
208 }
209
210 static __inline void
211 bus_space_read_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
212     uint8_t *a, size_t c)
213 {
214
215         while (c-- > 0)
216                 *a++ = bus_space_read_1(t, h, o);
217 }
218
219 static __inline void
220 bus_space_read_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
221     uint16_t *a, size_t c)
222 {
223
224         while (c-- > 0)
225                 *a++ = bus_space_read_2(t, h, o);
226 }
227
228 static __inline void
229 bus_space_read_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
230     uint32_t *a, size_t c)
231 {
232
233         while (c-- > 0)
234                 *a++ = bus_space_read_4(t, h, o);
235 }
236
237 static __inline void
238 bus_space_read_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
239     uint64_t *a, size_t c)
240 {
241
242         while (c-- > 0)
243                 *a++ = bus_space_read_8(t, h, o);
244 }
245
246 static __inline void
247 bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
248     uint8_t v)
249 {
250
251         __BUS_DEBUG_ACCESS(h, o, "write", 1);
252         stba_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
253 }
254
255 static __inline void
256 bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
257     uint16_t v)
258 {
259
260         __BUS_DEBUG_ACCESS(h, o, "write", 2);
261         stha_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
262 }
263
264 static __inline void
265 bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
266     uint32_t v)
267 {
268
269         __BUS_DEBUG_ACCESS(h, o, "write", 4);
270         stwa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
271 }
272
273 static __inline void
274 bus_space_write_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
275     uint64_t v)
276 {
277
278         __BUS_DEBUG_ACCESS(h, o, "write", 8);
279         stxa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
280 }
281
282 static __inline void
283 bus_space_write_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
284     const uint8_t *a, size_t c)
285 {
286
287         while (c-- > 0)
288                 bus_space_write_1(t, h, o, *a++);
289 }
290
291 static __inline void
292 bus_space_write_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
293     const uint16_t *a, size_t c)
294 {
295
296         while (c-- > 0)
297                 bus_space_write_2(t, h, o, *a++);
298 }
299
300 static __inline void
301 bus_space_write_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
302     const uint32_t *a, size_t c)
303 {
304
305         while (c-- > 0)
306                 bus_space_write_4(t, h, o, *a++);
307 }
308
309 static __inline void
310 bus_space_write_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
311     const uint64_t *a, size_t c)
312 {
313
314         while (c-- > 0)
315                 bus_space_write_8(t, h, o, *a++);
316 }
317
318 static __inline void
319 bus_space_set_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
320     uint8_t v, size_t c)
321 {
322
323         while (c-- > 0)
324                 bus_space_write_1(t, h, o, v);
325 }
326
327 static __inline void
328 bus_space_set_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
329     uint16_t v, size_t c)
330 {
331
332         while (c-- > 0)
333                 bus_space_write_2(t, h, o, v);
334 }
335
336 static __inline void
337 bus_space_set_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
338     uint32_t v, size_t c)
339 {
340
341         while (c-- > 0)
342                 bus_space_write_4(t, h, o, v);
343 }
344
345 static __inline void
346 bus_space_set_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
347     uint64_t v, size_t c)
348 {
349
350         while (c-- > 0)
351                 bus_space_write_8(t, h, o, v);
352 }
353
354 static __inline void
355 bus_space_read_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
356     uint8_t *a, bus_size_t c)
357 {
358
359         for (; c; a++, c--, o++)
360                 *a = bus_space_read_1(t, h, o);
361 }
362
363 static __inline void
364 bus_space_read_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
365     uint16_t *a, bus_size_t c)
366 {
367
368         for (; c; a++, c--, o += 2)
369                 *a = bus_space_read_2(t, h, o);
370 }
371
372 static __inline void
373 bus_space_read_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
374     uint32_t *a, bus_size_t c)
375 {
376
377         for (; c; a++, c--, o += 4)
378                 *a = bus_space_read_4(t, h, o);
379 }
380
381 static __inline void
382 bus_space_read_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
383     uint64_t *a, bus_size_t c)
384 {
385
386         for (; c; a++, c--, o += 8)
387                 *a = bus_space_read_8(t, h, o);
388 }
389
390 static __inline void
391 bus_space_write_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
392     const uint8_t *a, bus_size_t c)
393 {
394
395         for (; c; a++, c--, o++)
396                 bus_space_write_1(t, h, o, *a);
397 }
398
399 static __inline void
400 bus_space_write_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
401     const uint16_t *a, bus_size_t c)
402 {
403
404         for (; c; a++, c--, o += 2)
405                 bus_space_write_2(t, h, o, *a);
406 }
407
408 static __inline void
409 bus_space_write_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
410     const uint32_t *a, bus_size_t c)
411 {
412
413         for (; c; a++, c--, o += 4)
414                 bus_space_write_4(t, h, o, *a);
415 }
416
417 static __inline void
418 bus_space_write_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
419     const uint64_t *a, bus_size_t c)
420 {
421
422         for (; c; a++, c--, o += 8)
423                 bus_space_write_8(t, h, o, *a);
424 }
425
426 static __inline void
427 bus_space_set_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
428     const uint8_t v, bus_size_t c)
429 {
430
431         for (; c; c--, o++)
432                 bus_space_write_1(t, h, o, v);
433 }
434
435 static __inline void
436 bus_space_set_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
437     const uint16_t v, bus_size_t c)
438 {
439
440         for (; c; c--, o += 2)
441                 bus_space_write_2(t, h, o, v);
442 }
443
444 static __inline void
445 bus_space_set_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
446     const uint32_t v, bus_size_t c)
447 {
448
449         for (; c; c--, o += 4)
450                 bus_space_write_4(t, h, o, v);
451 }
452
453 static __inline void
454 bus_space_set_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
455     const uint64_t v, bus_size_t c)
456 {
457
458         for (; c; c--, o += 8)
459                 bus_space_write_8(t, h, o, v);
460 }
461
462 static __inline void
463 bus_space_copy_region_1(bus_space_tag_t t, bus_space_handle_t h1,
464     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
465 {
466
467         for (; c; c--, o1++, o2++)
468             bus_space_write_1(t, h1, o1, bus_space_read_1(t, h2, o2));
469 }
470
471 static __inline void
472 bus_space_copy_region_2(bus_space_tag_t t, bus_space_handle_t h1,
473     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
474 {
475
476         for (; c; c--, o1 += 2, o2 += 2)
477             bus_space_write_2(t, h1, o1, bus_space_read_2(t, h2, o2));
478 }
479
480 static __inline void
481 bus_space_copy_region_4(bus_space_tag_t t, bus_space_handle_t h1,
482     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
483 {
484
485         for (; c; c--, o1 += 4, o2 += 4)
486             bus_space_write_4(t, h1, o1, bus_space_read_4(t, h2, o2));
487 }
488
489 static __inline void
490 bus_space_copy_region_8(bus_space_tag_t t, bus_space_handle_t h1,
491     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
492 {
493
494         for (; c; c--, o1 += 8, o2 += 8)
495             bus_space_write_8(t, h1, o1, bus_space_read_8(t, h2, o2));
496 }
497
498 static __inline uint8_t
499 bus_space_read_stream_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
500 {
501
502         __BUS_DEBUG_ACCESS(h, o, "read stream", 1);
503         return (lduba_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
504 }
505
506 static __inline uint16_t
507 bus_space_read_stream_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
508 {
509
510         __BUS_DEBUG_ACCESS(h, o, "read stream", 2);
511         return (lduha_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
512 }
513
514 static __inline uint32_t
515 bus_space_read_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
516 {
517
518         __BUS_DEBUG_ACCESS(h, o, "read stream", 4);
519         return (lduwa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
520 }
521
522 static __inline uint64_t
523 bus_space_read_stream_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
524 {
525
526         __BUS_DEBUG_ACCESS(h, o, "read stream", 8);
527         return (ldxa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type]));
528 }
529
530 static __inline void
531 bus_space_read_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h,
532     bus_size_t o, uint8_t *a, size_t c)
533 {
534
535         while (c-- > 0)
536                 *a++ = bus_space_read_stream_1(t, h, o);
537 }
538
539 static __inline void
540 bus_space_read_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h,
541     bus_size_t o, uint16_t *a, size_t c)
542 {
543
544         while (c-- > 0)
545                 *a++ = bus_space_read_stream_2(t, h, o);
546 }
547
548 static __inline void
549 bus_space_read_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h,
550     bus_size_t o, uint32_t *a, size_t c)
551 {
552
553         while (c-- > 0)
554                 *a++ = bus_space_read_stream_4(t, h, o);
555 }
556
557 static __inline void
558 bus_space_read_multi_stream_8(bus_space_tag_t t, bus_space_handle_t h,
559     bus_size_t o, uint64_t *a, size_t c)
560 {
561
562         while (c-- > 0)
563                 *a++ = bus_space_read_stream_8(t, h, o);
564 }
565
566 static __inline void
567 bus_space_write_stream_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
568     uint8_t v)
569 {
570
571         __BUS_DEBUG_ACCESS(h, o, "write stream", 1);
572         stba_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
573 }
574
575 static __inline void
576 bus_space_write_stream_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
577     uint16_t v)
578 {
579
580         __BUS_DEBUG_ACCESS(h, o, "write stream", 2);
581         stha_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
582 }
583
584 static __inline void
585 bus_space_write_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
586     uint32_t v)
587 {
588
589         __BUS_DEBUG_ACCESS(h, o, "write stream", 4);
590         stwa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
591 }
592
593 static __inline void
594 bus_space_write_stream_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
595     uint64_t v)
596 {
597
598         __BUS_DEBUG_ACCESS(h, o, "write stream", 8);
599         stxa_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
600 }
601
602 static __inline void
603 bus_space_write_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h,
604     bus_size_t o, const uint8_t *a, size_t c)
605 {
606
607         while (c-- > 0)
608                 bus_space_write_stream_1(t, h, o, *a++);
609 }
610
611 static __inline void
612 bus_space_write_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h,
613     bus_size_t o, const uint16_t *a, size_t c)
614 {
615
616         while (c-- > 0)
617                 bus_space_write_stream_2(t, h, o, *a++);
618 }
619
620 static __inline void
621 bus_space_write_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h,
622     bus_size_t o, const uint32_t *a, size_t c)
623 {
624
625         while (c-- > 0)
626                 bus_space_write_stream_4(t, h, o, *a++);
627 }
628
629 static __inline void
630 bus_space_write_multi_stream_8(bus_space_tag_t t, bus_space_handle_t h,
631     bus_size_t o, const uint64_t *a, size_t c)
632 {
633
634         while (c-- > 0)
635                 bus_space_write_stream_8(t, h, o, *a++);
636 }
637
638 static __inline void
639 bus_space_set_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h,
640     bus_size_t o, uint8_t v, size_t c)
641 {
642
643         while (c-- > 0)
644                 bus_space_write_stream_1(t, h, o, v);
645 }
646
647 static __inline void
648 bus_space_set_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h,
649     bus_size_t o, uint16_t v, size_t c)
650 {
651
652         while (c-- > 0)
653                 bus_space_write_stream_2(t, h, o, v);
654 }
655
656 static __inline void
657 bus_space_set_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h,
658     bus_size_t o, uint32_t v, size_t c)
659 {
660
661         while (c-- > 0)
662                 bus_space_write_stream_4(t, h, o, v);
663 }
664
665 static __inline void
666 bus_space_set_multi_stream_8(bus_space_tag_t t, bus_space_handle_t h,
667     bus_size_t o, uint64_t v, size_t c)
668 {
669
670         while (c-- > 0)
671                 bus_space_write_stream_8(t, h, o, v);
672 }
673
674 static __inline void
675 bus_space_read_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
676     bus_size_t o, uint8_t *a, bus_size_t c)
677 {
678
679         for (; c; a++, c--, o++)
680                 *a = bus_space_read_stream_1(t, h, o);
681 }
682
683 static __inline void
684 bus_space_read_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
685     bus_size_t o, uint16_t *a, bus_size_t c)
686 {
687
688         for (; c; a++, c--, o += 2)
689                 *a = bus_space_read_stream_2(t, h, o);
690 }
691
692 static __inline void
693 bus_space_read_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
694     bus_size_t o, uint32_t *a, bus_size_t c)
695 {
696
697         for (; c; a++, c--, o += 4)
698                 *a = bus_space_read_stream_4(t, h, o);
699 }
700
701 static __inline void
702 bus_space_read_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
703     bus_size_t o, uint64_t *a, bus_size_t c)
704 {
705
706         for (; c; a++, c--, o += 8)
707                 *a = bus_space_read_stream_8(t, h, o);
708 }
709
710 static __inline void
711 bus_space_write_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
712     bus_size_t o, const uint8_t *a, bus_size_t c)
713 {
714
715         for (; c; a++, c--, o++)
716                 bus_space_write_stream_1(t, h, o, *a);
717 }
718
719 static __inline void
720 bus_space_write_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
721     bus_size_t o, const uint16_t *a, bus_size_t c)
722 {
723
724         for (; c; a++, c--, o += 2)
725                 bus_space_write_stream_2(t, h, o, *a);
726 }
727
728 static __inline void
729 bus_space_write_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
730     bus_size_t o, const uint32_t *a, bus_size_t c)
731 {
732
733         for (; c; a++, c--, o += 4)
734                 bus_space_write_stream_4(t, h, o, *a);
735 }
736
737 static __inline void
738 bus_space_write_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
739     bus_size_t o, const uint64_t *a, bus_size_t c)
740 {
741
742         for (; c; a++, c--, o += 8)
743                 bus_space_write_stream_8(t, h, o, *a);
744 }
745
746 static __inline void
747 bus_space_set_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
748     bus_size_t o, const uint8_t v, bus_size_t c)
749 {
750
751         for (; c; c--, o++)
752                 bus_space_write_stream_1(t, h, o, v);
753 }
754
755 static __inline void
756 bus_space_set_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
757     bus_size_t o, const uint16_t v, bus_size_t c)
758 {
759
760         for (; c; c--, o += 2)
761                 bus_space_write_stream_2(t, h, o, v);
762 }
763
764 static __inline void
765 bus_space_set_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
766     bus_size_t o, const uint32_t v, bus_size_t c)
767 {
768
769         for (; c; c--, o += 4)
770                 bus_space_write_stream_4(t, h, o, v);
771 }
772
773 static __inline void
774 bus_space_set_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
775     bus_size_t o, const uint64_t v, bus_size_t c)
776 {
777
778         for (; c; c--, o += 8)
779                 bus_space_write_stream_8(t, h, o, v);
780 }
781
782 static __inline void
783 bus_space_copy_region_stream_1(bus_space_tag_t t, bus_space_handle_t h1,
784     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
785 {
786
787         for (; c; c--, o1++, o2++)
788             bus_space_write_stream_1(t, h1, o1, bus_space_read_stream_1(t, h2,
789                 o2));
790 }
791
792 static __inline void
793 bus_space_copy_region_stream_2(bus_space_tag_t t, bus_space_handle_t h1,
794     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
795 {
796
797         for (; c; c--, o1 += 2, o2 += 2)
798             bus_space_write_stream_2(t, h1, o1, bus_space_read_stream_2(t, h2,
799                 o2));
800 }
801
802 static __inline void
803 bus_space_copy_region_stream_4(bus_space_tag_t t, bus_space_handle_t h1,
804     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
805 {
806
807         for (; c; c--, o1 += 4, o2 += 4)
808             bus_space_write_stream_4(t, h1, o1, bus_space_read_stream_4(t, h2,
809                 o2));
810 }
811
812 static __inline void
813 bus_space_copy_region_stream_8(bus_space_tag_t t, bus_space_handle_t h1,
814     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
815 {
816
817         for (; c; c--, o1 += 8, o2 += 8)
818             bus_space_write_stream_8(t, h1, o1, bus_space_read_8(t, h2, o2));
819 }
820
821 static __inline int
822 bus_space_peek_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
823         uint8_t *a)
824 {
825
826         __BUS_DEBUG_ACCESS(h, o, "peek", 1);
827         return (fasword8(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
828 }
829
830 static __inline int
831 bus_space_peek_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
832         uint16_t *a)
833 {
834
835         __BUS_DEBUG_ACCESS(h, o, "peek", 2);
836         return (fasword16(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
837 }
838
839 static __inline int
840 bus_space_peek_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
841         uint32_t *a)
842 {
843
844         __BUS_DEBUG_ACCESS(h, o, "peek", 4);
845         return (fasword32(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
846 }
847
848 #include <machine/bus_dma.h>
849
850 #endif /* !_MACHINE_BUS_H_ */