bus.h revision 1.15.40.1 1 /* $NetBSD: bus.h,v 1.15.40.1 2008/06/02 13:22:47 mjf Exp $ */
2
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 /*
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
64 #ifndef _SUN68K_BUS_H_
65 #define _SUN68K_BUS_H_
66
67 #define SUN68K_BUS_SPACE 0
68
69 /*
70 * Bus address and size types
71 */
72 typedef u_long bus_space_handle_t;
73 typedef u_long bus_type_t;
74 typedef u_long bus_addr_t;
75 typedef u_long bus_size_t;
76
77 #define BUS_ADDR_PADDR(x) ((x) & 0xffffffff)
78
79 /*
80 * Access methods for bus resources and address space.
81 */
82 typedef struct sun68k_bus_space_tag *bus_space_tag_t;
83
84 struct sun68k_bus_space_tag {
85 void *cookie;
86 bus_space_tag_t parent;
87
88 int (*sun68k_bus_map)(
89 bus_space_tag_t,
90 bus_type_t,
91 bus_addr_t,
92 bus_size_t,
93 int, /*flags*/
94 vaddr_t, /*preferred vaddr*/
95 bus_space_handle_t *);
96
97 int (*sun68k_bus_unmap)(
98 bus_space_tag_t,
99 bus_space_handle_t,
100 bus_size_t);
101
102 int (*sun68k_bus_subregion)(
103 bus_space_tag_t,
104 bus_space_handle_t,
105 bus_size_t, /*offset*/
106 bus_size_t, /*size*/
107 bus_space_handle_t *);
108
109 void (*sun68k_bus_barrier)(
110 bus_space_tag_t,
111 bus_space_handle_t,
112 bus_size_t, /*offset*/
113 bus_size_t, /*size*/
114 int); /*flags*/
115
116 paddr_t (*sun68k_bus_mmap)(
117 bus_space_tag_t,
118 bus_type_t, /**/
119 bus_addr_t, /**/
120 off_t, /*offset*/
121 int, /*prot*/
122 int); /*flags*/
123
124 void *(*sun68k_intr_establish)(
125 bus_space_tag_t,
126 int, /*bus-specific intr*/
127 int, /*device class level,
128 see machine/intr.h*/
129 int, /*flags*/
130 int (*)(void *), /*handler*/
131 void *); /*handler arg*/
132
133 int (*sun68k_bus_peek)(
134 bus_space_tag_t,
135 bus_space_handle_t,
136 bus_size_t, /*offset*/
137 size_t, /*probe size*/
138 void *); /*result ptr*/
139
140 int (*sun68k_bus_poke)(
141 bus_space_tag_t,
142 bus_space_handle_t,
143 bus_size_t, /*offset*/
144 size_t, /*probe size*/
145 uint32_t); /*value*/
146 };
147
148 #if 0
149 /*
150 * The following macro could be used to generate the bus_space*() functions
151 * but it uses a gcc extension and is ANSI-only.
152 #define PROTO_bus_space_xxx (bus_space_tag_t t, ...)
153 #define RETURNTYPE_bus_space_xxx void *
154 #define BUSFUN(name, returntype, t, args...) \
155 __inline RETURNTYPE_##name \
156 bus_##name PROTO_##name \
157 { \
158 while (t->sun68k_##name == NULL) \
159 t = t->parent; \
160 return (*(t)->sun68k_##name)(t, args); \
161 }
162 */
163 #endif
164
165 /*
166 * Bus space function prototypes.
167 */
168 static int bus_space_map(
169 bus_space_tag_t,
170 bus_addr_t,
171 bus_size_t,
172 int, /*flags*/
173 bus_space_handle_t *);
174 static int bus_space_map2(
175 bus_space_tag_t,
176 bus_type_t,
177 bus_addr_t,
178 bus_size_t,
179 int, /*flags*/
180 vaddr_t, /*preferred vaddr*/
181 bus_space_handle_t *);
182 static int bus_space_unmap(
183 bus_space_tag_t,
184 bus_space_handle_t,
185 bus_size_t);
186 static int bus_space_subregion(
187 bus_space_tag_t,
188 bus_space_handle_t,
189 bus_size_t,
190 bus_size_t,
191 bus_space_handle_t *);
192 static void bus_space_barrier(
193 bus_space_tag_t,
194 bus_space_handle_t,
195 bus_size_t,
196 bus_size_t,
197 int);
198 static paddr_t bus_space_mmap(
199 bus_space_tag_t,
200 bus_addr_t, /**/
201 off_t, /*offset*/
202 int, /*prot*/
203 int); /*flags*/
204 static paddr_t bus_space_mmap2(
205 bus_space_tag_t,
206 bus_type_t,
207 bus_addr_t, /**/
208 off_t, /*offset*/
209 int, /*prot*/
210 int); /*flags*/
211 static void *bus_intr_establish(
212 bus_space_tag_t,
213 int, /*bus-specific intr*/
214 int, /*device class level,
215 see machine/intr.h*/
216 int, /*flags*/
217 int (*)(void *), /*handler*/
218 void *); /*handler arg*/
219 static int _bus_space_peek(
220 bus_space_tag_t,
221 bus_space_handle_t,
222 bus_size_t, /*offset*/
223 size_t, /*probe size*/
224 void *); /*result ptr*/
225 static int _bus_space_poke(
226 bus_space_tag_t,
227 bus_space_handle_t,
228 bus_size_t, /*offset*/
229 size_t, /*probe size*/
230 uint32_t); /*value*/
231
232 /* This macro finds the first "upstream" implementation of method `f' */
233 #define _BS_CALL(t,f) \
234 while (t->f == NULL) \
235 t = t->parent; \
236 return (*(t)->f)
237
238 __inline int
239 bus_space_map(bus_space_tag_t t, bus_addr_t a, bus_size_t s, int f,
240 bus_space_handle_t *hp)
241 {
242 _BS_CALL(t, sun68k_bus_map)((t), 0, (a), (s), (f), 0, (hp));
243 }
244
245 __inline int
246 bus_space_map2(bus_space_tag_t t, bus_type_t bt, bus_addr_t a, bus_size_t s,
247 int f, vaddr_t v, bus_space_handle_t *hp)
248 {
249 _BS_CALL(t, sun68k_bus_map)(t, bt, a, s, f, v, hp);
250 }
251
252 __inline int
253 bus_space_unmap(bus_space_tag_t t, bus_space_handle_t h, bus_size_t s)
254 {
255 _BS_CALL(t, sun68k_bus_unmap)(t, h, s);
256 }
257
258 __inline int
259 bus_space_subregion(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
260 bus_size_t s, bus_space_handle_t *hp)
261 {
262 _BS_CALL(t, sun68k_bus_subregion)(t, h, o, s, hp);
263 }
264
265 __inline paddr_t
266 bus_space_mmap(bus_space_tag_t t, bus_addr_t a, off_t o, int p, int f)
267 {
268 _BS_CALL(t, sun68k_bus_mmap)(t, 0, a, o, p, f);
269 }
270
271 __inline paddr_t
272 bus_space_mmap2(bus_space_tag_t t, bus_type_t bt, bus_addr_t a, off_t o, int p,
273 int f)
274 {
275 _BS_CALL(t, sun68k_bus_mmap)(t, bt, a, o, p, f);
276 }
277
278 __inline void *
279 bus_intr_establish(bus_space_tag_t t, int p, int l, int f, int (*h)(void *),
280 void *a)
281 {
282 _BS_CALL(t, sun68k_intr_establish)(t, p, l, f, h, a);
283 }
284
285 __inline void
286 bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
287 bus_size_t s, int f)
288 {
289 _BS_CALL(t, sun68k_bus_barrier)(t, h, o, s, f);
290 }
291
292 __inline int
293 _bus_space_peek(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, size_t s,
294 void *vp)
295 {
296 _BS_CALL(t, sun68k_bus_peek)(t, h, o, s, vp);
297 }
298
299 __inline int
300 _bus_space_poke(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, size_t s,
301 uint32_t v)
302 {
303 _BS_CALL(t, sun68k_bus_poke)(t, h, o, s, v);
304 }
305
306 #if 0
307 int bus_space_alloc(bus_space_tag_t, bus_addr_t, bus_addr_t, bus_size_t,
308 bus_size_t, bus_size_t, int, bus_addr_t *, bus_space_handle_t *);
309 void bus_space_free(bus_space_tag_t, bus_space_handle_t, bus_size_t);
310 #endif
311
312 /*
313 * void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t);
314 *
315 * Get the kernel virtual address for the mapped bus space.
316 * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
317 * (XXX not enforced)
318 */
319 #define bus_space_vaddr(t, h) ((void)(t), (void *)(h))
320
321 /* flags for bus space map functions */
322 #define BUS_SPACE_MAP_CACHEABLE 0x0001
323 #define BUS_SPACE_MAP_LINEAR 0x0002
324 #define BUS_SPACE_MAP_PREFETCHABLE 0x0004
325 #define BUS_SPACE_MAP_BUS1 0x0100 /* placeholders for bus functions... */
326 #define BUS_SPACE_MAP_BUS2 0x0200
327 #define BUS_SPACE_MAP_BUS3 0x0400
328 #define BUS_SPACE_MAP_BUS4 0x0800
329
330 /* Internal flag: try to find and use a PROM maping for the device. */
331 #define _SUN68K_BUS_MAP_USE_PROM BUS_SPACE_MAP_BUS1
332
333 /* flags for intr_establish() */
334 #define BUS_INTR_ESTABLISH_FASTTRAP 1
335 #define BUS_INTR_ESTABLISH_SOFTINTR 2
336
337 /* flags for bus_space_barrier() */
338 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
339 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
340
341 /*
342 * int bus_space_peek_N(bus_space_tag_t tag,
343 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t *valuep);
344 *
345 * Cautiously read 1, 2, 4 or 8 byte quantity from bus space described
346 * by tag/handle/offset.
347 * If no hardware responds to the read access, the function returns a
348 * non-zero value. Otherwise the value read is placed in `valuep'.
349 */
350
351 #define bus_space_peek_1(t, h, o, vp) \
352 _bus_space_peek(t, h, o, sizeof(uint8_t), (void *)vp)
353
354 #define bus_space_peek_2(t, h, o, vp) \
355 _bus_space_peek(t, h, o, sizeof(uint16_t), (void *)vp)
356
357 #define bus_space_peek_4(t, h, o, vp) \
358 _bus_space_peek(t, h, o, sizeof(uint32_t), (void *)vp)
359
360 /*
361 * int bus_space_poke_N(bus_space_tag_t tag,
362 * bus_space_handle_t bsh, bus_size_t offset, uintN_t value);
363 *
364 * Cautiously write 1, 2, 4 or 8 byte quantity to bus space described
365 * by tag/handle/offset.
366 * If no hardware responds to the write access, the function returns a
367 * non-zero value.
368 */
369
370 #define bus_space_poke_1(t, h, o, v) \
371 _bus_space_poke(t, h, o, sizeof(uint8_t), v)
372
373 #define bus_space_poke_2(t, h, o, v) \
374 _bus_space_poke(t, h, o, sizeof(uint16_t), v)
375
376 #define bus_space_poke_4(t, h, o, v) \
377 _bus_space_poke(t, h, o, sizeof(uint32_t), v)
378
379 /*
380 * uintN_t bus_space_read_N(bus_space_tag_t tag,
381 * bus_space_handle_t bsh, bus_size_t offset);
382 *
383 * Read a 1, 2, 4, or 8 byte quantity from bus space
384 * described by tag/handle/offset.
385 */
386
387 #define bus_space_read_1(t, h, o) \
388 ((void)t, *(volatile uint8_t *)((h) + (o)))
389
390 #define bus_space_read_2(t, h, o) \
391 ((void)t, *(volatile uint16_t *)((h) + (o)))
392
393 #define bus_space_read_4(t, h, o) \
394 ((void)t, *(volatile uint32_t *)((h) + (o)))
395
396 #define bus_space_read_8(t, h, o) \
397 ((void)t, *(volatile uint64_t *)((h) + (o)))
398
399
400 /*
401 * void bus_space_write_N(bus_space_tag_t tag,
402 * bus_space_handle_t bsh, bus_size_t offset,
403 * uintN_t value);
404 *
405 * Write the 1, 2, 4, or 8 byte value `value' to bus space
406 * described by tag/handle/offset.
407 */
408
409 #define bus_space_write_1(t, h, o, v) do { \
410 ((void)t, (void)(*(volatile uint8_t *)((h) + (o)) = (v))); \
411 } while (0)
412
413 #define bus_space_write_2(t, h, o, v) do { \
414 ((void)t, (void)(*(volatile uint16_t *)((h) + (o)) = (v))); \
415 } while (0)
416
417 #define bus_space_write_4(t, h, o, v) do { \
418 ((void)t, (void)(*(volatile uint32_t *)((h) + (o)) = (v))); \
419 } while (0)
420
421 #define bus_space_write_8(t, h, o, v) do { \
422 ((void)t, (void)(*(volatile uint64_t *)((h) + (o)) = (v))); \
423 } while (0)
424
425
426 /*
427 * void bus_space_read_multi_N(bus_space_tag_t tag,
428 * bus_space_handle_t bsh, bus_size_t offset,
429 * uintN_t *addr, bus_size_t count);
430 *
431 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
432 * described by tag/handle/offset and copy into buffer provided.
433 */
434
435 void bus_space_read_multi_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
436 uint8_t *, bus_size_t);
437 void bus_space_read_multi_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
438 uint16_t *, bus_size_t);
439 void bus_space_read_multi_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
440 uint32_t *, bus_size_t);
441 void bus_space_read_multi_8(bus_space_tag_t, bus_space_handle_t, bus_size_t,
442 uint64_t *, bus_size_t);
443
444 extern __inline void
445 bus_space_read_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
446 uint8_t *a, bus_size_t c)
447 {
448 while (c-- > 0)
449 *a++ = bus_space_read_1(t, h, o);
450 }
451
452 extern __inline void
453 bus_space_read_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
454 uint16_t *a, bus_size_t c)
455 {
456 while (c-- > 0)
457 *a++ = bus_space_read_2(t, h, o);
458 }
459
460 extern __inline void
461 bus_space_read_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
462 uint32_t *a, bus_size_t c)
463 {
464 while (c-- > 0)
465 *a++ = bus_space_read_4(t, h, o);
466 }
467
468 extern __inline void
469 bus_space_read_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
470 uint64_t *a, bus_size_t c)
471 {
472 while (c-- > 0)
473 *a++ = bus_space_read_8(t, h, o);
474 }
475
476
477 /*
478 * void bus_space_write_multi_N(bus_space_tag_t tag,
479 * bus_space_handle_t bsh, bus_size_t offset,
480 * const u_intN_t *addr, bus_size_t count);
481 *
482 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
483 * provided to bus space described by tag/handle/offset.
484 */
485 void bus_space_write_multi_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
486 const uint8_t *, bus_size_t);
487 void bus_space_write_multi_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
488 const uint16_t *, bus_size_t);
489 void bus_space_write_multi_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
490 const uint32_t *, bus_size_t);
491 void bus_space_write_multi_8(bus_space_tag_t, bus_space_handle_t, bus_size_t,
492 const uint64_t *, bus_size_t);
493
494 extern __inline void
495 bus_space_write_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
496 const uint8_t *a, bus_size_t c)
497 {
498 while (c-- > 0)
499 bus_space_write_1(t, h, o, *a++);
500 }
501
502 extern __inline void
503 bus_space_write_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
504 const uint16_t *a, bus_size_t c)
505 {
506 while (c-- > 0)
507 bus_space_write_2(t, h, o, *a++);
508 }
509
510 extern __inline void
511 bus_space_write_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
512 const uint32_t *a, bus_size_t c)
513 {
514 while (c-- > 0)
515 bus_space_write_4(t, h, o, *a++);
516 }
517
518 extern __inline void
519 bus_space_write_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
520 const uint64_t *a, bus_size_t c)
521 {
522 while (c-- > 0)
523 bus_space_write_8(t, h, o, *a++);
524 }
525
526 /*
527 * void bus_space_set_multi_N(bus_space_tag_t tag,
528 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
529 * bus_size_t count);
530 *
531 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
532 * by tag/handle/offset `count' times.
533 */
534 void bus_space_set_multi_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
535 const uint8_t, bus_size_t);
536 void bus_space_set_multi_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
537 const uint16_t, bus_size_t);
538 void bus_space_set_multi_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
539 const uint32_t, bus_size_t);
540 void bus_space_set_multi_8(bus_space_tag_t, bus_space_handle_t, bus_size_t,
541 const uint64_t, bus_size_t);
542
543 extern __inline void
544 bus_space_set_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
545 const uint8_t v, bus_size_t c)
546 {
547 while (c-- > 0)
548 bus_space_write_1(t, h, o, v);
549 }
550
551 extern __inline void
552 bus_space_set_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
553 const uint16_t v, bus_size_t c)
554 {
555 while (c-- > 0)
556 bus_space_write_2(t, h, o, v);
557 }
558
559 extern __inline void
560 bus_space_set_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
561 const uint32_t v, bus_size_t c)
562 {
563 while (c-- > 0)
564 bus_space_write_4(t, h, o, v);
565 }
566
567 extern __inline void
568 bus_space_set_multi_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
569 const uint64_t v, bus_size_t c)
570 {
571 while (c-- > 0)
572 bus_space_write_8(t, h, o, v);
573 }
574
575
576 /*
577 * void bus_space_read_region_N(bus_space_tag_t tag,
578 * bus_space_handle_t bsh, bus_size_t off,
579 * uintN_t *addr, bus_size_t count);
580 *
581 */
582 void bus_space_read_region_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
583 uint8_t *, bus_size_t);
584 void bus_space_read_region_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
585 uint16_t *, bus_size_t);
586 void bus_space_read_region_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
587 uint32_t *, bus_size_t);
588 void bus_space_read_region_8(bus_space_tag_t, bus_space_handle_t, bus_size_t,
589 uint64_t *, bus_size_t);
590
591 extern __inline void
592 bus_space_read_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
593 uint8_t *a, bus_size_t c)
594 {
595 for (; c; a++, c--, o++)
596 *a = bus_space_read_1(t, h, o);
597 }
598 extern __inline void
599 bus_space_read_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
600 uint16_t *a, bus_size_t c)
601 {
602 for (; c; a++, c--, o += 2)
603 *a = bus_space_read_2(t, h, o);
604 }
605 extern __inline void
606 bus_space_read_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
607 uint32_t *a, bus_size_t c)
608 {
609 for (; c; a++, c--, o += 4)
610 *a = bus_space_read_4(t, h, o);
611 }
612 extern __inline void
613 bus_space_read_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
614 uint64_t *a, bus_size_t c)
615 {
616 for (; c; a++, c--, o += 8)
617 *a = bus_space_read_8(t, h, o);
618 }
619
620 /*
621 * void bus_space_write_region_N(bus_space_tag_t tag,
622 * bus_space_handle_t bsh, bus_size_t off,
623 * uintN_t *addr, bus_size_t count);
624 *
625 */
626 void bus_space_write_region_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
627 const uint8_t *, bus_size_t);
628 void bus_space_write_region_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
629 const uint16_t *, bus_size_t);
630 void bus_space_write_region_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
631 const uint32_t *, bus_size_t);
632 void bus_space_write_region_8(bus_space_tag_t, bus_space_handle_t, bus_size_t,
633 const uint64_t *, bus_size_t);
634
635 extern __inline void
636 bus_space_write_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
637 const uint8_t *a, bus_size_t c)
638 {
639 for (; c; a++, c--, o++)
640 bus_space_write_1(t, h, o, *a);
641 }
642
643 extern __inline void
644 bus_space_write_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
645 const uint16_t *a, bus_size_t c)
646 {
647 for (; c; a++, c--, o += 2)
648 bus_space_write_2(t, h, o, *a);
649 }
650
651 extern __inline void
652 bus_space_write_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
653 const uint32_t *a, bus_size_t c)
654 {
655 for (; c; a++, c--, o += 4)
656 bus_space_write_4(t, h, o, *a);
657 }
658
659 extern __inline void
660 bus_space_write_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
661 const uint64_t *a, bus_size_t c)
662 {
663 for (; c; a++, c--, o += 8)
664 bus_space_write_8(t, h, o, *a);
665 }
666
667
668 /*
669 * void bus_space_set_region_N(bus_space_tag_t tag,
670 * bus_space_handle_t bsh, bus_size_t off,
671 * uintN_t *addr, bus_size_t count);
672 *
673 */
674 void bus_space_set_region_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
675 const uint8_t, bus_size_t);
676 void bus_space_set_region_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
677 const uint16_t, bus_size_t);
678 void bus_space_set_region_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
679 const uint32_t, bus_size_t);
680 void bus_space_set_region_8(bus_space_tag_t, bus_space_handle_t, bus_size_t,
681 const uint64_t, bus_size_t);
682
683 extern __inline void
684 bus_space_set_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
685 const uint8_t v, bus_size_t c)
686 {
687 for (; c; c--, o++)
688 bus_space_write_1(t, h, o, v);
689 }
690
691 extern __inline void
692 bus_space_set_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
693 const uint16_t v, bus_size_t c)
694 {
695 for (; c; c--, o += 2)
696 bus_space_write_2(t, h, o, v);
697 }
698
699 extern __inline void
700 bus_space_set_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
701 const uint32_t v, bus_size_t c)
702 {
703 for (; c; c--, o += 4)
704 bus_space_write_4(t, h, o, v);
705 }
706
707 extern __inline void
708 bus_space_set_region_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
709 const uint64_t v, bus_size_t c)
710 {
711 for (; c; c--, o += 8)
712 bus_space_write_8(t, h, o, v);
713 }
714
715
716 /*
717 * void bus_space_copy_region_N(bus_space_tag_t tag,
718 * bus_space_handle_t bsh1, bus_size_t off1,
719 * bus_space_handle_t bsh2, bus_size_t off2,
720 * bus_size_t count);
721 *
722 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
723 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
724 */
725 void bus_space_copy_region_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
726 bus_space_handle_t, bus_size_t, bus_size_t);
727 void bus_space_copy_region_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
728 bus_space_handle_t, bus_size_t, bus_size_t);
729 void bus_space_copy_region_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
730 bus_space_handle_t, bus_size_t, bus_size_t);
731 void bus_space_copy_region_8(bus_space_tag_t, bus_space_handle_t, bus_size_t,
732 bus_space_handle_t, bus_size_t, bus_size_t);
733
734 extern __inline void
735 bus_space_copy_region_1(bus_space_tag_t t, bus_space_handle_t h1, bus_size_t o1,
736 bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
737 {
738 for (; c; c--, o1++, o2++)
739 bus_space_write_1(t, h1, o1, bus_space_read_1(t, h2, o2));
740 }
741
742 extern __inline void
743 bus_space_copy_region_2(bus_space_tag_t t, bus_space_handle_t h1, bus_size_t o1,
744 bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
745 {
746 for (; c; c--, o1 += 2, o2 += 2)
747 bus_space_write_2(t, h1, o1, bus_space_read_2(t, h2, o2));
748 }
749
750 extern __inline void
751 bus_space_copy_region_4(bus_space_tag_t t, bus_space_handle_t h1, bus_size_t o1,
752 bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
753 {
754 for (; c; c--, o1 += 4, o2 += 4)
755 bus_space_write_4(t, h1, o1, bus_space_read_4(t, h2, o2));
756 }
757
758 extern __inline void
759 bus_space_copy_region_8(bus_space_tag_t t, bus_space_handle_t h1, bus_size_t o1,
760 bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
761 {
762 for (; c; c--, o1 += 8, o2 += 8)
763 bus_space_write_8(t, h1, o1, bus_space_read_8(t, h2, o2));
764 }
765
766 /*
767 * void bus_space_copyin(bus_space_tag_t tag,
768 * bus_space_handle_t bsh, bus_size_t off,
769 * void *addr, bus_size_t count);
770 *
771 * Copy `count' bytes from bus space starting at tag/bsh/off
772 * to kernel memory at addr using the most optimized transfer
773 * possible for the bus.
774 */
775
776 #define bus_space_copyin(t, h, o, a, c) \
777 ((void)t, w16copy((uint8_t *)((h) + (o)), (a), (c)))
778
779 /*
780 * void bus_space_copyout(bus_space_tag_t tag,
781 * bus_space_handle_t bsh, bus_size_t off,
782 * const void *addr, bus_size_t count);
783 *
784 * Copy `count' bytes to bus space starting at tag/bsh/off
785 * from kernel memory at addr using the most optimized transfer
786 * possible for the bus.
787 */
788
789 #define bus_space_copyout(t, h, o, a, c) \
790 ((void)t, w16copy((a), (uint8_t *)((h) + (o)), (c)))
791
792 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
793
794 int find_prom_map(paddr_t, bus_type_t, int, vaddr_t *);
795
796 /*--------------------------------*/
797
798 /*
799 * Flags used in various bus DMA methods.
800 */
801 #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
802 #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
803 #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
804 #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
805 #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
806 #define BUS_DMA_BUS2 0x020
807 #define BUS_DMA_BUS3 0x040
808 #define BUS_DMA_BUS4 0x080
809 #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
810 #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
811 #define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */
812
813 /* For devices that have a 24-bit address space */
814 #define BUS_DMA_24BIT BUS_DMA_BUS1
815
816 /* Internal flag: current DVMA address is equal to the KVA buffer address */
817 #define _BUS_DMA_DIRECTMAP BUS_DMA_BUS2
818
819 /*
820 * Internal flag: current DVMA address has been double-mapped by hand
821 * to the KVA buffer address (without the pmap's help).
822 */
823 #define _BUS_DMA_NOPMAP BUS_DMA_BUS3
824
825 /* Forwards needed by prototypes below. */
826 struct mbuf;
827 struct uio;
828
829 /*
830 * Operations performed by bus_dmamap_sync().
831 */
832 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
833 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
834 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
835 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
836
837 typedef struct sun68k_bus_dma_tag *bus_dma_tag_t;
838 typedef struct sun68k_bus_dmamap *bus_dmamap_t;
839
840 #define BUS_DMA_TAG_VALID(t) ((t) != NULL)
841
842 /*
843 * bus_dma_segment_t
844 *
845 * Describes a single contiguous DMA transaction. Values
846 * are suitable for programming into DMA registers.
847 */
848 struct sun68k_bus_dma_segment {
849 bus_addr_t ds_addr; /* DVMA address */
850 bus_size_t ds_len; /* length of transfer */
851 bus_size_t _ds_sgsize; /* size of allocated DVMA segment */
852 void *_ds_mlist; /* page list when dmamem_alloc'ed */
853 vaddr_t _ds_va; /* VA when dmamem_map'ed */
854 };
855 typedef struct sun68k_bus_dma_segment bus_dma_segment_t;
856
857
858 /*
859 * bus_dma_tag_t
860 *
861 * A machine-dependent opaque type describing the implementation of
862 * DMA for a given bus.
863 */
864 struct sun68k_bus_dma_tag {
865 void *_cookie; /* cookie used in the guts */
866
867 /*
868 * DMA mapping methods.
869 */
870 int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int, bus_size_t,
871 bus_size_t, int, bus_dmamap_t *);
872 void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
873 int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t,
874 struct proc *, int);
875 int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t, struct mbuf *,
876 int);
877 int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t, struct uio *,
878 int);
879 int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
880 bus_dma_segment_t *, int, bus_size_t, int);
881 void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
882 void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
883 bus_size_t, int);
884
885 /*
886 * DMA memory utility functions.
887 */
888 int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
889 bus_size_t, bus_dma_segment_t *, int, int *, int);
890 void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int);
891 int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, int, size_t,
892 void **, int);
893 void (*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
894 paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, int, off_t,
895 int, int);
896 };
897
898 #define bus_dmamap_create(t, s, n, m, b, f, p) \
899 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
900 #define bus_dmamap_destroy(t, p) \
901 (*(t)->_dmamap_destroy)((t), (p))
902 #define bus_dmamap_load(t, m, b, s, p, f) \
903 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
904 #define bus_dmamap_load_mbuf(t, m, b, f) \
905 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
906 #define bus_dmamap_load_uio(t, m, u, f) \
907 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
908 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
909 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
910 #define bus_dmamap_unload(t, p) \
911 (*(t)->_dmamap_unload)((t), (p))
912 #define bus_dmamap_sync(t, p, o, l, ops) \
913 (void)((t)->_dmamap_sync ? \
914 (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) : (void)0)
915
916 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
917 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
918 #define bus_dmamem_free(t, sg, n) \
919 (*(t)->_dmamem_free)((t), (sg), (n))
920 #define bus_dmamem_map(t, sg, n, s, k, f) \
921 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
922 #define bus_dmamem_unmap(t, k, s) \
923 (*(t)->_dmamem_unmap)((t), (k), (s))
924 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
925 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
926
927 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
928 #define bus_dmatag_destroy(t)
929
930 /*
931 * bus_dmamap_t
932 *
933 * Describes a DMA mapping.
934 */
935 struct sun68k_bus_dmamap {
936 /*
937 * PRIVATE MEMBERS: not for use by machine-independent code.
938 */
939 bus_size_t _dm_size; /* largest DMA transfer mappable */
940 int _dm_segcnt; /* number of segs this map can map */
941 bus_size_t _dm_maxmaxsegsz; /* fixed largest possible segment */
942 bus_size_t _dm_boundary; /* don't cross this */
943 int _dm_flags; /* misc. flags */
944
945 void *_dm_cookie; /* cookie for bus-specific functions */
946
947 u_long _dm_align; /* DVMA alignment; must be a
948 multiple of the page size */
949 u_long _dm_ex_start; /* constraints on DVMA map */
950 u_long _dm_ex_end; /* allocations; used by the VME bus
951 driver and by the IOMMU driver
952 when mapping 24-bit devices */
953
954 /*
955 * PUBLIC MEMBERS: these are used by machine-independent code.
956 */
957 bus_size_t dm_maxsegsz; /* largest possible segment */
958 bus_size_t dm_mapsize; /* size of the mapping */
959 int dm_nsegs; /* # valid segments in mapping */
960 bus_dma_segment_t dm_segs[1]; /* segments; variable length */
961 };
962
963 #ifdef _SUN68K_BUS_DMA_PRIVATE
964 int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
965 bus_size_t, int, bus_dmamap_t *);
966 void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
967 int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int);
968 int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int);
969 int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *,
970 int, bus_size_t, int);
971 int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t,
972 struct proc *, int);
973 void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
974 void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, bus_size_t,
975 int);
976
977 int _bus_dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t,
978 bus_dma_segment_t *, int, int *, int);
979 void _bus_dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int);
980 int _bus_dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, int, size_t,
981 void **, int);
982 void _bus_dmamem_unmap(bus_dma_tag_t, void *, size_t);
983 paddr_t _bus_dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int, off_t, int,
984 int);
985
986 int _bus_dmamem_alloc_range(bus_dma_tag_t, bus_size_t, bus_size_t,
987 bus_size_t, bus_dma_segment_t *, int, int *, int, vaddr_t, vaddr_t);
988
989 vaddr_t _bus_dma_valloc_skewed(size_t, u_long, u_long, u_long);
990 #endif /* _SUN68K_BUS_DMA_PRIVATE */
991
992 #endif /* _SUN68K_BUS_H_ */
993