![]() |
RT-Thread RTOS
An open source embedded real-time operating system
|
#include <rtthread.h>#include <drivers/ofw.h>#include <drivers/misc.h>#include <drivers/core/dm.h>#include <mmu.h>#include <mm_page.h>#include <bitmap.h>
Include dependency graph for dma.h:Data Structures | |
| struct | rt_dma_slave_config |
| struct | rt_dma_slave_transfer |
| struct | rt_dma_controller |
| struct | rt_dma_controller_ops |
| struct | rt_dma_chan |
| struct | rt_dma_pool |
| struct | rt_dma_map_ops |
Macros | |
| #define | RT_DMA_F_LINEAR RT_BIT(0) |
| #define | RT_DMA_F_32BITS RT_BIT(1) |
| #define | RT_DMA_F_NOCACHE RT_BIT(2) |
| #define | RT_DMA_F_DEVICE RT_BIT(3) |
| #define | RT_DMA_F_NOMAP RT_BIT(4) |
| #define | RT_DMA_F_WT RT_BIT(5) |
| #define | RT_DMA_PAGE_SIZE ARCH_PAGE_SIZE |
Enumerations | |
| enum | rt_dma_transfer_direction { RT_DMA_MEM_TO_MEM , RT_DMA_MEM_TO_DEV , RT_DMA_DEV_TO_MEM , RT_DMA_DEV_TO_DEV , RT_DMA_DIR_MAX } |
| enum | rt_dma_slave_buswidth { RT_DMA_SLAVE_BUSWIDTH_UNDEFINED = 0 , RT_DMA_SLAVE_BUSWIDTH_1_BYTE = 1 , RT_DMA_SLAVE_BUSWIDTH_2_BYTES = 2 , RT_DMA_SLAVE_BUSWIDTH_3_BYTES = 3 , RT_DMA_SLAVE_BUSWIDTH_4_BYTES = 4 , RT_DMA_SLAVE_BUSWIDTH_8_BYTES = 8 , RT_DMA_SLAVE_BUSWIDTH_16_BYTES = 16 , RT_DMA_SLAVE_BUSWIDTH_32_BYTES = 32 , RT_DMA_SLAVE_BUSWIDTH_64_BYTES = 64 , RT_DMA_SLAVE_BUSWIDTH_128_BYTES = 128 , RT_DMA_SLAVE_BUSWIDTH_BYTES_MAX } |
Functions | |
| rt_inline void | rt_dma_controller_add_direction (struct rt_dma_controller *ctrl, enum rt_dma_transfer_direction dir) |
| rt_inline void | rt_dma_controller_set_addr_mask (struct rt_dma_controller *ctrl, rt_uint64_t mask) |
| rt_err_t | rt_dma_controller_register (struct rt_dma_controller *ctrl) |
| rt_err_t | rt_dma_controller_unregister (struct rt_dma_controller *ctrl) |
| rt_err_t | rt_dma_chan_start (struct rt_dma_chan *chan) |
| rt_err_t | rt_dma_chan_pause (struct rt_dma_chan *chan) |
| rt_err_t | rt_dma_chan_stop (struct rt_dma_chan *chan) |
| rt_err_t | rt_dma_chan_config (struct rt_dma_chan *chan, struct rt_dma_slave_config *conf) |
| rt_err_t | rt_dma_chan_done (struct rt_dma_chan *chan, rt_size_t size) |
| rt_err_t | rt_dma_prep_memcpy (struct rt_dma_chan *chan, struct rt_dma_slave_transfer *transfer) |
| rt_err_t | rt_dma_prep_cyclic (struct rt_dma_chan *chan, struct rt_dma_slave_transfer *transfer) |
| rt_err_t | rt_dma_prep_single (struct rt_dma_chan *chan, struct rt_dma_slave_transfer *transfer) |
| struct rt_dma_chan * | rt_dma_chan_request (struct rt_device *dev, const char *name) |
| rt_err_t | rt_dma_chan_release (struct rt_dma_chan *chan) |
| void * | rt_dma_alloc (struct rt_device *dev, rt_size_t size, rt_ubase_t *dma_handle, rt_ubase_t flags) |
| void | rt_dma_free (struct rt_device *dev, rt_size_t size, void *cpu_addr, rt_ubase_t dma_handle, rt_ubase_t flags) |
| rt_inline void * | rt_dma_alloc_coherent (struct rt_device *dev, rt_size_t size, rt_ubase_t *dma_handle) |
| rt_inline void | rt_dma_free_coherent (struct rt_device *dev, rt_size_t size, void *cpu_addr, rt_ubase_t dma_handle) |
| rt_err_t | rt_dma_sync_out_data (struct rt_device *dev, void *data, rt_size_t size, rt_ubase_t *dma_handle, rt_ubase_t flags) |
| rt_err_t | rt_dma_sync_in_data (struct rt_device *dev, void *out_data, rt_size_t size, rt_ubase_t dma_handle, rt_ubase_t flags) |
| rt_inline rt_bool_t | rt_dma_device_is_coherent (struct rt_device *dev) |
| rt_inline void | rt_dma_device_set_ops (struct rt_device *dev, const struct rt_dma_map_ops *ops) |
| struct rt_dma_pool * | rt_dma_pool_install (rt_region_t *region) |
| rt_err_t | rt_dma_pool_extract (rt_size_t cma_size, rt_size_t coherent_pool_size) |
DMA (Direct Memory Access) controller framework public API.
Defines the DMA controller, channel, memory pool, and mapping operations interfaces. Provides APIs for controller registration, channel lifecycle management, transfer preparation (memcpy, cyclic, single), DMA buffer allocation with cache coherence management, and device tree integration.
| #define RT_DMA_F_LINEAR RT_BIT(0) |
DMA pool: linear address space (all DMA pools have this flag)
| #define RT_DMA_F_32BITS RT_BIT(1) |
DMA pool: limited to 32-bit addressable memory (below 4GB)
| #define RT_DMA_F_NOCACHE RT_BIT(2) |
DMA allocation: use non-cacheable memory mapping.
| #define RT_DMA_F_DEVICE RT_BIT(3) |
DMA pool: device-private pool (matches pool->dev)
| #define RT_DMA_F_NOMAP RT_BIT(4) |
DMA allocation: do not map virtual address, return physical.
| #define RT_DMA_F_WT RT_BIT(5) |
DMA allocation: use write-through cache mapping.
| #define RT_DMA_PAGE_SIZE ARCH_PAGE_SIZE |
DMA pool page size matches architecture page size.
DMA transfer direction.
Defines the data flow direction for a DMA transfer. The controller's dir_cap bitmap indicates which directions are supported.
DMA slave bus width options.
Specifies the transfer width for source and destination on the DMA bus. Must match the peripheral's FIFO width for correct operation.
| rt_inline void rt_dma_controller_add_direction | ( | struct rt_dma_controller * | ctrl, |
| enum rt_dma_transfer_direction | dir | ||
| ) |
Add a supported transfer direction to a DMA controller.
Controllers call this during probe to declare which directions they support.
| [in] | ctrl | DMA controller |
| [in] | dir | Transfer direction to add |
| rt_inline void rt_dma_controller_set_addr_mask | ( | struct rt_dma_controller * | ctrl, |
| rt_uint64_t | mask | ||
| ) |
Set the address mask for a DMA controller.
The mask defines the valid address range for DMA transfers. For example, RT_DMA_ADDR_MASK(32) limits transfers to the lower 4GB.
| [in] | ctrl | DMA controller |
| [in] | mask | Address bit mask |
| rt_err_t rt_dma_controller_register | ( | struct rt_dma_controller * | ctrl | ) |
Register a DMA controller with the framework.
| rt_err_t rt_dma_controller_unregister | ( | struct rt_dma_controller * | ctrl | ) |
Unregister a DMA controller (fails if channels are in use)
| rt_err_t rt_dma_chan_start | ( | struct rt_dma_chan * | chan | ) |
Start a prepared DMA transfer on a channel.
| rt_err_t rt_dma_chan_pause | ( | struct rt_dma_chan * | chan | ) |
Pause a running DMA transfer (falls back to stop if not supported)
| rt_err_t rt_dma_chan_stop | ( | struct rt_dma_chan * | chan | ) |
Stop a running DMA transfer.
| rt_err_t rt_dma_chan_config | ( | struct rt_dma_chan * | chan, |
| struct rt_dma_slave_config * | conf | ||
| ) |
Configure a DMA channel with slave-specific parameters.
| rt_err_t rt_dma_chan_done | ( | struct rt_dma_chan * | chan, |
| rt_size_t | size | ||
| ) |
Signal transfer completion (called by controller ISR)
| rt_err_t rt_dma_prep_memcpy | ( | struct rt_dma_chan * | chan, |
| struct rt_dma_slave_transfer * | transfer | ||
| ) |
Prepare a memory-to-memory DMA transfer.
| rt_err_t rt_dma_prep_cyclic | ( | struct rt_dma_chan * | chan, |
| struct rt_dma_slave_transfer * | transfer | ||
| ) |
Prepare a cyclic (repeating) DMA transfer.
| rt_err_t rt_dma_prep_single | ( | struct rt_dma_chan * | chan, |
| struct rt_dma_slave_transfer * | transfer | ||
| ) |
Prepare a single (one-shot) DMA transfer.
| struct rt_dma_chan* rt_dma_chan_request | ( | struct rt_device * | dev, |
| const char * | name | ||
| ) |
Request a DMA channel for a slave device (by DT name or auto)
| rt_err_t rt_dma_chan_release | ( | struct rt_dma_chan * | chan | ) |
Release a DMA channel back to the controller.
| void* rt_dma_alloc | ( | struct rt_device * | dev, |
| rt_size_t | size, | ||
| rt_ubase_t * | dma_handle, | ||
| rt_ubase_t | flags | ||
| ) |
Allocate a DMA-capable memory buffer.
| void rt_dma_free | ( | struct rt_device * | dev, |
| rt_size_t | size, | ||
| void * | cpu_addr, | ||
| rt_ubase_t | dma_handle, | ||
| rt_ubase_t | flags | ||
| ) |
Free a DMA buffer previously allocated with rt_dma_alloc()
| rt_inline void* rt_dma_alloc_coherent | ( | struct rt_device * | dev, |
| rt_size_t | size, | ||
| rt_ubase_t * | dma_handle | ||
| ) |
Allocate a coherent (non-cacheable) DMA buffer.
Convenience wrapper around rt_dma_alloc() with RT_DMA_F_NOCACHE | RT_DMA_F_LINEAR.
| [in] | dev | DMA-capable device |
| [in] | size | Requested size in bytes |
| [out] | dma_handle | Physical DMA address |
| rt_inline void rt_dma_free_coherent | ( | struct rt_device * | dev, |
| rt_size_t | size, | ||
| void * | cpu_addr, | ||
| rt_ubase_t | dma_handle | ||
| ) |
Free a coherent DMA buffer.
| [in] | dev | DMA-capable device |
| [in] | size | Buffer size in bytes |
| [in] | cpu_addr | Kernel virtual address |
| [in] | dma_handle | Physical DMA address |
| rt_err_t rt_dma_sync_out_data | ( | struct rt_device * | dev, |
| void * | data, | ||
| rt_size_t | size, | ||
| rt_ubase_t * | dma_handle, | ||
| rt_ubase_t | flags | ||
| ) |
Synchronize CPU cache for DMA output (CPU → device)
| rt_err_t rt_dma_sync_in_data | ( | struct rt_device * | dev, |
| void * | out_data, | ||
| rt_size_t | size, | ||
| rt_ubase_t | dma_handle, | ||
| rt_ubase_t | flags | ||
| ) |
Synchronize CPU cache for DMA input (device → CPU)
| rt_inline rt_bool_t rt_dma_device_is_coherent | ( | struct rt_device * | dev | ) |
Check if a device is DMA-coherent.
Reads the "dma-coherent" boolean property from the device's device tree node (if present).
| [in] | dev | Device to check |
| rt_inline void rt_dma_device_set_ops | ( | struct rt_device * | dev, |
| const struct rt_dma_map_ops * | ops | ||
| ) |
Override the DMA mapping operations for a device.
| [in] | dev | Device to configure |
| [in] | ops | Custom DMA map operations (or NULL to reset) |
| struct rt_dma_pool* rt_dma_pool_install | ( | rt_region_t * | region | ) |
Install a DMA memory pool from a region descriptor.
| rt_err_t rt_dma_pool_extract | ( | rt_size_t | cma_size, |
| rt_size_t | coherent_pool_size | ||
| ) |
Extract coherent pool and CMA from memblock reserved memory.