From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.12628.1683331408032435924 for ; Fri, 05 May 2023 17:03:28 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=FtFTpGrR; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: raghava.gudla@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683331407; x=1714867407; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=pisepXEnJzvWKUnua2FBggMZXim726KFpk1zhHxfWvU=; b=FtFTpGrRvgUzZxgBWGhwkzLIcPdvTvQtPxu2ndZ//1vZx5I/Vl5s/mG2 9exm5nmQTncGUbUpJslXphm/g3koQBM4Ns6RDZA5PTHqmB1WeL523OfFX VJLH3N+xYyHdFrbEi2zEsjDhBVGGywIM2ormyBpBAfviZs8CCCqRacXgU 9MHTDpWXTEyWjONp6+yHYr2Qk6Twfk2nKupuM8Vo7bFWXUieAxaxj+rdT Pk1c+ppRhONca1j9MNlWyENzabkm/fwAF6yYegR88GuYsXYDAtKRmQFtT myVdkTUgdt8TbFeMlmKHGH1G2Ou9EY5bpGXZ+75UlMZXUepiaVnof2xaJ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="414867271" X-IronPort-AV: E=Sophos;i="5.99,253,1677571200"; d="scan'208";a="414867271" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 17:03:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="821918653" X-IronPort-AV: E=Sophos;i="5.99,253,1677571200"; d="scan'208";a="821918653" Received: from rgudlax-desk.amr.corp.intel.com ([10.34.40.178]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 17:03:19 -0700 From: Raghava Gudla To: devel@edk2.groups.io Cc: Raghava Gudla , Chasel Chiu , Nate DeSimone , Isaac Oram Subject: [edk2-platforms:PATCH V1] MinPlatformPkg/SaveMemoryConfig: Support NVS Data compression. Date: Fri, 5 May 2023 17:03:00 -0700 Message-Id: <20230506000300.389-1-raghava.gudla@intel.com> X-Mailer: git-send-email 2.40.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Around 50KB "FspNonVolatileStorageHob" data can be compressed to approximately 3 KB which can save NVRAM space and enhance life of the SPI part by decreasing the number of reclaim cycles needed. This patch added support to compress "FspNonVolatileStorageHob" data before saving to NVRAM. A PcdEnableCompressFspNvsHob is introduced to enable/disable this feature per platform usage. Cc: Chasel Chiu Cc: Nate DeSimone Cc: Isaac Oram Signed-off-by: Raghava Gudla --- .../SaveMemoryConfig/SaveMemoryConfig.c | 34 +++++++++++++++++++ .../SaveMemoryConfig/SaveMemoryConfig.inf | 6 +++- .../Include/Dsc/CoreCommonLib.dsc | 1 + .../Intel/MinPlatformPkg/MinPlatformPkg.dec | 5 +++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/Save= MemoryConfig.c b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/= SaveMemoryConfig.c index 0215e8eed..8aa935b54 100644 --- a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryC= onfig.c +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryC= onfig.c @@ -21,6 +21,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include =0D #include =0D #include =0D +#include =0D +#include =0D =0D /**=0D This is the standard EFI driver point that detects whether there is a=0D @@ -45,6 +47,9 @@ SaveMemoryConfigEntryPoint ( UINTN DataSize;=0D UINTN BufferSize;=0D BOOLEAN DataIsIdentical;=0D + VOID *CompressedData;=0D + UINT64 CompressedSize;=0D + UINTN CompressedAllocationPages;=0D =0D DataSize =3D 0;=0D BufferSize =3D 0;=0D @@ -73,6 +78,35 @@ SaveMemoryConfigEntryPoint ( }=0D }=0D =0D + if (PcdGetBool (PcdEnableCompressFspNvsHob) =3D=3D 1) {=0D + CompressedData =3D NULL;=0D + CompressedSize =3D 0;=0D + CompressedAllocationPages =3D 0;=0D +=0D + DEBUG ((DEBUG_INFO, "compressing mem config nvs variable\n"));=0D + if (DataSize > 0) {=0D + CompressedAllocationPages =3D EFI_SIZE_TO_PAGES (DataSize);=0D + CompressedData =3D AllocatePages (CompressedAllocationPages);=0D + if (CompressedData =3D=3D NULL) {=0D + DEBUG ((DEBUG_ERROR, "[%a] - Failed to allocate compressed data bu= ffer.\n", __func__));=0D + ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES);=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D +=0D + CompressedSize =3D EFI_PAGES_TO_SIZE (CompressedAllocationPages);=0D + Status =3D Compress (HobData, DataSize, CompressedData, &CompressedS= ize);=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((DEBUG_ERROR, "[%a] - failed to compress data. Status =3D %= r\n", __func__, Status));=0D + ASSERT_EFI_ERROR (Status);=0D + FreePool(CompressedData);=0D + return Status;=0D + } else {=0D + HobData =3D CompressedData;=0D + DataSize =3D (UINTN) CompressedSize;=0D + }=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 diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/Save= MemoryConfig.inf b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfi= g/SaveMemoryConfig.inf index 61e85a658..77920d031 100644 --- a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryC= onfig.inf +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryC= onfig.inf @@ -26,6 +26,7 @@ LargeVariableReadLib=0D LargeVariableWriteLib=0D BaseLib=0D + CompressLib=0D =0D [Packages]=0D MdePkg/MdePkg.dec=0D @@ -45,6 +46,9 @@ gFspNonVolatileStorageHob2Guid ## CONSUMES=0D gFspNvsBufferVariableGuid ## PRODUCES=0D =0D +[Pcd]=0D + gMinPlatformPkgTokenSpaceGuid.PcdEnableCompressFspNvsHob=0D +=0D [Depex]=0D gEfiVariableArchProtocolGuid AND=0D - gEfiVariableWriteArchProtocolGuid \ No newline at end of file + gEfiVariableWriteArchProtocolGuid=0D diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc b/= Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc index 5ce21cf31..dfe7d836d 100644 --- a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc +++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc @@ -147,6 +147,7 @@ BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.i= nf=0D LargeVariableReadLib|MinPlatformPkg/Library/BaseLargeVariableLib/BaseLar= geVariableReadLib.inf=0D LargeVariableWriteLib|MinPlatformPkg/Library/BaseLargeVariableLib/BaseLa= rgeVariableWriteLib.inf=0D + CompressLib|MinPlatformPkg/Library/CompressLib/CompressLib.inf=0D =0D #=0D # CryptLib=0D diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec b/Platform/In= tel/MinPlatformPkg/MinPlatformPkg.dec index 784abb828..e21d55fb3 100644 --- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec @@ -348,6 +348,11 @@ gMinPlatformPkgTokenSpaceGuid.PcdFadtFlags|0x000086A5|UINT32|0x90000027= =0D gMinPlatformPkgTokenSpaceGuid.PcdFadtMajorVersion|0x06|UINT8|0x90000030= =0D gMinPlatformPkgTokenSpaceGuid.PcdFadtMinorVersion|0x03|UINT8|0x90000031= =0D +## Controls whether the Memory Config UEFI Variable is saved as compressed= data.=0D +# Data compression can significantly reduce variable storage usage for FSP= NVS buffer data.=0D +# Platforms that choose to compress the data will need to decompress the v= ariable data upon=0D +# extraction.=0D + gMinPlatformPkgTokenSpaceGuid.PcdEnableCompressFspNvsHob|FALSE|BOOLEAN|0= x90000032=0D =0D [PcdsFixedAtBuild]=0D =0D --=20 2.19.1.windows.1