RE: How to convert virtual address to physical address and revers e?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Gaurav Dhiman [mailto:gaurav4lkg@xxxxxxxxx]
> 
> Linux kernel provides you with functions like virt_to_phys and friends to
> convert a kernel mode virtual address to physical address and vice versa.

>The functions you are talking are specifically for converting the
>physical addresses to kernel virtual address not to user virtual
>address space
	Infact, that was what I also meant.


>As I looked into the functions "virt_to_phys" and "phys_to_virt" in
>page.h file, i found the following macros:

>#define __PAGE_OFFSET           (0xC0000000UL)
>#define PAGE_OFFSET             ((unsigned long)__PAGE_OFFSET)

>#define __pa(x)                 ((unsigned long)(x)-PAGE_OFFSET)
>#define __va(x)                 ((void *)((unsigned long)(x)+PAGE_OFFSET))


>As per my understanding PAGE_OFFSET is the starting kernel virtual
>address, that means kernel virtual address will start from
>PAGE_OFFSET.

>My question is, why we are subtracting PAGE_OFFSET from a given
>address in __pa() macro, is it because physically kernel code is
>placed in lower memory. If this is not the reason, can someone please
>clarify this ?

	In the case of a 3:1 mapping, PAGE_OFFSET is 3 GB (0xc0000000)
 and the page tables are set such that , virtual address 0xc0000000
points to physical address 0x0 and so on. I have also seen systems
with 2:2 mapping and there PAGE_OFFSET is 2GB and hence the 
pysical address = virt addr - 2GB.



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux