]> xenbits.xensource.com Git - seabios.git/commitdiff
Convert kvm_para_available() to runningOnKVM().
authorKevin O'Connor <kevin@koconnor.net>
Sat, 9 Feb 2013 18:07:23 +0000 (13:07 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Wed, 13 Feb 2013 02:04:29 +0000 (21:04 -0500)
Make the KVM detection code use the same format as the QEMU/Xen
detection code.

Also, log when KVM is detected.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
src/paravirt.c
src/paravirt.h

index 73b06ca0f62037e626b9f648563fc66cedf872b5..7080c7f4baf7eaef3a245b78ba413192ace7037d 100644 (file)
 
 int qemu_cfg_present;
 
+/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx.  It
+ * should be used to determine that a VM is running under KVM.
+ */
+#define KVM_CPUID_SIGNATURE     0x40000000
+
+static void kvm_preinit(void)
+{
+    if (!CONFIG_QEMU)
+        return;
+    unsigned int eax, ebx, ecx, edx;
+    char signature[13];
+
+    cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
+    memcpy(signature + 0, &ebx, 4);
+    memcpy(signature + 4, &ecx, 4);
+    memcpy(signature + 8, &edx, 4);
+    signature[12] = 0;
+
+    if (strcmp(signature, "KVMKVMKVM") == 0) {
+        dprintf(1, "Running on KVM\n");
+        PlatformRunningOn |= PF_KVM;
+    }
+}
+
 void
 qemu_ramsize_preinit(void)
 {
@@ -28,6 +52,7 @@ qemu_ramsize_preinit(void)
         return;
 
     PlatformRunningOn = PF_QEMU;
+    kvm_preinit();
 
     // On emulators, get memory size from nvram.
     u32 rs = ((inb_cmos(CMOS_MEM_EXTMEM2_LOW) << 16)
@@ -60,7 +85,7 @@ qemu_ramsize_preinit(void)
             qemu_cfg_e820_load_next(&entry);
             add_e820(entry.address, entry.length, entry.type);
         }
-    } else if (kvm_para_available()) {
+    } else if (runningOnKVM()) {
         // Backwards compatibility - provide hard coded range.
         // 4 pages before the bios, 3 pages for vmx tss pages, the
         // other page for EPT real mode pagetable
index 62b1664ebdc032f16713035498d72a66acb8984a..208d0fb8eaed4f606f9c574dc20cc5a16e514a2b 100644 (file)
@@ -2,12 +2,12 @@
 #define __PV_H
 
 #include "config.h" // CONFIG_*
-#include "util.h" // memcpy
 #include "biosvar.h" // GET_GLOBAL
 
 // Types of paravirtualized platforms.
 #define PF_QEMU     (1<<0)
 #define PF_XEN      (1<<1)
+#define PF_KVM      (1<<2)
 
 // misc.c
 extern int PlatformRunningOn;
@@ -19,31 +19,11 @@ static inline int runningOnQEMU(void) {
 static inline int runningOnXen(void) {
     return CONFIG_XEN && GET_GLOBAL(PlatformRunningOn) & PF_XEN;
 }
-
-/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx.  It
- * should be used to determine that a VM is running under KVM.
- */
-#define KVM_CPUID_SIGNATURE     0x40000000
-
-static inline int kvm_para_available(void)
-{
-    if (!CONFIG_QEMU)
-        return 0;
-    unsigned int eax, ebx, ecx, edx;
-    char signature[13];
-
-    cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
-    memcpy(signature + 0, &ebx, 4);
-    memcpy(signature + 4, &ecx, 4);
-    memcpy(signature + 8, &edx, 4);
-    signature[12] = 0;
-
-    if (strcmp(signature, "KVMKVMKVM") == 0)
-        return 1;
-
-    return 0;
+static inline int runningOnKVM(void) {
+    return CONFIG_QEMU && GET_GLOBAL(PlatformRunningOn) & PF_KVM;
 }
 
+// QEMU "firmware config (fw_cfg)" interface
 #define QEMU_CFG_SIGNATURE              0x00
 #define QEMU_CFG_ID                     0x01
 #define QEMU_CFG_UUID                   0x02