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

Annotation of sys/arch/alpha/tc/tc_dma_3000_500.c, Revision 1.1.1.1

1.1       nbrk        1: /* $OpenBSD: tc_dma_3000_500.c,v 1.2 2006/04/04 21:20:40 brad Exp $ */
                      2: /* $NetBSD: tc_dma_3000_500.c,v 1.13 2001/07/19 06:40:03 thorpej 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: #define _ALPHA_BUS_DMA_PRIVATE
                     42:
                     43: #include <sys/param.h>
                     44: #include <sys/systm.h>
                     45: #include <sys/device.h>
                     46: #include <sys/kernel.h>
                     47: #include <sys/malloc.h>
                     48:
                     49: #include <uvm/uvm_extern.h>
                     50:
                     51: #include <machine/bus.h>
                     52:
                     53: #include <dev/tc/tcvar.h>
                     54: #include <alpha/tc/tc_sgmap.h>
                     55: #include <alpha/tc/tc_dma_3000_500.h>
                     56:
                     57: struct alpha_bus_dma_tag tc_dmat_sgmap = {
                     58:        NULL,                           /* _cookie */
                     59:        0,                              /* _wbase */
                     60:        0,                              /* _wsize */
                     61:        NULL,                           /* _next_window */
                     62:        0,                              /* _boundary */
                     63:        NULL,                           /* _sgmap */
                     64:        0,                              /* _pfthresh */
                     65:        NULL,                           /* _get_tag */
                     66:        tc_bus_dmamap_create_sgmap,
                     67:        tc_bus_dmamap_destroy_sgmap,
                     68:        tc_bus_dmamap_load_sgmap,
                     69:        tc_bus_dmamap_load_mbuf_sgmap,
                     70:        tc_bus_dmamap_load_uio_sgmap,
                     71:        tc_bus_dmamap_load_raw_sgmap,
                     72:        tc_bus_dmamap_unload_sgmap,
                     73:        _bus_dmamap_sync,
                     74:        _bus_dmamem_alloc,
                     75:        _bus_dmamem_free,
                     76:        _bus_dmamem_map,
                     77:        _bus_dmamem_unmap,
                     78:        _bus_dmamem_mmap,
                     79: };
                     80:
                     81: struct tc_dma_slot_info {
                     82:        struct alpha_sgmap tdsi_sgmap;          /* sgmap for slot */
                     83:        struct alpha_bus_dma_tag tdsi_dmat;     /* dma tag for slot */
                     84: };
                     85: struct tc_dma_slot_info *tc_dma_slot_info;
                     86:
                     87: void
                     88: tc_dma_init_3000_500(nslots)
                     89:        int nslots;
                     90: {
                     91:        extern struct alpha_bus_dma_tag tc_dmat_direct;
                     92:        size_t sisize;
                     93:        int i;
                     94:
                     95:        /* Allocate per-slot DMA info. */
                     96:        sisize = nslots * sizeof(struct tc_dma_slot_info);
                     97:        tc_dma_slot_info = malloc(sisize, M_DEVBUF, M_NOWAIT);
                     98:        if (tc_dma_slot_info == NULL)
                     99:                panic("tc_dma_init: can't allocate per-slot DMA info");
                    100:        memset(tc_dma_slot_info, 0, sisize);
                    101:
                    102:        /* Default all slots to direct-mapped. */
                    103:        for (i = 0; i < nslots; i++)
                    104:                memcpy(&tc_dma_slot_info[i].tdsi_dmat, &tc_dmat_direct,
                    105:                    sizeof(tc_dma_slot_info[i].tdsi_dmat));
                    106: }
                    107:
                    108: /*
                    109:  * Return the DMA tag for the given slot.
                    110:  */
                    111: bus_dma_tag_t
                    112: tc_dma_get_tag_3000_500(slot)
                    113:        int slot;
                    114: {
                    115:
                    116:        return (&tc_dma_slot_info[slot].tdsi_dmat);
                    117: }
                    118:
                    119: /*
                    120:  * Create a TurboChannel SGMAP-mapped DMA map.
                    121:  */
                    122: int
                    123: tc_bus_dmamap_create_sgmap(t, size, nsegments, maxsegsz, boundary,
                    124:     flags, dmamp)
                    125:        bus_dma_tag_t t;
                    126:        bus_size_t size;
                    127:        int nsegments;
                    128:        bus_size_t maxsegsz;
                    129:        bus_size_t boundary;
                    130:        int flags;
                    131:        bus_dmamap_t *dmamp;
                    132: {
                    133:        bus_dmamap_t map;
                    134:        int error;
                    135:
                    136:        error = _bus_dmamap_create(t, size, nsegments, maxsegsz,
                    137:            boundary, flags, dmamp);
                    138:        if (error)
                    139:                return (error);
                    140:
                    141:        map = *dmamp;
                    142:
                    143:        /* XXX BUS_DMA_ALLOCNOW */
                    144:
                    145:        return (error);
                    146: }
                    147:
                    148: /*
                    149:  * Destroy a TurboChannel SGMAP-mapped DMA map.
                    150:  */
                    151: void
                    152: tc_bus_dmamap_destroy_sgmap(t, map)
                    153:        bus_dma_tag_t t;
                    154:        bus_dmamap_t map;
                    155: {
                    156:
                    157:        KASSERT(map->dm_mapsize == 0);
                    158:
                    159:        _bus_dmamap_destroy(t, map);
                    160: }
                    161:
                    162: /*
                    163:  * Load a TurboChannel SGMAP-mapped DMA map with a linear buffer.
                    164:  */
                    165: int
                    166: tc_bus_dmamap_load_sgmap(t, map, buf, buflen, p, flags)
                    167:        bus_dma_tag_t t;
                    168:        bus_dmamap_t map;
                    169:        void *buf;
                    170:        bus_size_t buflen;
                    171:        struct proc *p;
                    172:        int flags;
                    173: {
                    174:        struct tc_dma_slot_info *tdsi = t->_cookie;
                    175:
                    176:        return (tc_sgmap_load(t, map, buf, buflen, p, flags,
                    177:            &tdsi->tdsi_sgmap));
                    178: }
                    179:
                    180: /*
                    181:  * Load a TurboChannel SGMAP-mapped DMA map with an mbuf chain.
                    182:  */
                    183: int
                    184: tc_bus_dmamap_load_mbuf_sgmap(t, map, m, flags)
                    185:        bus_dma_tag_t t;
                    186:        bus_dmamap_t map;
                    187:        struct mbuf *m;
                    188:        int flags;
                    189: {
                    190:        struct tc_dma_slot_info *tdsi = t->_cookie;
                    191:
                    192:        return (tc_sgmap_load_mbuf(t, map, m, flags, &tdsi->tdsi_sgmap));
                    193: }
                    194:
                    195: /*
                    196:  * Load a TurboChannel SGMAP-mapped DMA map with a uio.
                    197:  */
                    198: int
                    199: tc_bus_dmamap_load_uio_sgmap(t, map, uio, flags)
                    200:        bus_dma_tag_t t;
                    201:        bus_dmamap_t map;
                    202:        struct uio *uio;
                    203:        int flags;
                    204: {
                    205:        struct tc_dma_slot_info *tdsi = t->_cookie;
                    206:
                    207:        return (tc_sgmap_load_uio(t, map, uio, flags, &tdsi->tdsi_sgmap));
                    208: }
                    209:
                    210: /*
                    211:  * Load a TurboChannel SGMAP-mapped DMA map with raw memory.
                    212:  */
                    213: int
                    214: tc_bus_dmamap_load_raw_sgmap(t, map, segs, nsegs, size, flags)
                    215:        bus_dma_tag_t t;
                    216:        bus_dmamap_t map;
                    217:        bus_dma_segment_t *segs;
                    218:        int nsegs;
                    219:        bus_size_t size;
                    220:        int flags;
                    221: {
                    222:        struct tc_dma_slot_info *tdsi = t->_cookie;
                    223:
                    224:        return (tc_sgmap_load_raw(t, map, segs, nsegs, size, flags,
                    225:            &tdsi->tdsi_sgmap));
                    226: }
                    227:
                    228: /*
                    229:  * Unload a TurboChannel SGMAP-mapped DMA map.
                    230:  */
                    231: void
                    232: tc_bus_dmamap_unload_sgmap(t, map)
                    233:        bus_dma_tag_t t;
                    234:        bus_dmamap_t map;
                    235: {
                    236:        struct tc_dma_slot_info *tdsi = t->_cookie;
                    237:
                    238:        /*
                    239:         * Invalidate any SGMAP page table entries used by this
                    240:         * mapping.
                    241:         */
                    242:        tc_sgmap_unload(t, map, &tdsi->tdsi_sgmap);
                    243:
                    244:        /*
                    245:         * Do the generic bits of the unload.
                    246:         */
                    247:        _bus_dmamap_unload(t, map);
                    248: }

CVSweb