devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: linux-omap@vger.kernel.org
Cc: Vinod Koul <vinod.koul@intel.com>,
	dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	Aaro Koskinen <aaro.koskinen@iki.fi>,
	Arnd Bergmann <arnd@arndb.de>,
	Peter Ujfalusi <peter.ujfalusi@ti.com>,
	Russell King <rmk+kernel@armlinux.org.uk>,
	Vinod Koul <vkoul@kernel.org>,
	devicetree@vger.kernel.org
Subject: [PATCH 11/14] dmaengine: ti: omap-dma: Allocate channels directly
Date: Mon, 16 Dec 2019 16:19:22 -0800	[thread overview]
Message-ID: <20191217001925.44558-12-tony@atomide.com> (raw)
In-Reply-To: <20191217001925.44558-1-tony@atomide.com>

With the legacy IRQ handling gone, we can now start allocating channels
directly in the dmaengine driver for device tree based SoCs.

Cc: Aaro Koskinen <aaro.koskinen@iki.fi>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Peter Ujfalusi <peter.ujfalusi@ti.com>
Cc: Russell King <rmk+kernel@armlinux.org.uk>
Cc: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/dma/ti/omap-dma.c | 62 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 58 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/ti/omap-dma.c b/drivers/dma/ti/omap-dma.c
--- a/drivers/dma/ti/omap-dma.c
+++ b/drivers/dma/ti/omap-dma.c
@@ -28,6 +28,7 @@ struct omap_dma_config {
 	int lch_end;
 	unsigned int rw_priority:1;
 	unsigned int may_lose_context:1;
+	unsigned int needs_lch_clear:1;
 };
 
 struct omap_dma_context {
@@ -47,6 +48,8 @@ struct omap_dmadev {
 	struct notifier_block nb;
 	struct omap_dma_context context;
 	int lch_count;
+	DECLARE_BITMAP(lch_bitmap, OMAP_SDMA_CHANNELS);
+	struct mutex lch_lock;		/* for assigning logical channels */
 	bool legacy;
 	bool ll123_supported;
 	struct dma_pool *desc_pool;
@@ -664,6 +667,37 @@ static irqreturn_t omap_dma_irq(int irq, void *devid)
 	return IRQ_HANDLED;
 }
 
+static int omap_dma_get_lch(struct omap_dmadev *od, int *lch)
+{
+	int channel;
+
+	mutex_lock(&od->lch_lock);
+	channel = find_first_zero_bit(od->lch_bitmap, od->lch_count);
+	if (channel >= od->lch_count)
+		goto out_busy;
+	set_bit(channel, od->lch_bitmap);
+	mutex_unlock(&od->lch_lock);
+
+	omap_dma_clear_lch(od, channel);
+	*lch = channel;
+
+	return 0;
+
+out_busy:
+	mutex_unlock(&od->lch_lock);
+	*lch = -EINVAL;
+
+	return -EBUSY;
+}
+
+static void omap_dma_put_lch(struct omap_dmadev *od, int lch)
+{
+	omap_dma_clear_lch(od, lch);
+	mutex_lock(&od->lch_lock);
+	clear_bit(lch, od->lch_bitmap);
+	mutex_unlock(&od->lch_lock);
+}
+
 static int omap_dma_alloc_chan_resources(struct dma_chan *chan)
 {
 	struct omap_dmadev *od = to_omap_dma_dev(chan->device);
@@ -675,15 +709,13 @@ static int omap_dma_alloc_chan_resources(struct dma_chan *chan)
 		ret = omap_request_dma(c->dma_sig, "DMA engine",
 				       omap_dma_callback, c, &c->dma_ch);
 	} else {
-		ret = omap_request_dma(c->dma_sig, "DMA engine", NULL, NULL,
-				       &c->dma_ch);
+		ret = omap_dma_get_lch(od, &c->dma_ch);
 	}
 
 	dev_dbg(dev, "allocating channel %u for %u\n", c->dma_ch, c->dma_sig);
 
 	if (ret >= 0) {
 		omap_dma_assign(od, c, c->dma_ch);
-		pr_info("XXX %s: assigned lch: %i\n", __func__, c->dma_ch);
 
 		if (!od->legacy) {
 			unsigned val;
@@ -734,7 +766,11 @@ static void omap_dma_free_chan_resources(struct dma_chan *chan)
 	c->channel_base = NULL;
 	od->lch_map[c->dma_ch] = NULL;
 	vchan_free_chan_resources(&c->vc);
-	omap_free_dma(c->dma_ch);
+
+	if (od->legacy)
+		omap_free_dma(c->dma_ch);
+	else
+		omap_dma_put_lch(od, c->dma_ch);
 
 	dev_dbg(od->ddev.dev, "freeing channel %u used for %u\n", c->dma_ch,
 		c->dma_sig);
@@ -1574,6 +1610,7 @@ static int omap_dma_probe(struct platform_device *pdev)
 	struct omap_dmadev *od;
 	struct resource *res;
 	int rc, i, irq;
+	u32 val;
 
 	od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
 	if (!od)
@@ -1628,6 +1665,7 @@ static int omap_dma_probe(struct platform_device *pdev)
 	od->ddev.max_burst = SZ_16M - 1; /* CCEN: 24bit unsigned */
 	od->ddev.dev = &pdev->dev;
 	INIT_LIST_HEAD(&od->ddev.channels);
+	mutex_init(&od->lch_lock);
 	spin_lock_init(&od->lock);
 	spin_lock_init(&od->irq_lock);
 
@@ -1654,6 +1692,17 @@ static int omap_dma_probe(struct platform_device *pdev)
 		od->lch_count = OMAP_SDMA_CHANNELS;
 	}
 
+	/* Mask of allowed logical channels */
+	if (pdev->dev.of_node && !of_property_read_u32(pdev->dev.of_node,
+						       "dma-channel-mask",
+						       &val)) {
+		/* Tag channels not in mask as reserved */
+		val = ~val;
+		bitmap_from_arr32(od->lch_bitmap, &val, od->lch_count);
+	}
+	if (od->plat->dma_attr->dev_caps & HS_CHANNELS_RESERVED)
+		bitmap_set(od->lch_bitmap, 0, 2);
+
 	od->lch_map = devm_kcalloc(&pdev->dev, od->lch_count,
 				   sizeof(*od->lch_map),
 				   GFP_KERNEL);
@@ -1772,28 +1821,33 @@ static int omap_dma_remove(struct platform_device *pdev)
 static const struct omap_dma_config omap2420_data = {
 	.lch_end = CCFN,
 	.rw_priority = true,
+	.needs_lch_clear = true,
 };
 
 static const struct omap_dma_config omap2430_data = {
 	.lch_end = CCFN,
 	.rw_priority = true,
+	.needs_lch_clear = true,
 };
 
 static const struct omap_dma_config omap3430_data = {
 	.lch_end = CCFN,
 	.rw_priority = true,
+	.needs_lch_clear = true,
 	.may_lose_context = true,
 };
 
 static const struct omap_dma_config omap3630_data = {
 	.lch_end = CCDN,
 	.rw_priority = true,
+	.needs_lch_clear = true,
 	.may_lose_context = true,
 };
 
 static const struct omap_dma_config omap4_data = {
 	.lch_end = CCDN,
 	.rw_priority = true,
+	.needs_lch_clear = true,
 };
 
 static const struct of_device_id omap_dma_match[] = {
-- 
2.24.1

  parent reply	other threads:[~2019-12-17  0:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-17  0:19 [PATCH 00/14] Remove legacy sdma code for dt booting omaps Tony Lindgren
2019-12-17  0:19 ` [PATCH 01/14] ARM: dts: Add generic compatible for omap sdma instances Tony Lindgren
2019-12-17  0:19 ` [PATCH 02/14] ARM: dts: Configure interconnect target module for omap2 sdma Tony Lindgren
2019-12-17  0:19 ` [PATCH 03/14] ARM: dts: Configure interconnect target module for omap3 sdma Tony Lindgren
2019-12-17  0:19 ` [PATCH 04/14] ARM: OMAP2+: Drop unused sdma functions Tony Lindgren
2019-12-17  0:19 ` [PATCH 05/14] ARM: OMAP2+: Drop sdma interrupt handling for mach-omap2 Tony Lindgren
2019-12-17  0:19 ` [PATCH 06/14] ARM: OMAP2+: Configure sdma capabilities directly Tony Lindgren
2019-12-17  0:19 ` [PATCH 07/14] ARM: OMAP2+: Configure dma_plat_info directly and drop dma_dev_attr Tony Lindgren
2019-12-17  0:19 ` [PATCH 08/14] dmaengine: ti: omap-dma: Add device tree match data and use it for cpu_pm Tony Lindgren
2019-12-23  7:43   ` Vinod Koul
2019-12-17  0:19 ` [PATCH 09/14] dmaengine: ti: omap-dma: Configure global priority register directly Tony Lindgren
2019-12-23  7:44   ` Vinod Koul
2019-12-17  0:19 ` [PATCH 10/14] dmaengine: ti: omap-dma: Pass sdma auxdata to driver and use it Tony Lindgren
2019-12-23  7:46   ` Vinod Koul
2019-12-17  0:19 ` Tony Lindgren [this message]
2019-12-23  7:47   ` [PATCH 11/14] dmaengine: ti: omap-dma: Allocate channels directly Vinod Koul
2019-12-17  0:19 ` [PATCH 12/14] dmaengine: ti: omap-dma: Use cpu notifier to block idle for omap2 Tony Lindgren
2019-12-17  0:27   ` Tony Lindgren
2019-12-23  7:47     ` Vinod Koul
2019-12-17  0:19 ` [PATCH 13/14] ARM: OMAP2+: Drop legacy init for sdma Tony Lindgren
2019-12-17  0:19 ` [PATCH 14/14] ARM: OMAP2+: Drop legacy platform data " Tony Lindgren
2019-12-17  9:53 ` [PATCH 00/14] Remove legacy sdma code for dt booting omaps Peter Ujfalusi
2019-12-17 14:50   ` Tony Lindgren

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=20191217001925.44558-12-tony@atomide.com \
    --to=tony@atomide.com \
    --cc=aaro.koskinen@iki.fi \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=peter.ujfalusi@ti.com \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=vinod.koul@intel.com \
    --cc=vkoul@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).