Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: DMA API: use client data in dma_callback function instead of dma dev #8928

Closed
jli157 opened this issue Jul 13, 2018 · 1 comment
Closed
Labels
area: API Changes to public APIs area: DMA Direct Memory Access Enhancement Changes/Updates/Additions to existing features

Comments

@jli157
Copy link
Contributor

jli157 commented Jul 13, 2018

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.

@jli157 jli157 changed the title RFC: use client data in dma_callback function instead of dma dev RFC: DMA API: use client data in dma_callback function instead of dma dev Jul 13, 2018
@nashif nashif added the Enhancement Changes/Updates/Additions to existing features label Jul 17, 2018
@sathishkuttan
Copy link
Collaborator

This would be a good enhancement.
I would suggest the following naming, however.
void *client_data -> void *callback_arg
dma_callback(void *client_data, ..) -> dma_callback(void *arg, ..)

@nashif nashif added area: API Changes to public APIs area: DMA Direct Memory Access labels Oct 16, 2018
@jli157 jli157 closed this as completed Oct 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: DMA Direct Memory Access Enhancement Changes/Updates/Additions to existing features
Projects
None yet
Development

No branches or pull requests

3 participants