public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jordan Justen <jordan.l.justen@intel.com>
To: edk2-devel@lists.01.org
Cc: Jordan Justen <jordan.l.justen@intel.com>,
	Laszlo Ersek <lersek@redhat.com>
Subject: [PATCH 09/12] OvmfPkg PlatformPei: Set flash variable PCDs
Date: Mon, 27 Mar 2017 01:05:41 -0700	[thread overview]
Message-ID: <20170327080544.24748-10-jordan.l.justen@intel.com> (raw)
In-Reply-To: <20170327080544.24748-1-jordan.l.justen@intel.com>

This allows the PEI based variable drivers to run.

Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
---
 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.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>
 
   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.<BR>
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
   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.<BR>
+#  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
 #
 #  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.<BR>
+
+  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 <PiPei.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+
+#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



  parent reply	other threads:[~2017-03-27  8:08 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-27  8:05 [PATCH 00/12] OvmfPkg: Enable variable access in PEI Jordan Justen
2017-03-27  8:05 ` [PATCH 01/12] OvmfPkg/build.sh: Add support for --disable-flash switch Jordan Justen
2017-03-27  8:05 ` [PATCH 02/12] OvmfPkg: resolve PcdLib for all PEIMs individually Jordan Justen
2017-03-27  8:05 ` [PATCH 03/12] OvmfPkg: resolve PcdLib for PEIMs to PeiPcdLib by default Jordan Justen
2017-03-27  8:05 ` [PATCH 04/12] OvmfPkg QemuFlash: Make QemuFlash.* Base class safe Jordan Justen
2017-03-27  8:05 ` [PATCH 05/12] OvmfPkg QemuFlash: Make QemuFlashDetected external Jordan Justen
2017-03-27  8:05 ` [PATCH 06/12] OvmfPkg QemuFlash: Add DetectFlashBaseLib.inf 'NULL' library Jordan Justen
2017-03-27  8:05 ` [PATCH 07/12] OvmfPkg PlatformPei: Detect and set PcdOvmfFlashVariablesEnable Jordan Justen
2017-03-27  8:05 ` [PATCH 08/12] OvmfPkg/EmuVariableFvbRuntimeDxe: Use PcdOvmfFlashVariablesEnable Jordan Justen
2017-03-27  8:05 ` Jordan Justen [this message]
2017-03-27  8:05 ` [PATCH 10/12] OvmfPkg PlatformPei: Initialize memory based variable store buffer Jordan Justen
2017-03-27  8:05 ` [PATCH 11/12] OvmfPkg: Enable PEI variable access Jordan Justen
2017-03-27  8:05 ` [PATCH 12/12] OvmfPkg QemuFlashFvbServicesRuntimeDxe: Cleanup init now done in PEI Jordan Justen
2017-03-27 18:03 ` [PATCH 00/12] OvmfPkg: Enable variable access " Laszlo Ersek
2017-03-27 21:47   ` Jordan Justen
2017-03-28  9:22     ` Laszlo Ersek
2017-03-29  5:24       ` Jordan Justen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170327080544.24748-10-jordan.l.justen@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox