<div dir="ltr"><div>runningOnXEN()<br><br>It is Xen not XEN. It is not capitalized.<br><br></div>Also, hypercall_xen_version() has underscore, but runningOnXEN() has camelcase.<br>Maybe runningOnXEN() should be named running_on_Xen() ?<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Feb 9, 2013 at 8:08 PM, Kevin O'Connor <span dir="ltr"><<a href="mailto:kevin@koconnor.net" target="_blank">kevin@koconnor.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Introduce standard for performing and inspecting the run-time<br>
detection of para-virtualized environments.<br>
<br>
Signed-off-by: Kevin O'Connor <<a href="mailto:kevin@koconnor.net">kevin@koconnor.net</a>><br>
---<br>
 src/Kconfig    | 14 +++++++++++---<br>
 src/misc.c     |  2 ++<br>
 src/paravirt.c |  5 +++++<br>
 src/paravirt.h | 20 ++++++++++++++++++--<br>
 src/xen.c      |  7 +++++--<br>
 5 files changed, 41 insertions(+), 7 deletions(-)<br>
<br>
diff --git a/src/Kconfig b/src/Kconfig<br>
index bbcefe0..6fd45b4 100644<br>
--- a/src/Kconfig<br>
+++ b/src/Kconfig<br>
@@ -14,9 +14,10 @@ choice<br>
             Configure as a coreboot payload.<br>
<br>
     config QEMU<br>
-        bool "Build for QEMU"<br>
+        bool "Build for QEMU/XEN/KVM/Bochs"<br>
+        select QEMU_HARDWARE<br>
         help<br>
-            Configure as QEMU bios.<br>
+            Configure for an emulated machine (QEMU, XEN, KVM, or Bochs).<br>
<br>
     config CSM<br>
        bool "Build as Compatibilty Support Module for EFI BIOS"<br>
@@ -26,9 +27,16 @@ choice<br>
<br>
 endchoice<br>
<br>
+    config QEMU_HARDWARE<br>
+        bool "Support hardware found on emulators (QEMU/XEN/KVM/Bochs)" if !QEMU<br>
+        default n<br>
+        help<br>
+            Support virtual hardware when the code detects it is<br>
+            running on an emulator.<br>
+<br>
     config XEN<br>
         depends on QEMU<br>
-        bool "Build for Xen HVM"<br>
+        bool "Support Xen HVM"<br>
         default y<br>
         help<br>
             Configure to be used by xen hvmloader, for a HVM guest.<br>
diff --git a/src/misc.c b/src/misc.c<br>
index bcc450a..3b2ffc1 100644<br>
--- a/src/misc.c<br>
+++ b/src/misc.c<br>
@@ -16,6 +16,8 @@ u32 RamSize VAR16VISIBLE;<br>
 u64 RamSizeOver4G;<br>
 // Space for bios tables built an run-time.<br>
 char BiosTableSpace[CONFIG_MAX_BIOSTABLE] __aligned(MALLOC_MIN_ALIGN) VAR16VISIBLE;<br>
+// Type of emulator platform.<br>
+int PlatformRunningOn VAR16VISIBLE;<br>
<br>
<br>
 /****************************************************************<br>
diff --git a/src/paravirt.c b/src/paravirt.c<br>
index 9022186..6e230ee 100644<br>
--- a/src/paravirt.c<br>
+++ b/src/paravirt.c<br>
@@ -24,6 +24,11 @@ int qemu_cfg_present;<br>
 void<br>
 qemu_ramsize_preinit(void)<br>
 {<br>
+    if (!CONFIG_QEMU)<br>
+        return;<br>
+<br>
+    PlatformRunningOn = PF_QEMU;<br>
+<br>
     // On emulators, get memory size from nvram.<br>
     u32 rs = ((inb_cmos(CMOS_MEM_EXTMEM2_LOW) << 16)<br>
               | (inb_cmos(CMOS_MEM_EXTMEM2_HIGH) << 24));<br>
diff --git a/src/paravirt.h b/src/paravirt.h<br>
index 4f2d5b8..d32ca13 100644<br>
--- a/src/paravirt.h<br>
+++ b/src/paravirt.h<br>
@@ -1,8 +1,24 @@<br>
 #ifndef __PV_H<br>
 #define __PV_H<br>
<br>
-#include "config.h" // CONFIG_COREBOOT<br>
-#include "util.h"<br>
+#include "config.h" // CONFIG_*<br>
+#include "util.h" // memcpy<br>
+#include "biosvar.h" // GET_GLOBAL<br>
+<br>
+// Types of paravirtualized platforms.<br>
+#define PF_QEMU     (1<<0)<br>
+#define PF_XEN      (1<<1)<br>
+<br>
+// misc.c<br>
+extern int PlatformRunningOn;<br>
+<br>
+static inline int runningOnQEMU(void) {<br>
+    return CONFIG_QEMU || (<br>
+        CONFIG_QEMU_HARDWARE && GET_GLOBAL(PlatformRunningOn) & PF_QEMU);<br>
+}<br>
+static inline int runningOnXen(void) {<br>
+    return CONFIG_XEN && GET_GLOBAL(PlatformRunningOn) & PF_XEN;<br>
+}<br>
<br>
 /* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx.  It<br>
  * should be used to determine that a VM is running under KVM.<br>
diff --git a/src/xen.c b/src/xen.c<br>
index c9759f0..e075af2 100644<br>
--- a/src/xen.c<br>
+++ b/src/xen.c<br>
@@ -6,7 +6,7 @@<br>
<br>
 #include "config.h"<br>
 #include "xen.h"<br>
-<br>
+#include "paravirt.h" // PlatformRunningOn<br>
 #include "memmap.h" // add_e820<br>
 #include "types.h" // ASM32FLAT<br>
 #include "util.h" // copy_acpi_rsdp<br>
@@ -76,8 +76,11 @@ void xen_preinit(void)<br>
             break;<br>
         }<br>
     }<br>
-    if (!xen_cpuid_base)<br>
+    if (!xen_cpuid_base) {<br>
         dprintf(1, "No Xen hypervisor found.\n");<br>
+        return;<br>
+    }<br>
+    PlatformRunningOn = PF_QEMU|PF_XEN;<br>
 }<br>
<br>
 static int hypercall_xen_version( int cmd, void *arg)<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.11.7<br>
<br>
<br>
_______________________________________________<br>
SeaBIOS mailing list<br>
<a href="mailto:SeaBIOS@seabios.org">SeaBIOS@seabios.org</a><br>
<a href="http://www.seabios.org/mailman/listinfo/seabios" target="_blank">http://www.seabios.org/mailman/listinfo/seabios</a><br>
</font></span></blockquote></div><br></div>