Browse Source

EmulatorPkg: Add persistent memory in EmuThunkPpi

The persistent memory is for PEIM to use, and won't lose during cold
or warm reset. PcdPersistentMemorySize is only used by WinHost.c,
other modules can check the persistent memory size using the field
PersistentMemorySize.

Cc: Andrew Fish <afish@apple.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
Liu, Zhiguang 1 year ago
parent
commit
22f73b6d2d

+ 2 - 1
EmulatorPkg/EmulatorPkg.dec

@@ -2,7 +2,7 @@
 #
 #
 # This is the Emu Emulation Environment Platform
 # This is the Emu Emulation Environment Platform
 #
 #
-# Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.<BR>
 # Portions copyright (c) 2011, Apple Inc. All rights reserved.
 # Portions copyright (c) 2011, Apple Inc. All rights reserved.
 # (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
 # (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
 #
 #
@@ -86,6 +86,7 @@
   # The user ID and password are fixed as below.
   # The user ID and password are fixed as below.
   gEmulatorPkgTokenSpaceGuid.PcdRedfishServieUserId|"admin"|VOID*|0x00001022
   gEmulatorPkgTokenSpaceGuid.PcdRedfishServieUserId|"admin"|VOID*|0x00001022
   gEmulatorPkgTokenSpaceGuid.PcdRedfishServiePassword|"pwd123456"|VOID*|0x00001023
   gEmulatorPkgTokenSpaceGuid.PcdRedfishServiePassword|"pwd123456"|VOID*|0x00001023
+  gEmulatorPkgTokenSpaceGuid.PcdPersistentMemorySize|0x4000000|UINT32|0x00001024
 
 
 [PcdsFixedAtBuild, PcdsPatchableInModule]
 [PcdsFixedAtBuild, PcdsPatchableInModule]
   gEmulatorPkgTokenSpaceGuid.PcdEmuBootMode|1|UINT32|0x00001006
   gEmulatorPkgTokenSpaceGuid.PcdEmuBootMode|1|UINT32|0x00001006

+ 3 - 1
EmulatorPkg/Include/Ppi/EmuThunk.h

@@ -2,7 +2,7 @@
   Emulator Thunk to abstract OS services from pure EFI code
   Emulator Thunk to abstract OS services from pure EFI code
 
 
   Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
   Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
-
+  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 
 **/
 **/
@@ -107,6 +107,8 @@ typedef struct {
   EMU_PEI_AUTOSCAN           MemoryAutoScan;
   EMU_PEI_AUTOSCAN           MemoryAutoScan;
   EMU_PEI_FD_INFORMATION     FirmwareDevices;
   EMU_PEI_FD_INFORMATION     FirmwareDevices;
   EMU_PEI_THUNK_INTERFACE    Thunk;
   EMU_PEI_THUNK_INTERFACE    Thunk;
+  UINTN                      PersistentMemorySize;
+  UINT8                      PersistentMemory[0];
 } EMU_THUNK_PPI;
 } EMU_THUNK_PPI;
 
 
 extern EFI_GUID  gEmuThunkPpiGuid;
 extern EFI_GUID  gEmuThunkPpiGuid;

+ 11 - 2
EmulatorPkg/Unix/Host/Host.c

@@ -1,6 +1,6 @@
 /*++ @file
 /*++ @file
 
 
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.<BR>
 Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
 Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 
@@ -102,6 +102,7 @@ main (
   CHAR16                *FirmwareVolumesStr;
   CHAR16                *FirmwareVolumesStr;
   UINTN                 *StackPointer;
   UINTN                 *StackPointer;
   FILE                  *GdbTempFile;
   FILE                  *GdbTempFile;
+  EMU_THUNK_PPI         *SecEmuThunkPpi;
 
 
   //
   //
   // Xcode does not support sourcing gdb scripts directly, so the Xcode XML
   // Xcode does not support sourcing gdb scripts directly, so the Xcode XML
@@ -137,7 +138,15 @@ main (
   //
   //
   // PPIs pased into PEI_CORE
   // PPIs pased into PEI_CORE
   //
   //
-  AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuThunkPpiGuid, &mSecEmuThunkPpi);
+  SecEmuThunkPpi = AllocateZeroPool (sizeof (EMU_THUNK_PPI) + FixedPcdGet32 (PcdPersistentMemorySize));
+  if (SecEmuThunkPpi == NULL) {
+    printf ("ERROR : Can not allocate memory for SecEmuThunkPpi.  Exiting.\n");
+    exit (1);
+  }
+
+  CopyMem (SecEmuThunkPpi, &mSecEmuThunkPpi, sizeof (EMU_THUNK_PPI));
+  SecEmuThunkPpi->PersistentMemorySize = FixedPcdGet32 (PcdPersistentMemorySize);
+  AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuThunkPpiGuid, SecEmuThunkPpi);
 
 
   SecInitThunkProtocol ();
   SecInitThunkProtocol ();
 
 

+ 2 - 1
EmulatorPkg/Unix/Host/Host.inf

@@ -2,7 +2,7 @@
 # Entry Point of Emu Emulator
 # Entry Point of Emu Emulator
 #
 #
 # Main executable file of Unix Emulator that loads PEI core after initialization finished.
 # Main executable file of Unix Emulator that loads PEI core after initialization finished.
-# Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.<BR>
 # Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
 # Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
 #
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -106,6 +106,7 @@
   gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwSpareBase
   gEmulatorPkgTokenSpaceGuid.PcdEmuFlashNvStorageFtwSpareBase
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
   gEmulatorPkgTokenSpaceGuid.PcdPeiServicesTablePage
   gEmulatorPkgTokenSpaceGuid.PcdPeiServicesTablePage
+  gEmulatorPkgTokenSpaceGuid.PcdPersistentMemorySize
 
 
 [FeaturePcd]
 [FeaturePcd]
   gEmulatorPkgTokenSpaceGuid.PcdEmulatorLazyLoadSymbols
   gEmulatorPkgTokenSpaceGuid.PcdEmulatorLazyLoadSymbols

+ 10 - 1
EmulatorPkg/Win/Host/WinHost.c

@@ -450,6 +450,7 @@ Returns:
   UINTN                SystemAffinityMask;
   UINTN                SystemAffinityMask;
   INT32                LowBit;
   INT32                LowBit;
   UINTN                ResetJumpCode;
   UINTN                ResetJumpCode;
+  EMU_THUNK_PPI        *SecEmuThunkPpi;
 
 
   //
   //
   // Enable the privilege so that RTC driver can successfully run SetTime()
   // Enable the privilege so that RTC driver can successfully run SetTime()
@@ -491,7 +492,15 @@ Returns:
   //
   //
   // PPIs pased into PEI_CORE
   // PPIs pased into PEI_CORE
   //
   //
-  AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuThunkPpiGuid, &mSecEmuThunkPpi);
+  SecEmuThunkPpi = AllocateZeroPool (sizeof (EMU_THUNK_PPI) + FixedPcdGet32 (PcdPersistentMemorySize));
+  if (SecEmuThunkPpi == NULL) {
+    SecPrint ("ERROR : Can not allocate memory for SecEmuThunkPpi.  Exiting.\n");
+    exit (1);
+  }
+
+  CopyMem (SecEmuThunkPpi, &mSecEmuThunkPpi, sizeof (EMU_THUNK_PPI));
+  SecEmuThunkPpi->PersistentMemorySize = FixedPcdGet32 (PcdPersistentMemorySize);
+  AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuThunkPpiGuid, SecEmuThunkPpi);
   AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEfiPeiReset2PpiGuid, &mEmuReset2Ppi);
   AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEfiPeiReset2PpiGuid, &mEmuReset2Ppi);
 
 
   //
   //

+ 1 - 1
EmulatorPkg/Win/Host/WinHost.inf

@@ -74,7 +74,7 @@
 
 
 [Pcd]
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdInitValueInTempStack
   gEfiMdeModulePkgTokenSpaceGuid.PcdInitValueInTempStack
-
+  gEmulatorPkgTokenSpaceGuid.PcdPersistentMemorySize
   gEmulatorPkgTokenSpaceGuid.PcdEmuBootMode
   gEmulatorPkgTokenSpaceGuid.PcdEmuBootMode
   gEmulatorPkgTokenSpaceGuid.PcdEmuFirmwareVolume
   gEmulatorPkgTokenSpaceGuid.PcdEmuFirmwareVolume
   gEmulatorPkgTokenSpaceGuid.PcdEmuMemorySize
   gEmulatorPkgTokenSpaceGuid.PcdEmuMemorySize