bus_dma.h revision 1.9.6.2 1 1.9.6.2 nathanw /* $NetBSD: bus_dma.h,v 1.9.6.2 2002/02/28 04:10:52 nathanw Exp $ */
2 1.9.6.2 nathanw
3 1.9.6.2 nathanw /*
4 1.9.6.2 nathanw * This file was extracted from from next68k/include/bus.h
5 1.9.6.2 nathanw * and should probably be resynced when needed.
6 1.9.6.2 nathanw * original cvs id: NetBSD: bus_dma.h,v 1.3 1999/08/05 01:50:59 dbj Exp
7 1.9.6.2 nathanw */
8 1.9.6.2 nathanw
9 1.9.6.2 nathanw /*-
10 1.9.6.2 nathanw * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
11 1.9.6.2 nathanw * All rights reserved.
12 1.9.6.2 nathanw *
13 1.9.6.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
14 1.9.6.2 nathanw * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
15 1.9.6.2 nathanw * NASA Ames Research Center.
16 1.9.6.2 nathanw *
17 1.9.6.2 nathanw * Redistribution and use in source and binary forms, with or without
18 1.9.6.2 nathanw * modification, are permitted provided that the following conditions
19 1.9.6.2 nathanw * are met:
20 1.9.6.2 nathanw * 1. Redistributions of source code must retain the above copyright
21 1.9.6.2 nathanw * notice, this list of conditions and the following disclaimer.
22 1.9.6.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
23 1.9.6.2 nathanw * notice, this list of conditions and the following disclaimer in the
24 1.9.6.2 nathanw * documentation and/or other materials provided with the distribution.
25 1.9.6.2 nathanw * 3. All advertising materials mentioning features or use of this software
26 1.9.6.2 nathanw * must display the following acknowledgement:
27 1.9.6.2 nathanw * This product includes software developed by the NetBSD
28 1.9.6.2 nathanw * Foundation, Inc. and its contributors.
29 1.9.6.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
30 1.9.6.2 nathanw * contributors may be used to endorse or promote products derived
31 1.9.6.2 nathanw * from this software without specific prior written permission.
32 1.9.6.2 nathanw *
33 1.9.6.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
34 1.9.6.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
35 1.9.6.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
36 1.9.6.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
37 1.9.6.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 1.9.6.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 1.9.6.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40 1.9.6.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41 1.9.6.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 1.9.6.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 1.9.6.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
44 1.9.6.2 nathanw */
45 1.9.6.2 nathanw
46 1.9.6.2 nathanw /*
47 1.9.6.2 nathanw * Copyright (c) 1996 Carnegie-Mellon University.
48 1.9.6.2 nathanw * All rights reserved.
49 1.9.6.2 nathanw *
50 1.9.6.2 nathanw * Author: Chris G. Demetriou
51 1.9.6.2 nathanw *
52 1.9.6.2 nathanw * Permission to use, copy, modify and distribute this software and
53 1.9.6.2 nathanw * its documentation is hereby granted, provided that both the copyright
54 1.9.6.2 nathanw * notice and this permission notice appear in all copies of the
55 1.9.6.2 nathanw * software, derivative works or modified versions, and any portions
56 1.9.6.2 nathanw * thereof, and that both notices appear in supporting documentation.
57 1.9.6.2 nathanw *
58 1.9.6.2 nathanw * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
59 1.9.6.2 nathanw * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
60 1.9.6.2 nathanw * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
61 1.9.6.2 nathanw *
62 1.9.6.2 nathanw * Carnegie Mellon requests users of this software to return to
63 1.9.6.2 nathanw *
64 1.9.6.2 nathanw * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
65 1.9.6.2 nathanw * School of Computer Science
66 1.9.6.2 nathanw * Carnegie Mellon University
67 1.9.6.2 nathanw * Pittsburgh PA 15213-3890
68 1.9.6.2 nathanw *
69 1.9.6.2 nathanw * any improvements or extensions that they make and grant Carnegie the
70 1.9.6.2 nathanw * rights to redistribute these changes.
71 1.9.6.2 nathanw */
72 1.9.6.2 nathanw
73 1.9.6.2 nathanw #ifndef _MVME68K_BUS_DMA_H_
74 1.9.6.2 nathanw #define _MVME68K_BUS_DMA_H_
75 1.9.6.2 nathanw
76 1.9.6.2 nathanw /*
77 1.9.6.2 nathanw * Bus DMA methods.
78 1.9.6.2 nathanw */
79 1.9.6.2 nathanw
80 1.9.6.2 nathanw /*
81 1.9.6.2 nathanw * Flags used in various bus DMA methods.
82 1.9.6.2 nathanw */
83 1.9.6.2 nathanw #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
84 1.9.6.2 nathanw #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
85 1.9.6.2 nathanw #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
86 1.9.6.2 nathanw #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
87 1.9.6.2 nathanw #define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */
88 1.9.6.2 nathanw #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
89 1.9.6.2 nathanw #define BUS_DMA_BUS2 0x020
90 1.9.6.2 nathanw #define BUS_DMA_BUS3 0x040
91 1.9.6.2 nathanw #define BUS_DMA_BUS4 0x080
92 1.9.6.2 nathanw #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
93 1.9.6.2 nathanw #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
94 1.9.6.2 nathanw
95 1.9.6.2 nathanw /*
96 1.9.6.2 nathanw * Flags to constrain the physical memory allocated for DMA
97 1.9.6.2 nathanw */
98 1.9.6.2 nathanw #define BUS_DMA_ONBOARD_RAM BUS_DMA_BUS1
99 1.9.6.2 nathanw #define BUS_DMA_24BIT BUS_DMA_BUS2
100 1.9.6.2 nathanw
101 1.9.6.2 nathanw /* Forwards needed by prototypes below. */
102 1.9.6.2 nathanw struct mbuf;
103 1.9.6.2 nathanw struct uio;
104 1.9.6.2 nathanw
105 1.9.6.2 nathanw /*
106 1.9.6.2 nathanw * Operations performed by bus_dmamap_sync().
107 1.9.6.2 nathanw */
108 1.9.6.2 nathanw #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
109 1.9.6.2 nathanw #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
110 1.9.6.2 nathanw #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
111 1.9.6.2 nathanw #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
112 1.9.6.2 nathanw
113 1.9.6.2 nathanw typedef struct mvme68k_bus_dma_tag *bus_dma_tag_t;
114 1.9.6.2 nathanw typedef struct mvme68k_bus_dmamap *bus_dmamap_t;
115 1.9.6.2 nathanw
116 1.9.6.2 nathanw /*
117 1.9.6.2 nathanw * bus_dma_segment_t
118 1.9.6.2 nathanw *
119 1.9.6.2 nathanw * Describes a single contiguous DMA transaction. Values
120 1.9.6.2 nathanw * are suitable for programming into DMA registers.
121 1.9.6.2 nathanw */
122 1.9.6.2 nathanw struct mvme68k_bus_dma_segment {
123 1.9.6.2 nathanw bus_addr_t ds_addr; /* DMA address */
124 1.9.6.2 nathanw bus_size_t ds_len; /* length of transfer */
125 1.9.6.2 nathanw
126 1.9.6.2 nathanw /* PRIVATE */
127 1.9.6.2 nathanw bus_addr_t _ds_cpuaddr; /* CPU-relative phys addr of segment */
128 1.9.6.2 nathanw int _ds_flags;
129 1.9.6.2 nathanw };
130 1.9.6.2 nathanw typedef struct mvme68k_bus_dma_segment bus_dma_segment_t;
131 1.9.6.2 nathanw
132 1.9.6.2 nathanw /*
133 1.9.6.2 nathanw * bus_dma_tag_t
134 1.9.6.2 nathanw *
135 1.9.6.2 nathanw * A machine-dependent opaque type describing the implementation of
136 1.9.6.2 nathanw * DMA for a given bus.
137 1.9.6.2 nathanw */
138 1.9.6.2 nathanw struct mvme68k_bus_dma_tag {
139 1.9.6.2 nathanw void *_cookie; /* cookie used in the guts */
140 1.9.6.2 nathanw
141 1.9.6.2 nathanw /*
142 1.9.6.2 nathanw * DMA mapping methods.
143 1.9.6.2 nathanw */
144 1.9.6.2 nathanw int (*_dmamap_create) __P((bus_dma_tag_t, bus_size_t, int,
145 1.9.6.2 nathanw bus_size_t, bus_size_t, int, bus_dmamap_t *));
146 1.9.6.2 nathanw void (*_dmamap_destroy) __P((bus_dma_tag_t, bus_dmamap_t));
147 1.9.6.2 nathanw int (*_dmamap_load) __P((bus_dma_tag_t, bus_dmamap_t, void *,
148 1.9.6.2 nathanw bus_size_t, struct proc *, int));
149 1.9.6.2 nathanw int (*_dmamap_load_mbuf) __P((bus_dma_tag_t, bus_dmamap_t,
150 1.9.6.2 nathanw struct mbuf *, int));
151 1.9.6.2 nathanw int (*_dmamap_load_uio) __P((bus_dma_tag_t, bus_dmamap_t,
152 1.9.6.2 nathanw struct uio *, int));
153 1.9.6.2 nathanw int (*_dmamap_load_raw) __P((bus_dma_tag_t, bus_dmamap_t,
154 1.9.6.2 nathanw bus_dma_segment_t *, int, bus_size_t, int));
155 1.9.6.2 nathanw void (*_dmamap_unload) __P((bus_dma_tag_t, bus_dmamap_t));
156 1.9.6.2 nathanw void (*_dmamap_sync) __P((bus_dma_tag_t, bus_dmamap_t,
157 1.9.6.2 nathanw bus_addr_t, bus_size_t, int));
158 1.9.6.2 nathanw
159 1.9.6.2 nathanw /*
160 1.9.6.2 nathanw * DMA memory utility functions.
161 1.9.6.2 nathanw */
162 1.9.6.2 nathanw int (*_dmamem_alloc) __P((bus_dma_tag_t, bus_size_t, bus_size_t,
163 1.9.6.2 nathanw bus_size_t, bus_dma_segment_t *, int, int *, int));
164 1.9.6.2 nathanw void (*_dmamem_free) __P((bus_dma_tag_t,
165 1.9.6.2 nathanw bus_dma_segment_t *, int));
166 1.9.6.2 nathanw int (*_dmamem_map) __P((bus_dma_tag_t, bus_dma_segment_t *,
167 1.9.6.2 nathanw int, size_t, caddr_t *, int));
168 1.9.6.2 nathanw void (*_dmamem_unmap) __P((bus_dma_tag_t, caddr_t, size_t));
169 1.9.6.2 nathanw paddr_t (*_dmamem_mmap) __P((bus_dma_tag_t, bus_dma_segment_t *,
170 1.9.6.2 nathanw int, off_t, int, int));
171 1.9.6.2 nathanw };
172 1.9.6.2 nathanw
173 1.9.6.2 nathanw #define bus_dmamap_create(t, s, n, m, b, f, p) \
174 1.9.6.2 nathanw (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
175 1.9.6.2 nathanw #define bus_dmamap_destroy(t, p) \
176 1.9.6.2 nathanw (*(t)->_dmamap_destroy)((t), (p))
177 1.9.6.2 nathanw #define bus_dmamap_load(t, m, b, s, p, f) \
178 1.9.6.2 nathanw (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
179 1.9.6.2 nathanw #define bus_dmamap_load_mbuf(t, m, b, f) \
180 1.9.6.2 nathanw (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
181 1.9.6.2 nathanw #define bus_dmamap_load_uio(t, m, u, f) \
182 1.9.6.2 nathanw (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
183 1.9.6.2 nathanw #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
184 1.9.6.2 nathanw (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
185 1.9.6.2 nathanw #define bus_dmamap_unload(t, p) \
186 1.9.6.2 nathanw (*(t)->_dmamap_unload)((t), (p))
187 1.9.6.2 nathanw #define bus_dmamap_sync(t, p, o, l, ops) \
188 1.9.6.2 nathanw (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
189 1.9.6.2 nathanw #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
190 1.9.6.2 nathanw (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
191 1.9.6.2 nathanw #define bus_dmamem_free(t, sg, n) \
192 1.9.6.2 nathanw (*(t)->_dmamem_free)((t), (sg), (n))
193 1.9.6.2 nathanw #define bus_dmamem_map(t, sg, n, s, k, f) \
194 1.9.6.2 nathanw (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
195 1.9.6.2 nathanw #define bus_dmamem_unmap(t, k, s) \
196 1.9.6.2 nathanw (*(t)->_dmamem_unmap)((t), (k), (s))
197 1.9.6.2 nathanw #define bus_dmamem_mmap(t, sg, n, o, p, f) \
198 1.9.6.2 nathanw (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
199 1.9.6.2 nathanw
200 1.9.6.2 nathanw /*
201 1.9.6.2 nathanw * bus_dmamap_t
202 1.9.6.2 nathanw *
203 1.9.6.2 nathanw * Describes a DMA mapping.
204 1.9.6.2 nathanw */
205 1.9.6.2 nathanw struct mvme68k_bus_dmamap {
206 1.9.6.2 nathanw /*
207 1.9.6.2 nathanw * PRIVATE MEMBERS: not for use by machine-independent code.
208 1.9.6.2 nathanw */
209 1.9.6.2 nathanw bus_size_t _dm_size; /* largest DMA transfer mappable */
210 1.9.6.2 nathanw int _dm_segcnt; /* number of segs this map can map */
211 1.9.6.2 nathanw bus_size_t _dm_maxsegsz; /* largest possible segment */
212 1.9.6.2 nathanw bus_size_t _dm_boundary; /* don't cross this */
213 1.9.6.2 nathanw int _dm_flags; /* misc. flags */
214 1.9.6.2 nathanw void *_dm_cookie; /* Bus-specific cookie */
215 1.9.6.2 nathanw
216 1.9.6.2 nathanw /*
217 1.9.6.2 nathanw * PUBLIC MEMBERS: these are used by machine-independent code.
218 1.9.6.2 nathanw */
219 1.9.6.2 nathanw bus_size_t dm_mapsize; /* size of the mapping */
220 1.9.6.2 nathanw int dm_nsegs; /* # valid segments in mapping */
221 1.9.6.2 nathanw bus_dma_segment_t dm_segs[1]; /* segments; variable length */
222 1.9.6.2 nathanw };
223 1.9.6.2 nathanw
224 1.9.6.2 nathanw #ifdef _MVME68K_BUS_DMA_PRIVATE
225 1.9.6.2 nathanw int _bus_dmamap_create __P((bus_dma_tag_t, bus_size_t, int, bus_size_t,
226 1.9.6.2 nathanw bus_size_t, int, bus_dmamap_t *));
227 1.9.6.2 nathanw void _bus_dmamap_destroy __P((bus_dma_tag_t, bus_dmamap_t));
228 1.9.6.2 nathanw
229 1.9.6.2 nathanw int _bus_dmamap_load_direct __P((bus_dma_tag_t, bus_dmamap_t,
230 1.9.6.2 nathanw void *, bus_size_t, struct proc *, int));
231 1.9.6.2 nathanw int _bus_dmamap_load_mbuf_direct __P((bus_dma_tag_t,
232 1.9.6.2 nathanw bus_dmamap_t, struct mbuf *, int));
233 1.9.6.2 nathanw int _bus_dmamap_load_uio_direct __P((bus_dma_tag_t,
234 1.9.6.2 nathanw bus_dmamap_t, struct uio *, int));
235 1.9.6.2 nathanw int _bus_dmamap_load_raw_direct __P((bus_dma_tag_t,
236 1.9.6.2 nathanw bus_dmamap_t, bus_dma_segment_t *, int, bus_size_t, int));
237 1.9.6.2 nathanw void _bus_dmamap_unload __P((bus_dma_tag_t, bus_dmamap_t));
238 1.9.6.2 nathanw void _bus_dmamap_sync_030 __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
239 1.9.6.2 nathanw bus_size_t, int));
240 1.9.6.2 nathanw void _bus_dmamap_sync_0460 __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
241 1.9.6.2 nathanw bus_size_t, int));
242 1.9.6.2 nathanw int _bus_dmamem_alloc __P((bus_dma_tag_t tag, bus_size_t size,
243 1.9.6.2 nathanw bus_size_t alignment, bus_size_t boundary,
244 1.9.6.2 nathanw bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags));
245 1.9.6.2 nathanw void _bus_dmamem_free __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
246 1.9.6.2 nathanw int nsegs));
247 1.9.6.2 nathanw int _bus_dmamem_map __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
248 1.9.6.2 nathanw int nsegs, size_t size, caddr_t *kvap, int flags));
249 1.9.6.2 nathanw void _bus_dmamem_unmap __P((bus_dma_tag_t tag, caddr_t kva,
250 1.9.6.2 nathanw size_t size));
251 1.9.6.2 nathanw paddr_t _bus_dmamem_mmap __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
252 1.9.6.2 nathanw int nsegs, off_t off, int prot, int flags));
253 1.9.6.2 nathanw #endif /* _MVME68K_BUS_DMA_PRIVATE */
254 1.9.6.2 nathanw
255 1.9.6.2 nathanw /* Needed by mvmebus.c */
256 1.9.6.2 nathanw int _bus_dmamem_alloc_common __P((bus_dma_tag_t,
257 1.9.6.2 nathanw bus_addr_t, bus_addr_t, bus_size_t, bus_size_t, bus_size_t,
258 1.9.6.2 nathanw bus_dma_segment_t *, int, int *, int));
259 1.9.6.2 nathanw
260 1.9.6.2 nathanw #endif /* _MVME68K_BUS_DMA_H_ */
261