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