ttwoga_dma.c revision 1.3.2.2 1 1.3.2.2 thorpej /* $NetBSD: ttwoga_dma.c,v 1.3.2.2 2001/07/19 18:50:26 thorpej Exp $ */
2 1.3.2.2 thorpej
3 1.3.2.2 thorpej /*-
4 1.3.2.2 thorpej * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.3.2.2 thorpej * All rights reserved.
6 1.3.2.2 thorpej *
7 1.3.2.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.3.2.2 thorpej * by Jason R. Thorpe.
9 1.3.2.2 thorpej *
10 1.3.2.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.3.2.2 thorpej * modification, are permitted provided that the following conditions
12 1.3.2.2 thorpej * are met:
13 1.3.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.3.2.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.3.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.3.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.3.2.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.3.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.3.2.2 thorpej * must display the following acknowledgement:
20 1.3.2.2 thorpej * This product includes software developed by the NetBSD
21 1.3.2.2 thorpej * Foundation, Inc. and its contributors.
22 1.3.2.2 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.3.2.2 thorpej * contributors may be used to endorse or promote products derived
24 1.3.2.2 thorpej * from this software without specific prior written permission.
25 1.3.2.2 thorpej *
26 1.3.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.3.2.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.3.2.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.3.2.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.3.2.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.3.2.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.3.2.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.3.2.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.3.2.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.3.2.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.3.2.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.3.2.2 thorpej */
38 1.3.2.2 thorpej
39 1.3.2.2 thorpej #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
40 1.3.2.2 thorpej
41 1.3.2.2 thorpej __KERNEL_RCSID(0, "$NetBSD: ttwoga_dma.c,v 1.3.2.2 2001/07/19 18:50:26 thorpej Exp $");
42 1.3.2.2 thorpej
43 1.3.2.2 thorpej #include <sys/param.h>
44 1.3.2.2 thorpej #include <sys/systm.h>
45 1.3.2.2 thorpej #include <sys/kernel.h>
46 1.3.2.2 thorpej #include <sys/device.h>
47 1.3.2.2 thorpej
48 1.3.2.2 thorpej #include <uvm/uvm_extern.h>
49 1.3.2.2 thorpej
50 1.3.2.2 thorpej #define _ALPHA_BUS_DMA_PRIVATE
51 1.3.2.2 thorpej #include <machine/bus.h>
52 1.3.2.2 thorpej
53 1.3.2.2 thorpej #include <dev/pci/pcireg.h>
54 1.3.2.2 thorpej #include <dev/pci/pcivar.h>
55 1.3.2.2 thorpej
56 1.3.2.2 thorpej #include <alpha/pci/ttwogareg.h>
57 1.3.2.2 thorpej #include <alpha/pci/ttwogavar.h>
58 1.3.2.2 thorpej
59 1.3.2.2 thorpej bus_dma_tag_t ttwoga_dma_get_tag(bus_dma_tag_t, alpha_bus_t);
60 1.3.2.2 thorpej
61 1.3.2.2 thorpej int ttwoga_bus_dmamap_load_sgmap(bus_dma_tag_t, bus_dmamap_t, void *,
62 1.3.2.2 thorpej bus_size_t, struct proc *, int);
63 1.3.2.2 thorpej
64 1.3.2.2 thorpej int ttwoga_bus_dmamap_load_mbuf_sgmap(bus_dma_tag_t, bus_dmamap_t,
65 1.3.2.2 thorpej struct mbuf *, int);
66 1.3.2.2 thorpej
67 1.3.2.2 thorpej int ttwoga_bus_dmamap_load_uio_sgmap(bus_dma_tag_t, bus_dmamap_t,
68 1.3.2.2 thorpej struct uio *, int);
69 1.3.2.2 thorpej
70 1.3.2.2 thorpej int ttwoga_bus_dmamap_load_raw_sgmap(bus_dma_tag_t, bus_dmamap_t,
71 1.3.2.2 thorpej bus_dma_segment_t *, int, bus_size_t, int);
72 1.3.2.2 thorpej
73 1.3.2.2 thorpej void ttwoga_bus_dmamap_unload_sgmap(bus_dma_tag_t, bus_dmamap_t);
74 1.3.2.2 thorpej
75 1.3.2.2 thorpej /*
76 1.3.2.2 thorpej * Direct-mapped window: 1G at 1G
77 1.3.2.2 thorpej */
78 1.3.2.2 thorpej #define TTWOGA_DIRECT_MAPPED_BASE (1UL*1024UL*1024UL*1024UL)
79 1.3.2.2 thorpej #define TTWOGA_DIRECT_MAPPED_SIZE (1UL*1024UL*1024UL*1024UL)
80 1.3.2.2 thorpej
81 1.3.2.2 thorpej /*
82 1.3.2.2 thorpej * SGMAP window: 8M at 8M
83 1.3.2.2 thorpej */
84 1.3.2.2 thorpej #define TTWOGA_SGMAP_MAPPED_BASE (8UL*1024UL*1024UL)
85 1.3.2.2 thorpej #define TTWOGA_SGMAP_MAPPED_SIZE (8UL*1024UL*1024UL)
86 1.3.2.2 thorpej
87 1.3.2.2 thorpej /* T2 has a 256-byte out-bound DMA prefetch threshold. */
88 1.3.2.2 thorpej #define TTWOGA_SGMAP_PFTHRESH 256
89 1.3.2.2 thorpej
90 1.3.2.2 thorpej /*
91 1.3.2.2 thorpej * Macro to flush the T2 Gate Array scatter/gather TLB.
92 1.3.2.2 thorpej */
93 1.3.2.2 thorpej #define TTWOGA_TLB_INVALIDATE(tcp) \
94 1.3.2.2 thorpej do { \
95 1.3.2.2 thorpej u_int64_t temp; \
96 1.3.2.2 thorpej \
97 1.3.2.2 thorpej alpha_mb(); \
98 1.3.2.2 thorpej temp = T2GA((tcp), T2_IOCSR); \
99 1.3.2.2 thorpej T2GA((tcp), T2_IOCSR) = temp | IOCSR_FTLB; \
100 1.3.2.2 thorpej alpha_mb(); \
101 1.3.2.2 thorpej alpha_mb(); /* MAGIC */ \
102 1.3.2.2 thorpej T2GA((tcp), T2_IOCSR) = temp; \
103 1.3.2.2 thorpej alpha_mb(); \
104 1.3.2.2 thorpej alpha_mb(); /* MAGIC */ \
105 1.3.2.2 thorpej } while (0)
106 1.3.2.2 thorpej
107 1.3.2.2 thorpej void
108 1.3.2.2 thorpej ttwoga_dma_init(struct ttwoga_config *tcp)
109 1.3.2.2 thorpej {
110 1.3.2.2 thorpej bus_dma_tag_t t;
111 1.3.2.2 thorpej
112 1.3.2.2 thorpej /*
113 1.3.2.2 thorpej * Initialize the DMA tag used for direct-mapped DMA.
114 1.3.2.2 thorpej */
115 1.3.2.2 thorpej t = &tcp->tc_dmat_direct;
116 1.3.2.2 thorpej t->_cookie = tcp;
117 1.3.2.2 thorpej t->_wbase = TTWOGA_DIRECT_MAPPED_BASE;
118 1.3.2.2 thorpej t->_wsize = TTWOGA_DIRECT_MAPPED_SIZE;
119 1.3.2.2 thorpej t->_next_window = NULL;
120 1.3.2.2 thorpej t->_boundary = 0;
121 1.3.2.2 thorpej t->_sgmap = NULL;
122 1.3.2.2 thorpej t->_get_tag = ttwoga_dma_get_tag;
123 1.3.2.2 thorpej t->_dmamap_create = _bus_dmamap_create;
124 1.3.2.2 thorpej t->_dmamap_destroy = _bus_dmamap_destroy;
125 1.3.2.2 thorpej t->_dmamap_load = _bus_dmamap_load_direct;
126 1.3.2.2 thorpej t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct;
127 1.3.2.2 thorpej t->_dmamap_load_uio = _bus_dmamap_load_uio_direct;
128 1.3.2.2 thorpej t->_dmamap_load_raw = _bus_dmamap_load_raw_direct;
129 1.3.2.2 thorpej t->_dmamap_unload = _bus_dmamap_unload;
130 1.3.2.2 thorpej t->_dmamap_sync = _bus_dmamap_sync;
131 1.3.2.2 thorpej
132 1.3.2.2 thorpej t->_dmamem_alloc = _bus_dmamem_alloc;
133 1.3.2.2 thorpej t->_dmamem_free = _bus_dmamem_free;
134 1.3.2.2 thorpej t->_dmamem_map = _bus_dmamem_map;
135 1.3.2.2 thorpej t->_dmamem_unmap = _bus_dmamem_unmap;
136 1.3.2.2 thorpej t->_dmamem_mmap = _bus_dmamem_mmap;
137 1.3.2.2 thorpej
138 1.3.2.2 thorpej /*
139 1.3.2.2 thorpej * Initialize the DMA tag used for sgmap-mapped DMA.
140 1.3.2.2 thorpej */
141 1.3.2.2 thorpej t = &tcp->tc_dmat_sgmap;
142 1.3.2.2 thorpej t->_cookie = tcp;
143 1.3.2.2 thorpej t->_wbase = TTWOGA_SGMAP_MAPPED_BASE;
144 1.3.2.2 thorpej t->_wsize = TTWOGA_SGMAP_MAPPED_SIZE;
145 1.3.2.2 thorpej t->_next_window = NULL;
146 1.3.2.2 thorpej t->_boundary = 0;
147 1.3.2.2 thorpej t->_sgmap = &tcp->tc_sgmap;
148 1.3.2.2 thorpej t->_pfthresh = TTWOGA_SGMAP_PFTHRESH;
149 1.3.2.2 thorpej t->_get_tag = ttwoga_dma_get_tag;
150 1.3.2.2 thorpej t->_dmamap_create = alpha_sgmap_dmamap_create;
151 1.3.2.2 thorpej t->_dmamap_destroy = alpha_sgmap_dmamap_destroy;
152 1.3.2.2 thorpej t->_dmamap_load = ttwoga_bus_dmamap_load_sgmap;
153 1.3.2.2 thorpej t->_dmamap_load_mbuf = ttwoga_bus_dmamap_load_mbuf_sgmap;
154 1.3.2.2 thorpej t->_dmamap_load_uio = ttwoga_bus_dmamap_load_uio_sgmap;
155 1.3.2.2 thorpej t->_dmamap_load_raw = ttwoga_bus_dmamap_load_raw_sgmap;
156 1.3.2.2 thorpej t->_dmamap_unload = ttwoga_bus_dmamap_unload_sgmap;
157 1.3.2.2 thorpej t->_dmamap_sync = _bus_dmamap_sync;
158 1.3.2.2 thorpej
159 1.3.2.2 thorpej t->_dmamem_alloc = _bus_dmamem_alloc;
160 1.3.2.2 thorpej t->_dmamem_free = _bus_dmamem_free;
161 1.3.2.2 thorpej t->_dmamem_map = _bus_dmamem_map;
162 1.3.2.2 thorpej t->_dmamem_unmap = _bus_dmamem_unmap;
163 1.3.2.2 thorpej t->_dmamem_mmap = _bus_dmamem_mmap;
164 1.3.2.2 thorpej
165 1.3.2.2 thorpej /*
166 1.3.2.2 thorpej * Disable the SGMAP TLB, and flush it. We reenable it if
167 1.3.2.2 thorpej * we have a Sable or a Gamma with T3 or T4; Gamma with T2
168 1.3.2.2 thorpej * has a TLB bug apparently severe enough to require disabling
169 1.3.2.2 thorpej * it.
170 1.3.2.2 thorpej */
171 1.3.2.2 thorpej alpha_mb();
172 1.3.2.2 thorpej T2GA(tcp, T2_IOCSR) &= ~IOCSR_ETLB;
173 1.3.2.2 thorpej alpha_mb();
174 1.3.2.2 thorpej alpha_mb(); /* MAGIC */
175 1.3.2.2 thorpej
176 1.3.2.2 thorpej TTWOGA_TLB_INVALIDATE(tcp);
177 1.3.2.2 thorpej
178 1.3.2.2 thorpej /*
179 1.3.2.2 thorpej * XXX We might want to make sure our DMA windows don't
180 1.3.2.2 thorpej * XXX overlap with PCI memory space!
181 1.3.2.2 thorpej */
182 1.3.2.2 thorpej
183 1.3.2.2 thorpej /*
184 1.3.2.2 thorpej * Set up window 1 as a 1G direct-mapped window
185 1.3.2.2 thorpej * starting at 1G.
186 1.3.2.2 thorpej */
187 1.3.2.2 thorpej T2GA(tcp, T2_WBASE1) = 0;
188 1.3.2.2 thorpej alpha_mb();
189 1.3.2.2 thorpej
190 1.3.2.2 thorpej T2GA(tcp, T2_WMASK1) = (TTWOGA_DIRECT_MAPPED_SIZE - 1) & WMASKx_PWM;
191 1.3.2.2 thorpej alpha_mb();
192 1.3.2.2 thorpej
193 1.3.2.2 thorpej T2GA(tcp, T2_TBASE1) = 0;
194 1.3.2.2 thorpej alpha_mb();
195 1.3.2.2 thorpej
196 1.3.2.2 thorpej T2GA(tcp, T2_WBASE1) = TTWOGA_DIRECT_MAPPED_BASE |
197 1.3.2.2 thorpej ((TTWOGA_DIRECT_MAPPED_BASE + (TTWOGA_DIRECT_MAPPED_SIZE - 1)) >>
198 1.3.2.2 thorpej WBASEx_PWxA_SHIFT) | WBASEx_PWE;
199 1.3.2.2 thorpej alpha_mb();
200 1.3.2.2 thorpej
201 1.3.2.2 thorpej /*
202 1.3.2.2 thorpej * Initialize the SGMAP.
203 1.3.2.2 thorpej */
204 1.3.2.2 thorpej alpha_sgmap_init(t, &tcp->tc_sgmap, "ttwoga_sgmap",
205 1.3.2.2 thorpej TTWOGA_SGMAP_MAPPED_BASE, 0, TTWOGA_SGMAP_MAPPED_SIZE,
206 1.3.2.2 thorpej sizeof(u_int64_t), NULL, 0);
207 1.3.2.2 thorpej
208 1.3.2.2 thorpej /*
209 1.3.2.2 thorpej * Set up window 2 as an 8MB SGMAP-mapped window
210 1.3.2.2 thorpej * starting at 8MB.
211 1.3.2.2 thorpej */
212 1.3.2.2 thorpej #ifdef DIAGNOSTIC
213 1.3.2.2 thorpej if ((TTWOGA_SGMAP_MAPPED_BASE & WBASEx_PWSA) !=
214 1.3.2.2 thorpej TTWOGA_SGMAP_MAPPED_BASE)
215 1.3.2.2 thorpej panic("ttwoga_dma_init: SGMAP base inconsistency");
216 1.3.2.2 thorpej #endif
217 1.3.2.2 thorpej T2GA(tcp, T2_WBASE2) = 0;
218 1.3.2.2 thorpej alpha_mb();
219 1.3.2.2 thorpej
220 1.3.2.2 thorpej T2GA(tcp, T2_WMASK2) = (TTWOGA_SGMAP_MAPPED_SIZE - 1) & WMASKx_PWM;
221 1.3.2.2 thorpej alpha_mb();
222 1.3.2.2 thorpej
223 1.3.2.2 thorpej T2GA(tcp, T2_TBASE2) = tcp->tc_sgmap.aps_ptpa >> 1;
224 1.3.2.2 thorpej alpha_mb();
225 1.3.2.2 thorpej
226 1.3.2.2 thorpej T2GA(tcp, T2_WBASE2) = TTWOGA_SGMAP_MAPPED_BASE |
227 1.3.2.2 thorpej ((TTWOGA_SGMAP_MAPPED_BASE + (TTWOGA_SGMAP_MAPPED_SIZE - 1)) >>
228 1.3.2.2 thorpej WBASEx_PWxA_SHIFT) | WBASEx_SGE | WBASEx_PWE;
229 1.3.2.2 thorpej alpha_mb();
230 1.3.2.2 thorpej
231 1.3.2.2 thorpej /*
232 1.3.2.2 thorpej * Enable SGMAP TLB on Sable or Gamma with T3 or T4; see above.
233 1.3.2.2 thorpej */
234 1.3.2.2 thorpej if (alpha_implver() == ALPHA_IMPLVER_EV4 ||
235 1.3.2.2 thorpej tcp->tc_rev >= TRN_T3) {
236 1.3.2.2 thorpej alpha_mb();
237 1.3.2.2 thorpej T2GA(tcp, T2_IOCSR) |= IOCSR_ETLB;
238 1.3.2.2 thorpej alpha_mb();
239 1.3.2.2 thorpej alpha_mb(); /* MAGIC */
240 1.3.2.2 thorpej tcp->tc_use_tlb = 1;
241 1.3.2.2 thorpej }
242 1.3.2.2 thorpej
243 1.3.2.2 thorpej /* XXX XXX BEGIN XXX XXX */
244 1.3.2.2 thorpej { /* XXX */
245 1.3.2.2 thorpej extern paddr_t alpha_XXX_dmamap_or; /* XXX */
246 1.3.2.2 thorpej alpha_XXX_dmamap_or = TTWOGA_DIRECT_MAPPED_BASE;/* XXX */
247 1.3.2.2 thorpej } /* XXX */
248 1.3.2.2 thorpej /* XXX XXX END XXX XXX */
249 1.3.2.2 thorpej }
250 1.3.2.2 thorpej
251 1.3.2.2 thorpej /*
252 1.3.2.2 thorpej * Return the bus dma tag to be used for the specified bus type.
253 1.3.2.2 thorpej * INTERNAL USE ONLY!
254 1.3.2.2 thorpej */
255 1.3.2.2 thorpej bus_dma_tag_t
256 1.3.2.2 thorpej ttwoga_dma_get_tag(bus_dma_tag_t t, alpha_bus_t bustype)
257 1.3.2.2 thorpej {
258 1.3.2.2 thorpej struct ttwoga_config *tcp = t->_cookie;
259 1.3.2.2 thorpej
260 1.3.2.2 thorpej switch (bustype) {
261 1.3.2.2 thorpej case ALPHA_BUS_PCI:
262 1.3.2.2 thorpej case ALPHA_BUS_EISA:
263 1.3.2.2 thorpej /*
264 1.3.2.2 thorpej * Systems with a T2 Gate Array can have 2G
265 1.3.2.2 thorpej * of memory, but we only get a direct-mapped
266 1.3.2.2 thorpej * window of 1G!
267 1.3.2.2 thorpej *
268 1.3.2.2 thorpej * XXX FIX THIS SOMEDAY!
269 1.3.2.2 thorpej */
270 1.3.2.2 thorpej return (&tcp->tc_dmat_direct);
271 1.3.2.2 thorpej
272 1.3.2.2 thorpej case ALPHA_BUS_ISA:
273 1.3.2.2 thorpej /*
274 1.3.2.2 thorpej * ISA doesn't have enough address bits to use
275 1.3.2.2 thorpej * the direct-mapped DMA window, so we must use
276 1.3.2.2 thorpej * SGMAPs.
277 1.3.2.2 thorpej */
278 1.3.2.2 thorpej return (&tcp->tc_dmat_sgmap);
279 1.3.2.2 thorpej
280 1.3.2.2 thorpej default:
281 1.3.2.2 thorpej panic("ttwoga_dma_get_tag: shouldn't be here, really...");
282 1.3.2.2 thorpej }
283 1.3.2.2 thorpej }
284 1.3.2.2 thorpej
285 1.3.2.2 thorpej /*
286 1.3.2.2 thorpej * Load a T2 SGMAP-mapped DMA map with a liner buffer.
287 1.3.2.2 thorpej */
288 1.3.2.2 thorpej int
289 1.3.2.2 thorpej ttwoga_bus_dmamap_load_sgmap(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
290 1.3.2.2 thorpej bus_size_t buflen, struct proc *p, int flags)
291 1.3.2.2 thorpej {
292 1.3.2.2 thorpej struct ttwoga_config *tcp = t->_cookie;
293 1.3.2.2 thorpej int error;
294 1.3.2.2 thorpej
295 1.3.2.2 thorpej error = pci_sgmap_pte64_load(t, map, buf, buflen, p, flags,
296 1.3.2.2 thorpej t->_sgmap);
297 1.3.2.2 thorpej if (error == 0 && tcp->tc_use_tlb)
298 1.3.2.2 thorpej TTWOGA_TLB_INVALIDATE(tcp);
299 1.3.2.2 thorpej
300 1.3.2.2 thorpej return (error);
301 1.3.2.2 thorpej }
302 1.3.2.2 thorpej
303 1.3.2.2 thorpej /*
304 1.3.2.2 thorpej * Load a T2 SGMAP-mapped DMA map with an mbuf chain.
305 1.3.2.2 thorpej */
306 1.3.2.2 thorpej int
307 1.3.2.2 thorpej ttwoga_bus_dmamap_load_mbuf_sgmap(bus_dma_tag_t t, bus_dmamap_t map,
308 1.3.2.2 thorpej struct mbuf *m, int flags)
309 1.3.2.2 thorpej {
310 1.3.2.2 thorpej struct ttwoga_config *tcp = t->_cookie;
311 1.3.2.2 thorpej int error;
312 1.3.2.2 thorpej
313 1.3.2.2 thorpej error = pci_sgmap_pte64_load_mbuf(t, map, m, flags, t->_sgmap);
314 1.3.2.2 thorpej if (error == 0 && tcp->tc_use_tlb)
315 1.3.2.2 thorpej TTWOGA_TLB_INVALIDATE(tcp);
316 1.3.2.2 thorpej
317 1.3.2.2 thorpej return (error);
318 1.3.2.2 thorpej }
319 1.3.2.2 thorpej
320 1.3.2.2 thorpej /*
321 1.3.2.2 thorpej * Load a T2 SGMAP-mapped DMA map with a uio.
322 1.3.2.2 thorpej */
323 1.3.2.2 thorpej int
324 1.3.2.2 thorpej ttwoga_bus_dmamap_load_uio_sgmap(bus_dma_tag_t t, bus_dmamap_t map,
325 1.3.2.2 thorpej struct uio *uio, int flags)
326 1.3.2.2 thorpej {
327 1.3.2.2 thorpej struct ttwoga_config *tcp = t->_cookie;
328 1.3.2.2 thorpej int error;
329 1.3.2.2 thorpej
330 1.3.2.2 thorpej error = pci_sgmap_pte64_load_uio(t, map, uio, flags, t->_sgmap);
331 1.3.2.2 thorpej if (error == 0 && tcp->tc_use_tlb)
332 1.3.2.2 thorpej TTWOGA_TLB_INVALIDATE(tcp);
333 1.3.2.2 thorpej
334 1.3.2.2 thorpej return (error);
335 1.3.2.2 thorpej }
336 1.3.2.2 thorpej
337 1.3.2.2 thorpej /*
338 1.3.2.2 thorpej * Load a T2 SGMAP-mapped DMA map with raw memory.
339 1.3.2.2 thorpej */
340 1.3.2.2 thorpej int
341 1.3.2.2 thorpej ttwoga_bus_dmamap_load_raw_sgmap(bus_dma_tag_t t, bus_dmamap_t map,
342 1.3.2.2 thorpej bus_dma_segment_t *segs, int nsegs, bus_size_t size, int flags)
343 1.3.2.2 thorpej {
344 1.3.2.2 thorpej struct ttwoga_config *tcp = t->_cookie;
345 1.3.2.2 thorpej int error;
346 1.3.2.2 thorpej
347 1.3.2.2 thorpej error = pci_sgmap_pte64_load_raw(t, map, segs, nsegs, size, flags,
348 1.3.2.2 thorpej t->_sgmap);
349 1.3.2.2 thorpej if (error == 0 && tcp->tc_use_tlb)
350 1.3.2.2 thorpej TTWOGA_TLB_INVALIDATE(tcp);
351 1.3.2.2 thorpej
352 1.3.2.2 thorpej return (error);
353 1.3.2.2 thorpej }
354 1.3.2.2 thorpej
355 1.3.2.2 thorpej /*
356 1.3.2.2 thorpej * Unload an T2 DMA map.
357 1.3.2.2 thorpej */
358 1.3.2.2 thorpej void
359 1.3.2.2 thorpej ttwoga_bus_dmamap_unload_sgmap(bus_dma_tag_t t, bus_dmamap_t map)
360 1.3.2.2 thorpej {
361 1.3.2.2 thorpej struct ttwoga_config *tcp = t->_cookie;
362 1.3.2.2 thorpej
363 1.3.2.2 thorpej /*
364 1.3.2.2 thorpej * Invalidate any SGMAP page table entries used by this
365 1.3.2.2 thorpej * mapping.
366 1.3.2.2 thorpej */
367 1.3.2.2 thorpej pci_sgmap_pte64_unload(t, map, t->_sgmap);
368 1.3.2.2 thorpej if (tcp->tc_use_tlb)
369 1.3.2.2 thorpej TTWOGA_TLB_INVALIDATE(tcp);
370 1.3.2.2 thorpej
371 1.3.2.2 thorpej /*
372 1.3.2.2 thorpej * Do the generic bits of the unload.
373 1.3.2.2 thorpej */
374 1.3.2.2 thorpej _bus_dmamap_unload(t, map);
375 1.3.2.2 thorpej }
376