X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=kitten%2Farch%2Fx86_64%2Fmm%2Fphys_addr.c;fp=kitten%2Farch%2Fx86_64%2Fmm%2Fphys_addr.c;h=90e609702f8a1fd2b8189ddd00377f7fe347fddd;hb=6299cb929a586fd8debcc316c1ede714d5b95979;hp=0000000000000000000000000000000000000000;hpb=e9e3ee43cb302909917b5919f6043347b73c6995;p=palacios.git diff --git a/kitten/arch/x86_64/mm/phys_addr.c b/kitten/arch/x86_64/mm/phys_addr.c new file mode 100644 index 0000000..90e6097 --- /dev/null +++ b/kitten/arch/x86_64/mm/phys_addr.c @@ -0,0 +1,21 @@ +#include + +extern unsigned long phys_base; + +/** + * This converts a kernel virtual address to a physical address. + * + * NOTE: This function only works for kernel virtual addresses in the kernel's + * identity mapping of all of physical memory. It will not work for the + * fixmap, vmalloc() areas, or any other type of virtual address. + */ +unsigned long +__phys_addr(unsigned long virt_addr) +{ + /* Handle kernel symbols */ + if (virt_addr >= __START_KERNEL_map) + return virt_addr - __START_KERNEL_map + phys_base; + /* Handle kernel data */ + return virt_addr - PAGE_OFFSET; +} +