From nobody Mon May 20 22:24:36 2024 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+104169+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+104169+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1683341319; cv=none; d=zohomail.com; s=zohoarc; b=oLbrZrf/f1eAihipFfvCZ72Cwrx5ApOTnKaaaRuecK5HmbBFaT2yo8tPgj+7KUgA6v8S1/kcLVecDVb+jNq6gJx2eYGSxulNPhN5U4whaFeHgRAKkJG3neUqZGw75WB+xuhlHOCauzh5n03oJxh5kyvMuzrBuVW88/dp17DFq+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683341319; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=+RWWegeGwko9Tx8t/JJQaRlu0YIMBBu8mXfHUNOKPMo=; b=PG6v5jJa1Jzc4p9VSFIJXnWYIJ89+vSM/YyuFuX2IFPdX9a90ImB5T/dYC4191F2fJ2ItvHWGwaewDHwwPWg1IaN5cH/yi0975WEICP1VBzAldZmLiO5yvF9L3ACrFVMplrMscKdfvhuzmicgeqkePVnbBLsVjGlDr77Kn0lzhA= 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+104169+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 16833413196564.207837006087857; Fri, 5 May 2023 19:48:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id mrYPYY1788612x6uvMGka5me; Fri, 05 May 2023 19:48:39 -0700 X-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 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" X-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" X-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-devel] [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> 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,raghava.gudla@intel.com X-Gm-Message-State: ZCewVCYFY0qTsVVEQ6BIawqKx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683341319; bh=qYmCKtYYit7ru/Z3bCPRDkbVFKtpOjxGgVzuFbqxiIM=; h=Cc:Date:From:Reply-To:Subject:To; b=ElcV8VPUihGca1Q9PD6je1bCfMQw27BG5L9Zgq6hY3iYjjmRWsIbkEsZS2Gta3wfbZ7 gXlw603JM7sgWnUJfFSb4ektpe2kPxr63Odfz+5DXrDGAOME03h30ugmcYwpuY1wN0YDc P2lphJPso/QletVNK7vP/2JI8ad1zvWdwrQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683341321062100002 Content-Type: text/plain; charset="utf-8" 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 #include #include +#include +#include =20 /** This is the standard EFI driver point that detects whether there is a @@ -45,6 +47,9 @@ SaveMemoryConfigEntryPoint ( UINTN DataSize; UINTN BufferSize; BOOLEAN DataIsIdentical; + VOID *CompressedData; + UINT64 CompressedSize; + UINTN CompressedAllocationPages; =20 DataSize =3D 0; BufferSize =3D 0; @@ -73,6 +78,35 @@ SaveMemoryConfigEntryPoint ( } } =20 + if (PcdGetBool (PcdEnableCompressFspNvsHob) =3D=3D 1) { + CompressedData =3D NULL; + CompressedSize =3D 0; + CompressedAllocationPages =3D 0; + + DEBUG ((DEBUG_INFO, "compressing mem config nvs variable\n")); + if (DataSize > 0) { + CompressedAllocationPages =3D EFI_SIZE_TO_PAGES (DataSize); + CompressedData =3D AllocatePages (CompressedAllocationPages); + if (CompressedData =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "[%a] - Failed to allocate compressed data bu= ffer.\n", __func__)); + ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES); + return EFI_OUT_OF_RESOURCES; + } + + CompressedSize =3D EFI_PAGES_TO_SIZE (CompressedAllocationPages); + Status =3D Compress (HobData, DataSize, CompressedData, &CompressedS= ize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "[%a] - failed to compress data. Status =3D %= r\n", __func__, Status)); + ASSERT_EFI_ERROR (Status); + FreePool(CompressedData); + return Status; + } else { + HobData =3D CompressedData; + DataSize =3D (UINTN) CompressedSize; + } + } + } + if (HobData !=3D NULL) { DEBUG ((DEBUG_INFO, "FspNvsHob.NvsDataLength:%d\n", DataSize)); DEBUG ((DEBUG_INFO, "FspNvsHob.NvsDataPtr : 0x%x\n", HobData)); 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 LargeVariableWriteLib BaseLib + CompressLib =20 [Packages] MdePkg/MdePkg.dec @@ -45,6 +46,9 @@ gFspNonVolatileStorageHob2Guid ## CONSUMES gFspNvsBufferVariableGuid ## PRODUCES =20 +[Pcd] + gMinPlatformPkgTokenSpaceGuid.PcdEnableCompressFspNvsHob + [Depex] gEfiVariableArchProtocolGuid AND - gEfiVariableWriteArchProtocolGuid \ No newline at end of file + gEfiVariableWriteArchProtocolGuid 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 LargeVariableReadLib|MinPlatformPkg/Library/BaseLargeVariableLib/BaseLar= geVariableReadLib.inf LargeVariableWriteLib|MinPlatformPkg/Library/BaseLargeVariableLib/BaseLa= rgeVariableWriteLib.inf + CompressLib|MinPlatformPkg/Library/CompressLib/CompressLib.inf =20 # # CryptLib 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 gMinPlatformPkgTokenSpaceGuid.PcdFadtMajorVersion|0x06|UINT8|0x90000030 gMinPlatformPkgTokenSpaceGuid.PcdFadtMinorVersion|0x03|UINT8|0x90000031 +## Controls whether the Memory Config UEFI Variable is saved as compressed= data. +# Data compression can significantly reduce variable storage usage for FSP= NVS buffer data. +# Platforms that choose to compress the data will need to decompress the v= ariable data upon +# extraction. + gMinPlatformPkgTokenSpaceGuid.PcdEnableCompressFspNvsHob|FALSE|BOOLEAN|0= x90000032 =20 [PcdsFixedAtBuild] =20 --=20 2.19.1.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 (#104169): https://edk2.groups.io/g/devel/message/104169 Mute This Topic: https://groups.io/mt/98719541/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-