Panel For Example Panel For Example Panel For Example

Linux DMA Subsystem Driver Development

Author : Adrian September 16, 2025

1. Overview

DMA (Direct Memory Access) is a hardware component that can access system memory independently of the CPU. Its main function is to move memory data without involving the CPU cores.

Some CPUs expose a general-purpose DMA controller for use by various peripherals. Low-speed embedded peripherals that lack built-in DMA can use such a general DMA controller for efficient data transfer.

Many high-speed peripherals implement their own DMA engines to meet performance requirements.

For general-purpose DMA controllers, the Linux kernel provides a unified DMA driver framework known as the DMA subsystem.

2. DMA types

DMA can be classified from different perspectives.

2.1 DMA mapping types

  • Coherent DMA
  • Streaming DMA

2.2 DMA operating modes

  • Block DMA
  • Scatter-Gather DMA

The main difference between these operating modes is the address format presented to the DMA hardware. Block DMA typically requires an address register and a data length register in the peripheral registers. Scatter-Gather DMA uses a descriptor table, where each entry specifies an address and length; the hardware needs only a base address register for the descriptor table.

3. Linux DMA subsystem

3.1 DMA subsystem framework

The DMA subsystem is relatively lightweight. The blue part in the diagram below outlines the kernel components related to DMA.

The Linux DMA subsystem consists mainly of five parts:

  • dmaengine: the core of the DMA subsystem; provides APIs for DMA device drivers to register DMA controllers and offers a unified interface for DMA clients to hide device-specific details.
  • virt-dma: provides support for virtual DMA channels.
  • of-dma: provides device tree parsing support for passing DMA information into the subsystem.
  • DMA device driver: the driver implementation for a specific DMA controller.
  • dmatest: a test module that exercises DMA memcpy, memset, XOR, and RAID6 P+Q operations across various lengths and offsets between source and destination buffers.

3.2 Important APIs in the DMA subsystem

The following summarizes key APIs exposed to DMA clients and controller drivers. The dma-mapping API is not covered here.

3.2.1 Registration APIs

  • dma_async_device_register - register a DMA controller driver with the DMA subsystem.
  • dma_async_device_unregister - unregister a DMA controller driver from the DMA subsystem.

3.2.2 DMA client (device driver) APIs

  • dma_request_chan - find and return a DMA channel associated with a device by name; association is typically described via device tree.
  • dmaengine_slave_config - pass slave configuration parameters to the DMA driver; parameters are provided via struct dma_slave_config.
  • dmaengine_prep_slave_sg - prepare a scatterlist for data transfer; the scatterlist must be mapped and must not be freed until the DMA operation completes.
  • dmaengine_submit - submit a prepared descriptor to the pending queue.
  • dma_async_issue_pending - issue pending transactions in the queue. Once a transaction completes, the next pending transaction starts; if a completion callback is set, it will be invoked.