Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reserving memory for DMA usage

I am trying to make use of a contiguous memory i reserved while passing the "mem" parameter to Linux when booting.

Now, i have the physical address of this space i reserved earlier, and the length of it, and i wish to make use of this reserved space for DMA purposes in my driver.

Normally i would use dma_alloc_coherent() , and if i were using CMA i would use that too, but in this case, its different.

Now, i have read that an acceptable way of mapping a physical space to kernel virtual space is to use ioremap

And, an acceptable way of "taking over" a contiguous space for DMA purposes is to use dma_map_single (mapping it for bus address)

I'm having trouble combining the two. ioremap works and returns a virtual address. Now, i have read that this is no ordinary virtual address and i should only be using access methods to read/write from this memory.

Thing is, when i try to pass this virtual address to dma_map_single , it doesn't report an error, but i suspect that this is wrong.

Am i doing it right? What can i do to make it work like it should?

10x

like image 910
Yarel Avatar asked Nov 30 '25 16:11

Yarel


1 Answers

You are doing right You don't need to allocate the memory because you already set it on boot time but you need to use dam_map_single to prevent cache problems for example if you want to do a DMA from memory to the device but the RAM is not synchronised with the L2 cache (the cache has a newer version) you will get the wrong data so you need to map and unmap before and after the DMA operation

like image 154
Liran Ben Haim Avatar answered Dec 02 '25 05:12

Liran Ben Haim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!