bus.h revision 1.8 1 /* $NetBSD: bus.h,v 1.8 2000/08/09 02:12:50 shin Exp $ */
2
3 /*-
4 * Copyright (c) 1996, 1997, 1998 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 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 #ifndef _HPCMIPS_BUS_H_
41 #define _HPCMIPS_BUS_H_
42
43 #include <mips/locore.h>
44
45 #ifdef BUS_SPACE_DEBUG
46 #include <sys/systm.h> /* for printf() prototype */
47 /*
48 * Macros for sanity-checking the aligned-ness of pointers passed to
49 * bus space ops. These are not strictly necessary on the x86, but
50 * could lead to performance improvements, and help catch problems
51 * with drivers that would creep up on other architectures.
52 */
53 #define __BUS_SPACE_ALIGNED_ADDRESS(p, t) \
54 ((((u_long)(p)) & (sizeof(t)-1)) == 0)
55
56 #define __BUS_SPACE_ADDRESS_SANITY(p, t, d) \
57 ({ \
58 if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) { \
59 printf("%s 0x%lx not aligned to %d bytes %s:%d\n", \
60 d, (u_long)(p), sizeof(t), __FILE__, __LINE__); \
61 } \
62 (void) 0; \
63 })
64
65 #define BUS_SPACE_ALIGNED_POINTER(p, t) __BUS_SPACE_ALIGNED_ADDRESS(p, t)
66 #else
67 #define __BUS_SPACE_ADDRESS_SANITY(p,t,d) (void) 0
68 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
69 #endif /* BUS_SPACE_DEBUG */
70 /*
71 * Utility macros; do not use outside this file.
72 */
73 #define __PB_TYPENAME_PREFIX(BITS) ___CONCAT(u_int,BITS)
74 #define __PB_TYPENAME(BITS) ___CONCAT(__PB_TYPENAME_PREFIX(BITS),_t)
75
76 /*
77 * Bus address and size types
78 */
79
80 typedef u_long bus_addr_t;
81 typedef u_long bus_size_t;
82
83 /*
84 * Access methods for bus resources and address space.
85 */
86 typedef struct hpcmips_bus_space *bus_space_tag_t;
87 typedef u_int32_t bus_space_handle_t;
88 /*
89 * Initialize extent.
90 */
91 void hpcmips_init_bus_space_extent __P((bus_space_tag_t));
92 bus_space_tag_t hpcmips_alloc_bus_space_tag __P((void));
93
94 struct hpcmips_bus_space {
95 char t_name[16]; /* bus name */
96 u_int32_t t_base; /* extent base */
97 u_int32_t t_size; /* extent size */
98 void *t_extent;
99 };
100
101
102 /*
103 * int bus_space_map __P((bus_space_tag_t t, bus_addr_t addr,
104 * bus_size_t size, int flags, bus_space_handle_t *bshp));
105 *
106 * Map a region of bus space.
107 */
108
109 #define BUS_SPACE_MAP_CACHEABLE 0x01
110 #define BUS_SPACE_MAP_LINEAR 0x02
111 #define BUS_SPACE_MAP_PREFETCHABLE 0x04
112
113 int bus_space_map __P((bus_space_tag_t, bus_addr_t, bus_size_t,
114 int, bus_space_handle_t *));
115
116 /*
117 * void bus_space_unmap __P((bus_space_tag_t t,
118 * bus_space_handle_t bsh, bus_size_t size));
119 *
120 * Unmap a region of bus space.
121 */
122
123 void bus_space_unmap __P((bus_space_tag_t, bus_space_handle_t, bus_size_t));
124
125 /*
126 * int bus_space_subregion __P((bus_space_tag_t t,
127 * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
128 * bus_space_handle_t *nbshp));
129 *
130 * Get a new handle for a subregion of an already-mapped area of bus space.
131 */
132
133 int bus_space_subregion __P((bus_space_tag_t t, bus_space_handle_t bsh,
134 bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp));
135
136 /*
137 * int bus_space_alloc __P((bus_space_tag_t t, bus_addr_t, rstart,
138 * bus_addr_t rend, bus_size_t size, bus_size_t align,
139 * bus_size_t boundary, int flags, bus_addr_t *addrp,
140 * bus_space_handle_t *bshp));
141 *
142 * Allocate a region of bus space.
143 */
144
145 int bus_space_alloc __P((bus_space_tag_t t, bus_addr_t rstart,
146 bus_addr_t rend, bus_size_t size, bus_size_t align,
147 bus_size_t boundary, int cacheable, bus_addr_t *addrp,
148 bus_space_handle_t *bshp));
149
150 /*
151 * int bus_space_free __P((bus_space_tag_t t,
152 * bus_space_handle_t bsh, bus_size_t size));
153 *
154 * Free a region of bus space.
155 */
156
157 void bus_space_free __P((bus_space_tag_t t, bus_space_handle_t bsh,
158 bus_size_t size));
159
160 /*
161 * u_intN_t bus_space_read_N __P((bus_space_tag_t tag,
162 * bus_space_handle_t bsh, bus_size_t offset));
163 *
164 * Read a 1, 2, 4, or 8 byte quantity from bus space
165 * described by tag/handle/offset.
166 */
167
168 #define bus_space_read_1(t, h, o) \
169 (wbflush(), /* XXX */ \
170 (void) t, (*(volatile u_int8_t *)((h) + (o))))
171
172 #define bus_space_read_2(t, h, o) \
173 (wbflush(), /* XXX */ \
174 (void) t, (*(volatile u_int16_t *)((h) + (o))))
175
176 #define bus_space_read_4(t, h, o) \
177 (wbflush(), /* XXX */ \
178 (void) t, (*(volatile u_int32_t *)((h) + (o))))
179
180 #if 0 /* Cause a link error for bus_space_read_8 */
181 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
182 #endif
183
184 /*
185 * void bus_space_read_multi_N __P((bus_space_tag_t tag,
186 * bus_space_handle_t bsh, bus_size_t offset,
187 * u_intN_t *addr, size_t count));
188 *
189 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
190 * described by tag/handle/offset and copy into buffer provided.
191 */
192
193 #define __HPCMIPS_bus_space_read_multi(BYTES,BITS) \
194 static __inline void __CONCAT(bus_space_read_multi_,BYTES) \
195 __P((bus_space_tag_t, bus_space_handle_t, bus_size_t, \
196 __PB_TYPENAME(BITS) *, size_t)); \
197 \
198 static __inline void \
199 __CONCAT(bus_space_read_multi_,BYTES)(t, h, o, a, c) \
200 bus_space_tag_t t; \
201 bus_space_handle_t h; \
202 bus_size_t o; \
203 __PB_TYPENAME(BITS) *a; \
204 size_t c; \
205 { \
206 \
207 while (c--) \
208 *a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o); \
209 }
210
211 __HPCMIPS_bus_space_read_multi(1,8)
212 __HPCMIPS_bus_space_read_multi(2,16)
213 __HPCMIPS_bus_space_read_multi(4,32)
214
215 #if 0 /* Cause a link error for bus_space_read_multi_8 */
216 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
217 #endif
218
219 #undef __HPCMIPS_bus_space_read_multi
220
221 /*
222 * void bus_space_read_region_N __P((bus_space_tag_t tag,
223 * bus_space_handle_t bsh, bus_size_t offset,
224 * u_intN_t *addr, size_t count));
225 *
226 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
227 * described by tag/handle and starting at `offset' and copy into
228 * buffer provided.
229 */
230
231 #define __HPCMIPS_bus_space_read_region(BYTES,BITS) \
232 static __inline void __CONCAT(bus_space_read_region_,BYTES) \
233 __P((bus_space_tag_t, bus_space_handle_t, bus_size_t, \
234 __PB_TYPENAME(BITS) *, size_t)); \
235 \
236 static __inline void \
237 __CONCAT(bus_space_read_region_,BYTES)(t, h, o, a, c) \
238 bus_space_tag_t t; \
239 bus_space_handle_t h; \
240 bus_size_t o; \
241 __PB_TYPENAME(BITS) *a; \
242 size_t c; \
243 { \
244 \
245 while (c--) { \
246 *a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o); \
247 o += BYTES; \
248 } \
249 }
250
251 __HPCMIPS_bus_space_read_region(1,8)
252 __HPCMIPS_bus_space_read_region(2,16)
253 __HPCMIPS_bus_space_read_region(4,32)
254
255 #if 0 /* Cause a link error for bus_space_read_region_8 */
256 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
257 #endif
258
259 #undef __HPCMIPS_bus_space_read_region
260
261 /*
262 * void bus_space_write_N __P((bus_space_tag_t tag,
263 * bus_space_handle_t bsh, bus_size_t offset,
264 * u_intN_t value));
265 *
266 * Write the 1, 2, 4, or 8 byte value `value' to bus space
267 * described by tag/handle/offset.
268 */
269
270 #define bus_space_write_1(t, h, o, v) \
271 do { \
272 (void) t; \
273 *(volatile u_int8_t *)((h) + (o)) = (v); \
274 wbflush(); /* XXX */ \
275 } while (0)
276
277 #define bus_space_write_2(t, h, o, v) \
278 do { \
279 (void) t; \
280 *(volatile u_int16_t *)((h) + (o)) = (v); \
281 wbflush(); /* XXX */ \
282 } while (0)
283
284 #define bus_space_write_4(t, h, o, v) \
285 do { \
286 (void) t; \
287 *(volatile u_int32_t *)((h) + (o)) = (v); \
288 wbflush(); /* XXX */ \
289 } while (0)
290
291 #if 0 /* Cause a link error for bus_space_write_8 */
292 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
293 #endif
294
295 /*
296 * void bus_space_write_multi_N __P((bus_space_tag_t tag,
297 * bus_space_handle_t bsh, bus_size_t offset,
298 * const u_intN_t *addr, size_t count));
299 *
300 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
301 * provided to bus space described by tag/handle/offset.
302 */
303
304 #define __HPCMIPS_bus_space_write_multi(BYTES,BITS) \
305 static __inline void __CONCAT(bus_space_write_multi_,BYTES) \
306 __P((bus_space_tag_t, bus_space_handle_t, bus_size_t, \
307 __PB_TYPENAME(BITS) *, size_t)); \
308 \
309 static __inline void \
310 __CONCAT(bus_space_write_multi_,BYTES)(t, h, o, a, c) \
311 bus_space_tag_t t; \
312 bus_space_handle_t h; \
313 bus_size_t o; \
314 __PB_TYPENAME(BITS) *a; \
315 size_t c; \
316 { \
317 \
318 while (c--) \
319 __CONCAT(bus_space_write_,BYTES)(t, h, o, *a++); \
320 }
321
322 __HPCMIPS_bus_space_write_multi(1,8)
323 __HPCMIPS_bus_space_write_multi(2,16)
324 __HPCMIPS_bus_space_write_multi(4,32)
325
326 #if 0 /* Cause a link error for bus_space_write_8 */
327 #define bus_space_write_multi_8(t, h, o, a, c) \
328 !!! bus_space_write_multi_8 unimplimented !!!
329 #endif
330
331 #undef __HPCMIPS_bus_space_write_multi
332
333 /*
334 * void bus_space_write_region_N __P((bus_space_tag_t tag,
335 * bus_space_handle_t bsh, bus_size_t offset,
336 * const u_intN_t *addr, size_t count));
337 *
338 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
339 * to bus space described by tag/handle starting at `offset'.
340 */
341
342 #define __HPCMIPS_bus_space_write_region(BYTES,BITS) \
343 static __inline void __CONCAT(bus_space_write_region_,BYTES) \
344 __P((bus_space_tag_t, bus_space_handle_t, bus_size_t, \
345 __PB_TYPENAME(BITS) *, size_t)); \
346 \
347 static __inline void \
348 __CONCAT(bus_space_write_region_,BYTES)(t, h, o, a, c) \
349 bus_space_tag_t t; \
350 bus_space_handle_t h; \
351 bus_size_t o; \
352 __PB_TYPENAME(BITS) *a; \
353 size_t c; \
354 { \
355 \
356 while (c--) { \
357 __CONCAT(bus_space_write_,BYTES)(t, h, o, *a++); \
358 o += BYTES; \
359 } \
360 }
361
362 __HPCMIPS_bus_space_write_region(1,8)
363 __HPCMIPS_bus_space_write_region(2,16)
364 __HPCMIPS_bus_space_write_region(4,32)
365
366 #if 0 /* Cause a link error for bus_space_write_region_8 */
367 #define bus_space_write_region_8 \
368 !!! bus_space_write_region_8 unimplemented !!!
369 #endif
370
371 #undef __HPCMIPS_bus_space_write_region
372
373 /*
374 * void bus_space_set_multi_N __P((bus_space_tag_t tag,
375 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
376 * size_t count));
377 *
378 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
379 * by tag/handle/offset `count' times.
380 */
381
382 #define __HPCMIPS_bus_space_set_multi(BYTES,BITS) \
383 static __inline void __CONCAT(bus_space_set_multi_,BYTES) \
384 __P((bus_space_tag_t, bus_space_handle_t, bus_size_t, \
385 __PB_TYPENAME(BITS), size_t)); \
386 \
387 static __inline void \
388 __CONCAT(bus_space_set_multi_,BYTES)(t, h, o, v, c) \
389 bus_space_tag_t t; \
390 bus_space_handle_t h; \
391 bus_size_t o; \
392 __PB_TYPENAME(BITS) v; \
393 size_t c; \
394 { \
395 \
396 while (c--) \
397 __CONCAT(bus_space_write_,BYTES)(t, h, o, v); \
398 }
399
400 __HPCMIPS_bus_space_set_multi(1,8)
401 __HPCMIPS_bus_space_set_multi(2,16)
402 __HPCMIPS_bus_space_set_multi(4,32)
403
404 #if 0 /* Cause a link error for bus_space_set_multi_8 */
405 #define bus_space_set_multi_8 \
406 !!! bus_space_set_multi_8 unimplemented !!!
407 #endif
408
409 #undef __HPCMIPS_bus_space_set_multi
410
411 /*
412 * void bus_space_set_region_N __P((bus_space_tag_t tag,
413 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
414 * size_t count));
415 *
416 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
417 * by tag/handle starting at `offset'.
418 */
419
420 #define __HPCMIPS_bus_space_set_region(BYTES,BITS) \
421 static __inline void __CONCAT(bus_space_set_region_,BYTES) \
422 __P((bus_space_tag_t, bus_space_handle_t, bus_size_t, \
423 __PB_TYPENAME(BITS), size_t)); \
424 \
425 static __inline void \
426 __CONCAT(bus_space_set_region_,BYTES)(t, h, o, v, c) \
427 bus_space_tag_t t; \
428 bus_space_handle_t h; \
429 bus_size_t o; \
430 __PB_TYPENAME(BITS) v; \
431 size_t c; \
432 { \
433 \
434 while (c--) { \
435 __CONCAT(bus_space_write_,BYTES)(t, h, o, v); \
436 o += BYTES; \
437 } \
438 }
439
440 __HPCMIPS_bus_space_set_region(1,8)
441 __HPCMIPS_bus_space_set_region(2,16)
442 __HPCMIPS_bus_space_set_region(4,32)
443
444 #if 0 /* Cause a link error for bus_space_set_region_8 */
445 #define bus_space_set_region_8 \
446 !!! bus_space_set_region_8 unimplemented !!!
447 #endif
448
449 #undef __HPCMIPS_bus_space_set_region
450
451 /*
452 * void bus_space_copy_region_N __P((bus_space_tag_t tag,
453 * bus_space_handle_t bsh1, bus_size_t off1,
454 * bus_space_handle_t bsh2, bus_size_t off2,
455 * bus_size_t count));
456 *
457 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
458 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
459 */
460
461 #define __HPCMIPS_copy_region(BYTES) \
462 static __inline void __CONCAT(bus_space_copy_region_,BYTES) \
463 __P((bus_space_tag_t, \
464 bus_space_handle_t bsh1, bus_size_t off1, \
465 bus_space_handle_t bsh2, bus_size_t off2, \
466 bus_size_t count)); \
467 \
468 static __inline void \
469 __CONCAT(bus_space_copy_region_,BYTES)(t, h1, o1, h2, o2, c) \
470 bus_space_tag_t t; \
471 bus_space_handle_t h1, h2; \
472 bus_size_t o1, o2, c; \
473 { \
474 bus_size_t o; \
475 \
476 if ((h1 + o1) >= (h2 + o2)) { \
477 /* src after dest: copy forward */ \
478 for (o = 0; c != 0; c--, o += BYTES) \
479 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
480 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
481 } else { \
482 /* dest after src: copy backwards */ \
483 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
484 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
485 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
486 } \
487 }
488
489 __HPCMIPS_copy_region(1)
490 __HPCMIPS_copy_region(2)
491 __HPCMIPS_copy_region(4)
492
493 #if 0 /* Cause a link error for bus_space_copy_region_8 */
494 #define bus_space_copy_region_8 \
495 !!! bus_space_copy_region_8 unimplemented !!!
496 #endif
497
498 #undef __HPCMIPS_copy_region
499
500 /*
501 * Bus read/write barrier methods.
502 *
503 * void bus_space_barrier __P((bus_space_tag_t tag,
504 * bus_space_handle_t bsh, bus_size_t offset,
505 * bus_size_t len, int flags));
506 *
507 * On the MIPS, we just flush the write buffer.
508 */
509 #define bus_space_barrier(t, h, o, l, f) \
510 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)), \
511 wbflush())
512 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
513 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
514
515 #undef __PB_TYPENAME_PREFIX
516 #undef __PB_TYPENAME
517
518 /*
519 * Bus stream operations--defined in terms of non-stream counterparts
520 */
521 #define __BUS_SPACE_HAS_STREAM_METHODS 1
522 #define bus_space_read_stream_1 bus_space_read_1
523 #define bus_space_read_stream_2 bus_space_read_2
524 #define bus_space_read_stream_4 bus_space_read_4
525 #define bus_space_read_stream_8 bus_space_read_8
526 #define bus_space_read_multi_stream_1 bus_space_read_multi_1
527 #define bus_space_read_multi_stream_2 bus_space_read_multi_2
528 #define bus_space_read_multi_stream_4 bus_space_read_multi_4
529 #define bus_space_read_multi_stream_8 bus_space_read_multi_8
530 #define bus_space_read_region_stream_1 bus_space_read_region_1
531 #define bus_space_read_region_stream_2 bus_space_read_region_2
532 #define bus_space_read_region_stream_4 bus_space_read_region_4
533 #define bus_space_read_region_stream_8 bus_space_read_region_8
534 #define bus_space_write_stream_1 bus_space_write_1
535 #define bus_space_write_stream_2 bus_space_write_2
536 #define bus_space_write_stream_4 bus_space_write_4
537 #define bus_space_write_stream_8 bus_space_write_8
538 #define bus_space_write_multi_stream_1 bus_space_write_multi_1
539 #define bus_space_write_multi_stream_2 bus_space_write_multi_2
540 #define bus_space_write_multi_stream_4 bus_space_write_multi_4
541 #define bus_space_write_multi_stream_8 bus_space_write_multi_8
542 #define bus_space_write_region_stream_1 bus_space_write_region_1
543 #define bus_space_write_region_stream_2 bus_space_write_region_2
544 #define bus_space_write_region_stream_4 bus_space_write_region_4
545 #define bus_space_write_region_stream_8 bus_space_write_region_8
546
547 /*
548 * Flags used in various bus DMA methods.
549 */
550 #define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */
551 #define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */
552 #define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */
553 #define BUS_DMA_COHERENT 0x04 /* hint: map memory DMA coherent */
554 #define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */
555 #define BUS_DMA_BUS2 0x20
556 #define BUS_DMA_BUS3 0x40
557 #define BUS_DMA_BUS4 0x80
558
559 #define HPCMIPS_DMAMAP_COHERENT 0x100 /* no cache flush necessary on sync */
560
561 /* Forwards needed by prototypes below. */
562 struct mbuf;
563 struct uio;
564
565 /*
566 * Operations performed by bus_dmamap_sync().
567 */
568 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
569 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
570 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
571 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
572
573 typedef struct hpcmips_bus_dma_tag *bus_dma_tag_t;
574 typedef struct hpcmips_bus_dmamap *bus_dmamap_t;
575
576 /*
577 * bus_dma_segment_t
578 *
579 * Describes a single contiguous DMA transaction. Values
580 * are suitable for programming into DMA registers.
581 */
582 struct hpcmips_bus_dma_segment {
583 bus_addr_t ds_addr; /* DMA address */
584 bus_size_t ds_len; /* length of transfer */
585 bus_addr_t _ds_vaddr; /* virtual address, 0 if invalid */
586 };
587 typedef struct hpcmips_bus_dma_segment bus_dma_segment_t;
588
589 /*
590 * bus_dma_tag_t
591 *
592 * A machine-dependent opaque type describing the implementation of
593 * DMA for a given bus.
594 */
595
596 struct hpcmips_bus_dma_tag {
597 /*
598 * DMA mapping methods.
599 */
600 int (*_dmamap_create) __P((bus_dma_tag_t, bus_size_t, int,
601 bus_size_t, bus_size_t, int, bus_dmamap_t *));
602 void (*_dmamap_destroy) __P((bus_dma_tag_t, bus_dmamap_t));
603 int (*_dmamap_load) __P((bus_dma_tag_t, bus_dmamap_t, void *,
604 bus_size_t, struct proc *, int));
605 int (*_dmamap_load_mbuf) __P((bus_dma_tag_t, bus_dmamap_t,
606 struct mbuf *, int));
607 int (*_dmamap_load_uio) __P((bus_dma_tag_t, bus_dmamap_t,
608 struct uio *, int));
609 int (*_dmamap_load_raw) __P((bus_dma_tag_t, bus_dmamap_t,
610 bus_dma_segment_t *, int, bus_size_t, int));
611 void (*_dmamap_unload) __P((bus_dma_tag_t, bus_dmamap_t));
612 void (*_dmamap_sync) __P((bus_dma_tag_t, bus_dmamap_t,
613 bus_addr_t, bus_size_t, int));
614
615 /*
616 * DMA memory utility functions.
617 */
618 int (*_dmamem_alloc) __P((bus_dma_tag_t, bus_size_t, bus_size_t,
619 bus_size_t, bus_dma_segment_t *, int, int *, int));
620 void (*_dmamem_free) __P((bus_dma_tag_t,
621 bus_dma_segment_t *, int));
622 int (*_dmamem_map) __P((bus_dma_tag_t, bus_dma_segment_t *,
623 int, size_t, caddr_t *, int));
624 void (*_dmamem_unmap) __P((bus_dma_tag_t, caddr_t, size_t));
625 paddr_t (*_dmamem_mmap) __P((bus_dma_tag_t, bus_dma_segment_t *,
626 int, off_t, int, int));
627
628 void *_dmamap_chipset_v;
629 };
630
631 #define bus_dmamap_create(t, s, n, m, b, f, p) \
632 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
633 #define bus_dmamap_destroy(t, p) \
634 (*(t)->_dmamap_destroy)((t), (p))
635 #define bus_dmamap_load(t, m, b, s, p, f) \
636 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
637 #define bus_dmamap_load_mbuf(t, m, b, f) \
638 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
639 #define bus_dmamap_load_uio(t, m, u, f) \
640 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
641 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
642 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
643 #define bus_dmamap_unload(t, p) \
644 (*(t)->_dmamap_unload)((t), (p))
645 #define bus_dmamap_sync(t, p, o, l, ops) \
646 (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
647
648 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
649 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
650 #define bus_dmamem_free(t, sg, n) \
651 (*(t)->_dmamem_free)((t), (sg), (n))
652 #define bus_dmamem_map(t, sg, n, s, k, f) \
653 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
654 #define bus_dmamem_unmap(t, k, s) \
655 (*(t)->_dmamem_unmap)((t), (k), (s))
656 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
657 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
658
659 /*
660 * bus_dmamap_t
661 *
662 * Describes a DMA mapping.
663 */
664 struct hpcmips_bus_dmamap {
665 /*
666 * PRIVATE MEMBERS: not for use my machine-independent code.
667 */
668 bus_size_t _dm_size; /* largest DMA transfer mappable */
669 int _dm_segcnt; /* number of segs this map can map */
670 bus_size_t _dm_maxsegsz; /* largest possible segment */
671 bus_size_t _dm_boundary; /* don't cross this */
672 int _dm_flags; /* misc. flags */
673
674 /*
675 * PUBLIC MEMBERS: these are used by machine-independent code.
676 */
677 bus_size_t dm_mapsize; /* size of the mapping */
678 int dm_nsegs; /* # valid segments in mapping */
679 bus_dma_segment_t dm_segs[1]; /* segments; variable length */
680 };
681
682 #ifdef _HPCMIPS_BUS_DMA_PRIVATE
683 int _bus_dmamap_create __P((bus_dma_tag_t, bus_size_t, int, bus_size_t,
684 bus_size_t, int, bus_dmamap_t *));
685 void _bus_dmamap_destroy __P((bus_dma_tag_t, bus_dmamap_t));
686 int _bus_dmamap_load __P((bus_dma_tag_t, bus_dmamap_t, void *,
687 bus_size_t, struct proc *, int));
688 int _bus_dmamap_load_mbuf __P((bus_dma_tag_t, bus_dmamap_t,
689 struct mbuf *, int));
690 int _bus_dmamap_load_uio __P((bus_dma_tag_t, bus_dmamap_t,
691 struct uio *, int));
692 int _bus_dmamap_load_raw __P((bus_dma_tag_t, bus_dmamap_t,
693 bus_dma_segment_t *, int, bus_size_t, int));
694 void _bus_dmamap_unload __P((bus_dma_tag_t, bus_dmamap_t));
695 void _bus_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
696 bus_size_t, int));
697
698 int _bus_dmamem_alloc __P((bus_dma_tag_t tag, bus_size_t size,
699 bus_size_t alignment, bus_size_t boundary,
700 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags));
701 void _bus_dmamem_free __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
702 int nsegs));
703 int _bus_dmamem_map __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
704 int nsegs, size_t size, caddr_t *kvap, int flags));
705 void _bus_dmamem_unmap __P((bus_dma_tag_t tag, caddr_t kva,
706 size_t size));
707 paddr_t _bus_dmamem_mmap __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
708 int nsegs, off_t off, int prot, int flags));
709
710 int _bus_dmamem_alloc_range __P((bus_dma_tag_t tag, bus_size_t size,
711 bus_size_t alignment, bus_size_t boundary,
712 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
713 vaddr_t low, vaddr_t high));
714
715 extern struct hpcmips_bus_dma_tag hpcmips_default_bus_dma_tag;
716 #endif /* _HPCMIPS_BUS_DMA_PRIVATE */
717
718 #endif /* _HPCMIPS_BUS_H_ */
719