From 146a427352437070f0432294ade93af269c92aa2 Mon Sep 17 00:00:00 2001 From: Jonathan Matthew Date: Sat, 14 Jun 2014 23:11:21 +0000 Subject: Preallocate sgmap extent regions for tsp, cia and mcpcia dma maps, which fall back to sgmap if the direct mapping fails. ok miod@ --- sys/arch/alpha/dev/sgmap_common.c | 26 +++++++++++++++++++++----- sys/arch/alpha/dev/sgmapvar.h | 4 +++- sys/arch/alpha/pci/cia_dma.c | 25 +++++++++++++++++++++++-- sys/arch/alpha/pci/mcpcia_dma.c | 10 +++++++--- sys/arch/alpha/pci/tsp_dma.c | 10 +++++++--- 5 files changed, 61 insertions(+), 14 deletions(-) (limited to 'sys') diff --git a/sys/arch/alpha/dev/sgmap_common.c b/sys/arch/alpha/dev/sgmap_common.c index 0f0d6734703..11d26b8b48b 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.11 2014/03/31 21:10:10 kettenis Exp $ */ +/* $OpenBSD: sgmap_common.c,v 1.12 2014/06/14 23:11:20 jmatthew Exp $ */ /* $NetBSD: sgmap_common.c,v 1.13 2000/06/29 09:02:57 mrg Exp $ */ /*- @@ -142,6 +142,17 @@ alpha_sgmap_init(t, sgmap, name, wbase, sgvabase, sgvasize, ptesize, ptva, panic("alpha_sgmap_init"); } +int +alpha_sgmap_dmamap_setup(map, nsegments, flags) + bus_dmamap_t map; + int nsegments; + int flags; +{ + map->_dm_cookie = malloc(nsegments * sizeof(struct extent_region), + M_DEVBUF, (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK); + return (map->_dm_cookie == NULL); +} + int alpha_sgmap_dmamap_create(t, size, nsegments, maxsegsz, boundary, flags, dmamp) @@ -162,9 +173,7 @@ alpha_sgmap_dmamap_create(t, size, nsegments, maxsegsz, boundary, return (error); map = *dmamp; - map->_dm_cookie = malloc(nsegments * sizeof(struct extent_region), - M_DEVBUF, (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK); - if (map->_dm_cookie == NULL) { + if (alpha_sgmap_dmamap_setup(map, nsegments, flags)) { _bus_dmamap_destroy(t, map); return (ENOMEM); } @@ -174,6 +183,13 @@ alpha_sgmap_dmamap_create(t, size, nsegments, maxsegsz, boundary, return (0); } +void +alpha_sgmap_dmamap_teardown(map) + bus_dmamap_t map; +{ + free(map->_dm_cookie, M_DEVBUF); +} + void alpha_sgmap_dmamap_destroy(t, map) bus_dma_tag_t t; @@ -181,6 +197,6 @@ alpha_sgmap_dmamap_destroy(t, map) { KASSERT(map->dm_mapsize == 0); - free(map->_dm_cookie, M_DEVBUF); + alpha_sgmap_dmamap_teardown(map); _bus_dmamap_destroy(t, map); } diff --git a/sys/arch/alpha/dev/sgmapvar.h b/sys/arch/alpha/dev/sgmapvar.h index 097f33a30cd..3acefd9f04e 100644 --- a/sys/arch/alpha/dev/sgmapvar.h +++ b/sys/arch/alpha/dev/sgmapvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sgmapvar.h,v 1.6 2014/03/31 21:10:10 kettenis Exp $ */ +/* $OpenBSD: sgmapvar.h,v 1.7 2014/06/14 23:11:20 jmatthew Exp $ */ /* $NetBSD: sgmapvar.h,v 1.10 1998/08/14 16:50:02 thorpej Exp $ */ /*- @@ -70,6 +70,8 @@ void alpha_sgmap_init(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_dmamap_setup(bus_dmamap_t, int, int); +void alpha_sgmap_dmamap_teardown(bus_dmamap_t); 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); diff --git a/sys/arch/alpha/pci/cia_dma.c b/sys/arch/alpha/pci/cia_dma.c index 29b3ddae8f2..54b0d74be67 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.10 2009/02/01 14:34:00 miod Exp $ */ +/* $OpenBSD: cia_dma.c,v 1.11 2014/06/14 23:11:20 jmatthew Exp $ */ /* $NetBSD: cia_dma.c,v 1.16 2000/06/29 08:58:46 mrg Exp $ */ /*- @@ -56,6 +56,7 @@ 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 *); +void cia_bus_dmamap_destroy_direct(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); @@ -113,7 +114,7 @@ cia_dma_init(ccp) t->_sgmap = NULL; t->_get_tag = cia_dma_get_tag; t->_dmamap_create = cia_bus_dmamap_create_direct; - t->_dmamap_destroy = _bus_dmamap_destroy; + t->_dmamap_destroy = cia_bus_dmamap_destroy_direct; t->_dmamap_load = _bus_dmamap_load_direct; t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct; t->_dmamap_load_uio = _bus_dmamap_load_uio_direct; @@ -307,7 +308,15 @@ cia_bus_dmamap_create_direct(t, size, nsegments, maxsegsz, boundary, if (error) return (error); + /* + * Since we fall back to sgmap if the direct mapping fails, + * we need to set up for sgmap in any case. + */ map = *dmamp; + if (alpha_sgmap_dmamap_setup(map, nsegments, flags)) { + _bus_dmamap_destroy(t, map); + return (ENOMEM); + } if ((ccp->cc_flags & CCF_PYXISBUG) != 0 && map->_dm_segcnt > 1) { @@ -328,6 +337,18 @@ cia_bus_dmamap_create_direct(t, size, nsegments, maxsegsz, boundary, return (0); } +/* + * Destroy a CIA direct-mapped DMA map. + */ +void +cia_bus_dmamap_destroy_direct(t, map) + bus_dma_tag_t t; + bus_dmamap_t map; +{ + alpha_sgmap_dmamap_teardown(map); + _bus_dmamap_destroy(t, map); +} + /* * Load a CIA SGMAP-mapped DMA map with a linear buffer. */ diff --git a/sys/arch/alpha/pci/mcpcia_dma.c b/sys/arch/alpha/pci/mcpcia_dma.c index 7dba6aa8823..4d019dbb2cf 100644 --- a/sys/arch/alpha/pci/mcpcia_dma.c +++ b/sys/arch/alpha/pci/mcpcia_dma.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mcpcia_dma.c,v 1.4 2012/12/05 23:20:10 deraadt Exp $ */ +/* $OpenBSD: mcpcia_dma.c,v 1.5 2014/06/14 23:11:20 jmatthew Exp $ */ /* $NetBSD: mcpcia_dma.c,v 1.15 2001/07/19 18:55:40 thorpej Exp $ */ /*- @@ -108,8 +108,12 @@ mcpcia_dma_init(ccp) t->_boundary = 0; t->_sgmap = NULL; t->_get_tag = mcpcia_dma_get_tag; - t->_dmamap_create = _bus_dmamap_create; - t->_dmamap_destroy = _bus_dmamap_destroy; + /* + * Since we fall back to sgmap if the direct mapping fails, + * we need to set up for sgmap in any case. + */ + t->_dmamap_create = alpha_sgmap_dmamap_create; + t->_dmamap_destroy = alpha_sgmap_dmamap_destroy; t->_dmamap_load = _bus_dmamap_load_direct; t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct; t->_dmamap_load_uio = _bus_dmamap_load_uio_direct; diff --git a/sys/arch/alpha/pci/tsp_dma.c b/sys/arch/alpha/pci/tsp_dma.c index 32f5d3fb695..819a3c710ee 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.10 2014/05/08 20:46:49 miod Exp $ */ +/* $OpenBSD: tsp_dma.c,v 1.11 2014/06/14 23:11:20 jmatthew Exp $ */ /* $NetBSD: tsp_dma.c,v 1.1 1999/06/29 06:46:47 ross Exp $ */ /*- @@ -153,8 +153,12 @@ tsp_dma_init(struct device *tsp, struct tsp_config *pcp) t->_boundary = 0; t->_sgmap = NULL; t->_get_tag = tsp_dma_get_tag; - t->_dmamap_create = _bus_dmamap_create; - t->_dmamap_destroy = _bus_dmamap_destroy; + /* + * Since we fall back to sgmap if the direct mapping fails, + * we need to set up for sgmap in any case. + */ + t->_dmamap_create = alpha_sgmap_dmamap_create; + t->_dmamap_destroy = alpha_sgmap_dmamap_destroy; t->_dmamap_load = _bus_dmamap_load_direct; t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct; t->_dmamap_load_uio = _bus_dmamap_load_uio_direct; -- cgit v1.2.3