]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/ResetSystem: Implement ResetNotification protocol
authorRuiyu Ni <ruiyu.ni@intel.com>
Thu, 15 Jun 2017 08:31:56 +0000 (16:31 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Mon, 3 Jul 2017 07:40:57 +0000 (15:40 +0800)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystem.c
MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystem.h
MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf
MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.uni

index 64f2da5ce9def5ef4bc59141998490e03e2d54f2..b8e3ea460de220f15b0e58f2eb3a35f8392998ad 100644 (file)
@@ -1,5 +1,5 @@
 /** @file\r
 /** @file\r
-  Reset Architectural Protocol implementation\r
+  Reset Architectural and Reset Notification protocols implementation.\r
 \r
   Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
 \r
 \r
   Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
 \r
 \r
 #include "ResetSystem.h"\r
 \r
 \r
 #include "ResetSystem.h"\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 EFI_RESET_NOTIFICATION_PROTOCOL *This,\r
+  IN EFI_RESET_SYSTEM                ResetFunction\r
+  )\r
+{\r
+  RESET_NOTIFICATION_INSTANCE        *Instance;\r
+  LIST_ENTRY                         *Link;\r
+  RESET_NOTIFY_ENTRY                 *Entry;\r
+\r
+  if (ResetFunction == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Instance = RESET_NOTIFICATION_INSTANCE_FROM_THIS (This);\r
+\r
+  for ( Link = GetFirstNode (&Instance->ResetNotifies)\r
+      ; !IsNull (&Instance->ResetNotifies, Link)\r
+      ; Link = GetNextNode (&Instance->ResetNotifies, Link)\r
+      ) {\r
+    Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
+    if (Entry->ResetNotify == ResetFunction) {\r
+      return EFI_ALREADY_STARTED;\r
+    }\r
+  }\r
+\r
+  ASSERT (IsNull (&Instance->ResetNotifies, Link));\r
+  Entry = AllocatePool (sizeof (*Entry));\r
+  if (Entry == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  Entry->Signature   = RESET_NOTIFY_ENTRY_SIGNATURE;\r
+  Entry->ResetNotify = ResetFunction;\r
+  InsertTailList (&Instance->ResetNotifies, &Entry->Link);\r
+  return EFI_SUCCESS;\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
+{\r
+  RESET_NOTIFICATION_INSTANCE        *Instance;\r
+  LIST_ENTRY                         *Link;\r
+  RESET_NOTIFY_ENTRY                 *Entry;\r
+\r
+  if (ResetFunction == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Instance = RESET_NOTIFICATION_INSTANCE_FROM_THIS (This);\r
+\r
+  for ( Link = GetFirstNode (&Instance->ResetNotifies)\r
+      ; !IsNull (&Instance->ResetNotifies, Link)\r
+      ; Link = GetNextNode (&Instance->ResetNotifies, Link)\r
+      ) {\r
+    Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
+    if (Entry->ResetNotify == ResetFunction) {\r
+      RemoveEntryList (&Entry->Link);\r
+      FreePool (Entry);\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return EFI_INVALID_PARAMETER;\r
+}\r
+\r
+RESET_NOTIFICATION_INSTANCE mResetNotification = {\r
+  RESET_NOTIFICATION_INSTANCE_SIGNATURE,\r
+  {\r
+    RegisterResetNotify,\r
+    UnregisterResetNotify\r
+  },\r
+  INITIALIZE_LIST_HEAD_VARIABLE (mResetNotification.ResetNotifies)\r
+};\r
+\r
 /**\r
   The driver's entry point.\r
 \r
 /**\r
   The driver's entry point.\r
 \r
@@ -53,8 +168,8 @@ InitializeResetSystem (
   Handle = NULL;\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &Handle,\r
   Handle = NULL;\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &Handle,\r
-                  &gEfiResetArchProtocolGuid,\r
-                  NULL,\r
+                  &gEfiResetArchProtocolGuid,         NULL,\r
+                  &gEfiResetNotificationProtocolGuid, &mResetNotification.ResetNotification,\r
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
@@ -102,15 +217,27 @@ ResetSystem (
   IN VOID             *ResetData OPTIONAL\r
   )\r
 {\r
   IN VOID             *ResetData OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS    Status;\r
-  UINTN         Size;\r
-  UINTN         CapsuleDataPtr;\r
+  EFI_STATUS          Status;\r
+  UINTN               Size;\r
+  UINTN               CapsuleDataPtr;\r
+  LIST_ENTRY          *Link;\r
+  RESET_NOTIFY_ENTRY  *Entry;\r
   \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
   //\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
+  if (!EfiAtRuntime ()) {\r
+    for ( Link = GetFirstNode (&mResetNotification.ResetNotifies)\r
+        ; !IsNull (&mResetNotification.ResetNotifies, Link)\r
+        ; Link = GetNextNode (&mResetNotification.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
   case EfiResetWarm:\r
 \r
   switch (ResetType) {\r
   case EfiResetWarm:\r
 \r
index c3a2a7f1279a1df483c0b9958898aba7afa33735..73e657d4e0ce1352f32cde68fd992844534fb5eb 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
 /** @file\r
 \r
-  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2017, 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
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -19,6 +19,7 @@
 #include <PiDxe.h>\r
 \r
 #include <Protocol/Reset.h>\r
 #include <PiDxe.h>\r
 \r
 #include <Protocol/Reset.h>\r
+#include <Protocol/ResetNotification.h>\r
 #include <Guid/CapsuleVendor.h>\r
 \r
 #include <Library/BaseLib.h>\r
 #include <Guid/CapsuleVendor.h>\r
 \r
 #include <Library/BaseLib.h>\r
 #include <Library/UefiRuntimeServicesTableLib.h>\r
 #include <Library/ResetSystemLib.h>\r
 #include <Library/ReportStatusCodeLib.h>\r
 #include <Library/UefiRuntimeServicesTableLib.h>\r
 #include <Library/ResetSystemLib.h>\r
 #include <Library/ReportStatusCodeLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+typedef struct {\r
+  UINT32                   Signature;\r
+  LIST_ENTRY               Link;\r
+  EFI_RESET_SYSTEM         ResetNotify;\r
+} RESET_NOTIFY_ENTRY;\r
+#define RESET_NOTIFY_ENTRY_SIGNATURE    SIGNATURE_32('r', 's', 't', 'n')\r
+#define RESET_NOTIFY_ENTRY_FROM_LINK(a) CR (a, RESET_NOTIFY_ENTRY, Link, RESET_NOTIFY_ENTRY_SIGNATURE)\r
+\r
+typedef struct {\r
+  UINT32                          Signature;\r
+  EFI_RESET_NOTIFICATION_PROTOCOL ResetNotification;\r
+  LIST_ENTRY                      ResetNotifies;\r
+} RESET_NOTIFICATION_INSTANCE;\r
+#define RESET_NOTIFICATION_INSTANCE_SIGNATURE    SIGNATURE_32('r', 's', 't', 'i')\r
+#define RESET_NOTIFICATION_INSTANCE_FROM_THIS(a) \\r
+  CR (a, RESET_NOTIFICATION_INSTANCE, ResetNotification, RESET_NOTIFICATION_INSTANCE_SIGNATURE)\r
 \r
 /**\r
   The driver's entry point.\r
 \r
 /**\r
   The driver's entry point.\r
index 7ef52b328395cf70b8765d365ed2c16e69592f76..11233757c200a7a24c2ab4cf5a28c2dc91c85c13 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 ## @file\r
-# This driver implements Reset Architectural Protocol.\r
+# This driver implements Reset Architectural and Reset Notification protocols.\r
 #\r
 #\r
-# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2006 - 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
 #\r
 # This program and the accompanying materials are\r
 # licensed and made available under the terms and conditions of the BSD License\r
@@ -48,7 +48,7 @@
   DebugLib\r
   BaseLib\r
   ReportStatusCodeLib\r
   DebugLib\r
   BaseLib\r
   ReportStatusCodeLib\r
-\r
+  MemoryAllocationLib\r
 \r
 [Guids]\r
   gEfiCapsuleVendorGuid                         ## SOMETIMES_CONSUMES   ## Variable:L"CapsuleUpdateData"\r
 \r
 [Guids]\r
   gEfiCapsuleVendorGuid                         ## SOMETIMES_CONSUMES   ## Variable:L"CapsuleUpdateData"\r
@@ -56,6 +56,7 @@
 \r
 [Protocols]\r
   gEfiResetArchProtocolGuid                     ## PRODUCES\r
 \r
 [Protocols]\r
   gEfiResetArchProtocolGuid                     ## PRODUCES\r
+  gEfiResetNotificationProtocolGuid             ## PRODUCES\r
 \r
 \r
 [Depex]\r
 \r
 \r
 [Depex]\r
index e55ffd97ef57d3db34b0882044c0103cb1b209ee..3e1e12da33b3c6e995ee9a683803e793ed93c999 100644 (file)
@@ -1,9 +1,7 @@
 // /** @file\r
 // /** @file\r
-// This driver implements Reset Architectural Protocol.\r
+// This driver implements Reset Architectural and Reset Notification protocols.\r
 //\r
 //\r
-// This driver implements Reset Architectural Protocol.\r
-//\r
-// Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+// Copyright (c) 2006 - 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
 //\r
 // This program and the accompanying materials are\r
 // licensed and made available under the terms and conditions of the BSD License\r
@@ -16,7 +14,7 @@
 // **/\r
 \r
 \r
 // **/\r
 \r
 \r
-#string STR_MODULE_ABSTRACT             #language en-US "Implements Reset Architectural Protocol"\r
+#string STR_MODULE_ABSTRACT             #language en-US "Implements Reset Architectural and Reset Notification protocols"\r
 \r
 \r
-#string STR_MODULE_DESCRIPTION          #language en-US "This driver implements Reset Architectural Protocol."\r
+#string STR_MODULE_DESCRIPTION          #language en-US "This driver implements Reset Architectural and Reset Notification protocols."\r
 \r
 \r