From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 888AB211B5A27 for ; Mon, 14 Jan 2019 07:20:06 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jan 2019 07:20:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,478,1539673200"; d="scan'208";a="116647419" Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by fmsmga008.fm.intel.com with ESMTP; 14 Jan 2019 07:20:05 -0800 From: Star Zeng To: edk2-devel@lists.01.org Cc: Star Zeng , Jian J Wang , Hao Wu Date: Mon, 14 Jan 2019 23:19:44 +0800 Message-Id: <1547479196-40248-4-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1547479196-40248-1-git-send-email-star.zeng@intel.com> References: <1547479196-40248-1-git-send-email-star.zeng@intel.com> Subject: [PATCH V2 03/15] MdeModulePkg Variable: Not get NV PCD in VariableWriteServiceInitialize 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: Mon, 14 Jan 2019 15:20:06 -0000 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1323 Merge EmuVariable and Real variable driver. Add macro NV_STORAGE_VARIABLE_BASE. Not get NV PCD in VariableWriteServiceInitialize, but in FtwNotificationEvent/SmmFtwNotificationEvent, then VariableWriteServiceInitialize could be not aware the NV storage is real or emulated. This patch prepares for adding emulated variable NV mode support in VariableRuntimeDxe. Cc: Jian J Wang Cc: Hao Wu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- .../Universal/Variable/RuntimeDxe/Variable.c | 20 ++------------------ .../Universal/Variable/RuntimeDxe/Variable.h | 9 +++++++-- .../Universal/Variable/RuntimeDxe/VariableDxe.c | 12 ++++++++---- .../Universal/Variable/RuntimeDxe/VariableSmm.c | 16 +++++++++++----- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c index 0b675c8f36df..424f92a53757 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -3770,10 +3770,7 @@ InitRealNonVolatileVariableStore ( return EFI_OUT_OF_RESOURCES; } - NvStorageBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64); - if (NvStorageBase == 0) { - NvStorageBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase); - } + NvStorageBase = NV_STORAGE_VARIABLE_BASE; ASSERT (NvStorageBase != 0); // @@ -4027,7 +4024,7 @@ FlushHobVariableToFlash ( } /** - Initializes variable write service after FTW was ready. + Initializes variable write service. @retval EFI_SUCCESS Function successfully executed. @retval Others Fail to initialize the variable service. @@ -4041,23 +4038,10 @@ VariableWriteServiceInitialize ( EFI_STATUS Status; UINTN Index; UINT8 Data; - EFI_PHYSICAL_ADDRESS VariableStoreBase; - EFI_PHYSICAL_ADDRESS NvStorageBase; VARIABLE_ENTRY_PROPERTY *VariableEntry; AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock); - NvStorageBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64); - if (NvStorageBase == 0) { - NvStorageBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase); - } - VariableStoreBase = NvStorageBase + (mNvFvHeaderCache->HeaderLength); - - // - // Let NonVolatileVariableBase point to flash variable store base directly after FTW ready. - // - mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase; - // // Check if the free area is really free. // diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h index 938eb5de61fa..566e7268d187 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h @@ -2,7 +2,7 @@ The internal header file includes the common header files, defines internal structure and functions used by Variable modules. -Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -46,6 +46,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "PrivilegePolymorphic.h" +#define NV_STORAGE_VARIABLE_BASE (EFI_PHYSICAL_ADDRESS) \ + (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ? \ + PcdGet64 (PcdFlashNvStorageVariableBase64) : \ + PcdGet32 (PcdFlashNvStorageVariableBase)) + #define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE | \ EFI_VARIABLE_BOOTSERVICE_ACCESS | \ EFI_VARIABLE_RUNTIME_ACCESS | \ @@ -473,7 +478,7 @@ GetMaxVariableSize ( ); /** - Initializes variable write service after FVB was ready. + Initializes variable write service. @retval EFI_SUCCESS Function successfully executed. @retval Others Fail to initialize the variable service. diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c index f7185df3a7eb..baba6729c1c2 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c @@ -386,13 +386,17 @@ FtwNotificationEvent ( ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize); } + NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE; + VariableStoreBase = NvStorageVariableBase + (mNvFvHeaderCache->HeaderLength); + + // + // Let NonVolatileVariableBase point to flash variable store base directly after FTW ready. + // + mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase; + // // Find the proper FVB protocol for variable. // - NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64); - if (NvStorageVariableBase == 0) { - NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase); - } Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol); if (EFI_ERROR (Status)) { return ; diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c index 8c53f84ff6e8..018587ed7373 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c @@ -14,7 +14,7 @@ VariableServiceSetVariable(), VariableServiceQueryVariableInfo(), ReclaimForOS(), SmmVariableGetStatistics() should also do validation based on its own knowledge. -Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -37,6 +37,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include "Variable.h" +extern EFI_FIRMWARE_VOLUME_HEADER *mNvFvHeaderCache; extern VARIABLE_INFO_ENTRY *gVariableInfo; EFI_HANDLE mSmmVariableHandle = NULL; EFI_HANDLE mVariableHandle = NULL; @@ -867,6 +868,7 @@ SmmFtwNotificationEvent ( ) { EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS VariableStoreBase; EFI_SMM_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol; EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol; EFI_PHYSICAL_ADDRESS NvStorageVariableBase; @@ -889,13 +891,17 @@ SmmFtwNotificationEvent ( ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize); } + NvStorageVariableBase = NV_STORAGE_VARIABLE_BASE; + VariableStoreBase = NvStorageVariableBase + (mNvFvHeaderCache->HeaderLength); + + // + // Let NonVolatileVariableBase point to flash variable store base directly after FTW ready. + // + mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase; + // // Find the proper FVB protocol for variable. // - NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64); - if (NvStorageVariableBase == 0) { - NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase); - } Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol); if (EFI_ERROR (Status)) { return EFI_NOT_FOUND; -- 2.7.0.windows.1