We don't need this reservation / preallocation in order to save data from suspend to resume. (The ZeroMem() is added to make this obvious.) It rather acts as a placeholder after cold boot, to keep the OS away.
S3Resume2Pei needs a PEI_S3_RESUME_STATE object. The object cannot be on the stack (because it is used across stack switching). It also can't be a global variable (because S3Resume2Pei in general could run from flash). S3Resume2Pei cannot allocate it dynamically either (because that could trample OS data). Hence we must preallocate the object for S3Resume2Pei, in a spot that the OS never touches. The lower-level PeiServicesAllocatePages() function [MdePkg/Library/PeiServicesLib] is called rather than the higher-level AllocatePool() / AllocatePages() functions [MdePkg/Library/PeiMemoryAllocationLib] because the latter wrappers don't provide access to EfiACPIMemoryNVS. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek <ler...@redhat.com> --- OvmfPkg/PlatformPei/PlatformPei.inf | 2 ++ OvmfPkg/PlatformPei/Platform.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf index 028a640..aebfa33 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -56,6 +56,7 @@ PeimEntryPoint MtrrLib PcdLib + BaseMemoryLib [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfMemFvBase @@ -70,6 +71,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress + gUefiCpuPkgTokenSpaceGuid.PcdPeiS3ResumeState [Ppis] gEfiPeiMasterBootModePpiGuid diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index 2616757..261c36c 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -35,9 +35,11 @@ #include <Ppi/MasterBootMode.h> #include <IndustryStandard/Pci22.h> #include <Guid/XenInfo.h> +#include <Guid/AcpiS3Context.h> #include <IndustryStandard/E820.h> #include <Library/ResourcePublicationLib.h> #include <Library/MtrrLib.h> +#include <Library/BaseMemoryLib.h> #include "Platform.h" #include "Cmos.h" @@ -401,6 +403,28 @@ ReserveEmuSmmArea ( VOID +ReservePeiS3ResumeState ( + VOID + ) +{ + UINTN NumPages; + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS Address; + + // + // The contents of this region doesn't have to survive reboot. Its location + // must though. + // + NumPages = EFI_SIZE_TO_PAGES (sizeof (PEI_S3_RESUME_STATE)); + Status = PeiServicesAllocatePages (EfiACPIMemoryNVS, NumPages, &Address); + ASSERT_EFI_ERROR (Status); + ZeroMem ((VOID *)(UINTN) Address, NumPages * EFI_PAGE_SIZE); + PcdSet64 (PcdPeiS3ResumeState, Address); + DEBUG ((EFI_D_INFO, "preallocated PeiS3ResumeState at 0x%Lx\n", Address)); +} + + +VOID DebugDumpCmos ( VOID ) @@ -462,6 +486,7 @@ InitializePlatform ( ReserveEmuVariableNvStore (); ReserveEmuSmmArea (); + ReservePeiS3ResumeState (); PeiFvInitialization (); -- 1.8.3.1 ------------------------------------------------------------------------------ Sponsored by Intel(R) XDK Develop, test and display web and hybrid apps with a single code base. Download it for free now! http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk _______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-devel