Skip to contentSkip to conversation

dmaengine: add dmaengine_get_provider_device() API

PATCH Applied [email protected] 2 participants 2 messages Oct 2 – Oct 9

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: add dmaengine_get_provider_device() API

From: Frank Li <[email protected]>

Add dmaengine_get_provider_device() API and kernel doc for dmaengine_get_dma_device() to describe the difference.

dmaengine_get_dma_device() is used for DMA mapping because some DMA engines provide per-channel iommu mapping.

dmaengine_get_provider_device() is used to find a DMA engine channel by a filter function.

In most cases they return the same value, but they have different semantic meanings.

---
Prepare make dma_device private after all driver change to use new APIs.

---
 include/linux/dma/imx-dma.h |  6 ++++--
 include/linux/dmaengine.h   | 21 ++++++++++++++++++++-
 2 files changed, 24 insertions(+), 3 deletions(-)
include/linux/dma/imx-dma.h +4 -2
index 16e491f63883c..7c678316b7578 100644
@@ -59,8 +59,10 @@ struct imx_dma_data {
 
 static inline int imx_dma_is_general_purpose(struct dma_chan *chan)
 {
-	return !strcmp(chan->device->dev->driver->name, "imx-sdma") ||
-		!strcmp(chan->device->dev->driver->name, "imx-dma");
+	struct device *dev = dmaengine_get_provider_device(chan);
+
+	return !strcmp(dev->driver->name, "imx-sdma") ||
+		!strcmp(dev->driver->name, "imx-dma");
 }
 
 /**
include/linux/dmaengine.h +20 -1
index 1b57bc4a7e72a..f9918a42473f5 100644
@@ -1807,12 +1807,31 @@ static inline struct device *dmaengine_chan_dev(struct dma_chan *chan)
 	return &chan->chan_dev->device;
 }
 
+/*
+ * dmaengine_get_provider_device() - Get DMA engine provider device. Typical
+ *				     use is to find a DMA channel by filter.
+ * @chan: DMA channel
+ *
+ * Return: Pointer to the DMA engine provider device.
+ */
+static inline struct device *dmaengine_get_provider_device(struct dma_chan *chan)
+{
+	return chan->device->dev;
+}
+
+/*
+ * dmaengine_get_dma_device() - Get DMA device used for DMA mapping. Some
+ *				DMA engines provide per-channel iommu mapping.
+ * @chan: DMA channel
+ *
+ * Return: Pointer to the device used for DMA mapping.
+ */
 static inline struct device *dmaengine_get_dma_device(struct dma_chan *chan)
 {
 	if (chan->chan_dev->chan_dma_dev)
 		return dmaengine_chan_dev(chan);
 
-	return chan->device->dev;
+	return dmaengine_get_provider_device(chan);
 }
 
 #endif /* DMAENGINE_H */
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 10 lines · On Fri, 02 Oct 2026 16:23:40 -0400, [email protected] wrote:

Add dmaengine_get_provider_device() API and kernel doc for dmaengine_get_dma_device() to describe the difference.

dmaengine_get_dma_device() is used for DMA mapping because some DMA engines provide per-channel iommu mapping.

dmaengine_get_provider_device() is used to find a DMA engine channel by a filter function.

[...]

Applied, thanks!

[1/1] dmaengine: add dmaengine_get_provider_device() API

      commit: 61527d7e6998e87b3acd04f1cd2f4d6814385051

Best regards,

Signature · 1 line
~Vinod