tc_dma_3000_500.c revision 1.14 1 /* $NetBSD: tc_dma_3000_500.c,v 1.14 2008/04/28 20:23:12 martin 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 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
34
35 __KERNEL_RCSID(0, "$NetBSD: tc_dma_3000_500.c,v 1.14 2008/04/28 20:23:12 martin Exp $");
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 #include <sys/kernel.h>
41 #include <sys/malloc.h>
42
43 #include <uvm/uvm_extern.h>
44
45 #define _ALPHA_BUS_DMA_PRIVATE
46 #include <machine/bus.h>
47
48 #include <dev/tc/tcvar.h>
49 #include <alpha/tc/tc_sgmap.h>
50 #include <alpha/tc/tc_dma_3000_500.h>
51
52 struct alpha_bus_dma_tag tc_dmat_sgmap = {
53 NULL, /* _cookie */
54 0, /* _wbase */
55 0, /* _wsize */
56 NULL, /* _next_window */
57 0, /* _boundary */
58 NULL, /* _sgmap */
59 0, /* _pfthresh */
60 NULL, /* _get_tag */
61 tc_bus_dmamap_create_sgmap,
62 tc_bus_dmamap_destroy_sgmap,
63 tc_bus_dmamap_load_sgmap,
64 tc_bus_dmamap_load_mbuf_sgmap,
65 tc_bus_dmamap_load_uio_sgmap,
66 tc_bus_dmamap_load_raw_sgmap,
67 tc_bus_dmamap_unload_sgmap,
68 _bus_dmamap_sync,
69 _bus_dmamem_alloc,
70 _bus_dmamem_free,
71 _bus_dmamem_map,
72 _bus_dmamem_unmap,
73 _bus_dmamem_mmap,
74 };
75
76 struct tc_dma_slot_info {
77 struct alpha_sgmap tdsi_sgmap; /* sgmap for slot */
78 struct alpha_bus_dma_tag tdsi_dmat; /* dma tag for slot */
79 };
80 struct tc_dma_slot_info *tc_dma_slot_info;
81
82 void
83 tc_dma_init_3000_500(nslots)
84 int nslots;
85 {
86 extern struct alpha_bus_dma_tag tc_dmat_direct;
87 size_t sisize;
88 int i;
89
90 /* Allocate per-slot DMA info. */
91 sisize = nslots * sizeof(struct tc_dma_slot_info);
92 tc_dma_slot_info = malloc(sisize, M_DEVBUF, M_NOWAIT);
93 if (tc_dma_slot_info == NULL)
94 panic("tc_dma_init: can't allocate per-slot DMA info");
95 memset(tc_dma_slot_info, 0, sisize);
96
97 /* Default all slots to direct-mapped. */
98 for (i = 0; i < nslots; i++)
99 memcpy(&tc_dma_slot_info[i].tdsi_dmat, &tc_dmat_direct,
100 sizeof(tc_dma_slot_info[i].tdsi_dmat));
101 }
102
103 /*
104 * Return the DMA tag for the given slot.
105 */
106 bus_dma_tag_t
107 tc_dma_get_tag_3000_500(slot)
108 int slot;
109 {
110
111 return (&tc_dma_slot_info[slot].tdsi_dmat);
112 }
113
114 /*
115 * Create a TurboChannel SGMAP-mapped DMA map.
116 */
117 int
118 tc_bus_dmamap_create_sgmap(t, size, nsegments, maxsegsz, boundary,
119 flags, dmamp)
120 bus_dma_tag_t t;
121 bus_size_t size;
122 int nsegments;
123 bus_size_t maxsegsz;
124 bus_size_t boundary;
125 int flags;
126 bus_dmamap_t *dmamp;
127 {
128 bus_dmamap_t map;
129 int error;
130
131 error = _bus_dmamap_create(t, size, nsegments, maxsegsz,
132 boundary, flags, dmamp);
133 if (error)
134 return (error);
135
136 map = *dmamp;
137
138 /* XXX BUS_DMA_ALLOCNOW */
139
140 return (error);
141 }
142
143 /*
144 * Destroy a TurboChannel SGMAP-mapped DMA map.
145 */
146 void
147 tc_bus_dmamap_destroy_sgmap(t, map)
148 bus_dma_tag_t t;
149 bus_dmamap_t map;
150 {
151
152 KASSERT(map->dm_mapsize == 0);
153
154 _bus_dmamap_destroy(t, map);
155 }
156
157 /*
158 * Load a TurboChannel SGMAP-mapped DMA map with a linear buffer.
159 */
160 int
161 tc_bus_dmamap_load_sgmap(t, map, buf, buflen, p, flags)
162 bus_dma_tag_t t;
163 bus_dmamap_t map;
164 void *buf;
165 bus_size_t buflen;
166 struct proc *p;
167 int flags;
168 {
169 struct tc_dma_slot_info *tdsi = t->_cookie;
170
171 return (tc_sgmap_load(t, map, buf, buflen, p, flags,
172 &tdsi->tdsi_sgmap));
173 }
174
175 /*
176 * Load a TurboChannel SGMAP-mapped DMA map with an mbuf chain.
177 */
178 int
179 tc_bus_dmamap_load_mbuf_sgmap(t, map, m, flags)
180 bus_dma_tag_t t;
181 bus_dmamap_t map;
182 struct mbuf *m;
183 int flags;
184 {
185 struct tc_dma_slot_info *tdsi = t->_cookie;
186
187 return (tc_sgmap_load_mbuf(t, map, m, flags, &tdsi->tdsi_sgmap));
188 }
189
190 /*
191 * Load a TurboChannel SGMAP-mapped DMA map with a uio.
192 */
193 int
194 tc_bus_dmamap_load_uio_sgmap(t, map, uio, flags)
195 bus_dma_tag_t t;
196 bus_dmamap_t map;
197 struct uio *uio;
198 int flags;
199 {
200 struct tc_dma_slot_info *tdsi = t->_cookie;
201
202 return (tc_sgmap_load_uio(t, map, uio, flags, &tdsi->tdsi_sgmap));
203 }
204
205 /*
206 * Load a TurboChannel SGMAP-mapped DMA map with raw memory.
207 */
208 int
209 tc_bus_dmamap_load_raw_sgmap(t, map, segs, nsegs, size, flags)
210 bus_dma_tag_t t;
211 bus_dmamap_t map;
212 bus_dma_segment_t *segs;
213 int nsegs;
214 bus_size_t size;
215 int flags;
216 {
217 struct tc_dma_slot_info *tdsi = t->_cookie;
218
219 return (tc_sgmap_load_raw(t, map, segs, nsegs, size, flags,
220 &tdsi->tdsi_sgmap));
221 }
222
223 /*
224 * Unload a TurboChannel SGMAP-mapped DMA map.
225 */
226 void
227 tc_bus_dmamap_unload_sgmap(t, map)
228 bus_dma_tag_t t;
229 bus_dmamap_t map;
230 {
231 struct tc_dma_slot_info *tdsi = t->_cookie;
232
233 /*
234 * Invalidate any SGMAP page table entries used by this
235 * mapping.
236 */
237 tc_sgmap_unload(t, map, &tdsi->tdsi_sgmap);
238
239 /*
240 * Do the generic bits of the unload.
241 */
242 _bus_dmamap_unload(t, map);
243 }
244