我想编写一个内核模块,可以通过 DMA 在 RAM 之间传输数据。有一些帖子讨论了这个问题,但我不太明白。有人说有可能,有人说不可能。
如果我对 ldd3 的理解正确,那么使用 linux 的 DMA API 不可能实现 RAM 到 RAM 的复制,但是 driver/dma/dmaengine.c 为“DMA 传输类型”提供了一个标志 DMA_MEMCPY ”,所以应该有办法。
这是正确的吗?我可以使用 DMA 引擎将数据从一个 RAM 地址传输到另一个吗?
如果与硬件相关,我如何确定我的系统是否支持 dma memcpy?
最佳答案
正如您正确指出的那样,应该使用DMA_MEMCPY
来执行RAM到RAM的复制。它在 Documentation/dmaengine/provider.txt 中有描述。 。这里只是相关摘录,请查看整个文件以了解更多详细信息:
Supported transaction types
The next thing you need is to set which transaction types your device (and driver) supports.
Our
dma_device
structure has a field calledcap_mask
that holds the various types of transaction supported, and you need to modify this mask using thedma_cap_set
function, with various flags depending on transaction types you support as an argument.All those capabilities are defined in the
dma_transaction_type
enum, ininclude/linux/dmaengine.h
Currently, the types available are:
DMA_MEMCPY
- The device is able to do memory to memory copies
总结一下:
这取决于您的 DMA Controller 。有些能够进行 RAM 到 RAM 的事务,有些则不能。
例如,对于基于 OMAP 的 SoC,DMA Controller 会执行此操作(
drivers/dma/omap-dma.c
文件,在omap_dma_probe()
函数中):dma_cap_set(DMA_MEMCPY, od->ddev.cap_mask);
这样您以后就可以在驱动程序中检查它(如果您的 DMA Controller 能够进行 RAM 到 RAM 事务)。查看
drivers/dma/dmatest.c
中的dmatest_add_channel()
函数是如何完成的:if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
如果您需要有关如何使用 DMA API 执行 RAM 到 RAM 事务的示例,请参阅 drivers/dma/dmatest.c .
关于linux - 如何通过DMA从RAM到RAM传输数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37766230/