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 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the NetBSD
20 * Foundation, Inc. and its contributors.
21 * 4. Neither the name of The NetBSD Foundation nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37 /*
38 * Copyright (c) 1997-1999 Eduardo E. Horvath. All rights reserved.
39 * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
40 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 * must display the following acknowledgement:
52 * This product includes software developed by Christopher G. Demetriou
53 * for the NetBSD Project.
54 * 4. The name of the author may not be used to endorse or promote products
55 * derived from this software without specific prior written permission
56 *
57 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
61 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
62 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
66 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 *
68 * from: NetBSD: bus.h,v 1.28 2001/07/19 15:32:19 thorpej Exp
69 * and
70 * from: FreeBSD: src/sys/alpha/include/bus.h,v 1.9 2001/01/09
71 *
72 * $FreeBSD: releng/6.0/sys/sparc64/include/bus.h 145253 2005-04-18 21:45:34Z imp $
73 */
74
75 #ifndef _MACHINE_BUS_H_
76 #define _MACHINE_BUS_H_
77
78 #ifdef BUS_SPACE_DEBUG
79 #include <sys/ktr.h>
80 #endif
81
82 #include <machine/_bus.h>
83 #include <machine/cpufunc.h>
84 #include <machine/upa.h>
85
86 /*
87 * UPA and SBUS spaces are non-cached and big endian
88 * (except for RAM and PROM)
89 *
90 * PCI spaces are non-cached and little endian
91 */
92 #define UPA_BUS_SPACE 0
93 #define SBUS_BUS_SPACE 1
94 #define PCI_CONFIG_BUS_SPACE 2
95 #define PCI_IO_BUS_SPACE 3
96 #define PCI_MEMORY_BUS_SPACE 4
97 #define LAST_BUS_SPACE 5
98
99 extern int bus_type_asi[];
100 extern int bus_stream_asi[];
101
102 #define __BUS_SPACE_HAS_STREAM_METHODS 1
103
104 #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF
105 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
106 #define BUS_SPACE_MAXSIZE 0xFFFFFFFFFFFFFFFF
107 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF
108 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
109 #define BUS_SPACE_MAXADDR 0xFFFFFFFF
110
111 #define BUS_SPACE_UNRESTRICTED (~0)
112
113 /*
114 * Access methods for bus resources and address space.
115 */
116 typedef struct bus_space_tag *bus_space_tag_t;
117
118 struct bus_space_tag {
119 void *bst_cookie;
120 bus_space_tag_t bst_parent;
121 int bst_type;
122
123 void (*bst_bus_barrier)(bus_space_tag_t, bus_space_handle_t,
124 bus_size_t, bus_size_t, int);
125 };
126
127 /*
128 * Bus space function prototypes.
129 */
130 static void bus_space_barrier(bus_space_tag_t, bus_space_handle_t, bus_size_t,
131 bus_size_t, int);
132 static int bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
133 bus_size_t, bus_size_t, bus_space_handle_t *);
134
135 /*
136 * Map a region of device bus space into CPU virtual address space.
137 */
138
139 static __inline int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
140 bus_size_t size, int flags,
141 bus_space_handle_t *bshp);
142
143 static __inline int
144 bus_space_map(bus_space_tag_t t __unused, bus_addr_t addr,
145 bus_size_t size __unused, int flags __unused,
146 bus_space_handle_t *bshp)
147 {
148
149 *bshp = addr;
150 return (0);
151 }
152
153 /*
154 * Unmap a region of device bus space.
155 */
156 static __inline void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
157 bus_size_t size);
158
159 static __inline void
160 bus_space_unmap(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused,
161 bus_size_t size __unused)
162 {
163 }
164
165 /* This macro finds the first "upstream" implementation of method `f' */
166 #define _BS_CALL(t,f) \
167 while (t->f == NULL) \
168 t = t->bst_parent; \
169 return (*(t)->f)
170
171 static __inline void
172 bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
173 bus_size_t s, int f)
174 {
175 _BS_CALL(t, bst_bus_barrier)(t, h, o, s, f);
176 }
177
178 static __inline int
179 bus_space_subregion(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
180 bus_size_t s, bus_space_handle_t *hp)
181 {
182 *hp = h + o;
183 return (0);
184 }
185
186 /* flags for bus space map functions */
187 #define BUS_SPACE_MAP_CACHEABLE 0x0001
188 #define BUS_SPACE_MAP_LINEAR 0x0002
189 #define BUS_SPACE_MAP_READONLY 0x0004
190 #define BUS_SPACE_MAP_PREFETCHABLE 0x0008
191 /* placeholders for bus functions... */
192 #define BUS_SPACE_MAP_BUS1 0x0100
193 #define BUS_SPACE_MAP_BUS2 0x0200
194 #define BUS_SPACE_MAP_BUS3 0x0400
195 #define BUS_SPACE_MAP_BUS4 0x0800
196
197 /* flags for bus_space_barrier() */
198 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
199 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
200
201 #ifdef BUS_SPACE_DEBUG
202 #define KTR_BUS KTR_CT2
203 #define BUS_HANDLE_MIN UPA_MEMSTART
204 #define __BUS_DEBUG_ACCESS(h, o, desc, sz) do { \
205 CTR4(KTR_BUS, "bus space: %s %d: handle %#lx, offset %#lx", \
206 (desc), (sz), (h), (o)); \
207 if ((h) + (o) < BUS_HANDLE_MIN) \
208 panic("bus space access at %#lx out of range", \
209 (h) + (o)); \
210 } while (0)
211 #else
212 #define __BUS_DEBUG_ACCESS(h, o, desc, sz)
213 #endif
214
215 static __inline uint8_t
216 bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
217 {
218
219 __BUS_DEBUG_ACCESS(h, o, "read", 1);
220 return (lduba_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
221 }
222
223 static __inline uint16_t
224 bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
225 {
226
227 __BUS_DEBUG_ACCESS(h, o, "read", 2);
228 return (lduha_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
229 }
230
231 static __inline uint32_t
232 bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
233 {
234
235 __BUS_DEBUG_ACCESS(h, o, "read", 4);
236 return (lduwa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
237 }
238
239 static __inline uint64_t
240 bus_space_read_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
241 {
242
243 __BUS_DEBUG_ACCESS(h, o, "read", 8);
244 return (ldxa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
245 }
246
247 static __inline void
248 bus_space_read_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
249 uint8_t *a, size_t c)
250 {
251
252 while (c-- > 0)
253 *a++ = bus_space_read_1(t, h, o);
254 }
255
256 static __inline void
257 bus_space_read_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
258 uint16_t *a, size_t c)
259 {
260
261 while (c-- > 0)
262 *a++ = bus_space_read_2(t, h, o);
263 }
264
265 static __inline void
266 bus_space_read_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
267 uint32_t *a, size_t c)
268 {
269
270 while (c-- > 0)
271 *a++ = bus_space_read_4(t, h, o);
272 }
273
274 static __inline void
275 bus_space_read_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
276 uint64_t *a, size_t c)
277 {
278
279 while (c-- > 0)
280 *a++ = bus_space_read_8(t, h, o);
281 }
282
283 static __inline void
284 bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
285 uint8_t v)
286 {
287
288 __BUS_DEBUG_ACCESS(h, o, "write", 1);
289 stba_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
290 }
291
292 static __inline void
293 bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
294 uint16_t v)
295 {
296
297 __BUS_DEBUG_ACCESS(h, o, "write", 2);
298 stha_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
299 }
300
301 static __inline void
302 bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
303 uint32_t v)
304 {
305
306 __BUS_DEBUG_ACCESS(h, o, "write", 4);
307 stwa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
308 }
309
310 static __inline void
311 bus_space_write_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
312 uint64_t v)
313 {
314
315 __BUS_DEBUG_ACCESS(h, o, "write", 8);
316 stxa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
317 }
318
319 static __inline void
320 bus_space_write_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
321 uint8_t *a, size_t c)
322 {
323
324 while (c-- > 0)
325 bus_space_write_1(t, h, o, *a++);
326 }
327
328 static __inline void
329 bus_space_write_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
330 uint16_t *a, size_t c)
331 {
332
333 while (c-- > 0)
334 bus_space_write_2(t, h, o, *a++);
335 }
336
337 static __inline void
338 bus_space_write_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
339 uint32_t *a, size_t c)
340 {
341
342 while (c-- > 0)
343 bus_space_write_4(t, h, o, *a++);
344 }
345
346 static __inline void
347 bus_space_write_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
348 uint64_t *a, size_t c)
349 {
350
351 while (c-- > 0)
352 bus_space_write_8(t, h, o, *a++);
353 }
354
355 static __inline void
356 bus_space_set_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
357 uint8_t v, size_t c)
358 {
359
360 while (c-- > 0)
361 bus_space_write_1(t, h, o, v);
362 }
363
364 static __inline void
365 bus_space_set_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
366 uint16_t v, size_t c)
367 {
368
369 while (c-- > 0)
370 bus_space_write_2(t, h, o, v);
371 }
372
373 static __inline void
374 bus_space_set_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
375 uint32_t v, size_t c)
376 {
377
378 while (c-- > 0)
379 bus_space_write_4(t, h, o, v);
380 }
381
382 static __inline void
383 bus_space_set_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
384 uint64_t v, size_t c)
385 {
386
387 while (c-- > 0)
388 bus_space_write_8(t, h, o, v);
389 }
390
391 static __inline void
392 bus_space_read_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
393 u_int8_t *a, bus_size_t c)
394 {
395 for (; c; a++, c--, o++)
396 *a = bus_space_read_1(t, h, o);
397 }
398
399 static __inline void
400 bus_space_read_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
401 u_int16_t *a, bus_size_t c)
402 {
403 for (; c; a++, c--, o+=2)
404 *a = bus_space_read_2(t, h, o);
405 }
406
407 static __inline void
408 bus_space_read_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
409 u_int32_t *a, bus_size_t c)
410 {
411 for (; c; a++, c--, o+=4)
412 *a = bus_space_read_4(t, h, o);
413 }
414
415 static __inline void
416 bus_space_read_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
417 u_int64_t *a, bus_size_t c)
418 {
419 for (; c; a++, c--, o+=8)
420 *a = bus_space_read_8(t, h, o);
421 }
422
423 static __inline void
424 bus_space_write_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
425 const u_int8_t *a, bus_size_t c)
426 {
427 for (; c; a++, c--, o++)
428 bus_space_write_1(t, h, o, *a);
429 }
430
431 static __inline void
432 bus_space_write_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
433 const u_int16_t *a, bus_size_t c)
434 {
435 for (; c; a++, c--, o+=2)
436 bus_space_write_2(t, h, o, *a);
437 }
438
439 static __inline void
440 bus_space_write_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
441 const u_int32_t *a, bus_size_t c)
442 {
443 for (; c; a++, c--, o+=4)
444 bus_space_write_4(t, h, o, *a);
445 }
446
447 static __inline void
448 bus_space_write_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
449 const u_int64_t *a, bus_size_t c)
450 {
451 for (; c; a++, c--, o+=8)
452 bus_space_write_8(t, h, o, *a);
453 }
454
455 static __inline void
456 bus_space_set_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
457 const u_int8_t v, bus_size_t c)
458 {
459 for (; c; c--, o++)
460 bus_space_write_1(t, h, o, v);
461 }
462
463 static __inline void
464 bus_space_set_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
465 const u_int16_t v, bus_size_t c)
466 {
467 for (; c; c--, o+=2)
468 bus_space_write_2(t, h, o, v);
469 }
470
471 static __inline void
472 bus_space_set_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
473 const u_int32_t v, bus_size_t c)
474 {
475 for (; c; c--, o+=4)
476 bus_space_write_4(t, h, o, v);
477 }
478
479 static __inline void
480 bus_space_set_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
481 const u_int64_t v, bus_size_t c)
482 {
483 for (; c; c--, o+=8)
484 bus_space_write_8(t, h, o, v);
485 }
486
487 static __inline void
488 bus_space_copy_region_1(bus_space_tag_t t, bus_space_handle_t h1,
489 bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
490 {
491 for (; c; c--, o1++, o2++)
492 bus_space_write_1(t, h1, o1, bus_space_read_1(t, h2, o2));
493 }
494
495 static __inline void
496 bus_space_copy_region_2(bus_space_tag_t t, bus_space_handle_t h1,
497 bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
498 {
499 for (; c; c--, o1+=2, o2+=2)
500 bus_space_write_2(t, h1, o1, bus_space_read_2(t, h2, o2));
501 }
502
503 static __inline void
504 bus_space_copy_region_4(bus_space_tag_t t, bus_space_handle_t h1,
505 bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
506 {
507 for (; c; c--, o1+=4, o2+=4)
508 bus_space_write_4(t, h1, o1, bus_space_read_4(t, h2, o2));
509 }
510
511 static __inline void
512 bus_space_copy_region_8(bus_space_tag_t t, bus_space_handle_t h1,
513 bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
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, u_int8_t *a, bus_size_t c)
698 {
699 for (; c; a++, c--, o++)
700 *a = bus_space_read_stream_1(t, h, o);
701 }
702
703 static __inline void
704 bus_space_read_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
705 bus_size_t o, u_int16_t *a, bus_size_t c)
706 {
707 for (; c; a++, c--, o+=2)
708 *a = bus_space_read_stream_2(t, h, o);
709 }
710
711 static __inline void
712 bus_space_read_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
713 bus_size_t o, u_int32_t *a, bus_size_t c)
714 {
715 for (; c; a++, c--, o+=4)
716 *a = bus_space_read_stream_4(t, h, o);
717 }
718
719 static __inline void
720 bus_space_read_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
721 bus_size_t o, u_int64_t *a, bus_size_t c)
722 {
723 for (; c; a++, c--, o+=8)
724 *a = bus_space_read_stream_8(t, h, o);
725 }
726
727 static __inline void
728 bus_space_write_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
729 bus_size_t o, const u_int8_t *a, bus_size_t c)
730 {
731 for (; c; a++, c--, o++)
732 bus_space_write_stream_1(t, h, o, *a);
733 }
734
735 static __inline void
736 bus_space_write_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
737 bus_size_t o, const u_int16_t *a, bus_size_t c)
738 {
739 for (; c; a++, c--, o+=2)
740 bus_space_write_stream_2(t, h, o, *a);
741 }
742
743 static __inline void
744 bus_space_write_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
745 bus_size_t o, const u_int32_t *a, bus_size_t c)
746 {
747 for (; c; a++, c--, o+=4)
748 bus_space_write_stream_4(t, h, o, *a);
749 }
750
751 static __inline void
752 bus_space_write_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
753 bus_size_t o, const u_int64_t *a, bus_size_t c)
754 {
755 for (; c; a++, c--, o+=8)
756 bus_space_write_stream_8(t, h, o, *a);
757 }
758
759 static __inline void
760 bus_space_set_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
761 bus_size_t o, const u_int8_t v, bus_size_t c)
762 {
763 for (; c; c--, o++)
764 bus_space_write_stream_1(t, h, o, v);
765 }
766
767 static __inline void
768 bus_space_set_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
769 bus_size_t o, const u_int16_t v, bus_size_t c)
770 {
771 for (; c; c--, o+=2)
772 bus_space_write_stream_2(t, h, o, v);
773 }
774
775 static __inline void
776 bus_space_set_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
777 bus_size_t o, const u_int32_t v, bus_size_t c)
778 {
779 for (; c; c--, o+=4)
780 bus_space_write_stream_4(t, h, o, v);
781 }
782
783 static __inline void
784 bus_space_set_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
785 bus_size_t o, const u_int64_t v, bus_size_t c)
786 {
787 for (; c; c--, o+=8)
788 bus_space_write_stream_8(t, h, o, v);
789 }
790
791 static __inline void
792 bus_space_copy_region_stream_1(bus_space_tag_t t, bus_space_handle_t h1,
793 bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
794 {
795 for (; c; c--, o1++, o2++)
796 bus_space_write_stream_1(t, h1, o1, bus_space_read_stream_1(t, h2,
797 o2));
798 }
799
800 static __inline void
801 bus_space_copy_region_stream_2(bus_space_tag_t t, bus_space_handle_t h1,
802 bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
803 {
804 for (; c; c--, o1+=2, o2+=2)
805 bus_space_write_stream_2(t, h1, o1, bus_space_read_stream_2(t, h2,
806 o2));
807 }
808
809 static __inline void
810 bus_space_copy_region_stream_4(bus_space_tag_t t, bus_space_handle_t h1,
811 bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
812 {
813 for (; c; c--, o1+=4, o2+=4)
814 bus_space_write_stream_4(t, h1, o1, bus_space_read_stream_4(t, h2,
815 o2));
816 }
817
818 static __inline void
819 bus_space_copy_region_stream_8(bus_space_tag_t t, bus_space_handle_t h1,
820 bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
821 {
822 for (; c; c--, o1+=8, o2+=8)
823 bus_space_write_stream_8(t, h1, o1, bus_space_read_8(t, h2, o2));
824 }
825
826 static __inline int
827 bus_space_peek_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
828 u_int8_t *a)
829 {
830
831 __BUS_DEBUG_ACCESS(h, o, "peek", 1);
832 return (fasword8(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
833 }
834
835 static __inline int
836 bus_space_peek_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
837 u_int16_t *a)
838 {
839
840 __BUS_DEBUG_ACCESS(h, o, "peek", 2);
841 return (fasword16(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
842 }
843
844 static __inline int
845 bus_space_peek_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
846 u_int32_t *a)
847 {
848
849 __BUS_DEBUG_ACCESS(h, o, "peek", 4);
850 return (fasword32(bus_type_asi[t->bst_type], (caddr_t)(h + o), a));
851 }
852
853 /* Back-compat functions for old ISA drivers */
854 extern bus_space_tag_t isa_io_bt;
855 extern bus_space_handle_t isa_io_hdl;
856 extern bus_space_tag_t isa_mem_bt;
857 extern bus_space_handle_t isa_mem_hdl;
858
859 #define inb(o) bus_space_read_1(isa_io_bt, isa_io_hdl, o)
860 #define inw(o) bus_space_read_2(isa_io_bt, isa_io_hdl, o)
861 #define inl(o) bus_space_read_4(isa_io_bt, isa_io_hdl, o)
862 #define outb(o, v) bus_space_write_1(isa_io_bt, isa_io_hdl, o, v)
863 #define outw(o, v) bus_space_write_2(isa_io_bt, isa_io_hdl, o, v)
864 #define outl(o, v) bus_space_write_4(isa_io_bt, isa_io_hdl, o, v)
865
866 #define readb(o) bus_space_read_1(isa_mem_bt, isa_mem_hdl, o)
867 #define readw(o) bus_space_read_2(isa_mem_bt, isa_mem_hdl, o)
868 #define readl(o) bus_space_read_4(isa_mem_bt, isa_mem_hdl, o)
869 #define writeb(o, v) bus_space_write_1(isa_mem_bt, isa_mem_hdl, o, v)
870 #define writew(o, v) bus_space_write_2(isa_mem_bt, isa_mem_hdl, o, v)
871 #define writel(o, v) bus_space_write_4(isa_mem_bt, isa_mem_hdl, o, v)
872
873 #define insb(o, a, c) \
874 bus_space_read_multi_1(isa_io_bt, isa_io_hdl, o, (void*)a, c)
875 #define insw(o, a, c) \
876 bus_space_read_multi_2(isa_io_bt, isa_io_hdl, o, (void*)a, c)
877 #define insl(o, a, c) \
878 bus_space_read_multi_4(isa_io_bt, isa_io_hdl, o, (void*)a, c)
879 #define outsb(o, a, c) \
880 bus_space_write_multi_1(isa_io_bt, isa_io_hdl, o, (void*)a, c)
881 #define outsw(o, a, c) \
882 bus_space_write_multi_2(isa_io_bt, isa_io_hdl, o, (void*)a, c)
883 #define outsl(o, a, c) \
884 bus_space_write_multi_4(isa_io_bt, isa_io_hdl, o, (void*)a, c)
885
886 #define memcpy_fromio(d, s, c) \
887 bus_space_read_region_1(isa_mem_bt, isa_mem_hdl, s, d, c)
888 #define memcpy_toio(d, s, c) \
889 bus_space_write_region_1(isa_mem_bt, isa_mem_hdl, d, s, c)
890 #define memcpy_io(d, s, c) \
891 bus_space_copy_region_1(isa_mem_bt, isa_mem_hdl, s, isa_mem_hdl, d, c)
892 #define memset_io(d, v, c) \
893 bus_space_set_region_1(isa_mem_bt, isa_mem_hdl, d, v, c)
894 #define memsetw_io(d, v, c) \
895 bus_space_set_region_2(isa_mem_bt, isa_mem_hdl, d, v, c)
896
897 static __inline void
898 memsetw(void *d, int val, size_t size)
899 {
900 u_int16_t *sp = d;
901
902 while (size--)
903 *sp++ = val;
904 }
905
906 #include <machine/bus_dma.h>
907
908 #endif /* !_MACHINE_BUS_H_ */
Cache object: 3a2be6c30ccaeaa10b915682826feb67
|