如何通过DMA将数据从RAM传输到RAM?

时间:2021-12-31 13:48:00

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.

我想编写一个内核模块,它可以通过DMA将数据从RAM传输到RAM。有一些帖子讨论这个问题,但我不太明白。有人说可能有人说它不是。

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.

如果我理解ldd3的正确,RAM对RAM的复制不可能使用linux的DMA API,但是驱动/ DMA /dmaengine。c为“DMA传输类型”提供了一个标记DMA_MEMCPY,因此应该有一个方法。

Is this correct, can I use a dma engine to transfer data from one ram address to another?

我是否可以使用dma引擎将数据从一个ram地址传输到另一个ram地址?

If it is hardware dependent, how can I determine if my system supports dma memcpy?

如果它与硬件有关,我如何确定我的系统是否支持dma memcpy?

1 个解决方案

#1


2  

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:

正如您正确地指出的,应该使用DMA_MEMCPY执行ram到ram的复制。它在文档/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 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_device结构有一个名为cap_mask的字段,该字段保存所支持的各种类型的事务,您需要使用dma_cap_set函数修改该掩码,根据您支持的事务类型使用不同的标志作为参数。

All those capabilities are defined in the dma_transaction_type enum, in include/linux/dmaengine.h

所有这些功能都在dma_transaction_type枚举中定义,包括/linux/dmaengine.h

Currently, the types available are:

目前可用的类型有:

  • DMA_MEMCPY
    • The device is able to do memory to memory copies
    • 该设备能够对内存进行复制
  • 设备能够对内存进行拷贝

Just to summarize:

总结:

  • It depends on your DMA controller. Some are able to do RAM-to-RAM transaction, some aren't.

    这取决于你的DMA控制器。有些能够执行ramto - ram事务,有些则不能。

  • For example, for OMAP-based SoCs, DMA controller does this (drivers/dma/omap-dma.c file, in omap_dma_probe() function):

    例如,对于基于omap的SoCs, DMA控制器可以做到这一点(驱动程序/ DMA /omap-dma)。c文件,在omap_dma_probe()函数中):

    dma_cap_set(DMA_MEMCPY, od->ddev.cap_mask);
    
  • 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, in dmatest_add_channel() function:

    通过这种方式,您可以稍后在驱动程序中检查它(如果您的DMA控制器能够执行ram事务)。看看它是如何在驱动/dma/dmatest中实现的。c,在dmatest_add_channel()函数:

    if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
    

If you need an example on how to use DMA API to perform RAM-to-RAM transaction, please see drivers/dma/dmatest.c.

如果您需要关于如何使用DMA API执行ramto - ram事务的示例,请参见驱动程序/ DMA /dmat .c。

#1


2  

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:

正如您正确地指出的,应该使用DMA_MEMCPY执行ram到ram的复制。它在文档/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 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_device结构有一个名为cap_mask的字段,该字段保存所支持的各种类型的事务,您需要使用dma_cap_set函数修改该掩码,根据您支持的事务类型使用不同的标志作为参数。

All those capabilities are defined in the dma_transaction_type enum, in include/linux/dmaengine.h

所有这些功能都在dma_transaction_type枚举中定义,包括/linux/dmaengine.h

Currently, the types available are:

目前可用的类型有:

  • DMA_MEMCPY
    • The device is able to do memory to memory copies
    • 该设备能够对内存进行复制
  • 设备能够对内存进行拷贝

Just to summarize:

总结:

  • It depends on your DMA controller. Some are able to do RAM-to-RAM transaction, some aren't.

    这取决于你的DMA控制器。有些能够执行ramto - ram事务,有些则不能。

  • For example, for OMAP-based SoCs, DMA controller does this (drivers/dma/omap-dma.c file, in omap_dma_probe() function):

    例如,对于基于omap的SoCs, DMA控制器可以做到这一点(驱动程序/ DMA /omap-dma)。c文件,在omap_dma_probe()函数中):

    dma_cap_set(DMA_MEMCPY, od->ddev.cap_mask);
    
  • 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, in dmatest_add_channel() function:

    通过这种方式,您可以稍后在驱动程序中检查它(如果您的DMA控制器能够执行ram事务)。看看它是如何在驱动/dma/dmatest中实现的。c,在dmatest_add_channel()函数:

    if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
    

If you need an example on how to use DMA API to perform RAM-to-RAM transaction, please see drivers/dma/dmatest.c.

如果您需要关于如何使用DMA API执行ramto - ram事务的示例,请参见驱动程序/ DMA /dmat .c。