Zephyr ZDMA Driver Implementation

This page provides details on the implementation of the ZDMA Zephyr driver.

DMA Driver API

Similar to the dmaengine framework in Linux, Zephyr uses the dma driver api as an interface for managing DMA operations across various hardware implementations. This API lets the driver request channels, configure transfers, and manage the state of those transfers. It abstracts the underlying hardware specifics enabling compatibility with different devices.

Zephyr ZDMA driver stack (raw): the application talks directly to the DMA driver API, which talks to the underlying ZDMA driver.

Zephyr ZDMA driver stack.

Probe Data From Node

The driver assigns a device tree compatible string to DT_DRV_COMPAT. If a node has that compatible string and status okay, Zephyr registers the driver with the DMA subsystem.

DT_DRV_COMPAT

  • This macro holds the compatible string of the driver

  • The driver sets it to xlnx_zynqmp_dma_1_0 or amd_versal2_dma_1_0, depending on which compatible has a node with status okay. The same choice selects the register layout at compile time.

DT_INST_FOREACH_STATUS_OKAY

  • This macro calls “XILINX_ADMA_INIT(n)” on all node with compatible “DT_DRV_COMPAT” and status okay

  • For each instance, XILINX_ADMA_INIT(n) defines a static descriptor pool (SYS_MEM_BLOCKS_DEFINE_STATIC) of CONFIG_DMA_XILINX_ADMA_SG_BUFFER_COUNT entries, an interrupt configure function that calls IRQ_CONNECT, and the config and data structures.

DEVICE_DT_INST_DEFINE

  • This macro defines a device structure that is automatically configured by kernel during system init.

  • The kernel calls dma_xilinx_adma_init during system initialization. It maps the register space, enables the clk_apb and clk_main clocks, and connects the interrupt.

  • DEVICE_DT_NAME(n) supplies the device name.

  • dma_xilinx_adma##n##_data supplies the device data address.

  • dma_xilinx_adma##n##_config supplies the device config address.

  • POST_KERNEL defines the device initialization level.

  • CONFIG_DMA_INIT_PRIORITY device priority within the device initialization level.

  • dma_xilinx_adma_driver_api registers the config, start, stop, and get_status functions with the DMA subsystem.

DEVICE_DT_NAME(n)

  • This macro returns a string name for a device tree node.

DEVICE_MMIO_ROM_INIT(DT_DRV_INST(n))

  • This macro stores the instance register block address and size from the device tree. DEVICE_MMIO_MAP maps it as uncached memory during initialization, and DEVICE_MMIO_GET returns the mapped address.

DT_INST_PROP(n, Property)

  • This macro returns node property value

  • The driver uses DT_INST_PROP(n, dma_coherent) to read the dma-coherent property.

Clock Controller

DT_INST_CLOCKS_CTLR_BY_IDX(n, idx)

  • This macro returns the clock controller node at index idx of the clocks property. Index 0 is the main clock and index 1 is the APB clock.

Note

A state-machine diagram for the ZDMA driver is not currently included in this build. The states described in the surrounding text fully cover the same flow.

Driver in Zephyr

  • Driver Source file

  • Kconfig file

  • Device Tree bindings file

Place the driver in drivers/dma/

Driver Source File

A source file contains the implementation of the driver.

dma_xilinx_adma.c

The public header include/zephyr/drivers/dma/dma_xilinx_adma.h defines XILINX_ADMA_DIR_WRITE_ONLY, the channel direction value used to request Write Only mode.

Kconfig File

Kconfig controls Zephyr’s build-time configuration. Each Kconfig file contains configuration symbols (options). These options specify the configuration and define dependencies between symbols. Menus and submenus organize symbols in the interactive configuration interface. For more information, see https://docs.zephyrproject.org/latest/build/kconfig/index.html

Kconfig.xilinx_adma

  • CONFIG_DMA_XILINX_ADMA: enables the driver.

  • CONFIG_DMA_XILINX_ADMA_SG_BUFFER_COUNT: number of scatter gather descriptors per channel (1 to 32, default 32).

  • CONFIG_DMA_XILINX_ADMA_DESC_POOL_ALIGNMENT: descriptor pool alignment in bytes (default 64).

Kconfig produces the autoconf.h header with macros for build-time checks. The build can omit code for unused features to save space.

Device Tree Binding File

Binding files declare and describe the device-specific requirements for the device tree. A Zephyr DT binding is a YAML file that marks properties as required or optional for that driver. Zephyr has its own format for the YAML files. It does not use the dt-schema tools used by the Linux kernel. For more information, see the Zephyr DT bindings documentation.

xlnx,zynqmp-dma-1.0.yaml and amd,versal2-dma-1.0.yaml (the latter includes the former).