No, this is not a 'google first' post. (Or at least I hope it isn't, because I did spend some serious time already on this. :-) )
I work on ARM, and am writing a device driver. The problem is that I have a peace of memory I dynamically allocate with kmalloc( ..,..,GPF_KERNEL). Now our embedded device has a DMA-unit, which of course doesn't want to see the return address of kmalloc, because it is virtual.
Now, the question is whether:
virt_to_phys( kmalloc_return_address )
gives me the physical address. Some posters at Google say 'yes', other say 'no' and again others say it depends on the platform. The latter therefore doesn't sound logical.
On ARM, I suspect it is not, because my system violently crashes if I feed this address to my DMA-unit. If I then take a fixed physical address and via ioremap get a virtual address (actually a cookie, but on ARM this is fortunately the same, which made testing easy), and do a virt_to_phys on that cookie, I indeed don't get back my physical address. So this strengthes me in my assumtion, virt_to_phys does something, but not what I hoped/some believe ... (*)
So the first question is: What does virts_to_phys actually do (all all platforms)?
Second question is, because I found the function consistent_alloc. This function which is as I understood ARM and PPC only, and allocates a uncached, but also unbuffered peace of memory (The latter is at least not achived with kmalloc). However, it also gives me the hardware-address. So, in my case this should solve the problem, but this still makes me wonder, what developers on other platforms have to do to get a physical address of a kmalloc-ed peace of memory.
So the second question: Does there exists a portable method at all?
Or am I missing somnething completely? In that case please educate me. :-)
Regards,
Armin
(*) Although it seems that for IA32 this behaviour is 'normal' in the way, that virt_to_phys is not defibed for ioremap-ed addresses. However, in the case - as on ARM - where cookies and virtual addresses are by luck identical, this shouldn't matter since thevirt-to_phys function/macro cannot tell of course whether it is a cookie or 'true' virtual address.