如何通过DMA从RAM到RAM传输数据? [英] How to transfer data via DMA from RAM to RAM?
问题描述
我想编写一个内核模块,该模块可以通过DMA从RAM到RAM传输数据.有一些讨论这个问题的帖子,但是我真的不明白.有人说可能别人说不是.
I want to write a kernel module that can transfer data via DMA from RAM to RAM. There are some posts that discuss this, but I don't really get it. Some say it is possible others say it isn’t.
如果我对ldd3的理解正确,那么使用Linux的DMA API无法将RAM复制到RAM,但是 driver/dma/dmaengine.c 为"DMA传输类型"提供了标志DMA_MEMCPY ,所以应该有办法.
If I understood ldd3 right, RAM to RAM copying isn‘t possible with the DMA API of linux, but the driver/dma/dmaengine.c provides a flag DMA_MEMCPY for a "DMA Transfer Type", so there should be a way.
这是正确的吗,我可以使用dma引擎将数据从一个ram地址传输到另一个ram地址吗?
Is this correct, can I use a dma engine to transfer data from one ram address to another?
如果取决于硬件,如何确定我的系统是否支持dma memcpy?
If it is hardware dependent, how can I determine if my system supports dma memcpy?
推荐答案
正如您正确指出的那样,应使用DMA_MEMCPY
执行RAM到RAM的复制.在 Documentation/dmaengine/provider.txt 中进行了描述. .这只是一个相关摘录,请查看整个文件以了解更多详细信息:
As you correctly pointed out, DMA_MEMCPY
should be used to perform RAM-to-RAM copy. It is described in Documentation/dmaengine/provider.txt. Here is just a related excerpt, please see the whole file for more details:
支持的交易类型
下一步,您需要设置设备的交易类型 (和驱动程序)支持.
Supported transaction types
The next thing you need is to set which transaction types your device (and driver) supports.
我们的dma_device
结构具有一个名为cap_mask
的字段,其中包含
支持各种类型的交易,您需要对此进行修改
使用dma_cap_set
功能的蒙版,取决于
您支持作为参数的交易类型.
Our dma_device
structure has a field called cap_mask
that holds the
various types of transaction supported, and you need to modify this
mask using the dma_cap_set
function, with various flags depending on
transaction types you support as an argument.
所有这些功能都在dma_transaction_type
枚举中定义,
在include/linux/dmaengine.h
All those capabilities are defined in the dma_transaction_type
enum,
in include/linux/dmaengine.h
当前,可用的类型为:
-
DMA_MEMCPY
- 该设备能够执行内存到内存副本
DMA_MEMCPY
- The device is able to do memory to memory copies
总结一下:
-
这取决于您的DMA控制器.有些可以做到RAM到RAM的事务,有些则不能.
It depends on your DMA controller. Some are able to do RAM-to-RAM transaction, some aren't.
例如,对于基于OMAP的SoC,DMA控制器执行此操作(
drivers/dma/omap-dma.c
文件,在omap_dma_probe()
函数中):For example, for OMAP-based SoCs, DMA controller does this (
drivers/dma/omap-dma.c
file, inomap_dma_probe()
function):dma_cap_set(DMA_MEMCPY, od->ddev.cap_mask);
-
这样,您以后便可以在驱动程序中对其进行检查(如果DMA控制器能够进行RAM到RAM的事务).在
dmatest_add_channel()
函数的drivers/dma/dmatest.c
中查看其操作方式: This way you can later check it (if your DMA controller is capable of RAM-to-RAM transactions) in your driver. See how it's done in
drivers/dma/dmatest.c
, indmatest_add_channel()
function:if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
如果您需要有关如何使用DMA API执行RAM到RAM事务的示例,请参见
If you need an example on how to use DMA API to perform RAM-to-RAM transaction, please see drivers/dma/dmatest.c.
这篇关于如何通过DMA从RAM到RAM传输数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!