From nobody Fri Apr 19 10:26:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+73755+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+73755+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1617764803; cv=none; d=zohomail.com; s=zohoarc; b=eZX4nVPLmr6P49HiGU4W13bB4opRn3Ff6HTl9WTgQCzERcrPzoAZSAU9aE1fZdoSW+MCRj9xYLQUKNtieF+jdWbmZrisJ07nFGZj1LTufng5FB/yQcpkJeJpvFbVtxiaKdsR/QiuT3jq1LSbr8fsnEwIImtzh+sUyGlZoUV8l5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617764803; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Ik3LqfS230xRliL3XWCMuS41iqsYn/9rFvRe+wglOtU=; b=cUHD4S4zz4v4PVdz1n7i5q/gW7eitKQUuy2xlPeQGJYIMtSm1X7qSkAZRZLq2w9kcU+FiuJSiRDRapofRCzEFxZN3557sD0TMrFjcMkkBoJxOilcFAEtFLlqnglkgk4OLj5T4BWtw5P2YqfIXPUXEQgX98P27huF2Gi/pulPYOk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+73755+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1617764803330624.4520926188166; Tue, 6 Apr 2021 20:06:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8aIYYY1788612xcmP8qGvLrn; Tue, 06 Apr 2021 20:06:42 -0700 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web10.2005.1617764802326915683 for ; Tue, 06 Apr 2021 20:06:42 -0700 IronPort-SDR: 8riuzGoWLZhxhilts4C1V7e347thgCeCBudR71LL/YRKT5a4iPo7kLzLTzOPmnWiPJdhxtdo6j 95+z9vdTxQog== X-IronPort-AV: E=McAfee;i="6000,8403,9946"; a="213587416" X-IronPort-AV: E=Sophos;i="5.82,201,1613462400"; d="scan'208";a="213587416" X-Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Apr 2021 20:06:41 -0700 IronPort-SDR: 3oeWEWMbiKweNZJ14uPOInrM0ACNhnYw8HVrNpdx8mZFf9//KO9LGueLeAD84ljHpJ7lwQnZAt GdsaeN4gtljw== X-IronPort-AV: E=Sophos;i="5.82,201,1613462400"; d="scan'208";a="448896640" X-Received: from nldesimo-desk1.amr.corp.intel.com ([10.209.7.29]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Apr 2021 20:06:38 -0700 From: "Nate DeSimone" To: devel@edk2.groups.io Cc: Chasel Chiu , Liming Gao , Eric Dong , Michael Kubacki , Isaac Oram Subject: [edk2-devel] [edk2-platforms] [PATCH v4 1/4] MinPlatformPkg: Add VariableReadLib Date: Tue, 6 Apr 2021 20:04:23 -0700 Message-Id: <20210407030426.8075-2-nathaniel.l.desimone@intel.com> In-Reply-To: <20210407030426.8075-1-nathaniel.l.desimone@intel.com> References: <20210407030426.8075-1-nathaniel.l.desimone@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,nathaniel.l.desimone@intel.com X-Gm-Message-State: 5tB8q2aZXbzdwFeJYjVhAVQax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1617764802; bh=ubvUA0U6i8GIpk8JZz7eY8XlxnQbUj4nJPMbXcqMRiQ=; h=Cc:Date:From:Reply-To:Subject:To; b=rPavODm/oRymCIzeMjGVnqshiSkXtEtt9AKb+7j/GzMuY2mrNwOk1isaL/6oZJHNW2Y mQYuJODMPjl/W7Jl14Gwyz7mohugsvaC5C4Zsk3K2YrKELZwKogAavWx9/XPRWQtUYnsg L83Dkr8+IDr0miKDSkdu96OJPMXCq2u9QyQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" VariableReadLib is a phase agnostic libary for reading UEFI Variables. This library provides the MinGetVariable() and MinGetNextVariableName() APIs which are usable PEI, DXE, and SMM. Cc: Chasel Chiu Cc: Liming Gao Cc: Eric Dong Cc: Michael Kubacki Cc: Isaac Oram Signed-off-by: Nate DeSimone Reviewed-by: Isaac Oram --- .../MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc | 10 +- .../MinPlatformPkg/Include/Dsc/CorePeiLib.dsc | 9 +- .../Include/Library/VariableReadLib.h | 94 +++++++++++ .../DxeRuntimeVariableReadLib.c | 117 +++++++++++++ .../DxeRuntimeVariableReadLib.inf | 41 +++++ .../PeiVariableReadLib/PeiVariableReadLib.c | 155 ++++++++++++++++++ .../PeiVariableReadLib/PeiVariableReadLib.inf | 42 +++++ .../SmmVariableReadCommon.c | 116 +++++++++++++ .../StandaloneMmVariableReadLib.inf | 50 ++++++ .../StandaloneMmVariableReadLibConstructor.c | 51 ++++++ .../TraditionalMmVariableReadLib.inf | 49 ++++++ .../TraditionalMmVariableReadLibConstructor.c | 51 ++++++ .../Intel/MinPlatformPkg/MinPlatformPkg.dsc | 3 +- 13 files changed, 780 insertions(+), 8 deletions(-) create mode 100644 Platform/Intel/MinPlatformPkg/Include/Library/VariableR= eadLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariabl= eReadLib/DxeRuntimeVariableReadLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariabl= eReadLib/DxeRuntimeVariableReadLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLi= b/PeiVariableReadLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLi= b/PeiVariableReadLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLi= b/SmmVariableReadCommon.c create mode 100644 Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLi= b/StandaloneMmVariableReadLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLi= b/StandaloneMmVariableReadLibConstructor.c create mode 100644 Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLi= b/TraditionalMmVariableReadLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLi= b/TraditionalMmVariableReadLibConstructor.c diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc b/Pla= tform/Intel/MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc index fa9098d525..0db1250ab7 100644 --- a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc +++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc @@ -1,7 +1,7 @@ ## @file # Platform description. # -# Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -11,7 +11,7 @@ # # Generic EDKII Lib # - =20 + # # DXE phase common # @@ -23,7 +23,7 @@ ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExt= ractGuidedSectionLib.inf =20 HstiLib|MdePkg/Library/DxeHstiLib/DxeHstiLib.inf - =20 + LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf =20 CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf @@ -46,6 +46,9 @@ =20 VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 +[LibraryClasses.common.DXE_CORE, LibraryClasses.common.DXE_DRIVER, Library= Classes.common.DXE_RUNTIME_DRIVER, LibraryClasses.common.UEFI_DRIVER, Libra= ryClasses.common.UEFI_APPLICATION] + VariableReadLib|MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRunt= imeVariableReadLib.inf + [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeC= oreMemoryAllocationLib.inf @@ -89,6 +92,7 @@ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuE= xceptionHandlerLib.inf Tcg2PhysicalPresenceLib|SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/S= mmTcg2PhysicalPresenceLib.inf BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf + VariableReadLib|MinPlatformPkg/Library/SmmVariableReadLib/TraditionalMmV= ariableReadLib.inf =20 [LibraryClasses.common.SMM_CORE] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiLib.dsc b/Pla= tform/Intel/MinPlatformPkg/Include/Dsc/CorePeiLib.dsc index 2bcaed05a1..d64873ac6d 100644 --- a/Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiLib.dsc +++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiLib.dsc @@ -1,7 +1,7 @@ ## @file # Platform description. # -# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -10,11 +10,11 @@ # # Generic EDKII Lib # - =20 + # # PEI phase common # - =20 + [LibraryClasses.common.SEC,LibraryClasses.common.PEI_CORE,LibraryClasses.c= ommon.PEIM] S3BootScriptLib|MdePkg/Library/BaseS3BootScriptLibNull/BaseS3BootScriptL= ibNull.inf PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf @@ -52,7 +52,7 @@ !if gMinPlatformPkgTokenSpaceGuid.PcdPerformanceEnable =3D=3D TRUE PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.= inf !endif - =20 + [LibraryClasses.common.PEIM] CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiC= puExceptionHandlerLib.inf TimerLib|PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf @@ -70,3 +70,4 @@ !if gMinPlatformPkgTokenSpaceGuid.PcdPerformanceEnable =3D=3D TRUE PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.= inf !endif + VariableReadLib|MinPlatformPkg/Library/PeiVariableReadLib/PeiVariableRea= dLib.inf diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/VariableReadLib.= h b/Platform/Intel/MinPlatformPkg/Include/Library/VariableReadLib.h new file mode 100644 index 0000000000..b0b5ce7979 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Include/Library/VariableReadLib.h @@ -0,0 +1,94 @@ +/** @file + Variable Read Lib + + This library provides phase agnostic access to the UEFI Variable Service= s. + This is done by implementing a wrapper on top of the phase specific mech= anism + for reading from UEFI variables. For example, the PEI implementation of = this + library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation acc= esses + the UEFI Runtime Services Table, and the SMM implementation uses + EFI_SMM_VARIABLE_PROTOCOL. + + Using this library allows code to be written in a generic manner that ca= n be + used in PEI, DXE, or SMM without modification. + + Copyright (c) 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _VARIABLE_READ_LIB_H_ +#define _VARIABLE_READ_LIB_H_ + +#include + +/** + Returns the value of a variable. + + @param[in] VariableName A Null-terminated string that is the name= of the vendor's + variable. + @param[in] VendorGuid A unique identifier for the vendor. + @param[out] Attributes If not NULL, a pointer to the memory loca= tion to return the + attributes bitmask for the variable. + @param[in, out] DataSize On input, the size in bytes of the return= Data buffer. + On output the size of data returned in Da= ta. + @param[out] Data The buffer to return the contents of the = variable. May be NULL + with a zero DataSize in order to determin= e the size buffer needed. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The variable was not found. + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER DataSize is NULL. + @retval EFI_INVALID_PARAMETER The DataSize is not too small and Data is= NULL. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due t= o a hardware error. + @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due t= o an authentication failure. + @retval EFI_UNSUPPORTED This function is not implemented by this = instance of the LibraryClass + +**/ +EFI_STATUS +EFIAPI +VarLibGetVariable ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT UINT32 *Attributes, OPTIONAL + IN OUT UINTN *DataSize, + OUT VOID *Data OPTIONAL + ); + +/** + Enumerates the current variable names. + + @param[in, out] VariableNameSize The size of the VariableName buffer. T= he size must be large + enough to fit input string supplied in= VariableName buffer. + @param[in, out] VariableName On input, supplies the last VariableNa= me that was returned + by GetNextVariableName(). On output, r= eturns the Nullterminated + string of the current variable. + @param[in, out] VendorGuid On input, supplies the last VendorGuid= that was returned by + GetNextVariableName(). On output, retu= rns the + VendorGuid of the current variable. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The next variable was not found. + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the = result. + VariableNameSize has been updated with the= size needed to complete the request. + @retval EFI_INVALID_PARAMETER VariableNameSize is NULL. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER The input values of VariableName and Vendo= rGuid are not a name and + GUID of an existing variable. + @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first = VariableNameSize bytes of + the input VariableName buffer. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due to= a hardware error. + @retval EFI_UNSUPPORTED This function is not implemented by this i= nstance of the LibraryClass + +**/ +EFI_STATUS +EFIAPI +VarLibGetNextVariableName ( + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VendorGuid + ); + +#endif // _VARIABLE_READ_LIB_H_ diff --git a/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLi= b/DxeRuntimeVariableReadLib.c b/Platform/Intel/MinPlatformPkg/Library/DxeRu= ntimeVariableReadLib/DxeRuntimeVariableReadLib.c new file mode 100644 index 0000000000..eca766dbce --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRu= ntimeVariableReadLib.c @@ -0,0 +1,117 @@ +/** @file + DXE Variable Read Lib + + This library provides phase agnostic access to the UEFI Variable Service= s. + This is done by implementing a wrapper on top of the phase specific mech= anism + for reading from UEFI variables. For example, the PEI implementation of = this + library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation acc= esses + the UEFI Runtime Services Table, and the SMM implementation uses + EFI_SMM_VARIABLE_PROTOCOL. + + Using this library allows code to be written in a generic manner that ca= n be + used in PEI, DXE, or SMM without modification. + + Copyright (c) 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include + +/** + Returns the value of a variable. + + @param[in] VariableName A Null-terminated string that is the name= of the vendor's + variable. + @param[in] VendorGuid A unique identifier for the vendor. + @param[out] Attributes If not NULL, a pointer to the memory loca= tion to return the + attributes bitmask for the variable. + @param[in, out] DataSize On input, the size in bytes of the return= Data buffer. + On output the size of data returned in Da= ta. + @param[out] Data The buffer to return the contents of the = variable. May be NULL + with a zero DataSize in order to determin= e the size buffer needed. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The variable was not found. + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER DataSize is NULL. + @retval EFI_INVALID_PARAMETER The DataSize is not too small and Data is= NULL. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due t= o a hardware error. + @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due t= o an authentication failure. + @retval EFI_UNSUPPORTED This function is not implemented by this = instance of the LibraryClass + +**/ +EFI_STATUS +EFIAPI +VarLibGetVariable ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT UINT32 *Attributes, OPTIONAL + IN OUT UINTN *DataSize, + OUT VOID *Data OPTIONAL + ) +{ + EFI_STATUS Status =3D EFI_UNSUPPORTED; + + if (gRT !=3D NULL) { + Status =3D gRT->GetVariable ( + VariableName, + VendorGuid, + Attributes, + DataSize, + Data + ); + } + return Status; +} + +/** + Enumerates the current variable names. + + @param[in, out] VariableNameSize The size of the VariableName buffer. T= he size must be large + enough to fit input string supplied in= VariableName buffer. + @param[in, out] VariableName On input, supplies the last VariableNa= me that was returned + by GetNextVariableName(). On output, r= eturns the Nullterminated + string of the current variable. + @param[in, out] VendorGuid On input, supplies the last VendorGuid= that was returned by + GetNextVariableName(). On output, retu= rns the + VendorGuid of the current variable. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The next variable was not found. + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the = result. + VariableNameSize has been updated with the= size needed to complete the request. + @retval EFI_INVALID_PARAMETER VariableNameSize is NULL. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER The input values of VariableName and Vendo= rGuid are not a name and + GUID of an existing variable. + @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first = VariableNameSize bytes of + the input VariableName buffer. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due to= a hardware error. + @retval EFI_UNSUPPORTED This function is not implemented by this i= nstance of the LibraryClass + +**/ +EFI_STATUS +EFIAPI +VarLibGetNextVariableName ( + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VendorGuid + ) +{ + EFI_STATUS Status =3D EFI_UNSUPPORTED; + + if (gRT !=3D NULL) { + Status =3D gRT->GetNextVariableName ( + VariableNameSize, + VariableName, + VendorGuid + ); + } + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLi= b/DxeRuntimeVariableReadLib.inf b/Platform/Intel/MinPlatformPkg/Library/Dxe= RuntimeVariableReadLib/DxeRuntimeVariableReadLib.inf new file mode 100644 index 0000000000..848b76344b --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRu= ntimeVariableReadLib.inf @@ -0,0 +1,41 @@ +## @file +# Component description file for DXE Variable Read Lib +# +# This library provides phase agnostic access to the UEFI Variable Service= s. +# This is done by implementing a wrapper on top of the phase specific mech= anism +# for reading from UEFI variables. For example, the PEI implementation of = this +# library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation acc= esses +# the UEFI Runtime Services Table, and the SMM implementation uses +# EFI_SMM_VARIABLE_PROTOCOL. +# +# Using this library allows code to be written in a generic manner that ca= n be +# used in PEI, DXE, or SMM without modification. +# +# Copyright (c) 2021, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DxeRuntimeVariableReadLib + FILE_GUID =3D 9C357AD8-2BF4-450C-9E65-C0938F6D2424 + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D DXE_RUNTIME_DRIVER + LIBRARY_CLASS =3D VariableReadLib|DXE_CORE DXE_DRIVER D= XE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER + +[Packages] + MdePkg/MdePkg.dec + +[Sources] + DxeRuntimeVariableReadLib.c + +[LibraryClasses] + UefiRuntimeServicesTableLib + +[Protocols] + gEfiVariableArchProtocolGuid ## CONSUMES + +[Depex] + gEfiVariableArchProtocolGuid diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLib/PeiVa= riableReadLib.c b/Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLib/= PeiVariableReadLib.c new file mode 100644 index 0000000000..5eeee12a3c --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLib/PeiVariableR= eadLib.c @@ -0,0 +1,155 @@ +/** @file + PEI Variable Read Lib + + This library provides phase agnostic access to the UEFI Variable Service= s. + This is done by implementing a wrapper on top of the phase specific mech= anism + for reading from UEFI variables. For example, the PEI implementation of = this + library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation acc= esses + the UEFI Runtime Services Table, and the SMM implementation uses + EFI_SMM_VARIABLE_PROTOCOL. + + Using this library allows code to be written in a generic manner that ca= n be + used in PEI, DXE, or SMM without modification. + + Copyright (c) 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +#include +#include + +/** + Returns the value of a variable. + + @param[in] VariableName A Null-terminated string that is the name= of the vendor's + variable. + @param[in] VendorGuid A unique identifier for the vendor. + @param[out] Attributes If not NULL, a pointer to the memory loca= tion to return the + attributes bitmask for the variable. + @param[in, out] DataSize On input, the size in bytes of the return= Data buffer. + On output the size of data returned in Da= ta. + @param[out] Data The buffer to return the contents of the = variable. May be NULL + with a zero DataSize in order to determin= e the size buffer needed. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The variable was not found. + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER DataSize is NULL. + @retval EFI_INVALID_PARAMETER The DataSize is not too small and Data is= NULL. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due t= o a hardware error. + @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due t= o an authentication failure. + @retval EFI_UNSUPPORTED This function is not implemented by this = instance of the LibraryClass + +**/ +EFI_STATUS +EFIAPI +VarLibGetVariable ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT UINT32 *Attributes, OPTIONAL + IN OUT UINTN *DataSize, + OUT VOID *Data OPTIONAL + ) +{ + EFI_STATUS Status; + EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi; + + // + // Locate the variable PPI. + // + Status =3D PeiServicesLocatePpi ( + &gEfiPeiReadOnlyVariable2PpiGuid, + 0, + NULL, + &VariablePpi + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + + if (VariablePpi !=3D NULL) { + Status =3D VariablePpi->GetVariable ( + VariablePpi, + VariableName, + VendorGuid, + Attributes, + DataSize, + Data + ); + } else { + Status =3D EFI_UNSUPPORTED; + } + return Status; +} + +/** + Enumerates the current variable names. + + @param[in, out] VariableNameSize The size of the VariableName buffer. T= he size must be large + enough to fit input string supplied in= VariableName buffer. + @param[in, out] VariableName On input, supplies the last VariableNa= me that was returned + by GetNextVariableName(). On output, r= eturns the Nullterminated + string of the current variable. + @param[in, out] VendorGuid On input, supplies the last VendorGuid= that was returned by + GetNextVariableName(). On output, retu= rns the + VendorGuid of the current variable. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The next variable was not found. + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the = result. + VariableNameSize has been updated with the= size needed to complete the request. + @retval EFI_INVALID_PARAMETER VariableNameSize is NULL. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER The input values of VariableName and Vendo= rGuid are not a name and + GUID of an existing variable. + @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first = VariableNameSize bytes of + the input VariableName buffer. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due to= a hardware error. + @retval EFI_UNSUPPORTED This function is not implemented by this i= nstance of the LibraryClass + +**/ +EFI_STATUS +EFIAPI +VarLibGetNextVariableName ( + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VendorGuid + ) +{ + EFI_STATUS Status; + EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi; + + // + // Locate the variable PPI. + // + Status =3D PeiServicesLocatePpi ( + &gEfiPeiReadOnlyVariable2PpiGuid, + 0, + NULL, + &VariablePpi + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + + if (VariablePpi !=3D NULL) { + Status =3D VariablePpi->NextVariableName ( + VariablePpi, + VariableNameSize, + VariableName, + VendorGuid + ); + } else { + Status =3D EFI_UNSUPPORTED; + } + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLib/PeiVa= riableReadLib.inf b/Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLi= b/PeiVariableReadLib.inf new file mode 100644 index 0000000000..b1d8a4b9ea --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLib/PeiVariableR= eadLib.inf @@ -0,0 +1,42 @@ +## @file +# Component description file for PEI Variable Read Lib +# +# This library provides phase agnostic access to the UEFI Variable Service= s. +# This is done by implementing a wrapper on top of the phase specific mech= anism +# for reading from UEFI variables. For example, the PEI implementation of = this +# library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation acc= esses +# the UEFI Runtime Services Table, and the SMM implementation uses +# EFI_SMM_VARIABLE_PROTOCOL. +# +# Using this library allows code to be written in a generic manner that ca= n be +# used in PEI, DXE, or SMM without modification. +# +# Copyright (c) 2021, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PeiVariableReadLib + FILE_GUID =3D C8707767-5D9D-476B-81EE-8FAFA7098224 + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D PEIM + LIBRARY_CLASS =3D VariableReadLib|PEI_CORE PEIM + +[Packages] + MdePkg/MdePkg.dec + +[Sources] + PeiVariableReadLib.c + +[LibraryClasses] + DebugLib + PeiServicesLib + +[Ppis] + gEfiPeiReadOnlyVariable2PpiGuid ## CONSUMES + +[Depex] + gEfiPeiReadOnlyVariable2PpiGuid diff --git a/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/SmmVa= riableReadCommon.c b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadL= ib/SmmVariableReadCommon.c new file mode 100644 index 0000000000..12382a0683 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/SmmVariableR= eadCommon.c @@ -0,0 +1,116 @@ +/** @file + SMM Variable Read Lib + + This library provides phase agnostic access to the UEFI Variable Service= s. + This is done by implementing a wrapper on top of the phase specific mech= anism + for reading from UEFI variables. + + This is the common implementation pieces that are shared between + traditional SMM and standalone MM. + + Copyright (c) 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include + +EFI_SMM_VARIABLE_PROTOCOL *mVariableReadLibSmmVariable =3D NULL; + +/** + Returns the value of a variable. + + @param[in] VariableName A Null-terminated string that is the name= of the vendor's + variable. + @param[in] VendorGuid A unique identifier for the vendor. + @param[out] Attributes If not NULL, a pointer to the memory loca= tion to return the + attributes bitmask for the variable. + @param[in, out] DataSize On input, the size in bytes of the return= Data buffer. + On output the size of data returned in Da= ta. + @param[out] Data The buffer to return the contents of the = variable. May be NULL + with a zero DataSize in order to determin= e the size buffer needed. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The variable was not found. + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER DataSize is NULL. + @retval EFI_INVALID_PARAMETER The DataSize is not too small and Data is= NULL. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due t= o a hardware error. + @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due t= o an authentication failure. + @retval EFI_UNSUPPORTED This function is not implemented by this = instance of the LibraryClass + +**/ +EFI_STATUS +EFIAPI +VarLibGetVariable ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT UINT32 *Attributes, OPTIONAL + IN OUT UINTN *DataSize, + OUT VOID *Data OPTIONAL + ) +{ + EFI_STATUS Status =3D EFI_UNSUPPORTED; + + if (mVariableReadLibSmmVariable !=3D NULL) { + Status =3D mVariableReadLibSmmVariable->SmmGetVariable ( + VariableName, + VendorGuid, + Attributes, + DataSize, + Data + ); + } + return Status; +} + +/** + Enumerates the current variable names. + + @param[in, out] VariableNameSize The size of the VariableName buffer. T= he size must be large + enough to fit input string supplied in= VariableName buffer. + @param[in, out] VariableName On input, supplies the last VariableNa= me that was returned + by GetNextVariableName(). On output, r= eturns the Nullterminated + string of the current variable. + @param[in, out] VendorGuid On input, supplies the last VendorGuid= that was returned by + GetNextVariableName(). On output, retu= rns the + VendorGuid of the current variable. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The next variable was not found. + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the = result. + VariableNameSize has been updated with the= size needed to complete the request. + @retval EFI_INVALID_PARAMETER VariableNameSize is NULL. + @retval EFI_INVALID_PARAMETER VariableName is NULL. + @retval EFI_INVALID_PARAMETER VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER The input values of VariableName and Vendo= rGuid are not a name and + GUID of an existing variable. + @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first = VariableNameSize bytes of + the input VariableName buffer. + @retval EFI_DEVICE_ERROR The variable could not be retrieved due to= a hardware error. + @retval EFI_UNSUPPORTED This function is not implemented by this i= nstance of the LibraryClass + +**/ +EFI_STATUS +EFIAPI +VarLibGetNextVariableName ( + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VendorGuid + ) +{ + EFI_STATUS Status =3D EFI_UNSUPPORTED; + + if (mVariableReadLibSmmVariable !=3D NULL) { + Status =3D mVariableReadLibSmmVariable->SmmGetNextVariableName ( + VariableNameSize, + VariableName, + VendorGuid + ); + } + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/Stand= aloneMmVariableReadLib.inf b/Platform/Intel/MinPlatformPkg/Library/SmmVaria= bleReadLib/StandaloneMmVariableReadLib.inf new file mode 100644 index 0000000000..801f60a022 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/StandaloneMm= VariableReadLib.inf @@ -0,0 +1,50 @@ +## @file +# Component description file for Standalone MM Variable Read Lib +# +# This library provides phase agnostic access to the UEFI Variable Service= s. +# This is done by implementing a wrapper on top of the phase specific mech= anism +# for reading from UEFI variables. For example, the PEI implementation of = this +# library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation acc= esses +# the UEFI Runtime Services Table, and the SMM implementation uses +# EFI_SMM_VARIABLE_PROTOCOL. +# +# Using this library allows code to be written in a generic manner that ca= n be +# used in PEI, DXE, or SMM without modification. +# +# Copyright (c) 2021, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D StandaloneMmVariableReadLib + FILE_GUID =3D 46246048-856E-4C60-9026-F15E20C03B68 + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D MM_STANDALONE + PI_SPECIFICATION_VERSION =3D 0x00010032 + LIBRARY_CLASS =3D VariableReadLib|MM_STANDALONE MM_CORE= _STANDALONE + CONSTRUCTOR =3D StandaloneMmVariableReadLibConstructor + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Sources] + SmmVariableReadCommon.c + StandaloneMmVariableReadLibConstructor.c + +[LibraryClasses] + DebugLib + MmServicesTableLib + +[Guids] + +[Protocols] + gEfiSmmVariableProtocolGuid ## CONSUMES + +[Pcd] + +[Depex] + gEfiSmmVariableProtocolGuid diff --git a/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/Stand= aloneMmVariableReadLibConstructor.c b/Platform/Intel/MinPlatformPkg/Library= /SmmVariableReadLib/StandaloneMmVariableReadLibConstructor.c new file mode 100644 index 0000000000..fc10c4a026 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/StandaloneMm= VariableReadLibConstructor.c @@ -0,0 +1,51 @@ +/** @file + Standalone MM Variable Read Lib + + This library provides phase agnostic access to the UEFI Variable Service= s. + This is done by implementing a wrapper on top of the phase specific mech= anism + for reading from UEFI variables. + + This is the standalone MM specific LibraryClass constructor. + + Copyright (c) 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include + +#include +#include + +extern EFI_SMM_VARIABLE_PROTOCOL *mVariableReadLibSmmVariable; + +/** + The constructor function acquires the EFI SMM Variable Services + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the MM System Table. + + @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS. + @retval EFI_NOT_FOUND gEfiSmmVariableProtocolGuid Protocol interface n= ot + found, which technically should not be possible = since + this protocol is in the LibraryClass DEPEX + +**/ +EFI_STATUS +EFIAPI +StandaloneMmVariableReadLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_MM_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + // + // Locate SmmVariableProtocol. + // + Status =3D gMmst->MmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, = (VOID **) &mVariableReadLibSmmVariable); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/Tradi= tionalMmVariableReadLib.inf b/Platform/Intel/MinPlatformPkg/Library/SmmVari= ableReadLib/TraditionalMmVariableReadLib.inf new file mode 100644 index 0000000000..39cd8371dc --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/TraditionalM= mVariableReadLib.inf @@ -0,0 +1,49 @@ +## @file +# Component description file for Traditional MM Variable Read Lib +# +# This library provides phase agnostic access to the UEFI Variable Service= s. +# This is done by implementing a wrapper on top of the phase specific mech= anism +# for reading from UEFI variables. For example, the PEI implementation of = this +# library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation acc= esses +# the UEFI Runtime Services Table, and the SMM implementation uses +# EFI_SMM_VARIABLE_PROTOCOL. +# +# Using this library allows code to be written in a generic manner that ca= n be +# used in PEI, DXE, or SMM without modification. +# +# Copyright (c) 2021, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D TraditionalMmVariableReadLib + FILE_GUID =3D 50910542-A4ED-4142-AF25-25E141C016FC + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D DXE_SMM_DRIVER + LIBRARY_CLASS =3D VariableReadLib|DXE_SMM_DRIVER SMM_CO= RE + CONSTRUCTOR =3D TraditionalMmVariableReadLibConstruct= or + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Sources] + SmmVariableReadCommon.c + TraditionalMmVariableReadLibConstructor.c + +[LibraryClasses] + DebugLib + SmmServicesTableLib + +[Guids] + +[Protocols] + gEfiSmmVariableProtocolGuid ## CONSUMES + +[Pcd] + +[Depex] + gEfiSmmVariableProtocolGuid diff --git a/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/Tradi= tionalMmVariableReadLibConstructor.c b/Platform/Intel/MinPlatformPkg/Librar= y/SmmVariableReadLib/TraditionalMmVariableReadLibConstructor.c new file mode 100644 index 0000000000..d07c56b817 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/TraditionalM= mVariableReadLibConstructor.c @@ -0,0 +1,51 @@ +/** @file + Traditional MM Variable Read Lib + + This library provides phase agnostic access to the UEFI Variable Service= s. + This is done by implementing a wrapper on top of the phase specific mech= anism + for reading from UEFI variables. + + This is the traditional SMM specific LibraryClass constructor. + + Copyright (c) 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include + +#include +#include + +extern EFI_SMM_VARIABLE_PROTOCOL *mVariableReadLibSmmVariable; + +/** + The constructor function acquires the EFI SMM Variable Services + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS. + @retval EFI_NOT_FOUND gEfiSmmVariableProtocolGuid Protocol interface n= ot + found, which technically should not be possible = since + this protocol is in the LibraryClass DEPEX + +**/ +EFI_STATUS +EFIAPI +TraditionalMmVariableReadLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + // + // Locate SmmVariableProtocol. + // + Status =3D gSmst->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL,= (VOID **) &mVariableReadLibSmmVariable); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc b/Platform/In= tel/MinPlatformPkg/MinPlatformPkg.dsc index 998ee79095..18b5c6f5b1 100644 --- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc @@ -1,7 +1,7 @@ ## @file # Platform description. # -# Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -120,6 +120,7 @@ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf SpiFlashCommonLib|MinPlatformPkg/Flash/Library/SpiFlashCommonLibNull/Spi= FlashCommonLibNull.inf StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint= /StandaloneMmDriverEntryPoint.inf + VariableReadLib|MinPlatformPkg/Library/SmmVariableReadLib/StandaloneMmVa= riableReadLib.inf =20 ##########################################################################= ######################### # --=20 2.27.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#73755): https://edk2.groups.io/g/devel/message/73755 Mute This Topic: https://groups.io/mt/81907527/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-