From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web09.5182.1633670134020782646 for ; Thu, 07 Oct 2021 22:15:34 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: chasel.chiu@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10130"; a="249794420" X-IronPort-AV: E=Sophos;i="5.85,356,1624345200"; d="scan'208";a="249794420" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2021 22:15:32 -0700 X-IronPort-AV: E=Sophos;i="5.85,356,1624345200"; d="scan'208";a="489312704" Received: from cchiu4-mobl.gar.corp.intel.com ([10.252.188.53]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2021 22:15:31 -0700 From: "Chiu, Chasel" To: devel@edk2.groups.io Cc: Chasel Chiu , Nate DeSimone , Liming Gao , Eric Dong Subject: [edk2-platforms: PATCH v2 1/9] MinPlatformPkg: Support FSP 2.3 FSP_NON_VOLATILE_STORAGE_HOB2. Date: Fri, 8 Oct 2021 13:14:54 +0800 Message-Id: <20211008051502.1243-2-chasel.chiu@intel.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20211008051502.1243-1-chasel.chiu@intel.com> References: <20211008051502.1243-1-chasel.chiu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3678 Implementation should search FSP_NON_VOLATILE_STORAGE_HOB2 firstly and only search FSP_NON_VOLATILE_STORAGE_HOB when former one is not found. Also added PeiGetLargeVariable () to support the scenarios where the variable data size is bigger than a single variable size limit. Cc: Nate DeSimone Cc: Liming Gao Cc: Eric Dong Signed-off-by: Chasel Chiu --- Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig= .c | 39 ++++++++++++++++++++++++++++----------- Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.c = | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++- Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig= .inf | 5 ++++- Platform/Intel/MinPlatformPkg/Include/Library/PeiLib.h = | 33 ++++++++++++++++++++++++++++++++- Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.inf = | 4 +++- Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec = | 1 + 6 files changed, 136 insertions(+), 15 deletions(-) diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/Save= MemoryConfig.c b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/= SaveMemoryConfig.c index 41ed2550bd..497c2cffb8 100644 --- a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryC= onfig.c +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryC= onfig.c @@ -2,7 +2,7 @@ This is the driver that locates the MemoryConfigurationData HOB, if it=0D exists, and saves the data to nvRAM.=0D =0D -Copyright (c) 2017, Intel Corporation. All rights reserved.
=0D +Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D @@ -17,6 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include =0D #include =0D #include =0D +#include =0D =0D /**=0D This is the standard EFI driver point that detects whether there is a=0D @@ -50,11 +51,27 @@ SaveMemoryConfigEntryPoint ( //=0D // Search for the Memory Configuration GUID HOB. If it is not present, = then=0D // there's nothing we can do. It may not exist on the update path.=0D + // Firstly check version2 FspNvsHob.=0D //=0D - GuidHob =3D GetFirstGuidHob (&gFspNonVolatileStorageHobGuid);=0D + GuidHob =3D GetFirstGuidHob (&gFspNonVolatileStorageHob2Guid);=0D if (GuidHob !=3D NULL) {=0D - HobData =3D GET_GUID_HOB_DATA (GuidHob);=0D - DataSize =3D GET_GUID_HOB_DATA_SIZE(GuidHob);=0D + HobData =3D (VOID *) (UINTN) ((FSP_NON_VOLATILE_STORAGE_HOB2 *) (UINTN= ) GuidHob)->NvsDataPtr;=0D + DataSize =3D ((FSP_NON_VOLATILE_STORAGE_HOB2 *) (UINTN) GuidHob)->NvsD= ataLength;=0D + } else {=0D + //=0D + // Fall back to version1 FspNvsHob=0D + //=0D + GuidHob =3D GetFirstGuidHob (&gFspNonVolatileStorageHobGuid);=0D + if (GuidHob !=3D NULL) {=0D + HobData =3D GET_GUID_HOB_DATA (GuidHob);=0D + DataSize =3D GET_GUID_HOB_DATA_SIZE (GuidHob);=0D + }=0D + }=0D +=0D + if (HobData !=3D NULL) {=0D + DEBUG ((DEBUG_INFO, "FspNvsHob.NvsDataLength:%d\n", DataSize));=0D + DEBUG ((DEBUG_INFO, "FspNvsHob.NvsDataPtr : 0x%x\n", HobData));=0D +=0D if (DataSize > 0) {=0D //=0D // Use the HOB to save Memory Configuration Data=0D @@ -65,8 +82,8 @@ SaveMemoryConfigEntryPoint ( return EFI_UNSUPPORTED;=0D }=0D Status =3D gRT->GetVariable (=0D - L"MemoryConfig",=0D - &gFspNonVolatileStorageHobGuid,=0D + L"FspNvsBuffer",=0D + &gFspNvsBufferVariableGuid,=0D NULL,=0D &BufferSize,=0D VariableData=0D @@ -80,8 +97,8 @@ SaveMemoryConfigEntryPoint ( }=0D =0D Status =3D gRT->GetVariable (=0D - L"MemoryConfig",=0D - &gFspNonVolatileStorageHobGuid,=0D + L"FspNvsBuffer",=0D + &gFspNvsBufferVariableGuid,=0D NULL,=0D &BufferSize,=0D VariableData=0D @@ -90,8 +107,8 @@ SaveMemoryConfigEntryPoint ( =0D if ( (EFI_ERROR(Status)) || BufferSize !=3D DataSize || 0 !=3D Compa= reMem (HobData, VariableData, DataSize)) {=0D Status =3D gRT->SetVariable (=0D - L"MemoryConfig",=0D - &gFspNonVolatileStorageHobGuid,=0D + L"FspNvsBuffer",=0D + &gFspNvsBufferVariableGuid,=0D (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERV= ICE_ACCESS),=0D DataSize,=0D HobData=0D @@ -106,7 +123,7 @@ SaveMemoryConfigEntryPoint ( //=0D Status =3D gBS->LocateProtocol(&gEdkiiVariableLockProtocolGuid, NULL= , (VOID **)&VariableLock);=0D if (!EFI_ERROR(Status)) {=0D - Status =3D VariableLock->RequestToLock(VariableLock, L"MemoryConfi= g", &gFspNonVolatileStorageHobGuid);=0D + Status =3D VariableLock->RequestToLock(VariableLock, L"FspNvsBuffe= r", &gFspNvsBufferVariableGuid);=0D ASSERT_EFI_ERROR(Status);=0D }=0D =0D diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.c b/Platfo= rm/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.c index 96dfd588dc..9e92387761 100644 --- a/Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.c +++ b/Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.c @@ -1,6 +1,6 @@ /** @file=0D =0D -Copyright (c) 2017, Intel Corporation. All rights reserved.
=0D +Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D @@ -9,6 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include =0D #include =0D #include =0D +#include =0D #include =0D =0D /**=0D @@ -108,6 +109,72 @@ PeiGetVariable ( return Status;=0D }=0D =0D +/**=0D + Returns the status whether get the large variable success. When variable= size=0D + is bigger than single UEFI variable size limit, The variable will be sav= ed in=0D + multiple UEFI variables. This function retrieves such large variable thr= ough the=0D + ReadOnlyVariable2 PPI GetVariable().=0D + The returned buffer is allocated using AllocatePage() to support > 64KB = and this=0D + buffer cannot be Free().=0D +=0D + If Name is NULL, then ASSERT().=0D + If Guid is NULL, then ASSERT().=0D + If Value is NULL, then ASSERT().=0D +=0D + @param[in] Name The pointer to a Null-terminated Unicode string.=0D + @param[in] Guid The pointer to an EFI_GUID structure=0D + @param[out] Value The buffer point saved the variable info.=0D + @param[out] Size The buffer size of the variable.=0D +=0D + @return EFI_OUT_OF_RESOURCES Allocate buffer failed.=0D + @return EFI_SUCCESS Find the specified variable.=0D + @return Others Errors Return errors from call to gRT->GetVar= iable.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiGetLargeVariable (=0D + IN CHAR16 *Name,=0D + IN EFI_GUID *Guid,=0D + OUT VOID **Value,=0D + OUT UINTN *Size OPTIONAL=0D + )=0D +{=0D + EFI_STATUS Status;=0D + UINTN VariableSize;=0D + VOID *VariableData;=0D +=0D + ASSERT (Name !=3D NULL);=0D + ASSERT (Guid !=3D NULL);=0D + ASSERT (Value !=3D NULL);=0D +=0D + VariableSize =3D 0;=0D + VariableData =3D NULL;=0D + Status =3D GetLargeVariable (Name, Guid, &VariableSize, NULL);=0D + if (Status =3D=3D EFI_BUFFER_TOO_SMALL) {=0D + VariableData =3D AllocatePages (EFI_SIZE_TO_PAGES (VariableSize));=0D + if (VariableData =3D=3D NULL) {=0D + DEBUG ((DEBUG_ERROR, "Error: Cannot create VariableData, out of memo= ry!\n"));=0D + ASSERT (FALSE);=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D + Status =3D GetLargeVariable (Name, Guid, &VariableSize, VariableData);= =0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "Error: Unable to read UEFI variable Status: %r= \n", Status));=0D + ASSERT_EFI_ERROR (Status);=0D + return Status;=0D + }=0D + if (Value !=3D NULL) {=0D + *Value =3D VariableData;=0D + }=0D + if (Size !=3D NULL) {=0D + *Size =3D VariableSize;=0D + }=0D + return EFI_SUCCESS;=0D + }=0D + return Status;=0D +}=0D +=0D EFI_PEI_FILE_HANDLE=0D InternalGetFfsHandleFromAnyFv (=0D IN CONST EFI_GUID *NameGuid=0D diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/Save= MemoryConfig.inf b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfi= g/SaveMemoryConfig.inf index 0c8689a6f6..eac0880504 100644 --- a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryC= onfig.inf +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryC= onfig.inf @@ -1,7 +1,7 @@ ### @file=0D # Component information file for SaveMemoryConfig module=0D #=0D -# Copyright (c) 2017, Intel Corporation. All rights reserved.
=0D +# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
=0D #=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D @@ -28,6 +28,7 @@ MdePkg/MdePkg.dec=0D MdeModulePkg/MdeModulePkg.dec=0D IntelFsp2Pkg/IntelFsp2Pkg.dec=0D + MinPlatformPkg/MinPlatformPkg.dec=0D =0D [Sources]=0D SaveMemoryConfig.c=0D @@ -39,6 +40,8 @@ =0D [Guids]=0D gFspNonVolatileStorageHobGuid ## CONSUMES=0D + gFspNonVolatileStorageHob2Guid ## CONSUMES=0D + gFspNvsBufferVariableGuid ## PRODUCES=0D =0D [Depex]=0D gEfiVariableArchProtocolGuid AND=0D diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/PeiLib.h b/Platf= orm/Intel/MinPlatformPkg/Include/Library/PeiLib.h index d8b1a47c58..86ffb378ec 100644 --- a/Platform/Intel/MinPlatformPkg/Include/Library/PeiLib.h +++ b/Platform/Intel/MinPlatformPkg/Include/Library/PeiLib.h @@ -1,6 +1,6 @@ /** @file=0D =0D -Copyright (c) 2017, Intel Corporation. All rights reserved.
=0D +Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D @@ -38,6 +38,37 @@ PeiGetVariable ( OUT UINTN *Size=0D );=0D =0D +/**=0D + Returns the status whether get the large variable success. When variable= size=0D + is bigger than single UEFI variable size limit, The variable will be sav= ed in=0D + multiple UEFI variables. This function retrieves such large variable thr= ough the=0D + ReadOnlyVariable2 PPI GetVariable().=0D + The returned buffer is allocated using AllocatePage() to support > 64KB = and this=0D + buffer cannot be Free().=0D +=0D + If Name is NULL, then ASSERT().=0D + If Guid is NULL, then ASSERT().=0D + If Value is NULL, then ASSERT().=0D +=0D + @param[in] Name The pointer to a Null-terminated Unicode string.=0D + @param[in] Guid The pointer to an EFI_GUID structure=0D + @param[out] Value The buffer point saved the variable info.=0D + @param[out] Size The buffer size of the variable.=0D +=0D + @return EFI_OUT_OF_RESOURCES Allocate buffer failed.=0D + @return EFI_SUCCESS Find the specified variable.=0D + @return Others Errors Return errors from call to gRT->GetVar= iable.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +PeiGetLargeVariable (=0D + IN CHAR16 *Name,=0D + IN EFI_GUID *Guid,=0D + OUT VOID **Value,=0D + OUT UINTN *Size OPTIONAL=0D + );=0D +=0D /**=0D Finds the file in any FV and gets file Address and Size=0D =0D diff --git a/Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.inf b/Plat= form/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.inf index 7e740172a0..bd57cf7870 100644 --- a/Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.inf +++ b/Platform/Intel/MinPlatformPkg/Library/PeiLib/PeiLib.inf @@ -1,7 +1,7 @@ ## @file=0D # Component information file for Board Init Test Library=0D #=0D -# Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.
=0D +# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
=0D #=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D @@ -20,9 +20,11 @@ PeiServicesLib=0D MemoryAllocationLib=0D DebugLib=0D + LargeVariableReadLib=0D =0D [Packages]=0D MdePkg/MdePkg.dec=0D + MinPlatformPkg/MinPlatformPkg.dec=0D =0D [Sources]=0D PeiLib.c=0D diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec b/Platform/In= tel/MinPlatformPkg/MinPlatformPkg.dec index bcb42f0ef9..d6e80a66ce 100644 --- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec @@ -50,6 +50,7 @@ gBdsEventBeforeConsoleAfterTrustedConsoleGuid =3D {0x51e49ff5, 0x28a9, = 0x4159, { 0xac, 0x8a, 0xb8, 0xc4, 0x88, 0xa7, 0xfd, 0xee}}=0D gBdsEventBeforeConsoleBeforeEndOfDxeGuid =3D {0xfcf26e41, 0xbda6, = 0x4633, { 0xb5, 0x73, 0xd4, 0xb8, 0x0e, 0x6d, 0xd0, 0x78}}=0D gBdsEventAfterConsoleReadyBeforeBootOptionGuid =3D {0x8eb3d5dc, 0xf4e7, = 0x4b57, { 0xa9, 0xe7, 0x27, 0x39, 0x10, 0xf2, 0x18, 0x9f}}=0D + gFspNvsBufferVariableGuid =3D {0x9c7715cd, 0x8d66, = 0x4d2a, { 0x90, 0x0d, 0x01, 0x45, 0x9a, 0x57, 0x59, 0x6b}}=0D =0D [LibraryClasses]=0D =0D --=20 2.28.0.windows.1