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

Annotation of sys/arch/alpha/dev/sgmap_common.c, Revision 1.1

1.1     ! nbrk        1: /* $OpenBSD: sgmap_common.c,v 1.9 2006/04/13 14:41:08 brad Exp $ */
        !             2: /* $NetBSD: sgmap_common.c,v 1.13 2000/06/29 09:02:57 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: #define _ALPHA_BUS_DMA_PRIVATE
        !            42:
        !            43: #include <sys/param.h>
        !            44: #include <sys/systm.h>
        !            45: #include <sys/kernel.h>
        !            46: #include <sys/malloc.h>
        !            47: #include <sys/proc.h>
        !            48:
        !            49: #include <uvm/uvm_extern.h>
        !            50:
        !            51: #include <machine/bus.h>
        !            52:
        !            53: #include <alpha/dev/sgmapvar.h>
        !            54:
        !            55: /*
        !            56:  * Some systems will prefetch the next page during a memory -> device DMA.
        !            57:  * This can cause machine checks if there is not a spill page after the
        !            58:  * last page of the DMA (thus avoiding hitting an invalid SGMAP PTE).
        !            59:  */
        !            60: vaddr_t                alpha_sgmap_prefetch_spill_page_va;
        !            61: bus_addr_t     alpha_sgmap_prefetch_spill_page_pa;
        !            62:
        !            63: void
        !            64: alpha_sgmap_init(t, sgmap, name, wbase, sgvabase, sgvasize, ptesize, ptva,
        !            65:     minptalign)
        !            66:        bus_dma_tag_t t;
        !            67:        struct alpha_sgmap *sgmap;
        !            68:        const char *name;
        !            69:        bus_addr_t wbase;
        !            70:        bus_addr_t sgvabase;
        !            71:        bus_size_t sgvasize;
        !            72:        size_t ptesize;
        !            73:        void *ptva;
        !            74:        bus_size_t minptalign;
        !            75: {
        !            76:        bus_dma_segment_t seg;
        !            77:        size_t ptsize;
        !            78:        int rseg;
        !            79:
        !            80:        if (sgvasize & PGOFSET) {
        !            81:                printf("size botch for sgmap `%s'\n", name);
        !            82:                goto die;
        !            83:        }
        !            84:
        !            85:        sgmap->aps_wbase = wbase;
        !            86:        sgmap->aps_sgvabase = sgvabase;
        !            87:        sgmap->aps_sgvasize = sgvasize;
        !            88:
        !            89:        if (ptva != NULL) {
        !            90:                /*
        !            91:                 * We already have a page table; this may be a system
        !            92:                 * where the page table resides in bridge-resident SRAM.
        !            93:                 */
        !            94:                sgmap->aps_pt = ptva;
        !            95:                sgmap->aps_ptpa = 0;
        !            96:        } else {
        !            97:                /*
        !            98:                 * Compute the page table size and allocate it.  At minimum,
        !            99:                 * this must be aligned to the page table size.  However,
        !           100:                 * some platforms have more strict alignment requirements.
        !           101:                 */
        !           102:                ptsize = (sgvasize / PAGE_SIZE) * ptesize;
        !           103:                if (minptalign != 0) {
        !           104:                        if (minptalign < ptsize)
        !           105:                                minptalign = ptsize;
        !           106:                } else
        !           107:                        minptalign = ptsize;
        !           108:                if (bus_dmamem_alloc(t, ptsize, minptalign, 0, &seg, 1, &rseg,
        !           109:                    BUS_DMA_NOWAIT)) {
        !           110:                        panic("unable to allocate page table for sgmap `%s'",
        !           111:                            name);
        !           112:                        goto die;
        !           113:                }
        !           114:                sgmap->aps_ptpa = seg.ds_addr;
        !           115:                sgmap->aps_pt = (caddr_t)ALPHA_PHYS_TO_K0SEG(sgmap->aps_ptpa);
        !           116:        }
        !           117:
        !           118:        /*
        !           119:         * Create the extent map used to manage the virtual address
        !           120:         * space.
        !           121:         */
        !           122:        sgmap->aps_ex = extent_create((char *)name, sgvabase, sgvasize - 1,
        !           123:            M_DEVBUF, NULL, 0, EX_NOWAIT|EX_NOCOALESCE);
        !           124:        if (sgmap->aps_ex == NULL) {
        !           125:                printf("unable to create extent map for sgmap `%s'\n",
        !           126:                    name);
        !           127:                goto die;
        !           128:        }
        !           129:
        !           130:        /*
        !           131:         * Allocate a spill page if that hasn't already been done.
        !           132:         */
        !           133:        if (alpha_sgmap_prefetch_spill_page_va == 0) {
        !           134:                if (bus_dmamem_alloc(t, PAGE_SIZE, 0, 0, &seg, 1, &rseg,
        !           135:                    BUS_DMA_NOWAIT)) {
        !           136:                        printf("unable to allocate spill page for sgmap `%s'\n",
        !           137:                            name);
        !           138:                        goto die;
        !           139:                }
        !           140:                alpha_sgmap_prefetch_spill_page_pa = seg.ds_addr;
        !           141:                alpha_sgmap_prefetch_spill_page_va =
        !           142:                    ALPHA_PHYS_TO_K0SEG(alpha_sgmap_prefetch_spill_page_pa);
        !           143:                bzero((caddr_t)alpha_sgmap_prefetch_spill_page_va, PAGE_SIZE);
        !           144:        }
        !           145:
        !           146:        return;
        !           147:  die:
        !           148:        panic("alpha_sgmap_init");
        !           149: }
        !           150:
        !           151: int
        !           152: alpha_sgmap_dmamap_create(t, size, nsegments, maxsegsz, boundary,
        !           153:     flags, dmamp)
        !           154:        bus_dma_tag_t t;
        !           155:        bus_size_t size;
        !           156:        int nsegments;
        !           157:        bus_size_t maxsegsz;
        !           158:        bus_size_t boundary;
        !           159:        int flags;
        !           160:        bus_dmamap_t *dmamp;
        !           161: {
        !           162:        bus_dmamap_t map;
        !           163:        int error;
        !           164:
        !           165:        error = _bus_dmamap_create(t, size, nsegments, maxsegsz,
        !           166:            boundary, flags, dmamp);
        !           167:        if (error)
        !           168:                return (error);
        !           169:
        !           170:        map = *dmamp;
        !           171:
        !           172:        /* XXX BUS_DMA_ALLOCNOW */
        !           173:
        !           174:        return (error);
        !           175: }
        !           176:
        !           177: void
        !           178: alpha_sgmap_dmamap_destroy(t, map)
        !           179:        bus_dma_tag_t t;
        !           180:        bus_dmamap_t map;
        !           181: {
        !           182:        KASSERT(map->dm_mapsize == 0);
        !           183:
        !           184:        _bus_dmamap_destroy(t, map);
        !           185: }

CVSweb