Skip to contentSkip to conversation

i2c: use dmaengine_get_dma_device() instead of chan->device->dev

PATCH Superseded [email protected] 2 participants 2 messages Nov 3 – Nov 4

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: use dmaengine_get_dma_device() instead of chan->device->dev

From: Frank Li <[email protected]>

Replace direct dma_chan::device::dev access with the proper dmaengine_get_dma_device() for consumer API.

chan->device->dev is not always the device used for DMA mapping. Some DMA engines support per-channel IOMMU mappings, so different channels may use different DMA devices. dmaengine_get_dma_device() returns the correct device for each channel.

This also prepares for making the DMA engine provider data structures private. DMA consumers should not access DMA engine internals directly.

---
 drivers/i2c/busses/i2c-rcar.c      | 6 +++---
 drivers/i2c/busses/i2c-sh_mobile.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-rcar.c +3 -3
index 755064804cb21..86b1df3a56c4d 100644
@@ -455,7 +455,7 @@ static void rcar_i2c_cleanup_dma(struct rcar_i2c_priv *priv, bool terminate)
 	if (terminate)
 		dmaengine_terminate_sync(chan);
 
-	dma_unmap_single(chan->device->dev, sg_dma_address(&priv->sg),
+	dma_unmap_single(dmaengine_get_dma_device(chan), sg_dma_address(&priv->sg),
 			 sg_dma_len(&priv->sg), priv->dma_direction);
 
 	/* Gen3+ can only do one RXDMA per transfer and we just completed it */
@@ -511,8 +511,8 @@ static bool rcar_i2c_dma(struct rcar_i2c_priv *priv)
 		len = priv->msg->len - 1;
 	}
 
-	dma_addr = dma_map_single(chan->device->dev, buf, len, dir);
-	if (dma_mapping_error(chan->device->dev, dma_addr)) {
+	dma_addr = dma_map_single(dmaengine_get_dma_device(chan), buf, len, dir);
+	if (dma_mapping_error(dmaengine_get_dma_device(chan), dma_addr)) {
 		dev_dbg(dev, "dma map failed, using PIO\n");
 		return false;
 	}
drivers/i2c/busses/i2c-sh_mobile.c +3 -3
index 3a55f803e4f15..023813c2f7809 100644
@@ -452,7 +452,7 @@ static void sh_mobile_i2c_cleanup_dma(struct sh_mobile_i2c_data *pd, bool termin
 	if (terminate)
 		dmaengine_terminate_sync(chan);
 
-	dma_unmap_single(chan->device->dev, sg_dma_address(&pd->sg),
+	dma_unmap_single(dmaengine_get_dma_device(chan), sg_dma_address(&pd->sg),
 			 pd->msg->len, pd->dma_direction);
 
 	pd->dma_direction = DMA_NONE;
@@ -526,8 +526,8 @@ static void sh_mobile_i2c_xfer_dma(struct sh_mobile_i2c_data *pd)
 	if (IS_ERR(chan))
 		return;
 
-	dma_addr = dma_map_single(chan->device->dev, pd->dma_buf, pd->msg->len, dir);
-	if (dma_mapping_error(chan->device->dev, dma_addr)) {
+	dma_addr = dma_map_single(dmaengine_get_dma_device(chan), pd->dma_buf, pd->msg->len, dir);
+	if (dma_mapping_error(dmaengine_get_dma_device(chan), dma_addr)) {
 		dev_dbg(pd->dev, "dma map failed, using PIO\n");
 		return;
 	}
Signature · 1 line
2.43.0
maintainer
#1 lore raw

Hi Frank,

Quoted 5 lines · On Tue, Nov 03, 2026 at 04:26:54PM -0500, [email protected] wrote:

From: Frank Li <[email protected]>

Replace direct dma_chan::device::dev access with the proper dmaengine_get_dma_device() for consumer API.

Quoted 7 lines

chan->device->dev is not always the device used for DMA mapping. Some DMA engines support per-channel IOMMU mappings, so different channels may use different DMA devices. dmaengine_get_dma_device() returns the correct device for each channel.

This also prepares for making the DMA engine provider data structures private. DMA consumers should not access DMA engine internals directly.

Thanks for this, looks useful.

drivers/i2c/busses/i2c-rcar.c static bool rcar_i2c_dma(struct rcar_i2c_priv *priv) · line 516

Quoted 5 lines
drivers/i2c/busses/i2c-rcar.c +2 -2
-	dma_addr = dma_map_single(chan->device->dev, buf, len, dir);
-	if (dma_mapping_error(chan->device->dev, dma_addr)) {
+	dma_addr = dma_map_single(dmaengine_get_dma_device(chan), buf, len, dir);
+	if (dma_mapping_error(dmaengine_get_dma_device(chan), dma_addr)) {
 		dev_dbg(dev, "dma map failed, using PIO\n");

I think we should populate a dma_dev-variable here and reuse it instead of calling dmaengine_get_dma_device() twice.

Happy hacking,

Wolfram