From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: Frank Li <Frank.Li@nxp.com>, Vinod Koul <vkoul@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>
Cc: Frank Li <Frank.Li@kernel.org>, Joy Zou <joy.zou@nxp.com>,
imx@lists.linux.dev, dmaengine@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Peng Fan <peng.fan@nxp.com>
Subject: [PATCH v2 2/3] dmaengine: fsl-edma: support per-channel DT child nodes
Date: Wed, 30 Sep 2026 14:26:10 +0800 [thread overview]
Message-ID: <20260930-edma-iommu-v2-2-72a62bf44c74@nxp.com> (raw)
In-Reply-To: <20260930-edma-iommu-v2-0-72a62bf44c74@nxp.com>
From: Peng Fan <peng.fan@nxp.com>
Add support for parsing per-channel child nodes from devicetree.
Each child node can carry its own interrupts, iommus, and
power-domains properties.
The implementation is split into three functions:
- fsl_edma_child_to_chan_id(): derives the channel index from the
child MMIO address relative to the parent base.
- fsl_edma_configure_chan_from_dt(): called before setup_irq() to
populate per-channel txirq from child interrupt properties.
fsl_edma3_irq_init() is updated to skip platform_get_irq() for
channels that already have an IRQ assigned from their child node.
- fsl_edma_configure_chan_iommu(): called after
dmaenginem_async_device_register() to configure per-channel IOMMU
by calling of_dma_configure() on each dma_chan_dev and setting
chan_dma_dev so dmaengine_get_dma_device() returns the per-channel
device.
Existing DTS without child nodes continues to work unchanged.
Assisted-by: LLM
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/dma/fsl-edma-common.c | 10 +--
drivers/dma/fsl-edma-main.c | 149 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 149 insertions(+), 10 deletions(-)
diff --git a/drivers/dma/fsl-edma-common.c b/drivers/dma/fsl-edma-common.c
index bb7531c456df..8c78b0d781b0 100644
--- a/drivers/dma/fsl-edma-common.c
+++ b/drivers/dma/fsl-edma-common.c
@@ -283,10 +283,10 @@ int fsl_edma_resume(struct dma_chan *chan)
static void fsl_edma_unprep_slave_dma(struct fsl_edma_chan *fsl_chan)
{
+ struct device *dev = dmaengine_get_dma_device(&fsl_chan->vchan.chan);
+
if (fsl_chan->dma_dir != DMA_NONE)
- dma_unmap_resource(fsl_chan->vchan.chan.device->dev,
- fsl_chan->dma_dev_addr,
- fsl_chan->dma_dev_size,
+ dma_unmap_resource(dev, fsl_chan->dma_dev_addr, fsl_chan->dma_dev_size,
fsl_chan->dma_dir, 0);
fsl_chan->dma_dir = DMA_NONE;
}
@@ -294,7 +294,7 @@ static void fsl_edma_unprep_slave_dma(struct fsl_edma_chan *fsl_chan)
static bool fsl_edma_prep_slave_dma(struct fsl_edma_chan *fsl_chan,
enum dma_transfer_direction dir)
{
- struct device *dev = fsl_chan->vchan.chan.device->dev;
+ struct device *dev = dmaengine_get_dma_device(&fsl_chan->vchan.chan);
enum dma_data_direction dma_dir;
phys_addr_t addr = 0;
u32 size = 0;
@@ -847,7 +847,7 @@ int fsl_edma_alloc_chan_resources(struct dma_chan *chan)
if (fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_HAS_CHCLK)
clk_prepare_enable(fsl_chan->clk);
- fsl_chan->tcd_pool = dma_pool_create("tcd_pool", chan->device->dev,
+ fsl_chan->tcd_pool = dma_pool_create("tcd_pool", dmaengine_get_dma_device(chan),
fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_TCD64 ?
sizeof(struct fsl_edma_hw_tcd64) : sizeof(struct fsl_edma_hw_tcd),
32, 0);
diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c
index 6934ac882697..13bc5059d1bc 100644
--- a/drivers/dma/fsl-edma-main.c
+++ b/drivers/dma/fsl-edma-main.c
@@ -16,7 +16,10 @@
#include <linux/interrupt.h>
#include <linux/clk.h>
#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
#include <linux/of_dma.h>
+#include <linux/of_irq.h>
#include <linux/dma-mapping.h>
#include <linux/pm_runtime.h>
#include <linux/pm_domain.h>
@@ -395,12 +398,13 @@ static int fsl_edma3_irq_init(struct platform_device *pdev, struct fsl_edma_engi
if (fsl_edma->chan_masked & BIT(i))
continue;
- /* request channel irq */
- fsl_chan->txirq = platform_get_irq(pdev, i);
- if (fsl_chan->txirq < 0)
- return -EINVAL;
+ if (fsl_chan->txirq <= 0) {
+ fsl_chan->txirq = platform_get_irq(pdev, i);
+ if (fsl_chan->txirq < 0)
+ return -EINVAL;
- fsl_chan->irq_handler = fsl_edma3_tx_handler;
+ fsl_chan->irq_handler = fsl_edma3_tx_handler;
+ }
if (!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_ERRIRQ_SHARE)) {
fsl_chan->errirq = fsl_chan->txirq;
@@ -698,6 +702,133 @@ static int fsl_edma3_attach_pd(struct platform_device *pdev, struct fsl_edma_eng
return -EINVAL;
}
+static int fsl_edma_child_to_chan_id(struct platform_device *pdev,
+ struct fsl_edma_engine *fsl_edma,
+ struct device_node *child,
+ struct resource *parent_res)
+{
+ const struct fsl_edma_drvdata *drvdata = fsl_edma->drvdata;
+ struct resource child_res;
+ u32 ch_id;
+ int ret;
+
+ ret = of_address_to_resource(child, 0, &child_res);
+ if (ret)
+ return ret;
+
+ if (child_res.start < parent_res->start + drvdata->chreg_off)
+ return -EINVAL;
+
+ ch_id = (child_res.start - parent_res->start - drvdata->chreg_off)
+ / drvdata->chreg_space_sz;
+
+ if (ch_id >= fsl_edma->n_chans)
+ return -EINVAL;
+
+ return ch_id;
+}
+
+static int fsl_edma_configure_chan_from_dt(struct platform_device *pdev,
+ struct fsl_edma_engine *fsl_edma)
+{
+ struct device_node *np = pdev->dev.of_node;
+ struct resource parent_res;
+ struct device_node *child;
+ int ret;
+
+ ret = of_address_to_resource(np, 0, &parent_res);
+ if (ret)
+ return ret;
+
+ for_each_available_child_of_node(np, child) {
+ struct fsl_edma_chan *fsl_chan;
+ int ch_id, irq;
+
+ ch_id = fsl_edma_child_to_chan_id(pdev, fsl_edma, child,
+ &parent_res);
+ if (ch_id < 0) {
+ dev_err(&pdev->dev, "invalid channel in %pOFn\n", child);
+ of_node_put(child);
+ return -EINVAL;
+ }
+
+ if (fsl_edma->chan_masked & BIT(ch_id))
+ continue;
+
+ fsl_chan = &fsl_edma->chans[ch_id];
+
+ irq = of_irq_get(child, 0);
+ if (irq > 0) {
+ fsl_chan->txirq = irq;
+ fsl_chan->irq_handler = fsl_edma3_tx_handler;
+ }
+ }
+
+ return 0;
+}
+
+static int fsl_edma_configure_chan_iommu(struct platform_device *pdev,
+ struct fsl_edma_engine *fsl_edma)
+{
+ struct device_node *np = pdev->dev.of_node;
+ struct resource parent_res;
+ struct device_node *child;
+ struct dma_chan *chan;
+ int ret;
+
+ ret = of_address_to_resource(np, 0, &parent_res);
+ if (ret)
+ return ret;
+
+ for_each_available_child_of_node(np, child) {
+ struct fsl_edma_chan *fsl_chan;
+ int ch_id;
+
+ if (!of_property_present(child, "iommus"))
+ continue;
+
+ ch_id = fsl_edma_child_to_chan_id(pdev, fsl_edma, child,
+ &parent_res);
+ if (ch_id < 0)
+ continue;
+
+ if (fsl_edma->chan_masked & BIT(ch_id))
+ continue;
+
+ fsl_chan = &fsl_edma->chans[ch_id];
+
+ list_for_each_entry(chan, &fsl_edma->dma_dev.channels,
+ device_node) {
+ struct device *chdev;
+
+ if (to_fsl_edma_chan(chan) != fsl_chan)
+ continue;
+
+ chdev = dmaengine_chan_dev(chan);
+ chdev->bus = pdev->dev.bus;
+ if (fsl_edma->drvdata->flags & FSL_EDMA_DRV_TCD64)
+ dma_coerce_mask_and_coherent(chdev,
+ DMA_BIT_MASK(64));
+ else
+ dma_coerce_mask_and_coherent(chdev,
+ DMA_BIT_MASK(32));
+ ret = of_dma_configure(chdev, child, true);
+ if (ret) {
+ dev_err(&pdev->dev,
+ "IOMMU config failed for channel %d: %d\n",
+ ch_id, ret);
+ of_node_put(child);
+ return ret;
+ }
+
+ chan->chan_dev->chan_dma_dev = true;
+ break;
+ }
+ }
+
+ return 0;
+}
+
static int fsl_edma_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
@@ -831,6 +962,10 @@ static int fsl_edma_probe(struct platform_device *pdev)
clk_disable_unprepare(fsl_chan->clk);
}
+ ret = fsl_edma_configure_chan_from_dt(pdev, fsl_edma);
+ if (ret)
+ return ret;
+
ret = fsl_edma->drvdata->setup_irq(pdev, fsl_edma);
if (ret)
return ret;
@@ -885,6 +1020,10 @@ static int fsl_edma_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, ret,
"Can't register Freescale eDMA engine.\n");
+ ret = fsl_edma_configure_chan_iommu(pdev, fsl_edma);
+ if (ret)
+ return ret;
+
ret = devm_of_dma_controller_register(&pdev->dev, np,
drvdata->dmamuxs ? fsl_edma_xlate : fsl_edma3_xlate,
fsl_edma);
--
2.51.0
next prev parent reply other threads:[~2026-09-30 6:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 6:26 [PATCH v2 0/3] dmaengine: fsl-edma: per-channel IOMMU support via DT child nodes Peng Fan (OSS)
2026-09-30 6:26 ` [PATCH v2 1/3] dt-bindings: dma: fsl,edma: add per-channel child node support Peng Fan (OSS)
2026-09-30 16:00 ` Frank Li
2026-09-30 6:26 ` Peng Fan (OSS) [this message]
2026-09-30 6:26 ` [PATCH v2 3/3] arm64: dts: imx95: convert eDMA to per-channel child nodes Peng Fan (OSS)
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=20260930-edma-iommu-v2-2-72a62bf44c74@nxp.com \
--to=peng.fan@oss.nxp.com \
--cc=Frank.Li@kernel.org \
--cc=Frank.Li@nxp.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=joy.zou@nxp.com \
--cc=kernel@pengutronix.de \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peng.fan@nxp.com \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--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