All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@stericsson.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: <linux-kernel@vger.kernel.org>, Lee Jones <lee.jones@linaro.org>,
	Rabin Vincent <rabin.vincent@stericsson.com>,
	Linus Walleij <linus.walleij@stericsson.com>
Subject: [PATCH 15/32] dma40: combine desc init functions
Date: Tue, 25 Jan 2011 11:18:18 +0100	[thread overview]
Message-ID: <1295950715-22340-16-git-send-email-linus.walleij@stericsson.com> (raw)
In-Reply-To: <1295950715-22340-1-git-send-email-linus.walleij@stericsson.com>

From: Rabin Vincent <rabin.vincent@stericsson.com>

The desc init code can be shared between the mem and slave prep routines.

Acked-by: Per Forlin <per.forlin@stericsson.com>
Acked-by: Jonas Aaberg <jonas.aberg@stericsson.com>
Signed-off-by: Rabin Vincent <rabin.vincent@stericsson.com>
Signed-off-by: Linus Walleij <linus.walleij@stericsson.com>
---
 drivers/dma/ste_dma40.c |   76 ++++++++++++++++++++---------------------------
 1 files changed, 32 insertions(+), 44 deletions(-)

diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
index 0a20179..5259a98 100644
--- a/drivers/dma/ste_dma40.c
+++ b/drivers/dma/ste_dma40.c
@@ -1617,6 +1617,35 @@ static u32 stedma40_residue(struct dma_chan *chan)
 	return bytes_left;
 }
 
+static struct d40_desc *
+d40_prep_desc(struct d40_chan *chan, struct scatterlist *sg,
+	      unsigned int sg_len, unsigned long dma_flags)
+{
+	struct stedma40_chan_cfg *cfg = &chan->dma_cfg;
+	struct d40_desc *desc;
+
+	desc = d40_desc_get(chan);
+	if (!desc)
+		return NULL;
+
+	desc->lli_len = d40_sg_2_dmalen(sg, sg_len, cfg->src_info.data_width,
+					cfg->dst_info.data_width);
+	if (desc->lli_len < 0) {
+		chan_err(chan, "Unaligned size\n");
+		d40_desc_free(chan, desc);
+
+		return NULL;
+	}
+
+	desc->lli_current = 0;
+	desc->txd.flags = dma_flags;
+	desc->txd.tx_submit = d40_tx_submit;
+
+	dma_async_tx_descriptor_init(&desc->txd, &chan->chan);
+
+	return desc;
+}
+
 struct dma_async_tx_descriptor *stedma40_memcpy_sg(struct dma_chan *chan,
 						   struct scatterlist *sgl_dst,
 						   struct scatterlist *sgl_src,
@@ -1635,22 +1664,11 @@ struct dma_async_tx_descriptor *stedma40_memcpy_sg(struct dma_chan *chan,
 	}
 
 	spin_lock_irqsave(&d40c->lock, flags);
-	d40d = d40_desc_get(d40c);
 
-	if (d40d == NULL)
+	d40d = d40_prep_desc(d40c, sgl_dst, sgl_len, dma_flags);
+	if (!d40d)
 		goto err;
 
-	d40d->lli_len = d40_sg_2_dmalen(sgl_dst, sgl_len,
-					d40c->dma_cfg.src_info.data_width,
-					d40c->dma_cfg.dst_info.data_width);
-	if (d40d->lli_len < 0) {
-		chan_err(d40c, "Unaligned size\n");
-		goto err;
-	}
-
-	d40d->lli_current = 0;
-	d40d->txd.flags = dma_flags;
-
 	if (chan_is_logical(d40c)) {
 
 		if (d40_pool_lli_alloc(d40c, d40d, d40d->lli_len, true) < 0) {
@@ -1708,10 +1726,6 @@ struct dma_async_tx_descriptor *stedma40_memcpy_sg(struct dma_chan *chan,
 					   d40d->lli_pool.size, DMA_TO_DEVICE);
 	}
 
-	dma_async_tx_descriptor_init(&d40d->txd, chan);
-
-	d40d->txd.tx_submit = d40_tx_submit;
-
 	spin_unlock_irqrestore(&d40c->lock, flags);
 
 	return &d40d->txd;
@@ -1900,21 +1914,11 @@ static int d40_prep_slave_sg_log(struct d40_desc *d40d,
 	dma_addr_t dev_addr = 0;
 	int total_size;
 
-	d40d->lli_len = d40_sg_2_dmalen(sgl, sg_len,
-					d40c->dma_cfg.src_info.data_width,
-					d40c->dma_cfg.dst_info.data_width);
-	if (d40d->lli_len < 0) {
-		chan_err(d40c, "Unaligned size\n");
-		return -EINVAL;
-	}
-
 	if (d40_pool_lli_alloc(d40c, d40d, d40d->lli_len, true) < 0) {
 		chan_err(d40c, "Out of memory\n");
 		return -ENOMEM;
 	}
 
-	d40d->lli_current = 0;
-
 	if (direction == DMA_FROM_DEVICE)
 		if (d40c->runtime_addr)
 			dev_addr = d40c->runtime_addr;
@@ -1954,21 +1958,11 @@ static int d40_prep_slave_sg_phy(struct d40_desc *d40d,
 	dma_addr_t dst_dev_addr;
 	int res;
 
-	d40d->lli_len = d40_sg_2_dmalen(sgl, sgl_len,
-					d40c->dma_cfg.src_info.data_width,
-					d40c->dma_cfg.dst_info.data_width);
-	if (d40d->lli_len < 0) {
-		chan_err(d40c, "Unaligned size\n");
-		return -EINVAL;
-	}
-
 	if (d40_pool_lli_alloc(d40c, d40d, d40d->lli_len, false) < 0) {
 		chan_err(d40c, "Out of memory\n");
 		return -ENOMEM;
 	}
 
-	d40d->lli_current = 0;
-
 	if (direction == DMA_FROM_DEVICE) {
 		dst_dev_addr = 0;
 		if (d40c->runtime_addr)
@@ -2031,8 +2025,8 @@ static struct dma_async_tx_descriptor *d40_prep_slave_sg(struct dma_chan *chan,
 	}
 
 	spin_lock_irqsave(&d40c->lock, flags);
-	d40d = d40_desc_get(d40c);
 
+	d40d = d40_prep_desc(d40c, sgl, sg_len, dma_flags);
 	if (d40d == NULL)
 		goto err;
 
@@ -2048,12 +2042,6 @@ static struct dma_async_tx_descriptor *d40_prep_slave_sg(struct dma_chan *chan,
 		goto err;
 	}
 
-	d40d->txd.flags = dma_flags;
-
-	dma_async_tx_descriptor_init(&d40d->txd, chan);
-
-	d40d->txd.tx_submit = d40_tx_submit;
-
 	spin_unlock_irqrestore(&d40c->lock, flags);
 	return &d40d->txd;
 
-- 
1.7.3.2


  parent reply	other threads:[~2011-01-25 10:24 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-25 10:18 DMA40 improvements Linus Walleij
2011-01-25 10:18 ` [PATCH 01/32] dma40: make init function static Linus Walleij
2011-01-25 10:18 ` [PATCH 02/32] dma40: ensure event lines get enabled Linus Walleij
2011-01-25 10:18 ` [PATCH 03/32] dma40: remove "hardware link with previous jobs" code Linus Walleij
2011-01-25 10:18 ` [PATCH 04/32] dma40: use helper for channel registers base Linus Walleij
2011-01-25 10:18 ` [PATCH 05/32] dma40: use helpers for channel type check Linus Walleij
2011-01-25 10:18 ` [PATCH 06/32] dma40: use helpers for error functions Linus Walleij
2011-01-25 10:18 ` [PATCH 07/32] dma40: fix comment to refer to SOCs rather than boards Linus Walleij
2011-01-25 10:18 ` [PATCH 08/32] dma40: allow realtime and priority for event lines Linus Walleij
2011-01-25 10:18 ` [PATCH 09/32] dma40: remove unnecessary ALIGN()s Linus Walleij
2011-01-25 10:18 ` [PATCH 10/32] dma40: use sg_dma_address() instead of sg_phys() Linus Walleij
2011-01-25 10:18 ` [PATCH 11/32] dma40: fix DMA API usage for LCLA Linus Walleij
2011-01-25 10:18 ` [PATCH 12/32] dma40: fix DMA API usage for LLIs Linus Walleij
2011-01-25 10:18 ` [PATCH 13/32] dma40: remove unnecessary casts Linus Walleij
2011-01-25 10:18 ` [PATCH 14/32] dma40: implement prep_memcpy as a wrapper around memcpy_sg Linus Walleij
2011-01-25 10:18 ` Linus Walleij [this message]
2011-01-25 10:18 ` [PATCH 16/32] dma40: combine duplicated d40_pool_lli_alloc() calls Linus Walleij
2011-01-25 10:18 ` [PATCH 17/32] dma40: remove duplicated dev addr code Linus Walleij
2011-01-25 10:18 ` [PATCH 18/32] dma40: combine mem and slave sg-to-lli functions Linus Walleij
2011-01-25 10:18 ` [PATCH 19/32] dma40: remove export of stedma40_memcpy_sg Linus Walleij
2011-01-25 10:18 ` [PATCH 20/32] dma40: combine mem and slave prep_sg functions Linus Walleij
2011-01-25 10:18 ` [PATCH 21/32] dma40: move lli_load to main source file Linus Walleij
2011-01-25 10:18 ` [PATCH 22/32] dma40: combine duplicated code in log_sg_to_dev Linus Walleij
2011-01-25 10:18 ` [PATCH 23/32] dma40: unify d40_log_sg_to_lli funcs for mem and slave Linus Walleij
2011-01-25 10:18 ` [PATCH 24/32] dma40: pass the info pointer all the way to reduce argument count Linus Walleij
2011-01-25 10:18 ` [PATCH 25/32] dma40: unify src/dst addr check Linus Walleij
2011-01-25 10:18 ` [PATCH 26/32] dma40: make d40_log_buf_to_lli static Linus Walleij
2011-01-25 10:18 ` [PATCH 27/32] dma40: use flags to reduce parameter count Linus Walleij
2011-01-25 10:18 ` [PATCH 28/32] dma40: extract lcla code into separate function Linus Walleij
2011-01-25 10:18 ` [PATCH 29/32] dma40: handle failure to allocate first LCLA Linus Walleij
2011-01-25 10:18 ` [PATCH 30/32] dma40: fix DMA_SG capability and channels Linus Walleij
2011-01-25 10:18 ` [PATCH 31/32] dma40: stop ongoing transfers in DMA_TERMINATE_ALL Linus Walleij
2011-01-25 10:18 ` [PATCH 32/32] dma40: cyclic xfer support Linus Walleij
2011-01-31  6:17 ` DMA40 improvements Dan Williams
2011-01-31  6:21   ` Dan Williams
2011-01-31 11:14   ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1295950715-22340-16-git-send-email-linus.walleij@stericsson.com \
    --to=linus.walleij@stericsson.com \
    --cc=dan.j.williams@intel.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rabin.vincent@stericsson.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.