-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
In DMA API's data structure (within include/dma.h):
struct dma_config {
u32_t dma_slot : 6;
...
u32_t block_count;
struct dma_block_config *head_block;
void (*dma_callback)(struct device *dev, u32_t channel,
int error_code);
};
The first argument of the callback function dma_callback is set as the pointer to the DMA driver device in all current DMA drivers. However, the owner of the callback function implementation usually is another device driver, like UART, SPI, etc, which has no idea how the parameter dev can be useful to it given that those devices don't know much about the DMA device only from struct device *dev. However, when the callee's callback function is called, it could need to access its context parameter to retrieve its private data which is actually absent in the callback arguments.
To address this request, suggest to change the callback API to the following:
struct dma_config {
u32_t dma_slot : 6;
...
u32_t block_count;
struct dma_block_config *head_block;
void * client_data;
void (*dma_callback)(void * client_data, u32_t channel,
int error_code);
};
Here, a new member void * client_data is introduced to the struct dma_config and will be assigned by the DMA client, and passed to the callback function dma_callback as the first argument which replaces the current argument struct device *dev. In this way, the DMA client can access its private data when its callback function is called by the DMA driver.