Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <[email protected]>
---
 OvmfPkg/PlatformPei/Platform.c |  5 ++---
 OvmfPkg/PlatformPei/Platform.h |  4 ++--
 OvmfPkg/PlatformPei/Xen.c      | 34 +++++++++++++++++++++++-----------
 3 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index 7ba4ab2..1eab41f 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -410,7 +410,6 @@ InitializePlatform (
   )
 {
   EFI_PHYSICAL_ADDRESS  TopOfMemory;
-  UINT32 XenLeaf;
 
   TopOfMemory = 0;
 
@@ -418,7 +417,7 @@ InitializePlatform (
 
   DebugDumpCmos ();
 
-  XenLeaf = XenDetect ();
+  XenDetect ();
 
   PublishPeiMemory ();
 
@@ -430,7 +429,7 @@ InitializePlatform (
 
   if (mXen) {
     DEBUG ((EFI_D_INFO, "Xen was detected\n"));
-    InitializeXen (XenLeaf);
+    InitializeXen ();
   }
 
   ReserveEmuVariableNvStore ();
diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h
index cc371c5..4b72ee6 100644
--- a/OvmfPkg/PlatformPei/Platform.h
+++ b/OvmfPkg/PlatformPei/Platform.h
@@ -76,10 +76,10 @@ PeiFvInitialization (
 
 EFI_STATUS
 InitializeXen (
-  UINT32 XenLeaf
+  VOID
   );
 
-UINT32
+BOOLEAN
 XenDetect (
   VOID
   );
diff --git a/OvmfPkg/PlatformPei/Xen.c b/OvmfPkg/PlatformPei/Xen.c
index 0f75fa7..da3133b 100644
--- a/OvmfPkg/PlatformPei/Xen.c
+++ b/OvmfPkg/PlatformPei/Xen.c
@@ -33,6 +33,8 @@
 
 BOOLEAN mXen = FALSE;
 
+STATIC UINT32 mXenLeaf = 0;
+
 EFI_XEN_INFO mXenInfo;
 
 /**
@@ -114,31 +116,37 @@ XenConnect (
 /**
   Figures out if we are running inside Xen HVM.
 
-  @return UINT32     CPUID index used to connect to HV.
+  @retval TRUE   Xen was detected
+  @retval FALSE  Xen was not detected
 
 **/
-UINT32
+BOOLEAN
 XenDetect (
   VOID
   )
 {
-
-  UINT32 XenLeaf;
   UINT8 Signature[13];
 
-  for (XenLeaf = 0x40000000; XenLeaf < 0x40010000; XenLeaf += 0x100) {
-    AsmCpuid (XenLeaf, NULL, (UINT32 *) &Signature[0],
+  if (mXenLeaf != 0) {
+    return TRUE;
+  }
+
+  Signature[12] = '\0';
+  for (mXenLeaf = 0x40000000; mXenLeaf < 0x40010000; mXenLeaf += 0x100) {
+    AsmCpuid (mXenLeaf,
+              NULL,
+              (UINT32 *) &Signature[0],
               (UINT32 *) &Signature[4],
               (UINT32 *) &Signature[8]);
-    Signature[12] = '\0';
 
     if (!AsciiStrCmp ((CHAR8 *) Signature, "XenVMMXenVMM")) {
       mXen = TRUE;
-      return XenLeaf;
+      return TRUE;
     }
   }
 
-  return 0;
+  mXenLeaf = 0;
+  return FALSE;
 }
 
 /**
@@ -150,10 +158,14 @@ XenDetect (
 **/
 EFI_STATUS
 InitializeXen (
-  UINT32 XenLeaf
+  VOID
   )
 {
-  XenConnect (XenLeaf);
+  if (mXenLeaf == 0) {
+    return EFI_NOT_FOUND;
+  }
+
+  XenConnect (mXenLeaf);
 
   //
   // Reserve away HVMLOADER reserved memory [0xFC000000,0xFD000000).
-- 
1.8.5.3


------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable 
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to