__pa() vs. virt_to_phys()

Dave Hansen haveblue at us.ibm.com
Wed Mar 17 12:58:41 EST 2004


On Tue, 2004-03-16 at 17:43, Anton Blanchard wrote:
> > Are you sure you want __pa there?  Isn't virt_to_phys() more applicable?
>
> Im not convinced :)
>
> static inline unsigned long virt_to_phys(volatile void * address)
> {
> #ifdef __IO_DEBUG
>         printk("virt_to_phys: 0x%08lx -> 0x%08lx\n",
>                         (unsigned long) address,
>                         __pa((unsigned long)address));
> #endif
>         return __pa((unsigned long)address);
> }

__pa() is simply supposed to be the addr-PAGE_OFFSET calculation.
virt_to_phys() will be guaranteed to take care of any layout changes if
kernel addresses ever fail to be mapped flat, and 1:1 with the physical
address layout.

So, let's say that someone is working on ... say ... memory hotplug.
They will be modifying the virt_to_phys() function to make up for any
weird mappings that are going on.  But, they'll leave __{v,p}a alone,
because those are used for stuff that occurs very early, even at compile
time.

More virt_to_phys() and less __pa() will save me lots of auditing later
on :)  If you're not in early boot, or really know what you're doing,
use virt_to_phys() and cousins.

Plus, it's more type safe.

-- dave


** Sent via the linuxppc64-dev mail list. See http://lists.linuxppc.org/





More information about the Linuxppc64-dev mailing list