6 #define CONFIG_X86_32 1
12 #define CONFIG_X86_64 1
16 #if defined(__i386__) || defined (__x86_64__)
41 /* CPU virtualization extensions handling
43 * This should carry the code for handling CPU virtualization extensions
44 * that needs to live in the kernel core.
46 * Author: Eduardo Habkost <ehabkost@redhat.com>
48 * Copyright (C) 2008, Red Hat Inc.
50 * Contains code from KVM, Copyright (C) 2006 Qumranet, Inc.
52 * This work is licensed under the terms of the GNU GPL, version 2. See
53 * the COPYING file in the top-level directory.
55 #ifndef _ASM_X86_VIRTEX_H
56 #define _ASM_X86_VIRTEX_H
58 #include <asm/processor.h>
59 #include <asm/system.h>
68 static inline int cpu_has_vmx(void)
70 unsigned long ecx
= cpuid_ecx(1);
71 return test_bit(5, &ecx
); /* CPUID.1:ECX.VMX[bit 5] -> VT */
75 /** Disable VMX on the current CPU
77 * vmxoff causes a undefined-opcode exception if vmxon was not run
78 * on the CPU previously. Only call this function if you know VMX
81 static inline void cpu_vmxoff(void)
83 asm volatile (ASM_VMX_VMXOFF
: : : "cc");
84 write_cr4(read_cr4() & ~X86_CR4_VMXE
);
87 static inline int cpu_vmx_enabled(void)
89 return read_cr4() & X86_CR4_VMXE
;
92 /** Disable VMX if it is enabled on the current CPU
94 * You shouldn't call this if cpu_has_vmx() returns 0.
96 static inline void __cpu_emergency_vmxoff(void)
98 if (cpu_vmx_enabled())
102 /** Disable VMX if it is supported and enabled on the current CPU
104 static inline void cpu_emergency_vmxoff(void)
107 __cpu_emergency_vmxoff();
117 /** Check if the CPU has SVM support
119 * You can use the 'msg' arg to get a message describing the problem,
120 * if the function returns zero. Simply pass NULL if you are not interested
121 * on the messages; gcc should take care of not generating code for
122 * the messages on this case.
124 static inline int cpu_has_svm(const char **msg
)
126 uint32_t eax
, ebx
, ecx
, edx
;
128 if (boot_cpu_data
.x86_vendor
!= X86_VENDOR_AMD
) {
134 cpuid(0x80000000, &eax
, &ebx
, &ecx
, &edx
);
135 if (eax
< SVM_CPUID_FUNC
) {
137 *msg
= "can't execute cpuid_8000000a";
141 cpuid(0x80000001, &eax
, &ebx
, &ecx
, &edx
);
142 if (!(ecx
& (1 << SVM_CPUID_FEATURE_SHIFT
))) {
144 *msg
= "svm not available";
151 /** Disable SVM on the current CPU
153 * You should call this only if cpu_has_svm() returned true.
155 static inline void cpu_svm_disable(void)
159 wrmsrl(MSR_VM_HSAVE_PA
, 0);
160 rdmsrl(MSR_EFER
, efer
);
161 wrmsrl(MSR_EFER
, efer
& ~EFER_SVME
);
164 /** Makes sure SVM is disabled, if it is supported on the CPU
166 static inline void cpu_emergency_svm_disable(void)
168 if (cpu_has_svm(NULL
))
172 #endif /* _ASM_X86_VIRTEX_H */