From e00571939f85829ae561001db340acf4c46ea2f5 Mon Sep 17 00:00:00 2001 From: Artur Grabowski Date: Wed, 21 Mar 2001 17:26:40 +0000 Subject: Move files from common to dev to be more like other archs (and so that tab completion on "compile" works as on other archs. :)) --- sys/arch/alpha/common/bus_dma.c | 674 ---------------------------------- sys/arch/alpha/common/sgmap_common.c | 225 ------------ sys/arch/alpha/common/sgmap_typedep.c | 331 ----------------- sys/arch/alpha/common/sgmap_typedep.h | 59 --- sys/arch/alpha/common/sgmapvar.h | 96 ----- sys/arch/alpha/conf/files.alpha | 6 +- sys/arch/alpha/dev/bus_dma.c | 674 ++++++++++++++++++++++++++++++++++ sys/arch/alpha/dev/sgmap_common.c | 225 ++++++++++++ sys/arch/alpha/dev/sgmap_typedep.c | 331 +++++++++++++++++ sys/arch/alpha/dev/sgmap_typedep.h | 59 +++ sys/arch/alpha/dev/sgmapvar.h | 96 +++++ sys/arch/alpha/pci/pci_sgmap_pte64.c | 4 +- sys/arch/alpha/pci/pci_sgmap_pte64.h | 6 +- 13 files changed, 1393 insertions(+), 1393 deletions(-) delete mode 100644 sys/arch/alpha/common/bus_dma.c delete mode 100644 sys/arch/alpha/common/sgmap_common.c delete mode 100644 sys/arch/alpha/common/sgmap_typedep.c delete mode 100644 sys/arch/alpha/common/sgmap_typedep.h delete mode 100644 sys/arch/alpha/common/sgmapvar.h create mode 100644 sys/arch/alpha/dev/bus_dma.c create mode 100644 sys/arch/alpha/dev/sgmap_common.c create mode 100644 sys/arch/alpha/dev/sgmap_typedep.c create mode 100644 sys/arch/alpha/dev/sgmap_typedep.h create mode 100644 sys/arch/alpha/dev/sgmapvar.h (limited to 'sys/arch/alpha') diff --git a/sys/arch/alpha/common/bus_dma.c b/sys/arch/alpha/common/bus_dma.c deleted file mode 100644 index bf6f95c9ed3..00000000000 --- a/sys/arch/alpha/common/bus_dma.c +++ /dev/null @@ -1,674 +0,0 @@ -/* $OpenBSD: bus_dma.c,v 1.2 2000/11/08 21:27:09 ericj Exp $ */ -/* $NetBSD: bus_dma.c,v 1.40 2000/07/17 04:47:56 thorpej Exp $ */ - -/*- - * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, - * NASA Ames Research Center. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#define _ALPHA_BUS_DMA_PRIVATE -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -int _bus_dmamap_load_buffer_direct_common __P((bus_dma_tag_t, - bus_dmamap_t, void *, bus_size_t, struct proc *, int, - paddr_t *, int *, int)); - -extern paddr_t avail_start, avail_end; /* from pmap.c */ - -/* - * Common function for DMA map creation. May be called by bus-specific - * DMA map creation functions. - */ -int -_bus_dmamap_create(t, size, nsegments, maxsegsz, boundary, flags, dmamp) - bus_dma_tag_t t; - bus_size_t size; - int nsegments; - bus_size_t maxsegsz; - bus_size_t boundary; - int flags; - bus_dmamap_t *dmamp; -{ - struct alpha_bus_dmamap *map; - void *mapstore; - size_t mapsize; - - /* - * Allocate and initialize the DMA map. The end of the map - * is a variable-sized array of segments, so we allocate enough - * room for them in one shot. - * - * Note we don't preserve the WAITOK or NOWAIT flags. Preservation - * of ALLOCNOW notifes others that we've reserved these resources, - * and they are not to be freed. - * - * The bus_dmamap_t includes one bus_dma_segment_t, hence - * the (nsegments - 1). - */ - mapsize = sizeof(struct alpha_bus_dmamap) + - (sizeof(bus_dma_segment_t) * (nsegments - 1)); - if ((mapstore = malloc(mapsize, M_DEVBUF, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) - return (ENOMEM); - - bzero(mapstore, mapsize); - map = (struct alpha_bus_dmamap *)mapstore; - map->_dm_size = size; - map->_dm_segcnt = nsegments; - map->_dm_maxsegsz = maxsegsz; - if (t->_boundary != 0 && t->_boundary < boundary) - map->_dm_boundary = t->_boundary; - else - map->_dm_boundary = boundary; - map->_dm_flags = flags & ~(BUS_DMA_WAITOK|BUS_DMA_NOWAIT); - map->dm_mapsize = 0; /* no valid mappings */ - map->dm_nsegs = 0; - - *dmamp = map; - return (0); -} - -/* - * Common function for DMA map destruction. May be called by bus-specific - * DMA map destruction functions. - */ -void -_bus_dmamap_destroy(t, map) - bus_dma_tag_t t; - bus_dmamap_t map; -{ - - free(map, M_DEVBUF); -} - -/* - * Utility function to load a linear buffer. lastaddrp holds state - * between invocations (for multiple-buffer loads). segp contains - * the starting segment on entrance, and the ending segment on exit. - * first indicates if this is the first invocation of this function. - */ -int -_bus_dmamap_load_buffer_direct_common(t, map, buf, buflen, p, flags, - lastaddrp, segp, first) - bus_dma_tag_t t; - bus_dmamap_t map; - void *buf; - bus_size_t buflen; - struct proc *p; - int flags; - paddr_t *lastaddrp; - int *segp; - int first; -{ - bus_size_t sgsize; - bus_addr_t curaddr, lastaddr, baddr, bmask; - vaddr_t vaddr = (vaddr_t)buf; - int seg; - - lastaddr = *lastaddrp; - bmask = ~(map->_dm_boundary - 1); - - for (seg = *segp; buflen > 0 ; ) { - /* - * Get the physical address for this segment. - */ - if (p != NULL) - curaddr = pmap_extract(p->p_vmspace->vm_map.pmap, - vaddr); - else - curaddr = vtophys(vaddr); - - /* - * If we're beyond the current DMA window, indicate - * that and try to fall back into SGMAPs. - */ - if (t->_wsize != 0 && curaddr >= t->_wsize) - return (EINVAL); - - curaddr |= t->_wbase; - - /* - * Compute the segment size, and adjust counts. - */ - sgsize = NBPG - ((u_long)vaddr & PGOFSET); - if (buflen < sgsize) - sgsize = buflen; - if (map->_dm_maxsegsz < sgsize) - sgsize = map->_dm_maxsegsz; - - /* - * Make sure we don't cross any boundaries. - */ - if (map->_dm_boundary > 0) { - baddr = (curaddr + map->_dm_boundary) & bmask; - if (sgsize > (baddr - curaddr)) - sgsize = (baddr - curaddr); - } - - /* - * Insert chunk into a segment, coalescing with - * the previous segment if possible. - */ - if (first) { - map->dm_segs[seg].ds_addr = curaddr; - map->dm_segs[seg].ds_len = sgsize; - first = 0; - } else { - if ((map->_dm_flags & DMAMAP_NO_COALESCE) == 0 && - curaddr == lastaddr && - (map->dm_segs[seg].ds_len + sgsize) <= - map->_dm_maxsegsz && - (map->_dm_boundary == 0 || - (map->dm_segs[seg].ds_addr & bmask) == - (curaddr & bmask))) - map->dm_segs[seg].ds_len += sgsize; - else { - if (++seg >= map->_dm_segcnt) - break; - map->dm_segs[seg].ds_addr = curaddr; - map->dm_segs[seg].ds_len = sgsize; - } - } - - lastaddr = curaddr + sgsize; - vaddr += sgsize; - buflen -= sgsize; - } - - *segp = seg; - *lastaddrp = lastaddr; - - /* - * Did we fit? - */ - if (buflen != 0) { - /* - * If there is a chained window, we will automatically - * fall back to it. - */ - return (EFBIG); /* XXX better return value here? */ - } - - return (0); -} - -/* - * Common function for loading a direct-mapped DMA map with a linear - * buffer. Called by bus-specific DMA map load functions with the - * OR value appropriate for indicating "direct-mapped" for that - * chipset. - */ -int -_bus_dmamap_load_direct(t, map, buf, buflen, p, flags) - bus_dma_tag_t t; - bus_dmamap_t map; - void *buf; - bus_size_t buflen; - struct proc *p; - int flags; -{ - paddr_t lastaddr; - int seg, error; - - /* - * Make sure that on error condition we return "no valid mappings". - */ - map->dm_mapsize = 0; - map->dm_nsegs = 0; - - if (buflen > map->_dm_size) - return (EINVAL); - - seg = 0; - error = _bus_dmamap_load_buffer_direct_common(t, map, buf, buflen, - p, flags, &lastaddr, &seg, 1); - if (error == 0) { - map->dm_mapsize = buflen; - map->dm_nsegs = seg + 1; - } else if (t->_next_window != NULL) { - /* - * Give the next window a chance. - */ - error = bus_dmamap_load(t->_next_window, map, buf, buflen, - p, flags); - } - return (error); -} - -/* - * Like _bus_dmamap_load_direct_common(), but for mbufs. - */ -int -_bus_dmamap_load_mbuf_direct(t, map, m0, flags) - bus_dma_tag_t t; - bus_dmamap_t map; - struct mbuf *m0; - int flags; -{ - paddr_t lastaddr; - int seg, error, first; - struct mbuf *m; - - /* - * Make sure that on error condition we return "no valid mappings." - */ - map->dm_mapsize = 0; - map->dm_nsegs = 0; - -#ifdef DIAGNOSTIC - if ((m0->m_flags & M_PKTHDR) == 0) - panic("_bus_dmamap_load_mbuf_direct_common: no packet header"); -#endif - - if (m0->m_pkthdr.len > map->_dm_size) - return (EINVAL); - - first = 1; - seg = 0; - error = 0; - for (m = m0; m != NULL && error == 0; m = m->m_next) { - error = _bus_dmamap_load_buffer_direct_common(t, map, - m->m_data, m->m_len, NULL, flags, &lastaddr, &seg, first); - first = 0; - } - if (error == 0) { - map->dm_mapsize = m0->m_pkthdr.len; - map->dm_nsegs = seg + 1; - } else if (t->_next_window != NULL) { - /* - * Give the next window a chance. - */ - error = bus_dmamap_load_mbuf(t->_next_window, map, m0, flags); - } - return (error); -} - -/* - * Like _bus_dmamap_load_direct_common(), but for uios. - */ -int -_bus_dmamap_load_uio_direct(t, map, uio, flags) - bus_dma_tag_t t; - bus_dmamap_t map; - struct uio *uio; - int flags; -{ - paddr_t lastaddr; - int seg, i, error, first; - bus_size_t minlen, resid; - struct proc *p = NULL; - struct iovec *iov; - caddr_t addr; - - /* - * Make sure that on error condition we return "no valid mappings." - */ - map->dm_mapsize = 0; - map->dm_nsegs = 0; - - resid = uio->uio_resid; - iov = uio->uio_iov; - - if (uio->uio_segflg == UIO_USERSPACE) { - p = uio->uio_procp; -#ifdef DIAGNOSTIC - if (p == NULL) - panic("_bus_dmamap_load_direct_common: USERSPACE but no proc"); -#endif - } - - first = 1; - seg = 0; - error = 0; - for (i = 0; i < uio->uio_iovcnt && resid != 0 && error == 0; i++) { - /* - * Now at the first iovec to load. Load each iovec - * until we have exhausted the residual count. - */ - minlen = resid < iov[i].iov_len ? resid : iov[i].iov_len; - addr = (caddr_t)iov[i].iov_base; - - error = _bus_dmamap_load_buffer_direct_common(t, map, - addr, minlen, p, flags, &lastaddr, &seg, first); - first = 0; - - resid -= minlen; - } - if (error == 0) { - map->dm_mapsize = uio->uio_resid; - map->dm_nsegs = seg + 1; - } else if (t->_next_window != NULL) { - /* - * Give the next window a chance. - */ - error = bus_dmamap_load_uio(t->_next_window, map, uio, flags); - } - return (error); -} - -/* - * Like _bus_dmamap_load_direct_common(), but for raw memory. - */ -int -_bus_dmamap_load_raw_direct(t, map, segs, nsegs, size, flags) - bus_dma_tag_t t; - bus_dmamap_t map; - bus_dma_segment_t *segs; - int nsegs; - bus_size_t size; - int flags; -{ - - panic("_bus_dmamap_load_raw_direct: not implemented"); -} - -/* - * Common function for unloading a DMA map. May be called by - * chipset-specific DMA map unload functions. - */ -void -_bus_dmamap_unload(t, map) - bus_dma_tag_t t; - bus_dmamap_t map; -{ - - /* - * No resources to free; just mark the mappings as - * invalid. - */ - map->dm_mapsize = 0; - map->dm_nsegs = 0; -} - -/* - * Common function for DMA map synchronization. May be called - * by chipset-specific DMA map synchronization functions. - */ -void -_bus_dmamap_sync(t, map, op) - bus_dma_tag_t t; - bus_dmamap_t map; - bus_dmasync_op_t op; -{ - - /* - * Flush the store buffer. - */ - alpha_mb(); -} - -/* - * Common function for DMA-safe memory allocation. May be called - * by bus-specific DMA memory allocation functions. - */ -int -_bus_dmamem_alloc(t, size, alignment, boundary, segs, nsegs, rsegs, flags) - bus_dma_tag_t t; - bus_size_t size, alignment, boundary; - bus_dma_segment_t *segs; - int nsegs; - int *rsegs; - int flags; -{ - - return (_bus_dmamem_alloc_range(t, size, alignment, boundary, - segs, nsegs, rsegs, flags, 0, trunc_page(avail_end))); -} - -/* - * Allocate physical memory from the given physical address range. - * Called by DMA-safe memory allocation methods. - */ -int -_bus_dmamem_alloc_range(t, size, alignment, boundary, segs, nsegs, rsegs, - flags, low, high) - bus_dma_tag_t t; - bus_size_t size, alignment, boundary; - bus_dma_segment_t *segs; - int nsegs; - int *rsegs; - int flags; - paddr_t low; - paddr_t high; -{ - paddr_t curaddr, lastaddr; - vm_page_t m; - struct pglist mlist; - int curseg, error; - - /* Always round the size. */ - size = round_page(size); - - high = avail_end - PAGE_SIZE; - - /* - * Allocate pages from the VM system. - */ - TAILQ_INIT(&mlist); - error = uvm_pglistalloc(size, low, high, alignment, boundary, - &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0); - if (error) - return (error); - - /* - * Compute the location, size, and number of segments actually - * returned by the VM code. - */ - m = mlist.tqh_first; - curseg = 0; - lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m); - segs[curseg].ds_len = PAGE_SIZE; - m = m->pageq.tqe_next; - - for (; m != NULL; m = m->pageq.tqe_next) { - curaddr = VM_PAGE_TO_PHYS(m); -#ifdef DIAGNOSTIC - if (curaddr < avail_start || curaddr >= high) { - printf("vm_page_alloc_memory returned non-sensical" - " address 0x%lx\n", curaddr); - panic("_bus_dmamem_alloc"); - } -#endif - if (curaddr == (lastaddr + PAGE_SIZE)) - segs[curseg].ds_len += PAGE_SIZE; - else { - curseg++; - segs[curseg].ds_addr = curaddr; - segs[curseg].ds_len = PAGE_SIZE; - } - lastaddr = curaddr; - } - - *rsegs = curseg + 1; - - return (0); -} - -/* - * Common function for freeing DMA-safe memory. May be called by - * bus-specific DMA memory free functions. - */ -void -_bus_dmamem_free(t, segs, nsegs) - bus_dma_tag_t t; - bus_dma_segment_t *segs; - int nsegs; -{ - vm_page_t m; - bus_addr_t addr; - struct pglist mlist; - int curseg; - - /* - * Build a list of pages to free back to the VM system. - */ - TAILQ_INIT(&mlist); - for (curseg = 0; curseg < nsegs; curseg++) { - for (addr = segs[curseg].ds_addr; - addr < (segs[curseg].ds_addr + segs[curseg].ds_len); - addr += PAGE_SIZE) { - m = PHYS_TO_VM_PAGE(addr); - TAILQ_INSERT_TAIL(&mlist, m, pageq); - } - } - - uvm_pglistfree(&mlist); -} - -/* - * Common function for mapping DMA-safe memory. May be called by - * bus-specific DMA memory map functions. - */ -int -_bus_dmamem_map(t, segs, nsegs, size, kvap, flags) - bus_dma_tag_t t; - bus_dma_segment_t *segs; - int nsegs; - size_t size; - caddr_t *kvap; - int flags; -{ - vaddr_t va; - bus_addr_t addr; - int curseg; - - /* - * If we're only mapping 1 segment, use K0SEG, to avoid - * TLB thrashing. - */ - if (nsegs == 1) { - *kvap = (caddr_t)ALPHA_PHYS_TO_K0SEG(segs[0].ds_addr); - return (0); - } - - size = round_page(size); - - va = uvm_km_valloc(kernel_map, size); - - if (va == 0) - return (ENOMEM); - - *kvap = (caddr_t)va; - - for (curseg = 0; curseg < nsegs; curseg++) { - for (addr = segs[curseg].ds_addr; - addr < (segs[curseg].ds_addr + segs[curseg].ds_len); - addr += NBPG, va += NBPG, size -= NBPG) { - if (size == 0) - panic("_bus_dmamem_map: size botch"); - pmap_enter(pmap_kernel(), va, addr, - VM_PROT_READ | VM_PROT_WRITE, 1, - VM_PROT_READ | VM_PROT_WRITE); - } - } - - return (0); -} - -/* - * Common function for unmapping DMA-safe memory. May be called by - * bus-specific DMA memory unmapping functions. - */ -void -_bus_dmamem_unmap(t, kva, size) - bus_dma_tag_t t; - caddr_t kva; - size_t size; -{ - -#ifdef DIAGNOSTIC - if ((u_long)kva & PGOFSET) - panic("_bus_dmamem_unmap"); -#endif - - /* - * Nothing to do if we mapped it with K0SEG. - */ - if (kva >= (caddr_t)ALPHA_K0SEG_BASE && - kva <= (caddr_t)ALPHA_K0SEG_END) - return; - - size = round_page(size); - uvm_km_free(kernel_map, (vaddr_t)kva, size); -} - -/* - * Common functin for mmap(2)'ing DMA-safe memory. May be called by - * bus-specific DMA mmap(2)'ing functions. - */ -paddr_t -_bus_dmamem_mmap(t, segs, nsegs, off, prot, flags) - bus_dma_tag_t t; - bus_dma_segment_t *segs; - int nsegs; - off_t off; - int prot, flags; -{ - int i; - - for (i = 0; i < nsegs; i++) { -#ifdef DIAGNOSTIC - if (off & PGOFSET) - panic("_bus_dmamem_mmap: offset unaligned"); - if (segs[i].ds_addr & PGOFSET) - panic("_bus_dmamem_mmap: segment unaligned"); - if (segs[i].ds_len & PGOFSET) - panic("_bus_dmamem_mmap: segment size not multiple" - " of page size"); -#endif - if (off >= segs[i].ds_len) { - off -= segs[i].ds_len; - continue; - } - - return (alpha_btop((caddr_t)segs[i].ds_addr + off)); - } - - /* Page not found. */ - return (-1); -} diff --git a/sys/arch/alpha/common/sgmap_common.c b/sys/arch/alpha/common/sgmap_common.c deleted file mode 100644 index ff3f9740160..00000000000 --- a/sys/arch/alpha/common/sgmap_common.c +++ /dev/null @@ -1,225 +0,0 @@ -/* $OpenBSD: sgmap_common.c,v 1.2 2000/11/08 21:27:10 ericj Exp $ */ -/* $NetBSD: sgmap_common.c,v 1.13 2000/06/29 09:02:57 mrg Exp $ */ - -/*- - * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, - * NASA Ames Research Center. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include - -/* - * Some systems will prefetch the next page during a memory -> device DMA. - * This can cause machine checks if there is not a spill page after the - * last page of the DMA (thus avoiding hitting an invalid SGMAP PTE). - */ -vaddr_t alpha_sgmap_prefetch_spill_page_va; -bus_addr_t alpha_sgmap_prefetch_spill_page_pa; - -void -alpha_sgmap_init(t, sgmap, name, wbase, sgvabase, sgvasize, ptesize, ptva, - minptalign) - bus_dma_tag_t t; - struct alpha_sgmap *sgmap; - const char *name; - bus_addr_t wbase; - bus_addr_t sgvabase; - bus_size_t sgvasize; - size_t ptesize; - void *ptva; - bus_size_t minptalign; -{ - bus_dma_segment_t seg; - size_t ptsize; - int rseg; - - if (sgvasize & PGOFSET) { - printf("size botch for sgmap `%s'\n", name); - goto die; - } - - sgmap->aps_wbase = wbase; - sgmap->aps_sgvabase = sgvabase; - sgmap->aps_sgvasize = sgvasize; - - if (ptva != NULL) { - /* - * We already have a page table; this may be a system - * where the page table resides in bridge-resident SRAM. - */ - sgmap->aps_pt = ptva; - sgmap->aps_ptpa = 0; - } else { - /* - * Compute the page table size and allocate it. At minimum, - * this must be aligned to the page table size. However, - * some platforms have more strict alignment reqirements. - */ - ptsize = (sgvasize / NBPG) * ptesize; - if (minptalign != 0) { - if (minptalign < ptsize) - minptalign = ptsize; - } else - minptalign = ptsize; - if (bus_dmamem_alloc(t, ptsize, minptalign, 0, &seg, 1, &rseg, - BUS_DMA_NOWAIT)) { - panic("unable to allocate page table for sgmap `%s'\n", - name); - goto die; - } - sgmap->aps_ptpa = seg.ds_addr; - sgmap->aps_pt = (caddr_t)ALPHA_PHYS_TO_K0SEG(sgmap->aps_ptpa); - } - - /* - * Create the extent map used to manage the virtual address - * space. - */ - sgmap->aps_ex = extent_create((char *)name, sgvabase, sgvasize - 1, - M_DEVBUF, NULL, 0, EX_NOWAIT|EX_NOCOALESCE); - if (sgmap->aps_ex == NULL) { - printf("unable to create extent map for sgmap `%s'\n", - name); - goto die; - } - - /* - * Allocate a spill page if that hasn't already been done. - */ - if (alpha_sgmap_prefetch_spill_page_va == 0) { - if (bus_dmamem_alloc(t, NBPG, 0, 0, &seg, 1, &rseg, - BUS_DMA_NOWAIT)) { - printf("unable to allocate spill page for sgmap `%s'\n", - name); - goto die; - } - alpha_sgmap_prefetch_spill_page_pa = seg.ds_addr; - alpha_sgmap_prefetch_spill_page_va = - ALPHA_PHYS_TO_K0SEG(alpha_sgmap_prefetch_spill_page_pa); - bzero((caddr_t)alpha_sgmap_prefetch_spill_page_va, NBPG); - } - - return; - die: - panic("alpha_sgmap_init"); -} - -int -alpha_sgmap_alloc(map, origlen, sgmap, flags) - bus_dmamap_t map; - bus_size_t origlen; - struct alpha_sgmap *sgmap; - int flags; -{ - int error; - bus_size_t len = origlen, boundary, alignment; - -#ifdef DIAGNOSTIC - if (map->_dm_flags & DMAMAP_HAS_SGMAP) - panic("alpha_sgmap_alloc: already have sgva space"); -#endif - /* - * Add a range for spill page. - */ - len += NBPG; - - /* - * And add an additional amount in case of ALLOCNOW. - */ - if (flags & BUS_DMA_ALLOCNOW) - len += NBPG; - - map->_dm_sgvalen = round_page(len); - - /* - * ARGH! If the addition of spill pages bumped us over our - * boundary, we have to 2x the boundary limit. - */ - boundary = map->_dm_boundary; - if (boundary && boundary < map->_dm_sgvalen) { - alignment = boundary; - do { - boundary <<= 1; - } while (boundary < map->_dm_sgvalen); - } else - alignment = NBPG; -#if 0 - printf("len %x -> %x, _dm_sgvalen %x _dm_boundary %x boundary %x -> ", - origlen, len, map->_dm_sgvalen, map->_dm_boundary, boundary); -#endif - - error = extent_alloc(sgmap->aps_ex, map->_dm_sgvalen, alignment, - boundary, (flags & BUS_DMA_NOWAIT) ? EX_NOWAIT : EX_WAITOK, - &map->_dm_sgva); -#if 0 - printf("error %d _dm_sgva %x\n", error, map->_dm_sgva); -#endif - - if (error == 0) - map->_dm_flags |= DMAMAP_HAS_SGMAP; - else - map->_dm_flags &= ~DMAMAP_HAS_SGMAP; - - return (error); -} - -void -alpha_sgmap_free(map, sgmap) - bus_dmamap_t map; - struct alpha_sgmap *sgmap; -{ - -#ifdef DIAGNOSTIC - if ((map->_dm_flags & DMAMAP_HAS_SGMAP) == 0) - panic("alpha_sgmap_free: no sgva space to free"); -#endif - - if (extent_free(sgmap->aps_ex, map->_dm_sgva, map->_dm_sgvalen, - EX_NOWAIT)) - panic("alpha_sgmap_free"); - - map->_dm_flags &= ~DMAMAP_HAS_SGMAP; -} diff --git a/sys/arch/alpha/common/sgmap_typedep.c b/sys/arch/alpha/common/sgmap_typedep.c deleted file mode 100644 index 9ff47606354..00000000000 --- a/sys/arch/alpha/common/sgmap_typedep.c +++ /dev/null @@ -1,331 +0,0 @@ -/* $OpenBSD: sgmap_typedep.c,v 1.2 2000/11/08 21:27:11 ericj Exp $ */ -/* $NetBSD: sgmap_typedep.c,v 1.13 1999/07/08 18:05:23 thorpej Exp $ */ - -/*- - * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, - * NASA Ames Research Center. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef SGMAP_LOG - -#ifndef SGMAP_LOGSIZE -#define SGMAP_LOGSIZE 4096 -#endif - -struct sgmap_log_entry __C(SGMAP_TYPE,_log)[SGMAP_LOGSIZE]; -int __C(SGMAP_TYPE,_log_next); -int __C(SGMAP_TYPE,_log_last); -u_long __C(SGMAP_TYPE,_log_loads); -u_long __C(SGMAP_TYPE,_log_unloads); - -#endif /* SGMAP_LOG */ - -#ifdef SGMAP_DEBUG -int __C(SGMAP_TYPE,_debug) = 0; -#endif - -SGMAP_PTE_TYPE __C(SGMAP_TYPE,_prefetch_spill_page_pte); - -void -__C(SGMAP_TYPE,_init_spill_page_pte)() -{ - - __C(SGMAP_TYPE,_prefetch_spill_page_pte) = - (alpha_sgmap_prefetch_spill_page_pa >> - SGPTE_PGADDR_SHIFT) | SGPTE_VALID; -} - -int -__C(SGMAP_TYPE,_load)(t, map, buf, buflen, p, flags, sgmap) - bus_dma_tag_t t; - bus_dmamap_t map; - void *buf; - bus_size_t buflen; - struct proc *p; - int flags; - struct alpha_sgmap *sgmap; -{ - vaddr_t endva, va = (vaddr_t)buf; - paddr_t pa; - bus_addr_t dmaoffset; - bus_size_t dmalen; - SGMAP_PTE_TYPE *pte, *page_table = sgmap->aps_pt; - int pteidx, error; -#ifdef SGMAP_LOG - struct sgmap_log_entry sl; -#endif - - /* - * Initialize the spill page PTE if that hasn't already been done. - */ - if (__C(SGMAP_TYPE,_prefetch_spill_page_pte) == 0) - __C(SGMAP_TYPE,_init_spill_page_pte)(); - - /* - * Make sure that on error condition we return "no valid mappings". - */ - map->dm_mapsize = 0; - map->dm_nsegs = 0; - - if (buflen > map->_dm_size) - return (EINVAL); - - /* - * Remember the offset into the first page and the total - * transfer length. - */ - dmaoffset = ((u_long)buf) & PGOFSET; - dmalen = buflen; - -#ifdef SGMAP_DEBUG - if (__C(SGMAP_TYPE,_debug)) { - printf("sgmap_load: ----- buf = %p -----\n", buf); - printf("sgmap_load: dmaoffset = 0x%lx, dmalen = 0x%lx\n", - dmaoffset, dmalen); - } -#endif - -#ifdef SGMAP_LOG - if (panicstr == NULL) { - sl.sl_op = 1; - sl.sl_sgmap = sgmap; - sl.sl_origbuf = buf; - sl.sl_pgoffset = dmaoffset; - sl.sl_origlen = dmalen; - } -#endif - - /* - * Allocate the necessary virtual address space for the - * mapping. Round the size, since we deal with whole pages. - * - * alpha_sgmap_alloc will deal with the appropriate spill page - * allocations. - * - */ - endva = round_page(va + buflen); - va = trunc_page(va); - if ((map->_dm_flags & DMAMAP_HAS_SGMAP) == 0) { - error = alpha_sgmap_alloc(map, (endva - va), sgmap, flags); - if (error) - return (error); - } - - pteidx = map->_dm_sgva >> PGSHIFT; - pte = &page_table[pteidx * SGMAP_PTE_SPACING]; - -#ifdef SGMAP_DEBUG - if (__C(SGMAP_TYPE,_debug)) - printf("sgmap_load: sgva = 0x%lx, pteidx = %d, " - "pte = %p (pt = %p)\n", map->_dm_sgva, pteidx, pte, - page_table); -#endif - - /* - * Generate the DMA address. - */ - map->dm_segs[0].ds_addr = sgmap->aps_wbase | - (pteidx << SGMAP_ADDR_PTEIDX_SHIFT) | dmaoffset; - map->dm_segs[0].ds_len = dmalen; - -#ifdef SGMAP_LOG - if (panicstr == NULL) { - sl.sl_sgva = map->_dm_sgva; - sl.sl_dmaaddr = map->dm_segs[0].ds_addr; - } -#endif - -#ifdef SGMAP_DEBUG - if (__C(SGMAP_TYPE,_debug)) - printf("sgmap_load: wbase = 0x%lx, vpage = 0x%x, " - "dma addr = 0x%lx\n", sgmap->aps_wbase, - (pteidx << SGMAP_ADDR_PTEIDX_SHIFT), - map->dm_segs[0].ds_addr); -#endif - - map->_dm_pteidx = pteidx; - map->_dm_ptecnt = 0; - - for (; va < endva; va += NBPG, pteidx++, - pte = &page_table[pteidx * SGMAP_PTE_SPACING], - map->_dm_ptecnt++) { - /* - * Get the physical address for this segment. - */ - if (p != NULL) - pa = pmap_extract(p->p_vmspace->vm_map.pmap, va); - else - pa = vtophys(va); - - /* - * Load the current PTE with this page. - */ - *pte = (pa >> SGPTE_PGADDR_SHIFT) | SGPTE_VALID; -#ifdef SGMAP_DEBUG - if (__C(SGMAP_TYPE,_debug)) - printf("sgmap_load: pa = 0x%lx, pte = %p, " - "*pte = 0x%lx\n", pa, pte, (u_long)(*pte)); -#endif - } - - /* - * ...and the prefetch-spill page. - */ - *pte = __C(SGMAP_TYPE,_prefetch_spill_page_pte); - map->_dm_ptecnt++; -#ifdef SGMAP_DEBUG - if (__C(SGMAP_TYPE,_debug)) { - printf("sgmap_load: spill page, pte = %p, *pte = 0x%lx\n", - pte, *pte); - printf("sgmap_load: pte count = %d\n", map->_dm_ptecnt); - } -#endif - - alpha_mb(); - -#ifdef SGMAP_LOG - if (panicstr == NULL) { - sl.sl_ptecnt = map->_dm_ptecnt; - bcopy(&sl, &__C(SGMAP_TYPE,_log)[__C(SGMAP_TYPE,_log_next)], - sizeof(sl)); - __C(SGMAP_TYPE,_log_last) = __C(SGMAP_TYPE,_log_next); - if (++__C(SGMAP_TYPE,_log_next) == SGMAP_LOGSIZE) - __C(SGMAP_TYPE,_log_next) = 0; - __C(SGMAP_TYPE,_log_loads)++; - } -#endif - -#if defined(SGMAP_DEBUG) && defined(DDB) - if (__C(SGMAP_TYPE,_debug) > 1) - Debugger(); -#endif - map->dm_mapsize = buflen; - map->dm_nsegs = 1; - return (0); -} - -int -__C(SGMAP_TYPE,_load_mbuf)(t, map, m, flags, sgmap) - bus_dma_tag_t t; - bus_dmamap_t map; - struct mbuf *m; - int flags; - struct alpha_sgmap *sgmap; -{ - - panic(__S(__C(SGMAP_TYPE,_load_mbuf)) ": not implemented"); -} - -int -__C(SGMAP_TYPE,_load_uio)(t, map, uio, flags, sgmap) - bus_dma_tag_t t; - bus_dmamap_t map; - struct uio *uio; - int flags; - struct alpha_sgmap *sgmap; -{ - - panic(__S(__C(SGMAP_TYPE,_load_uio)) ": not implemented"); -} - -int -__C(SGMAP_TYPE,_load_raw)(t, map, segs, nsegs, size, flags, sgmap) - bus_dma_tag_t t; - bus_dmamap_t map; - bus_dma_segment_t *segs; - int nsegs; - bus_size_t size; - int flags; - struct alpha_sgmap *sgmap; -{ - - panic(__S(__C(SGMAP_TYPE,_load_raw)) ": not implemented"); -} - -void -__C(SGMAP_TYPE,_unload)(t, map, sgmap) - bus_dma_tag_t t; - bus_dmamap_t map; - struct alpha_sgmap *sgmap; -{ - SGMAP_PTE_TYPE *pte, *page_table = sgmap->aps_pt; - int ptecnt, pteidx; -#ifdef SGMAP_LOG - struct sgmap_log_entry *sl; - - if (panicstr == NULL) { - sl = &__C(SGMAP_TYPE,_log)[__C(SGMAP_TYPE,_log_next)]; - - bzero(sl, sizeof(*sl)); - sl->sl_op = 0; - sl->sl_sgmap = sgmap; - sl->sl_sgva = map->_dm_sgva; - sl->sl_dmaaddr = map->dm_segs[0].ds_addr; - - __C(SGMAP_TYPE,_log_last) = __C(SGMAP_TYPE,_log_next); - if (++__C(SGMAP_TYPE,_log_next) == SGMAP_LOGSIZE) - __C(SGMAP_TYPE,_log_next) = 0; - __C(SGMAP_TYPE,_log_unloads)++; - } -#endif - - /* - * Invalidate the PTEs for the mapping. - */ - for (ptecnt = map->_dm_ptecnt, pteidx = map->_dm_pteidx, - pte = &page_table[pteidx * SGMAP_PTE_SPACING]; - ptecnt != 0; - ptecnt--, pteidx++, - pte = &page_table[pteidx * SGMAP_PTE_SPACING]) { -#ifdef SGMAP_DEBUG - if (__C(SGMAP_TYPE,_debug)) - printf("sgmap_unload: pte = %p, *pte = 0x%lx\n", - pte, (u_long)(*pte)); -#endif - *pte = 0; - } - - /* - * Free the virtual address space used by the mapping - * if necessary. - */ - if ((map->_dm_flags & BUS_DMA_ALLOCNOW) == 0) - alpha_sgmap_free(map, sgmap); - /* - * Mark the mapping invalid. - */ - map->dm_mapsize = 0; - map->dm_nsegs = 0; -} diff --git a/sys/arch/alpha/common/sgmap_typedep.h b/sys/arch/alpha/common/sgmap_typedep.h deleted file mode 100644 index 5f58198f8ca..00000000000 --- a/sys/arch/alpha/common/sgmap_typedep.h +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: sgmap_typedep.h,v 1.2 2000/11/08 21:27:11 ericj Exp $ */ -/* $NetBSD: sgmap_typedep.h,v 1.4 1998/06/04 01:22:52 thorpej Exp $ */ - -/*- - * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, - * NASA Ames Research Center. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#undef __C -#undef __S - -#define __C(A,B) __CONCAT(A,B) -#define __S(S) __STRING(S) - -extern SGMAP_PTE_TYPE __C(SGMAP_TYPE,_prefetch_spill_page_pte); - -void __C(SGMAP_TYPE,_init_spill_page_pte) __P((void)); -int __C(SGMAP_TYPE,_load) __P((bus_dma_tag_t, bus_dmamap_t, - void *, bus_size_t, struct proc *, int, struct alpha_sgmap *)); -int __C(SGMAP_TYPE,_load_mbuf) __P((bus_dma_tag_t, bus_dmamap_t, - struct mbuf *, int, struct alpha_sgmap *)); -int __C(SGMAP_TYPE,_load_uio) __P((bus_dma_tag_t, bus_dmamap_t, - struct uio *, int, struct alpha_sgmap *)); -int __C(SGMAP_TYPE,_load_raw) __P((bus_dma_tag_t, bus_dmamap_t, - bus_dma_segment_t *, int, bus_size_t, int, struct alpha_sgmap *)); -void __C(SGMAP_TYPE,_unload) __P((bus_dma_tag_t, bus_dmamap_t, - struct alpha_sgmap *)); diff --git a/sys/arch/alpha/common/sgmapvar.h b/sys/arch/alpha/common/sgmapvar.h deleted file mode 100644 index 41ffe70d253..00000000000 --- a/sys/arch/alpha/common/sgmapvar.h +++ /dev/null @@ -1,96 +0,0 @@ -/* $OpenBSD: sgmapvar.h,v 1.2 2000/11/08 21:27:12 ericj Exp $ */ -/* $NetBSD: sgmapvar.h,v 1.10 1998/08/14 16:50:02 thorpej Exp $ */ - -/*- - * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, - * NASA Ames Research Center. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _ALPHA_COMMON_SGMAPVAR_H -#define _ALPHA_COMMON_SGMAPVAR_H - -#include -#include - -/* - * Bits n:13 of the DMA address are the index of the PTE into - * the SGMAP page table. - */ -#define SGMAP_ADDR_PTEIDX_SHIFT 13 - -/* - * An Alpha SGMAP's state information. Nothing in the sgmap requires - * locking[*], with the exception of the extent map. Locking of the - * extent map is handled within the extent manager itself. - * - * [*] While the page table is a `global' resource, access to it is - * controlled by the extent map; once a region has been allocated from - * the map, that region is effectively `locked'. - */ -struct alpha_sgmap { - struct extent *aps_ex; /* extent map to manage sgva space */ - void *aps_pt; /* page table */ - bus_addr_t aps_ptpa; /* page table physical address */ - bus_addr_t aps_sgvabase; /* base of the sgva space */ - bus_size_t aps_sgvasize; /* size of the sgva space */ - bus_addr_t aps_wbase; /* base of the dma window */ -}; - -/* - * Log entry, used for debugging SGMAPs. - */ -struct sgmap_log_entry { - int sl_op; /* op; 1 = load, 0 = unload */ - struct alpha_sgmap *sl_sgmap; /* sgmap for entry */ - void *sl_origbuf; /* original buffer */ - u_long sl_pgoffset; /* page offset of buffer start */ - u_long sl_origlen; /* length of transfer */ - u_long sl_sgva; /* sgva of transfer */ - u_long sl_dmaaddr; /* dma address */ - int sl_ptecnt; /* pte count */ -}; - -extern vaddr_t alpha_sgmap_prefetch_spill_page_va; -extern bus_addr_t alpha_sgmap_prefetch_spill_page_pa; - -void alpha_sgmap_init __P((bus_dma_tag_t, struct alpha_sgmap *, - const char *, bus_addr_t, bus_addr_t, bus_size_t, size_t, void *, - bus_size_t)); - -int alpha_sgmap_alloc __P((bus_dmamap_t, bus_size_t, - struct alpha_sgmap *, int)); -void alpha_sgmap_free __P((bus_dmamap_t, struct alpha_sgmap *)); - -#endif /* _ALPHA_COMMON_SGMAPVAR_H */ diff --git a/sys/arch/alpha/conf/files.alpha b/sys/arch/alpha/conf/files.alpha index 87d418781d9..8795ac9080a 100644 --- a/sys/arch/alpha/conf/files.alpha +++ b/sys/arch/alpha/conf/files.alpha @@ -1,4 +1,4 @@ -# $OpenBSD: files.alpha,v 1.45 2001/03/18 04:39:07 nate Exp $ +# $OpenBSD: files.alpha,v 1.46 2001/03/21 17:26:38 art Exp $ # $NetBSD: files.alpha,v 1.32 1996/11/25 04:03:21 cgd Exp $ # # alpha-specific configuration info @@ -14,7 +14,7 @@ file arch/alpha/dev/shared_intr.c alpha_shared_intr | dec_eb164 | dec_kn20aa | dec_6600 | dec_550 define alpha_sgmap -file arch/alpha/common/sgmap_common.c alpha_sgmap | dec_3000_500 +file arch/alpha/dev/sgmap_common.c alpha_sgmap | dec_3000_500 # # Bus-independent devices @@ -262,7 +262,7 @@ file arch/alpha/alpha/sys_machdep.c file arch/alpha/alpha/trap.c file arch/alpha/alpha/vm_machdep.c file arch/alpha/alpha/disksubr.c -file arch/alpha/common/bus_dma.c +file arch/alpha/dev/bus_dma.c file dev/clock_subr.c file dev/cons.c diff --git a/sys/arch/alpha/dev/bus_dma.c b/sys/arch/alpha/dev/bus_dma.c new file mode 100644 index 00000000000..0b6eb960e2f --- /dev/null +++ b/sys/arch/alpha/dev/bus_dma.c @@ -0,0 +1,674 @@ +/* $OpenBSD: bus_dma.c,v 1.1 2001/03/21 17:26:38 art Exp $ */ +/* $NetBSD: bus_dma.c,v 1.40 2000/07/17 04:47:56 thorpej Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#define _ALPHA_BUS_DMA_PRIVATE +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +int _bus_dmamap_load_buffer_direct_common __P((bus_dma_tag_t, + bus_dmamap_t, void *, bus_size_t, struct proc *, int, + paddr_t *, int *, int)); + +extern paddr_t avail_start, avail_end; /* from pmap.c */ + +/* + * Common function for DMA map creation. May be called by bus-specific + * DMA map creation functions. + */ +int +_bus_dmamap_create(t, size, nsegments, maxsegsz, boundary, flags, dmamp) + bus_dma_tag_t t; + bus_size_t size; + int nsegments; + bus_size_t maxsegsz; + bus_size_t boundary; + int flags; + bus_dmamap_t *dmamp; +{ + struct alpha_bus_dmamap *map; + void *mapstore; + size_t mapsize; + + /* + * Allocate and initialize the DMA map. The end of the map + * is a variable-sized array of segments, so we allocate enough + * room for them in one shot. + * + * Note we don't preserve the WAITOK or NOWAIT flags. Preservation + * of ALLOCNOW notifes others that we've reserved these resources, + * and they are not to be freed. + * + * The bus_dmamap_t includes one bus_dma_segment_t, hence + * the (nsegments - 1). + */ + mapsize = sizeof(struct alpha_bus_dmamap) + + (sizeof(bus_dma_segment_t) * (nsegments - 1)); + if ((mapstore = malloc(mapsize, M_DEVBUF, + (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) + return (ENOMEM); + + bzero(mapstore, mapsize); + map = (struct alpha_bus_dmamap *)mapstore; + map->_dm_size = size; + map->_dm_segcnt = nsegments; + map->_dm_maxsegsz = maxsegsz; + if (t->_boundary != 0 && t->_boundary < boundary) + map->_dm_boundary = t->_boundary; + else + map->_dm_boundary = boundary; + map->_dm_flags = flags & ~(BUS_DMA_WAITOK|BUS_DMA_NOWAIT); + map->dm_mapsize = 0; /* no valid mappings */ + map->dm_nsegs = 0; + + *dmamp = map; + return (0); +} + +/* + * Common function for DMA map destruction. May be called by bus-specific + * DMA map destruction functions. + */ +void +_bus_dmamap_destroy(t, map) + bus_dma_tag_t t; + bus_dmamap_t map; +{ + + free(map, M_DEVBUF); +} + +/* + * Utility function to load a linear buffer. lastaddrp holds state + * between invocations (for multiple-buffer loads). segp contains + * the starting segment on entrance, and the ending segment on exit. + * first indicates if this is the first invocation of this function. + */ +int +_bus_dmamap_load_buffer_direct_common(t, map, buf, buflen, p, flags, + lastaddrp, segp, first) + bus_dma_tag_t t; + bus_dmamap_t map; + void *buf; + bus_size_t buflen; + struct proc *p; + int flags; + paddr_t *lastaddrp; + int *segp; + int first; +{ + bus_size_t sgsize; + bus_addr_t curaddr, lastaddr, baddr, bmask; + vaddr_t vaddr = (vaddr_t)buf; + int seg; + + lastaddr = *lastaddrp; + bmask = ~(map->_dm_boundary - 1); + + for (seg = *segp; buflen > 0 ; ) { + /* + * Get the physical address for this segment. + */ + if (p != NULL) + curaddr = pmap_extract(p->p_vmspace->vm_map.pmap, + vaddr); + else + curaddr = vtophys(vaddr); + + /* + * If we're beyond the current DMA window, indicate + * that and try to fall back into SGMAPs. + */ + if (t->_wsize != 0 && curaddr >= t->_wsize) + return (EINVAL); + + curaddr |= t->_wbase; + + /* + * Compute the segment size, and adjust counts. + */ + sgsize = NBPG - ((u_long)vaddr & PGOFSET); + if (buflen < sgsize) + sgsize = buflen; + if (map->_dm_maxsegsz < sgsize) + sgsize = map->_dm_maxsegsz; + + /* + * Make sure we don't cross any boundaries. + */ + if (map->_dm_boundary > 0) { + baddr = (curaddr + map->_dm_boundary) & bmask; + if (sgsize > (baddr - curaddr)) + sgsize = (baddr - curaddr); + } + + /* + * Insert chunk into a segment, coalescing with + * the previous segment if possible. + */ + if (first) { + map->dm_segs[seg].ds_addr = curaddr; + map->dm_segs[seg].ds_len = sgsize; + first = 0; + } else { + if ((map->_dm_flags & DMAMAP_NO_COALESCE) == 0 && + curaddr == lastaddr && + (map->dm_segs[seg].ds_len + sgsize) <= + map->_dm_maxsegsz && + (map->_dm_boundary == 0 || + (map->dm_segs[seg].ds_addr & bmask) == + (curaddr & bmask))) + map->dm_segs[seg].ds_len += sgsize; + else { + if (++seg >= map->_dm_segcnt) + break; + map->dm_segs[seg].ds_addr = curaddr; + map->dm_segs[seg].ds_len = sgsize; + } + } + + lastaddr = curaddr + sgsize; + vaddr += sgsize; + buflen -= sgsize; + } + + *segp = seg; + *lastaddrp = lastaddr; + + /* + * Did we fit? + */ + if (buflen != 0) { + /* + * If there is a chained window, we will automatically + * fall back to it. + */ + return (EFBIG); /* XXX better return value here? */ + } + + return (0); +} + +/* + * Common function for loading a direct-mapped DMA map with a linear + * buffer. Called by bus-specific DMA map load functions with the + * OR value appropriate for indicating "direct-mapped" for that + * chipset. + */ +int +_bus_dmamap_load_direct(t, map, buf, buflen, p, flags) + bus_dma_tag_t t; + bus_dmamap_t map; + void *buf; + bus_size_t buflen; + struct proc *p; + int flags; +{ + paddr_t lastaddr; + int seg, error; + + /* + * Make sure that on error condition we return "no valid mappings". + */ + map->dm_mapsize = 0; + map->dm_nsegs = 0; + + if (buflen > map->_dm_size) + return (EINVAL); + + seg = 0; + error = _bus_dmamap_load_buffer_direct_common(t, map, buf, buflen, + p, flags, &lastaddr, &seg, 1); + if (error == 0) { + map->dm_mapsize = buflen; + map->dm_nsegs = seg + 1; + } else if (t->_next_window != NULL) { + /* + * Give the next window a chance. + */ + error = bus_dmamap_load(t->_next_window, map, buf, buflen, + p, flags); + } + return (error); +} + +/* + * Like _bus_dmamap_load_direct_common(), but for mbufs. + */ +int +_bus_dmamap_load_mbuf_direct(t, map, m0, flags) + bus_dma_tag_t t; + bus_dmamap_t map; + struct mbuf *m0; + int flags; +{ + paddr_t lastaddr; + int seg, error, first; + struct mbuf *m; + + /* + * Make sure that on error condition we return "no valid mappings." + */ + map->dm_mapsize = 0; + map->dm_nsegs = 0; + +#ifdef DIAGNOSTIC + if ((m0->m_flags & M_PKTHDR) == 0) + panic("_bus_dmamap_load_mbuf_direct_common: no packet header"); +#endif + + if (m0->m_pkthdr.len > map->_dm_size) + return (EINVAL); + + first = 1; + seg = 0; + error = 0; + for (m = m0; m != NULL && error == 0; m = m->m_next) { + error = _bus_dmamap_load_buffer_direct_common(t, map, + m->m_data, m->m_len, NULL, flags, &lastaddr, &seg, first); + first = 0; + } + if (error == 0) { + map->dm_mapsize = m0->m_pkthdr.len; + map->dm_nsegs = seg + 1; + } else if (t->_next_window != NULL) { + /* + * Give the next window a chance. + */ + error = bus_dmamap_load_mbuf(t->_next_window, map, m0, flags); + } + return (error); +} + +/* + * Like _bus_dmamap_load_direct_common(), but for uios. + */ +int +_bus_dmamap_load_uio_direct(t, map, uio, flags) + bus_dma_tag_t t; + bus_dmamap_t map; + struct uio *uio; + int flags; +{ + paddr_t lastaddr; + int seg, i, error, first; + bus_size_t minlen, resid; + struct proc *p = NULL; + struct iovec *iov; + caddr_t addr; + + /* + * Make sure that on error condition we return "no valid mappings." + */ + map->dm_mapsize = 0; + map->dm_nsegs = 0; + + resid = uio->uio_resid; + iov = uio->uio_iov; + + if (uio->uio_segflg == UIO_USERSPACE) { + p = uio->uio_procp; +#ifdef DIAGNOSTIC + if (p == NULL) + panic("_bus_dmamap_load_direct_common: USERSPACE but no proc"); +#endif + } + + first = 1; + seg = 0; + error = 0; + for (i = 0; i < uio->uio_iovcnt && resid != 0 && error == 0; i++) { + /* + * Now at the first iovec to load. Load each iovec + * until we have exhausted the residual count. + */ + minlen = resid < iov[i].iov_len ? resid : iov[i].iov_len; + addr = (caddr_t)iov[i].iov_base; + + error = _bus_dmamap_load_buffer_direct_common(t, map, + addr, minlen, p, flags, &lastaddr, &seg, first); + first = 0; + + resid -= minlen; + } + if (error == 0) { + map->dm_mapsize = uio->uio_resid; + map->dm_nsegs = seg + 1; + } else if (t->_next_window != NULL) { + /* + * Give the next window a chance. + */ + error = bus_dmamap_load_uio(t->_next_window, map, uio, flags); + } + return (error); +} + +/* + * Like _bus_dmamap_load_direct_common(), but for raw memory. + */ +int +_bus_dmamap_load_raw_direct(t, map, segs, nsegs, size, flags) + bus_dma_tag_t t; + bus_dmamap_t map; + bus_dma_segment_t *segs; + int nsegs; + bus_size_t size; + int flags; +{ + + panic("_bus_dmamap_load_raw_direct: not implemented"); +} + +/* + * Common function for unloading a DMA map. May be called by + * chipset-specific DMA map unload functions. + */ +void +_bus_dmamap_unload(t, map) + bus_dma_tag_t t; + bus_dmamap_t map; +{ + + /* + * No resources to free; just mark the mappings as + * invalid. + */ + map->dm_mapsize = 0; + map->dm_nsegs = 0; +} + +/* + * Common function for DMA map synchronization. May be called + * by chipset-specific DMA map synchronization functions. + */ +void +_bus_dmamap_sync(t, map, op) + bus_dma_tag_t t; + bus_dmamap_t map; + bus_dmasync_op_t op; +{ + + /* + * Flush the store buffer. + */ + alpha_mb(); +} + +/* + * Common function for DMA-safe memory allocation. May be called + * by bus-specific DMA memory allocation functions. + */ +int +_bus_dmamem_alloc(t, size, alignment, boundary, segs, nsegs, rsegs, flags) + bus_dma_tag_t t; + bus_size_t size, alignment, boundary; + bus_dma_segment_t *segs; + int nsegs; + int *rsegs; + int flags; +{ + + return (_bus_dmamem_alloc_range(t, size, alignment, boundary, + segs, nsegs, rsegs, flags, 0, trunc_page(avail_end))); +} + +/* + * Allocate physical memory from the given physical address range. + * Called by DMA-safe memory allocation methods. + */ +int +_bus_dmamem_alloc_range(t, size, alignment, boundary, segs, nsegs, rsegs, + flags, low, high) + bus_dma_tag_t t; + bus_size_t size, alignment, boundary; + bus_dma_segment_t *segs; + int nsegs; + int *rsegs; + int flags; + paddr_t low; + paddr_t high; +{ + paddr_t curaddr, lastaddr; + vm_page_t m; + struct pglist mlist; + int curseg, error; + + /* Always round the size. */ + size = round_page(size); + + high = avail_end - PAGE_SIZE; + + /* + * Allocate pages from the VM system. + */ + TAILQ_INIT(&mlist); + error = uvm_pglistalloc(size, low, high, alignment, boundary, + &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0); + if (error) + return (error); + + /* + * Compute the location, size, and number of segments actually + * returned by the VM code. + */ + m = mlist.tqh_first; + curseg = 0; + lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m); + segs[curseg].ds_len = PAGE_SIZE; + m = m->pageq.tqe_next; + + for (; m != NULL; m = m->pageq.tqe_next) { + curaddr = VM_PAGE_TO_PHYS(m); +#ifdef DIAGNOSTIC + if (curaddr < avail_start || curaddr >= high) { + printf("vm_page_alloc_memory returned non-sensical" + " address 0x%lx\n", curaddr); + panic("_bus_dmamem_alloc"); + } +#endif + if (curaddr == (lastaddr + PAGE_SIZE)) + segs[curseg].ds_len += PAGE_SIZE; + else { + curseg++; + segs[curseg].ds_addr = curaddr; + segs[curseg].ds_len = PAGE_SIZE; + } + lastaddr = curaddr; + } + + *rsegs = curseg + 1; + + return (0); +} + +/* + * Common function for freeing DMA-safe memory. May be called by + * bus-specific DMA memory free functions. + */ +void +_bus_dmamem_free(t, segs, nsegs) + bus_dma_tag_t t; + bus_dma_segment_t *segs; + int nsegs; +{ + vm_page_t m; + bus_addr_t addr; + struct pglist mlist; + int curseg; + + /* + * Build a list of pages to free back to the VM system. + */ + TAILQ_INIT(&mlist); + for (curseg = 0; curseg < nsegs; curseg++) { + for (addr = segs[curseg].ds_addr; + addr < (segs[curseg].ds_addr + segs[curseg].ds_len); + addr += PAGE_SIZE) { + m = PHYS_TO_VM_PAGE(addr); + TAILQ_INSERT_TAIL(&mlist, m, pageq); + } + } + + uvm_pglistfree(&mlist); +} + +/* + * Common function for mapping DMA-safe memory. May be called by + * bus-specific DMA memory map functions. + */ +int +_bus_dmamem_map(t, segs, nsegs, size, kvap, flags) + bus_dma_tag_t t; + bus_dma_segment_t *segs; + int nsegs; + size_t size; + caddr_t *kvap; + int flags; +{ + vaddr_t va; + bus_addr_t addr; + int curseg; + + /* + * If we're only mapping 1 segment, use K0SEG, to avoid + * TLB thrashing. + */ + if (nsegs == 1) { + *kvap = (caddr_t)ALPHA_PHYS_TO_K0SEG(segs[0].ds_addr); + return (0); + } + + size = round_page(size); + + va = uvm_km_valloc(kernel_map, size); + + if (va == 0) + return (ENOMEM); + + *kvap = (caddr_t)va; + + for (curseg = 0; curseg < nsegs; curseg++) { + for (addr = segs[curseg].ds_addr; + addr < (segs[curseg].ds_addr + segs[curseg].ds_len); + addr += NBPG, va += NBPG, size -= NBPG) { + if (size == 0) + panic("_bus_dmamem_map: size botch"); + pmap_enter(pmap_kernel(), va, addr, + VM_PROT_READ | VM_PROT_WRITE, 1, + VM_PROT_READ | VM_PROT_WRITE); + } + } + + return (0); +} + +/* + * Common function for unmapping DMA-safe memory. May be called by + * bus-specific DMA memory unmapping functions. + */ +void +_bus_dmamem_unmap(t, kva, size) + bus_dma_tag_t t; + caddr_t kva; + size_t size; +{ + +#ifdef DIAGNOSTIC + if ((u_long)kva & PGOFSET) + panic("_bus_dmamem_unmap"); +#endif + + /* + * Nothing to do if we mapped it with K0SEG. + */ + if (kva >= (caddr_t)ALPHA_K0SEG_BASE && + kva <= (caddr_t)ALPHA_K0SEG_END) + return; + + size = round_page(size); + uvm_km_free(kernel_map, (vaddr_t)kva, size); +} + +/* + * Common functin for mmap(2)'ing DMA-safe memory. May be called by + * bus-specific DMA mmap(2)'ing functions. + */ +paddr_t +_bus_dmamem_mmap(t, segs, nsegs, off, prot, flags) + bus_dma_tag_t t; + bus_dma_segment_t *segs; + int nsegs; + off_t off; + int prot, flags; +{ + int i; + + for (i = 0; i < nsegs; i++) { +#ifdef DIAGNOSTIC + if (off & PGOFSET) + panic("_bus_dmamem_mmap: offset unaligned"); + if (segs[i].ds_addr & PGOFSET) + panic("_bus_dmamem_mmap: segment unaligned"); + if (segs[i].ds_len & PGOFSET) + panic("_bus_dmamem_mmap: segment size not multiple" + " of page size"); +#endif + if (off >= segs[i].ds_len) { + off -= segs[i].ds_len; + continue; + } + + return (alpha_btop((caddr_t)segs[i].ds_addr + off)); + } + + /* Page not found. */ + return (-1); +} diff --git a/sys/arch/alpha/dev/sgmap_common.c b/sys/arch/alpha/dev/sgmap_common.c new file mode 100644 index 00000000000..45867565d44 --- /dev/null +++ b/sys/arch/alpha/dev/sgmap_common.c @@ -0,0 +1,225 @@ +/* $OpenBSD: sgmap_common.c,v 1.1 2001/03/21 17:26:38 art Exp $ */ +/* $NetBSD: sgmap_common.c,v 1.13 2000/06/29 09:02:57 mrg Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +/* + * Some systems will prefetch the next page during a memory -> device DMA. + * This can cause machine checks if there is not a spill page after the + * last page of the DMA (thus avoiding hitting an invalid SGMAP PTE). + */ +vaddr_t alpha_sgmap_prefetch_spill_page_va; +bus_addr_t alpha_sgmap_prefetch_spill_page_pa; + +void +alpha_sgmap_init(t, sgmap, name, wbase, sgvabase, sgvasize, ptesize, ptva, + minptalign) + bus_dma_tag_t t; + struct alpha_sgmap *sgmap; + const char *name; + bus_addr_t wbase; + bus_addr_t sgvabase; + bus_size_t sgvasize; + size_t ptesize; + void *ptva; + bus_size_t minptalign; +{ + bus_dma_segment_t seg; + size_t ptsize; + int rseg; + + if (sgvasize & PGOFSET) { + printf("size botch for sgmap `%s'\n", name); + goto die; + } + + sgmap->aps_wbase = wbase; + sgmap->aps_sgvabase = sgvabase; + sgmap->aps_sgvasize = sgvasize; + + if (ptva != NULL) { + /* + * We already have a page table; this may be a system + * where the page table resides in bridge-resident SRAM. + */ + sgmap->aps_pt = ptva; + sgmap->aps_ptpa = 0; + } else { + /* + * Compute the page table size and allocate it. At minimum, + * this must be aligned to the page table size. However, + * some platforms have more strict alignment reqirements. + */ + ptsize = (sgvasize / NBPG) * ptesize; + if (minptalign != 0) { + if (minptalign < ptsize) + minptalign = ptsize; + } else + minptalign = ptsize; + if (bus_dmamem_alloc(t, ptsize, minptalign, 0, &seg, 1, &rseg, + BUS_DMA_NOWAIT)) { + panic("unable to allocate page table for sgmap `%s'\n", + name); + goto die; + } + sgmap->aps_ptpa = seg.ds_addr; + sgmap->aps_pt = (caddr_t)ALPHA_PHYS_TO_K0SEG(sgmap->aps_ptpa); + } + + /* + * Create the extent map used to manage the virtual address + * space. + */ + sgmap->aps_ex = extent_create((char *)name, sgvabase, sgvasize - 1, + M_DEVBUF, NULL, 0, EX_NOWAIT|EX_NOCOALESCE); + if (sgmap->aps_ex == NULL) { + printf("unable to create extent map for sgmap `%s'\n", + name); + goto die; + } + + /* + * Allocate a spill page if that hasn't already been done. + */ + if (alpha_sgmap_prefetch_spill_page_va == 0) { + if (bus_dmamem_alloc(t, NBPG, 0, 0, &seg, 1, &rseg, + BUS_DMA_NOWAIT)) { + printf("unable to allocate spill page for sgmap `%s'\n", + name); + goto die; + } + alpha_sgmap_prefetch_spill_page_pa = seg.ds_addr; + alpha_sgmap_prefetch_spill_page_va = + ALPHA_PHYS_TO_K0SEG(alpha_sgmap_prefetch_spill_page_pa); + bzero((caddr_t)alpha_sgmap_prefetch_spill_page_va, NBPG); + } + + return; + die: + panic("alpha_sgmap_init"); +} + +int +alpha_sgmap_alloc(map, origlen, sgmap, flags) + bus_dmamap_t map; + bus_size_t origlen; + struct alpha_sgmap *sgmap; + int flags; +{ + int error; + bus_size_t len = origlen, boundary, alignment; + +#ifdef DIAGNOSTIC + if (map->_dm_flags & DMAMAP_HAS_SGMAP) + panic("alpha_sgmap_alloc: already have sgva space"); +#endif + /* + * Add a range for spill page. + */ + len += NBPG; + + /* + * And add an additional amount in case of ALLOCNOW. + */ + if (flags & BUS_DMA_ALLOCNOW) + len += NBPG; + + map->_dm_sgvalen = round_page(len); + + /* + * ARGH! If the addition of spill pages bumped us over our + * boundary, we have to 2x the boundary limit. + */ + boundary = map->_dm_boundary; + if (boundary && boundary < map->_dm_sgvalen) { + alignment = boundary; + do { + boundary <<= 1; + } while (boundary < map->_dm_sgvalen); + } else + alignment = NBPG; +#if 0 + printf("len %x -> %x, _dm_sgvalen %x _dm_boundary %x boundary %x -> ", + origlen, len, map->_dm_sgvalen, map->_dm_boundary, boundary); +#endif + + error = extent_alloc(sgmap->aps_ex, map->_dm_sgvalen, alignment, + boundary, (flags & BUS_DMA_NOWAIT) ? EX_NOWAIT : EX_WAITOK, + &map->_dm_sgva); +#if 0 + printf("error %d _dm_sgva %x\n", error, map->_dm_sgva); +#endif + + if (error == 0) + map->_dm_flags |= DMAMAP_HAS_SGMAP; + else + map->_dm_flags &= ~DMAMAP_HAS_SGMAP; + + return (error); +} + +void +alpha_sgmap_free(map, sgmap) + bus_dmamap_t map; + struct alpha_sgmap *sgmap; +{ + +#ifdef DIAGNOSTIC + if ((map->_dm_flags & DMAMAP_HAS_SGMAP) == 0) + panic("alpha_sgmap_free: no sgva space to free"); +#endif + + if (extent_free(sgmap->aps_ex, map->_dm_sgva, map->_dm_sgvalen, + EX_NOWAIT)) + panic("alpha_sgmap_free"); + + map->_dm_flags &= ~DMAMAP_HAS_SGMAP; +} diff --git a/sys/arch/alpha/dev/sgmap_typedep.c b/sys/arch/alpha/dev/sgmap_typedep.c new file mode 100644 index 00000000000..54e292ec50b --- /dev/null +++ b/sys/arch/alpha/dev/sgmap_typedep.c @@ -0,0 +1,331 @@ +/* $OpenBSD: sgmap_typedep.c,v 1.1 2001/03/21 17:26:38 art Exp $ */ +/* $NetBSD: sgmap_typedep.c,v 1.13 1999/07/08 18:05:23 thorpej Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef SGMAP_LOG + +#ifndef SGMAP_LOGSIZE +#define SGMAP_LOGSIZE 4096 +#endif + +struct sgmap_log_entry __C(SGMAP_TYPE,_log)[SGMAP_LOGSIZE]; +int __C(SGMAP_TYPE,_log_next); +int __C(SGMAP_TYPE,_log_last); +u_long __C(SGMAP_TYPE,_log_loads); +u_long __C(SGMAP_TYPE,_log_unloads); + +#endif /* SGMAP_LOG */ + +#ifdef SGMAP_DEBUG +int __C(SGMAP_TYPE,_debug) = 0; +#endif + +SGMAP_PTE_TYPE __C(SGMAP_TYPE,_prefetch_spill_page_pte); + +void +__C(SGMAP_TYPE,_init_spill_page_pte)() +{ + + __C(SGMAP_TYPE,_prefetch_spill_page_pte) = + (alpha_sgmap_prefetch_spill_page_pa >> + SGPTE_PGADDR_SHIFT) | SGPTE_VALID; +} + +int +__C(SGMAP_TYPE,_load)(t, map, buf, buflen, p, flags, sgmap) + bus_dma_tag_t t; + bus_dmamap_t map; + void *buf; + bus_size_t buflen; + struct proc *p; + int flags; + struct alpha_sgmap *sgmap; +{ + vaddr_t endva, va = (vaddr_t)buf; + paddr_t pa; + bus_addr_t dmaoffset; + bus_size_t dmalen; + SGMAP_PTE_TYPE *pte, *page_table = sgmap->aps_pt; + int pteidx, error; +#ifdef SGMAP_LOG + struct sgmap_log_entry sl; +#endif + + /* + * Initialize the spill page PTE if that hasn't already been done. + */ + if (__C(SGMAP_TYPE,_prefetch_spill_page_pte) == 0) + __C(SGMAP_TYPE,_init_spill_page_pte)(); + + /* + * Make sure that on error condition we return "no valid mappings". + */ + map->dm_mapsize = 0; + map->dm_nsegs = 0; + + if (buflen > map->_dm_size) + return (EINVAL); + + /* + * Remember the offset into the first page and the total + * transfer length. + */ + dmaoffset = ((u_long)buf) & PGOFSET; + dmalen = buflen; + +#ifdef SGMAP_DEBUG + if (__C(SGMAP_TYPE,_debug)) { + printf("sgmap_load: ----- buf = %p -----\n", buf); + printf("sgmap_load: dmaoffset = 0x%lx, dmalen = 0x%lx\n", + dmaoffset, dmalen); + } +#endif + +#ifdef SGMAP_LOG + if (panicstr == NULL) { + sl.sl_op = 1; + sl.sl_sgmap = sgmap; + sl.sl_origbuf = buf; + sl.sl_pgoffset = dmaoffset; + sl.sl_origlen = dmalen; + } +#endif + + /* + * Allocate the necessary virtual address space for the + * mapping. Round the size, since we deal with whole pages. + * + * alpha_sgmap_alloc will deal with the appropriate spill page + * allocations. + * + */ + endva = round_page(va + buflen); + va = trunc_page(va); + if ((map->_dm_flags & DMAMAP_HAS_SGMAP) == 0) { + error = alpha_sgmap_alloc(map, (endva - va), sgmap, flags); + if (error) + return (error); + } + + pteidx = map->_dm_sgva >> PGSHIFT; + pte = &page_table[pteidx * SGMAP_PTE_SPACING]; + +#ifdef SGMAP_DEBUG + if (__C(SGMAP_TYPE,_debug)) + printf("sgmap_load: sgva = 0x%lx, pteidx = %d, " + "pte = %p (pt = %p)\n", map->_dm_sgva, pteidx, pte, + page_table); +#endif + + /* + * Generate the DMA address. + */ + map->dm_segs[0].ds_addr = sgmap->aps_wbase | + (pteidx << SGMAP_ADDR_PTEIDX_SHIFT) | dmaoffset; + map->dm_segs[0].ds_len = dmalen; + +#ifdef SGMAP_LOG + if (panicstr == NULL) { + sl.sl_sgva = map->_dm_sgva; + sl.sl_dmaaddr = map->dm_segs[0].ds_addr; + } +#endif + +#ifdef SGMAP_DEBUG + if (__C(SGMAP_TYPE,_debug)) + printf("sgmap_load: wbase = 0x%lx, vpage = 0x%x, " + "dma addr = 0x%lx\n", sgmap->aps_wbase, + (pteidx << SGMAP_ADDR_PTEIDX_SHIFT), + map->dm_segs[0].ds_addr); +#endif + + map->_dm_pteidx = pteidx; + map->_dm_ptecnt = 0; + + for (; va < endva; va += NBPG, pteidx++, + pte = &page_table[pteidx * SGMAP_PTE_SPACING], + map->_dm_ptecnt++) { + /* + * Get the physical address for this segment. + */ + if (p != NULL) + pa = pmap_extract(p->p_vmspace->vm_map.pmap, va); + else + pa = vtophys(va); + + /* + * Load the current PTE with this page. + */ + *pte = (pa >> SGPTE_PGADDR_SHIFT) | SGPTE_VALID; +#ifdef SGMAP_DEBUG + if (__C(SGMAP_TYPE,_debug)) + printf("sgmap_load: pa = 0x%lx, pte = %p, " + "*pte = 0x%lx\n", pa, pte, (u_long)(*pte)); +#endif + } + + /* + * ...and the prefetch-spill page. + */ + *pte = __C(SGMAP_TYPE,_prefetch_spill_page_pte); + map->_dm_ptecnt++; +#ifdef SGMAP_DEBUG + if (__C(SGMAP_TYPE,_debug)) { + printf("sgmap_load: spill page, pte = %p, *pte = 0x%lx\n", + pte, *pte); + printf("sgmap_load: pte count = %d\n", map->_dm_ptecnt); + } +#endif + + alpha_mb(); + +#ifdef SGMAP_LOG + if (panicstr == NULL) { + sl.sl_ptecnt = map->_dm_ptecnt; + bcopy(&sl, &__C(SGMAP_TYPE,_log)[__C(SGMAP_TYPE,_log_next)], + sizeof(sl)); + __C(SGMAP_TYPE,_log_last) = __C(SGMAP_TYPE,_log_next); + if (++__C(SGMAP_TYPE,_log_next) == SGMAP_LOGSIZE) + __C(SGMAP_TYPE,_log_next) = 0; + __C(SGMAP_TYPE,_log_loads)++; + } +#endif + +#if defined(SGMAP_DEBUG) && defined(DDB) + if (__C(SGMAP_TYPE,_debug) > 1) + Debugger(); +#endif + map->dm_mapsize = buflen; + map->dm_nsegs = 1; + return (0); +} + +int +__C(SGMAP_TYPE,_load_mbuf)(t, map, m, flags, sgmap) + bus_dma_tag_t t; + bus_dmamap_t map; + struct mbuf *m; + int flags; + struct alpha_sgmap *sgmap; +{ + + panic(__S(__C(SGMAP_TYPE,_load_mbuf)) ": not implemented"); +} + +int +__C(SGMAP_TYPE,_load_uio)(t, map, uio, flags, sgmap) + bus_dma_tag_t t; + bus_dmamap_t map; + struct uio *uio; + int flags; + struct alpha_sgmap *sgmap; +{ + + panic(__S(__C(SGMAP_TYPE,_load_uio)) ": not implemented"); +} + +int +__C(SGMAP_TYPE,_load_raw)(t, map, segs, nsegs, size, flags, sgmap) + bus_dma_tag_t t; + bus_dmamap_t map; + bus_dma_segment_t *segs; + int nsegs; + bus_size_t size; + int flags; + struct alpha_sgmap *sgmap; +{ + + panic(__S(__C(SGMAP_TYPE,_load_raw)) ": not implemented"); +} + +void +__C(SGMAP_TYPE,_unload)(t, map, sgmap) + bus_dma_tag_t t; + bus_dmamap_t map; + struct alpha_sgmap *sgmap; +{ + SGMAP_PTE_TYPE *pte, *page_table = sgmap->aps_pt; + int ptecnt, pteidx; +#ifdef SGMAP_LOG + struct sgmap_log_entry *sl; + + if (panicstr == NULL) { + sl = &__C(SGMAP_TYPE,_log)[__C(SGMAP_TYPE,_log_next)]; + + bzero(sl, sizeof(*sl)); + sl->sl_op = 0; + sl->sl_sgmap = sgmap; + sl->sl_sgva = map->_dm_sgva; + sl->sl_dmaaddr = map->dm_segs[0].ds_addr; + + __C(SGMAP_TYPE,_log_last) = __C(SGMAP_TYPE,_log_next); + if (++__C(SGMAP_TYPE,_log_next) == SGMAP_LOGSIZE) + __C(SGMAP_TYPE,_log_next) = 0; + __C(SGMAP_TYPE,_log_unloads)++; + } +#endif + + /* + * Invalidate the PTEs for the mapping. + */ + for (ptecnt = map->_dm_ptecnt, pteidx = map->_dm_pteidx, + pte = &page_table[pteidx * SGMAP_PTE_SPACING]; + ptecnt != 0; + ptecnt--, pteidx++, + pte = &page_table[pteidx * SGMAP_PTE_SPACING]) { +#ifdef SGMAP_DEBUG + if (__C(SGMAP_TYPE,_debug)) + printf("sgmap_unload: pte = %p, *pte = 0x%lx\n", + pte, (u_long)(*pte)); +#endif + *pte = 0; + } + + /* + * Free the virtual address space used by the mapping + * if necessary. + */ + if ((map->_dm_flags & BUS_DMA_ALLOCNOW) == 0) + alpha_sgmap_free(map, sgmap); + /* + * Mark the mapping invalid. + */ + map->dm_mapsize = 0; + map->dm_nsegs = 0; +} diff --git a/sys/arch/alpha/dev/sgmap_typedep.h b/sys/arch/alpha/dev/sgmap_typedep.h new file mode 100644 index 00000000000..692ec524ff0 --- /dev/null +++ b/sys/arch/alpha/dev/sgmap_typedep.h @@ -0,0 +1,59 @@ +/* $OpenBSD: sgmap_typedep.h,v 1.1 2001/03/21 17:26:38 art Exp $ */ +/* $NetBSD: sgmap_typedep.h,v 1.4 1998/06/04 01:22:52 thorpej Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#undef __C +#undef __S + +#define __C(A,B) __CONCAT(A,B) +#define __S(S) __STRING(S) + +extern SGMAP_PTE_TYPE __C(SGMAP_TYPE,_prefetch_spill_page_pte); + +void __C(SGMAP_TYPE,_init_spill_page_pte) __P((void)); +int __C(SGMAP_TYPE,_load) __P((bus_dma_tag_t, bus_dmamap_t, + void *, bus_size_t, struct proc *, int, struct alpha_sgmap *)); +int __C(SGMAP_TYPE,_load_mbuf) __P((bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, int, struct alpha_sgmap *)); +int __C(SGMAP_TYPE,_load_uio) __P((bus_dma_tag_t, bus_dmamap_t, + struct uio *, int, struct alpha_sgmap *)); +int __C(SGMAP_TYPE,_load_raw) __P((bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int, struct alpha_sgmap *)); +void __C(SGMAP_TYPE,_unload) __P((bus_dma_tag_t, bus_dmamap_t, + struct alpha_sgmap *)); diff --git a/sys/arch/alpha/dev/sgmapvar.h b/sys/arch/alpha/dev/sgmapvar.h new file mode 100644 index 00000000000..ebdc972a6ea --- /dev/null +++ b/sys/arch/alpha/dev/sgmapvar.h @@ -0,0 +1,96 @@ +/* $OpenBSD: sgmapvar.h,v 1.1 2001/03/21 17:26:38 art Exp $ */ +/* $NetBSD: sgmapvar.h,v 1.10 1998/08/14 16:50:02 thorpej Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ALPHA_COMMON_SGMAPVAR_H +#define _ALPHA_COMMON_SGMAPVAR_H + +#include +#include + +/* + * Bits n:13 of the DMA address are the index of the PTE into + * the SGMAP page table. + */ +#define SGMAP_ADDR_PTEIDX_SHIFT 13 + +/* + * An Alpha SGMAP's state information. Nothing in the sgmap requires + * locking[*], with the exception of the extent map. Locking of the + * extent map is handled within the extent manager itself. + * + * [*] While the page table is a `global' resource, access to it is + * controlled by the extent map; once a region has been allocated from + * the map, that region is effectively `locked'. + */ +struct alpha_sgmap { + struct extent *aps_ex; /* extent map to manage sgva space */ + void *aps_pt; /* page table */ + bus_addr_t aps_ptpa; /* page table physical address */ + bus_addr_t aps_sgvabase; /* base of the sgva space */ + bus_size_t aps_sgvasize; /* size of the sgva space */ + bus_addr_t aps_wbase; /* base of the dma window */ +}; + +/* + * Log entry, used for debugging SGMAPs. + */ +struct sgmap_log_entry { + int sl_op; /* op; 1 = load, 0 = unload */ + struct alpha_sgmap *sl_sgmap; /* sgmap for entry */ + void *sl_origbuf; /* original buffer */ + u_long sl_pgoffset; /* page offset of buffer start */ + u_long sl_origlen; /* length of transfer */ + u_long sl_sgva; /* sgva of transfer */ + u_long sl_dmaaddr; /* dma address */ + int sl_ptecnt; /* pte count */ +}; + +extern vaddr_t alpha_sgmap_prefetch_spill_page_va; +extern bus_addr_t alpha_sgmap_prefetch_spill_page_pa; + +void alpha_sgmap_init __P((bus_dma_tag_t, struct alpha_sgmap *, + const char *, bus_addr_t, bus_addr_t, bus_size_t, size_t, void *, + bus_size_t)); + +int alpha_sgmap_alloc __P((bus_dmamap_t, bus_size_t, + struct alpha_sgmap *, int)); +void alpha_sgmap_free __P((bus_dmamap_t, struct alpha_sgmap *)); + +#endif /* _ALPHA_COMMON_SGMAPVAR_H */ diff --git a/sys/arch/alpha/pci/pci_sgmap_pte64.c b/sys/arch/alpha/pci/pci_sgmap_pte64.c index cf838adefbd..325196b4b94 100644 --- a/sys/arch/alpha/pci/pci_sgmap_pte64.c +++ b/sys/arch/alpha/pci/pci_sgmap_pte64.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pci_sgmap_pte64.c,v 1.2 2000/11/08 20:59:25 ericj Exp $ */ +/* $OpenBSD: pci_sgmap_pte64.c,v 1.3 2001/03/21 17:26:39 art Exp $ */ /* $NetBSD: pci_sgmap_pte64.c,v 1.4 2000/06/29 08:58:49 mrg Exp $ */ /*- @@ -52,4 +52,4 @@ #include -#include +#include diff --git a/sys/arch/alpha/pci/pci_sgmap_pte64.h b/sys/arch/alpha/pci/pci_sgmap_pte64.h index a26b0e638f7..78113d355d9 100644 --- a/sys/arch/alpha/pci/pci_sgmap_pte64.h +++ b/sys/arch/alpha/pci/pci_sgmap_pte64.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pci_sgmap_pte64.h,v 1.2 2000/11/08 20:59:25 ericj Exp $ */ +/* $OpenBSD: pci_sgmap_pte64.h,v 1.3 2001/03/21 17:26:39 art Exp $ */ /* $NetBSD: pci_sgmap_pte64.h,v 1.2 1997/06/06 23:59:29 thorpej Exp $ */ /*- @@ -54,5 +54,5 @@ #define SGPTE_PGADDR_SHIFT 12 #define SGPTE_VALID 0x0000000000000001UL -#include -#include +#include +#include -- cgit v1.2.3