From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=softfail (domain: citrix.com, ip: , mailfrom: prvs=99536ed25=anthony.perard@citrix.com) Received: from SMTP03.CITRIX.COM (SMTP03.CITRIX.COM []) by groups.io with SMTP; Tue, 09 Apr 2019 04:27:48 -0700 X-IronPort-AV: E=Sophos;i="5.60,329,1549929600"; d="scan'208";a="83096420" From: "Anthony PERARD" To: CC: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Julien Grall , , Anthony PERARD Subject: [PATCH v2 13/31] OvmfPkg/Library/XenPlatformLib: New library Date: Tue, 9 Apr 2019 12:08:26 +0100 Message-ID: <20190409110844.14746-14-anthony.perard@citrix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190409110844.14746-1-anthony.perard@citrix.com> References: <20190409110844.14746-1-anthony.perard@citrix.com> MIME-Version: 1.0 Return-Path: anthony.perard@citrix.com Content-Transfer-Encoding: 8bit Content-Type: text/plain The purpose of XenPlatformPei is to regroup the few functions that are used in several places to detect if Xen is detected, and to get the XenInfo HOB. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Anthony PERARD --- OvmfPkg/XenOvmf.dsc | 1 + MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf => OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf | 27 +++---- OvmfPkg/Include/Library/XenPlatformLib.h | 59 +++++++++++++++ OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c | 75 ++++++++++++++++++++ 4 files changed, 150 insertions(+), 12 deletions(-) diff --git a/OvmfPkg/XenOvmf.dsc b/OvmfPkg/XenOvmf.dsc index cc51bac3be..9529b4834f 100644 --- a/OvmfPkg/XenOvmf.dsc +++ b/OvmfPkg/XenOvmf.dsc @@ -198,6 +198,7 @@ [LibraryClasses] SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf + XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf diff --git a/MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf similarity index 56% copy from MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf copy to OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf index 4fd4874595..ca078f7263 100644 --- a/MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf +++ b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf @@ -1,7 +1,10 @@ ## @file -# Null implementation of the SMBUS Library. +# Get information about Xen # -# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
+# This library simply allow to find out if OVMF is running under Xen and +# allow to get more information when it is the case. +# +# Copyright (c) 2019, Citrix Systems, Inc. # # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -10,26 +13,26 @@ # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. # +# ## [Defines] INF_VERSION = 0x00010005 - BASE_NAME = BaseSmbusLibNull - MODULE_UNI_FILE = BaseSmbusLibNull.uni - FILE_GUID = E2ECA273-A1C0-407E-9A5C-F10C55142196 + BASE_NAME = XenPlatformLib + FILE_GUID = DB54DBB7-8142-4EE5-9364-78C824B582EB MODULE_TYPE = BASE VERSION_STRING = 1.0 - LIBRARY_CLASS = SmbusLib - -# -# VALID_ARCHITECTURES = IA32 X64 EBC -# + LIBRARY_CLASS = XenPlatformLib [Sources] - BaseSmbusLibNull.c + XenPlatformLib.c [Packages] MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec [LibraryClasses] - DebugLib + HobLib + +[Guids] + gEfiXenInfoGuid diff --git a/OvmfPkg/Include/Library/XenPlatformLib.h b/OvmfPkg/Include/Library/XenPlatformLib.h new file mode 100644 index 0000000000..8f57450575 --- /dev/null +++ b/OvmfPkg/Include/Library/XenPlatformLib.h @@ -0,0 +1,59 @@ +/** @file +* Get information about Xen +* +* This library simply allow to find out if OVMF is running under Xen and +* allow to get more information when it is the case. +* +* Copyright (c) 2019, Citrix Systems, Inc. +* +* This program and the accompanying materials are +* licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#ifndef _XEN_PLATFORM_LIB_H_ +#define _XEN_PLATFORM_LIB_H_ + +#include + +/** + This function detects if OVMF is running on Xen. + + @retval TRUE OVMF is running on Xen + @retval FALSE Xen as not been detected +**/ +BOOLEAN +EFIAPI +XenDetected ( + VOID + ); + +/** + This function detect if OVMF have started via the PVH entry point. + + @retval TRUE PVH entry point as been used + @retval FALSE OVMF have started via the HVM route +**/ +BOOLEAN +EFIAPI +XenPvhDetected ( + VOID + ); + +/** + This function return a pointer to the XenInfo HOB. + + @return XenInfo pointer or NULL if not available +**/ +EFI_XEN_INFO * +EFIAPI +XenGetInfoHOB ( + VOID + ); + +#endif diff --git a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c new file mode 100644 index 0000000000..274ddfc9ad --- /dev/null +++ b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c @@ -0,0 +1,75 @@ +/** @file +* Get information about Xen +* +* This library simply allow to find out if OVMF is running under Xen and +* allow to get more information when it is the case. +* +* Copyright (c) 2019, Citrix Systems, Inc. +* +* This program and the accompanying materials are +* licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#include +#include +#include + +/** + This function return a pointer to the XenInfo HOB. + + @return XenInfo pointer or NULL if not available +**/ +EFI_XEN_INFO * +EFIAPI +XenGetInfoHOB ( + VOID + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + + GuidHob = GetFirstGuidHob (&gEfiXenInfoGuid); + if (GuidHob == NULL) { + return NULL; + } + + return (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob); +} + +/** + This function detects if OVMF is running on Xen. + + @retval TRUE OVMF is running on Xen + @retval FALSE Xen as not been detected +**/ +BOOLEAN +EFIAPI +XenDetected ( + VOID + ) +{ + return (XenGetInfoHOB () != NULL); +} + +/** + This function detect if OVMF have started via the PVH entry point. + + @retval TRUE PVH entry point as been used + @retval FALSE OVMF have started via the HVM route +**/ +BOOLEAN +EFIAPI +XenPvhDetected ( + VOID + ) +{ + EFI_XEN_INFO *XenInfo; + + XenInfo = XenGetInfoHOB (); + return (XenInfo != NULL && XenInfo->RsdpPvh != NULL); +} -- Anthony PERARD