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

标签 linux linux-kernel dma

我想编写一个内核模块,可以通过 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 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.

All those capabilities are defined in the dma_transaction_type enum, in include/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/

相关文章:

c - 在父进程终止时向子进程树发出 SIGKILL

linux - 在与 nohup 兼容的 shell 脚本中替代 ls

Linux 内核模块,创建后进先出设备

linux-kernel - mwait x86 指令不等待 DMA

c - strstr() 不适用于 C

Linux 时间命令——真实 vs 用户 vs 系统

Linux - 当优先级较高的任务繁忙时,不会安排优先级较低的线程

linux - 如何使用 DMA 在一个线程中同时写入不同磁盘上的多个文件?

windows - 有什么方法可以在 Vista x64 上分配 4GB 以上的物理内存吗?

linux - WKHTMLTOPDF 在 Ubuntu 上安装错误