From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Thu, 11 Apr 2019 05:10:57 -0700 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 31785307D979; Thu, 11 Apr 2019 12:10:56 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-225.rdu2.redhat.com [10.10.120.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DA34605AF; Thu, 11 Apr 2019 12:10:52 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v2 13/31] OvmfPkg/Library/XenPlatformLib: New library To: devel@edk2.groups.io, anthony.perard@citrix.com Cc: Jordan Justen , Ard Biesheuvel , Julien Grall , xen-devel@lists.xenproject.org References: <20190409110844.14746-1-anthony.perard@citrix.com> <20190409110844.14746-14-anthony.perard@citrix.com> From: "Laszlo Ersek" Message-ID: <1a61482b-68a8-76fa-409f-ac3f87aedb52@redhat.com> Date: Thu, 11 Apr 2019 14:10:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190409110844.14746-14-anthony.perard@citrix.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 11 Apr 2019 12:10:56 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 04/09/19 13:08, Anthony PERARD wrote: > The purpose of XenPlatformPei is to regroup the few functions that are (1) did you mean XenPlatformLib here? > 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 obviously this is a false positive for git's "--find-copies-harder", but I can look at the file in isolation using your git branch... (3) Please use "SPDX-License-Identifier: BSD-2-Clause-Patent", rather than the open-coded 2-clause BSDL. (This applies to other new files in this patch as well.) [...] > 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 (4) "has" not been detected ... same for the function definition as well, in the .c file below. (5) At the introduction of a new library class, we should update the [LibraryClasses] section in the "OvmfPkg/OvmfPkg.dec" file. I think you can add this new class under XenHypercallLib and XenIoMmioLib there. (To confirm, I'm not speaking about the .dsc file, but the .dec file.) Thanks Laszlo > +**/ > +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); > +} >