OvmfPkg/XenPlatformLib: Cache result for XenDetected

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>
This commit is contained in:
Anthony PERARD 2019-08-13 12:31:10 +01:00 committed by Laszlo Ersek
parent 198a8dc9cd
commit 054c3fe9b5
1 changed files with 16 additions and 4 deletions

View File

@ -26,13 +26,25 @@ XenGetInfoHOB (
) )
{ {
EFI_HOB_GUID_TYPE *GuidHob; EFI_HOB_GUID_TYPE *GuidHob;
STATIC BOOLEAN Cached = FALSE;
STATIC EFI_XEN_INFO *XenInfo;
//
// Return the cached result for the benefit of XenDetected that can be
// called many times.
//
if (Cached) {
return XenInfo;
}
GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid); GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);
if (GuidHob == NULL) { if (GuidHob == NULL) {
return NULL; XenInfo = NULL;
} else {
XenInfo = (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);
} }
Cached = TRUE;
return (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob); return XenInfo;
} }
/** /**