From: "Michael Kubacki" <mikuback@linux.microsoft.com>
To: devel@edk2.groups.io, nathaniel.l.desimone@intel.com
Cc: Chasel Chiu <chasel.chiu@intel.com>,
Liming Gao <gaoliming@byosoft.com.cn>,
Eric Dong <eric.dong@intel.com>,
Michael Kubacki <michael.kubacki@microsoft.com>,
Isaac Oram <isaac.w.oram@intel.com>
Subject: Re: [edk2-devel] [edk2-platforms] [PATCH v3 1/4] MinPlatformPkg: Add VariableReadLib
Date: Tue, 6 Apr 2021 14:59:27 -0700 [thread overview]
Message-ID: <b46312d9-b9fc-677b-7f08-526fccc270d2@linux.microsoft.com> (raw)
In-Reply-To: <20210406192411.6888-2-nathaniel.l.desimone@intel.com>
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 <chasel.chiu@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Michael Kubacki <michael.kubacki@microsoft.com>
> Cc: Isaac Oram <isaac.w.oram@intel.com>
> Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
> Reviewed-by: Isaac Oram <isaac.w.oram@intel.com>
> ---
> .../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.<BR>
> +# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
> #
> # 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.<BR>
> +# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
> #
> # 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.<BR>
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
This file is missing a header guard.
> +#include <Uefi/UefiBaseType.h>
> +
> +/**
> + 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.<BR>
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Uefi.h>
> +
> +#include <Library/UefiRuntimeServicesTableLib.h>
> +
> +/**
> + 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.<BR>
> +#
> +# 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.<BR>
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiPei.h>
> +#include <Ppi/ReadOnlyVariable2.h>
> +
> +#include <Library/DebugLib.h>
> +#include <Library/PeiServicesLib.h>
> +
> +/**
> + 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.<BR>
> +#
> +# 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.<BR>
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Uefi/UefiBaseType.h>
> +
> +#include <Protocol/SmmVariable.h>
> +
> +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.<BR>
> +#
> +# 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.<BR>
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Uefi/UefiBaseType.h>
> +
> +#include <Protocol/SmmVariable.h>
> +
> +#include <Library/DebugLib.h>
> +#include <Library/MmServicesTableLib.h>
> +
> +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.<BR>
> +#
> +# 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.<BR>
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Uefi.h>
> +
> +#include <Protocol/SmmVariable.h>
> +
> +#include <Library/DebugLib.h>
> +#include <Library/SmmServicesTableLib.h>
> +
> +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.<BR>
> +# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
> # Copyright (c) Microsoft Corporation.<BR>
> #
> # 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
>
> ###################################################################################################
> #
>
next prev parent reply other threads:[~2021-04-06 21:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-06 19:24 [edk2-platforms] [PATCH v3 0/4] Add Large Variable Libraries Nate DeSimone
2021-04-06 19:24 ` [edk2-platforms] [PATCH v3 1/4] MinPlatformPkg: Add VariableReadLib Nate DeSimone
2021-04-06 21:59 ` Michael Kubacki [this message]
2021-04-06 19:24 ` [edk2-platforms] [PATCH v3 2/4] MinPlatformPkg: Add VariableWriteLib Nate DeSimone
2021-04-06 19:24 ` [edk2-platforms] [PATCH v3 3/4] MinPlatformPkg: Add LargeVariableReadLib Nate DeSimone
2021-04-06 22:01 ` [edk2-devel] " Michael Kubacki
2021-04-07 3:05 ` Nate DeSimone
2021-04-06 19:24 ` [edk2-platforms] [PATCH v3 4/4] MinPlatformPkg: Add LargeVariableWriteLib Nate DeSimone
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b46312d9-b9fc-677b-7f08-526fccc270d2@linux.microsoft.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox