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