]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/ResetSystemRuntimeDxe: Add platform filter and handler
authorMichael D Kinney <michael.d.kinney@intel.com>
Fri, 1 Sep 2017 07:51:08 +0000 (00:51 -0700)
committerRuiyu Ni <ruiyu.ni@intel.com>
Fri, 9 Feb 2018 07:29:56 +0000 (15:29 +0800)
Add support for platform specific reset filters and platform
specific reset handlers to ResetSystem().  A filter may modify
the reset type and reset data and call ResetSystem() with the
modified parameters.  A handler performs the reset action.

The support for platform specific filters and platform specific
handlers is based on the Reset Notification feature added to the
UEFI 2.7 Specification.

Platform specific reset filters are processed first so the final
reset type and reset data can be determined.  In the DXE Phase
The UEFI Reset Notifications are processed second so all UEFI
Drivers that have registered for a Reset Notification can perform
any required clean up actions.  The platform specific reset
handlers are processed third.  If there are no registered
platform specific reset handlers or none of them reset the
platform, then the default reset action based on the
ResetSystemLib is performed.

In the PEI Phase, filters and handlers are registered through
the following 2 PPIs that are based on
EFI_RESET_NOTIFICATION_PROTOCOL.
* gEdkiiPlatformSpecificResetFilterPpiGuid
* gEdkiiPlatformSpecificResetHandlerPpiGuid

In the DXE Phase, filters and handlers are registered through
the following 2 Protocols that are based on
EFI_RESET_NOTIFICATION_PROTOCOL.
* gEdkiiPlatformSpecificResetFilterProtocolGuid
* gEdkiiPlatformSpecificResetHandlerProtocolGuid

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

diff --git a/MdeModulePkg/Include/Ppi/PlatformSpecificResetFilter.h b/MdeModulePkg/Include/Ppi/PlatformSpecificResetFilter.h
new file mode 100644 (file)
index 0000000..0f1432f
--- /dev/null
@@ -0,0 +1,31 @@
+/** @file\r
+  This PPI provides services to register a platform specific reset filter\r
+  for ResetSystem().  A reset filter evaluates the parameters passed to\r
+  ResetSystem() and converts a ResetType of EfiResetPlatformSpecific to a\r
+  non-platform specific reset type.  The registered filters are processed before\r
+  EDKII_PLATFORM_SPECIFIC_RESET_HANDLER_PPI handlers.\r
+\r
+  Copyright (c) 2017 Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  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 _PLATFORM_SPECIFIC_RESET_FILTER_PPI_H_\r
+#define _PLATFORM_SPECIFIC_RESET_FILTER_PPI_H_\r
+\r
+#include <Protocol/ResetNotification.h>\r
+\r
+#define EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI_GUID \\r
+  { 0x8c9f4de3, 0x7b90, 0x47ef, { 0x93, 0x8, 0x28, 0x7c, 0xec, 0xd6, 0x6d, 0xe8 } }\r
+\r
+typedef EFI_RESET_NOTIFICATION_PROTOCOL  EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI;\r
+\r
+extern EFI_GUID gEdkiiPlatformSpecificResetFilterPpiGuid;\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Include/Ppi/PlatformSpecificResetHandler.h b/MdeModulePkg/Include/Ppi/PlatformSpecificResetHandler.h
new file mode 100644 (file)
index 0000000..d5f1350
--- /dev/null
@@ -0,0 +1,29 @@
+/** @file\r
+  This PPI provides services to register a platform specific handler for\r
+  ResetSystem().  The registered handlers are processed after\r
+  EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PPI notifications.\r
+\r
+  Copyright (c) 2017 Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  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 _PLATFORM_SPECIFIC_RESET_HANDLER_PPI_H_\r
+#define _PLATFORM_SPECIFIC_RESET_HANDLER_PPI_H_\r
+\r
+#include <Protocol/ResetNotification.h>\r
+\r
+#define EDKII_PLATFORM_SPECIFIC_RESET_HANDLER_PPI_GUID \\r
+  { 0x75cf14ae, 0x3441, 0x49dc, { 0xaa, 0x10, 0xbb, 0x35, 0xa7, 0xba, 0x8b, 0xab } }\r
+\r
+typedef EFI_RESET_NOTIFICATION_PROTOCOL  EDKII_PLATFORM_SPECIFIC_RESET_HANDLER_PPI;\r
+\r
+extern EFI_GUID gEdkiiPlatformSpecificResetHandlerPpiGuid;\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Include/Protocol/PlatformSpecificResetFilter.h b/MdeModulePkg/Include/Protocol/PlatformSpecificResetFilter.h
new file mode 100644 (file)
index 0000000..ff5ca48
--- /dev/null
@@ -0,0 +1,31 @@
+/** @file\r
+  This Protocol provides services to register a platform specific reset filter\r
+  for ResetSystem().  A reset filter evaluates the parameters passed to\r
+  ResetSystem() and converts a ResetType of EfiResetPlatformSpecific to a\r
+  non-platform specific reset type.  The registered filters are processed before\r
+  the UEFI 2.7 Reset Notifications.\r
+\r
+  Copyright (c) 2017 Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  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 _PLATFORM_SPECIFIC_RESET_FILTER_PROTOCOL_H_\r
+#define _PLATFORM_SPECIFIC_RESET_FILTER_PROTOCOL_H_\r
+\r
+#include <Protocol/ResetNotification.h>\r
+\r
+#define EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PROTOCOL_GUID \\r
+  { 0x695d7835, 0x8d47, 0x4c11, { 0xab, 0x22, 0xfa, 0x8a, 0xcc, 0xe7, 0xae, 0x7a } }\r
+\r
+typedef EFI_RESET_NOTIFICATION_PROTOCOL  EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PROTOCOL;\r
+\r
+extern EFI_GUID gEdkiiPlatformSpecificResetFilterProtocolGuid;\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Include/Protocol/PlatformSpecificResetHandler.h b/MdeModulePkg/Include/Protocol/PlatformSpecificResetHandler.h
new file mode 100644 (file)
index 0000000..8a44e86
--- /dev/null
@@ -0,0 +1,29 @@
+/** @file\r
+  This protocol provides services to register a platform specific handler for\r
+  ResetSystem().  The registered handlers are called after the UEFI 2.7 Reset\r
+  Notifications are processed\r
+\r
+  Copyright (c) 2017 Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  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 _PLATFORM_SPECIFIC_RESET_HANDLER_PROTOCOL_H_\r
+#define _PLATFORM_SPECIFIC_RESET_HANDLER_PROTOCOL_H_\r
+\r
+#include <Protocol/ResetNotification.h>\r
+\r
+#define EDKII_PLATFORM_SPECIFIC_RESET_HANDLER_PROTOCOL_GUID \\r
+  { 0x2df6ba0b, 0x7092, 0x440d, { 0xbd, 0x4, 0xfb, 0x9, 0x1e, 0xc3, 0xf3, 0xc1 } }\r
+\r
+typedef EFI_RESET_NOTIFICATION_PROTOCOL  EDKII_PLATFORM_SPECIFIC_RESET_HANDLER_PROTOCOL;\r
+\r
+extern EFI_GUID gEdkiiPlatformSpecificResetHandlerProtocolGuid;\r
+\r
+#endif\r
index 5ea2e0b1dd4bdbeb04253cf3938ba0f2e539ff45..5dc0f570ecb3386f589897e0bd3e33739a4d9bce 100644 (file)
   ## Include/Ppi/IoMmu.h\r
   gEdkiiIoMmuPpiGuid = { 0x70b0af26, 0xf847, 0x4bb6, { 0xaa, 0xb9, 0xcd, 0xe8, 0x4f, 0xc6, 0x14, 0x31 } }\r
 \r
+  ## Include/Ppi/PlatformSpecificResetFilter.h\r
+  gEdkiiPlatformSpecificResetFilterPpiGuid = { 0x8c9f4de3, 0x7b90, 0x47ef, { 0x93, 0x8, 0x28, 0x7c, 0xec, 0xd6, 0x6d, 0xe8 } }\r
+\r
+  ## Include/Ppi/PlatformSpecificResetHandler.h\r
+  gEdkiiPlatformSpecificResetHandlerPpiGuid = { 0x75cf14ae, 0x3441, 0x49dc, { 0xaa, 0x10, 0xbb, 0x35, 0xa7, 0xba, 0x8b, 0xab } }\r
+\r
 [Protocols]\r
   ## Load File protocol provides capability to load and unload EFI image into memory and execute it.\r
   #  Include/Protocol/LoadPe32Image.h\r
   ## Include/Protocol/SdMmcOverride.h\r
   gEdkiiSdMmcOverrideProtocolGuid = { 0xeaf9e3c1, 0xc9cd, 0x46db, { 0xa5, 0xe5, 0x5a, 0x12, 0x4c, 0x83, 0x23, 0x23 } }\r
 \r
+  ## Include/Protocol/PlatformSpecificResetFilter.h\r
+  gEdkiiPlatformSpecificResetFilterProtocolGuid  = { 0x695d7835, 0x8d47, 0x4c11, { 0xab, 0x22, 0xfa, 0x8a, 0xcc, 0xe7, 0xae, 0x7a } }\r
+  ## Include/Protocol/PlatformSpecificResetHandler.h\r
+  gEdkiiPlatformSpecificResetHandlerProtocolGuid = { 0x2df6ba0b, 0x7092, 0x440d, { 0xbd, 0x4, 0xfb, 0x9, 0x1e, 0xc3, 0xf3, 0xc1 } }\r
 #\r
 # [Error.gEfiMdeModulePkgTokenSpaceGuid]\r
 #   0x80000001 | Invalid value provided.\r
index 75cff3777358e9ead41ce32438ea84e21feb90b9..fed527fac2dbca7f9dfd1e50fbe82b90c504cbcc 100644 (file)
 \r
 #include "ResetSystem.h"\r
 \r
+//\r
+// The current ResetSystem() notification recursion depth\r
+//\r
+UINTN  mResetNotifyDepth = 0;\r
+\r
 /**\r
   Register a notification function to be called when ResetSystem() is called.\r
 \r
@@ -130,6 +135,24 @@ RESET_NOTIFICATION_INSTANCE mResetNotification = {
   INITIALIZE_LIST_HEAD_VARIABLE (mResetNotification.ResetNotifies)\r
 };\r
 \r
+RESET_NOTIFICATION_INSTANCE mPlatformSpecificResetFilter = {\r
+  RESET_NOTIFICATION_INSTANCE_SIGNATURE,\r
+  {\r
+    RegisterResetNotify,\r
+    UnregisterResetNotify\r
+  },\r
+  INITIALIZE_LIST_HEAD_VARIABLE (mPlatformSpecificResetFilter.ResetNotifies)\r
+};\r
+\r
+RESET_NOTIFICATION_INSTANCE mPlatformSpecificResetHandler = {\r
+  RESET_NOTIFICATION_INSTANCE_SIGNATURE,\r
+  {\r
+    RegisterResetNotify,\r
+    UnregisterResetNotify\r
+  },\r
+  INITIALIZE_LIST_HEAD_VARIABLE (mPlatformSpecificResetHandler.ResetNotifies)\r
+};\r
+\r
 /**\r
   The driver's entry point.\r
 \r
@@ -170,6 +193,8 @@ InitializeResetSystem (
                   &Handle,\r
                   &gEfiResetArchProtocolGuid,         NULL,\r
                   &gEfiResetNotificationProtocolGuid, &mResetNotification.ResetNotification,\r
+                  &gEdkiiPlatformSpecificResetFilterProtocolGuid, &mPlatformSpecificResetFilter.ResetNotification,\r
+                  &gEdkiiPlatformSpecificResetHandlerProtocolGuid, &mPlatformSpecificResetHandler.ResetNotification,\r
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
@@ -225,13 +250,44 @@ ResetSystem (
   UINTN               CapsuleDataPtr;\r
   LIST_ENTRY          *Link;\r
   RESET_NOTIFY_ENTRY  *Entry;\r
-  \r
+\r
+  //\r
+  // Above the maximum recursion depth, so do the smallest amount of\r
+  // work to perform a cold reset.\r
+  //\r
+  if (mResetNotifyDepth >= MAX_RESET_NOTIFY_DEPTH) {\r
+    ResetCold ();\r
+    ASSERT (FALSE);\r
+    return;\r
+  }\r
+\r
   //\r
-  // Indicate reset system runtime service is called.\r
+  // Only do REPORT_STATUS_CODE() on first call to ResetSystem()\r
   //\r
-  REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_RESET_SYSTEM));\r
+  if (mResetNotifyDepth == 0) {\r
+    //\r
+    // Indicate reset system runtime service is called.\r
+    //\r
+    REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_RESET_SYSTEM));\r
+  }\r
 \r
-  if (!EfiAtRuntime ()) {\r
+  mResetNotifyDepth++;\r
+  if (!EfiAtRuntime () && mResetNotifyDepth < MAX_RESET_NOTIFY_DEPTH) {\r
+    //\r
+    // Call reset notification functions registered through the\r
+    // EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PROTOCOL.\r
+    //\r
+    for ( Link = GetFirstNode (&mPlatformSpecificResetFilter.ResetNotifies)\r
+        ; !IsNull (&mPlatformSpecificResetFilter.ResetNotifies, Link)\r
+        ; Link = GetNextNode (&mPlatformSpecificResetFilter.ResetNotifies, Link)\r
+        ) {\r
+      Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
+      Entry->ResetNotify (ResetType, ResetStatus, DataSize, ResetData);\r
+    }\r
+    //\r
+    // Call reset notification functions registered through the\r
+    // EFI_RESET_NOTIFICATION_PROTOCOL.\r
+    //\r
     for ( Link = GetFirstNode (&mResetNotification.ResetNotifies)\r
         ; !IsNull (&mResetNotification.ResetNotifies, Link)\r
         ; Link = GetNextNode (&mResetNotification.ResetNotifies, Link)\r
@@ -239,6 +295,17 @@ ResetSystem (
       Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
       Entry->ResetNotify (ResetType, ResetStatus, DataSize, ResetData);\r
     }\r
+    //\r
+    // call reset notification functions registered through the \r
+    // EDKII_PLATFORM_SPECIFIC_RESET_HANDLER_PROTOCOL.\r
+    //\r
+    for ( Link = GetFirstNode (&mPlatformSpecificResetHandler.ResetNotifies)\r
+        ; !IsNull (&mPlatformSpecificResetHandler.ResetNotifies, Link)\r
+        ; Link = GetNextNode (&mPlatformSpecificResetHandler.ResetNotifies, Link)\r
+        ) {\r
+      Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
+      Entry->ResetNotify (ResetType, ResetStatus, DataSize, ResetData);\r
+    }\r
   }\r
 \r
   switch (ResetType) {\r
index 75cdd8889692afa86fec271953e3ae1b82eeb145..ea5660274b643ab836afde3fbb6903a6b9b2395f 100644 (file)
@@ -20,6 +20,8 @@
 \r
 #include <Protocol/Reset.h>\r
 #include <Protocol/ResetNotification.h>\r
+#include <Protocol/PlatformSpecificResetFilter.h>\r
+#include <Protocol/PlatformSpecificResetHandler.h>\r
 #include <Guid/CapsuleVendor.h>\r
 \r
 #include <Library/BaseLib.h>\r
 #include <Library/ReportStatusCodeLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 \r
+//\r
+// The maximum recurstion depth to ResetSystem() by reset notification handlers\r
+//\r
+#define MAX_RESET_NOTIFY_DEPTH 10\r
+\r
 typedef struct {\r
   UINT32                   Signature;\r
   LIST_ENTRY               Link;\r
index 11233757c200a7a24c2ab4cf5a28c2dc91c85c13..da9e8e118b5d77b5a0c3822fc05e56671b48be72 100644 (file)
 \r
 \r
 [Protocols]\r
-  gEfiResetArchProtocolGuid                     ## PRODUCES\r
-  gEfiResetNotificationProtocolGuid             ## PRODUCES\r
-\r
+  gEfiResetArchProtocolGuid                       ## PRODUCES\r
+  gEfiResetNotificationProtocolGuid               ## PRODUCES\r
+  gEdkiiPlatformSpecificResetFilterProtocolGuid   ## PRODUCES\r
+  gEdkiiPlatformSpecificResetHandlerProtocolGuid  ## PRODUCES\r
 \r
 [Depex]\r
   TRUE\r