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

In driver we need to assign the compatible string to a zephyr macro, DT_DRV_COMPAT. If the assigned string matched with any one of the DT nodes along with status property okay then driver need to register the driver API to the dma interface.

DT_DRV_COMPAT

  • This macro holds the compatible string of the driver

DT_INST_FOREACH_STATUS_OKAY

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

DEVICE_DT_INST_DEFINE

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

  • amd_zdma_init API is run by the kernel during system initialization.

  • device→name is set by “DEVICE_DT_NAME(n)” macro.

  • device→data is set with data##n variable address.

  • device→config is set with amd_zdma_inst_##n variable address.

  • POST_KERNEL defines the device initialization level.

  • CONFIG_KERNEL_INIT_PRIORITY_DEVICE device priority within the device initialization level.

  • zdma_api is a structure where we add all the api that need to be registered to subsystem

DEVICE_DT_NAME(n)

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

DT_INST_REG_ADDR(n)

  • This macro returns instances register block address

DT_INST_PROP(n, Property)

  • This macro returns node property value

DT_INST_PROP_OR(n, Property, Default)

  • This macro returns node property value or default value.

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.

amd_zdma.c

Kconfig File

It is used for build time configuration of Zephyr. Each Kconfig file contains configuration symbols (options). These options not only specify the configuration but also they define dependencies between symbols. Symbols can be grouped into menus and sub-menus to keep the interactive configuration interfaces organized. For more info refer https://docs.zephyrproject.org/latest/build/kconfig/index.html

Kconfig.amd_zdma

The output from Kconfig is a header file autoconf.h with macros that can be tested at build time. Code for unused features can be compiled out to save space.

Device Tree Binding File

Binding files declare and describe the device-specific requirements for the device tree. Zephyr DT binding is a YAML file that defines which properties are required and optional for that particular 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.