What Is Dma Mapping and Dma Engine in Context of Linux Kernel

What is the difference between DMA-Engine and DMA-Controller?

DMA - Direct memory access. The operation of your driver reading or writing from/to your HW memory without the CPU being involved in it (freeing it to do other stuff).

DMA Controller - reading and writing can't be done by magic. if the CPU doesn't do it, we need another HW to do it. Many years ago (at the time of ISA/EISA) it was common to use a shared HW on the motherboard that did this operation. In recent years , each HW has its own DMA HW mechanism.
But in all cases this specific HW gets the source address and the destination address and passes the data. Usually triggering an interrupt when done.

DMA Engine - Now here I am not sure what you mean. I believe you probably refer to the SW side that handles the DMA.
DMA is a little more complicated than usual I\O since all memory SRC and DST has to be physically present at all times during the DMA operation. If the DST address is swapped to disk, the HW will write to a bad address and the system will crash.
This and other aspects of DMA are handled by the driver with code sections you probably refer to as the "DMA Engine"

*Another interpretation of what 'DMA Engine' is, may be a code part of Firmware (or HW) that handles the DMA HW controller on the HW side.

What is the difference between DMA and IOMMU?

DMA (direct memory access) is a hardware feature that allows memory access to occur independently of the program currently run by the micro processor. It can either be used by I/O devices to directly read from or write to memory without executing any micro processor instructions. Or, it can be used to efficiently copy blocks of memory. During DMA transfers, the micro processor can execute an unrelated program at the same time.

IOMMU (input–output memory management unit) is a hardware feature that extends MMU to I/O devices. A MMU maps virtual memory addresses to physical memory address. While the normal MMU is used to give each process its own virtual address space, the IOMMU is used to give each I/O device its own virtual address space. That way, the I/O device sees a simple contiguous address space, possibly accessible with 32 bit addresses while in reality the physical address space is fragmented and extends beyond 32 bit.

DMA without IOMMU requires the I/O devices to use the real physical addresses. The physical addresses must also be used by the processor when setting up the DMA transfer. Additionall, DMA without IOMMU can be used for memory copy (as it involves no I/O devices).

IOMMU is only available on more powerful micro processor. You will not find it on microcontrollers and most embedded systems.

How to do a single dma transaction in kernel?

What is a DMA transfer?

DMA is the hardware mechanism that allows peripheral components to transfer their I/O data directly to and from main memory without the need to involve the system processor. Use of this mechanism can greatly increase throughput to and from a device, because a great deal of computational overhead is eliminated from the main CPU.

...the use of dma_alloc_coherent() is done as if it actually responsible for the transaction.

On the contrary, dma_alloc_coherent() simply creates a buffer that is acceptable to the dma controller i.e. reserves a region in main memory (usually contiguous) that can be shared between the CPU and the DMA controller.

For example to perform a DMA-write, the CPU can populate this buffer and instruct the DMA controller to write it to the device and once it is done, invoke the callback function (to notify the SW running on the CPU).

In the meantime, the CPU can continue performing other unrelated tasks that do not depend on the data being transferred at the same time when the data transfer to the external device is being handled by the DMA controller in parallel.

Similarly, to perform a DMA-read, the CPU simply passes a buffer obtained by calling dma_allocate_coherent()to the DMA controller and instructs it to perform a read. Subsequently the DMA controller reads the external device and starts filling the provided buffer and invokes the callback function once the buffer is filled (or half-filled or after a certain time interval as configured.)


Further Reading:

Chapter 15 of LDD3 - "mmap and DMA".

Article on DMA APIs in the Linux kernel.


In general this depends on the DMA controller.
i.e. the APIs the DMA controller driver provides.

dma-engine is a standard framework in the Linux kernel used by several DMA providers.

Related: What is DMA mapping and DMA engine in context of linux kernel?


In the case of dma-engine :

Is there a callback when it is finished?

Populate the callback pointer in the descriptor obtained from dmaengine_prep_slave_sg()

How to trigger the dma transaction to start?

Use dma_async_issue_pending() and pass the initialised descriptor.


For more details refer to the dma-engine client documentation.

Rx descriptor dma mapping in device driver what that actually means, Does it mean mapping of packets at physical NIC to struct object in memory

DMA accesses are translated by the IOMMU, which on Intel systems is described in the Intel® Virtualization Technology for Directed I/O (VT-d) specification.

The function dma_alloc_coherent allocates memory and introduces a mapping into the DMA page tables so that the memory is accessible to the device. The address returned is not the virtual or physical address of the memory, but is a I/O virtual address (IOVA), which the device can use to access memory. The IOVA is translated by the IOMMU into the physical memory address when the device performs DMA.

The IOMMU prevents any device from accessing physical memory that hasn't been mapped into that specific device's I/O address space.

What is the difference between DMA and memory-mapped IO?

Memory-mapped I/O allows the CPU to control hardware by reading and writing specific memory addresses. Usually, this would be used for low-bandwidth operations such as changing control bits.

DMA allows hardware to directly read and write memory without involving the CPU. Usually, this would be used for high-bandwidth operations such as disk I/O or camera video input.

Here is a paper has a thorough comparison between MMIO and DMA.

Design Guidelines for High Performance RDMA Systems



Related Topics



Leave a reply



Submit