]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmulatorPkg/WinHost: Add Reset2 PPI
authorNi, Ray <ray.ni@intel.com>
Sat, 12 Nov 2022 04:00:42 +0000 (12:00 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 5 Dec 2022 05:35:41 +0000 (05:35 +0000)
When shutdown is requested, WinHost exits.
Otherwise, WinHost re-runs from SEC.
Tested no extra memory consumption with multiple resets in PEI.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Cc: Andrew Fish <afish@apple.com>
Reviewed-by: Zhiguang Liu <zhiguang.liu@intel.com>
EmulatorPkg/Win/Host/WinHost.c
EmulatorPkg/Win/Host/WinHost.h
EmulatorPkg/Win/Host/WinHost.inf

index 9b10290ff3c089ec846698bec093d4f68dd58ea8..096292f95a6fadc2e6ef3c1098212d63f5c40608 100644 (file)
@@ -56,6 +56,14 @@ NT_FD_INFO  *gFdInfo;
 UINTN             gSystemMemoryCount = 0;\r
 NT_SYSTEM_MEMORY  *gSystemMemory;\r
 \r
+BASE_LIBRARY_JUMP_BUFFER  mResetJumpBuffer;\r
+CHAR8                     *mResetTypeStr[] = {\r
+  "EfiResetCold",\r
+  "EfiResetWarm",\r
+  "EfiResetShutdown",\r
+  "EfiResetPlatformSpecific"\r
+};\r
+\r
 /*++\r
 \r
 Routine Description:\r
@@ -196,6 +204,45 @@ SecPrint (
     );\r
 }\r
 \r
+/**\r
+  Resets the entire platform.\r
+\r
+  @param[in] ResetType      The type of reset to perform.\r
+  @param[in] ResetStatus    The status code for the reset.\r
+  @param[in] DataSize       The size, in bytes, of ResetData.\r
+  @param[in] ResetData      For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown\r
+                            the data buffer starts with a Null-terminated string, optionally\r
+                            followed by additional binary data. The string is a description\r
+                            that the caller may use to further indicate the reason for the\r
+                            system reset.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+WinReset (\r
+  IN EFI_RESET_TYPE  ResetType,\r
+  IN EFI_STATUS      ResetStatus,\r
+  IN UINTN           DataSize,\r
+  IN VOID            *ResetData OPTIONAL\r
+  )\r
+{\r
+  ASSERT (ResetType <= EfiResetPlatformSpecific);\r
+  SecPrint ("  Emu ResetSystem is called: ResetType = %s\n", mResetTypeStr[ResetType]);\r
+\r
+  if (ResetType == EfiResetShutdown) {\r
+    exit (0);\r
+  } else {\r
+    //\r
+    // Jump back to SetJump with jump code = ResetType + 1\r
+    //\r
+    LongJump (&mResetJumpBuffer, ResetType + 1);\r
+  }\r
+}\r
+\r
+EFI_PEI_RESET2_PPI  mEmuReset2Ppi = {\r
+  WinReset\r
+};\r
+\r
 /*++\r
 \r
 Routine Description:\r
@@ -388,6 +435,7 @@ Returns:
   UINTN                ProcessAffinityMask;\r
   UINTN                SystemAffinityMask;\r
   INT32                LowBit;\r
+  UINTN                ResetJumpCode;\r
 \r
   //\r
   // Enable the privilege so that RTC driver can successfully run SetTime()\r
@@ -430,6 +478,7 @@ Returns:
   // PPIs pased into PEI_CORE\r
   //\r
   AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEmuThunkPpiGuid, &mSecEmuThunkPpi);\r
+  AddThunkPpi (EFI_PEI_PPI_DESCRIPTOR_PPI, &gEfiPeiReset2PpiGuid, &mEmuReset2Ppi);\r
 \r
   //\r
   // Emulator Bus Driver Thunks\r
@@ -500,14 +549,6 @@ Returns:
     exit (1);\r
   }\r
 \r
-  SetMem32 (TemporaryRam, TemporaryRamSize, PcdGet32 (PcdInitValueInTempStack));\r
-\r
-  SecPrint (\r
-    "  OS Emulator passing in %u KB of temp RAM at 0x%08lx to SEC\n\r",\r
-    TemporaryRamSize / SIZE_1KB,\r
-    TemporaryRam\r
-    );\r
-\r
   //\r
   // If enabled use the magic page to communicate between modules\r
   // This replaces the PI PeiServicesTable pointer mechanism that\r
@@ -591,6 +632,24 @@ Returns:
     SecPrint ("\n\r");\r
   }\r
 \r
+  ResetJumpCode = SetJump (&mResetJumpBuffer);\r
+\r
+  //\r
+  // Do not clear memory content for warm reset.\r
+  //\r
+  if (ResetJumpCode != EfiResetWarm + 1) {\r
+    SecPrint ("  OS Emulator clearing temp RAM and physical RAM (to be discovered later)......\n\r");\r
+    SetMem32 (TemporaryRam, TemporaryRamSize, PcdGet32 (PcdInitValueInTempStack));\r
+    for (Index = 0; Index < gSystemMemoryCount; Index++) {\r
+      SetMem32 ((VOID *)(UINTN)gSystemMemory[Index].Memory, (UINTN)gSystemMemory[Index].Size, PcdGet32 (PcdInitValueInTempStack));\r
+    }\r
+  }\r
+\r
+  SecPrint (\r
+    "  OS Emulator passing in %u KB of temp RAM at 0x%08lx to SEC\n\r",\r
+    TemporaryRamSize / SIZE_1KB,\r
+    TemporaryRam\r
+    );\r
   //\r
   // Hand off to SEC Core\r
   //\r
index 49d42d1ad86175034fb0bbda3bc0491b1cd3a98b..a9a21007e316e5da7279ce66c609d4638a6e3250 100644 (file)
@@ -1,6 +1,6 @@
 /**@file\r
 \r
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -26,6 +26,7 @@ Abstract:
 #include <Guid/FileSystemInfo.h>\r
 #include <Guid/FileSystemVolumeLabelInfo.h>\r
 #include <Ppi/EmuThunk.h>\r
+#include <Ppi/Reset2.h>\r
 #include <Protocol/EmuThunk.h>\r
 #include <Protocol/SimpleFileSystem.h>\r
 \r
index 2030ac084702550b014269b9e7879d57015dced9..b61901fae294f7bd4445fd8812180b3b42c1752d 100644 (file)
@@ -2,7 +2,7 @@
 # Entry Point of Win Emulator\r
 #\r
 # Main executable file of Win Emulator that loads Sec core after initialization finished.\r
-# Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2022, Intel Corporation. All rights reserved.<BR>\r
 # Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
 # (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>\r
 #\r
@@ -58,6 +58,7 @@
 \r
 [Ppis]\r
   gEmuThunkPpiGuid\r
+  gEfiPeiReset2PpiGuid\r
 \r
 [Protocols]\r
   gEmuIoThunkProtocolGuid\r