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