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