From patchwork Mon Apr 8 14:23:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 10889649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8B83139A for ; Mon, 8 Apr 2019 14:29:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 908B327F90 for ; Mon, 8 Apr 2019 14:29:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84F0728385; Mon, 8 Apr 2019 14:29:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ED52D27F90 for ; Mon, 8 Apr 2019 14:29:49 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hDVFf-0002BR-0g; Mon, 08 Apr 2019 14:27:59 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hDVFd-0002AT-OS for xen-devel@lists.xenproject.org; Mon, 08 Apr 2019 14:27:57 +0000 X-Inumbo-ID: 80a7e250-5a0a-11e9-92d7-bc764e045a96 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 80a7e250-5a0a-11e9-92d7-bc764e045a96; Mon, 08 Apr 2019 14:27:56 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.60,325,1549929600"; d="scan'208";a="83010316" From: Anthony PERARD To: Date: Mon, 8 Apr 2019 15:23:50 +0100 Message-ID: <20190408142408.30419-14-anthony.perard@citrix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190408142408.30419-1-anthony.perard@citrix.com> References: <20190408142408.30419-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 13/31] OvmfPkg/Library/XenPlatformLib: New library X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony PERARD , xen-devel@lists.xenproject.org, Laszlo Ersek Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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); +}