All of lore.kernel.org
 help / color / mirror / Atom feed
From: aftnix@gmail.com (AFT)
To: kernelnewbies@lists.kernelnewbies.org
Subject: explanation of __va() and __pa() macros.
Date: Fri, 22 Jun 2012 20:45:15 +0600	[thread overview]
Message-ID: <mx3vfls4.fsf@s1.test.com> (raw)
In-Reply-To: <87txy3lf44.fsf@nemi.mork.no> ("Bjørn Mork"'s message of "Fri, 22 Jun 2012 14:12:43 +0200")

Bj?rn Mork <bjorn@mork.no> writes:

> AFT <aftnix@gmail.com> writes:
>
>> My source is from 2.6 git tree. In LDD3 its said that a logical address
>> is mapped to physical address and vice versa by the macros __va() and
>> __pa().
>>
>> In my source tree they are defined as follows:
>>
>> <include/asm-generic/page.h>
>
> There's an important comment in the beginning of that file:
>
> /*
>  * Generic page.h implementation, for NOMMU architectures.
>  * This provides the dummy definitions for the memory management.
>  */
>
>
>> #define __va(x) ((void *)((unsigned long) (x)))
>> #define __pa(x) ((unsigned long) (x))
>>
>>
>> I'm not actually understanding how these "cute" looking casting is
>> performing "address mapping". I thought address mapping involves more
>> complex operations.
>
> The dummy definition is the identity mapping.  You can look at the real
> implementations to see more complex mappings:
>
> bjorn at nemi:/usr/local/src/git/linux$ egrep '#define __(p|v)a\(' arch/*/include/asm/page.h 
> arch/alpha/include/asm/page.h:#define __pa(x)                   ((unsigned long) (x) - PAGE_OFFSET)
> arch/alpha/include/asm/page.h:#define __va(x)                   ((void *)((unsigned long) (x) + PAGE_OFFSET))
> arch/avr32/include/asm/page.h:#define __pa(x)           PHYSADDR(x)
> arch/avr32/include/asm/page.h:#define __va(x)           ((void *)(P1SEGADDR(x)))
> arch/frv/include/asm/page.h:#define __pa(vaddr)         virt_to_phys((void *) (unsigned long) (vaddr))
> arch/frv/include/asm/page.h:#define __va(paddr)         phys_to_virt((unsigned long) (paddr))
> arch/h8300/include/asm/page.h:#define __pa(vaddr)               virt_to_phys(vaddr)
> arch/h8300/include/asm/page.h:#define __va(paddr)               phys_to_virt((unsigned long)paddr)
> arch/hexagon/include/asm/page.h:#define __pa(x) ((unsigned long)(x) - PAGE_OFFSET)
> arch/hexagon/include/asm/page.h:#define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET))
> arch/ia64/include/asm/page.h:#define __pa(x)            ({ia64_va _v; _v.l = (long) (x); _v.f.reg = 0; _v.l;})
> arch/ia64/include/asm/page.h:#define __va(x)            ({ia64_va _v; _v.l = (long) (x); _v.f.reg = -1; _v.p;})
> arch/m32r/include/asm/page.h:#define __pa(x)                    ((unsigned long)(x) - PAGE_OFFSET)
> arch/m32r/include/asm/page.h:#define __va(x)                    ((void *)((unsigned long)(x) + PAGE_OFFSET))
> arch/mips/include/asm/page.h:#define __pa(x)                                                            \
> arch/mips/include/asm/page.h:#define __pa(x)                                                            \
> arch/mips/include/asm/page.h:#define __va(x)            ((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET))
> arch/mn10300/include/asm/page.h:#define __pa(x)                 ((unsigned long)(x))
> arch/mn10300/include/asm/page.h:#define __va(x)                 ((void *)(unsigned long)(x))
> arch/openrisc/include/asm/page.h:#define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET))
> arch/openrisc/include/asm/page.h:#define __pa(x) ((unsigned long) (x) - PAGE_OFFSET)
> arch/parisc/include/asm/page.h:#define __pa(x)                  ((unsigned long)(x)-PAGE_OFFSET)
> arch/parisc/include/asm/page.h:#define __va(x)                  ((void *)((unsigned long)(x)+PAGE_OFFSET))
> arch/powerpc/include/asm/page.h:#define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + VIRT_PHYS_OFFSET))
> arch/powerpc/include/asm/page.h:#define __pa(x) ((unsigned long)(x) - VIRT_PHYS_OFFSET)
> arch/powerpc/include/asm/page.h:#define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + PAGE_OFFSET - MEMORY_START))
> arch/powerpc/include/asm/page.h:#define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + MEMORY_START)
> arch/s390/include/asm/page.h:#define __pa(x)                 (unsigned long)(x)
> arch/s390/include/asm/page.h:#define __va(x)                 (void *)(unsigned long)(x)
> arch/score/include/asm/page.h:#define __pa(x)           ((unsigned long)(x) - PAGE_OFFSET)
> arch/score/include/asm/page.h:#define __va(x)           ((void *)((unsigned long) (x) + PAGE_OFFSET))
> arch/sh/include/asm/page.h:#define __pa(x)              ___pa((unsigned long)x)
> arch/sh/include/asm/page.h:#define __va(x)              (void *)___va((unsigned long)x)
> arch/tile/include/asm/page.h:#define __pa(kaddr) virt_to_phys((void *)(unsigned long)(kaddr))
> arch/tile/include/asm/page.h:#define __va(paddr) phys_to_virt((phys_addr_t)(paddr))
> arch/um/include/asm/page.h:#define __pa(virt) to_phys((void *) (unsigned long) (virt))
> arch/um/include/asm/page.h:#define __va(phys) to_virt((unsigned long) (phys))
> arch/x86/include/asm/page.h:#define __pa(x)             __phys_addr((unsigned long)(x))
> arch/x86/include/asm/page.h:#define __va(x)                     ((void *)((unsigned long)(x)+PAGE_OFFSET))
> arch/xtensa/include/asm/page.h:#define __pa(x)                  ((unsigned long) (x) - PAGE_OFFSET)
> arch/xtensa/include/asm/page.h:#define __va(x)                  ((void *)((unsigned long) (x) + PAGE_OFFSET))
>
>
>
> Bj?rn

Hi Bjorn,

Thanks for the reply. 

cheers,
aft

      reply	other threads:[~2012-06-22 14:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-22 11:49 explanation of __va() and __pa() macros AFT
2012-06-22 12:06 ` Vlad Dogaru
2012-06-22 14:38   ` AFT
2012-06-22 12:12 ` Bjørn Mork
2012-06-22 14:45   ` AFT [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mx3vfls4.fsf@s1.test.com \
    --to=aftnix@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.