]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Add ResetSystemPei PEIM
authorRuiyu Ni <ruiyu.ni@intel.com>
Mon, 4 Sep 2017 08:50:14 +0000 (16:50 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Fri, 9 Feb 2018 07:30:00 +0000 (15:30 +0800)
This driver implements Reset2, ResetFilter and ResetHandler PPIs.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/MdeModulePkg.dsc
MdeModulePkg/MdeModulePkg.uni
MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c [new file with mode: 0644]
MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h [new file with mode: 0644]
MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf [new file with mode: 0644]
MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni [new file with mode: 0644]
MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni [new file with mode: 0644]

index 0d567d0ebf9f5b68cc9738897f6e7c8fdee17c7a..af0474223b13fef85d2115fd60b06efbdf4dd580 100644 (file)
   # @Prompt String FPDT Record Enable Only\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdEdkiiFpdtStringRecordEnableOnly|FALSE|BOOLEAN|0x00000109\r
 \r
   # @Prompt String FPDT Record Enable Only\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdEdkiiFpdtStringRecordEnableOnly|FALSE|BOOLEAN|0x00000109\r
 \r
+  ## Indicates the allowable maximum number of Reset Filters or Reset Handlers in PEI phase.\r
+  # @Prompt Maximum Number of PEI Reset Filters or Reset Handlers.\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaximumPeiResetNotifies|0x10|UINT32|0x0000010A\r
+\r
 [PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]\r
   ## This PCD defines the Console output row. The default value is 25 according to UEFI spec.\r
   #  This PCD could be set to 0 then console output would be at max column and max row.\r
 [PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]\r
   ## This PCD defines the Console output row. The default value is 25 according to UEFI spec.\r
   #  This PCD could be set to 0 then console output would be at max column and max row.\r
   ## This PCD specifies the additional pad size in FPDT Basic Boot Performance Table for\r
   #  the extension FPDT boot records received after ReadyToBoot and before ExitBootService.\r
   # @Prompt Pad size for extension FPDT boot records.\r
   ## This PCD specifies the additional pad size in FPDT Basic Boot Performance Table for\r
   #  the extension FPDT boot records received after ReadyToBoot and before ExitBootService.\r
   # @Prompt Pad size for extension FPDT boot records.\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdExtFpdtBootRecordPadSize|0x20000|UINT32|0x0001005F\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdExtFpdtBootRecordPadSize|0x0|UINT32|0x0001005F\r
 \r
   ## Indicates if ConIn device are connected on demand.<BR><BR>\r
   #   TRUE  - ConIn device are not connected during BDS and ReadKeyStroke/ReadKeyStrokeEx produced\r
 \r
   ## Indicates if ConIn device are connected on demand.<BR><BR>\r
   #   TRUE  - ConIn device are not connected during BDS and ReadKeyStroke/ReadKeyStrokeEx produced\r
index 34bb1a10ece128a9aebfbc59426832e47b04d4b5..b301f0c3b3721e13417e029800a966c2e430f380 100644 (file)
   MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf\r
   MdeModulePkg/Universal/Metronome/Metronome.inf\r
   MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf\r
   MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf\r
   MdeModulePkg/Universal/Metronome/Metronome.inf\r
   MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf\r
+  MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf {\r
+    <LibraryClasses>\r
+      ResetSystemLib|MdeModulePkg/Library/BaseResetSystemLibNull/BaseResetSystemLibNull.inf\r
+  }\r
   MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf\r
   MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf\r
   MdeModulePkg/Universal/SmbiosMeasurementDxe/SmbiosMeasurementDxe.inf\r
   MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf\r
   MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf\r
   MdeModulePkg/Universal/SmbiosMeasurementDxe/SmbiosMeasurementDxe.inf\r
index dacd6718d72ed89d21da1acb064376ed4dd2c053..203fe9230ff348cd5e3f3be8d534f24ea78b91b2 100644 (file)
 \r
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdCapsuleMax_HELP  #language en-US "CapsuleMax value in capsule report variable."\r
 \r
 \r
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdCapsuleMax_HELP  #language en-US "CapsuleMax value in capsule report variable."\r
 \r
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaximumPeiResetNotifies_PROMPT  #language en-US "Maximum Number of PEI Reset Filters or Reset Handlers."\r
+\r
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdMaximumPeiResetNotifies_HELP  #language en-US "Indicates the allowable maximum number of Reset Filters or Reset Handlers in PEI phase."\r
+\r
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdRecoveryFileName_PROMPT  #language en-US "Recover file name in PEI phase"\r
 \r
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdRecoveryFileName_HELP  #language en-US "This is recover file name in PEI phase.\n"\r
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdRecoveryFileName_PROMPT  #language en-US "Recover file name in PEI phase"\r
 \r
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdRecoveryFileName_HELP  #language en-US "This is recover file name in PEI phase.\n"\r
diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.c
new file mode 100644 (file)
index 0000000..0832e86
--- /dev/null
@@ -0,0 +1,355 @@
+/** @file\r
+  Implementation of Reset2, ResetFilter and ResetHandler PPIs.\r
+\r
+  Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "ResetSystem.h"\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 *mResetTypeStr[] = {\r
+  L"Cold", L"Warm", L"Shutdown", L"PlatformSpecific"\r
+};\r
+\r
+EFI_PEI_RESET2_PPI mPpiReset2 = {\r
+  ResetSystem2\r
+};\r
+\r
+EFI_GUID                *mProcessingOrder[] = {\r
+  &gEdkiiPlatformSpecificResetFilterPpiGuid,\r
+  &gEdkiiPlatformSpecificResetHandlerPpiGuid\r
+};\r
+\r
+RESET_FILTER_INSTANCE   mResetFilter = {\r
+  {\r
+    RegisterResetNotify,\r
+    UnregisterResetNotify\r
+  },\r
+  &gEdkiiPlatformSpecificResetFilterPpiGuid\r
+};\r
+\r
+RESET_FILTER_INSTANCE   mResetHandler = {\r
+  {\r
+    RegisterResetNotify,\r
+    UnregisterResetNotify\r
+  },\r
+  &gEdkiiPlatformSpecificResetHandlerPpiGuid\r
+};\r
+\r
+EFI_PEI_PPI_DESCRIPTOR mPpiListReset[] = {\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &gEfiPeiReset2PpiGuid,\r
+    &mPpiReset2\r
+  },\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &gEdkiiPlatformSpecificResetFilterPpiGuid,\r
+    &mResetFilter.ResetFilter\r
+  },\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
+    &gEdkiiPlatformSpecificResetHandlerPpiGuid,\r
+    &mResetHandler.ResetFilter\r
+  }\r
+};\r
+\r
+/**\r
+  Register a notification function to be called when ResetSystem() is called.\r
+\r
+  The RegisterResetNotify() function registers a notification function that is called when\r
+  ResetSystem() is called and prior to completing the reset of the platform.\r
+  The registered functions must not perform a platform reset themselves. These\r
+  notifications are intended only for the notification of components which may need some\r
+  special-purpose maintenance prior to the platform resetting.\r
+  The list of registered reset notification functions are processed if ResetSystem()is called\r
+  before ExitBootServices(). The list of registered reset notification functions is ignored if\r
+  ResetSystem() is called after ExitBootServices().\r
+\r
+  @param[in]  This              A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.\r
+  @param[in]  ResetFunction     Points to the function to be called when a ResetSystem() is executed.\r
+\r
+  @retval EFI_SUCCESS           The reset notification function was successfully registered.\r
+  @retval EFI_INVALID_PARAMETER ResetFunction is NULL.\r
+  @retval EFI_OUT_OF_RESOURCES  There are not enough resources available to register the reset notification function.\r
+  @retval EFI_ALREADY_STARTED   The reset notification function specified by ResetFunction has already been registered.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterResetNotify (\r
+  IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This,\r
+  IN EFI_RESET_SYSTEM                         ResetFunction\r
+  )\r
+{\r
+  RESET_FILTER_INSTANCE                       *ResetFilter;\r
+  RESET_FILTER_LIST                           *List;\r
+  VOID                                        *Hob;\r
+  UINTN                                       Index;\r
+\r
+  if (ResetFunction == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  ResetFilter = (RESET_FILTER_INSTANCE *) This;\r
+  ASSERT (CompareGuid (ResetFilter->Guid, &gEdkiiPlatformSpecificResetFilterPpiGuid) ||\r
+          CompareGuid (ResetFilter->Guid, &gEdkiiPlatformSpecificResetHandlerPpiGuid)\r
+          );\r
+\r
+  Hob = GetFirstGuidHob (ResetFilter->Guid);\r
+  if (Hob == NULL) {\r
+    //\r
+    // When the GUIDed HOB doesn't exist, create it.\r
+    //\r
+    List = (RESET_FILTER_LIST *)BuildGuidHob (\r
+                                  ResetFilter->Guid,\r
+                                  sizeof (RESET_FILTER_LIST) + sizeof (EFI_RESET_SYSTEM) * PcdGet32 (PcdMaximumPeiResetNotifies)\r
+                                  );\r
+    if (List == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    List->Signature = RESET_FILTER_LIST_SIGNATURE;\r
+    List->Count     = PcdGet32 (PcdMaximumPeiResetNotifies);\r
+    ZeroMem (List->ResetFilters, sizeof (EFI_RESET_SYSTEM) * List->Count);\r
+    List->ResetFilters[0] = ResetFunction;\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob);\r
+    ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE);\r
+    //\r
+    // Firstly check whether the ResetFunction is already registerred.\r
+    //\r
+    for (Index = 0; Index < List->Count; Index++) {\r
+      if (List->ResetFilters[Index] == ResetFunction) {\r
+        break;\r
+      }\r
+    }\r
+    if (Index != List->Count) {\r
+      return EFI_ALREADY_STARTED;\r
+    }\r
+\r
+    //\r
+    // Secondly find the first free slot.\r
+    //\r
+    for (Index = 0; Index < List->Count; Index++) {\r
+      if (List->ResetFilters[Index] == NULL) {\r
+        break;\r
+      }\r
+    }\r
+\r
+    if (Index == List->Count) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    List->ResetFilters[Index] = ResetFunction;\r
+    return EFI_SUCCESS;\r
+  }\r
+}\r
+\r
+/**\r
+  Unregister a notification function.\r
+\r
+  The UnregisterResetNotify() function removes the previously registered\r
+  notification using RegisterResetNotify().\r
+\r
+  @param[in]  This              A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.\r
+  @param[in]  ResetFunction     The pointer to the ResetFunction being unregistered.\r
+\r
+  @retval EFI_SUCCESS           The reset notification function was unregistered.\r
+  @retval EFI_INVALID_PARAMETER ResetFunction is NULL.\r
+  @retval EFI_INVALID_PARAMETER The reset notification function specified by ResetFunction was not previously\r
+                                registered using RegisterResetNotify().\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UnregisterResetNotify (\r
+  IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This,\r
+  IN EFI_RESET_SYSTEM                         ResetFunction\r
+  )\r
+{\r
+\r
+  RESET_FILTER_INSTANCE                       *ResetFilter;\r
+  RESET_FILTER_LIST                           *List;\r
+  VOID                                        *Hob;\r
+  UINTN                                       Index;\r
+\r
+  if (ResetFunction == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  ResetFilter = (RESET_FILTER_INSTANCE *)This;\r
+  ASSERT (CompareGuid (ResetFilter->Guid, &gEdkiiPlatformSpecificResetFilterPpiGuid) ||\r
+    CompareGuid (ResetFilter->Guid, &gEdkiiPlatformSpecificResetHandlerPpiGuid)\r
+  );\r
+\r
+  Hob = GetFirstGuidHob (ResetFilter->Guid);\r
+  if (Hob == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob);\r
+  ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE);\r
+  for (Index = 0; Index < List->Count; Index++) {\r
+    if (List->ResetFilters[Index] == ResetFunction) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (Index == List->Count) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  List->ResetFilters[Index] = NULL;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  The PEIM's entry point.\r
+\r
+  It initializes the Reset2, ResetFilter and ResetHandler PPIs.\r
+\r
+  @param[in] FileHandle  Handle of the file being invoked.\r
+  @param[in] PeiServices Describes the list of possible PEI Services.\r
+  \r
+  @retval EFI_SUCCESS         The entry point is executed successfully.\r
+  @retval EFI_ALREADY_STARTED The Reset2 PPI was already installed.\r
+  @retval others              Status code returned from PeiServicesInstallPpi().\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeResetSystem (\r
+  IN EFI_PEI_FILE_HANDLE     FileHandle,\r
+  IN CONST EFI_PEI_SERVICES  **PeiServices\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  VOID        *Ppi;\r
+\r
+  Status = PeiServicesLocatePpi (&gEfiPeiReset2PpiGuid, 0, NULL, (VOID **)&Ppi);\r
+  if (Status != EFI_NOT_FOUND) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  PeiServicesInstallPpi (mPpiListReset);\r
+\r
+  return Status;\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\r
+                                EfiResetShutdown the data buffer starts with a Null-terminated\r
+                                string, optionally followed by additional binary data.\r
+                                The string is a description that the caller may use to further\r
+                                indicate the reason for the system reset. ResetData is only\r
+                                valid if ResetStatus is something other than EFI_SUCCESS\r
+                                unless the ResetType is EfiResetPlatformSpecific\r
+                                where a minimum amount of ResetData is always required.\r
+                                For a ResetType of EfiResetPlatformSpecific the data buffer\r
+                                also starts with a Null-terminated string that is followed\r
+                                by an EFI_GUID that describes the specific type of reset to perform.\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetSystem2 (\r
+  IN EFI_RESET_TYPE   ResetType,\r
+  IN EFI_STATUS       ResetStatus,\r
+  IN UINTN            DataSize,\r
+  IN VOID             *ResetData OPTIONAL\r
+  )\r
+{\r
+  VOID                *Hob;\r
+  UINTN               Index;\r
+  RESET_FILTER_LIST   *List;\r
+  UINTN               OrderIndex;\r
+  UINT8               RecursionDepth;\r
+  UINT8               *RecursionDepthPointer;\r
+\r
+  //\r
+  // The recursion depth is stored in GUIDed HOB using gEfiCallerIdGuid.\r
+  //\r
+  Hob = GetFirstGuidHob (&gEfiCallerIdGuid);\r
+  if (Hob == NULL) {\r
+    RecursionDepth = 0;\r
+    RecursionDepthPointer = BuildGuidDataHob (&gEfiCallerIdGuid, &RecursionDepth, sizeof (RecursionDepth));\r
+  } else {\r
+    RecursionDepthPointer = (UINT8 *)GET_GUID_HOB_DATA (Hob);\r
+  }\r
+  //\r
+  // Only do REPORT_STATUS_CODE() on first call to ResetSystem()\r
+  //\r
+  if (*RecursionDepthPointer == 0) {\r
+    //\r
+    // Indicate reset system PEI service is called.\r
+    //\r
+    REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_SERVICE | EFI_SW_PS_PC_RESET_SYSTEM));\r
+  }\r
+\r
+  //\r
+  // Increase the call depth\r
+  //\r
+  (*RecursionDepthPointer)++;\r
+  DEBUG ((DEBUG_INFO, "PEI ResetSystem2: Reset call depth = %d.\n", *RecursionDepthPointer));\r
+\r
+  if (*RecursionDepthPointer <= MAX_RESET_NOTIFY_DEPTH) {\r
+    //\r
+    // Iteratively call Reset Filters and Reset Handlers.\r
+    //\r
+    for (OrderIndex = 0; OrderIndex < ARRAY_SIZE (mProcessingOrder); OrderIndex++) {\r
+      Hob = GetFirstGuidHob (mProcessingOrder[OrderIndex]);\r
+      if (Hob != NULL) {\r
+        List = (RESET_FILTER_LIST *)GET_GUID_HOB_DATA (Hob);\r
+        ASSERT (List->Signature == RESET_FILTER_LIST_SIGNATURE);\r
+\r
+        for (Index = 0; Index < List->Count; Index++) {\r
+          if (List->ResetFilters[Index] != NULL) {\r
+            List->ResetFilters[Index] (ResetType, ResetStatus, DataSize, ResetData);\r
+          }\r
+        }\r
+      }\r
+    }\r
+  } else {\r
+    ASSERT (ResetType < ARRAY_SIZE (mResetTypeStr));\r
+    DEBUG ((DEBUG_ERROR, "PEI ResetSystem2: Maximum reset call depth is met. Use the current reset type: %s!\n", mResetTypeStr[ResetType]));\r
+  }\r
+\r
+  switch (ResetType) {\r
+  case EfiResetWarm:\r
+    ResetWarm ();\r
+    break;\r
+\r
+ case EfiResetCold:\r
+    ResetCold ();\r
+    break;\r
+\r
+  case EfiResetShutdown:\r
+    ResetShutdown ();\r
+    return ;\r
+\r
+  case EfiResetPlatformSpecific:\r
+    ResetPlatformSpecific (DataSize, ResetData);\r
+    return;\r
+\r
+  default:\r
+    return ;\r
+  }\r
+\r
+  //\r
+  // Given we should have reset getting here would be bad\r
+  //\r
+  ASSERT (FALSE);\r
+}\r
diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h b/MdeModulePkg/Universal/ResetSystemPei/ResetSystem.h
new file mode 100644 (file)
index 0000000..f06d39b
--- /dev/null
@@ -0,0 +1,129 @@
+/** @file\r
+\r
+  Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _RESET_SYSTEM2_H_\r
+#define _RESET_SYSTEM2_H_\r
+\r
+\r
+#include <Uefi.h>\r
+#include <PiPei.h>\r
+\r
+#include <Ppi/Reset2.h>\r
+#include <Ppi/PlatformSpecificResetFilter.h>\r
+#include <Ppi/PlatformSpecificResetHandler.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/ResetSystemLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
+\r
+\r
+//\r
+// The maximum recursion depth to ResetSystem() by reset notification handlers\r
+//\r
+#define MAX_RESET_NOTIFY_DEPTH 10\r
+\r
+//\r
+// Data to put in GUIDed HOB\r
+//\r
+typedef struct {\r
+  UINT32                          Signature;\r
+  UINT32                          Count;\r
+  EFI_RESET_SYSTEM                ResetFilters[0]; // ResetFilters[PcdGet32 (PcdMaximumResetNotifies)]\r
+} RESET_FILTER_LIST;\r
+#define RESET_FILTER_LIST_SIGNATURE    SIGNATURE_32('r', 's', 't', 'l')\r
+\r
+\r
+typedef struct {\r
+  EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI ResetFilter;\r
+  EFI_GUID                                 *Guid;\r
+} RESET_FILTER_INSTANCE;\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\r
+                                EfiResetShutdown the data buffer starts with a Null-terminated\r
+                                string, optionally followed by additional binary data.\r
+                                The string is a description that the caller may use to further\r
+                                indicate the reason for the system reset. ResetData is only\r
+                                valid if ResetStatus is something other than EFI_SUCCESS\r
+                                unless the ResetType is EfiResetPlatformSpecific\r
+                                where a minimum amount of ResetData is always required.\r
+                                For a ResetType of EfiResetPlatformSpecific the data buffer\r
+                                also starts with a Null-terminated string that is followed\r
+                                by an EFI_GUID that describes the specific type of reset to perform.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetSystem2 (\r
+  IN EFI_RESET_TYPE   ResetType,\r
+  IN EFI_STATUS       ResetStatus,\r
+  IN UINTN            DataSize,\r
+  IN VOID             *ResetData OPTIONAL\r
+  );\r
+/**\r
+  Register a notification function to be called when ResetSystem() is called.\r
+\r
+  The RegisterResetNotify() function registers a notification function that is called when\r
+  ResetSystem()is called and prior to completing the reset of the platform.\r
+  The registered functions must not perform a platform reset themselves. These\r
+  notifications are intended only for the notification of components which may need some\r
+  special-purpose maintenance prior to the platform resetting.\r
+\r
+  @param[in]  This              A pointer to the EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI instance.\r
+  @param[in]  ResetFunction     Points to the function to be called when a ResetSystem() is executed.\r
+\r
+  @retval EFI_SUCCESS           The reset notification function was successfully registered.\r
+  @retval EFI_INVALID_PARAMETER ResetFunction is NULL.\r
+  @retval EFI_OUT_OF_RESOURCES  There are not enough resources available to register the reset notification function.\r
+  @retval EFI_ALREADY_STARTED   The reset notification function specified by ResetFunction has already been registered.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterResetNotify (\r
+  IN EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI *This,\r
+  IN EFI_RESET_SYSTEM                         ResetFunction\r
+  );\r
+\r
+/**\r
+  Unregister a notification function.\r
+\r
+  The UnregisterResetNotify() function removes the previously registered\r
+  notification using RegisterResetNotify().\r
+\r
+  @param[in]  This              A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.\r
+  @param[in]  ResetFunction     The pointer to the ResetFunction being unregistered.\r
+\r
+  @retval EFI_SUCCESS           The reset notification function was unregistered.\r
+  @retval EFI_INVALID_PARAMETER ResetFunction is NULL.\r
+  @retval EFI_INVALID_PARAMETER The reset notification function specified by ResetFunction was not previously\r
+                                registered using RegisterResetNotify().\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UnregisterResetNotify (\r
+  IN EFI_RESET_NOTIFICATION_PROTOCOL *This,\r
+  IN EFI_RESET_SYSTEM                ResetFunction\r
+  );\r
+#endif\r
diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.inf
new file mode 100644 (file)
index 0000000..38fdd16
--- /dev/null
@@ -0,0 +1,62 @@
+## @file\r
+# This driver implements Reset2, ResetFilter and ResetHandler PPIs.\r
+#\r
+# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials are\r
+# licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = ResetSystemPei\r
+  MODULE_UNI_FILE                = ResetSystemPei.uni\r
+  FILE_GUID                      = 6141E486-7543-4F1A-A579-FF532ED78E75\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InitializeResetSystem\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64\r
+#\r
+\r
+[Sources]\r
+  ResetSystem.h\r
+  ResetSystem.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  PeiServicesLib\r
+  HobLib\r
+  PeimEntryPoint\r
+  ResetSystemLib\r
+  ReportStatusCodeLib\r
+\r
+[Ppis]\r
+  gEfiPeiReset2PpiGuid                       ## PRODUCES\r
+  gEdkiiPlatformSpecificResetFilterPpiGuid   ## PRODUCES\r
+  gEdkiiPlatformSpecificResetHandlerPpiGuid  ## PRODUCES\r
+\r
+[Pcd]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaximumPeiResetNotifies\r
+\r
+[Depex]\r
+  TRUE\r
+\r
+[UserExtensions.TianoCore."ExtraFiles"]\r
+  ResetSystemPeiExtra.uni\r
diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPei.uni
new file mode 100644 (file)
index 0000000..6d2d650
--- /dev/null
@@ -0,0 +1,20 @@
+// /** @file\r
+// This driver implements Reset2, ResetFilter and ResetHandler PPIs.\r
+//\r
+// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials are\r
+// licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+// \r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// **/\r
+\r
+\r
+#string STR_MODULE_ABSTRACT             #language en-US "Implements Reset2, ResetFilter and ResetHandler PPIs"\r
+\r
+#string STR_MODULE_DESCRIPTION          #language en-US "This driver implements Reset2, ResetFilter and ResetHandler PPIs."\r
+\r
diff --git a/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni b/MdeModulePkg/Universal/ResetSystemPei/ResetSystemPeiExtra.uni
new file mode 100644 (file)
index 0000000..2681afc
--- /dev/null
@@ -0,0 +1,20 @@
+// /** @file\r
+// ResetSystemPei Localized Strings and Content\r
+//\r
+// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials are\r
+// licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// **/\r
+\r
+#string STR_PROPERTIES_MODULE_NAME \r
+#language en-US \r
+"Reset System PEIM"\r
+\r
+\r