From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CCC6F21173C7A for ; Sat, 13 Oct 2018 02:09:55 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Oct 2018 02:09:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,376,1534834800"; d="scan'208";a="272077136" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga006.fm.intel.com with ESMTP; 13 Oct 2018 02:09:54 -0700 Received: from fmsmsx154.amr.corp.intel.com (10.18.116.70) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sat, 13 Oct 2018 02:09:54 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by FMSMSX154.amr.corp.intel.com (10.18.116.70) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sat, 13 Oct 2018 02:09:53 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.217]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.245]) with mapi id 14.03.0319.002; Sat, 13 Oct 2018 17:09:52 +0800 From: "Zeng, Star" To: Sami Mujawar , "edk2-devel@lists.01.org" CC: "ard.biesheuvel@linaro.org" , "leif.lindholm@linaro.org" , "Wang, Jian J" , "Ni, Ruiyu" , "evan.lloyd@arm.com" , "Matteo.Carlini@arm.com" , "Stephanie.Hughes-Fitt@arm.com" , "nd@arm.com" , "Zeng, Star" Thread-Topic: [PATCH v1 3/6] MdeModulePkg: Map persistent (NV) memory Thread-Index: AQHUYjmKVbDeE1pxHEKEB8tHNvxqcKUc1f3w Date: Sat, 13 Oct 2018 09:09:51 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103BC1E173@shsmsx102.ccr.corp.intel.com> References: <20181012144009.48732-1-sami.mujawar@arm.com> <20181012144009.48732-4-sami.mujawar@arm.com> In-Reply-To: <20181012144009.48732-4-sami.mujawar@arm.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v1 3/6] MdeModulePkg: Map persistent (NV) memory X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Oct 2018 09:09:56 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Sami, Thanks for the patch. I just checked this patch and roughly checked [PATCH v1 5/6] ArmVirtPkg: Ad= d kvmtool platform driver. I would like to suggest that the code added in this patch to be moved into = KvmtoolPlatformDxe which is added by [PATCH v1 5/6] as KvmtoolPlatformDxe i= s the producer of KvmtoolPlatformDxe and has full knowledge to that memory = usage. Thanks, Star -----Original Message----- From: Sami Mujawar [mailto:sami.mujawar@arm.com]=20 Sent: Friday, October 12, 2018 10:40 PM To: edk2-devel@lists.01.org Cc: ard.biesheuvel@linaro.org; leif.lindholm@linaro.org; Zeng, Star ; Wang, Jian J ; Ni, Ruiyu ; evan.lloyd@arm.com; Matteo.Carlini@arm.com; Stephanie.Hughes-Fit= t@arm.com; nd@arm.com Subject: [PATCH v1 3/6] MdeModulePkg: Map persistent (NV) memory Some platforms are able to preserve a memory range across system resets. Th= is memory can be used for the Non-Volatile variables storage. The PcdEmuVar= iableNvStoreReserved is used to specify this option. This patch enables mapping of this Non-Volatile memory range as runtime mem= ory so that the variable storage is accessible post ExitBootServices. Also added PcdMapEmuVariableNvStoreReserved to select if the memory region = described by PcdMapEmuVariableNvStoreReserved should be mapped by the Varia= ble Emulation driver. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sami Mujawar --- The changes can be seen at https://github.com/samimujawar/edk2/commit/a4fbf= 2336578546031920337239f41544a3a130e Notes: v1: - Add support for mapping memory used for Non-Volatile variable [SAMI= ] storage as runtime memory. MdeModulePkg/MdeModulePkg.dec | = 9 +++ MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c | = 77 +++++++++++++++++++- MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf | = 6 ++ 3 files changed, 90 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec = index 6037504fa789d4ca96d45bf3a776dd77bc17a909..077d3682371e1d44b0c86f922f8= 0536080403e52 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -8,6 +8,7 @@ # (C) Copyright 2016 Hewlett Packard Enterprise Development LP
# Copy= right (c) 2017, AMD Incorporated. All rights reserved.
# Copyright (c)= 2016, Microsoft Corporation
+# Copyright (c) 2018, ARM Limited. All rights reserved.
# This program and the accompanying materials are licensed and made availa= ble under # the terms and conditions of the BSD License that accompanies t= his distribution. # The full text of the license may be found at @@ -1592,6 +1593,14 @@ [Pcd= sFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] # @Prompt Reserved memory range for EMU variable NV storage. gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0|UINT64|0x= 40000008 =20 + ## Indicates if the reserved memory range for the EMU Variable=20 + driver's # NV Variable Store should be mapped by the driver. The=20 + memory range size # must be PcdVariableStoreSize. + # TRUE - Map the memory as persistent runtime memory.
+ # FALSE - Do not map the memory.
+ # @Prompt Map persistent memory range for EMU variable NV storage. + =20 + gEfiMdeModulePkgTokenSpaceGuid.PcdMapEmuVariableNvStoreReserved|FALSE| + BOOLEAN|0x4000000f + ## This PCD defines the times to print hello world string. # This PCD is a sample to explain UINT32 PCD usage. # @Prompt HellowWorld print times. diff --git a/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c b/= MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c index 1bcf931b96a670ab1fc66cd66f9d88d68f363e7f..e103a340aea9394d9ff146efa55= 81d3180c45035 100644 --- a/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c +++ b/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c @@ -4,6 +4,7 @@ The nonvolatile variable space doesn't exist. =20 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2018, ARM Limited. All rights reserved.
This program and the accompanying materials are licensed and made availab= le under the terms and conditions of the BSD License which accompanies thi= s distribution. The full text of the license may be found at @@ -14,6 +15,= 8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR I= MPLIED. =20 **/ =20 +#include + #include "Variable.h" =20 /// @@ -1643,11 +1646,13 @@ EmuQueryVariableInfo ( =20 This function allocates memory space for variable store area and initial= izes its attributes. =20 + @param ImageHandle The Image handle of this driver. @param VolatileStore Indicates if the variable store is volatile. =20 **/ EFI_STATUS InitializeVariableStore ( + IN EFI_HANDLE ImageHandle, IN BOOLEAN VolatileStore ) { @@ -1693,6 +1698,74 @@ InitializeVariableStore ( VariableStore =3D (VARIABLE_STORE_HEADER *)(VOID*)(UINTN) PcdGet64 (PcdEmuVariableNvStoreReserved); + + if (PcdGetBool (PcdMapEmuVariableNvStoreReserved)) { + DEBUG(( + DEBUG_INFO, + "Initializing NV Variable Store at %p, Size =3D 0x%x\n", + VariableStore, PcdGet32 (PcdVariableStoreSize) + )); + + // Declare the NV Storage as persistent EFI_MEMORY_RUNTIME memory + Status =3D gDS->AddMemorySpace ( + EfiGcdMemoryTypePersistent, + (EFI_PHYSICAL_ADDRESS)VariableStore, + PcdGet32 (PcdVariableStoreSize), + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, "Failed to add memory space. Status =3D %r\n", + Status + )); + return Status; + } + + Status =3D gDS->AllocateMemorySpace ( + EfiGcdAllocateAddress, + EfiGcdMemoryTypePersistent, + 0, + PcdGet32 (PcdVariableStoreSize), + (EFI_PHYSICAL_ADDRESS*)&VariableStore, + ImageHandle, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Failed to allocate memory space. Status =3D %r\n", + Status + )); + gDS->RemoveMemorySpace ( + (EFI_PHYSICAL_ADDRESS)VariableStore, + PcdGet32 (PcdVariableStoreSize) + ); + return Status; + } + + Status =3D gDS->SetMemorySpaceAttributes ( + (EFI_PHYSICAL_ADDRESS)VariableStore, + PcdGet32 (PcdVariableStoreSize), + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Failed to set memory attributes. Status =3D %r\n", + Status + )); + gDS->FreeMemorySpace ( + (EFI_PHYSICAL_ADDRESS)VariableStore, + PcdGet32 (PcdVariableStoreSize) + ); + gDS->RemoveMemorySpace ( + (EFI_PHYSICAL_ADDRESS)VariableStore, + PcdGet32 (PcdVariableStoreSize) + ); + return Status; + } + } + if ( (VariableStore->Size =3D=3D PcdGet32 (PcdVariableStoreSize)) && (VariableStore->Format =3D=3D VARIABLE_STORE_FORMATTED) && @@ -18= 06,7 +1879,7 @@ VariableCommonInitialize ( // // Intialize volatile variable store // - Status =3D InitializeVariableStore (TRUE); + Status =3D InitializeVariableStore (ImageHandle, TRUE); if (EFI_ERROR (Status)) { FreePool(mVariableModuleGlobal); return Status; @@ -1814,7 +1887,7 @@ VariableCommonInitialize ( // // Intialize non volatile variable store // - Status =3D InitializeVariableStore (FALSE); + Status =3D InitializeVariableStore (ImageHandle, FALSE); =20 return Status; } diff --git a/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRunti= meDxe.inf b/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntim= eDxe.inf index 12d52dd130e317c7ed041cf144805b8547bfc62b..1b5902749e1806143e92ccc2009= a7512d57b940b 100644 --- a/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.i= nf +++ b/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDx +++ e.inf @@ -5,6 +5,7 @@ # four EFI_RUNTIME_SERVICES: SetVariable, GetVariable, GetNextVariableName= and QueryVariableInfo. # # Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2018, ARM Limited. All rights reserved.
# # This program and the accompanying materials # are licensed and made a= vailable under the terms and conditions of the BSD License @@ -53,6 +54,7 @= @ [LibraryClasses] BaseMemoryLib HobLib PcdLib + DxeServicesTableLib =20 [Protocols] gEfiVariableArchProtocolGuid ## PRODUCES @@ -77,10 +79,14 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize ## CON= SUMES gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize ## CON= SUMES gEfiMdeModulePkgTokenSpaceGuid.PcdHwErrStorageSize ## CON= SUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdMapEmuVariableNvStoreReserved ## CON= SUMES =20 [FeaturePcd] gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics ## CONSUME= S # statistic the information of variable. =20 +[Depex.common.DXE_RUNTIME_DRIVER] + gEfiCpuArchProtocolGuid + [Depex] TRUE =20 -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'