From 835954550a2fbc3b2244324492456b47f0c22c8b Mon Sep 17 00:00:00 2001 From: Rabin Vincent Date: Tue, 25 Jan 2011 11:18:14 +0100 Subject: dma40: fix DMA API usage for LCLA Map the buffer once and use dma_sync*() appropriately instead of mapping the buffer over and over without unmapping it. Change-Id: I4a16dc96409ba657b4994329e53668320393e0e0 Acked-by: Per Forlin Acked-by: Jonas Aaberg Signed-off-by: Rabin Vincent Signed-off-by: Linus Walleij Signed-off-by: Dan Williams Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/31856 Tested-by: Narayanan GOPALAKRISHNAN Reviewed-by: Jonas ABERG --- drivers/dma/ste_dma40.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'drivers/dma') diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c index 52d67e6f2b2..b56fd03e55e 100644 --- a/drivers/dma/ste_dma40.c +++ b/drivers/dma/ste_dma40.c @@ -189,6 +189,7 @@ struct d40_desc { */ struct d40_lcla_pool { void *base; + dma_addr_t dma_addr; void *base_unaligned; int pages; spinlock_t lock; @@ -612,8 +613,11 @@ static int d40_desc_log_lli_to_lcxa(struct d40_chan *d40c, return first_lcla; for (; d40d->lli_current < d40d->lli_len; d40d->lli_current++) { + unsigned int lcla_offset = d40c->phy_chan->num * 1024 + + 8 * curr_lcla * 2; + struct d40_lcla_pool *pool = &d40c->base->lcla_pool; + struct d40_log_lli *lcla = pool->base + lcla_offset; int lli_current = d40d->lli_current; - struct d40_log_lli *lcla; int next_lcla; bool interrupt; @@ -639,10 +643,6 @@ static int d40_desc_log_lli_to_lcxa(struct d40_chan *d40c, interrupt); } - lcla = d40c->base->lcla_pool.base + - d40c->phy_chan->num * 1024 + - 8 * curr_lcla * 2; - d40_log_lli_lcla_write(lcla, &lli->dst[lli_current], &lli->src[lli_current], @@ -656,9 +656,10 @@ static int d40_desc_log_lli_to_lcxa(struct d40_chan *d40c, * mapped in esram */ if (!use_esram_lcla) { - (void) dma_map_single(d40c->base->dev, lcla, - 2 * sizeof(struct d40_log_lli), - DMA_TO_DEVICE); + dma_sync_single_range_for_device(d40c->base->dev, + pool->dma_addr, lcla_offset, + 2 * sizeof(struct d40_log_lli), + DMA_TO_DEVICE); } curr_lcla = next_lcla; @@ -3484,6 +3485,7 @@ static void __init d40_hw_init(struct d40_base *base) static int __init d40_lcla_allocate(struct d40_base *base) { + struct d40_lcla_pool *pool = &base->lcla_pool; unsigned long *page_list; int i; int j; @@ -3549,6 +3551,15 @@ static int __init d40_lcla_allocate(struct d40_base *base) LCLA_ALIGNMENT); } + pool->dma_addr = dma_map_single(base->dev, pool->base, + SZ_1K * base->num_phy_chans, + DMA_TO_DEVICE); + if (dma_mapping_error(base->dev, pool->dma_addr)) { + pool->dma_addr = 0; + ret = -ENOMEM; + goto failure; + } + writel(virt_to_phys(base->lcla_pool.base), base->virtbase + D40_DREG_LCLA); failure: @@ -3689,6 +3700,11 @@ failure: base->lcla_pool.base = NULL; } + if (base->lcla_pool.dma_addr) + dma_unmap_single(base->dev, base->lcla_pool.dma_addr, + SZ_1K * base->num_phy_chans, + DMA_TO_DEVICE); + if (!base->lcla_pool.base_unaligned && base->lcla_pool.base) free_pages((unsigned long)base->lcla_pool.base, base->lcla_pool.pages); -- cgit v1.2.3