From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 AE3CE203BEBF5 for ; Mon, 27 Mar 2017 01:08:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490602136; x=1522138136; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=zanHpqemdOOekzMge/GpSlUiPsoMETOjdPH9r5f6zKA=; b=nS/J/j619P2W6BgiiCJxvX3doyLPvNkF310c/6Q1a6E4A3p88vT1UtI5 Oz6ghA/KL3ANRx0zrvlO1R2KBWhUdA==; Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Mar 2017 01:08:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,229,1486454400"; d="scan'208";a="80948373" Received: from junghyun-mobl.amr.corp.intel.com (HELO jljusten-skl.amr.corp.intel.com) ([10.252.131.12]) by fmsmga005.fm.intel.com with ESMTP; 27 Mar 2017 01:08:56 -0700 From: Jordan Justen To: edk2-devel@lists.01.org Cc: Jordan Justen , Laszlo Ersek Date: Mon, 27 Mar 2017 01:05:41 -0700 Message-Id: <20170327080544.24748-10-jordan.l.justen@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170327080544.24748-1-jordan.l.justen@intel.com> References: <20170327080544.24748-1-jordan.l.justen@intel.com> Subject: [PATCH 09/12] OvmfPkg PlatformPei: Set flash variable PCDs X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Mar 2017 08:08:56 -0000 This allows the PEI based variable drivers to run. Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jordan Justen --- OvmfPkg/PlatformPei/Platform.c | 34 +--------- OvmfPkg/PlatformPei/Platform.h | 7 ++- OvmfPkg/PlatformPei/PlatformPei.inf | 10 ++- OvmfPkg/PlatformPei/Vars.c | 122 ++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+), 33 deletions(-) create mode 100644 OvmfPkg/PlatformPei/Vars.c diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index 77a8a16c15..2e943d6e7b 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -1,7 +1,7 @@ /**@file Platform PEI driver - Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
Copyright (c) 2011, Andrei Warkentin This program and the accompanying materials @@ -499,35 +499,6 @@ BootModeInitialization ( VOID -ReserveEmuVariableNvStore ( - ) -{ - EFI_PHYSICAL_ADDRESS VariableStore; - RETURN_STATUS PcdStatus; - - // - // Allocate storage for NV variables early on so it will be - // at a consistent address. Since VM memory is preserved - // across reboots, this allows the NV variable storage to survive - // a VM reboot. - // - VariableStore = - (EFI_PHYSICAL_ADDRESS)(UINTN) - AllocateAlignedRuntimePages ( - EFI_SIZE_TO_PAGES (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)), - PcdGet32 (PcdFlashNvStorageFtwSpareSize) - ); - DEBUG ((EFI_D_INFO, - "Reserved variable store memory: 0x%lX; size: %dkb\n", - VariableStore, - (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024 - )); - PcdStatus = PcdSet64S (PcdEmuVariableNvStoreReserved, VariableStore); - ASSERT_RETURN_ERROR (PcdStatus); -} - - -VOID DebugDumpCmos ( VOID ) @@ -660,8 +631,9 @@ InitializePlatform ( // mHostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID); + SetupVariables (); + if (mBootMode != BOOT_ON_S3_RESUME) { - ReserveEmuVariableNvStore (); PeiFvInitialization (); MemMapInitialization (); NoexecDxeInitialization (); diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h index 18f42c3f0e..dfbdb8b75d 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -1,7 +1,7 @@ /** @file Platform PEI module include file. - Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2017, 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 @@ -95,6 +95,11 @@ XenPublishRamRegions ( VOID ); +VOID +SetupVariables ( + VOID + ); + extern EFI_BOOT_MODE mBootMode; extern BOOLEAN mS3Supported; diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf index 53c6dd445a..0eaf27e553 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -2,7 +2,7 @@ # Platform PEI driver # # This module provides platform specific function to detect boot mode. -# Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2006 - 2017, 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 @@ -34,6 +34,7 @@ Fv.c MemDetect.c Platform.c + Vars.c Xen.c [Packages] @@ -83,9 +84,16 @@ gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDecompressionScratchEnd gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageVariableBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageFtwWorkingBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageFtwSpareBase gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration diff --git a/OvmfPkg/PlatformPei/Vars.c b/OvmfPkg/PlatformPei/Vars.c new file mode 100644 index 0000000000..563f847a55 --- /dev/null +++ b/OvmfPkg/PlatformPei/Vars.c @@ -0,0 +1,122 @@ +/**@file + Platform PEI Variable Store Initialization + + Copyright (c) 2006 - 2017, 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 http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" + BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER + EXPRESS OR IMPLIED. + +**/ + +#include +#include +#include +#include +#include + +#include "Platform.h" + +#define OVMF_FVB_BLOCK_SIZE (FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize)) +#define OVMF_FVB_SIZE (2 * FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize)) +#define OVMF_FV_HEADER_LENGTH OFFSET_OF (FVB_FV_HDR_AND_VARS_TEMPLATE, VarHdr) + + +VOID +ReserveEmuVariableNvStore ( + ) +{ + EFI_PHYSICAL_ADDRESS VariableStore; + UINT32 Offset; + RETURN_STATUS PcdStatus; + + // + // Allocate storage for NV variables early on so it will be + // at a consistent address. Since VM memory is preserved + // across reboots, this allows the NV variable storage to survive + // a VM reboot. + // + VariableStore = + (EFI_PHYSICAL_ADDRESS)(UINTN) + AllocateAlignedRuntimePages ( + EFI_SIZE_TO_PAGES (OVMF_FVB_SIZE), + PcdGet32 (PcdFlashNvStorageFtwSpareSize) + ); + ASSERT (VariableStore != 0); + ASSERT ((VariableStore + OVMF_FVB_SIZE) <= MAX_ADDRESS); + DEBUG ((EFI_D_INFO, + "Reserved variable store memory: 0x%lX; size: %dkb\n", + VariableStore, + (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024 + )); + PcdStatus = PcdSet64S (PcdEmuVariableNvStoreReserved, VariableStore); + ASSERT_RETURN_ERROR (PcdStatus); + + // + // Initialize the main FV header and variable store header + // + PcdStatus = PcdSet64S ( + PcdFlashNvStorageVariableBase64, + VariableStore); + ASSERT_RETURN_ERROR (PcdStatus); + + // + // Initialize the Fault Tolerant Write data area + // + Offset = PcdGet32 (PcdVariableStoreSize); + PcdStatus = PcdSet32S ( + PcdFlashNvStorageFtwWorkingBase, + VariableStore + Offset); + ASSERT_RETURN_ERROR (PcdStatus); + + // + // Initialize the Fault Tolerant Write spare block + // + Offset = FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize); + PcdStatus = PcdSet32S ( + PcdFlashNvStorageFtwSpareBase, + VariableStore + Offset); + ASSERT_RETURN_ERROR (PcdStatus); +} + + +VOID +SetupVariables ( + VOID + ) +{ + RETURN_STATUS PcdStatus; + + if (PcdGetBool (PcdOvmfFlashVariablesEnable)) { + // + // If flash is enabled, then set the variable PCD to point + // directly at flash. + // + PcdStatus = PcdSet64S ( + PcdFlashNvStorageVariableBase64, + (UINTN) PcdGet32 (PcdOvmfFlashNvStorageVariableBase) + ); + ASSERT_RETURN_ERROR (PcdStatus); + PcdStatus = PcdSet32S ( + PcdFlashNvStorageFtwWorkingBase, + PcdGet32 (PcdOvmfFlashNvStorageFtwWorkingBase) + ); + ASSERT_RETURN_ERROR (PcdStatus); + PcdStatus = PcdSet32S ( + PcdFlashNvStorageFtwSpareBase, + PcdGet32 (PcdOvmfFlashNvStorageFtwSpareBase) + ); + ASSERT_RETURN_ERROR (PcdStatus); + } else { + // + // If flash is not enabled, then allocate a buffer and initialize + // it if necessary for variable operations. + // + ReserveEmuVariableNvStore (); + } +} -- 2.11.0