Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/arc bus_space/bus_dma implementation for arc port, ...
details: https://anonhg.NetBSD.org/src/rev/0fea261c1d3c
branches: trunk
changeset: 487546:0fea261c1d3c
user: soda <soda%NetBSD.org@localhost>
date: Fri Jun 09 05:14:42 2000 +0000
description:
bus_space/bus_dma implementation for arc port, based on i386 port, pmax port,
hpcmips port, and the version contributed by Shuichiro URATA <ur%a-r.org@localhost>.
diffstat:
sys/arch/arc/arc/bus_dma.c | 858 +++++++++++++++++++++++++++++++++++
sys/arch/arc/arc/bus_space.c | 284 +++++++++++
sys/arch/arc/arc/bus_space_large.c | 153 ++++++
sys/arch/arc/arc/bus_space_sparse.c | 171 +++++++
sys/arch/arc/include/bus.h | 862 ++++++++++++++++++++++++++++++-----
5 files changed, 2207 insertions(+), 121 deletions(-)
diffs (truncated from 2434 to 300 lines):
diff -r 13070d7c42f5 -r 0fea261c1d3c sys/arch/arc/arc/bus_dma.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arc/arc/bus_dma.c Fri Jun 09 05:14:42 2000 +0000
@@ -0,0 +1,858 @@
+/* $NetBSD: bus_dma.c,v 1.1 2000/06/09 05:14:44 soda Exp $ */
+/* NetBSD: bus_dma.c,v 1.20 2000/01/10 03:24:36 simonb 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 <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/device.h>
+
+#include <vm/vm.h>
+#include <vm/vm_kern.h>
+
+
+#define _ARC_BUS_DMA_PRIVATE
+#include <machine/bus.h>
+
+extern paddr_t kvtophys __P((vaddr_t)); /* XXX */
+
+static int _bus_dmamap_load_buffer __P((bus_dma_tag_t, bus_dmamap_t,
+ void *, bus_size_t, struct proc *, int, paddr_t *,
+ int *, int));
+
+void
+_bus_dma_tag_init(t)
+ bus_dma_tag_t t;
+{
+ t->dma_offset = 0;
+
+ t->_dmamap_create = _bus_dmamap_create;
+ t->_dmamap_destroy = _bus_dmamap_destroy;
+ t->_dmamap_load = _bus_dmamap_load;
+ t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf;
+ t->_dmamap_load_uio = _bus_dmamap_load_uio;
+ t->_dmamap_load_raw = _bus_dmamap_load_raw;
+ t->_dmamap_unload = _bus_dmamap_unload;
+#if defined(MIPS1) && defined(MIPS3)
+ t->_dmamap_sync = (CPUISMIPS3) ?
+ _mips3_bus_dmamap_sync : _mips1_bus_dmamap_sync;
+#elif defined(MIPS1)
+ t->_dmamap_sync = _mips1_bus_dmamap_sync;
+#elif defined(MIPS3)
+ t->_dmamap_sync = _mips3_bus_dmamap_sync;
+#else
+#error neither MIPS1 nor MIPS3 is defined
+#endif
+ t->_dmamem_alloc = _bus_dmamem_alloc;
+ t->_dmamem_free = _bus_dmamem_free;
+ t->_dmamem_map = _bus_dmamem_map;
+ t->_dmamem_unmap = _bus_dmamem_unmap;
+ t->_dmamem_mmap = _bus_dmamem_mmap;
+}
+
+/*
+ * 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 arc_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 notifies 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 arc_bus_dmamap) +
+ (sizeof(bus_dma_segment_t) * (nsegments - 1));
+ if ((mapstore = malloc(mapsize, M_DMAMAP,
+ (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL)
+ return (ENOMEM);
+
+ bzero(mapstore, mapsize);
+ map = (struct arc_bus_dmamap *)mapstore;
+ map->_dm_size = size;
+ map->_dm_segcnt = nsegments;
+ map->_dm_maxsegsz = maxsegsz;
+ 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_DMAMAP);
+}
+
+/*
+ * 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.
+ */
+static int
+_bus_dmamap_load_buffer(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 baddr, bmask;
+ paddr_t curaddr, lastaddr;
+ 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) {
+ (void) pmap_extract(p->p_vmspace->vm_map.pmap,
+ vaddr, &curaddr);
+ } else
+ curaddr = kvtophys(vaddr);
+
+ /*
+ * Compute the segment size, and adjust counts.
+ */
+ sgsize = NBPG - ((u_long)vaddr & PGOFSET);
+ if (buflen < sgsize)
+ sgsize = buflen;
+
+ /*
+ * 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 + t->dma_offset;
+ map->dm_segs[seg].ds_len = sgsize;
+ map->dm_segs[seg]._ds_vaddr = vaddr;
+ map->dm_segs[seg]._ds_paddr = curaddr;
+ first = 0;
+ } else {
+ if (curaddr == lastaddr &&
+ (map->dm_segs[seg].ds_len + sgsize) <=
+ map->_dm_maxsegsz &&
+ (map->_dm_boundary == 0 ||
+ (map->dm_segs[seg]._ds_paddr & bmask) ==
+ (curaddr & bmask)))
+ map->dm_segs[seg].ds_len += sgsize;
+ else {
+ if (++seg >= map->_dm_segcnt)
+ break;
+ map->dm_segs[seg].ds_addr =
+ curaddr + t->dma_offset;
+ map->dm_segs[seg].ds_len = sgsize;
+ map->dm_segs[seg]._ds_vaddr = vaddr;
+ map->dm_segs[seg]._ds_paddr = curaddr;
+ }
+ }
+
+ lastaddr = curaddr + sgsize;
+ vaddr += sgsize;
+ buflen -= sgsize;
+ }
+
+ *segp = seg;
+ *lastaddrp = lastaddr;
+
+ /*
+ * Did we fit?
+ */
+ if (buflen != 0)
+ return (EFBIG); /* XXX better return value here? */
+
+ return (0);
+}
+
+/*
+ * Common function for loading a direct-mapped DMA map with a linear
+ * buffer.
+ */
+int
+_bus_dmamap_load(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(t, map, buf, buflen,
+ p, flags, &lastaddr, &seg, 1);
+ if (error == 0) {
+ map->dm_mapsize = buflen;
+ map->dm_nsegs = seg + 1;
+
+ /*
+ * For linear buffers, we support marking the mapping
+ * as COHERENT.
+ *
+ * XXX Check TLB entries for cache-inhibit bits?
+ */
+ if (buf >= (void *)MIPS_KSEG1_START &&
+ buf < (void *)MIPS_KSEG2_START)
+ map->_dm_flags |= ARC_DMAMAP_COHERENT;
+ }
+ return (error);
+}
+
+/*
Home |
Main Index |
Thread Index |
Old Index