From: Thierry Reding <thierry.reding@gmail.com>
To: Akhil R <akhilrajeev@nvidia.com>
Cc: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Jonathan Hunter <jonathanh@nvidia.com>,
Laxman Dewangan <ldewangan@nvidia.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
dmaengine@vger.kernel.org, devicetree@vger.kernel.org,
linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 08/10] dmaengine: tegra: Use iommu-map for stream ID
Date: Fri, 22 May 2026 12:37:42 +0200 [thread overview]
Message-ID: <ahAxVwpUJES7NB8q@orome> (raw)
In-Reply-To: <20260331102303.33181-9-akhilrajeev@nvidia.com>
[-- Attachment #1: Type: text/plain, Size: 5591 bytes --]
On Tue, Mar 31, 2026 at 03:53:01PM +0530, Akhil R wrote:
> Use 'iommu-map', when provided, to get the stream ID to be programmed
> for each channel. Iterate over the channels registered and configure
> each channel device separately using of_dma_configure_id() to allow
> it to use a separate IOMMU domain for the transfer. However, do this
> in a second loop since the first loop populates the DMA device channels
> list and async_device_register() registers the channels. Both are
> prerequisites for using the channel device in the next loop.
>
> Channels will continue to use the same global stream ID if the
> 'iommu-map' property is not present in the device tree.
>
> Signed-off-by: Akhil R <akhilrajeev@nvidia.com>
> ---
> drivers/dma/tegra186-gpc-dma.c | 53 ++++++++++++++++++++++++++++------
> 1 file changed, 44 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/dma/tegra186-gpc-dma.c b/drivers/dma/tegra186-gpc-dma.c
> index 9bea2ffb3b9e..cd480d047204 100644
> --- a/drivers/dma/tegra186-gpc-dma.c
> +++ b/drivers/dma/tegra186-gpc-dma.c
> @@ -15,6 +15,7 @@
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/of_dma.h>
> +#include <linux/of_device.h>
> #include <linux/platform_device.h>
> #include <linux/reset.h>
> #include <linux/slab.h>
> @@ -1380,9 +1381,13 @@ static int tegra_dma_program_sid(struct tegra_dma_channel *tdc, int stream_id)
> static int tegra_dma_probe(struct platform_device *pdev)
> {
> const struct tegra_dma_chip_data *cdata = NULL;
> + struct tegra_dma_channel *tdc;
> + struct tegra_dma *tdma;
> + struct dma_chan *chan;
> + struct device *chdev;
> + bool use_iommu_map = false;
No use in initiazising this since you immediately assign to it the
return value of of_property_present() below.
> unsigned int i;
> u32 stream_id;
> - struct tegra_dma *tdma;
> int ret;
>
> cdata = of_device_get_match_data(&pdev->dev);
> @@ -1410,9 +1415,10 @@ static int tegra_dma_probe(struct platform_device *pdev)
>
> tdma->dma_dev.dev = &pdev->dev;
>
> - if (!tegra_dev_iommu_get_stream_id(&pdev->dev, &stream_id)) {
> - dev_err(&pdev->dev, "Missing iommu stream-id\n");
> - return -EINVAL;
> + use_iommu_map = of_property_present(pdev->dev.of_node, "iommu-map");
> + if (!use_iommu_map) {
> + if (!tegra_dev_iommu_get_stream_id(&pdev->dev, &stream_id))
> + return dev_err_probe(&pdev->dev, -EINVAL, "Missing iommu stream-id\n");
Looks like checkpatch.pl would complain about this being too long.
> }
>
> ret = device_property_read_u32(&pdev->dev, "dma-channel-mask",
> @@ -1424,9 +1430,10 @@ static int tegra_dma_probe(struct platform_device *pdev)
> tdma->chan_mask = TEGRA_GPCDMA_DEFAULT_CHANNEL_MASK;
> }
>
> + /* Initialize vchan for each channel and populate the channels list */
> INIT_LIST_HEAD(&tdma->dma_dev.channels);
> for (i = 0; i < cdata->nr_channels; i++) {
> - struct tegra_dma_channel *tdc = &tdma->channels[i];
> + tdc = &tdma->channels[i];
>
> /* Check for channel mask */
> if (!(tdma->chan_mask & BIT(i)))
> @@ -1446,10 +1453,6 @@ static int tegra_dma_probe(struct platform_device *pdev)
>
> vchan_init(&tdc->vc, &tdma->dma_dev);
> tdc->vc.desc_free = tegra_dma_desc_free;
> -
> - /* program stream-id for this channel */
> - tegra_dma_program_sid(tdc, stream_id);
> - tdc->stream_id = stream_id;
> }
>
> dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(cdata->addr_bits));
> @@ -1483,6 +1486,7 @@ static int tegra_dma_probe(struct platform_device *pdev)
> tdma->dma_dev.device_synchronize = tegra_dma_chan_synchronize;
> tdma->dma_dev.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
>
> + /* Register the DMA device and the channels */
> ret = dmaenginem_async_device_register(&tdma->dma_dev);
> if (ret < 0) {
> dev_err_probe(&pdev->dev, ret,
> @@ -1490,6 +1494,37 @@ static int tegra_dma_probe(struct platform_device *pdev)
> return ret;
> }
>
> + /*
> + * Configure stream ID for each channel from the channels registered
> + * above. This is done in a separate iteration to ensure that only
> + * the channels available and registered for the DMA device are used.
> + */
> + list_for_each_entry(chan, &tdma->dma_dev.channels, device_node) {
> + chdev = &chan->dev->device;
> + tdc = to_tegra_dma_chan(chan);
> +
> + if (use_iommu_map) {
> + chdev->bus = pdev->dev.bus;
> + dma_coerce_mask_and_coherent(chdev, DMA_BIT_MASK(cdata->addr_bits));
> +
> + ret = of_dma_configure_id(chdev, pdev->dev.of_node,
> + true, &tdc->id);
> + if (ret)
> + return dev_err_probe(chdev, ret,
> + "Failed to configure IOMMU for channel %d\n", tdc->id);
> +
> + if (!tegra_dev_iommu_get_stream_id(chdev, &stream_id))
> + return dev_err_probe(chdev, -EINVAL,
> + "Failed to get stream ID for channel %d\n", tdc->id);
There are also a few very long lines here. Make sure to run checkpatch
on these patches and remove all warnings. For dev_err_probe() some of
these might be okay. Otherwise, one alternative might be to reduce the
nesting here and push the inner "if" into a separate function.
Thierry
> +
> + chan->dev->chan_dma_dev = true;
> + }
> +
> + /* program stream-id for this channel */
> + tegra_dma_program_sid(tdc, stream_id);
> + tdc->stream_id = stream_id;
> + }
> +
> ret = devm_of_dma_controller_register(&pdev->dev, pdev->dev.of_node,
> tegra_dma_of_xlate, tdma);
> if (ret < 0) {
> --
> 2.50.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2026-05-22 10:37 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 10:22 [PATCH v6 00/10] Add GPCDMA support in Tegra264 Akhil R
2026-03-31 10:22 ` [PATCH v6 01/10] dt-bindings: dma: nvidia,tegra186-gpc-dma: Make reset optional Akhil R
2026-05-22 10:09 ` Thierry Reding
2026-03-31 10:22 ` [PATCH v6 02/10] arm64: tegra: Remove fallback compatible for GPCDMA Akhil R
2026-03-31 10:22 ` [PATCH v6 03/10] dt-bindings: dma: nvidia,tegra186-gpc-dma: Add iommu-map property Akhil R
2026-05-22 10:10 ` Thierry Reding
2026-03-31 10:22 ` [PATCH v6 04/10] dmaengine: tegra: Make reset control optional Akhil R
2026-05-22 10:11 ` Thierry Reding
2026-03-31 10:22 ` [PATCH v6 05/10] dmaengine: tegra: Use struct for register offsets Akhil R
2026-05-22 10:15 ` Thierry Reding
2026-03-31 10:22 ` [PATCH v6 06/10] dmaengine: tegra: Support address width > 39 bits Akhil R
2026-05-22 10:32 ` Thierry Reding
2026-03-31 10:23 ` [PATCH v6 07/10] dmaengine: tegra: Use managed DMA controller registration Akhil R
2026-05-22 10:33 ` Thierry Reding
2026-03-31 10:23 ` [PATCH v6 08/10] dmaengine: tegra: Use iommu-map for stream ID Akhil R
2026-03-31 14:12 ` Frank Li
2026-05-22 10:37 ` Thierry Reding [this message]
2026-03-31 10:23 ` [PATCH v6 09/10] dmaengine: tegra: Add Tegra264 support Akhil R
2026-05-22 10:38 ` Thierry Reding
2026-03-31 10:23 ` [PATCH v6 10/10] arm64: tegra: Enable GPCDMA in Tegra264 and add iommu-map Akhil R
2026-03-31 18:06 ` [PATCH v6 00/10] Add GPCDMA support in Tegra264 Jon Hunter
2026-04-10 8:09 ` Jon Hunter
2026-05-06 3:46 ` Akhil R
2026-05-21 10:07 ` Jon Hunter
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=ahAxVwpUJES7NB8q@orome \
--to=thierry.reding@gmail.com \
--cc=Frank.Li@kernel.org \
--cc=akhilrajeev@nvidia.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=jonathanh@nvidia.com \
--cc=krzk+dt@kernel.org \
--cc=ldewangan@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
--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