From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: nathaniel.l.desimone@intel.com) 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" 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" 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-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> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: <20210407030426.8075-1-nathaniel.l.desimone@intel.com> References: <20210407030426.8075-1-nathaniel.l.desimone@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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/VariableReadLib.h create mode 100644 Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRuntimeVariableReadLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRuntimeVariableReadLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLib/PeiVariableReadLib.c create mode 100644 Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLib/PeiVariableReadLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/SmmVariableReadCommon.c create mode 100644 Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/StandaloneMmVariableReadLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/StandaloneMmVariableReadLibConstructor.c create mode 100644 Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/TraditionalMmVariableReadLib.inf create mode 100644 Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/TraditionalMmVariableReadLibConstructor.c diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreDxeLib.dsc b/Platform/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 # - + # # DXE phase common # @@ -23,7 +23,7 @@ ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf HstiLib|MdePkg/Library/DxeHstiLib/DxeHstiLib.inf - + LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf @@ -46,6 +46,9 @@ VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf +[LibraryClasses.common.DXE_CORE, LibraryClasses.common.DXE_DRIVER, LibraryClasses.common.DXE_RUNTIME_DRIVER, LibraryClasses.common.UEFI_DRIVER, LibraryClasses.common.UEFI_APPLICATION] + VariableReadLib|MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRuntimeVariableReadLib.inf + [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf @@ -89,6 +92,7 @@ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf Tcg2PhysicalPresenceLib|SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf + VariableReadLib|MinPlatformPkg/Library/SmmVariableReadLib/TraditionalMmVariableReadLib.inf [LibraryClasses.common.SMM_CORE] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CorePeiLib.dsc b/Platform/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 # - + # # PEI phase common # - + [LibraryClasses.common.SEC,LibraryClasses.common.PEI_CORE,LibraryClasses.common.PEIM] S3BootScriptLib|MdePkg/Library/BaseS3BootScriptLibNull/BaseS3BootScriptLibNull.inf PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf @@ -52,7 +52,7 @@ !if gMinPlatformPkgTokenSpaceGuid.PcdPerformanceEnable == TRUE PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf !endif - + [LibraryClasses.common.PEIM] CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf TimerLib|PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf @@ -70,3 +70,4 @@ !if gMinPlatformPkgTokenSpaceGuid.PcdPerformanceEnable == TRUE PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf !endif + VariableReadLib|MinPlatformPkg/Library/PeiVariableReadLib/PeiVariableReadLib.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 Services. + This is done by implementing a wrapper on top of the phase specific mechanism + for reading from UEFI variables. For example, the PEI implementation of this + library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation accesses + 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 can 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 location 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 Data. + @param[out] Data The buffer to return the contents of the variable. May be NULL + with a zero DataSize in order to determine 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 to a hardware error. + @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due to 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. The size must be large + enough to fit input string supplied in VariableName buffer. + @param[in, out] VariableName On input, supplies the last VariableName that was returned + by GetNextVariableName(). On output, returns the Nullterminated + string of the current variable. + @param[in, out] VendorGuid On input, supplies the last VendorGuid that was returned by + GetNextVariableName(). On output, returns 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 VendorGuid 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 instance 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/DxeRuntimeVariableReadLib/DxeRuntimeVariableReadLib.c b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRuntimeVariableReadLib.c new file mode 100644 index 0000000000..eca766dbce --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRuntimeVariableReadLib.c @@ -0,0 +1,117 @@ +/** @file + DXE Variable Read Lib + + This library provides phase agnostic access to the UEFI Variable Services. + This is done by implementing a wrapper on top of the phase specific mechanism + for reading from UEFI variables. For example, the PEI implementation of this + library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation accesses + 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 can 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 location 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 Data. + @param[out] Data The buffer to return the contents of the variable. May be NULL + with a zero DataSize in order to determine 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 to a hardware error. + @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due to 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_UNSUPPORTED; + + if (gRT != NULL) { + Status = gRT->GetVariable ( + VariableName, + VendorGuid, + Attributes, + DataSize, + Data + ); + } + return Status; +} + +/** + Enumerates the current variable names. + + @param[in, out] VariableNameSize The size of the VariableName buffer. The size must be large + enough to fit input string supplied in VariableName buffer. + @param[in, out] VariableName On input, supplies the last VariableName that was returned + by GetNextVariableName(). On output, returns the Nullterminated + string of the current variable. + @param[in, out] VendorGuid On input, supplies the last VendorGuid that was returned by + GetNextVariableName(). On output, returns 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 VendorGuid 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 instance of the LibraryClass + +**/ +EFI_STATUS +EFIAPI +VarLibGetNextVariableName ( + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VendorGuid + ) +{ + EFI_STATUS Status = EFI_UNSUPPORTED; + + if (gRT != NULL) { + Status = gRT->GetNextVariableName ( + VariableNameSize, + VariableName, + VendorGuid + ); + } + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRuntimeVariableReadLib.inf b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRuntimeVariableReadLib.inf new file mode 100644 index 0000000000..848b76344b --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRuntimeVariableReadLib.inf @@ -0,0 +1,41 @@ +## @file +# Component description file for DXE Variable Read Lib +# +# This library provides phase agnostic access to the UEFI Variable Services. +# This is done by implementing a wrapper on top of the phase specific mechanism +# for reading from UEFI variables. For example, the PEI implementation of this +# library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation accesses +# 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 can 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 = 0x00010005 + BASE_NAME = DxeRuntimeVariableReadLib + FILE_GUID = 9C357AD8-2BF4-450C-9E65-C0938F6D2424 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_RUNTIME_DRIVER + LIBRARY_CLASS = VariableReadLib|DXE_CORE DXE_DRIVER DXE_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/PeiVariableReadLib.c b/Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLib/PeiVariableReadLib.c new file mode 100644 index 0000000000..5eeee12a3c --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLib/PeiVariableReadLib.c @@ -0,0 +1,155 @@ +/** @file + PEI Variable Read Lib + + This library provides phase agnostic access to the UEFI Variable Services. + This is done by implementing a wrapper on top of the phase specific mechanism + for reading from UEFI variables. For example, the PEI implementation of this + library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation accesses + 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 can 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 location 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 Data. + @param[out] Data The buffer to return the contents of the variable. May be NULL + with a zero DataSize in order to determine 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 to a hardware error. + @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due to 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 = PeiServicesLocatePpi ( + &gEfiPeiReadOnlyVariable2PpiGuid, + 0, + NULL, + &VariablePpi + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + + if (VariablePpi != NULL) { + Status = VariablePpi->GetVariable ( + VariablePpi, + VariableName, + VendorGuid, + Attributes, + DataSize, + Data + ); + } else { + Status = EFI_UNSUPPORTED; + } + return Status; +} + +/** + Enumerates the current variable names. + + @param[in, out] VariableNameSize The size of the VariableName buffer. The size must be large + enough to fit input string supplied in VariableName buffer. + @param[in, out] VariableName On input, supplies the last VariableName that was returned + by GetNextVariableName(). On output, returns the Nullterminated + string of the current variable. + @param[in, out] VendorGuid On input, supplies the last VendorGuid that was returned by + GetNextVariableName(). On output, returns 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 VendorGuid 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 instance 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 = PeiServicesLocatePpi ( + &gEfiPeiReadOnlyVariable2PpiGuid, + 0, + NULL, + &VariablePpi + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + + if (VariablePpi != NULL) { + Status = VariablePpi->NextVariableName ( + VariablePpi, + VariableNameSize, + VariableName, + VendorGuid + ); + } else { + Status = EFI_UNSUPPORTED; + } + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLib/PeiVariableReadLib.inf b/Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLib/PeiVariableReadLib.inf new file mode 100644 index 0000000000..b1d8a4b9ea --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLib/PeiVariableReadLib.inf @@ -0,0 +1,42 @@ +## @file +# Component description file for PEI Variable Read Lib +# +# This library provides phase agnostic access to the UEFI Variable Services. +# This is done by implementing a wrapper on top of the phase specific mechanism +# for reading from UEFI variables. For example, the PEI implementation of this +# library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation accesses +# 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 can 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 = 0x00010005 + BASE_NAME = PeiVariableReadLib + FILE_GUID = C8707767-5D9D-476B-81EE-8FAFA7098224 + VERSION_STRING = 1.0 + MODULE_TYPE = PEIM + LIBRARY_CLASS = 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/SmmVariableReadCommon.c b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/SmmVariableReadCommon.c new file mode 100644 index 0000000000..12382a0683 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/SmmVariableReadCommon.c @@ -0,0 +1,116 @@ +/** @file + SMM Variable Read Lib + + This library provides phase agnostic access to the UEFI Variable Services. + This is done by implementing a wrapper on top of the phase specific mechanism + 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 = 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 location 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 Data. + @param[out] Data The buffer to return the contents of the variable. May be NULL + with a zero DataSize in order to determine 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 to a hardware error. + @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due to 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_UNSUPPORTED; + + if (mVariableReadLibSmmVariable != NULL) { + Status = mVariableReadLibSmmVariable->SmmGetVariable ( + VariableName, + VendorGuid, + Attributes, + DataSize, + Data + ); + } + return Status; +} + +/** + Enumerates the current variable names. + + @param[in, out] VariableNameSize The size of the VariableName buffer. The size must be large + enough to fit input string supplied in VariableName buffer. + @param[in, out] VariableName On input, supplies the last VariableName that was returned + by GetNextVariableName(). On output, returns the Nullterminated + string of the current variable. + @param[in, out] VendorGuid On input, supplies the last VendorGuid that was returned by + GetNextVariableName(). On output, returns 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 VendorGuid 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 instance of the LibraryClass + +**/ +EFI_STATUS +EFIAPI +VarLibGetNextVariableName ( + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VendorGuid + ) +{ + EFI_STATUS Status = EFI_UNSUPPORTED; + + if (mVariableReadLibSmmVariable != NULL) { + Status = mVariableReadLibSmmVariable->SmmGetNextVariableName ( + VariableNameSize, + VariableName, + VendorGuid + ); + } + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/StandaloneMmVariableReadLib.inf b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/StandaloneMmVariableReadLib.inf new file mode 100644 index 0000000000..801f60a022 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/StandaloneMmVariableReadLib.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 Services. +# This is done by implementing a wrapper on top of the phase specific mechanism +# for reading from UEFI variables. For example, the PEI implementation of this +# library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation accesses +# 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 can 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 = 0x0001001B + BASE_NAME = StandaloneMmVariableReadLib + FILE_GUID = 46246048-856E-4C60-9026-F15E20C03B68 + VERSION_STRING = 1.0 + MODULE_TYPE = MM_STANDALONE + PI_SPECIFICATION_VERSION = 0x00010032 + LIBRARY_CLASS = VariableReadLib|MM_STANDALONE MM_CORE_STANDALONE + CONSTRUCTOR = 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/StandaloneMmVariableReadLibConstructor.c b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/StandaloneMmVariableReadLibConstructor.c new file mode 100644 index 0000000000..fc10c4a026 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/StandaloneMmVariableReadLibConstructor.c @@ -0,0 +1,51 @@ +/** @file + Standalone MM Variable Read Lib + + This library provides phase agnostic access to the UEFI Variable Services. + This is done by implementing a wrapper on top of the phase specific mechanism + 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 not + 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 = gMmst->MmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **) &mVariableReadLibSmmVariable); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/TraditionalMmVariableReadLib.inf b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/TraditionalMmVariableReadLib.inf new file mode 100644 index 0000000000..39cd8371dc --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/TraditionalMmVariableReadLib.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 Services. +# This is done by implementing a wrapper on top of the phase specific mechanism +# for reading from UEFI variables. For example, the PEI implementation of this +# library uses EFI_PEI_READ_ONLY_VARIABLE2_PPI. The DXE implementation accesses +# 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 can 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 = 0x00010005 + BASE_NAME = TraditionalMmVariableReadLib + FILE_GUID = 50910542-A4ED-4142-AF25-25E141C016FC + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_SMM_DRIVER + LIBRARY_CLASS = VariableReadLib|DXE_SMM_DRIVER SMM_CORE + CONSTRUCTOR = TraditionalMmVariableReadLibConstructor + +[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/TraditionalMmVariableReadLibConstructor.c b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/TraditionalMmVariableReadLibConstructor.c new file mode 100644 index 0000000000..d07c56b817 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/TraditionalMmVariableReadLibConstructor.c @@ -0,0 +1,51 @@ +/** @file + Traditional MM Variable Read Lib + + This library provides phase agnostic access to the UEFI Variable Services. + This is done by implementing a wrapper on top of the phase specific mechanism + 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 not + 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 = gSmst->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **) &mVariableReadLibSmmVariable); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc b/Platform/Intel/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/SpiFlashCommonLibNull.inf StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf + VariableReadLib|MinPlatformPkg/Library/SmmVariableReadLib/StandaloneMmVariableReadLib.inf ################################################################################################### # -- 2.27.0.windows.1