tc_dma_3000_500.c revision 1.1.2.1 1 1.1.2.1 thorpej /* $NetBSD: tc_dma_3000_500.c,v 1.1.2.1 1997/06/06 02:41:14 thorpej Exp $ */
2 1.1.2.1 thorpej
3 1.1.2.1 thorpej /*-
4 1.1.2.1 thorpej * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 1.1.2.1 thorpej * All rights reserved.
6 1.1.2.1 thorpej *
7 1.1.2.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.1 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1.2.1 thorpej * NASA Ames Research Center.
10 1.1.2.1 thorpej *
11 1.1.2.1 thorpej * Redistribution and use in source and binary forms, with or without
12 1.1.2.1 thorpej * modification, are permitted provided that the following conditions
13 1.1.2.1 thorpej * are met:
14 1.1.2.1 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.1.2.1 thorpej * notice, this list of conditions and the following disclaimer.
16 1.1.2.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.1.2.1 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.1.2.1 thorpej * documentation and/or other materials provided with the distribution.
19 1.1.2.1 thorpej * 3. All advertising materials mentioning features or use of this software
20 1.1.2.1 thorpej * must display the following acknowledgement:
21 1.1.2.1 thorpej * This product includes software developed by the NetBSD
22 1.1.2.1 thorpej * Foundation, Inc. and its contributors.
23 1.1.2.1 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1.2.1 thorpej * contributors may be used to endorse or promote products derived
25 1.1.2.1 thorpej * from this software without specific prior written permission.
26 1.1.2.1 thorpej *
27 1.1.2.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1.2.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1.2.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1.2.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1.2.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1.2.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1.2.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1.2.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1.2.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1.2.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1.2.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
38 1.1.2.1 thorpej */
39 1.1.2.1 thorpej
40 1.1.2.1 thorpej #include <machine/options.h> /* Config options headers */
41 1.1.2.1 thorpej #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
42 1.1.2.1 thorpej
43 1.1.2.1 thorpej __KERNEL_RCSID(0, "$NetBSD: tc_dma_3000_500.c,v 1.1.2.1 1997/06/06 02:41:14 thorpej Exp $");
44 1.1.2.1 thorpej
45 1.1.2.1 thorpej #include <sys/param.h>
46 1.1.2.1 thorpej #include <sys/systm.h>
47 1.1.2.1 thorpej #include <sys/kernel.h>
48 1.1.2.1 thorpej #include <sys/malloc.h>
49 1.1.2.1 thorpej #include <vm/vm.h>
50 1.1.2.1 thorpej
51 1.1.2.1 thorpej #define _ALPHA_BUS_DMA_PRIVATE
52 1.1.2.1 thorpej #include <machine/bus.h>
53 1.1.2.1 thorpej
54 1.1.2.1 thorpej #include <dev/tc/tcvar.h>
55 1.1.2.1 thorpej #include <alpha/tc/tc_sgmap.h>
56 1.1.2.1 thorpej #include <alpha/tc/tc_dma_3000_500.h>
57 1.1.2.1 thorpej
58 1.1.2.1 thorpej struct alpha_bus_dma_tag tc_dmat_sgmap = {
59 1.1.2.1 thorpej NULL, /* _cookie */
60 1.1.2.1 thorpej NULL, /* _get_tag */
61 1.1.2.1 thorpej tc_bus_dmamap_create_sgmap,
62 1.1.2.1 thorpej tc_bus_dmamap_destroy_sgmap,
63 1.1.2.1 thorpej tc_bus_dmamap_load_sgmap,
64 1.1.2.1 thorpej tc_bus_dmamap_load_mbuf_sgmap,
65 1.1.2.1 thorpej tc_bus_dmamap_load_uio_sgmap,
66 1.1.2.1 thorpej tc_bus_dmamap_load_raw_sgmap,
67 1.1.2.1 thorpej tc_bus_dmamap_unload_sgmap,
68 1.1.2.1 thorpej NULL, /* _dmamap_sync */
69 1.1.2.1 thorpej _bus_dmamem_alloc,
70 1.1.2.1 thorpej _bus_dmamem_free,
71 1.1.2.1 thorpej _bus_dmamem_map,
72 1.1.2.1 thorpej _bus_dmamem_unmap,
73 1.1.2.1 thorpej _bus_dmamem_mmap,
74 1.1.2.1 thorpej };
75 1.1.2.1 thorpej
76 1.1.2.1 thorpej struct tc_dma_slot_info {
77 1.1.2.1 thorpej struct alpha_sgmap tdsi_sgmap; /* sgmap for slot */
78 1.1.2.1 thorpej struct alpha_bus_dma_tag tdsi_dmat; /* dma tag for slot */
79 1.1.2.1 thorpej };
80 1.1.2.1 thorpej struct tc_dma_slot_info *tc_dma_slot_info;
81 1.1.2.1 thorpej
82 1.1.2.1 thorpej void
83 1.1.2.1 thorpej tc_dma_init_3000_500(nslots)
84 1.1.2.1 thorpej int nslots;
85 1.1.2.1 thorpej {
86 1.1.2.1 thorpej extern struct alpha_bus_dma_tag tc_dmat_direct;
87 1.1.2.1 thorpej size_t sisize;
88 1.1.2.1 thorpej int i;
89 1.1.2.1 thorpej
90 1.1.2.1 thorpej /* Allocate per-slot DMA info. */
91 1.1.2.1 thorpej sisize = nslots * sizeof(struct tc_dma_slot_info);
92 1.1.2.1 thorpej tc_dma_slot_info = malloc(sisize, M_DEVBUF, M_NOWAIT);
93 1.1.2.1 thorpej if (tc_dma_slot_info == NULL)
94 1.1.2.1 thorpej panic("tc_dma_init: can't allocate per-slot DMA info");
95 1.1.2.1 thorpej bzero(tc_dma_slot_info, sisize);
96 1.1.2.1 thorpej
97 1.1.2.1 thorpej /* Default all slots to direct-mapped. */
98 1.1.2.1 thorpej for (i = 0; i < nslots; i++)
99 1.1.2.1 thorpej bcopy(&tc_dmat_direct, &tc_dma_slot_info[i].tdsi_dmat,
100 1.1.2.1 thorpej sizeof(tc_dma_slot_info[i].tdsi_dmat));
101 1.1.2.1 thorpej }
102 1.1.2.1 thorpej
103 1.1.2.1 thorpej /*
104 1.1.2.1 thorpej * Return the DMA tag for the given slot.
105 1.1.2.1 thorpej */
106 1.1.2.1 thorpej bus_dma_tag_t
107 1.1.2.1 thorpej tc_dma_get_tag_3000_500(slot)
108 1.1.2.1 thorpej int slot;
109 1.1.2.1 thorpej {
110 1.1.2.1 thorpej
111 1.1.2.1 thorpej return (&tc_dma_slot_info[slot].tdsi_dmat);
112 1.1.2.1 thorpej }
113 1.1.2.1 thorpej
114 1.1.2.1 thorpej /*
115 1.1.2.1 thorpej * Create a TurboChannel SGMAP-mapped DMA map.
116 1.1.2.1 thorpej */
117 1.1.2.1 thorpej int
118 1.1.2.1 thorpej tc_bus_dmamap_create_sgmap(t, size, nsegments, maxsegsz, boundary,
119 1.1.2.1 thorpej flags, dmamp)
120 1.1.2.1 thorpej bus_dma_tag_t t;
121 1.1.2.1 thorpej bus_size_t size;
122 1.1.2.1 thorpej int nsegments;
123 1.1.2.1 thorpej bus_size_t maxsegsz;
124 1.1.2.1 thorpej bus_size_t boundary;
125 1.1.2.1 thorpej int flags;
126 1.1.2.1 thorpej bus_dmamap_t *dmamp;
127 1.1.2.1 thorpej {
128 1.1.2.1 thorpej struct tc_dma_slot_info *tdsi = t->_cookie;
129 1.1.2.1 thorpej struct alpha_sgmap_cookie *a;
130 1.1.2.1 thorpej bus_dmamap_t map;
131 1.1.2.1 thorpej int error;
132 1.1.2.1 thorpej
133 1.1.2.1 thorpej error = _bus_dmamap_create(t, size, nsegments, maxsegsz,
134 1.1.2.1 thorpej boundary, flags, dmamp);
135 1.1.2.1 thorpej if (error)
136 1.1.2.1 thorpej return (error);
137 1.1.2.1 thorpej
138 1.1.2.1 thorpej map = *dmamp;
139 1.1.2.1 thorpej
140 1.1.2.1 thorpej a = malloc(sizeof(struct alpha_sgmap_cookie), M_DEVBUF,
141 1.1.2.1 thorpej (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK);
142 1.1.2.1 thorpej if (a == NULL) {
143 1.1.2.1 thorpej _bus_dmamap_destroy(t, map);
144 1.1.2.1 thorpej return (ENOMEM);
145 1.1.2.1 thorpej }
146 1.1.2.1 thorpej bzero(a, sizeof(struct alpha_sgmap_cookie));
147 1.1.2.1 thorpej map->_dm_sgcookie = a;
148 1.1.2.1 thorpej
149 1.1.2.1 thorpej if (flags & BUS_DMA_ALLOCNOW) {
150 1.1.2.1 thorpej error = alpha_sgmap_alloc(map, round_page(size),
151 1.1.2.1 thorpej &tdsi->tdsi_sgmap, flags);
152 1.1.2.1 thorpej if (error)
153 1.1.2.1 thorpej tc_bus_dmamap_destroy_sgmap(t, map);
154 1.1.2.1 thorpej }
155 1.1.2.1 thorpej
156 1.1.2.1 thorpej return (error);
157 1.1.2.1 thorpej }
158 1.1.2.1 thorpej
159 1.1.2.1 thorpej /*
160 1.1.2.1 thorpej * Destroy a TurboChannel SGMAP-mapped DMA map.
161 1.1.2.1 thorpej */
162 1.1.2.1 thorpej void
163 1.1.2.1 thorpej tc_bus_dmamap_destroy_sgmap(t, map)
164 1.1.2.1 thorpej bus_dma_tag_t t;
165 1.1.2.1 thorpej bus_dmamap_t map;
166 1.1.2.1 thorpej {
167 1.1.2.1 thorpej struct tc_dma_slot_info *tdsi = t->_cookie;
168 1.1.2.1 thorpej struct alpha_sgmap_cookie *a = map->_dm_sgcookie;
169 1.1.2.1 thorpej
170 1.1.2.1 thorpej if (a->apdc_flags & APDC_HAS_SGMAP)
171 1.1.2.1 thorpej alpha_sgmap_free(&tdsi->tdsi_sgmap, a);
172 1.1.2.1 thorpej
173 1.1.2.1 thorpej free(a, M_DEVBUF);
174 1.1.2.1 thorpej _bus_dmamap_destroy(t, map);
175 1.1.2.1 thorpej }
176 1.1.2.1 thorpej
177 1.1.2.1 thorpej /*
178 1.1.2.1 thorpej * Load a TurboChannel SGMAP-mapped DMA map with a linear buffer.
179 1.1.2.1 thorpej */
180 1.1.2.1 thorpej int
181 1.1.2.1 thorpej tc_bus_dmamap_load_sgmap(t, map, buf, buflen, p, flags)
182 1.1.2.1 thorpej bus_dma_tag_t t;
183 1.1.2.1 thorpej bus_dmamap_t map;
184 1.1.2.1 thorpej void *buf;
185 1.1.2.1 thorpej bus_size_t buflen;
186 1.1.2.1 thorpej struct proc *p;
187 1.1.2.1 thorpej int flags;
188 1.1.2.1 thorpej {
189 1.1.2.1 thorpej struct tc_dma_slot_info *tdsi = t->_cookie;
190 1.1.2.1 thorpej
191 1.1.2.1 thorpej return (tc_sgmap_load(t, map, buf, buflen, p, flags,
192 1.1.2.1 thorpej &tdsi->tdsi_sgmap));
193 1.1.2.1 thorpej }
194 1.1.2.1 thorpej
195 1.1.2.1 thorpej /*
196 1.1.2.1 thorpej * Load a TurboChannel SGMAP-mapped DMA map with an mbuf chain.
197 1.1.2.1 thorpej */
198 1.1.2.1 thorpej int
199 1.1.2.1 thorpej tc_bus_dmamap_load_mbuf_sgmap(t, map, m, flags)
200 1.1.2.1 thorpej bus_dma_tag_t t;
201 1.1.2.1 thorpej bus_dmamap_t map;
202 1.1.2.1 thorpej struct mbuf *m;
203 1.1.2.1 thorpej int flags;
204 1.1.2.1 thorpej {
205 1.1.2.1 thorpej struct tc_dma_slot_info *tdsi = t->_cookie;
206 1.1.2.1 thorpej
207 1.1.2.1 thorpej return (tc_sgmap_load_mbuf(t, map, m, flags, &tdsi->tdsi_sgmap));
208 1.1.2.1 thorpej }
209 1.1.2.1 thorpej
210 1.1.2.1 thorpej /*
211 1.1.2.1 thorpej * Load a TurboChannel SGMAP-mapped DMA map with a uio.
212 1.1.2.1 thorpej */
213 1.1.2.1 thorpej int
214 1.1.2.1 thorpej tc_bus_dmamap_load_uio_sgmap(t, map, uio, flags)
215 1.1.2.1 thorpej bus_dma_tag_t t;
216 1.1.2.1 thorpej bus_dmamap_t map;
217 1.1.2.1 thorpej struct uio *uio;
218 1.1.2.1 thorpej int flags;
219 1.1.2.1 thorpej {
220 1.1.2.1 thorpej struct tc_dma_slot_info *tdsi = t->_cookie;
221 1.1.2.1 thorpej
222 1.1.2.1 thorpej return (tc_sgmap_load_uio(t, map, uio, flags, &tdsi->tdsi_sgmap));
223 1.1.2.1 thorpej }
224 1.1.2.1 thorpej
225 1.1.2.1 thorpej /*
226 1.1.2.1 thorpej * Load a TurboChannel SGMAP-mapped DMA map with raw memory.
227 1.1.2.1 thorpej */
228 1.1.2.1 thorpej int
229 1.1.2.1 thorpej tc_bus_dmamap_load_raw_sgmap(t, map, segs, nsegs, size, flags)
230 1.1.2.1 thorpej bus_dma_tag_t t;
231 1.1.2.1 thorpej bus_dmamap_t map;
232 1.1.2.1 thorpej bus_dma_segment_t *segs;
233 1.1.2.1 thorpej int nsegs;
234 1.1.2.1 thorpej bus_size_t size;
235 1.1.2.1 thorpej int flags;
236 1.1.2.1 thorpej {
237 1.1.2.1 thorpej struct tc_dma_slot_info *tdsi = t->_cookie;
238 1.1.2.1 thorpej
239 1.1.2.1 thorpej return (tc_sgmap_load_raw(t, map, segs, nsegs, size, flags,
240 1.1.2.1 thorpej &tdsi->tdsi_sgmap));
241 1.1.2.1 thorpej }
242 1.1.2.1 thorpej
243 1.1.2.1 thorpej /*
244 1.1.2.1 thorpej * Unload a TurboChannel SGMAP-mapped DMA map.
245 1.1.2.1 thorpej */
246 1.1.2.1 thorpej void
247 1.1.2.1 thorpej tc_bus_dmamap_unload_sgmap(t, map)
248 1.1.2.1 thorpej bus_dma_tag_t t;
249 1.1.2.1 thorpej bus_dmamap_t map;
250 1.1.2.1 thorpej {
251 1.1.2.1 thorpej struct tc_dma_slot_info *tdsi = t->_cookie;
252 1.1.2.1 thorpej
253 1.1.2.1 thorpej /*
254 1.1.2.1 thorpej * Invalidate any SGMAP page table entries used by this
255 1.1.2.1 thorpej * mapping.
256 1.1.2.1 thorpej */
257 1.1.2.1 thorpej tc_sgmap_unload(t, map, &tdsi->tdsi_sgmap);
258 1.1.2.1 thorpej
259 1.1.2.1 thorpej /*
260 1.1.2.1 thorpej * Do the generic bits of the unload.
261 1.1.2.1 thorpej */
262 1.1.2.1 thorpej _bus_dmamap_unload(t, map);
263 1.1.2.1 thorpej }
264