[BACK]Return to apecs_dma.c CVS log [TXT][DIR] Up to [local] / sys / arch / alpha / pci

Annotation of sys/arch/alpha/pci/apecs_dma.c, Revision 1.1.1.1

1.1       nbrk        1: /* $OpenBSD: apecs_dma.c,v 1.5 2006/04/04 21:20:40 brad Exp $ */
                      2: /* $NetBSD: apecs_dma.c,v 1.13 2000/06/29 08:58:45 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/apecsreg.h>
                     60: #include <alpha/pci/apecsvar.h>
                     61:
                     62: bus_dma_tag_t apecs_dma_get_tag(bus_dma_tag_t, alpha_bus_t);
                     63:
                     64: int    apecs_bus_dmamap_load_sgmap(bus_dma_tag_t, bus_dmamap_t, void *,
                     65:            bus_size_t, struct proc *, int);
                     66:
                     67: int    apecs_bus_dmamap_load_mbuf_sgmap(bus_dma_tag_t, bus_dmamap_t,
                     68:            struct mbuf *, int);
                     69:
                     70: int    apecs_bus_dmamap_load_uio_sgmap(bus_dma_tag_t, bus_dmamap_t,
                     71:            struct uio *, int);
                     72:
                     73: int    apecs_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   apecs_bus_dmamap_unload_sgmap(bus_dma_tag_t, bus_dmamap_t);
                     77:
                     78: /*
                     79:  * Direct-mapped window: 1G at 1G
                     80:  */
                     81: #define        APECS_DIRECT_MAPPED_BASE (1*1024*1024*1024)
                     82: #define        APECS_DIRECT_MAPPED_SIZE (1*1024*1024*1024)
                     83:
                     84: /*
                     85:  * SGMAP window: 8M at 8M
                     86:  */
                     87: #define        APECS_SGMAP_MAPPED_BASE (8*1024*1024)
                     88: #define        APECS_SGMAP_MAPPED_SIZE (8*1024*1024)
                     89:
                     90: /* APECS has a 256-byte out-bound DMA prefetch threshold. */
                     91: #define        APECS_SGMAP_PFTHRESH    256
                     92:
                     93: /*
                     94:  * Macro to flush APECS scatter/gather TLB.
                     95:  */
                     96: #define        APECS_TLB_INVALIDATE() \
                     97: do { \
                     98:        alpha_mb(); \
                     99:        REGVAL(EPIC_TBIA) = 0; \
                    100:        alpha_mb(); \
                    101: } while (0)
                    102:
                    103: void
                    104: apecs_dma_init(acp)
                    105:        struct apecs_config *acp;
                    106: {
                    107:        bus_addr_t tbase;
                    108:        bus_dma_tag_t t;
                    109:
                    110:        /*
                    111:         * Initialize the DMA tag used for direct-mapped DMA.
                    112:         */
                    113:        t = &acp->ac_dmat_direct;
                    114:        t->_cookie = acp;
                    115:        t->_wbase = APECS_DIRECT_MAPPED_BASE;
                    116:        t->_wsize = APECS_DIRECT_MAPPED_SIZE;
                    117:        t->_next_window = NULL;
                    118:        t->_boundary = 0;
                    119:        t->_sgmap = NULL;
                    120:        t->_get_tag = apecs_dma_get_tag;
                    121:        t->_dmamap_create = _bus_dmamap_create;
                    122:        t->_dmamap_destroy = _bus_dmamap_destroy;
                    123:        t->_dmamap_load = _bus_dmamap_load_direct;
                    124:        t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct;
                    125:        t->_dmamap_load_uio = _bus_dmamap_load_uio_direct;
                    126:        t->_dmamap_load_raw = _bus_dmamap_load_raw_direct;
                    127:        t->_dmamap_unload = _bus_dmamap_unload;
                    128:        t->_dmamap_sync = _bus_dmamap_sync;
                    129:
                    130:        t->_dmamem_alloc = _bus_dmamem_alloc;
                    131:        t->_dmamem_free = _bus_dmamem_free;
                    132:        t->_dmamem_map = _bus_dmamem_map;
                    133:        t->_dmamem_unmap = _bus_dmamem_unmap;
                    134:        t->_dmamem_mmap = _bus_dmamem_mmap;
                    135:
                    136:        /*
                    137:         * Initialize the DMA tag used for sgmap-mapped DMA.
                    138:         */
                    139:        t = &acp->ac_dmat_sgmap;
                    140:        t->_cookie = acp;
                    141:        t->_wbase = APECS_SGMAP_MAPPED_BASE;
                    142:        t->_wsize = APECS_SGMAP_MAPPED_SIZE;
                    143:        t->_next_window = NULL;
                    144:        t->_boundary = 0;
                    145:        t->_sgmap = &acp->ac_sgmap;
                    146:        t->_pfthresh = APECS_SGMAP_PFTHRESH;
                    147:        t->_get_tag = apecs_dma_get_tag;
                    148:        t->_dmamap_create = alpha_sgmap_dmamap_create;
                    149:        t->_dmamap_destroy = alpha_sgmap_dmamap_destroy;
                    150:        t->_dmamap_load = apecs_bus_dmamap_load_sgmap;
                    151:        t->_dmamap_load_mbuf = apecs_bus_dmamap_load_mbuf_sgmap;
                    152:        t->_dmamap_load_uio = apecs_bus_dmamap_load_uio_sgmap;
                    153:        t->_dmamap_load_raw = apecs_bus_dmamap_load_raw_sgmap;
                    154:        t->_dmamap_unload = apecs_bus_dmamap_unload_sgmap;
                    155:        t->_dmamap_sync = _bus_dmamap_sync;
                    156:
                    157:        t->_dmamem_alloc = _bus_dmamem_alloc;
                    158:        t->_dmamem_free = _bus_dmamem_free;
                    159:        t->_dmamem_map = _bus_dmamem_map;
                    160:        t->_dmamem_unmap = _bus_dmamem_unmap;
                    161:        t->_dmamem_mmap = _bus_dmamem_mmap;
                    162:
                    163:        /*
                    164:         * The firmware has set up window 2 as a 1G direct-mapped DMA
                    165:         * window beginning at 1G.  We leave it alone.  Disable
                    166:         * window 1.
                    167:         */
                    168:        REGVAL(EPIC_PCI_BASE_1) = 0;
                    169:        alpha_mb();
                    170:
                    171:        /*
                    172:         * Initialize the SGMAP.
                    173:         */
                    174:        alpha_sgmap_init(t, &acp->ac_sgmap, "apecs_sgmap",
                    175:            APECS_SGMAP_MAPPED_BASE, 0, APECS_SGMAP_MAPPED_SIZE,
                    176:            sizeof(u_int64_t), NULL, 0);
                    177:
                    178:        /*
                    179:         * Set up window 1 as an 8MB SGMAP-mapped window
                    180:         * starting at 8MB.
                    181:         */
                    182:        REGVAL(EPIC_PCI_BASE_1) = APECS_SGMAP_MAPPED_BASE |
                    183:            EPIC_PCI_BASE_SGEN | EPIC_PCI_BASE_WENB;
                    184:        alpha_mb();
                    185:
                    186:        REGVAL(EPIC_PCI_MASK_1) = EPIC_PCI_MASK_8M;
                    187:        alpha_mb();
                    188:
                    189:        tbase = acp->ac_sgmap.aps_ptpa >> EPIC_TBASE_SHIFT;
                    190:        if ((tbase & EPIC_TBASE_T_BASE) != tbase)
                    191:                panic("apecs_dma_init: bad page table address");
                    192:        REGVAL(EPIC_TBASE_1) = tbase;
                    193:        alpha_mb();
                    194:
                    195:        APECS_TLB_INVALIDATE();
                    196:
                    197:        /* XXX XXX BEGIN XXX XXX */
                    198:        {                                                       /* XXX */
                    199:                extern paddr_t alpha_XXX_dmamap_or;             /* XXX */
                    200:                alpha_XXX_dmamap_or = APECS_DIRECT_MAPPED_BASE; /* XXX */
                    201:        }                                                       /* XXX */
                    202:        /* XXX XXX END XXX XXX */
                    203: }
                    204:
                    205: /*
                    206:  * Return the bus dma tag to be used for the specified bus type.
                    207:  * INTERNAL USE ONLY!
                    208:  */
                    209: bus_dma_tag_t
                    210: apecs_dma_get_tag(t, bustype)
                    211:        bus_dma_tag_t t;
                    212:        alpha_bus_t bustype;
                    213: {
                    214:        struct apecs_config *acp = t->_cookie;
                    215:
                    216:        switch (bustype) {
                    217:        case ALPHA_BUS_PCI:
                    218:        case ALPHA_BUS_EISA:
                    219:                /*
                    220:                 * Systems with an APECS can only support 1G
                    221:                 * of memory, so we use the direct-mapped window
                    222:                 * on busses that have 32-bit DMA.
                    223:                 */
                    224:                return (&acp->ac_dmat_direct);
                    225:
                    226:        case ALPHA_BUS_ISA:
                    227:                /*
                    228:                 * ISA doesn't have enough address bits to use
                    229:                 * the direct-mapped DMA window, so we must use
                    230:                 * SGMAPs.
                    231:                 */
                    232:                return (&acp->ac_dmat_sgmap);
                    233:
                    234:        default:
                    235:                panic("apecs_dma_get_tag: shouldn't be here, really...");
                    236:        }
                    237: }
                    238:
                    239: /*
                    240:  * Load an APECS SGMAP-mapped DMA map with a linear buffer.
                    241:  */
                    242: int
                    243: apecs_bus_dmamap_load_sgmap(t, map, buf, buflen, p, flags)
                    244:        bus_dma_tag_t t;
                    245:        bus_dmamap_t map;
                    246:        void *buf;
                    247:        bus_size_t buflen;
                    248:        struct proc *p;
                    249:        int flags;
                    250: {
                    251:        int error;
                    252:
                    253:        error = pci_sgmap_pte64_load(t, map, buf, buflen, p, flags,
                    254:            t->_sgmap);
                    255:        if (error == 0)
                    256:                APECS_TLB_INVALIDATE();
                    257:
                    258:        return (error);
                    259: }
                    260:
                    261: /*
                    262:  * Load an APECS SGMAP-mapped DMA map with an mbuf chain.
                    263:  */
                    264: int
                    265: apecs_bus_dmamap_load_mbuf_sgmap(t, map, m, flags)
                    266:        bus_dma_tag_t t;
                    267:        bus_dmamap_t map;
                    268:        struct mbuf *m;
                    269:        int flags;
                    270: {
                    271:        int error;
                    272:
                    273:        error = pci_sgmap_pte64_load_mbuf(t, map, m, flags, t->_sgmap);
                    274:        if (error == 0)
                    275:                APECS_TLB_INVALIDATE();
                    276:
                    277:        return (error);
                    278: }
                    279:
                    280: /*
                    281:  * Load an APECS SGMAP-mapped DMA map with a uio.
                    282:  */
                    283: int
                    284: apecs_bus_dmamap_load_uio_sgmap(t, map, uio, flags)
                    285:        bus_dma_tag_t t;
                    286:        bus_dmamap_t map;
                    287:        struct uio *uio;
                    288:        int flags;
                    289: {
                    290:        int error;
                    291:
                    292:        error = pci_sgmap_pte64_load_uio(t, map, uio, flags, t->_sgmap);
                    293:        if (error == 0)
                    294:                APECS_TLB_INVALIDATE();
                    295:
                    296:        return (error);
                    297: }
                    298:
                    299: /*
                    300:  * Load an APECS SGMAP-mapped DMA map with raw memory.
                    301:  */
                    302: int
                    303: apecs_bus_dmamap_load_raw_sgmap(t, map, segs, nsegs, size, flags)
                    304:        bus_dma_tag_t t;
                    305:        bus_dmamap_t map;
                    306:        bus_dma_segment_t *segs;
                    307:        int nsegs;
                    308:        bus_size_t size;
                    309:        int flags;
                    310: {
                    311:        int error;
                    312:
                    313:        error = pci_sgmap_pte64_load_raw(t, map, segs, nsegs, size, flags,
                    314:            t->_sgmap);
                    315:        if (error == 0)
                    316:                APECS_TLB_INVALIDATE();
                    317:
                    318:        return (error);
                    319: }
                    320:
                    321: /*
                    322:  * Unload an APECS DMA map.
                    323:  */
                    324: void
                    325: apecs_bus_dmamap_unload_sgmap(t, map)
                    326:        bus_dma_tag_t t;
                    327:        bus_dmamap_t map;
                    328: {
                    329:
                    330:        /*
                    331:         * Invalidate any SGMAP page table entries used by this
                    332:         * mapping.
                    333:         */
                    334:        pci_sgmap_pte64_unload(t, map, t->_sgmap);
                    335:        APECS_TLB_INVALIDATE();
                    336:
                    337:        /*
                    338:         * Do the generic bits of the unload.
                    339:         */
                    340:        _bus_dmamap_unload(t, map);
                    341: }

CVSweb