]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/Library/XenPlatformLib: New library
authorAnthony PERARD <anthony.perard@citrix.com>
Tue, 13 Aug 2019 11:30:57 +0000 (12:30 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Wed, 21 Aug 2019 16:03:49 +0000 (18:03 +0200)
The purpose of XenPlatformLib is to regroup the few functions that are
used in several places to detect if Xen is detected, and to get the
XenInfo HOB.

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-14-anthony.perard@citrix.com>

Maintainers.txt
OvmfPkg/Include/Library/XenPlatformLib.h [new file with mode: 0644]
OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c [new file with mode: 0644]
OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf [new file with mode: 0644]
OvmfPkg/OvmfPkg.dec
OvmfPkg/OvmfXen.dsc

index 016523b4010479db5347a4f9ab1ef25656380f1f..f51731a6b658057b2228b89b07551afec8d60599 100644 (file)
@@ -365,6 +365,7 @@ F: OvmfPkg/Include/Guid/XenInfo.h
 F: OvmfPkg/Include/IndustryStandard/Xen/\r
 F: OvmfPkg/Include/Library/XenHypercallLib.h\r
 F: OvmfPkg/Include/Library/XenIoMmioLib.h\r
+F: OvmfPkg/Include/Library/XenPlatformLib.h\r
 F: OvmfPkg/Include/Protocol/XenBus.h\r
 F: OvmfPkg/Include/Protocol/XenIo.h\r
 F: OvmfPkg/Library/PciHostBridgeLib/XenSupport.c\r
@@ -372,6 +373,7 @@ F: OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
 F: OvmfPkg/Library/XenConsoleSerialPortLib/\r
 F: OvmfPkg/Library/XenHypercallLib/\r
 F: OvmfPkg/Library/XenIoMmioLib/\r
+F: OvmfPkg/Library/XenPlatformLib/\r
 F: OvmfPkg/OvmfXen.*\r
 F: OvmfPkg/OvmfXenElfHeaderGenerator.c\r
 F: OvmfPkg/PlatformPei/MemDetect.c\r
diff --git a/OvmfPkg/Include/Library/XenPlatformLib.h b/OvmfPkg/Include/Library/XenPlatformLib.h
new file mode 100644 (file)
index 0000000..8b8c0d0
--- /dev/null
@@ -0,0 +1,53 @@
+/** @file\r
+  Get information about Xen\r
+\r
+  This library simply allow to find out if OVMF is running under Xen and\r
+  allow to get more information when it is the case.\r
+\r
+  Copyright (c) 2019, Citrix Systems, Inc.\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef _XEN_PLATFORM_LIB_H_\r
+#define _XEN_PLATFORM_LIB_H_\r
+\r
+#include <Guid/XenInfo.h>\r
+\r
+/**\r
+  This function detects if OVMF is running on Xen.\r
+\r
+  @retval TRUE    OVMF is running on Xen\r
+  @retval FALSE   Xen has not been detected\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+XenDetected (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  This function detect if OVMF have started via the PVH entry point.\r
+\r
+  @retval TRUE  PVH entry point as been used\r
+  @retval FALSE OVMF have started via the HVM route\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+XenPvhDetected (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  This function return a pointer to the XenInfo HOB.\r
+\r
+  @return  XenInfo pointer or NULL if not available\r
+**/\r
+EFI_XEN_INFO *\r
+EFIAPI\r
+XenGetInfoHOB (\r
+  VOID\r
+  );\r
+\r
+#endif\r
diff --git a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c
new file mode 100644 (file)
index 0000000..974a0e7
--- /dev/null
@@ -0,0 +1,69 @@
+/** @file\r
+  Get information about Xen\r
+\r
+  This library simply allow to find out if OVMF is running under Xen and\r
+  allow to get more information when it is the case.\r
+\r
+  Copyright (c) 2019, Citrix Systems, Inc.\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/XenPlatformLib.h>\r
+\r
+/**\r
+  This function return a pointer to the XenInfo HOB.\r
+\r
+  @return  XenInfo pointer or NULL if not available\r
+**/\r
+EFI_XEN_INFO *\r
+EFIAPI\r
+XenGetInfoHOB (\r
+  VOID\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE  *GuidHob;\r
+\r
+  GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid);\r
+  if (GuidHob == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  return (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);\r
+}\r
+\r
+/**\r
+  This function detects if OVMF is running on Xen.\r
+\r
+  @retval TRUE    OVMF is running on Xen\r
+  @retval FALSE   Xen has not been detected\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+XenDetected (\r
+  VOID\r
+  )\r
+{\r
+  return (XenGetInfoHOB () != NULL);\r
+}\r
+\r
+/**\r
+  This function detect if OVMF have started via the PVH entry point.\r
+\r
+  @retval TRUE  PVH entry point as been used\r
+  @retval FALSE OVMF have started via the HVM route\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+XenPvhDetected (\r
+  VOID\r
+  )\r
+{\r
+  EFI_XEN_INFO        *XenInfo;\r
+\r
+  XenInfo = XenGetInfoHOB ();\r
+  return (XenInfo != NULL && XenInfo->RsdpPvh != NULL);\r
+}\r
diff --git a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf
new file mode 100644 (file)
index 0000000..32adb24
--- /dev/null
@@ -0,0 +1,33 @@
+## @file\r
+#  Get information about Xen\r
+#\r
+#  This library simply allow to find out if OVMF is running under Xen and\r
+#  allow to get more information when it is the case.\r
+#\r
+#  Copyright (c) 2019, Citrix Systems, Inc.\r
+#\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = XenPlatformLib\r
+  FILE_GUID                      = DB54DBB7-8142-4EE5-9364-78C824B582EB\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = XenPlatformLib\r
+\r
+[Sources]\r
+  XenPlatformLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+  HobLib\r
+\r
+[Guids]\r
+  gEfiXenInfoGuid\r
index c2a2ebfb958740d1c6942d1fc977b55f67ee4984..04d5e29272f1ef7581718be1390c8bfe22474a64 100644 (file)
   #\r
   XenIoMmioLib|Include/Library/XenIoMmioLib.h\r
 \r
+  ##  @libraryclass  Get information about Xen\r
+  #\r
+  XenPlatformLib|Include/Library/XenPlatformLib.h\r
+\r
 [Guids]\r
   gUefiOvmfPkgTokenSpaceGuid          = {0x93bb96af, 0xb9f2, 0x4eb8, {0x94, 0x62, 0xe0, 0xba, 0x74, 0x56, 0x42, 0x36}}\r
   gEfiXenInfoGuid                     = {0xd3b46f3b, 0xd441, 0x1244, {0x9a, 0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}}\r
index b40d39e003b8a3fce6182f9def78cd029514c87a..22970eda5defb0d63ee95e255852f55b1b2ddf8c 100644 (file)
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf\r
   OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf\r
   XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf\r
+  XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf\r
 \r
   Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf\r
   TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf\r