Question on Virtual Address to Physcial Address, need help - Embedded
This is a discussion on Question on Virtual Address to Physcial Address, need help - Embedded ; Hi
How can I get physics address from a virtual address in kernel space?
For low mem I can simply use virt_to_phys macro, and for those memory
been mapped
by ioremap, I try to walk through the pagetable by following ...
-
Question on Virtual Address to Physcial Address, need help
Hi
How can I get physics address from a virtual address in kernel space?
For low mem I can simply use virt_to_phys macro, and for those memory
been mapped
by ioremap, I try to walk through the pagetable by following code on arm
platform:
static unsigned long himem_virt_to_phys(unsigned long virt)
{
pmd_t * pmd;
pte_t * pte;
unsigned long phys_addr;
pmd = ( pmd_t * ) (pgd_offset_k(virt));
pte = pte_offset_kernel(pmd, virt & ~PGDIR_MASK);
phys_addr = ( pte_val(*pte) & PAGE_MASK ) | ( virt & ~PAGE_MASK);
printk("--- pmd addr = %lx, pte addr = %lx \n",pmd,pte);
printk("--- pte content = %lx\n",pte_val(*pte));
printk("------ virt = %lx, phys= %lx \n",virt, phys_addr);
return phys_addr;
}
it did work, but when I try to get the physical address of a local var
say i,
it won't work! Why ? Is there some thing I missing?
the code i test the func is as following:
//---------------------
int i;
unsigned long virt;
virt = (unsigned long)ioremap(0x10018000,0x10000);
himem_virt_to_phys(virt);
i = 28;
printk("&i = %x\n", &i);
himem_virt_to_phys((unsigned long)&i);
//---------------------
and the outcome:
--- pmd addr = c0007120, pte addr = c3fdba9c
--- pte content = 100180a3
------ virt = c48a7000, phys= 10018000
&i = c3d99f64
--- pmd addr = c00070f0, pte addr = c3c00e64
--- pte content = e51b5084
------ virt = c3d99f64, phys= e51b5f64
this is not right , since pte's last bit is not 1 ,
and actually my sdram mem is on 0x1xxxxxxx
not 0xExxxxxxx
Any ideas ? Thx
-
Re: Question on Virtual Address to Physcial Address, need help
Raymond wrote:
> Hi
Hallo
> pmd = ( pmd_t * ) (pgd_offset_k(virt));
pmd = pgd_offset(current->mm, virt);
> pte = pte_offset_kernel(pmd, virt & ~PGDIR_MASK);
pte = pte_offset_kernel(pmd, virt);
> Any ideas ? Thx
For local variables pgd is in current->mm (I hope) and for vmalloc (ioremap)
is in init_mm at the begining and after page fault on others directories,
see gorman book chapter 7.
Staszek Gruszka