diff options
author | Martin Reindl <martin@cvs.openbsd.org> | 2006-03-20 01:00:59 +0000 |
---|---|---|
committer | Martin Reindl <martin@cvs.openbsd.org> | 2006-03-20 01:00:59 +0000 |
commit | 10c3543afc957b694b05960e2373daf5f4ee710c (patch) | |
tree | f6f71c1b85806ec21dda3923487d9ddf62712db4 /sys/arch | |
parent | 47d1b7910df488e3f366bcf35740d01d2e08323c (diff) |
factorize SGMAP-mapped DMA map creation and destroy code
ok miod@, additional testing jsg@
from NetBSD
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/alpha/dev/sgmap_common.c | 47 | ||||
-rw-r--r-- | sys/arch/alpha/dev/sgmapvar.h | 6 | ||||
-rw-r--r-- | sys/arch/alpha/pci/apecs_dma.c | 60 | ||||
-rw-r--r-- | sys/arch/alpha/pci/cia_dma.c | 60 | ||||
-rw-r--r-- | sys/arch/alpha/pci/lca_dma.c | 60 | ||||
-rw-r--r-- | sys/arch/alpha/pci/tsp_dma.c | 60 |
6 files changed, 63 insertions, 230 deletions
diff --git a/sys/arch/alpha/dev/sgmap_common.c b/sys/arch/alpha/dev/sgmap_common.c index 53cc0a4881f..f650f889795 100644 --- a/sys/arch/alpha/dev/sgmap_common.c +++ b/sys/arch/alpha/dev/sgmap_common.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sgmap_common.c,v 1.6 2003/10/18 20:14:41 jmc Exp $ */ +/* $OpenBSD: sgmap_common.c,v 1.7 2006/03/20 01:00:58 martin Exp $ */ /* $NetBSD: sgmap_common.c,v 1.13 2000/06/29 09:02:57 mrg Exp $ */ /*- @@ -38,6 +38,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#define _ALPHA_BUS_DMA_PRIVATE + #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> @@ -228,3 +230,46 @@ alpha_sgmap_free(map, sgmap) map->_dm_flags &= ~DMAMAP_HAS_SGMAP; } + +int +alpha_sgmap_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; +{ + bus_dmamap_t map; + int error; + + error = _bus_dmamap_create(t, size, nsegments, maxsegsz, + boundary, flags, dmamp); + if (error) + return (error); + + map = *dmamp; + + if (flags & BUS_DMA_ALLOCNOW) { + error = alpha_sgmap_alloc(map, round_page(size), + t->_sgmap, flags); + if (error) + alpha_sgmap_dmamap_destroy(t, map); +} + + return (error); +} + +void +alpha_sgmap_dmamap_destroy(t, map) + bus_dma_tag_t t; + bus_dmamap_t map; +{ + + if (map->_dm_flags & DMAMAP_HAS_SGMAP) + alpha_sgmap_free(map, t->_sgmap); + + _bus_dmamap_destroy(t, map); +} diff --git a/sys/arch/alpha/dev/sgmapvar.h b/sys/arch/alpha/dev/sgmapvar.h index c8c150fd5ac..402aaaacb34 100644 --- a/sys/arch/alpha/dev/sgmapvar.h +++ b/sys/arch/alpha/dev/sgmapvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sgmapvar.h,v 1.2 2002/03/14 01:26:26 millert Exp $ */ +/* $OpenBSD: sgmapvar.h,v 1.3 2006/03/20 01:00:58 martin Exp $ */ /* $NetBSD: sgmapvar.h,v 1.10 1998/08/14 16:50:02 thorpej Exp $ */ /*- @@ -93,4 +93,8 @@ int alpha_sgmap_alloc(bus_dmamap_t, bus_size_t, struct alpha_sgmap *, int); void alpha_sgmap_free(bus_dmamap_t, struct alpha_sgmap *); +int alpha_sgmap_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, + bus_size_t, int, bus_dmamap_t *); +void alpha_sgmap_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); + #endif /* _ALPHA_COMMON_SGMAPVAR_H */ diff --git a/sys/arch/alpha/pci/apecs_dma.c b/sys/arch/alpha/pci/apecs_dma.c index 3442f194e73..a4ba8c61253 100644 --- a/sys/arch/alpha/pci/apecs_dma.c +++ b/sys/arch/alpha/pci/apecs_dma.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apecs_dma.c,v 1.3 2002/03/14 01:26:27 millert Exp $ */ +/* $OpenBSD: apecs_dma.c,v 1.4 2006/03/20 01:00:58 martin Exp $ */ /* $NetBSD: apecs_dma.c,v 1.13 2000/06/29 08:58:45 mrg Exp $ */ /*- @@ -61,11 +61,6 @@ bus_dma_tag_t apecs_dma_get_tag(bus_dma_tag_t, alpha_bus_t); -int apecs_bus_dmamap_create_sgmap(bus_dma_tag_t, bus_size_t, int, - bus_size_t, bus_size_t, int, bus_dmamap_t *); - -void apecs_bus_dmamap_destroy_sgmap(bus_dma_tag_t, bus_dmamap_t); - int apecs_bus_dmamap_load_sgmap(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t, struct proc *, int); @@ -146,8 +141,8 @@ apecs_dma_init(acp) t->_boundary = 0; t->_sgmap = &acp->ac_sgmap; t->_get_tag = apecs_dma_get_tag; - t->_dmamap_create = apecs_bus_dmamap_create_sgmap; - t->_dmamap_destroy = apecs_bus_dmamap_destroy_sgmap; + t->_dmamap_create = alpha_sgmap_dmamap_create; + t->_dmamap_destroy = alpha_sgmap_dmamap_destroy; t->_dmamap_load = apecs_bus_dmamap_load_sgmap; t->_dmamap_load_mbuf = apecs_bus_dmamap_load_mbuf_sgmap; t->_dmamap_load_uio = apecs_bus_dmamap_load_uio_sgmap; @@ -340,52 +335,3 @@ apecs_bus_dmamap_unload_sgmap(t, map) */ _bus_dmamap_unload(t, map); } - -/* - * Create a APECS SGMAP-mapped DMA map. - */ -int -apecs_bus_dmamap_create_sgmap(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; -{ - bus_dmamap_t map; - int error; - - error = _bus_dmamap_create(t, size, nsegments, maxsegsz, - boundary, flags, dmamp); - if (error) - return (error); - - map = *dmamp; - - if (flags & BUS_DMA_ALLOCNOW) { - error = alpha_sgmap_alloc(map, round_page(size), - t->_sgmap, flags); - if (error) - apecs_bus_dmamap_destroy_sgmap(t, map); - } - - return (error); -} - -/* - * Destroy a APECS SGMAP-mapped DMA map. - */ -void -apecs_bus_dmamap_destroy_sgmap(t, map) - bus_dma_tag_t t; - bus_dmamap_t map; -{ - - if (map->_dm_flags & DMAMAP_HAS_SGMAP) - alpha_sgmap_free(map, t->_sgmap); - - _bus_dmamap_destroy(t, map); -} diff --git a/sys/arch/alpha/pci/cia_dma.c b/sys/arch/alpha/pci/cia_dma.c index 56413640d07..37394c9e799 100644 --- a/sys/arch/alpha/pci/cia_dma.c +++ b/sys/arch/alpha/pci/cia_dma.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cia_dma.c,v 1.5 2003/10/18 20:14:42 jmc Exp $ */ +/* $OpenBSD: cia_dma.c,v 1.6 2006/03/20 01:00:58 martin Exp $ */ /* $NetBSD: cia_dma.c,v 1.16 2000/06/29 08:58:46 mrg Exp $ */ /*- @@ -64,11 +64,6 @@ bus_dma_tag_t cia_dma_get_tag(bus_dma_tag_t, alpha_bus_t); int cia_bus_dmamap_create_direct(bus_dma_tag_t, bus_size_t, int, bus_size_t, bus_size_t, int, bus_dmamap_t *); -int cia_bus_dmamap_create_sgmap(bus_dma_tag_t, bus_size_t, int, - bus_size_t, bus_size_t, int, bus_dmamap_t *); - -void cia_bus_dmamap_destroy_sgmap(bus_dma_tag_t, bus_dmamap_t); - int cia_bus_dmamap_load_sgmap(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t, struct proc *, int); @@ -150,8 +145,8 @@ cia_dma_init(ccp) t->_boundary = 0; t->_sgmap = &ccp->cc_sgmap; t->_get_tag = cia_dma_get_tag; - t->_dmamap_create = cia_bus_dmamap_create_sgmap; - t->_dmamap_destroy = cia_bus_dmamap_destroy_sgmap; + t->_dmamap_create = alpha_sgmap_dmamap_create; + t->_dmamap_destroy = alpha_sgmap_dmamap_destroy; t->_dmamap_load = cia_bus_dmamap_load_sgmap; t->_dmamap_load_mbuf = cia_bus_dmamap_load_mbuf_sgmap; t->_dmamap_load_uio = cia_bus_dmamap_load_uio_sgmap; @@ -335,55 +330,6 @@ cia_bus_dmamap_create_direct(t, size, nsegments, maxsegsz, boundary, } /* - * Create a CIA SGMAP-mapped DMA map. - */ -int -cia_bus_dmamap_create_sgmap(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; -{ - bus_dmamap_t map; - int error; - - error = _bus_dmamap_create(t, size, nsegments, maxsegsz, - boundary, flags, dmamp); - if (error) - return (error); - - map = *dmamp; - - if (flags & BUS_DMA_ALLOCNOW) { - error = alpha_sgmap_alloc(map, round_page(size), - t->_sgmap, flags); - if (error) - cia_bus_dmamap_destroy_sgmap(t, map); - } - - return (error); -} - -/* - * Destroy a CIA SGMAP-mapped DMA map. - */ -void -cia_bus_dmamap_destroy_sgmap(t, map) - bus_dma_tag_t t; - bus_dmamap_t map; -{ - - if (map->_dm_flags & DMAMAP_HAS_SGMAP) - alpha_sgmap_free(map, t->_sgmap); - - _bus_dmamap_destroy(t, map); -} - -/* * Load a CIA SGMAP-mapped DMA map with a linear buffer. */ int diff --git a/sys/arch/alpha/pci/lca_dma.c b/sys/arch/alpha/pci/lca_dma.c index 25d1f0ed16f..a6c4f293f4c 100644 --- a/sys/arch/alpha/pci/lca_dma.c +++ b/sys/arch/alpha/pci/lca_dma.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lca_dma.c,v 1.5 2003/10/18 20:14:42 jmc Exp $ */ +/* $OpenBSD: lca_dma.c,v 1.6 2006/03/20 01:00:58 martin Exp $ */ /* $NetBSD: lca_dma.c,v 1.13 2000/06/29 08:58:47 mrg Exp $ */ /*- @@ -61,11 +61,6 @@ bus_dma_tag_t lca_dma_get_tag(bus_dma_tag_t, alpha_bus_t); -int lca_bus_dmamap_create_sgmap(bus_dma_tag_t, bus_size_t, int, - bus_size_t, bus_size_t, int, bus_dmamap_t *); - -void lca_bus_dmamap_destroy_sgmap(bus_dma_tag_t, bus_dmamap_t); - int lca_bus_dmamap_load_sgmap(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t, struct proc *, int); @@ -145,9 +140,9 @@ lca_dma_init(lcp) t->_boundary = 0; t->_sgmap = &lcp->lc_sgmap; t->_get_tag = lca_dma_get_tag; - t->_dmamap_create = lca_bus_dmamap_create_sgmap; + t->_dmamap_create = alpha_sgmap_dmamap_create; - t->_dmamap_destroy = lca_bus_dmamap_destroy_sgmap; + t->_dmamap_destroy = alpha_sgmap_dmamap_destroy; t->_dmamap_load = lca_bus_dmamap_load_sgmap; t->_dmamap_load_mbuf = lca_bus_dmamap_load_mbuf_sgmap; t->_dmamap_load_uio = lca_bus_dmamap_load_uio_sgmap; @@ -344,52 +339,3 @@ lca_bus_dmamap_unload_sgmap(t, map) */ _bus_dmamap_unload(t, map); } - -/* - * Create a LCA SGMAP-mapped DMA map. - */ -int -lca_bus_dmamap_create_sgmap(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; -{ - bus_dmamap_t map; - int error; - - error = _bus_dmamap_create(t, size, nsegments, maxsegsz, - boundary, flags, dmamp); - if (error) - return (error); - - map = *dmamp; - - if (flags & BUS_DMA_ALLOCNOW) { - error = alpha_sgmap_alloc(map, round_page(size), - t->_sgmap, flags); - if (error) - lca_bus_dmamap_destroy_sgmap(t, map); - } - - return (error); -} - -/* - * Destroy a LCA SGMAP-mapped DMA map. - */ -void -lca_bus_dmamap_destroy_sgmap(t, map) - bus_dma_tag_t t; - bus_dmamap_t map; -{ - - if (map->_dm_flags & DMAMAP_HAS_SGMAP) - alpha_sgmap_free(map, t->_sgmap); - - _bus_dmamap_destroy(t, map); -} diff --git a/sys/arch/alpha/pci/tsp_dma.c b/sys/arch/alpha/pci/tsp_dma.c index 5dcab88356f..339daaf9648 100644 --- a/sys/arch/alpha/pci/tsp_dma.c +++ b/sys/arch/alpha/pci/tsp_dma.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tsp_dma.c,v 1.3 2002/03/14 01:26:27 millert Exp $ */ +/* $OpenBSD: tsp_dma.c,v 1.4 2006/03/20 01:00:58 martin Exp $ */ /* $NetBSD: tsp_dma.c,v 1.1 1999/06/29 06:46:47 ross Exp $ */ /*- @@ -95,11 +95,6 @@ bus_dma_tag_t tsp_dma_get_tag(bus_dma_tag_t, alpha_bus_t); -int tsp_bus_dmamap_create_sgmap(bus_dma_tag_t, bus_size_t, int, - bus_size_t, bus_size_t, int, bus_dmamap_t *); - -void tsp_bus_dmamap_destroy_sgmap(bus_dma_tag_t, bus_dmamap_t); - int tsp_bus_dmamap_load_sgmap(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t, struct proc *, int); @@ -185,8 +180,8 @@ tsp_dma_init(pcp) t->_boundary = 0; t->_sgmap = &pcp->pc_sgmap; t->_get_tag = tsp_dma_get_tag; - t->_dmamap_create = tsp_bus_dmamap_create_sgmap; - t->_dmamap_destroy = tsp_bus_dmamap_destroy_sgmap; + t->_dmamap_create = alpha_sgmap_dmamap_create; + t->_dmamap_destroy = alpha_sgmap_dmamap_destroy; t->_dmamap_load = tsp_bus_dmamap_load_sgmap; t->_dmamap_load_mbuf = tsp_bus_dmamap_load_mbuf_sgmap; t->_dmamap_load_uio = tsp_bus_dmamap_load_uio_sgmap; @@ -275,55 +270,6 @@ tsp_dma_get_tag(t, bustype) } /* - * Create a TSP SGMAP-mapped DMA map. - */ -int -tsp_bus_dmamap_create_sgmap(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; -{ - bus_dmamap_t map; - int error; - - error = _bus_dmamap_create(t, size, nsegments, maxsegsz, - boundary, flags, dmamp); - if (error) - return (error); - - map = *dmamp; - - if (flags & BUS_DMA_ALLOCNOW) { - error = alpha_sgmap_alloc(map, round_page(size), - t->_sgmap, flags); - if (error) - tsp_bus_dmamap_destroy_sgmap(t, map); - } - - return (error); -} - -/* - * Destroy a TSP SGMAP-mapped DMA map. - */ -void -tsp_bus_dmamap_destroy_sgmap(t, map) - bus_dma_tag_t t; - bus_dmamap_t map; -{ - - if (map->_dm_flags & DMAMAP_HAS_SGMAP) - alpha_sgmap_free(map, t->_sgmap); - - _bus_dmamap_destroy(t, map); -} - -/* * Load a TSP SGMAP-mapped DMA map with a linear buffer. */ int |