NVRAM emulation has no other purpose than implementing S3 support.

With S3 turned off in the VM configuration, this patch saves over 33 MB of
guest RAM: the 0x01400000..0x03500000 range is not reserved any longer;
see "OvmfPkg/PlatformPei/MemoryMap.txt".

The absence of LockBox (which is part of the emulated NVRAM) automatically
prevents:
- installation of OVMF's AcpiS3SaveDxe driver,
- loading of the BootScriptExecutorDxe driver (via Depex, due to lack of
  gEfiLockBoxProtocolGuid normally installed by OVMF's AcpiS3SaveDxe),
- coverage of the NVRAM area with an EfiACPIMemoryNVS memory allocation
  HOB, in PeiFvInitialization() [OvmfPkg/PlatformPei/Fv.c],
- installation of the cold-boot pemanent PEI memory above the NVRAM in
  PublishPeiMemory() [OvmfPkg/PlatformPei/MemDetect.c] -- it will be
  placed above the decompressed firmware image, same as before S3 was
  supported,
- enforcement of the decompression scratch buffer falling below the NVRAM
  base address in DecompressGuidedFv() [OvmfPkg/Sec/SecMain.c].

The patch causes OVMF's SEC to depend on QemuFwCfgLib (via EmuNvramLib),
which is where we rely on the new QemuFwCfgSecLib library instance.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <[email protected]>
---
 OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf |  1 +
 OvmfPkg/Library/EmuNvramLib/EmuNvramLib.c   | 31 +++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf 
b/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf
index a6c2851..6834e35 100644
--- a/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf
+++ b/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf
@@ -33,6 +33,7 @@
 [LibraryClasses]
   PcdLib
   DebugLib
+  QemuFwCfgLib
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdEmuNvramLockBoxSize
diff --git a/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.c 
b/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.c
index 31912da..309d961 100644
--- a/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.c
+++ b/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.c
@@ -15,11 +15,34 @@
 #include <Library/PcdLib.h>
 #include <Library/DebugLib.h>
 #include <Library/EmuNvramLib.h>
+#include <Library/QemuFwCfgLib.h>
+
+/**
+  Detect if S3 support has been explicitly deactivated.
+
+  @retval  TRUE  if S3 explicitly disabled,
+  @retval  FALSE if firmware configuration unavailable, or S3 enabled.
+*/
+STATIC
+BOOLEAN
+EFIAPI
+IsS3Disabled (
+  VOID
+  )
+{
+  //
+  // Since this code can run in SEC, we must explicitly check for the
+  // availability of the firmware configuration interface.
+  //
+  return QemuFwCfgIsAvailable () && QemuFwCfgS3Disabled ();
+}
+
 
 /**
   Return the size of the NVRAM portion used as LockBox.
 
   @retval  0 if LockBox inside the NVRAM is disabled.
+             This includes the case when S3 has been explicitly disabled.
   @return  Size otherwise.
 */
 UINT32
@@ -28,6 +51,9 @@ EmuNvramLockBoxSize (
   VOID
   )
 {
+  if (IsS3Disabled ()) {
+    return 0;
+  }
   return PcdGet32 (PcdEmuNvramLockBoxSize);
 }
 
@@ -35,6 +61,7 @@ EmuNvramLockBoxSize (
   Return the size of the NVRAM portion used for S3 Resume Pool emulation.
 
   @retval  0 if S3 Resume Pool emulation inside the NVRAM is disabled.
+             This includes the case when S3 has been explicitly disabled.
   @return  Size otherwise.
 */
 UINT32
@@ -43,6 +70,9 @@ EmuNvramS3ResumePoolSize (
   VOID
   )
 {
+  if (IsS3Disabled ()) {
+    return 0;
+  }
   return PcdGet32 (PcdEmuNvramS3ResumePoolSize);
 }
 
@@ -50,6 +80,7 @@ EmuNvramS3ResumePoolSize (
   Return the full (cumulative) size of the emulated NVRAM.
 
   @retval  0 if NVRAM emulation is disabled.
+             This includes the case when S3 has been explicitly disabled.
   @return  Size otherwise.
 **/
 UINT32
-- 
1.8.3.1



------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to