]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/XenPlatformLib: Cache result for XenDetected
authorAnthony PERARD <anthony.perard@citrix.com>
Tue, 13 Aug 2019 11:31:10 +0000 (12:31 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Wed, 21 Aug 2019 16:03:49 +0000 (18:03 +0200)
We are going to replace XenDetected() implementation in
PlatformBootManagerLib by the one in XenPlatformLib.
PlatformBootManagerLib's implementation does cache the result of
GetFirstGuidHob(), so we do something similar in XenPlatformLib.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20190813113119.14804-27-anthony.perard@citrix.com>

OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c

index 974a0e73f189a8988f0b0319c777d9070a612466..8f20ae2d456ee329233d2253cc32661859ca78d3 100644 (file)
@@ -25,14 +25,26 @@ XenGetInfoHOB (
   VOID\r
   )\r
 {\r
-  EFI_HOB_GUID_TYPE  *GuidHob;\r
+  EFI_HOB_GUID_TYPE   *GuidHob;\r
+  STATIC BOOLEAN      Cached = FALSE;\r
+  STATIC EFI_XEN_INFO *XenInfo;\r
+\r
+  //\r
+  // Return the cached result for the benefit of XenDetected that can be\r
+  // called many times.\r
+  //\r
+  if (Cached) {\r
+    return XenInfo;\r
+  }\r
 \r
   GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);\r
   if (GuidHob == NULL) {\r
-    return NULL;\r
+    XenInfo = NULL;\r
+  } else {\r
+    XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);\r
   }\r
-\r
-  return (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);\r
+  Cached = TRUE;\r
+  return XenInfo;\r
 }\r
 \r
 /**\r