From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web12.1499.1617746367726286889 for ; Tue, 06 Apr 2021 14:59:28 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=shYTe5vc; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from [10.124.238.202] (unknown [167.220.2.74]) by linux.microsoft.com (Postfix) with ESMTPSA id 2623620B5680; Tue, 6 Apr 2021 14:59:27 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2623620B5680 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1617746367; bh=r9TAW9i5Yif1VAjqDdaUvoQWv91FthlwjZ8HqwyNCbM=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=shYTe5vcE0uHtkCOEVkUjfCZDfetXj1ao0q0bbNamCiC2uK64rWIEFJ2AUS1b7b1+ BzAv23l3mIcA4TN+zvcRSBVgzhBHPW1Lf4IGN+TLfP9m0JA3JUUKqh/0TUXVQOHTKL Isu6RKt8welIh1TCB2Tmg+mew43/Vjd+TyyCwbRU= Subject: Re: [edk2-devel] [edk2-platforms] [PATCH v3 1/4] MinPlatformPkg: Add VariableReadLib To: devel@edk2.groups.io, nathaniel.l.desimone@intel.com Cc: Chasel Chiu , Liming Gao , Eric Dong , Michael Kubacki , Isaac Oram References: <20210406192411.6888-1-nathaniel.l.desimone@intel.com> <20210406192411.6888-2-nathaniel.l.desimone@intel.com> From: "Michael Kubacki" Message-ID: Date: Tue, 6 Apr 2021 14:59:27 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <20210406192411.6888-2-nathaniel.l.desimone@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Hi Nate, Feedback is inline. Most of the items carry over to the VariableWriteLib patch as well but I didn't duplicate the response to that patch. Thanks, Michael On 4/6/2021 12:24 PM, Nate DeSimone wrote: > 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 | 87 ++++++++++ > .../DxeRuntimeVariableReadLib.c | 115 +++++++++++++ > .../DxeRuntimeVariableReadLib.inf | 41 +++++ > .../PeiVariableReadLib/PeiVariableReadLib.c | 153 ++++++++++++++++++ > .../PeiVariableReadLib/PeiVariableReadLib.inf | 42 +++++ > .../SmmVariableReadCommon.c | 114 +++++++++++++ > .../StandaloneMmVariableReadLib.inf | 50 ++++++ > .../StandaloneMmVariableReadLibConstructor.c | 48 ++++++ > .../TraditionalMmVariableReadLib.inf | 49 ++++++ > .../TraditionalMmVariableReadLibConstructor.c | 48 ++++++ > .../Intel/MinPlatformPkg/MinPlatformPkg.dsc | 3 +- > 13 files changed, 761 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..6ff762a960 > --- /dev/null > +++ b/Platform/Intel/MinPlatformPkg/Include/Library/VariableReadLib.h > @@ -0,0 +1,87 @@ > +/** @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 > + > +**/ > + This file is missing a header guard. > +#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. > + > +**/ > +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. > + > +**/ > +EFI_STATUS > +EFIAPI > +VarLibGetNextVariableName ( > + IN OUT UINTN *VariableNameSize, > + IN OUT CHAR16 *VariableName, > + IN OUT EFI_GUID *VendorGuid > + ); > diff --git a/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRuntimeVariableReadLib.c b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRuntimeVariableReadLib.c > new file mode 100644 > index 0000000000..f611891d6a > --- /dev/null > +++ b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableReadLib/DxeRuntimeVariableReadLib.c > @@ -0,0 +1,115 @@ > +/** @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. > + It would be nice to have EFI_UNSUPPORTED described as a retval for all instances of the library functions. > +**/ > +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. > + > +**/ > +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..d9fbce7981 > --- /dev/null > +++ b/Platform/Intel/MinPlatformPkg/Library/PeiVariableReadLib/PeiVariableReadLib.c > @@ -0,0 +1,153 @@ > +/** @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. > + > +**/ > +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. > + > +**/ > +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..b663b93999 > --- /dev/null > +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/SmmVariableReadCommon.c > @@ -0,0 +1,114 @@ > +/** @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. > + > +**/ > +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. > + > +**/ > +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..96a4a25fd7 > --- /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 = SmmVariableReadLib BASE_NAME of "StandaloneMmVariableReadLib" would help distinguish this library instance. > + FILE_GUID = 46246048-856E-4C60-9026-F15E20C03B68 > + VERSION_STRING = 1.0 > + MODULE_TYPE = MM_STANDALONE > + PI_SPECIFICATION_VERSION = 0x00010032 > + LIBRARY_CLASS = VariableReadLib|MM_STANDALONE I noticed the LIBRARY_CLASS in TraditionalMmVariableReadLib.inf included core modules ("DXE_SMM_DRIVER SMM_CORE") whereas this instance does not include "MM_CORE_STANDALONE". Was there a particular reason for that? > + 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..d9fb915bb4 > --- /dev/null > +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/StandaloneMmVariableReadLibConstructor.c > @@ -0,0 +1,48 @@ > +/** @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. > + > +**/ > +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..5d35bedc05 > --- /dev/null > +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableReadLib/TraditionalMmVariableReadLibConstructor.c > @@ -0,0 +1,48 @@ > +/** @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. > + This applies to StandaloneMmVariableReadLibConstructor.c as well, the constructors could currently return a value other than EFI_SUCCESS. > +**/ > +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 > > ################################################################################################### > # >