bus_dma.h revision 1.1 1 /* $NetBSD: bus_dma.h,v 1.1 1998/06/09 07:53:05 dbj Exp $ */
2
3 /*-
4 * Copyright (c) 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 /*
41 * Copyright (c) 1996 Carnegie-Mellon University.
42 * All rights reserved.
43 *
44 * Author: Chris G. Demetriou
45 *
46 * Permission to use, copy, modify and distribute this software and
47 * its documentation is hereby granted, provided that both the copyright
48 * notice and this permission notice appear in all copies of the
49 * software, derivative works or modified versions, and any portions
50 * thereof, and that both notices appear in supporting documentation.
51 *
52 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
53 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
54 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
55 *
56 * Carnegie Mellon requests users of this software to return to
57 *
58 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
59 * School of Computer Science
60 * Carnegie Mellon University
61 * Pittsburgh PA 15213-3890
62 *
63 * any improvements or extensions that they make and grant Carnegie the
64 * rights to redistribute these changes.
65 */
66
67 #ifndef _BUS_DMA_H_
68 #define _BUS_DMA_H_
69
70 /*
71 * Bus DMA methods.
72 */
73
74 /*
75 * Flags used in various bus DMA methods.
76 */
77 #define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */
78 #define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */
79 #define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */
80 #define BUS_DMA_COHERENT 0x04 /* hint: map memory DMA coherent */
81 #define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */
82 #define BUS_DMA_BUS2 0x20
83 #define BUS_DMA_BUS3 0x40
84 #define BUS_DMA_BUS4 0x80
85
86 /*
87 * Private flags stored in the DMA map.
88 */
89 #define DMAMAP_HAS_SGMAP 0x80000000 /* sgva/len are valid */
90
91 /* Forwards needed by prototypes below. */
92 struct mbuf;
93 struct uio;
94
95 /*
96 * Operations performed by bus_dmamap_sync().
97 */
98 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
99 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
100 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
101 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
102
103 /*
104 * generic_bus_t
105 *
106 * Busses supported by NetBSD/generic, used by internal
107 * utility functions. NOT TO BE USED BY MACHINE-INDEPENDENT
108 * CODE!
109 */
110 typedef enum {
111 GENERIC_BUS_UNKNOWN,
112 } generic_bus_t;
113
114 typedef struct generic_bus_dma_tag *bus_dma_tag_t;
115 typedef struct generic_bus_dmamap *bus_dmamap_t;
116
117 /*
118 * bus_dma_segment_t
119 *
120 * Describes a single contiguous DMA transaction. Values
121 * are suitable for programming into DMA registers.
122 */
123 struct generic_bus_dma_segment {
124 bus_addr_t ds_addr; /* DMA address */
125 bus_size_t ds_len; /* length of transfer */
126 };
127 typedef struct generic_bus_dma_segment bus_dma_segment_t;
128
129 /*
130 * bus_dma_tag_t
131 *
132 * A machine-dependent opaque type describing the implementation of
133 * DMA for a given bus.
134 */
135 struct generic_bus_dma_tag {
136 void *_cookie; /* cookie used in the guts */
137
138 /*
139 * Internal-use only utility methods. NOT TO BE USED BY
140 * MACHINE-INDEPENDENT CODE!
141 */
142 bus_dma_tag_t (*_get_tag) __P((bus_dma_tag_t, generic_bus_t));
143
144 /*
145 * DMA mapping methods.
146 */
147 int (*_dmamap_create) __P((bus_dma_tag_t, bus_size_t, int,
148 bus_size_t, bus_size_t, int, bus_dmamap_t *));
149 void (*_dmamap_destroy) __P((bus_dma_tag_t, bus_dmamap_t));
150 int (*_dmamap_load) __P((bus_dma_tag_t, bus_dmamap_t, void *,
151 bus_size_t, struct proc *, int));
152 int (*_dmamap_load_mbuf) __P((bus_dma_tag_t, bus_dmamap_t,
153 struct mbuf *, int));
154 int (*_dmamap_load_uio) __P((bus_dma_tag_t, bus_dmamap_t,
155 struct uio *, int));
156 int (*_dmamap_load_raw) __P((bus_dma_tag_t, bus_dmamap_t,
157 bus_dma_segment_t *, int, bus_size_t, int));
158 void (*_dmamap_unload) __P((bus_dma_tag_t, bus_dmamap_t));
159 void (*_dmamap_sync) __P((bus_dma_tag_t, bus_dmamap_t,
160 bus_addr_t, bus_size_t, int));
161
162 /*
163 * DMA memory utility functions.
164 */
165 int (*_dmamem_alloc) __P((bus_dma_tag_t, bus_size_t, bus_size_t,
166 bus_size_t, bus_dma_segment_t *, int, int *, int));
167 void (*_dmamem_free) __P((bus_dma_tag_t,
168 bus_dma_segment_t *, int));
169 int (*_dmamem_map) __P((bus_dma_tag_t, bus_dma_segment_t *,
170 int, size_t, caddr_t *, int));
171 void (*_dmamem_unmap) __P((bus_dma_tag_t, caddr_t, size_t));
172 int (*_dmamem_mmap) __P((bus_dma_tag_t, bus_dma_segment_t *,
173 int, int, int, int));
174 };
175
176 #define genericbus_dma_get_tag(t, b) \
177 (*(t)->_get_tag)(t, b)
178
179 #define bus_dmamap_create(t, s, n, m, b, f, p) \
180 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
181 #define bus_dmamap_destroy(t, p) \
182 (*(t)->_dmamap_destroy)((t), (p))
183 #define bus_dmamap_load(t, m, b, s, p, f) \
184 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
185 #define bus_dmamap_load_mbuf(t, m, b, f) \
186 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
187 #define bus_dmamap_load_uio(t, m, u, f) \
188 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
189 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
190 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
191 #define bus_dmamap_unload(t, p) \
192 (*(t)->_dmamap_unload)((t), (p))
193 #define bus_dmamap_sync(t, p, o, l, ops) \
194 (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
195 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
196 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
197 #define bus_dmamem_free(t, sg, n) \
198 (*(t)->_dmamem_free)((t), (sg), (n))
199 #define bus_dmamem_map(t, sg, n, s, k, f) \
200 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
201 #define bus_dmamem_unmap(t, k, s) \
202 (*(t)->_dmamem_unmap)((t), (k), (s))
203 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
204 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
205
206 /*
207 * bus_dmamap_t
208 *
209 * Describes a DMA mapping.
210 */
211 struct generic_bus_dmamap {
212 /*
213 * PRIVATE MEMBERS: not for use my machine-independent code.
214 */
215 bus_size_t _dm_size; /* largest DMA transfer mappable */
216 int _dm_segcnt; /* number of segs this map can map */
217 bus_size_t _dm_maxsegsz; /* largest possible segment */
218 bus_size_t _dm_boundary; /* don't cross this */
219 int _dm_flags; /* misc. flags */
220
221 #if 0 /* useful on alpha, but not here */
222
223 /*
224 * This is used only for SGMAP-mapped DMA, but we keep it
225 * here to avoid pointless indirection.
226 */
227 int _dm_pteidx; /* PTE index */
228 int _dm_ptecnt; /* PTE count */
229 u_long _dm_sgva; /* allocated sgva */
230 bus_size_t _dm_sgvalen; /* svga length */
231 #endif
232
233 /*
234 * PUBLIC MEMBERS: these are used by machine-independent code.
235 */
236 bus_size_t dm_mapsize; /* size of the mapping */
237 int dm_nsegs; /* # valid segments in mapping */
238 bus_dma_segment_t dm_segs[1]; /* segments; variable length */
239 };
240
241 #ifdef _GENERIC_BUS_DMA_PRIVATE
242 int _bus_dmamap_create __P((bus_dma_tag_t, bus_size_t, int, bus_size_t,
243 bus_size_t, int, bus_dmamap_t *));
244 void _bus_dmamap_destroy __P((bus_dma_tag_t, bus_dmamap_t));
245
246 int _bus_dmamap_load_direct __P((bus_dma_tag_t, bus_dmamap_t,
247 void *, bus_size_t, struct proc *, int));
248 int _bus_dmamap_load_mbuf_direct __P((bus_dma_tag_t,
249 bus_dmamap_t, struct mbuf *, int));
250 int _bus_dmamap_load_uio_direct __P((bus_dma_tag_t,
251 bus_dmamap_t, struct uio *, int));
252 int _bus_dmamap_load_raw_direct __P((bus_dma_tag_t,
253 bus_dmamap_t, bus_dma_segment_t *, int, bus_size_t,
254 int));
255
256 void _bus_dmamap_unload __P((bus_dma_tag_t, bus_dmamap_t));
257 void _bus_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
258 bus_size_t, int));
259
260 int _bus_dmamem_alloc __P((bus_dma_tag_t tag, bus_size_t size,
261 bus_size_t alignment, bus_size_t boundary,
262 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags));
263 void _bus_dmamem_free __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
264 int nsegs));
265 int _bus_dmamem_map __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
266 int nsegs, size_t size, caddr_t *kvap, int flags));
267 void _bus_dmamem_unmap __P((bus_dma_tag_t tag, caddr_t kva,
268 size_t size));
269 int _bus_dmamem_mmap __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
270 int nsegs, int off, int prot, int flags));
271 #endif /* _GENERIC_BUS_DMA_PRIVATE */
272
273 #endif /* _BUS_DMA_H_ */
274