linuxlinux-kerneldma

How to transfer data via DMA from RAM to 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.

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.

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

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


Solution

  • 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.

    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

    Just to summarize:

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