+/**\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