test: export vm helpers
[qemu-kvm/amd-iommu.git] / kvm / test / x86 / vm.h
blob80dab8b6dd40935b06ac2dd0ae72896588fa6d9f
1 #ifndef VM_H
2 #define VM_H
4 #define PAGE_SIZE 4096ul
5 #ifdef __x86_64__
6 #define LARGE_PAGE_SIZE (512 * PAGE_SIZE)
7 #else
8 #define LARGE_PAGE_SIZE (1024 * PAGE_SIZE)
9 #endif
11 #define PTE_PRESENT (1ull << 0)
12 #define PTE_PSE (1ull << 7)
13 #define PTE_WRITE (1ull << 1)
14 #define PTE_ADDR (0xffffffffff000ull)
16 void setup_vm();
18 void *vmalloc(unsigned long size);
19 void vfree(void *mem);
20 void *vmap(unsigned long long phys, unsigned long size);
22 void install_pte(unsigned long *cr3,
23 int pte_level,
24 void *virt,
25 unsigned long pte,
26 unsigned long *pt_page);
28 void *alloc_page();
30 void install_large_page(unsigned long *cr3,unsigned long phys,
31 void *virt);
32 void install_page(unsigned long *cr3, unsigned long phys, void *virt);
34 static inline unsigned long virt_to_phys(const void *virt)
36 return (unsigned long)virt;
39 static inline void *phys_to_virt(unsigned long phys)
41 return (void *)phys;
45 static inline void load_cr3(unsigned long cr3)
47 asm ( "mov %0, %%cr3" : : "r"(cr3) );
50 static inline unsigned long read_cr3()
52 unsigned long cr3;
54 asm volatile ( "mov %%cr3, %0" : "=r"(cr3) );
55 return cr3;
58 static inline void load_cr0(unsigned long cr0)
60 asm volatile ( "mov %0, %%cr0" : : "r"(cr0) );
63 static inline unsigned long read_cr0()
65 unsigned long cr0;
67 asm volatile ( "mov %%cr0, %0" : "=r"(cr0) );
68 return cr0;
72 static inline void load_cr4(unsigned long cr4)
74 asm volatile ( "mov %0, %%cr4" : : "r"(cr4) );
77 static inline unsigned long read_cr4()
79 unsigned long cr4;
81 asm volatile ( "mov %%cr4, %0" : "=r"(cr4) );
82 return cr4;
85 #endif