Hi I have written a kernel module that do 2 MB kmalloc (for physical contiguous memory) and convert its virtual address to bus address using virt_to_bus() to sent it back to application.
I need bus address because I have to transfer it to another system running linux and connected to host system using pcie-link. Now another system would be able to initiate a DMA transfer using this bus address.
Problem is: virt_to_bus() is deprecated and results in warning, is there any other way around to translate this address to bus address?
is there any other way around to translate this address to bus address
Yes, use virt_to_phys. A quick trip in the kernel shows this for x86:
#define virt_to_bus virt_to_phys
#define bus_to_virt phys_to_virt
Their generic counterparts, defined in asm-generic/io.h simply cast to unsigned long / void * respectively.
Of course you know you can always just subtract PAGE_OFFSET for linear mapped memory to obtain the physical address.
I am using arm
In that case you're likely looking for dma_map_single.
static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
size_t size, enum dma_data_direction dir)
The buffer has to be pre-allocated (e.g. using kmalloc()). DMA for it is set up with dma_map_single().
I really have little experience with DMA but there's a lot of information out there pointing out that dma_map* should replace virt_to_bus.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With