KVM: paravirtualized clocksource: host part
[deliverable/linux.git] / include / asm-x86 / kvm_para.h
1 #ifndef __X86_KVM_PARA_H
2 #define __X86_KVM_PARA_H
3
4 /* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
5 * should be used to determine that a VM is running under KVM.
6 */
7 #define KVM_CPUID_SIGNATURE 0x40000000
8
9 /* This CPUID returns a feature bitmap in eax. Before enabling a particular
10 * paravirtualization, the appropriate feature bit should be checked.
11 */
12 #define KVM_CPUID_FEATURES 0x40000001
13 #define KVM_FEATURE_CLOCKSOURCE 0
14
15 #define MSR_KVM_WALL_CLOCK 0x11
16 #define MSR_KVM_SYSTEM_TIME 0x12
17
18 #ifdef __KERNEL__
19 #include <asm/processor.h>
20
21 /* xen binary-compatible interface. See xen headers for details */
22 struct kvm_vcpu_time_info {
23 uint32_t version;
24 uint32_t pad0;
25 uint64_t tsc_timestamp;
26 uint64_t system_time;
27 uint32_t tsc_to_system_mul;
28 int8_t tsc_shift;
29 int8_t pad[3];
30 } __attribute__((__packed__)); /* 32 bytes */
31
32 struct kvm_wall_clock {
33 uint32_t wc_version;
34 uint32_t wc_sec;
35 uint32_t wc_nsec;
36 } __attribute__((__packed__));
37
38
39 extern void kvmclock_init(void);
40
41
42 /* This instruction is vmcall. On non-VT architectures, it will generate a
43 * trap that we will then rewrite to the appropriate instruction.
44 */
45 #define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
46
47 /* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
48 * instruction. The hypervisor may replace it with something else but only the
49 * instructions are guaranteed to be supported.
50 *
51 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
52 * The hypercall number should be placed in rax and the return value will be
53 * placed in rax. No other registers will be clobbered unless explicited
54 * noted by the particular hypercall.
55 */
56
57 static inline long kvm_hypercall0(unsigned int nr)
58 {
59 long ret;
60 asm volatile(KVM_HYPERCALL
61 : "=a"(ret)
62 : "a"(nr));
63 return ret;
64 }
65
66 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
67 {
68 long ret;
69 asm volatile(KVM_HYPERCALL
70 : "=a"(ret)
71 : "a"(nr), "b"(p1));
72 return ret;
73 }
74
75 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
76 unsigned long p2)
77 {
78 long ret;
79 asm volatile(KVM_HYPERCALL
80 : "=a"(ret)
81 : "a"(nr), "b"(p1), "c"(p2));
82 return ret;
83 }
84
85 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
86 unsigned long p2, unsigned long p3)
87 {
88 long ret;
89 asm volatile(KVM_HYPERCALL
90 : "=a"(ret)
91 : "a"(nr), "b"(p1), "c"(p2), "d"(p3));
92 return ret;
93 }
94
95 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
96 unsigned long p2, unsigned long p3,
97 unsigned long p4)
98 {
99 long ret;
100 asm volatile(KVM_HYPERCALL
101 : "=a"(ret)
102 : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4));
103 return ret;
104 }
105
106 static inline int kvm_para_available(void)
107 {
108 unsigned int eax, ebx, ecx, edx;
109 char signature[13];
110
111 cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
112 memcpy(signature + 0, &ebx, 4);
113 memcpy(signature + 4, &ecx, 4);
114 memcpy(signature + 8, &edx, 4);
115 signature[12] = 0;
116
117 if (strcmp(signature, "KVMKVMKVM") == 0)
118 return 1;
119
120 return 0;
121 }
122
123 static inline unsigned int kvm_arch_para_features(void)
124 {
125 return cpuid_eax(KVM_CPUID_FEATURES);
126 }
127
128 #endif
129
130 #endif
This page took 0.088635 seconds and 5 git commands to generate.