CMEM_getPhys() (API wrapper for ioctl that boils down to a call to the
get_phys() below) is designed to work on user process virtual addresses.
The __pa() macro translates only kernel direct-mapped virtual addresses
(it's just a simple subtraction/addition operation).  The code preceding
the call to __pa() is getting the kernel's virtual address corresponding
to the user virtual address passed in, at which point it can call
__pa().

The version below is an older version with some problems.  The latest
CMEM (v2.00 or greater) contains a better version which doesn't much
involve __pa().

Regards,

- Rob 

> -----Original Message-----
> From: 
> [EMAIL PROTECTED]
> p.com 
> [mailto:[EMAIL PROTECTED]
> avincidsp.com] On Behalf Of wanghao
> Sent: Monday, April 14, 2008 10:00 AM
> To: [email protected]
> Subject: why not only use MACRO __pa() to traverse one 
> virtual address tophysical address in cmem.c ?
> 
> 
> in cmem.c :
> static unsigned long get_phys(unsigned long virtp) {
>     pgd_t *pgd;
>     pmd_t *pmd;
>     pte_t *pte;
>     struct mm_struct *mm = current->mm;
> 
>     pgd = pgd_offset(mm, virtp);
>     if (!(pgd_none(*pgd) || pgd_bad(*pgd))) {
>         pmd = pmd_offset(pgd, virtp);
> 
>         if (!(pmd_none(*pmd) || pmd_bad(*pmd))) {
>             pte = pte_offset_kernel(pmd, virtp);                  
> 
>             if (pte_present(*pte)) {
>                 return __pa(page_address(pte_page(*pte)) +
>                             (virtp & ~PAGE_MASK));
>             }
>         }
>     }
> 
>     return 0;
> }
> 
> get_phys() is different from      __pa() ? or they are all 
> correct but used in different condittion ?
> 
> 
> 
> 
> 
> _______________________________________________
> Davinci-linux-open-source mailing list
> [email protected]
> http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source
> 
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to