In the following patches we'll need two kinds of storage that are reserved
from the OS and survive S3 suspend. (Non-volatility across cold reboot is
not needed.) This trivial library ensures that all parties will have the
same notion about where in guest RAM the various sections of the NVRAM are
stored.

Placement and size of the emulated NVRAM are arbitrary, we only take care
that it is above the decompressed firmware image, and safely apart from
the temporary output and scratch buffers.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <[email protected]>
---
 OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf |  41 +++++++++++
 OvmfPkg/Include/Library/EmuNvramLib.h       |  30 +++++++++
 OvmfPkg/Library/EmuNvramLib/EmuNvramLib.c   | 101 ++++++++++++++++++++++++++++
 OvmfPkg/OvmfPkg.dec                         |   7 ++
 OvmfPkg/OvmfPkgIa32.dsc                     |   1 +
 OvmfPkg/OvmfPkgIa32X64.dsc                  |   1 +
 OvmfPkg/OvmfPkgX64.dsc                      |   1 +
 7 files changed, 182 insertions(+)
 create mode 100644 OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf
 create mode 100644 OvmfPkg/Include/Library/EmuNvramLib.h
 create mode 100644 OvmfPkg/Library/EmuNvramLib/EmuNvramLib.c

diff --git a/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf 
b/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf
new file mode 100644
index 0000000..a6c2851
--- /dev/null
+++ b/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf
@@ -0,0 +1,41 @@
+## @file
+#
+#  Library exposing OVMF's emulated NVRAM.
+#
+#  Copyright (C) 2013, Red Hat, Inc.
+#
+#  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.
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = EmuNvramLib
+  FILE_GUID                      = 7FAD4BDA-A5BD-4D38-AEA5-4D93F49A1A0C
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = EmuNvramLib
+
+[Sources]
+  EmuNvramLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+  PcdLib
+  DebugLib
+
+[Pcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdEmuNvramLockBoxSize
+  gUefiOvmfPkgTokenSpaceGuid.PcdEmuNvramS3ResumePoolSize
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfMemFvBase
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfMemFvSize
diff --git a/OvmfPkg/Include/Library/EmuNvramLib.h 
b/OvmfPkg/Include/Library/EmuNvramLib.h
new file mode 100644
index 0000000..a9be356
--- /dev/null
+++ b/OvmfPkg/Include/Library/EmuNvramLib.h
@@ -0,0 +1,30 @@
+/** @file
+  Library exposing OVMF's emulated NVRAM.
+
+  Copyright (C) 2013, Red Hat, Inc.
+
+  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.
+**/
+
+#ifndef __EMU_NVRAM_LIB__
+#define __EMU_NVRAM_LIB__
+
+#include <Uefi/UefiBaseType.h>
+
+//
+// Please see the documentation in the C source file.
+//
+
+UINT32 EFIAPI EmuNvramBase             (VOID);
+UINT32 EFIAPI EmuNvramSize             (VOID);
+UINT32 EFIAPI EmuNvramLockBoxBase      (VOID);
+UINT32 EFIAPI EmuNvramLockBoxSize      (VOID);
+UINT32 EFIAPI EmuNvramS3ResumePoolBase (VOID);
+UINT32 EFIAPI EmuNvramS3ResumePoolSize (VOID);
+#endif
diff --git a/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.c 
b/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.c
new file mode 100644
index 0000000..31912da
--- /dev/null
+++ b/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.c
@@ -0,0 +1,101 @@
+/** @file
+  Library exposing OVMF's emulated NVRAM.
+
+  Copyright (C) 2013, Red Hat, Inc.
+
+  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 <Library/PcdLib.h>
+#include <Library/DebugLib.h>
+#include <Library/EmuNvramLib.h>
+
+/**
+  Return the size of the NVRAM portion used as LockBox.
+
+  @retval  0 if LockBox inside the NVRAM is disabled.
+  @return  Size otherwise.
+*/
+UINT32
+EFIAPI
+EmuNvramLockBoxSize (
+  VOID
+  )
+{
+  return PcdGet32 (PcdEmuNvramLockBoxSize);
+}
+
+/**
+  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.
+  @return  Size otherwise.
+*/
+UINT32
+EFIAPI
+EmuNvramS3ResumePoolSize (
+  VOID
+  )
+{
+  return PcdGet32 (PcdEmuNvramS3ResumePoolSize);
+}
+
+/**
+  Return the full (cumulative) size of the emulated NVRAM.
+
+  @retval  0 if NVRAM emulation is disabled.
+  @return  Size otherwise.
+**/
+UINT32
+EFIAPI
+EmuNvramSize (
+  VOID
+  )
+{
+  return ALIGN_VALUE (EmuNvramLockBoxSize (), EFI_PAGE_SIZE) +
+         ALIGN_VALUE (EmuNvramS3ResumePoolSize (), EFI_PAGE_SIZE);
+}
+
+/**
+  Return the base address of the emulated NVRAM.
+**/
+UINT32
+EFIAPI
+EmuNvramBase (
+  VOID
+  )
+{
+  return PcdGet32 (PcdOvmfMemFvBase) + PcdGet32 (PcdOvmfMemFvSize) + SIZE_4MB;
+}
+
+/**
+  Return the base address of the NVRAM portion used as LockBox.
+*/
+UINT32
+EFIAPI
+EmuNvramLockBoxBase (
+  VOID
+  )
+{
+  return EmuNvramBase ();
+}
+
+/**
+  Return the base address of the NVRAM portion used for S3 Resume Pool
+  emulation.
+*/
+UINT32
+EFIAPI
+EmuNvramS3ResumePoolBase (
+  VOID
+  )
+{
+  return EmuNvramLockBoxBase () +
+    ALIGN_VALUE (EmuNvramLockBoxSize (), EFI_PAGE_SIZE);
+}
diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 9d7fedf..f83a36e 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -69,6 +69,13 @@
   gUefiOvmfPkgTokenSpaceGuid.PcdVirtioScsiMaxTargetLimit|31|UINT16|6
   gUefiOvmfPkgTokenSpaceGuid.PcdVirtioScsiMaxLunLimit|7|UINT32|7
 
+  ## Sizes of the different areas inside the emulated NVRAM. Areas can be
+  #  disabled individually by setting their respective sizes to zero. If all
+  #  sizes are zero, then NVRAM emulation is fully disabled. Supported areas
+  #  are: LockBox, S3 Resume Pool.
+  gUefiOvmfPkgTokenSpaceGuid.PcdEmuNvramLockBoxSize|0x00100000|UINT32|0x11
+  gUefiOvmfPkgTokenSpaceGuid.PcdEmuNvramS3ResumePoolSize|0x02000000|UINT32|0x12
+
 [PcdsFixedAtBuild]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageEventLogBase|0x0|UINT32|0x8
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageEventLogSize|0x0|UINT32|0x9
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 2e13e0e..52abe22 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -101,6 +101,7 @@
   LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf
   LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf
   
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
+  EmuNvramLib|OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf
 
 !ifdef $(SOURCE_DEBUG_ENABLE)
   
PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 64404a6..4d964a5 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -106,6 +106,7 @@
   LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf
   LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf
   
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
+  EmuNvramLib|OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf
 
 !ifdef $(SOURCE_DEBUG_ENABLE)
   
PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index ab9cd16..7427fa2 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -106,6 +106,7 @@
   LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf
   LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf
   
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
+  EmuNvramLib|OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf
 
 !ifdef $(SOURCE_DEBUG_ENABLE)
   
PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLibDebug.inf
-- 
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