DMA APIs

This topic provides details for the DMA APIs.

dma_request_channel

Synopsis
struct dma_channel *dma_request_channel(struct device *dev, const char *name)
Description Requests an available DMA channel.
Parameter
  • dev: The DMA applicant device.
  • name: Name of the DMA channel.
Return
  • Success: A pointer to the handle of DMA channel
  • Failure: NULL

dma_release_channel

Synopsis
void dma_release_channel(struct dma_chan *chan)
Description Releases a specified DMA channel.
Parameter
  • chan: The pointer to the handle of DMA channel to be released
Return None

dmaengine_slave_config

Synopsis
int dmaengine_slave_config(struct dma_chan *chan, struct dma_slave_config *config)
Description Configures the device (slave) information of a DMA channel.
Parameter
  • chan: The pointer to the handle of DMA channel to be released
  • config: Parameters of the salve in the DMA channel
Return
  • Success: 0
  • Failure: Error code

dmaengine_prep_dma_cyclic

Synopsis
static inline struct dma_async_tx_descriptor *
        dmaengine_prep_dma_cyclic(struct dma_chan *chan, 
                        dma_addr_t buf_addr,
                        size_t buf_len,
                        size_t period_len,
                        enum dma_transfer_direction dir,
                        unsigned long flags)
Description Prepares a transmission of the ring buffer. The interface is usually used in audio scenarios. In a DMA transmission with a certain length, every time when a certain amount of bytes (defined in period_len) has been transmitted, the system requests the callback function of transmission completion.
Parameter
  • chan: The relevant DMA channel
  • buf_addr: Destination address
  • buf_len: The length of the transmission. Must be integral multiple of period_len.
  • period_len: When a certain number of data bytes are transferred, the callback function that completes the transfer is executed.
  • dir: Transmission direction. For example:
    • DMA_MEM_TO_DEV: From memory to device.
    • DMA_DEV_TO_MEM: From device to memory.
  • flags: The macro definitions started with "DMA_PREP_", which provides additional information for the DMA Controller (DMAC) driver. For example:
    • DMA_PREP_INTERRUPT: The flag is used to inform DMAC that an interrupt will be generated after the transmission, so that DMAC will use the callback function from the client.
    • DMA_PREP_FENCE: The flag is used to inform DMAC that all the later transmissions rely on the success of the current transmission, so that DMAC will prioritize the DMA transmissions accordingly.
Return
  • Success: A pointer to the transmission descriptor.
  • Failure: NULL

dmaengine_prep_slave_sg

Synopsis
static inline struct dma_async_tx_descriptor *
        dmaengine_prep_slave_sg(struct dma_chan *chan, 
                                struct scatterlist *sgl,
                                unsigned int sg_len,
                                enum dma_transfer_direction dir,
                                unsigned long flags)
Description Prepares a DMA transmission for the scattered buffer.
Parameter
  • chan: The relevant DMA channel
  • sgl: The address of the scattered transmission list. The list should be created before a scattered transmission.
  • dir: Transmission direction. For example:
    • DMA_MEM_TO_DEV: From memory to device
    • DMA_DEV_TO_MEM: From device to memory
  • flags: The macro definitions started with "DMA_PREP_", which provides additional information for the DMA Controller (DMAC) driver. For example:
    • DMA_PREP_INTERRUPT: The flag is used to inform DMAC that an interrupt will be generated after the transmission, so that DMAC will use the callback function from the client.
    • DMA_PREP_FENCE: The flag is used to inform DMAC that all the later transmissions rely on the success of the current transmission, so that DMAC will prioritize the DMA transmissions accordingly.
Return
  • Success: A pointer to the transmission descriptor.
  • Failure: NULL

dmaengine_submit

Synopsis
dma_cookie_t dmaengine_submit(struct dma_async_tx_descriptor *desc)
Description Submits a prepared transmission.
Parameter
  • desc: The pointer to the description of the transmission.
Return
  • Success: A cookie greater than 0
  • Failure: Error code

dma_async_issue_pending

Synopsis
void dma_async_issue_pending(struct dma_chan *chan)
Description Starts the transmission in a certain channel.
Parameter
  • chan: The pointer to the handle of the relevant DMA channel
Return None

dmaengine_terminate_all

Synopsis
void dma_async_issue_pending(struct dma_chan *chan)
Description Stops the DMA transmission in a certain channel.
Parameter
  • chan: The pointer to the handle of the relevant DMA channel
Return
  • Success: 0
  • Failure: Error code