kvm userspace: ksm support
[qemu-kvm/fedora.git] / kvm / include / x86 / asm / kvm_para.h
blob7a30a52c09a67b2b1cc22778019ce2bc985a4cb2
1 #ifndef KVM_UNIFDEF_H
2 #define KVM_UNIFDEF_H
4 #ifdef __i386__
5 #ifndef CONFIG_X86_32
6 #define CONFIG_X86_32 1
7 #endif
8 #endif
10 #ifdef __x86_64__
11 #ifndef CONFIG_X86_64
12 #define CONFIG_X86_64 1
13 #endif
14 #endif
16 #if defined(__i386__) || defined (__x86_64__)
17 #ifndef CONFIG_X86
18 #define CONFIG_X86 1
19 #endif
20 #endif
22 #ifdef __ia64__
23 #ifndef CONFIG_IA64
24 #define CONFIG_IA64 1
25 #endif
26 #endif
28 #ifdef __PPC__
29 #ifndef CONFIG_PPC
30 #define CONFIG_PPC 1
31 #endif
32 #endif
34 #ifdef __s390__
35 #ifndef CONFIG_S390
36 #define CONFIG_S390 1
37 #endif
38 #endif
40 #endif
41 #ifndef _ASM_X86_KVM_PARA_H
42 #define _ASM_X86_KVM_PARA_H
44 /* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
45 * should be used to determine that a VM is running under KVM.
47 #define KVM_CPUID_SIGNATURE 0x40000000
49 /* This CPUID returns a feature bitmap in eax. Before enabling a particular
50 * paravirtualization, the appropriate feature bit should be checked.
52 #define KVM_CPUID_FEATURES 0x40000001
53 #define KVM_FEATURE_CLOCKSOURCE 0
54 #define KVM_FEATURE_NOP_IO_DELAY 1
55 #define KVM_FEATURE_MMU_OP 2
57 #define MSR_KVM_WALL_CLOCK 0x11
58 #define MSR_KVM_SYSTEM_TIME 0x12
60 #define KVM_MAX_MMU_OP_BATCH 32
62 /* Operations for KVM_HC_MMU_OP */
63 #define KVM_MMU_OP_WRITE_PTE 1
64 #define KVM_MMU_OP_FLUSH_TLB 2
65 #define KVM_MMU_OP_RELEASE_PT 3
67 /* Payload for KVM_HC_MMU_OP */
68 struct kvm_mmu_op_header {
69 __u32 op;
70 __u32 pad;
73 struct kvm_mmu_op_write_pte {
74 struct kvm_mmu_op_header header;
75 __u64 pte_phys;
76 __u64 pte_val;
79 struct kvm_mmu_op_flush_tlb {
80 struct kvm_mmu_op_header header;
83 struct kvm_mmu_op_release_pt {
84 struct kvm_mmu_op_header header;
85 __u64 pt_phys;
88 #ifdef __KERNEL__
89 #include <asm/processor.h>
91 extern void kvmclock_init(void);
94 /* This instruction is vmcall. On non-VT architectures, it will generate a
95 * trap that we will then rewrite to the appropriate instruction.
97 #define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
99 /* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
100 * instruction. The hypervisor may replace it with something else but only the
101 * instructions are guaranteed to be supported.
103 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
104 * The hypercall number should be placed in rax and the return value will be
105 * placed in rax. No other registers will be clobbered unless explicited
106 * noted by the particular hypercall.
109 static inline long kvm_hypercall0(unsigned int nr)
111 long ret;
112 asm volatile(KVM_HYPERCALL
113 : "=a"(ret)
114 : "a"(nr)
115 : "memory");
116 return ret;
119 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
121 long ret;
122 asm volatile(KVM_HYPERCALL
123 : "=a"(ret)
124 : "a"(nr), "b"(p1)
125 : "memory");
126 return ret;
129 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
130 unsigned long p2)
132 long ret;
133 asm volatile(KVM_HYPERCALL
134 : "=a"(ret)
135 : "a"(nr), "b"(p1), "c"(p2)
136 : "memory");
137 return ret;
140 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
141 unsigned long p2, unsigned long p3)
143 long ret;
144 asm volatile(KVM_HYPERCALL
145 : "=a"(ret)
146 : "a"(nr), "b"(p1), "c"(p2), "d"(p3)
147 : "memory");
148 return ret;
151 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
152 unsigned long p2, unsigned long p3,
153 unsigned long p4)
155 long ret;
156 asm volatile(KVM_HYPERCALL
157 : "=a"(ret)
158 : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
159 : "memory");
160 return ret;
163 static inline int kvm_para_available(void)
165 unsigned int eax, ebx, ecx, edx;
166 char signature[13];
168 cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
169 memcpy(signature + 0, &ebx, 4);
170 memcpy(signature + 4, &ecx, 4);
171 memcpy(signature + 8, &edx, 4);
172 signature[12] = 0;
174 if (strcmp(signature, "KVMKVMKVM") == 0)
175 return 1;
177 return 0;
180 static inline unsigned int kvm_arch_para_features(void)
182 return cpuid_eax(KVM_CPUID_FEATURES);
185 #endif
187 #endif /* _ASM_X86_KVM_PARA_H */