tsp_dma.c revision 1.4.2.2 1 1.4.2.2 thorpej /* $NetBSD: tsp_dma.c,v 1.4.2.2 2001/07/19 19:09:23 thorpej Exp $ */
2 1.4.2.2 thorpej
3 1.4.2.2 thorpej /*-
4 1.4.2.2 thorpej * Copyright (c) 1999 by Ross Harvey. All rights reserved.
5 1.4.2.2 thorpej *
6 1.4.2.2 thorpej * Redistribution and use in source and binary forms, with or without
7 1.4.2.2 thorpej * modification, are permitted provided that the following conditions
8 1.4.2.2 thorpej * are met:
9 1.4.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
10 1.4.2.2 thorpej * notice, this list of conditions and the following disclaimer.
11 1.4.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
12 1.4.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
13 1.4.2.2 thorpej * documentation and/or other materials provided with the distribution.
14 1.4.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
15 1.4.2.2 thorpej * must display the following acknowledgement:
16 1.4.2.2 thorpej * This product includes software developed by Ross Harvey.
17 1.4.2.2 thorpej * 4. The name of Ross Harvey may not be used to endorse or promote products
18 1.4.2.2 thorpej * derived from this software without specific prior written permission.
19 1.4.2.2 thorpej *
20 1.4.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY ROSS HARVEY ``AS IS'' AND ANY EXPRESS
21 1.4.2.2 thorpej * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 1.4.2.2 thorpej * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP0SE
23 1.4.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL ROSS HARVEY BE LIABLE FOR ANY
24 1.4.2.2 thorpej * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.4.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.4.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.4.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.4.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.4.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.4.2.2 thorpej * SUCH DAMAGE.
31 1.4.2.2 thorpej *
32 1.4.2.2 thorpej */
33 1.4.2.2 thorpej
34 1.4.2.2 thorpej /*-
35 1.4.2.2 thorpej * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
36 1.4.2.2 thorpej * All rights reserved.
37 1.4.2.2 thorpej *
38 1.4.2.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
39 1.4.2.2 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
40 1.4.2.2 thorpej * NASA Ames Research Center.
41 1.4.2.2 thorpej *
42 1.4.2.2 thorpej * Redistribution and use in source and binary forms, with or without
43 1.4.2.2 thorpej * modification, are permitted provided that the following conditions
44 1.4.2.2 thorpej * are met:
45 1.4.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
46 1.4.2.2 thorpej * notice, this list of conditions and the following disclaimer.
47 1.4.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
48 1.4.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
49 1.4.2.2 thorpej * documentation and/or other materials provided with the distribution.
50 1.4.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
51 1.4.2.2 thorpej * must display the following acknowledgement:
52 1.4.2.2 thorpej * This product includes software developed by the NetBSD
53 1.4.2.2 thorpej * Foundation, Inc. and its contributors.
54 1.4.2.2 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
55 1.4.2.2 thorpej * contributors may be used to endorse or promote products derived
56 1.4.2.2 thorpej * from this software without specific prior written permission.
57 1.4.2.2 thorpej *
58 1.4.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
59 1.4.2.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
60 1.4.2.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
61 1.4.2.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
62 1.4.2.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
63 1.4.2.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
64 1.4.2.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
65 1.4.2.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
66 1.4.2.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
67 1.4.2.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
68 1.4.2.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
69 1.4.2.2 thorpej */
70 1.4.2.2 thorpej
71 1.4.2.2 thorpej #include <sys/param.h>
72 1.4.2.2 thorpej #include <sys/systm.h>
73 1.4.2.2 thorpej #include <sys/kernel.h>
74 1.4.2.2 thorpej #include <sys/device.h>
75 1.4.2.2 thorpej #include <sys/malloc.h>
76 1.4.2.2 thorpej
77 1.4.2.2 thorpej #include <uvm/uvm_extern.h>
78 1.4.2.2 thorpej
79 1.4.2.2 thorpej #include <machine/autoconf.h>
80 1.4.2.2 thorpej #define _ALPHA_BUS_DMA_PRIVATE
81 1.4.2.2 thorpej #include <machine/bus.h>
82 1.4.2.2 thorpej #include <machine/rpb.h>
83 1.4.2.2 thorpej
84 1.4.2.2 thorpej #include <dev/pci/pcireg.h>
85 1.4.2.2 thorpej #include <dev/pci/pcivar.h>
86 1.4.2.2 thorpej #include <alpha/pci/tsreg.h>
87 1.4.2.2 thorpej #include <alpha/pci/tsvar.h>
88 1.4.2.2 thorpej
89 1.4.2.2 thorpej #define tsp_dma() { Generate ctags(1) key. }
90 1.4.2.2 thorpej
91 1.4.2.2 thorpej #define EDIFF(a, b) (((a) | WSBA_ENA | WSBA_SG) != ((b) | WSBA_ENA | WSBA_SG))
92 1.4.2.2 thorpej
93 1.4.2.2 thorpej bus_dma_tag_t tsp_dma_get_tag __P((bus_dma_tag_t, alpha_bus_t));
94 1.4.2.2 thorpej
95 1.4.2.2 thorpej int tsp_bus_dmamap_load_sgmap __P((bus_dma_tag_t, bus_dmamap_t, void *,
96 1.4.2.2 thorpej bus_size_t, struct proc *, int));
97 1.4.2.2 thorpej
98 1.4.2.2 thorpej int tsp_bus_dmamap_load_mbuf_sgmap __P((bus_dma_tag_t, bus_dmamap_t,
99 1.4.2.2 thorpej struct mbuf *, int));
100 1.4.2.2 thorpej
101 1.4.2.2 thorpej int tsp_bus_dmamap_load_uio_sgmap __P((bus_dma_tag_t, bus_dmamap_t,
102 1.4.2.2 thorpej struct uio *, int));
103 1.4.2.2 thorpej
104 1.4.2.2 thorpej int tsp_bus_dmamap_load_raw_sgmap __P((bus_dma_tag_t, bus_dmamap_t,
105 1.4.2.2 thorpej bus_dma_segment_t *, int, bus_size_t, int));
106 1.4.2.2 thorpej
107 1.4.2.2 thorpej void tsp_bus_dmamap_unload_sgmap __P((bus_dma_tag_t, bus_dmamap_t));
108 1.4.2.2 thorpej
109 1.4.2.2 thorpej void tsp_tlb_invalidate __P((struct tsp_config *));
110 1.4.2.2 thorpej
111 1.4.2.2 thorpej /*
112 1.4.2.2 thorpej * XXX Need to figure out what this is, if any. Initialize it to
113 1.4.2.2 thorpej * XXX something that should be safe.
114 1.4.2.2 thorpej */
115 1.4.2.2 thorpej #define TSP_SGMAP_PFTHRESH 256
116 1.4.2.2 thorpej
117 1.4.2.2 thorpej void
118 1.4.2.2 thorpej tsp_dma_init(pcp)
119 1.4.2.2 thorpej struct tsp_config *pcp;
120 1.4.2.2 thorpej {
121 1.4.2.2 thorpej int i;
122 1.4.2.2 thorpej bus_dma_tag_t t;
123 1.4.2.2 thorpej struct ts_pchip *pccsr = pcp->pc_csr;
124 1.4.2.2 thorpej bus_addr_t dwbase, dwlen, sgwbase, sgwlen, tbase;
125 1.4.2.2 thorpej static struct map_expected {
126 1.4.2.2 thorpej u_int32_t base, mask, enables;
127 1.4.2.2 thorpej } premap[4] = {
128 1.4.2.2 thorpej { 0x800000, 0x700000, WSBA_ENA | WSBA_SG },
129 1.4.2.2 thorpej { 0x80000000 | WSBA_ENA, 0x3ff00000, WSBA_ENA },
130 1.4.2.2 thorpej { 0, 0 },
131 1.4.2.2 thorpej { 0, 0 }
132 1.4.2.2 thorpej };
133 1.4.2.2 thorpej
134 1.4.2.2 thorpej alpha_mb();
135 1.4.2.2 thorpej for(i = 0; i < 4; ++i) {
136 1.4.2.2 thorpej if (EDIFF(pccsr->tsp_wsba[i].tsg_r, premap[i].base) ||
137 1.4.2.2 thorpej EDIFF(pccsr->tsp_wsm[i].tsg_r, premap[i].mask))
138 1.4.2.2 thorpej printf("tsp%d: window %d: %lx/base %lx/mask %lx"
139 1.4.2.2 thorpej " reinitialized\n",
140 1.4.2.2 thorpej pcp->pc_pslot, i,
141 1.4.2.2 thorpej pccsr->tsp_wsba[i].tsg_r,
142 1.4.2.2 thorpej pccsr->tsp_wsm[i].tsg_r,
143 1.4.2.2 thorpej pccsr->tsp_tba[i].tsg_r);
144 1.4.2.2 thorpej pccsr->tsp_wsba[i].tsg_r = premap[i].base | premap[i].enables;
145 1.4.2.2 thorpej pccsr->tsp_wsm[i].tsg_r = premap[i].mask;
146 1.4.2.2 thorpej }
147 1.4.2.2 thorpej alpha_mb();
148 1.4.2.2 thorpej
149 1.4.2.2 thorpej /*
150 1.4.2.2 thorpej * Initialize the DMA tag used for direct-mapped DMA.
151 1.4.2.2 thorpej */
152 1.4.2.2 thorpej t = &pcp->pc_dmat_direct;
153 1.4.2.2 thorpej t->_cookie = pcp;
154 1.4.2.2 thorpej t->_wbase = dwbase = WSBA_ADDR(pccsr->tsp_wsba[1].tsg_r);
155 1.4.2.2 thorpej t->_wsize = dwlen = WSM_LEN(pccsr->tsp_wsm[1].tsg_r);
156 1.4.2.2 thorpej t->_next_window = &pcp->pc_dmat_sgmap;
157 1.4.2.2 thorpej t->_boundary = 0;
158 1.4.2.2 thorpej t->_sgmap = NULL;
159 1.4.2.2 thorpej t->_get_tag = tsp_dma_get_tag;
160 1.4.2.2 thorpej t->_dmamap_create = _bus_dmamap_create;
161 1.4.2.2 thorpej t->_dmamap_destroy = _bus_dmamap_destroy;
162 1.4.2.2 thorpej t->_dmamap_load = _bus_dmamap_load_direct;
163 1.4.2.2 thorpej t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct;
164 1.4.2.2 thorpej t->_dmamap_load_uio = _bus_dmamap_load_uio_direct;
165 1.4.2.2 thorpej t->_dmamap_load_raw = _bus_dmamap_load_raw_direct;
166 1.4.2.2 thorpej t->_dmamap_unload = _bus_dmamap_unload;
167 1.4.2.2 thorpej t->_dmamap_sync = _bus_dmamap_sync;
168 1.4.2.2 thorpej
169 1.4.2.2 thorpej t->_dmamem_alloc = _bus_dmamem_alloc;
170 1.4.2.2 thorpej t->_dmamem_free = _bus_dmamem_free;
171 1.4.2.2 thorpej t->_dmamem_map = _bus_dmamem_map;
172 1.4.2.2 thorpej t->_dmamem_unmap = _bus_dmamem_unmap;
173 1.4.2.2 thorpej t->_dmamem_mmap = _bus_dmamem_mmap;
174 1.4.2.2 thorpej
175 1.4.2.2 thorpej /*
176 1.4.2.2 thorpej * Initialize the DMA tag used for sgmap-mapped DMA.
177 1.4.2.2 thorpej */
178 1.4.2.2 thorpej t = &pcp->pc_dmat_sgmap;
179 1.4.2.2 thorpej t->_cookie = pcp;
180 1.4.2.2 thorpej t->_wbase = sgwbase = WSBA_ADDR(pccsr->tsp_wsba[0].tsg_r);
181 1.4.2.2 thorpej t->_wsize = sgwlen = WSM_LEN(pccsr->tsp_wsm[0].tsg_r);
182 1.4.2.2 thorpej t->_next_window = NULL;
183 1.4.2.2 thorpej t->_boundary = 0;
184 1.4.2.2 thorpej t->_sgmap = &pcp->pc_sgmap;
185 1.4.2.2 thorpej t->_pfthresh = TSP_SGMAP_PFTHRESH;
186 1.4.2.2 thorpej t->_get_tag = tsp_dma_get_tag;
187 1.4.2.2 thorpej t->_dmamap_create = alpha_sgmap_dmamap_create;
188 1.4.2.2 thorpej t->_dmamap_destroy = alpha_sgmap_dmamap_destroy;
189 1.4.2.2 thorpej t->_dmamap_load = tsp_bus_dmamap_load_sgmap;
190 1.4.2.2 thorpej t->_dmamap_load_mbuf = tsp_bus_dmamap_load_mbuf_sgmap;
191 1.4.2.2 thorpej t->_dmamap_load_uio = tsp_bus_dmamap_load_uio_sgmap;
192 1.4.2.2 thorpej t->_dmamap_load_raw = tsp_bus_dmamap_load_raw_sgmap;
193 1.4.2.2 thorpej t->_dmamap_unload = tsp_bus_dmamap_unload_sgmap;
194 1.4.2.2 thorpej t->_dmamap_sync = _bus_dmamap_sync;
195 1.4.2.2 thorpej
196 1.4.2.2 thorpej t->_dmamem_alloc = _bus_dmamem_alloc;
197 1.4.2.2 thorpej t->_dmamem_free = _bus_dmamem_free;
198 1.4.2.2 thorpej t->_dmamem_map = _bus_dmamem_map;
199 1.4.2.2 thorpej t->_dmamem_unmap = _bus_dmamem_unmap;
200 1.4.2.2 thorpej t->_dmamem_mmap = _bus_dmamem_mmap;
201 1.4.2.2 thorpej
202 1.4.2.2 thorpej /*
203 1.4.2.2 thorpej * Initialize the SGMAP. Align page table to 32k in case
204 1.4.2.2 thorpej * window is somewhat larger than expected.
205 1.4.2.2 thorpej */
206 1.4.2.2 thorpej alpha_sgmap_init(t, &pcp->pc_sgmap, "tsp_sgmap",
207 1.4.2.2 thorpej sgwbase, 0, sgwlen, sizeof(u_int64_t), NULL, (32*1024));
208 1.4.2.2 thorpej
209 1.4.2.2 thorpej /*
210 1.4.2.2 thorpej * Enable window 0 and enable SG PTE mapping.
211 1.4.2.2 thorpej */
212 1.4.2.2 thorpej alpha_mb();
213 1.4.2.2 thorpej pccsr->tsp_wsba[0].tsg_r |= WSBA_SG | WSBA_ENA;
214 1.4.2.2 thorpej alpha_mb();
215 1.4.2.2 thorpej
216 1.4.2.2 thorpej /*
217 1.4.2.2 thorpej * Check windows for sanity, especially if we later decide to
218 1.4.2.2 thorpej * use the firmware's initialization in some cases.
219 1.4.2.2 thorpej */
220 1.4.2.2 thorpej if ((sgwbase <= dwbase && dwbase < sgwbase + sgwlen) ||
221 1.4.2.2 thorpej (dwbase <= sgwbase && sgwbase < dwbase + dwlen))
222 1.4.2.2 thorpej panic("tsp_dma_init: overlap");
223 1.4.2.2 thorpej
224 1.4.2.2 thorpej tbase = pcp->pc_sgmap.aps_ptpa;
225 1.4.2.2 thorpej if (tbase & ~0x7fffffc00UL)
226 1.4.2.2 thorpej panic("tsp_dma_init: bad page table address");
227 1.4.2.2 thorpej alpha_mb();
228 1.4.2.2 thorpej pccsr->tsp_tba[0].tsg_r = tbase;
229 1.4.2.2 thorpej alpha_mb();
230 1.4.2.2 thorpej
231 1.4.2.2 thorpej tsp_tlb_invalidate(pcp);
232 1.4.2.2 thorpej alpha_mb();
233 1.4.2.2 thorpej
234 1.4.2.2 thorpej /* XXX XXX BEGIN XXX XXX */
235 1.4.2.2 thorpej { /* XXX */
236 1.4.2.2 thorpej extern paddr_t alpha_XXX_dmamap_or; /* XXX */
237 1.4.2.2 thorpej alpha_XXX_dmamap_or = dwbase; /* XXX */
238 1.4.2.2 thorpej } /* XXX */
239 1.4.2.2 thorpej /* XXX XXX END XXX XXX */
240 1.4.2.2 thorpej }
241 1.4.2.2 thorpej
242 1.4.2.2 thorpej /*
243 1.4.2.2 thorpej * Return the bus dma tag to be used for the specified bus type.
244 1.4.2.2 thorpej * INTERNAL USE ONLY!
245 1.4.2.2 thorpej */
246 1.4.2.2 thorpej bus_dma_tag_t
247 1.4.2.2 thorpej tsp_dma_get_tag(t, bustype)
248 1.4.2.2 thorpej bus_dma_tag_t t;
249 1.4.2.2 thorpej alpha_bus_t bustype;
250 1.4.2.2 thorpej {
251 1.4.2.2 thorpej struct tsp_config *pcp = t->_cookie;
252 1.4.2.2 thorpej
253 1.4.2.2 thorpej switch (bustype) {
254 1.4.2.2 thorpej case ALPHA_BUS_PCI:
255 1.4.2.2 thorpej case ALPHA_BUS_EISA:
256 1.4.2.2 thorpej /*
257 1.4.2.2 thorpej * The direct mapped window will work for most systems,
258 1.4.2.2 thorpej * most of the time. When it doesn't, we chain to the sgmap
259 1.4.2.2 thorpej * window automatically.
260 1.4.2.2 thorpej */
261 1.4.2.2 thorpej return (&pcp->pc_dmat_direct);
262 1.4.2.2 thorpej
263 1.4.2.2 thorpej case ALPHA_BUS_ISA:
264 1.4.2.2 thorpej /*
265 1.4.2.2 thorpej * ISA doesn't have enough address bits to use
266 1.4.2.2 thorpej * the direct-mapped DMA window, so we must use
267 1.4.2.2 thorpej * SGMAPs.
268 1.4.2.2 thorpej */
269 1.4.2.2 thorpej return (&pcp->pc_dmat_sgmap);
270 1.4.2.2 thorpej
271 1.4.2.2 thorpej default:
272 1.4.2.2 thorpej panic("tsp_dma_get_tag: shouldn't be here, really...");
273 1.4.2.2 thorpej }
274 1.4.2.2 thorpej }
275 1.4.2.2 thorpej
276 1.4.2.2 thorpej /*
277 1.4.2.2 thorpej * Load a TSP SGMAP-mapped DMA map with a linear buffer.
278 1.4.2.2 thorpej */
279 1.4.2.2 thorpej int
280 1.4.2.2 thorpej tsp_bus_dmamap_load_sgmap(t, map, buf, buflen, p, flags)
281 1.4.2.2 thorpej bus_dma_tag_t t;
282 1.4.2.2 thorpej bus_dmamap_t map;
283 1.4.2.2 thorpej void *buf;
284 1.4.2.2 thorpej bus_size_t buflen;
285 1.4.2.2 thorpej struct proc *p;
286 1.4.2.2 thorpej int flags;
287 1.4.2.2 thorpej {
288 1.4.2.2 thorpej int error;
289 1.4.2.2 thorpej
290 1.4.2.2 thorpej error = pci_sgmap_pte64_load(t, map, buf, buflen, p, flags,
291 1.4.2.2 thorpej t->_sgmap);
292 1.4.2.2 thorpej if (error == 0)
293 1.4.2.2 thorpej tsp_tlb_invalidate(t->_cookie);
294 1.4.2.2 thorpej
295 1.4.2.2 thorpej return (error);
296 1.4.2.2 thorpej }
297 1.4.2.2 thorpej
298 1.4.2.2 thorpej /*
299 1.4.2.2 thorpej * Load a TSP SGMAP-mapped DMA map with an mbuf chain.
300 1.4.2.2 thorpej */
301 1.4.2.2 thorpej int
302 1.4.2.2 thorpej tsp_bus_dmamap_load_mbuf_sgmap(t, map, m, flags)
303 1.4.2.2 thorpej bus_dma_tag_t t;
304 1.4.2.2 thorpej bus_dmamap_t map;
305 1.4.2.2 thorpej struct mbuf *m;
306 1.4.2.2 thorpej int flags;
307 1.4.2.2 thorpej {
308 1.4.2.2 thorpej int error;
309 1.4.2.2 thorpej
310 1.4.2.2 thorpej error = pci_sgmap_pte64_load_mbuf(t, map, m, flags, t->_sgmap);
311 1.4.2.2 thorpej if (error == 0)
312 1.4.2.2 thorpej tsp_tlb_invalidate(t->_cookie);
313 1.4.2.2 thorpej
314 1.4.2.2 thorpej return (error);
315 1.4.2.2 thorpej }
316 1.4.2.2 thorpej
317 1.4.2.2 thorpej /*
318 1.4.2.2 thorpej * Load a TSP SGMAP-mapped DMA map with a uio.
319 1.4.2.2 thorpej */
320 1.4.2.2 thorpej int
321 1.4.2.2 thorpej tsp_bus_dmamap_load_uio_sgmap(t, map, uio, flags)
322 1.4.2.2 thorpej bus_dma_tag_t t;
323 1.4.2.2 thorpej bus_dmamap_t map;
324 1.4.2.2 thorpej struct uio *uio;
325 1.4.2.2 thorpej int flags;
326 1.4.2.2 thorpej {
327 1.4.2.2 thorpej int error;
328 1.4.2.2 thorpej
329 1.4.2.2 thorpej error = pci_sgmap_pte64_load_uio(t, map, uio, flags, t->_sgmap);
330 1.4.2.2 thorpej if (error == 0)
331 1.4.2.2 thorpej tsp_tlb_invalidate(t->_cookie);
332 1.4.2.2 thorpej
333 1.4.2.2 thorpej return (error);
334 1.4.2.2 thorpej }
335 1.4.2.2 thorpej
336 1.4.2.2 thorpej /*
337 1.4.2.2 thorpej * Load a TSP SGMAP-mapped DMA map with raw memory.
338 1.4.2.2 thorpej */
339 1.4.2.2 thorpej int
340 1.4.2.2 thorpej tsp_bus_dmamap_load_raw_sgmap(t, map, segs, nsegs, size, flags)
341 1.4.2.2 thorpej bus_dma_tag_t t;
342 1.4.2.2 thorpej bus_dmamap_t map;
343 1.4.2.2 thorpej bus_dma_segment_t *segs;
344 1.4.2.2 thorpej int nsegs;
345 1.4.2.2 thorpej bus_size_t size;
346 1.4.2.2 thorpej int flags;
347 1.4.2.2 thorpej {
348 1.4.2.2 thorpej int error;
349 1.4.2.2 thorpej
350 1.4.2.2 thorpej error = pci_sgmap_pte64_load_raw(t, map, segs, nsegs, size, flags,
351 1.4.2.2 thorpej t->_sgmap);
352 1.4.2.2 thorpej if (error == 0)
353 1.4.2.2 thorpej tsp_tlb_invalidate(t->_cookie);
354 1.4.2.2 thorpej
355 1.4.2.2 thorpej return (error);
356 1.4.2.2 thorpej }
357 1.4.2.2 thorpej
358 1.4.2.2 thorpej /*
359 1.4.2.2 thorpej * Unload a TSP DMA map.
360 1.4.2.2 thorpej */
361 1.4.2.2 thorpej void
362 1.4.2.2 thorpej tsp_bus_dmamap_unload_sgmap(t, map)
363 1.4.2.2 thorpej bus_dma_tag_t t;
364 1.4.2.2 thorpej bus_dmamap_t map;
365 1.4.2.2 thorpej {
366 1.4.2.2 thorpej
367 1.4.2.2 thorpej /*
368 1.4.2.2 thorpej * Invalidate any SGMAP page table entries used by this
369 1.4.2.2 thorpej * mapping.
370 1.4.2.2 thorpej */
371 1.4.2.2 thorpej pci_sgmap_pte64_unload(t, map, t->_sgmap);
372 1.4.2.2 thorpej tsp_tlb_invalidate(t->_cookie);
373 1.4.2.2 thorpej
374 1.4.2.2 thorpej /*
375 1.4.2.2 thorpej * Do the generic bits of the unload.
376 1.4.2.2 thorpej */
377 1.4.2.2 thorpej _bus_dmamap_unload(t, map);
378 1.4.2.2 thorpej }
379 1.4.2.2 thorpej
380 1.4.2.2 thorpej /*
381 1.4.2.2 thorpej * Flush the TSP scatter/gather TLB.
382 1.4.2.2 thorpej */
383 1.4.2.2 thorpej void
384 1.4.2.2 thorpej tsp_tlb_invalidate(pcp)
385 1.4.2.2 thorpej struct tsp_config *pcp;
386 1.4.2.2 thorpej {
387 1.4.2.2 thorpej
388 1.4.2.2 thorpej alpha_mb();
389 1.4.2.2 thorpej pcp->pc_csr->tsp_tlbia.tsg_r = 0;
390 1.4.2.2 thorpej alpha_mb();
391 1.4.2.2 thorpej }
392