Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Switch to the generic bounce buffer support.
details: https://anonhg.NetBSD.org/src/rev/7892edc87014
branches: trunk
changeset: 781667:7892edc87014
user: matt <matt%NetBSD.org@localhost>
date: Fri Sep 21 14:21:57 2012 +0000
description:
Switch to the generic bounce buffer support.
diffstat:
sys/arch/arm/footbridge/isa/isadma_machdep.c | 555 +--------------------------
sys/arch/arm/include/isa_machdep.h | 38 +-
sys/arch/cats/conf/std.cats | 3 +-
sys/arch/netwinder/conf/std.netwinder | 3 +-
sys/arch/shark/conf/std.shark | 3 +-
sys/arch/shark/isa/isadma_machdep.c | 547 +--------------------------
6 files changed, 17 insertions(+), 1132 deletions(-)
diffs (truncated from 1267 to 300 lines):
diff -r 0b8ae9ca8ff7 -r 7892edc87014 sys/arch/arm/footbridge/isa/isadma_machdep.c
--- a/sys/arch/arm/footbridge/isa/isadma_machdep.c Fri Sep 21 14:10:14 2012 +0000
+++ b/sys/arch/arm/footbridge/isa/isadma_machdep.c Fri Sep 21 14:21:57 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: isadma_machdep.c,v 1.15 2012/02/12 16:34:07 matt Exp $ */
+/* $NetBSD: isadma_machdep.c,v 1.16 2012/09/21 14:21:58 matt Exp $ */
#define ISA_DMA_STATS
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: isadma_machdep.c,v 1.15 2012/02/12 16:34:07 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isadma_machdep.c,v 1.16 2012/09/21 14:21:58 matt Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -65,51 +65,15 @@
struct arm32_dma_range *footbridge_isa_dma_ranges;
int footbridge_isa_dma_nranges;
-int _isa_bus_dmamap_create(bus_dma_tag_t, bus_size_t, int,
- bus_size_t, bus_size_t, int, bus_dmamap_t *);
-void _isa_bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
-int _isa_bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
- bus_size_t, struct proc *, int);
-int _isa_bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
- struct mbuf *, int);
-int _isa_bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
- struct uio *, int);
-int _isa_bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
- bus_dma_segment_t *, int, bus_size_t, int);
-void _isa_bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
-void _isa_bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t,
- bus_addr_t, bus_size_t, int);
-
-int _isa_bus_dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t,
- bus_size_t, bus_dma_segment_t *, int, int *, int);
-
-int _isa_dma_alloc_bouncebuf(bus_dma_tag_t, bus_dmamap_t,
- bus_size_t, int);
-void _isa_dma_free_bouncebuf(bus_dma_tag_t, bus_dmamap_t);
-
/*
* Entry points for ISA DMA. These are mostly wrappers around
* the generic functions that understand how to deal with bounce
* buffers, if necessary.
*/
struct arm32_bus_dma_tag isa_bus_dma_tag = {
- 0, /* _ranges */
- 0, /* _nranges */
- NULL,
- _isa_bus_dmamap_create,
- _isa_bus_dmamap_destroy,
- _isa_bus_dmamap_load,
- _isa_bus_dmamap_load_mbuf,
- _isa_bus_dmamap_load_uio,
- _isa_bus_dmamap_load_raw,
- _isa_bus_dmamap_unload,
- _isa_bus_dmamap_sync, /* pre */
- _isa_bus_dmamap_sync, /* post */
- _isa_bus_dmamem_alloc,
- _bus_dmamem_free,
- _bus_dmamem_map,
- _bus_dmamem_unmap,
- _bus_dmamem_mmap,
+ _BUS_DMAMAP_FUNCS,
+ _BUS_DMAMEM_FUNCS,
+ _BUS_DMATAG_FUNCS,
};
/*
@@ -122,512 +86,3 @@
isa_bus_dma_tag._ranges = footbridge_isa_dma_ranges;
isa_bus_dma_tag._nranges = footbridge_isa_dma_nranges;
}
-
-/**********************************************************************
- * bus.h dma interface entry points
- **********************************************************************/
-
-#ifdef ISA_DMA_STATS
-#define STAT_INCR(v) (v)++
-#define STAT_DECR(v) do { \
- if ((v) == 0) \
- printf("%s:%d -- Already 0!\n", __FILE__, __LINE__); \
- else \
- (v)--; \
- } while (0)
-u_long isa_dma_stats_loads;
-u_long isa_dma_stats_bounces;
-u_long isa_dma_stats_nbouncebufs;
-#else
-#define STAT_INCR(v)
-#define STAT_DECR(v)
-#endif
-
-/*
- * Create an ISA DMA map.
- */
-int
-_isa_bus_dmamap_create(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 arm32_isa_dma_cookie *cookie;
- bus_dmamap_t map;
- int error, cookieflags;
- void *cookiestore;
- size_t cookiesize;
-
- /* Call common function to create the basic map. */
- error = _bus_dmamap_create(t, size, nsegments, maxsegsz, boundary,
- flags, dmamp);
- if (error)
- return (error);
-
- map = *dmamp;
- map->_dm_cookie = NULL;
-
- cookiesize = sizeof(struct arm32_isa_dma_cookie);
-
- /*
- * ISA only has 24-bits of address space. This means
- * we can't DMA to pages over 16M. In order to DMA to
- * arbitrary buffers, we use "bounce buffers" - pages
- * in memory below the 16M boundary. On DMA reads,
- * DMA happens to the bounce buffers, and is copied into
- * the caller's buffer. On writes, data is copied into
- * but bounce buffer, and the DMA happens from those
- * pages. To software using the DMA mapping interface,
- * this looks simply like a data cache.
- *
- * If we have more than 16M of RAM in the system, we may
- * need bounce buffers. We check and remember that here.
- *
- * There are exceptions, however. VLB devices can do
- * 32-bit DMA, and indicate that here.
- *
- * ...or, there is an opposite case. The most segments
- * a transfer will require is (maxxfer / PAGE_SIZE) + 1. If
- * the caller can't handle that many segments (e.g. the
- * ISA DMA controller), we may have to bounce it as well.
- *
- * Well, not really... see note above regarding DMA ranges.
- * Because of the range issue on this platform, we just
- * always "might bounce".
- */
- cookieflags = ID_MIGHT_NEED_BOUNCE;
- cookiesize += (sizeof(bus_dma_segment_t) * map->_dm_segcnt);
-
- /*
- * Allocate our cookie.
- */
- if ((cookiestore = malloc(cookiesize, M_DMAMAP,
- (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) {
- error = ENOMEM;
- goto out;
- }
- memset(cookiestore, 0, cookiesize);
- cookie = (struct arm32_isa_dma_cookie *)cookiestore;
- cookie->id_flags = cookieflags;
- map->_dm_cookie = cookie;
-
- if (cookieflags & ID_MIGHT_NEED_BOUNCE) {
- /*
- * Allocate the bounce pages now if the caller
- * wishes us to do so.
- */
- if ((flags & BUS_DMA_ALLOCNOW) == 0)
- goto out;
-
- error = _isa_dma_alloc_bouncebuf(t, map, size, flags);
- }
-
- out:
- if (error) {
- if (map->_dm_cookie != NULL)
- free(map->_dm_cookie, M_DMAMAP);
- _bus_dmamap_destroy(t, map);
- }
- return (error);
-}
-
-/*
- * Destroy an ISA DMA map.
- */
-void
-_isa_bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
-{
- struct arm32_isa_dma_cookie *cookie = map->_dm_cookie;
-
- /*
- * Free any bounce pages this map might hold.
- */
- if (cookie->id_flags & ID_HAS_BOUNCE)
- _isa_dma_free_bouncebuf(t, map);
-
- free(cookie, M_DMAMAP);
- _bus_dmamap_destroy(t, map);
-}
-
-/*
- * Load an ISA DMA map with a linear buffer.
- */
-int
-_isa_bus_dmamap_load(
- bus_dma_tag_t t,
- bus_dmamap_t map,
- void *buf,
- bus_size_t buflen,
- struct proc *p,
- int flags)
-{
- struct arm32_isa_dma_cookie *cookie = map->_dm_cookie;
- int error;
-
- STAT_INCR(isa_dma_stats_loads);
-
- /*
- * Make sure that on error condition we return "no valid mappings."
- */
- map->dm_mapsize = 0;
- map->dm_nsegs = 0;
-
- /*
- * Try to load the map the normal way. If this errors out,
- * and we can bounce, we will.
- */
- error = _bus_dmamap_load(t, map, buf, buflen, p, flags);
- if (error == 0 ||
- (error != 0 && (cookie->id_flags & ID_MIGHT_NEED_BOUNCE) == 0))
- return (error);
-
- /*
- * First attempt failed; bounce it.
- */
-
- STAT_INCR(isa_dma_stats_bounces);
-
- /*
- * Allocate bounce pages, if necessary.
- */
- if ((cookie->id_flags & ID_HAS_BOUNCE) == 0) {
- error = _isa_dma_alloc_bouncebuf(t, map, buflen, flags);
- if (error)
- return (error);
- }
-
- /*
- * Cache a pointer to the caller's buffer and load the DMA map
- * with the bounce buffer.
- */
- cookie->id_origbuf = buf;
- cookie->id_origbuflen = buflen;
- cookie->id_buftype = ID_BUFTYPE_LINEAR;
- error = _bus_dmamap_load(t, map, cookie->id_bouncebuf, buflen,
- NULL, flags);
- if (error) {
- /*
- * Free the bounce pages, unless our resources
- * are reserved for our exclusive use.
- */
- if ((map->_dm_flags & BUS_DMA_ALLOCNOW) == 0)
- _isa_dma_free_bouncebuf(t, map);
- return (error);
- }
-
- /* ...so _isa_bus_dmamap_sync() knows we're bouncing */
- cookie->id_flags |= ID_IS_BOUNCING;
- return (0);
-}
-
-/*
- * Like _isa_bus_dmamap_load(), but for mbufs.
- */
-int
-_isa_bus_dmamap_load_mbuf(
- bus_dma_tag_t t,
- bus_dmamap_t map,
- struct mbuf *m0,
- int flags)
-{
- struct arm32_isa_dma_cookie *cookie = map->_dm_cookie;
- int error;
-
- /*
- * 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("_isa_bus_dmamap_load_mbuf: no packet header");
-#endif
-
- if (m0->m_pkthdr.len > map->_dm_size)
- return (EINVAL);
-
- /*
Home |
Main Index |
Thread Index |
Old Index