From nobody Sat Feb 7 10:16:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+88651+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+88651+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1649452705; cv=none; d=zohomail.com; s=zohoarc; b=MIX0jE/GQKAxsErFov3tozvgrbLNs+bL9zxjgywsFnQLLvILCKGS9gODYJdzTMfsDX6yI8DX7w1pwfxQ6/15V2KbhW1K+P+TeJwxLubcRdup2b30ks1o7ppvAKgJCB85EJOUTyM9//CxIG1YV3iG/JkjCvxk+rDT++dhuIT3MeU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1649452705; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=pxNnbwAK9banSroUvhIVK0GS3ilET/QR0Y+Q0Vw513k=; b=NmzGwnBFoCn/mqTdLl/Ef6vsORxmda91ttWA9zuV8l/xBYej1HdIE/hTQ1PURgpUVB/wJIuXQ+MS4c7RmAdEVfpl0eI6ayUxS06vgqyW1VKes6JOkYc6s1AWLIEl9OdxkditTc1pb3H6C8UON48stC+YCpv+Zz5Dqli0nnrCEBE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+88651+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1649452705521323.5321879256602; Fri, 8 Apr 2022 14:18:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id bV1DYY1788612xVhnCRIuQzc; Fri, 08 Apr 2022 14:18:25 -0700 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.727.1649452704278829748 for ; Fri, 08 Apr 2022 14:18:24 -0700 X-Received: from localhost.localdomain (unknown [47.201.46.36]) by linux.microsoft.com (Postfix) with ESMTPSA id 5C40B2034C44; Fri, 8 Apr 2022 14:18:23 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5C40B2034C44 From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Liming Gao Subject: [edk2-devel] [PATCH v2 2/8] MdeModulePkg/VariableFlashInfoLib: Add initial library Date: Fri, 8 Apr 2022 17:17:27 -0400 Message-Id: <20220408211733.1332-3-mikuback@linux.microsoft.com> In-Reply-To: <20220408211733.1332-1-mikuback@linux.microsoft.com> References: <20220408211733.1332-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mikuback@linux.microsoft.com X-Gm-Message-State: ftBEBw02Zt5NIlklwxmDeeZUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1649452705; bh=NltCdXWH/cTlEYQc4MHf8+nUa3uHRm7Gzgc7h6DjvoA=; h=Cc:Date:From:Reply-To:Subject:To; b=Ijz5SCcNaWZgHsHUmbhAA/O3Wifgt69R5r4D6ctYBmPdsGZ9ZHKcoSG6TrnWrNtqW3o olX3zK757OiC/vRUyJEmYHVYyeBa5I4Nlj+YwCvE/ntDqJToOzqS/kyXP8nfdFxtQZbBV oKKU2Pv1Ch9GNGNGt5fUaot8C3FEoiEUqGU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1649452707229100003 Content-Type: text/plain; charset="utf-8" From: Michael Kubacki REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3479 Adds a new library class VariableFlashInfoLib that abstracts access to variable flash information. The instance provided first attempts to retrieve information from the Variable Flash Info HOB. If that HOB is not present, it falls back to the PCDs defined in MdeModulePkg. This fall back behavior provides backward compatibility for platforms that only provide PCDs but also allows platforms that need to dynamically provide the information using the Variable Flash Info HOB to do so at runtime. Cc: Jian J Wang Cc: Hao A Wu Cc: Liming Gao Signed-off-by: Michael Kubacki --- MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c = | 178 ++++++++++++++++++++ MdeModulePkg/Include/Library/VariableFlashInfoLib.h = | 68 ++++++++ MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf= | 48 ++++++ MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.uni= | 12 ++ MdeModulePkg/MdeModulePkg.dec = | 4 + MdeModulePkg/MdeModulePkg.dsc = | 2 + 6 files changed, 312 insertions(+) diff --git a/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlas= hInfoLib.c b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlas= hInfoLib.c new file mode 100644 index 000000000000..8e3c6e75c957 --- /dev/null +++ b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLi= b.c @@ -0,0 +1,178 @@ +/** @file + Variable Flash Information Library + + Copyright (c) Microsoft Corporation
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +/** + Get the HOB that contains variable flash information. + + @param[out] VariableFlashInfo Pointer to a pointer to set to the varia= ble flash information structure. + + @retval EFI_SUCCESS Variable flash information was found suc= cessfully. + @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is N= ULL. + @retval EFI_NOT_FOUND Variable flash information could not be = found. + +**/ +EFI_STATUS +GetVariableFlashInfoFromHob ( + OUT VARIABLE_FLASH_INFO **VariableFlashInfo + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + + if (VariableFlashInfo =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + GuidHob =3D GetFirstGuidHob (&gVariableFlashInfoHobGuid); + if (GuidHob =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + *VariableFlashInfo =3D GET_GUID_HOB_DATA (GuidHob); + + // + // Assert if more than one variable flash information HOB is present. + // + DEBUG_CODE ( + if ((GetNextGuidHob (&gVariableFlashInfoHobGuid, GET_NEXT_HOB (GuidHob= )) !=3D NULL)) { + DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information HOBs= \n")); + ASSERT (FALSE); + } + + ); + + return EFI_SUCCESS; +} + +/** + Get the base address and size for the NV storage area used for UEFI vari= able storage. + + @param[out] BaseAddress The NV storage base address. + @param[out] Length The NV storage length in bytes. + + @retval EFI_SUCCESS NV storage information was found success= fully. + @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL. + +**/ +EFI_STATUS +EFIAPI +GetVariableFlashNvStorageInfo ( + OUT EFI_PHYSICAL_ADDRESS *BaseAddress, + OUT UINT64 *Length + ) +{ + EFI_STATUS Status; + VARIABLE_FLASH_INFO *VariableFlashInfo; + + if ((BaseAddress =3D=3D NULL) || (Length =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + Status =3D GetVariableFlashInfoFromHob (&VariableFlashInfo); + if (!EFI_ERROR (Status)) { + *BaseAddress =3D VariableFlashInfo->NvStorageBaseAddress; + *Length =3D VariableFlashInfo->NvStorageLength; + } else { + *BaseAddress =3D (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageVar= iableBase64) !=3D 0 ? + PcdGet64 (PcdFlashNvStorageVaria= bleBase64) : + PcdGet32 (PcdFlashNvStorageVaria= bleBase) + ); + *Length =3D (UINT64)PcdGet32 (PcdFlashNvStorageVariableSize); + } + + return EFI_SUCCESS; +} + +/** + Get the base address and size for the fault tolerant write (FTW) spare + area used for UEFI variable storage. + + @param[out] BaseAddress The FTW spare base address. + @param[out] Length The FTW spare length in bytes. + + @retval EFI_SUCCESS FTW spare information was found successf= ully. + @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL. + @retval EFI_NOT_FOUND FTW spare information could not be found. + +**/ +EFI_STATUS +EFIAPI +GetVariableFlashFtwSpareInfo ( + OUT EFI_PHYSICAL_ADDRESS *BaseAddress, + OUT UINT64 *Length + ) +{ + EFI_STATUS Status; + VARIABLE_FLASH_INFO *VariableFlashInfo; + + if ((BaseAddress =3D=3D NULL) || (Length =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + Status =3D GetVariableFlashInfoFromHob (&VariableFlashInfo); + if (!EFI_ERROR (Status)) { + *BaseAddress =3D VariableFlashInfo->FtwSpareBaseAddress; + *Length =3D VariableFlashInfo->FtwSpareLength; + } else { + *BaseAddress =3D (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageFtw= SpareBase64) !=3D 0 ? + PcdGet64 (PcdFlashNvStorageFtwSp= areBase64) : + PcdGet32 (PcdFlashNvStorageFtwSp= areBase) + ); + *Length =3D (UINT64)PcdGet32 (PcdFlashNvStorageFtwSpareSize); + } + + return EFI_SUCCESS; +} + +/** + Get the base address and size for the fault tolerant write (FTW) working + area used for UEFI variable storage. + + @param[out] BaseAddress The FTW working area base address. + @param[out] Length The FTW working area length in bytes. + + @retval EFI_SUCCESS FTW working information was found succes= sfully. + @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL. + @retval EFI_NOT_FOUND FTW working information could not be fou= nd. + +**/ +EFI_STATUS +EFIAPI +GetVariableFlashFtwWorkingInfo ( + OUT EFI_PHYSICAL_ADDRESS *BaseAddress, + OUT UINT64 *Length + ) +{ + EFI_STATUS Status; + VARIABLE_FLASH_INFO *VariableFlashInfo; + + if ((BaseAddress =3D=3D NULL) || (Length =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + Status =3D GetVariableFlashInfoFromHob (&VariableFlashInfo); + if (!EFI_ERROR (Status)) { + *BaseAddress =3D VariableFlashInfo->FtwWorkingBaseAddress; + *Length =3D VariableFlashInfo->FtwWorkingLength; + } else { + *BaseAddress =3D (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageFtw= WorkingBase64) !=3D 0 ? + PcdGet64 (PcdFlashNvStorageFtwWo= rkingBase64) : + PcdGet32 (PcdFlashNvStorageFtwWo= rkingBase) + ); + *Length =3D (UINT64)PcdGet32 (PcdFlashNvStorageFtwWorkingSize); + } + + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Include/Library/VariableFlashInfoLib.h b/MdeModul= ePkg/Include/Library/VariableFlashInfoLib.h new file mode 100644 index 000000000000..1367be9376ea --- /dev/null +++ b/MdeModulePkg/Include/Library/VariableFlashInfoLib.h @@ -0,0 +1,68 @@ +/** @file + Variable Flash Information Library + +Copyright (c) Microsoft Corporation
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef VARIABLE_FLASH_INFO_LIB_H_ +#define VARIABLE_FLASH_INFO_LIB_H_ + +/** + Get the base address and size for the NV storage area used for UEFI vari= able storage. + + @param[out] BaseAddress The NV storage base address. + @param[out] Length The NV storage length in bytes. + + @retval EFI_SUCCESS NV storage information was found success= fully. + @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL. + @retval EFI_NOT_FOUND NV storage information could not be foun= d. + +**/ +EFI_STATUS +EFIAPI +GetVariableFlashNvStorageInfo ( + OUT EFI_PHYSICAL_ADDRESS *BaseAddress, + OUT UINT64 *Length + ); + +/** + Get the base address and size for the fault tolerant write (FTW) spare + area used for UEFI variable storage. + + @param[out] BaseAddress The FTW spare base address. + @param[out] Length The FTW spare length in bytes. + + @retval EFI_SUCCESS FTW spare information was found successf= ully. + @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL. + @retval EFI_NOT_FOUND FTW spare information could not be found. + +**/ +EFI_STATUS +EFIAPI +GetVariableFlashFtwSpareInfo ( + OUT EFI_PHYSICAL_ADDRESS *BaseAddress, + OUT UINT64 *Length + ); + +/** + Get the base address and size for the fault tolerant write (FTW) working + area used for UEFI variable storage. + + @param[out] BaseAddress The FTW working area base address. + @param[out] Length The FTW working area length in bytes. + + @retval EFI_SUCCESS FTW working information was found succes= sfully. + @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL. + @retval EFI_NOT_FOUND FTW working information could not be fou= nd. + +**/ +EFI_STATUS +EFIAPI +GetVariableFlashFtwWorkingInfo ( + OUT EFI_PHYSICAL_ADDRESS *BaseAddress, + OUT UINT64 *Length + ); + +#endif diff --git a/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlas= hInfoLib.inf b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFl= ashInfoLib.inf new file mode 100644 index 000000000000..70175e75f9b1 --- /dev/null +++ b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLi= b.inf @@ -0,0 +1,48 @@ +## @file +# Variable Flash Information Library +# +# Provides services to access UEFI variable flash information. +# +# Copyright (c) Microsoft Corporation
+# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D BaseVariableFlashInfoLib + MODULE_UNI_FILE =3D BaseVariableFlashInfoLib.uni + FILE_GUID =3D DEC426C9-C92E-4BAD-8E93-3F61C261118B + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D VariableFlashInfoLib + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D ANY +# + +[Sources] + BaseVariableFlashInfoLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + DebugLib + HobLib + +[Guids] + gVariableFlashInfoHobGuid ## CONSUMES ## HOB + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## SOM= ETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## SOM= ETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## SOM= ETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## SOM= ETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## SOM= ETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## SOM= ETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## SOM= ETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## SOM= ETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## SOM= ETIMES_CONSUMES diff --git a/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlas= hInfoLib.uni b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFl= ashInfoLib.uni new file mode 100644 index 000000000000..9a5348fa02a0 --- /dev/null +++ b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLi= b.uni @@ -0,0 +1,12 @@ +// /** @file +// Variable Flash Information Library +// +// Copyright (c) Microsoft Corporation
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "UEFI variable flash infor= mation library" + +#string STR_MODULE_DESCRIPTION #language en-US "Provides services to acce= ss UEFI variable flash information." diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 4e82f5836096..2bcb9f9453af 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -154,6 +154,10 @@ [LibraryClasses] # VariablePolicyHelperLib|Include/Library/VariablePolicyHelperLib.h =20 + ## @libraryclass Provides services to access UEFI variable flash infor= mation. + # + VariableFlashInfoLib|Include/Library/VariableFlashInfoLib.h + [Guids] ## MdeModule package token space guid # Include/Guid/MdeModulePkgTokenSpace.h diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index b1d83461865e..90a0a7ec4a7c 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -103,6 +103,7 @@ [LibraryClasses] DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdateProgressLibGr= aphics/DisplayUpdateProgressLibGraphics.inf VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/Var= iablePolicyHelperLib.inf MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibN= ull.inf + VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseV= ariableFlashInfoLib.inf =20 [LibraryClasses.EBC.PEIM] IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf @@ -440,6 +441,7 @@ [Components] MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.i= nf MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf + MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.i= nf =20 [Components.IA32, Components.X64, Components.AARCH64] MdeModulePkg/Universal/EbcDxe/EbcDxe.inf --=20 2.28.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#88651): https://edk2.groups.io/g/devel/message/88651 Mute This Topic: https://groups.io/mt/90345654/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-