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