In the following patches we'll need three 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 |  42 +++++++++
 OvmfPkg/Include/Library/EmuNvramLib.h       |  32 +++++++
 OvmfPkg/Library/EmuNvramLib/EmuNvramLib.c   | 138 ++++++++++++++++++++++++++++
 OvmfPkg/OvmfPkg.dec                         |   8 ++
 OvmfPkg/OvmfPkgIa32.dsc                     |   1 +
 OvmfPkg/OvmfPkgIa32X64.dsc                  |   1 +
 OvmfPkg/OvmfPkgX64.dsc                      |   1 +
 7 files changed, 223 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..d1d441a
--- /dev/null
+++ b/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.inf
@@ -0,0 +1,42 @@
+## @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.PcdEmuNvramSmramSize
+  gUefiOvmfPkgTokenSpaceGuid.PcdEmuNvramSmstPtrSize
+  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..50c7a38
--- /dev/null
+++ b/OvmfPkg/Include/Library/EmuNvramLib.h
@@ -0,0 +1,32 @@
+/** @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 EmuNvramSmramBase        (VOID);
+UINT32 EFIAPI EmuNvramSmramSize        (VOID);
+UINT32 EFIAPI EmuNvramSmstPtrBase      (VOID);
+UINT32 EFIAPI EmuNvramSmstPtrSize      (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..ccd0942
--- /dev/null
+++ b/OvmfPkg/Library/EmuNvramLib/EmuNvramLib.c
@@ -0,0 +1,138 @@
+/** @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 for SMRAM emulation.
+
+  @retval  0 if SMRAM emulation inside the NVRAM is disabled.
+  @return  Size otherwise.
+*/
+UINT32
+EFIAPI
+EmuNvramSmramSize (
+  VOID
+  )
+{
+  return PcdGet32 (PcdEmuNvramSmramSize);
+}
+
+/**
+  Return the size of the NVRAM portion that stores the pointer to the SMST
+  (system management system table).
+
+  @retval  0                            if the NVRAM doesn't provide such
+                                        storage,
+  @retval  sizeof(EFI_PHYSICAL_ADDRESS) if the storage is provided.
+*/
+UINT32
+EFIAPI
+EmuNvramSmstPtrSize (
+  VOID
+  )
+{
+  UINT32 Size;
+
+  Size = PcdGet32 (PcdEmuNvramSmstPtrSize);
+  ASSERT (Size == 0 || Size == sizeof (EFI_PHYSICAL_ADDRESS));
+  return Size;
+}
+
+/**
+  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 disbled.
+  @return  Size otherwise.
+**/
+UINT32
+EFIAPI
+EmuNvramSize (
+  VOID
+  )
+{
+  return ALIGN_VALUE (EmuNvramSmramSize (), EFI_PAGE_SIZE) +
+         ALIGN_VALUE (EmuNvramSmstPtrSize (), 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 for SMRAM emulation.
+*/
+UINT32
+EFIAPI
+EmuNvramSmramBase (
+  VOID
+  )
+{
+  return EmuNvramBase ();
+}
+
+/**
+  Return the base address of the NVRAM portion that stores the pointer to the
+  SMST (system management system table).
+*/
+UINT32
+EFIAPI
+EmuNvramSmstPtrBase (
+  VOID
+  )
+{
+  return EmuNvramSmramBase () +
+    ALIGN_VALUE (EmuNvramSmramSize (), EFI_PAGE_SIZE);
+}
+
+
+/**
+  Return the base address of the NVRAM portion used for S3 Resume Pool
+  emulation.
+*/
+UINT32
+EFIAPI
+EmuNvramS3ResumePoolBase (
+  VOID
+  )
+{
+  return EmuNvramSmstPtrBase () +
+    ALIGN_VALUE (EmuNvramSmstPtrSize (), EFI_PAGE_SIZE);
+}
diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 9d7fedf..6cdf38f 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -69,6 +69,14 @@
   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: SMRAM, storage for pointer to SMST, S3 Resume Pool.
+  gUefiOvmfPkgTokenSpaceGuid.PcdEmuNvramSmramSize|0x00100000|UINT32|0x11
+  gUefiOvmfPkgTokenSpaceGuid.PcdEmuNvramSmstPtrSize|0x00000008|UINT32|0x12
+  gUefiOvmfPkgTokenSpaceGuid.PcdEmuNvramS3ResumePoolSize|0x02000000|UINT32|0x13
+
 [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