From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: citrix.com, ip: 216.71.145.153, mailfrom: anthony.perard@citrix.com) Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by groups.io with SMTP; Thu, 04 Jul 2019 07:57:40 -0700 Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: qXky3MaPYhAU7QB2RFNuWs81jhFH2ycO3CKrQI7Yn0ZeCQ5frQ0IVxy5mXzl6Rlv3S+uZLWn4f IXoigpNYnsdObYGHu/VR0pH3yUO1D52boaJSeIPFBbfbxwAW+w2BvUanWe8stuG0DbjL6RFC1p Gof9xaZgig7zXVm/flmtVJegEfZfCUDiCXWrUTLS0QCirBvWc+sEQ4IaUu65PgzPnmBLZHJTur IEjtT3oF649zDneyXoUbCnHztVgh8RzS4bjv7oFqdGPDSOlXkG41yDAkP5TxuGm0nED4gjKtgT 3e8= X-SBRS: 2.7 X-MesageID: 2589134 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.63,451,1557201600"; d="scan'208";a="2589134" From: "Anthony PERARD" To: CC: , Ard Biesheuvel , Jordan Justen , Laszlo Ersek , Julien Grall , Anthony PERARD Subject: [PATCH v3 13/35] OvmfPkg/Library/XenPlatformLib: New library Date: Thu, 4 Jul 2019 15:42:11 +0100 Message-ID: <20190704144233.27968-14-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190704144233.27968-1-anthony.perard@citrix.com> References: <20190704144233.27968-1-anthony.perard@citrix.com> MIME-Version: 1.0 Return-Path: anthony.perard@citrix.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain 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=3D1689 Signed-off-by: Anthony PERARD --- Notes: v3: - use SPDX - add XenPlatformLib.h to [LibraryClasses] in OvmfPkg.dec - fix typos OvmfPkg/OvmfPkg.dec | 4 ++ OvmfPkg/OvmfXen.dsc | 1 + .../Library/XenPlatformLib/XenPlatformLib.inf | 33 +++++++++ OvmfPkg/Include/Library/XenPlatformLib.h | 53 ++++++++++++++ .../Library/XenPlatformLib/XenPlatformLib.c | 69 +++++++++++++++++++ 5 files changed, 160 insertions(+) create mode 100644 OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf create mode 100644 OvmfPkg/Include/Library/XenPlatformLib.h create mode 100644 OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index c2a2ebfb95..04d5e29272 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -70,6 +70,10 @@ [LibraryClasses] #=0D XenIoMmioLib|Include/Library/XenIoMmioLib.h=0D =0D + ## @libraryclass Get information about Xen=0D + #=0D + XenPlatformLib|Include/Library/XenPlatformLib.h=0D +=0D [Guids]=0D gUefiOvmfPkgTokenSpaceGuid =3D {0x93bb96af, 0xb9f2, 0x4eb8, {0x= 94, 0x62, 0xe0, 0xba, 0x74, 0x56, 0x42, 0x36}}=0D gEfiXenInfoGuid =3D {0xd3b46f3b, 0xd441, 0x1244, {0x= 9a, 0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}}=0D diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 6288394eb8..68d82da7aa 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -195,6 +195,7 @@ [LibraryClasses] SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf=0D OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib= /BaseOrderedCollectionRedBlackTreeLib.inf=0D XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf=0D + XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf=0D =0D Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeT= cg2PhysicalPresenceLib.inf=0D =0D diff --git a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf b/OvmfPkg/Li= brary/XenPlatformLib/XenPlatformLib.inf new file mode 100644 index 0000000000..32adb246d6 --- /dev/null +++ b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf @@ -0,0 +1,33 @@ +## @file=0D +# Get information about Xen=0D +#=0D +# This library simply allow to find out if OVMF is running under Xen and= =0D +# allow to get more information when it is the case.=0D +#=0D +# Copyright (c) 2019, Citrix Systems, Inc.=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D XenPlatformLib=0D + FILE_GUID =3D DB54DBB7-8142-4EE5-9364-78C824B582EB= =0D + MODULE_TYPE =3D BASE=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D XenPlatformLib=0D +=0D +[Sources]=0D + XenPlatformLib.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + OvmfPkg/OvmfPkg.dec=0D +=0D +[LibraryClasses]=0D + HobLib=0D +=0D +[Guids]=0D + gEfiXenInfoGuid=0D diff --git a/OvmfPkg/Include/Library/XenPlatformLib.h b/OvmfPkg/Include/Lib= rary/XenPlatformLib.h new file mode 100644 index 0000000000..a8347602b7 --- /dev/null +++ b/OvmfPkg/Include/Library/XenPlatformLib.h @@ -0,0 +1,53 @@ +/** @file=0D +* Get information about Xen=0D +*=0D +* This library simply allow to find out if OVMF is running under Xen and= =0D +* allow to get more information when it is the case.=0D +*=0D +* Copyright (c) 2019, Citrix Systems, Inc.=0D +*=0D +* SPDX-License-Identifier: BSD-2-Clause-Patent=0D +*=0D +**/=0D +=0D +#ifndef _XEN_PLATFORM_LIB_H_=0D +#define _XEN_PLATFORM_LIB_H_=0D +=0D +#include =0D +=0D +/**=0D + This function detects if OVMF is running on Xen.=0D +=0D + @retval TRUE OVMF is running on Xen=0D + @retval FALSE Xen has not been detected=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +XenDetected (=0D + VOID=0D + );=0D +=0D +/**=0D + This function detect if OVMF have started via the PVH entry point.=0D +=0D + @retval TRUE PVH entry point as been used=0D + @retval FALSE OVMF have started via the HVM route=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +XenPvhDetected (=0D + VOID=0D + );=0D +=0D +/**=0D + This function return a pointer to the XenInfo HOB.=0D +=0D + @return XenInfo pointer or NULL if not available=0D +**/=0D +EFI_XEN_INFO *=0D +EFIAPI=0D +XenGetInfoHOB (=0D + VOID=0D + );=0D +=0D +#endif=0D diff --git a/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c b/OvmfPkg/Libr= ary/XenPlatformLib/XenPlatformLib.c new file mode 100644 index 0000000000..6f27cbffa8 --- /dev/null +++ b/OvmfPkg/Library/XenPlatformLib/XenPlatformLib.c @@ -0,0 +1,69 @@ +/** @file=0D +* Get information about Xen=0D +*=0D +* This library simply allow to find out if OVMF is running under Xen and= =0D +* allow to get more information when it is the case.=0D +*=0D +* Copyright (c) 2019, Citrix Systems, Inc.=0D +*=0D +* SPDX-License-Identifier: BSD-2-Clause-Patent=0D +*=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +=0D +/**=0D + This function return a pointer to the XenInfo HOB.=0D +=0D + @return XenInfo pointer or NULL if not available=0D +**/=0D +EFI_XEN_INFO *=0D +EFIAPI=0D +XenGetInfoHOB (=0D + VOID=0D + )=0D +{=0D + EFI_HOB_GUID_TYPE *GuidHob;=0D +=0D + GuidHob =3D GetFirstGuidHob (&gEfiXenInfoGuid);=0D + if (GuidHob =3D=3D NULL) {=0D + return NULL;=0D + }=0D +=0D + return (EFI_XEN_INFO *) GET_GUID_HOB_DATA (GuidHob);=0D +}=0D +=0D +/**=0D + This function detects if OVMF is running on Xen.=0D +=0D + @retval TRUE OVMF is running on Xen=0D + @retval FALSE Xen has not been detected=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +XenDetected (=0D + VOID=0D + )=0D +{=0D + return (XenGetInfoHOB () !=3D NULL);=0D +}=0D +=0D +/**=0D + This function detect if OVMF have started via the PVH entry point.=0D +=0D + @retval TRUE PVH entry point as been used=0D + @retval FALSE OVMF have started via the HVM route=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +XenPvhDetected (=0D + VOID=0D + )=0D +{=0D + EFI_XEN_INFO *XenInfo;=0D +=0D + XenInfo =3D XenGetInfoHOB ();=0D + return (XenInfo !=3D NULL && XenInfo->RsdpPvh !=3D NULL);=0D +}=0D --=20 Anthony PERARD