Annotation of sys/arch/alpha/pci/lca_dma.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: lca_dma.c,v 1.7 2006/04/04 21:20:40 brad Exp $ */
! 2: /* $NetBSD: lca_dma.c,v 1.13 2000/06/29 08:58:47 mrg Exp $ */
! 3:
! 4: /*-
! 5: * Copyright (c) 1997, 1998 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 of the Numerical Aerospace Simulation Facility,
! 10: * 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: /*
! 42: * XXX - We should define this before including bus.h, but since other stuff
! 43: * pulls in bus.h we must do this here.
! 44: */
! 45: #define _ALPHA_BUS_DMA_PRIVATE
! 46:
! 47: #include <sys/param.h>
! 48: #include <sys/systm.h>
! 49: #include <sys/kernel.h>
! 50: #include <sys/device.h>
! 51: #include <sys/malloc.h>
! 52:
! 53: #include <uvm/uvm_extern.h>
! 54:
! 55: #include <machine/bus.h>
! 56:
! 57: #include <dev/pci/pcireg.h>
! 58: #include <dev/pci/pcivar.h>
! 59: #include <alpha/pci/lcareg.h>
! 60: #include <alpha/pci/lcavar.h>
! 61:
! 62: bus_dma_tag_t lca_dma_get_tag(bus_dma_tag_t, alpha_bus_t);
! 63:
! 64: int lca_bus_dmamap_load_sgmap(bus_dma_tag_t, bus_dmamap_t, void *,
! 65: bus_size_t, struct proc *, int);
! 66:
! 67: int lca_bus_dmamap_load_mbuf_sgmap(bus_dma_tag_t, bus_dmamap_t,
! 68: struct mbuf *, int);
! 69:
! 70: int lca_bus_dmamap_load_uio_sgmap(bus_dma_tag_t, bus_dmamap_t,
! 71: struct uio *, int);
! 72:
! 73: int lca_bus_dmamap_load_raw_sgmap(bus_dma_tag_t, bus_dmamap_t,
! 74: bus_dma_segment_t *, int, bus_size_t, int);
! 75:
! 76: void lca_bus_dmamap_unload_sgmap(bus_dma_tag_t, bus_dmamap_t);
! 77:
! 78: /*
! 79: * Direct-mapped window: 1G at 1G
! 80: */
! 81: #define LCA_DIRECT_MAPPED_BASE (1*1024*1024*1024)
! 82: #define LCA_DIRECT_MAPPED_SIZE (1*1024*1024*1024)
! 83:
! 84: /*
! 85: * SGMAP window: 8M at 8M
! 86: */
! 87: #define LCA_SGMAP_MAPPED_BASE (8*1024*1024)
! 88: #define LCA_SGMAP_MAPPED_SIZE (8*1024*1024)
! 89:
! 90: /*
! 91: * The LCA doesn't have a DMA prefetch threshold. However, it is known
! 92: * to lose if we don't allocate a spill page. So initialize it to 256.
! 93: */
! 94: #define LCA_SGMAP_PFTHRESH 256
! 95:
! 96: /*
! 97: * Macro to flush LCA scatter/gather TLB.
! 98: */
! 99: #define LCA_TLB_INVALIDATE() \
! 100: do { \
! 101: alpha_mb(); \
! 102: REGVAL64(LCA_IOC_TBIA) = 0; \
! 103: alpha_mb(); \
! 104: } while (0)
! 105:
! 106: void
! 107: lca_dma_init(lcp)
! 108: struct lca_config *lcp;
! 109: {
! 110: bus_dma_tag_t t;
! 111:
! 112: /*
! 113: * Initialize the DMA tag used for direct-mapped DMA.
! 114: */
! 115: t = &lcp->lc_dmat_direct;
! 116: t->_cookie = lcp;
! 117: t->_wbase = LCA_DIRECT_MAPPED_BASE;
! 118: t->_wsize = LCA_DIRECT_MAPPED_SIZE;
! 119: t->_next_window = NULL;
! 120: t->_boundary = 0;
! 121: t->_sgmap = NULL;
! 122: t->_get_tag = lca_dma_get_tag;
! 123: t->_dmamap_create = _bus_dmamap_create;
! 124: t->_dmamap_destroy = _bus_dmamap_destroy;
! 125: t->_dmamap_load = _bus_dmamap_load_direct;
! 126: t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct;
! 127: t->_dmamap_load_uio = _bus_dmamap_load_uio_direct;
! 128: t->_dmamap_load_raw = _bus_dmamap_load_raw_direct;
! 129: t->_dmamap_unload = _bus_dmamap_unload;
! 130: t->_dmamap_sync = _bus_dmamap_sync;
! 131:
! 132: t->_dmamem_alloc = _bus_dmamem_alloc;
! 133: t->_dmamem_free = _bus_dmamem_free;
! 134: t->_dmamem_map = _bus_dmamem_map;
! 135: t->_dmamem_unmap = _bus_dmamem_unmap;
! 136: t->_dmamem_mmap = _bus_dmamem_mmap;
! 137:
! 138: /*
! 139: * Initialize the DMA tag used for sgmap-mapped DMA.
! 140: */
! 141: t = &lcp->lc_dmat_sgmap;
! 142: t->_cookie = lcp;
! 143: t->_wbase = LCA_SGMAP_MAPPED_BASE;
! 144: t->_wsize = LCA_SGMAP_MAPPED_SIZE;
! 145: t->_next_window = NULL;
! 146: t->_boundary = 0;
! 147: t->_sgmap = &lcp->lc_sgmap;
! 148: t->_pfthresh = LCA_SGMAP_PFTHRESH;
! 149: t->_get_tag = lca_dma_get_tag;
! 150: t->_dmamap_create = alpha_sgmap_dmamap_create;
! 151:
! 152: t->_dmamap_destroy = alpha_sgmap_dmamap_destroy;
! 153: t->_dmamap_load = lca_bus_dmamap_load_sgmap;
! 154: t->_dmamap_load_mbuf = lca_bus_dmamap_load_mbuf_sgmap;
! 155: t->_dmamap_load_uio = lca_bus_dmamap_load_uio_sgmap;
! 156: t->_dmamap_load_raw = lca_bus_dmamap_load_raw_sgmap;
! 157: t->_dmamap_unload = lca_bus_dmamap_unload_sgmap;
! 158: t->_dmamap_sync = _bus_dmamap_sync;
! 159:
! 160: t->_dmamem_alloc = _bus_dmamem_alloc;
! 161: t->_dmamem_free = _bus_dmamem_free;
! 162: t->_dmamem_map = _bus_dmamem_map;
! 163: t->_dmamem_unmap = _bus_dmamem_unmap;
! 164: t->_dmamem_mmap = _bus_dmamem_mmap;
! 165:
! 166: /*
! 167: * The firmware has set up window 1 as a 1G direct-mapped DMA
! 168: * window beginning at 1G. We leave it alone. Disable
! 169: * window 0.
! 170: */
! 171: REGVAL64(LCA_IOC_W_BASE0) = 0;
! 172: alpha_mb();
! 173:
! 174: /*
! 175: * Initialize the SGMAP.
! 176: */
! 177: alpha_sgmap_init(t, &lcp->lc_sgmap, "lca_sgmap",
! 178: LCA_SGMAP_MAPPED_BASE, 0, LCA_SGMAP_MAPPED_SIZE,
! 179: sizeof(u_int64_t), NULL, 0);
! 180:
! 181: /*
! 182: * Set up window 0 as an 8MB SGMAP-mapped window
! 183: * starting at 8MB.
! 184: */
! 185: REGVAL64(LCA_IOC_W_BASE0) = LCA_SGMAP_MAPPED_BASE |
! 186: IOC_W_BASE_SG | IOC_W_BASE_WEN;
! 187: alpha_mb();
! 188:
! 189: REGVAL64(LCA_IOC_W_MASK0) = IOC_W_MASK_8M;
! 190: alpha_mb();
! 191:
! 192: if ((lcp->lc_sgmap.aps_ptpa & IOC_W_T_BASE) !=
! 193: lcp->lc_sgmap.aps_ptpa)
! 194: panic("lca_dma_init: bad page table address");
! 195: REGVAL64(LCA_IOC_W_T_BASE0) = lcp->lc_sgmap.aps_ptpa;
! 196: alpha_mb();
! 197:
! 198: /* Enable the scatter/gather TLB. */
! 199: REGVAL64(LCA_IOC_TB_ENA) = IOC_TB_ENA_TEN;
! 200: alpha_mb();
! 201:
! 202: LCA_TLB_INVALIDATE();
! 203:
! 204: /* XXX XXX BEGIN XXX XXX */
! 205: { /* XXX */
! 206: extern paddr_t alpha_XXX_dmamap_or; /* XXX */
! 207: alpha_XXX_dmamap_or = LCA_DIRECT_MAPPED_BASE; /* XXX */
! 208: } /* XXX */
! 209: /* XXX XXX END XXX XXX */
! 210: }
! 211:
! 212: /*
! 213: * Return the bus dma tag to be used for the specified bus type.
! 214: * INTERNAL USE ONLY!
! 215: */
! 216: bus_dma_tag_t
! 217: lca_dma_get_tag(t, bustype)
! 218: bus_dma_tag_t t;
! 219: alpha_bus_t bustype;
! 220: {
! 221: struct lca_config *lcp = t->_cookie;
! 222:
! 223: switch (bustype) {
! 224: case ALPHA_BUS_PCI:
! 225: case ALPHA_BUS_EISA:
! 226: /*
! 227: * Systems with an LCA can only support 1G
! 228: * of memory, so we use the direct-mapped window
! 229: * on busses that have 32-bit DMA.
! 230: */
! 231: return (&lcp->lc_dmat_direct);
! 232:
! 233: case ALPHA_BUS_ISA:
! 234: /*
! 235: * ISA doesn't have enough address bits to use
! 236: * the direct-mapped DMA window, so we must use
! 237: * SGMAPs.
! 238: */
! 239: return (&lcp->lc_dmat_sgmap);
! 240:
! 241: default:
! 242: panic("lca_dma_get_tag: shouldn't be here, really...");
! 243: }
! 244: }
! 245:
! 246: /*
! 247: * Load an LCA SGMAP-mapped DMA map with a linear buffer.
! 248: */
! 249: int
! 250: lca_bus_dmamap_load_sgmap(t, map, buf, buflen, p, flags)
! 251: bus_dma_tag_t t;
! 252: bus_dmamap_t map;
! 253: void *buf;
! 254: bus_size_t buflen;
! 255: struct proc *p;
! 256: int flags;
! 257: {
! 258: int error;
! 259:
! 260: error = pci_sgmap_pte64_load(t, map, buf, buflen, p, flags,
! 261: t->_sgmap);
! 262: if (error == 0)
! 263: LCA_TLB_INVALIDATE();
! 264:
! 265: return (error);
! 266: }
! 267:
! 268: /*
! 269: * Load an LCA SGMAP-mapped DMA map with an mbuf chain.
! 270: */
! 271: int
! 272: lca_bus_dmamap_load_mbuf_sgmap(t, map, m, flags)
! 273: bus_dma_tag_t t;
! 274: bus_dmamap_t map;
! 275: struct mbuf *m;
! 276: int flags;
! 277: {
! 278: int error;
! 279:
! 280: error = pci_sgmap_pte64_load_mbuf(t, map, m, flags, t->_sgmap);
! 281: if (error == 0)
! 282: LCA_TLB_INVALIDATE();
! 283:
! 284: return (error);
! 285: }
! 286:
! 287: /*
! 288: * Load an LCA SGMAP-mapped DMA map with a uio.
! 289: */
! 290: int
! 291: lca_bus_dmamap_load_uio_sgmap(t, map, uio, flags)
! 292: bus_dma_tag_t t;
! 293: bus_dmamap_t map;
! 294: struct uio *uio;
! 295: int flags;
! 296: {
! 297: int error;
! 298:
! 299: error = pci_sgmap_pte64_load_uio(t, map, uio, flags, t->_sgmap);
! 300: if (error == 0)
! 301: LCA_TLB_INVALIDATE();
! 302:
! 303: return (error);
! 304: }
! 305:
! 306: /*
! 307: * Load an LCA SGMAP-mapped DMA map with raw memory.
! 308: */
! 309: int
! 310: lca_bus_dmamap_load_raw_sgmap(t, map, segs, nsegs, size, flags)
! 311: bus_dma_tag_t t;
! 312: bus_dmamap_t map;
! 313: bus_dma_segment_t *segs;
! 314: int nsegs;
! 315: bus_size_t size;
! 316: int flags;
! 317: {
! 318: int error;
! 319:
! 320: error = pci_sgmap_pte64_load_raw(t, map, segs, nsegs, size, flags,
! 321: t->_sgmap);
! 322: if (error == 0)
! 323: LCA_TLB_INVALIDATE();
! 324:
! 325: return (error);
! 326: }
! 327:
! 328: /*
! 329: * Unload an LCA DMA map.
! 330: */
! 331: void
! 332: lca_bus_dmamap_unload_sgmap(t, map)
! 333: bus_dma_tag_t t;
! 334: bus_dmamap_t map;
! 335: {
! 336:
! 337: /*
! 338: * Invalidate any SGMAP page table entries used by this
! 339: * mapping.
! 340: */
! 341: pci_sgmap_pte64_unload(t, map, t->_sgmap);
! 342: LCA_TLB_INVALIDATE();
! 343:
! 344: /*
! 345: * Do the generic bits of the unload.
! 346: */
! 347: _bus_dmamap_unload(t, map);
! 348: }
CVSweb