bus.h revision 1.6 1 /* $NetBSD: bus.h,v 1.6 2002/03/17 21:45:08 simonb 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 * 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 _NEWSMIPS_BUS_H_
41 #define _NEWSMIPS_BUS_H_
42
43 #include <mips/locore.h>
44
45 /*
46 * Utility macros; do not use outside this file.
47 */
48 #define __PB_TYPENAME_PREFIX(BITS) ___CONCAT(u_int,BITS)
49 #define __PB_TYPENAME(BITS) ___CONCAT(__PB_TYPENAME_PREFIX(BITS),_t)
50
51 /*
52 * Bus address and size types
53 */
54 typedef u_long bus_addr_t;
55 typedef u_long bus_size_t;
56
57 /*
58 * Access methods for bus resources and address space.
59 */
60 typedef int bus_space_tag_t;
61 typedef u_long bus_space_handle_t;
62
63 /*
64 * int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
65 * bus_size_t size, int flags, bus_space_handle_t *bshp);
66 *
67 * Map a region of bus space.
68 */
69
70 #define BUS_SPACE_MAP_CACHEABLE 0x01
71 #define BUS_SPACE_MAP_LINEAR 0x02
72 #define BUS_SPACE_MAP_PREFETCHABLE 0x04
73
74 int bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
75 int, bus_space_handle_t *);
76
77 /*
78 * void bus_space_unmap(bus_space_tag_t t,
79 * bus_space_handle_t bsh, bus_size_t size);
80 *
81 * Unmap a region of bus space.
82 */
83
84 void bus_space_unmap (bus_space_tag_t, bus_space_handle_t, bus_size_t);
85
86 /*
87 * int bus_space_subregion(bus_space_tag_t t,
88 * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
89 * bus_space_handle_t *nbshp);
90 *
91 * Get a new handle for a subregion of an already-mapped area of bus space.
92 */
93
94 int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
95 bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp);
96
97 /*
98 * int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart,
99 * bus_addr_t rend, bus_size_t size, bus_size_t align,
100 * bus_size_t boundary, int flags, bus_addr_t *addrp,
101 * bus_space_handle_t *bshp);
102 *
103 * Allocate a region of bus space.
104 */
105
106 int bus_space_alloc (bus_space_tag_t t, bus_addr_t rstart,
107 bus_addr_t rend, bus_size_t size, bus_size_t align,
108 bus_size_t boundary, int cacheable, bus_addr_t *addrp,
109 bus_space_handle_t *bshp);
110
111 /*
112 * int bus_space_free (bus_space_tag_t t,
113 * bus_space_handle_t bsh, bus_size_t size);
114 *
115 * Free a region of bus space.
116 */
117
118 void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
119 bus_size_t size);
120
121 /*
122 * u_intN_t bus_space_read_N(bus_space_tag_t tag,
123 * bus_space_handle_t bsh, bus_size_t offset);
124 *
125 * Read a 1, 2, 4, or 8 byte quantity from bus space
126 * described by tag/handle/offset.
127 */
128
129 #define bus_space_read_1(t, h, o) \
130 ((void) t, (*(volatile u_int8_t *)((h) + (o))))
131
132 #define bus_space_read_2(t, h, o) \
133 ((void) t, (*(volatile u_int16_t *)((h) + (o))))
134
135 #define bus_space_read_4(t, h, o) \
136 ((void) t, (*(volatile u_int32_t *)((h) + (o))))
137
138 #if 0 /* Cause a link error for bus_space_read_8 */
139 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
140 #endif
141
142 /*
143 * void bus_space_read_multi_N(bus_space_tag_t tag,
144 * bus_space_handle_t bsh, bus_size_t offset,
145 * u_intN_t *addr, size_t count);
146 *
147 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
148 * described by tag/handle/offset and copy into buffer provided.
149 */
150
151 #define __NEWSMIPS_bus_space_read_multi(BYTES,BITS) \
152 static __inline void __CONCAT(bus_space_read_multi_,BYTES) \
153 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
154 __PB_TYPENAME(BITS) *, size_t); \
155 \
156 static __inline void \
157 __CONCAT(bus_space_read_multi_,BYTES)(t, h, o, a, c) \
158 bus_space_tag_t t; \
159 bus_space_handle_t h; \
160 bus_size_t o; \
161 __PB_TYPENAME(BITS) *a; \
162 size_t c; \
163 { \
164 \
165 while (c--) \
166 *a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o); \
167 }
168
169 __NEWSMIPS_bus_space_read_multi(1,8)
170 __NEWSMIPS_bus_space_read_multi(2,16)
171 __NEWSMIPS_bus_space_read_multi(4,32)
172
173 #if 0 /* Cause a link error for bus_space_read_multi_8 */
174 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
175 #endif
176
177 #undef __NEWSMIPS_bus_space_read_multi
178
179 /*
180 * void bus_space_read_region_N(bus_space_tag_t tag,
181 * bus_space_handle_t bsh, bus_size_t offset,
182 * u_intN_t *addr, size_t count);
183 *
184 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
185 * described by tag/handle and starting at `offset' and copy into
186 * buffer provided.
187 */
188
189 #define __NEWSMIPS_bus_space_read_region(BYTES,BITS) \
190 static __inline void __CONCAT(bus_space_read_region_,BYTES) \
191 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
192 __PB_TYPENAME(BITS) *, size_t); \
193 \
194 static __inline void \
195 __CONCAT(bus_space_read_region_,BYTES)(t, h, o, a, c) \
196 bus_space_tag_t t; \
197 bus_space_handle_t h; \
198 bus_size_t o; \
199 __PB_TYPENAME(BITS) *a; \
200 size_t c; \
201 { \
202 \
203 while (c--) { \
204 *a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o); \
205 o += BYTES; \
206 } \
207 }
208
209 __NEWSMIPS_bus_space_read_region(1,8)
210 __NEWSMIPS_bus_space_read_region(2,16)
211 __NEWSMIPS_bus_space_read_region(4,32)
212
213 #if 0 /* Cause a link error for bus_space_read_region_8 */
214 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
215 #endif
216
217 #undef __NEWSMIPS_bus_space_read_region
218
219 /*
220 * void bus_space_write_N(bus_space_tag_t tag,
221 * bus_space_handle_t bsh, bus_size_t offset,
222 * u_intN_t value);
223 *
224 * Write the 1, 2, 4, or 8 byte value `value' to bus space
225 * described by tag/handle/offset.
226 */
227
228 #define bus_space_write_1(t, h, o, v) \
229 do { \
230 (void) t; \
231 *(volatile u_int8_t *)((h) + (o)) = (v); \
232 } while (0)
233
234 #define bus_space_write_2(t, h, o, v) \
235 do { \
236 (void) t; \
237 *(volatile u_int16_t *)((h) + (o)) = (v); \
238 } while (0)
239
240 #define bus_space_write_4(t, h, o, v) \
241 do { \
242 (void) t; \
243 *(volatile u_int32_t *)((h) + (o)) = (v); \
244 } while (0)
245
246 #if 0 /* Cause a link error for bus_space_write_8 */
247 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
248 #endif
249
250 /*
251 * void bus_space_write_multi_N(bus_space_tag_t tag,
252 * bus_space_handle_t bsh, bus_size_t offset,
253 * const u_intN_t *addr, size_t count);
254 *
255 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
256 * provided to bus space described by tag/handle/offset.
257 */
258
259 #define __NEWSMIPS_bus_space_write_multi(BYTES,BITS) \
260 static __inline void __CONCAT(bus_space_write_multi_,BYTES) \
261 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
262 const __PB_TYPENAME(BITS) *, size_t); \
263 \
264 static __inline void \
265 __CONCAT(bus_space_write_multi_,BYTES)(t, h, o, a, c) \
266 bus_space_tag_t t; \
267 bus_space_handle_t h; \
268 bus_size_t o; \
269 const __PB_TYPENAME(BITS) *a; \
270 size_t c; \
271 { \
272 \
273 while (c--) \
274 __CONCAT(bus_space_write_,BYTES)(t, h, o, *a++); \
275 }
276
277 __NEWSMIPS_bus_space_write_multi(1,8)
278 __NEWSMIPS_bus_space_write_multi(2,16)
279 __NEWSMIPS_bus_space_write_multi(4,32)
280
281 #if 0 /* Cause a link error for bus_space_write_8 */
282 #define bus_space_write_multi_8(t, h, o, a, c) \
283 !!! bus_space_write_multi_8 unimplimented !!!
284 #endif
285
286 #undef __NEWSMIPS_bus_space_write_multi
287
288 /*
289 * void bus_space_write_region_N(bus_space_tag_t tag,
290 * bus_space_handle_t bsh, bus_size_t offset,
291 * const u_intN_t *addr, size_t count);
292 *
293 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
294 * to bus space described by tag/handle starting at `offset'.
295 */
296
297 #define __NEWSMIPS_bus_space_write_region(BYTES,BITS) \
298 static __inline void __CONCAT(bus_space_write_region_,BYTES) \
299 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
300 const __PB_TYPENAME(BITS) *, size_t); \
301 \
302 static __inline void \
303 __CONCAT(bus_space_write_region_,BYTES)(t, h, o, a, c) \
304 bus_space_tag_t t; \
305 bus_space_handle_t h; \
306 bus_size_t o; \
307 const __PB_TYPENAME(BITS) *a; \
308 size_t c; \
309 { \
310 \
311 while (c--) { \
312 __CONCAT(bus_space_write_,BYTES)(t, h, o, *a++); \
313 o += BYTES; \
314 } \
315 }
316
317 __NEWSMIPS_bus_space_write_region(1,8)
318 __NEWSMIPS_bus_space_write_region(2,16)
319 __NEWSMIPS_bus_space_write_region(4,32)
320
321 #if 0 /* Cause a link error for bus_space_write_region_8 */
322 #define bus_space_write_region_8 \
323 !!! bus_space_write_region_8 unimplemented !!!
324 #endif
325
326 #undef __NEWSMIPS_bus_space_write_region
327
328 /*
329 * void bus_space_set_multi_N(bus_space_tag_t tag,
330 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
331 * size_t count);
332 *
333 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
334 * by tag/handle/offset `count' times.
335 */
336
337 #define __NEWSMIPS_bus_space_set_multi(BYTES,BITS) \
338 static __inline void __CONCAT(bus_space_set_multi_,BYTES) \
339 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
340 __PB_TYPENAME(BITS), size_t); \
341 \
342 static __inline void \
343 __CONCAT(bus_space_set_multi_,BYTES)(t, h, o, v, c) \
344 bus_space_tag_t t; \
345 bus_space_handle_t h; \
346 bus_size_t o; \
347 __PB_TYPENAME(BITS) v; \
348 size_t c; \
349 { \
350 \
351 while (c--) \
352 __CONCAT(bus_space_write_,BYTES)(t, h, o, v); \
353 }
354
355 __NEWSMIPS_bus_space_set_multi(1,8)
356 __NEWSMIPS_bus_space_set_multi(2,16)
357 __NEWSMIPS_bus_space_set_multi(4,32)
358
359 #if 0 /* Cause a link error for bus_space_set_multi_8 */
360 #define bus_space_set_multi_8 \
361 !!! bus_space_set_multi_8 unimplemented !!!
362 #endif
363
364 #undef __NEWSMIPS_bus_space_set_multi
365
366 /*
367 * void bus_space_set_region_N(bus_space_tag_t tag,
368 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
369 * size_t count);
370 *
371 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
372 * by tag/handle starting at `offset'.
373 */
374
375 #define __NEWSMIPS_bus_space_set_region(BYTES,BITS) \
376 static __inline void __CONCAT(bus_space_set_region_,BYTES) \
377 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
378 __PB_TYPENAME(BITS), size_t); \
379 \
380 static __inline void \
381 __CONCAT(bus_space_set_region_,BYTES)(t, h, o, v, c) \
382 bus_space_tag_t t; \
383 bus_space_handle_t h; \
384 bus_size_t o; \
385 __PB_TYPENAME(BITS) v; \
386 size_t c; \
387 { \
388 \
389 while (c--) { \
390 __CONCAT(bus_space_write_,BYTES)(t, h, o, v); \
391 o += BYTES; \
392 } \
393 }
394
395 __NEWSMIPS_bus_space_set_region(1,8)
396 __NEWSMIPS_bus_space_set_region(2,16)
397 __NEWSMIPS_bus_space_set_region(4,32)
398
399 #if 0 /* Cause a link error for bus_space_set_region_8 */
400 #define bus_space_set_region_8 \
401 !!! bus_space_set_region_8 unimplemented !!!
402 #endif
403
404 #undef __NEWSMIPS_bus_space_set_region
405
406 /*
407 * void bus_space_copy_region_N(bus_space_tag_t tag,
408 * bus_space_handle_t bsh1, bus_size_t off1,
409 * bus_space_handle_t bsh2, bus_size_t off2,
410 * bus_size_t count);
411 *
412 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
413 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
414 */
415
416 #define __NEWSMIPS_copy_region(BYTES) \
417 static __inline void __CONCAT(bus_space_copy_region_,BYTES) \
418 (bus_space_tag_t, \
419 bus_space_handle_t bsh1, bus_size_t off1, \
420 bus_space_handle_t bsh2, bus_size_t off2, \
421 bus_size_t count); \
422 \
423 static __inline void \
424 __CONCAT(bus_space_copy_region_,BYTES)(t, h1, o1, h2, o2, c) \
425 bus_space_tag_t t; \
426 bus_space_handle_t h1, h2; \
427 bus_size_t o1, o2, c; \
428 { \
429 bus_size_t o; \
430 \
431 if ((h1 + o1) >= (h2 + o2)) { \
432 /* src after dest: copy forward */ \
433 for (o = 0; c != 0; c--, o += BYTES) \
434 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
435 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
436 } else { \
437 /* dest after src: copy backwards */ \
438 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
439 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
440 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
441 } \
442 }
443
444 __NEWSMIPS_copy_region(1)
445 __NEWSMIPS_copy_region(2)
446 __NEWSMIPS_copy_region(4)
447
448 #if 0 /* Cause a link error for bus_space_copy_region_8 */
449 #define bus_space_copy_region_8 \
450 !!! bus_space_copy_region_8 unimplemented !!!
451 #endif
452
453 #undef __NEWSMIPS_copy_region
454
455 /*
456 * Bus read/write barrier methods.
457 *
458 * void bus_space_barrier(bus_space_tag_t tag,
459 * bus_space_handle_t bsh, bus_size_t offset,
460 * bus_size_t len, int flags);
461 *
462 * On the MIPS, we just flush the write buffer.
463 */
464 #define bus_space_barrier(t, h, o, l, f) \
465 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)), \
466 wbflush())
467 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
468 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
469
470 #undef __PB_TYPENAME_PREFIX
471 #undef __PB_TYPENAME
472
473 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
474
475 /*
476 * Flags used in various bus DMA methods.
477 */
478 #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
479 #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
480 #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
481 #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
482 #define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */
483 #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
484 #define BUS_DMA_BUS2 0x020
485 #define BUS_DMA_BUS3 0x040
486 #define BUS_DMA_BUS4 0x080
487 #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
488 #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
489
490 #define NEWSMIPS_DMAMAP_COHERENT 0x10000 /* no cache flush necessary on sync */
491 #define NEWSMIPS_DMAMAP_MAPTBL 0x20000 /* use DMA maping table */
492
493 /* Forwards needed by prototypes below. */
494 struct mbuf;
495 struct uio;
496
497 /*
498 * Operations performed by bus_dmamap_sync().
499 */
500 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
501 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
502 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
503 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
504
505 typedef struct newsmips_bus_dma_tag *bus_dma_tag_t;
506 typedef struct newsmips_bus_dmamap *bus_dmamap_t;
507
508 /*
509 * bus_dma_segment_t
510 *
511 * Describes a single contiguous DMA transaction. Values
512 * are suitable for programming into DMA registers.
513 */
514 struct newsmips_bus_dma_segment {
515 bus_addr_t ds_addr; /* DMA address */
516 bus_size_t ds_len; /* length of transfer */
517 bus_addr_t _ds_vaddr; /* virtual address, 0 if invalid */
518 };
519 typedef struct newsmips_bus_dma_segment bus_dma_segment_t;
520
521 /*
522 * bus_dma_tag_t
523 *
524 * A machine-dependent opaque type describing the implementation of
525 * DMA for a given bus.
526 */
527
528 struct newsmips_bus_dma_tag {
529 /*
530 * DMA mapping methods.
531 */
532 int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
533 bus_size_t, bus_size_t, int, bus_dmamap_t *);
534 void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
535 int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
536 bus_size_t, struct proc *, int);
537 int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
538 struct mbuf *, int);
539 int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
540 struct uio *, int);
541 int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
542 bus_dma_segment_t *, int, bus_size_t, int);
543 void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
544 void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
545 bus_addr_t, bus_size_t, int);
546
547 /*
548 * DMA memory utility functions.
549 */
550 int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
551 bus_size_t, bus_dma_segment_t *, int, int *, int);
552 void (*_dmamem_free)(bus_dma_tag_t,
553 bus_dma_segment_t *, int);
554 int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
555 int, size_t, caddr_t *, int);
556 void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t);
557 paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
558 int, off_t, int, int);
559
560 /*
561 * NEWSMIPS quirks.
562 * This is NOT a constant. Slot dependent information is
563 * required to flush DMA cache correctly.
564 */
565 int _slotno;
566 bus_space_tag_t _slotbaset;
567 bus_space_handle_t _slotbaseh;
568 };
569
570 #define bus_dmamap_create(t, s, n, m, b, f, p) \
571 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
572 #define bus_dmamap_destroy(t, p) \
573 (*(t)->_dmamap_destroy)((t), (p))
574 #define bus_dmamap_load(t, m, b, s, p, f) \
575 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
576 #define bus_dmamap_load_mbuf(t, m, b, f) \
577 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
578 #define bus_dmamap_load_uio(t, m, u, f) \
579 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
580 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
581 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
582 #define bus_dmamap_unload(t, p) \
583 (*(t)->_dmamap_unload)((t), (p))
584 #define bus_dmamap_sync(t, p, o, l, ops) \
585 (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
586
587 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
588 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
589 #define bus_dmamem_free(t, sg, n) \
590 (*(t)->_dmamem_free)((t), (sg), (n))
591 #define bus_dmamem_map(t, sg, n, s, k, f) \
592 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
593 #define bus_dmamem_unmap(t, k, s) \
594 (*(t)->_dmamem_unmap)((t), (k), (s))
595 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
596 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
597
598 /*
599 * bus_dmamap_t
600 *
601 * Describes a DMA mapping.
602 */
603 struct newsmips_bus_dmamap {
604 /*
605 * PRIVATE MEMBERS: not for use my machine-independent code.
606 */
607 bus_size_t _dm_size; /* largest DMA transfer mappable */
608 int _dm_segcnt; /* number of segs this map can map */
609 bus_size_t _dm_maxsegsz; /* largest possible segment */
610 bus_size_t _dm_boundary; /* don't cross this */
611 int _dm_flags; /* misc. flags */
612 int _dm_maptbl; /* DMA mapping table index */
613 int _dm_maptblcnt; /* number of DMA mapping table */
614 struct proc *_dm_proc; /* proc that owns the mapping */
615
616 /*
617 * PUBLIC MEMBERS: these are used by machine-independent code.
618 */
619 bus_size_t dm_mapsize; /* size of the mapping */
620 int dm_nsegs; /* # valid segments in mapping */
621 bus_dma_segment_t dm_segs[1]; /* segments; variable length */
622 };
623
624 #ifdef _NEWSMIPS_BUS_DMA_PRIVATE
625 void newsmips_bus_dma_init(void);
626
627 int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
628 bus_size_t, int, bus_dmamap_t *);
629 void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
630 int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
631 bus_size_t, struct proc *, int);
632 int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
633 struct mbuf *, int);
634 int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
635 struct uio *, int);
636 int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
637 bus_dma_segment_t *, int, bus_size_t, int);
638 void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
639 void _bus_dmamap_sync_r3k(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
640 bus_size_t, int);
641 void _bus_dmamap_sync_r4k(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
642 bus_size_t, int);
643
644 int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
645 bus_size_t alignment, bus_size_t boundary,
646 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
647 void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
648 int nsegs);
649 int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
650 int nsegs, size_t size, caddr_t *kvap, int flags);
651 void _bus_dmamem_unmap(bus_dma_tag_t tag, caddr_t kva,
652 size_t size);
653 paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
654 int nsegs, off_t off, int prot, int flags);
655
656 int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
657 bus_size_t alignment, bus_size_t boundary,
658 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
659 vaddr_t low, vaddr_t high);
660
661 extern struct newsmips_bus_dma_tag newsmips_default_bus_dma_tag;
662 #endif /* _NEWSMIPS_BUS_DMA_PRIVATE */
663
664 #endif /* _NEWSMIPS_BUS_H_ */
665