bus.h revision 1.17
1/*	$NetBSD: bus.h,v 1.17 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 _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 */
54typedef u_long bus_addr_t;
55typedef u_long bus_size_t;
56
57/*
58 * Access methods for bus resources and address space.
59 */
60typedef int	bus_space_tag_t;
61typedef 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
74int	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
84void	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
94int	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
106int	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
118void	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)				\
162static __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									\
166static __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)			\
200static __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									\
204static __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)					\
239do {									\
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)					\
246do {									\
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)					\
253do {									\
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)			\
273static __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									\
277static __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)			\
311static __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									\
315static __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)				\
351static __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									\
355static __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)				\
389static __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									\
393static __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)					\
430static __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									\
436static __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
503#define	PMAX_DMAMAP_COHERENT	0x10000	/* no cache flush necessary on sync */
504
505/* Forwards needed by prototypes below. */
506struct mbuf;
507struct uio;
508
509/*
510 * Operations performed by bus_dmamap_sync().
511 */
512#define	BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
513#define	BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
514#define	BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
515#define	BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
516
517typedef struct pmax_bus_dma_tag		*bus_dma_tag_t;
518typedef struct pmax_bus_dmamap		*bus_dmamap_t;
519
520/*
521 *	bus_dma_segment_t
522 *
523 *	Describes a single contiguous DMA transaction.  Values
524 *	are suitable for programming into DMA registers.
525 */
526struct pmax_bus_dma_segment {
527	bus_addr_t	ds_addr;	/* DMA address */
528	bus_size_t	ds_len;		/* length of transfer */
529	bus_addr_t	_ds_vaddr;	/* virtual address, 0 if invalid */
530};
531typedef struct pmax_bus_dma_segment	bus_dma_segment_t;
532
533/*
534 *	bus_dma_tag_t
535 *
536 *	A machine-dependent opaque type describing the implementation of
537 *	DMA for a given bus.
538 */
539
540struct pmax_bus_dma_tag {
541	/*
542	 * DMA mapping methods.
543	 */
544	int	(*_dmamap_create) __P((bus_dma_tag_t, bus_size_t, int,
545		    bus_size_t, bus_size_t, int, bus_dmamap_t *));
546	void	(*_dmamap_destroy) __P((bus_dma_tag_t, bus_dmamap_t));
547	int	(*_dmamap_load) __P((bus_dma_tag_t, bus_dmamap_t, void *,
548		    bus_size_t, struct proc *, int));
549	int	(*_dmamap_load_mbuf) __P((bus_dma_tag_t, bus_dmamap_t,
550		    struct mbuf *, int));
551	int	(*_dmamap_load_uio) __P((bus_dma_tag_t, bus_dmamap_t,
552		    struct uio *, int));
553	int	(*_dmamap_load_raw) __P((bus_dma_tag_t, bus_dmamap_t,
554		    bus_dma_segment_t *, int, bus_size_t, int));
555	void	(*_dmamap_unload) __P((bus_dma_tag_t, bus_dmamap_t));
556	void	(*_dmamap_sync) __P((bus_dma_tag_t, bus_dmamap_t,
557		    bus_addr_t, bus_size_t, int));
558
559	/*
560	 * DMA memory utility functions.
561	 */
562	int	(*_dmamem_alloc) __P((bus_dma_tag_t, bus_size_t, bus_size_t,
563		    bus_size_t, bus_dma_segment_t *, int, int *, int));
564	void	(*_dmamem_free) __P((bus_dma_tag_t,
565		    bus_dma_segment_t *, int));
566	int	(*_dmamem_map) __P((bus_dma_tag_t, bus_dma_segment_t *,
567		    int, size_t, caddr_t *, int));
568	void	(*_dmamem_unmap) __P((bus_dma_tag_t, caddr_t, size_t));
569	paddr_t	(*_dmamem_mmap) __P((bus_dma_tag_t, bus_dma_segment_t *,
570		    int, off_t, int, int));
571};
572
573#define	bus_dmamap_create(t, s, n, m, b, f, p)			\
574	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
575#define	bus_dmamap_destroy(t, p)				\
576	(*(t)->_dmamap_destroy)((t), (p))
577#define	bus_dmamap_load(t, m, b, s, p, f)			\
578	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
579#define	bus_dmamap_load_mbuf(t, m, b, f)			\
580	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
581#define	bus_dmamap_load_uio(t, m, u, f)				\
582	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
583#define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
584	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
585#define	bus_dmamap_unload(t, p)					\
586	(*(t)->_dmamap_unload)((t), (p))
587#define	bus_dmamap_sync(t, p, o, l, ops)			\
588	(*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
589
590#define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
591	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
592#define	bus_dmamem_free(t, sg, n)				\
593	(*(t)->_dmamem_free)((t), (sg), (n))
594#define	bus_dmamem_map(t, sg, n, s, k, f)			\
595	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
596#define	bus_dmamem_unmap(t, k, s)				\
597	(*(t)->_dmamem_unmap)((t), (k), (s))
598#define	bus_dmamem_mmap(t, sg, n, o, p, f)			\
599	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
600
601/*
602 *	bus_dmamap_t
603 *
604 *	Describes a DMA mapping.
605 */
606struct pmax_bus_dmamap {
607	/*
608	 * PRIVATE MEMBERS: not for use my machine-independent code.
609	 */
610	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
611	int		_dm_segcnt;	/* number of segs this map can map */
612	bus_size_t	_dm_maxsegsz;	/* largest possible segment */
613	bus_size_t	_dm_boundary;	/* don't cross this */
614	int		_dm_flags;	/* misc. flags */
615	struct proc	*_dm_proc;	/* proc that owns the mapping */
616
617	/*
618	 * PUBLIC MEMBERS: these are used by machine-independent code.
619	 */
620	bus_size_t	dm_mapsize;	/* size of the mapping */
621	int		dm_nsegs;	/* # valid segments in mapping */
622	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
623};
624
625#ifdef _PMAX_BUS_DMA_PRIVATE
626void	pmax_bus_dma_init(void);
627
628int	_bus_dmamap_create __P((bus_dma_tag_t, bus_size_t, int, bus_size_t,
629	    bus_size_t, int, bus_dmamap_t *));
630void	_bus_dmamap_destroy __P((bus_dma_tag_t, bus_dmamap_t));
631int	_bus_dmamap_load __P((bus_dma_tag_t, bus_dmamap_t, void *,
632	    bus_size_t, struct proc *, int));
633int	_bus_dmamap_load_mbuf __P((bus_dma_tag_t, bus_dmamap_t,
634	    struct mbuf *, int));
635int	_bus_dmamap_load_uio __P((bus_dma_tag_t, bus_dmamap_t,
636	    struct uio *, int));
637int	_bus_dmamap_load_raw __P((bus_dma_tag_t, bus_dmamap_t,
638	    bus_dma_segment_t *, int, bus_size_t, int));
639void	_bus_dmamap_unload __P((bus_dma_tag_t, bus_dmamap_t));
640void	_bus_dmamap_sync_r3k __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
641	    bus_size_t, int));
642void	_bus_dmamap_sync_r4k __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
643	    bus_size_t, int));
644
645int	_bus_dmamem_alloc __P((bus_dma_tag_t tag, bus_size_t size,
646	    bus_size_t alignment, bus_size_t boundary,
647	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags));
648void	_bus_dmamem_free __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
649	    int nsegs));
650int	_bus_dmamem_map __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
651	    int nsegs, size_t size, caddr_t *kvap, int flags));
652void	_bus_dmamem_unmap __P((bus_dma_tag_t tag, caddr_t kva,
653	    size_t size));
654paddr_t	_bus_dmamem_mmap __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
655	    int nsegs, off_t off, int prot, int flags));
656
657int	_bus_dmamem_alloc_range __P((bus_dma_tag_t tag, bus_size_t size,
658	    bus_size_t alignment, bus_size_t boundary,
659	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
660	    vaddr_t low, vaddr_t high));
661
662extern struct pmax_bus_dma_tag pmax_default_bus_dma_tag;
663#endif /* _PMAX_BUS_DMA_PRIVATE */
664
665#endif /* !_PMAX_BUS_H_ */
666