summaryrefslogtreecommitdiffstats
path: root/arch/x86/include/asm
diff options
context:
space:
mode:
authorEduardo Habkost <ehabkost@redhat.com>2008-11-17 22:03:20 +0100
committerAvi Kivity <avi@redhat.com>2008-12-31 15:52:29 +0100
commit63d1142f8f69e39468bc6079ab2239e902828134 (patch)
tree1f6b12fca77403b7ee3323b2ef18ef53e5593094 /arch/x86/include/asm
parentx86: cpu_emergency_vmxoff() function (diff)
downloadlinux-63d1142f8f69e39468bc6079ab2239e902828134.tar.xz
linux-63d1142f8f69e39468bc6079ab2239e902828134.zip
KVM: SVM: move has_svm() code to asm/virtext.h
Use a trick to keep the printk()s on has_svm() working as before. gcc will take care of not generating code for the 'msg' stuff when the function is called with a NULL msg argument. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/include/asm')
-rw-r--r--arch/x86/include/asm/virtext.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/arch/x86/include/asm/virtext.h b/arch/x86/include/asm/virtext.h
index 6bcf0acb4ef1..6f0d409c3682 100644
--- a/arch/x86/include/asm/virtext.h
+++ b/arch/x86/include/asm/virtext.h
@@ -19,6 +19,7 @@
#include <asm/system.h>
#include <asm/vmx.h>
+#include <asm/svm.h>
/*
* VMX functions:
@@ -66,4 +67,44 @@ static inline void cpu_emergency_vmxoff(void)
__cpu_emergency_vmxoff();
}
+
+
+
+/*
+ * SVM functions:
+ */
+
+/** Check if the CPU has SVM support
+ *
+ * You can use the 'msg' arg to get a message describing the problem,
+ * if the function returns zero. Simply pass NULL if you are not interested
+ * on the messages; gcc should take care of not generating code for
+ * the messages on this case.
+ */
+static inline int cpu_has_svm(const char **msg)
+{
+ uint32_t eax, ebx, ecx, edx;
+
+ if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) {
+ if (msg)
+ *msg = "not amd";
+ return 0;
+ }
+
+ cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
+ if (eax < SVM_CPUID_FUNC) {
+ if (msg)
+ *msg = "can't execute cpuid_8000000a";
+ return 0;
+ }
+
+ cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
+ if (!(ecx & (1 << SVM_CPUID_FEATURE_SHIFT))) {
+ if (msg)
+ *msg = "svm not available";
+ return 0;
+ }
+ return 1;
+}
+
#endif /* _ASM_X86_VIRTEX_H */