Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

virt_to_bus() is deprecated in linux kernel module compilation

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?

like image 799
flying-high Avatar asked May 02 '26 09:05

flying-high


1 Answers

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.

EDIT

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.

like image 124
cnicutar Avatar answered May 05 '26 05:05

cnicutar