How to get a device from cdev

I am writing a kernel module that will allocate some connected memory and return the corresponding virtual and physical addresses.

I am registering the module as cdev , allocating space using dma_alloc_coherent() , and I would like to make it using dma_common_mmap() .

dma_common_mmap() requires a pointer to a struct device : how can I get it?

+5
source share
1 answer
 void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, int flag); 

This function handles both distribution and display of the buffer. The first two arguments are the structure of the device and the size of the required buffer. The function returns the result of the DMA mapping in two places. The return value of the function is the virtual kernel address for the buffer that can be used by the driver. The corresponding bus address, meanwhile, is returned in dma_handle.

0
source

Source: https://habr.com/ru/post/1236372/


All Articles