* Should dma_map_single take the dma controller or its consumer as an argument?
@ 2023-06-28 10:57 Li Chen
2023-06-28 11:02 ` Russell King (Oracle)
0 siblings, 1 reply; 3+ messages in thread
From: Li Chen @ 2023-06-28 10:57 UTC (permalink / raw)
To: dmaengine, linux-arm-kernel, linux-kernel; +Cc: Arnd Bergmann
Hi all,
I recently encountered an issue where the dma_mask was set in the DMA controller's driver, but the consumer peripheral driver didn't set its own dma_mask.
If I utilize APIs such as dma_map_single or dma_alloc_coherent and pass a DMA controller as the argument, such as dma_map_single(dma_chan->device->dev, ...), the dma_mask is respected and there would be no issues. I also saw there are some user cases in the kernel:
```
# rg "dma_map_single.*chan"
drivers/i2c/busses/i2c-sh_mobile.c
536: dma_addr = dma_map_single(chan->device->dev, pd->dma_buf, pd->msg->len, dir);
drivers/i2c/busses/i2c-imx.c
399: dma->dma_buf = dma_map_single(chan_dev, msgs->buf,
drivers/i2c/busses/i2c-stm32.c
121: dma->dma_buf = dma_map_single(chan_dev, buf, dma->dma_len,
drivers/i2c/busses/i2c-rcar.c
443: dma_addr = dma_map_single(chan->device->dev, buf, len, dir);
drivers/net/ethernet/ti/davinci_cpdma.c
1049: buffer = dma_map_single(ctlr->dev, si->data_virt, len, chan->dir);
drivers/tty/serial/ambarella_uart.c
826: dma_phys = dma_map_single(dma_chan->device->dev,
836: dma_phys = dma_map_single(dma_chan->device->dev,
drivers/tty/serial/samsung_tty.c
1105: dma->rx_addr = dma_map_single(dma->rx_chan->device->dev, dma->rx_buf,
1114: dma->tx_addr = dma_map_single(dma->tx_chan->device->dev,
drivers/tty/serial/8250/8250_dma.c
253: dma->tx_addr = dma_map_single(dma->txchan->device->dev,
drivers/tty/serial/sh-sci.c
1600: s->tx_dma_addr = dma_map_single(chan->device->dev,
drivers/mtd/hyperbus/hbmc-am654.c
87: dma_dst = dma_map_single(rx_chan->device->dev, to, len, DMA_FROM_DEVICE);
drivers/mtd/nand/raw/intel-nand-controller.c
314: buf_dma = dma_map_single(chan->device->dev, (void *)buf, len, dir);
drivers/mtd/nand/raw/sh_flctl.c
398: dma_addr = dma_map_single(chan->device->dev, buf, len, dir);
...
```
However, if I pass the consumer peripheral's struct device to dma_map_single, the dma_mask would not be respected because the peripheral driver doesn't set it, which would lead to unexpected outcomes. For instance, even if the DMA controller is capable of handling 64-bit operations, it would still use SWIOTLB, which is really unnecessary.
So my question is which device should be dma_map_single's first argument? DMA controller or the consumer peripheral itself?
I know I could also set dma_mask in my peripheral driver, just the same as the DMA controller did, but I want to learn the best practice.
Thanks in advanced.
Regards,
Li
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Should dma_map_single take the dma controller or its consumer as an argument?
2023-06-28 10:57 Should dma_map_single take the dma controller or its consumer as an argument? Li Chen
@ 2023-06-28 11:02 ` Russell King (Oracle)
2023-06-28 11:16 ` Li Chen
0 siblings, 1 reply; 3+ messages in thread
From: Russell King (Oracle) @ 2023-06-28 11:02 UTC (permalink / raw)
To: Li Chen; +Cc: dmaengine, linux-arm-kernel, linux-kernel, Arnd Bergmann
On Wed, Jun 28, 2023 at 06:57:35PM +0800, Li Chen wrote:
> Hi all,
>
> I recently encountered an issue where the dma_mask was set in the DMA controller's driver, but the consumer peripheral driver didn't set its own dma_mask.
It should always take the device that is *actually* performing the DMA,
since that is the device that has restrictions on what addresses can be
accessed, etc.
Devices that "consume" the data from a DMA controller don't access
memory - they are merely the targets, and they can't on their own access
host memory. Therefore, their dma mask _should_ be irrelevant.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Should dma_map_single take the dma controller or its consumer as an argument?
2023-06-28 11:02 ` Russell King (Oracle)
@ 2023-06-28 11:16 ` Li Chen
0 siblings, 0 replies; 3+ messages in thread
From: Li Chen @ 2023-06-28 11:16 UTC (permalink / raw)
To: Russell King (Oracle)
Cc: dmaengine, linux-arm-kernel, linux-kernel, Arnd Bergmann
Hi Russell,
---- On Wed, 28 Jun 2023 19:02:47 +0800 Russell King (Oracle) wrote ---
> On Wed, Jun 28, 2023 at 06:57:35PM +0800, Li Chen wrote:
> > Hi all,
> >
> > I recently encountered an issue where the dma_mask was set in the DMA controller's driver, but the consumer peripheral driver didn't set its own dma_mask.
>
> It should always take the device that is *actually* performing the DMA,
> since that is the device that has restrictions on what addresses can be
> accessed, etc.
>
> Devices that "consume" the data from a DMA controller don't access
> memory - they are merely the targets, and they can't on their own access
> host memory. Therefore, their dma mask _should_ be irrelevant.
Thanks for your quick response. Therefore, I just need to use chan->device->dev in my dma_map_single and there is no need to configure the dma_mask for my consumer peripherals.
Regards,
Li
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-28 11:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-28 10:57 Should dma_map_single take the dma controller or its consumer as an argument? Li Chen
2023-06-28 11:02 ` Russell King (Oracle)
2023-06-28 11:16 ` Li Chen
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).