Annotation of sys/arch/alpha/pci/mcpcia_dma.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: mcpcia_dma.c,v 1.1 2007/03/16 21:22:27 robert Exp $ */
2: /* $NetBSD: mcpcia_dma.c,v 1.15 2001/07/19 18:55:40 thorpej Exp $ */
3:
4: /*-
5: * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
6: * All rights reserved.
7: *
8: * This code is derived from software contributed to The NetBSD Foundation
9: * by Jason R. Thorpe and Matthew Jacob of the Numerical Aerospace Simulation
10: * Facility, NASA Ames Research Center.
11: *
12: * Redistribution and use in source and binary forms, with or without
13: * modification, are permitted provided that the following conditions
14: * are met:
15: * 1. Redistributions of source code must retain the above copyright
16: * notice, this list of conditions and the following disclaimer.
17: * 2. Redistributions in binary form must reproduce the above copyright
18: * notice, this list of conditions and the following disclaimer in the
19: * documentation and/or other materials provided with the distribution.
20: * 3. All advertising materials mentioning features or use of this software
21: * must display the following acknowledgement:
22: * This product includes software developed by the NetBSD
23: * Foundation, Inc. and its contributors.
24: * 4. Neither the name of The NetBSD Foundation nor the names of its
25: * contributors may be used to endorse or promote products derived
26: * from this software without specific prior written permission.
27: *
28: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38: * POSSIBILITY OF SUCH DAMAGE.
39: */
40:
41: #define _ALPHA_BUS_DMA_PRIVATE
42:
43: #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
44: #include <sys/param.h>
45: #include <sys/systm.h>
46: #include <sys/kernel.h>
47: #include <sys/device.h>
48: #include <sys/malloc.h>
49:
50: #include <uvm/uvm_extern.h>
51:
52: #include <machine/bus.h>
53: #include <machine/rpb.h>
54:
55: #include <dev/pci/pcireg.h>
56: #include <dev/pci/pcivar.h>
57: #include <alpha/pci/mcpciareg.h>
58: #include <alpha/pci/mcpciavar.h>
59: #include <alpha/pci/pci_kn300.h>
60:
61: bus_dma_tag_t mcpcia_dma_get_tag (bus_dma_tag_t, alpha_bus_t);
62:
63: int mcpcia_bus_dmamap_load_sgmap (bus_dma_tag_t, bus_dmamap_t, void *,
64: bus_size_t, struct proc *, int);
65:
66: int mcpcia_bus_dmamap_load_mbuf_sgmap (bus_dma_tag_t, bus_dmamap_t,
67: struct mbuf *, int);
68:
69: int mcpcia_bus_dmamap_load_uio_sgmap (bus_dma_tag_t, bus_dmamap_t,
70: struct uio *, int);
71:
72: int mcpcia_bus_dmamap_load_raw_sgmap (bus_dma_tag_t, bus_dmamap_t,
73: bus_dma_segment_t *, int, bus_size_t, int);
74:
75: void mcpcia_bus_dmamap_unload_sgmap (bus_dma_tag_t, bus_dmamap_t);
76:
77: /*
78: * Direct-mapped window: 2G at 2G
79: */
80: #define MCPCIA_DIRECT_MAPPED_BASE (2UL*1024UL*1024UL*1024UL)
81: #define MCPCIA_DIRECT_MAPPED_SIZE (2UL*1024UL*1024UL*1024UL)
82:
83: /*
84: * SGMAP window for PCI: 1G at 1G
85: */
86: #define MCPCIA_PCI_SG_MAPPED_BASE (1UL*1024UL*1024UL*1024UL)
87: #define MCPCIA_PCI_SG_MAPPED_SIZE (1UL*1024UL*1024UL*1024UL)
88:
89: /*
90: * SGMAP window for ISA: 8M at 8M
91: */
92: #define MCPCIA_ISA_SG_MAPPED_BASE (8*1024*1024)
93: #define MCPCIA_ISA_SG_MAPPED_SIZE (8*1024*1024)
94:
95: /* MCPCIA has a 256-byte out-bound DMA prefetch threshold. */
96: #define MCPCIA_SG_MAPPED_PFTHRESH 256
97:
98: #define MCPCIA_SGTLB_INVALIDATE(ccp) \
99: do { \
100: alpha_mb(); \
101: REGVAL(MCPCIA_SG_TBIA(ccp)) = 0xdeadbeef; \
102: alpha_mb(); \
103: } while (0)
104:
105: void
106: mcpcia_dma_init(ccp)
107: struct mcpcia_config *ccp;
108: {
109: bus_dma_tag_t t;
110:
111: /*
112: * Initialize the DMA tag used for direct-mapped DMA.
113: */
114: t = &ccp->cc_dmat_direct;
115: t->_cookie = ccp;
116: t->_wbase = MCPCIA_DIRECT_MAPPED_BASE;
117: t->_wsize = MCPCIA_DIRECT_MAPPED_SIZE;
118: t->_next_window = &ccp->cc_dmat_pci_sgmap;
119: t->_boundary = 0;
120: t->_sgmap = NULL;
121: t->_get_tag = mcpcia_dma_get_tag;
122: t->_dmamap_create = _bus_dmamap_create;
123: t->_dmamap_destroy = _bus_dmamap_destroy;
124: t->_dmamap_load = _bus_dmamap_load_direct;
125: t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct;
126: t->_dmamap_load_uio = _bus_dmamap_load_uio_direct;
127: t->_dmamap_load_raw = _bus_dmamap_load_raw_direct;
128: t->_dmamap_unload = _bus_dmamap_unload;
129: t->_dmamap_sync = _bus_dmamap_sync;
130:
131: t->_dmamem_alloc = _bus_dmamem_alloc;
132: t->_dmamem_free = _bus_dmamem_free;
133: t->_dmamem_map = _bus_dmamem_map;
134: t->_dmamem_unmap = _bus_dmamem_unmap;
135: t->_dmamem_mmap = _bus_dmamem_mmap;
136:
137: /*
138: * Initialize the DMA tag used for sgmap-mapped PCI DMA.
139: */
140: t = &ccp->cc_dmat_pci_sgmap;
141: t->_cookie = ccp;
142: t->_wbase = MCPCIA_PCI_SG_MAPPED_BASE;
143: t->_wsize = MCPCIA_PCI_SG_MAPPED_SIZE;
144: t->_next_window = NULL;
145: t->_boundary = 0;
146: t->_sgmap = &ccp->cc_pci_sgmap;
147: t->_pfthresh = MCPCIA_SG_MAPPED_PFTHRESH;
148: t->_get_tag = mcpcia_dma_get_tag;
149: t->_dmamap_create = alpha_sgmap_dmamap_create;
150: t->_dmamap_destroy = alpha_sgmap_dmamap_destroy;
151: t->_dmamap_load = mcpcia_bus_dmamap_load_sgmap;
152: t->_dmamap_load_mbuf = mcpcia_bus_dmamap_load_mbuf_sgmap;
153: t->_dmamap_load_uio = mcpcia_bus_dmamap_load_uio_sgmap;
154: t->_dmamap_load_raw = mcpcia_bus_dmamap_load_raw_sgmap;
155: t->_dmamap_unload = mcpcia_bus_dmamap_unload_sgmap;
156: t->_dmamap_sync = _bus_dmamap_sync;
157:
158: t->_dmamem_alloc = _bus_dmamem_alloc;
159: t->_dmamem_free = _bus_dmamem_free;
160: t->_dmamem_map = _bus_dmamem_map;
161: t->_dmamem_unmap = _bus_dmamem_unmap;
162: t->_dmamem_mmap = _bus_dmamem_mmap;
163:
164: /*
165: * Initialize the DMA tag used for sgmap-mapped ISA DMA.
166: */
167: t = &ccp->cc_dmat_isa_sgmap;
168: t->_cookie = ccp;
169: t->_wbase = MCPCIA_ISA_SG_MAPPED_BASE;
170: t->_wsize = MCPCIA_ISA_SG_MAPPED_SIZE;
171: t->_next_window = NULL;
172: t->_boundary = 0;
173: t->_sgmap = &ccp->cc_isa_sgmap;
174: t->_pfthresh = MCPCIA_SG_MAPPED_PFTHRESH;
175: t->_get_tag = mcpcia_dma_get_tag;
176: t->_dmamap_create = alpha_sgmap_dmamap_create;
177: t->_dmamap_destroy = alpha_sgmap_dmamap_destroy;
178: t->_dmamap_load = mcpcia_bus_dmamap_load_sgmap;
179: t->_dmamap_load_mbuf = mcpcia_bus_dmamap_load_mbuf_sgmap;
180: t->_dmamap_load_uio = mcpcia_bus_dmamap_load_uio_sgmap;
181: t->_dmamap_load_raw = mcpcia_bus_dmamap_load_raw_sgmap;
182: t->_dmamap_unload = mcpcia_bus_dmamap_unload_sgmap;
183: t->_dmamap_sync = _bus_dmamap_sync;
184:
185: t->_dmamem_alloc = _bus_dmamem_alloc;
186: t->_dmamem_free = _bus_dmamem_free;
187: t->_dmamem_map = _bus_dmamem_map;
188: t->_dmamem_unmap = _bus_dmamem_unmap;
189: t->_dmamem_mmap = _bus_dmamem_mmap;
190:
191: /*
192: * Initialize the SGMAPs.
193: */
194: alpha_sgmap_init(&ccp->cc_dmat_pci_sgmap, &ccp->cc_pci_sgmap,
195: "mcpcia pci sgmap",
196: MCPCIA_PCI_SG_MAPPED_BASE, 0, MCPCIA_PCI_SG_MAPPED_SIZE,
197: sizeof(u_int64_t), NULL, 0);
198:
199: alpha_sgmap_init(&ccp->cc_dmat_isa_sgmap, &ccp->cc_isa_sgmap,
200: "mcpcia isa sgmap",
201: MCPCIA_ISA_SG_MAPPED_BASE, 0, MCPCIA_ISA_SG_MAPPED_SIZE,
202: sizeof(u_int64_t), NULL, 0);
203:
204: /*
205: * Disable windows first.
206: */
207: REGVAL(MCPCIA_W0_BASE(ccp)) = 0;
208: REGVAL(MCPCIA_W1_BASE(ccp)) = 0;
209: REGVAL(MCPCIA_W2_BASE(ccp)) = 0;
210: REGVAL(MCPCIA_W3_BASE(ccp)) = 0;
211: REGVAL(MCPCIA_T0_BASE(ccp)) = 0;
212: REGVAL(MCPCIA_T1_BASE(ccp)) = 0;
213: REGVAL(MCPCIA_T2_BASE(ccp)) = 0;
214: REGVAL(MCPCIA_T3_BASE(ccp)) = 0;
215: alpha_mb();
216:
217: /*
218: * Set up window 0 as an 8MB SGMAP-mapped window starting at 8MB.
219: */
220: REGVAL(MCPCIA_W0_MASK(ccp)) = MCPCIA_WMASK_8M;
221: REGVAL(MCPCIA_T0_BASE(ccp)) =
222: ccp->cc_isa_sgmap.aps_ptpa >> MCPCIA_TBASEX_SHIFT;
223: alpha_mb();
224: REGVAL(MCPCIA_W0_BASE(ccp)) =
225: MCPCIA_WBASE_EN | MCPCIA_WBASE_SG | MCPCIA_ISA_SG_MAPPED_BASE;
226: alpha_mb();
227:
228: MCPCIA_SGTLB_INVALIDATE(ccp);
229:
230: /*
231: * Set up window 1 as a 2 GB Direct-mapped window starting at 2GB.
232: */
233: REGVAL(MCPCIA_W1_MASK(ccp)) = MCPCIA_WMASK_2G;
234: REGVAL(MCPCIA_T1_BASE(ccp)) = 0;
235: alpha_mb();
236: REGVAL(MCPCIA_W1_BASE(ccp)) =
237: MCPCIA_DIRECT_MAPPED_BASE | MCPCIA_WBASE_EN;
238: alpha_mb();
239:
240: /*
241: * Set up window 2 as a 1G SGMAP-mapped window starting at 1G.
242: */
243: REGVAL(MCPCIA_W2_MASK(ccp)) = MCPCIA_WMASK_1G;
244: REGVAL(MCPCIA_T2_BASE(ccp)) =
245: ccp->cc_pci_sgmap.aps_ptpa >> MCPCIA_TBASEX_SHIFT;
246: alpha_mb();
247: REGVAL(MCPCIA_W2_BASE(ccp)) =
248: MCPCIA_WBASE_EN | MCPCIA_WBASE_SG | MCPCIA_PCI_SG_MAPPED_BASE;
249: alpha_mb();
250:
251: /* XXX XXX BEGIN XXX XXX */
252: { /* XXX */
253: extern paddr_t alpha_XXX_dmamap_or; /* XXX */
254: alpha_XXX_dmamap_or = MCPCIA_DIRECT_MAPPED_BASE;/* XXX */
255: } /* XXX */
256: /* XXX XXX END XXX XXX */
257: }
258:
259: /*
260: * Return the bus dma tag to be used for the specified bus type.
261: * INTERNAL USE ONLY!
262: */
263: bus_dma_tag_t
264: mcpcia_dma_get_tag(t, bustype)
265: bus_dma_tag_t t;
266: alpha_bus_t bustype;
267: {
268: struct mcpcia_config *ccp = t->_cookie;
269:
270: switch (bustype) {
271: case ALPHA_BUS_PCI:
272: case ALPHA_BUS_EISA:
273: /*
274: * Start off using the direct-mapped window. We will
275: * automatically fall backed onto the chained PCI SGMAP
276: * window if necessary.
277: */
278: return (&ccp->cc_dmat_direct);
279:
280: case ALPHA_BUS_ISA:
281: /*
282: * ISA doesn't have enough address bits to use
283: * the direct-mapped DMA window, so we must use
284: * SGMAPs.
285: */
286: return (&ccp->cc_dmat_isa_sgmap);
287:
288: default:
289: panic("mcpcia_dma_get_tag: shouldn't be here, really...");
290: }
291: }
292:
293: /*
294: * Load a MCPCIA SGMAP-mapped DMA map with a linear buffer.
295: */
296: int
297: mcpcia_bus_dmamap_load_sgmap(t, map, buf, buflen, p, flags)
298: bus_dma_tag_t t;
299: bus_dmamap_t map;
300: void *buf;
301: bus_size_t buflen;
302: struct proc *p;
303: int flags;
304: {
305: int error;
306: struct mcpcia_config *ccp = t->_cookie;
307:
308: error = pci_sgmap_pte64_load(t, map, buf, buflen, p, flags,
309: t->_sgmap);
310: if (error == 0)
311: MCPCIA_SGTLB_INVALIDATE(ccp);
312: return (error);
313: }
314:
315: /*
316: * Load a MCPCIA SGMAP-mapped DMA map with an mbuf chain.
317: */
318: int
319: mcpcia_bus_dmamap_load_mbuf_sgmap(t, map, m, flags)
320: bus_dma_tag_t t;
321: bus_dmamap_t map;
322: struct mbuf *m;
323: int flags;
324: {
325: int error;
326: struct mcpcia_config *ccp = t->_cookie;
327:
328: error = pci_sgmap_pte64_load_mbuf(t, map, m, flags, t->_sgmap);
329: if (error == 0)
330: MCPCIA_SGTLB_INVALIDATE(ccp);
331: return (error);
332: }
333:
334: /*
335: * Load a MCPCIA SGMAP-mapped DMA map with a uio.
336: */
337: int
338: mcpcia_bus_dmamap_load_uio_sgmap(t, map, uio, flags)
339: bus_dma_tag_t t;
340: bus_dmamap_t map;
341: struct uio *uio;
342: int flags;
343: {
344: int error;
345: struct mcpcia_config *ccp = t->_cookie;
346:
347: error = pci_sgmap_pte64_load_uio(t, map, uio, flags, t->_sgmap);
348: if (error == 0)
349: MCPCIA_SGTLB_INVALIDATE(ccp);
350: return (error);
351: }
352:
353: /*
354: * Load a MCPCIA SGMAP-mapped DMA map with raw memory.
355: */
356: int
357: mcpcia_bus_dmamap_load_raw_sgmap(t, map, segs, nsegs, size, flags)
358: bus_dma_tag_t t;
359: bus_dmamap_t map;
360: bus_dma_segment_t *segs;
361: int nsegs;
362: bus_size_t size;
363: int flags;
364: {
365: int error;
366: struct mcpcia_config *ccp = t->_cookie;
367:
368: error = pci_sgmap_pte64_load_raw(t, map, segs, nsegs, size, flags,
369: t->_sgmap);
370: if (error == 0)
371: MCPCIA_SGTLB_INVALIDATE(ccp);
372: return (error);
373: }
374:
375: /*
376: * Unload a MCPCIA DMA map.
377: */
378: void
379: mcpcia_bus_dmamap_unload_sgmap(t, map)
380: bus_dma_tag_t t;
381: bus_dmamap_t map;
382: {
383: struct mcpcia_config *ccp = t->_cookie;
384:
385: /*
386: * Invalidate any SGMAP page table entries used by this mapping.
387: */
388: pci_sgmap_pte64_unload(t, map, t->_sgmap);
389: MCPCIA_SGTLB_INVALIDATE(ccp);
390:
391: /*
392: * Do the generic bits of the unload.
393: */
394: _bus_dmamap_unload(t, map);
395: }
CVSweb