/** @file\r
- Reset Architectural Protocol implementation\r
+ Reset Architectural and Reset Notification protocols implementation.\r
\r
- Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2006 - 2019, 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
+ SPDX-License-Identifier: BSD-2-Clause-Patent\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
//\r
-// The handle onto which the Reset Architectural Protocol is installed\r
+// The current ResetSystem() notification recursion depth\r
//\r
-EFI_HANDLE mResetHandle = NULL;\r
+UINTN mResetNotifyDepth = 0;\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
+ {\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
+\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
+ {\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
+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
It initializes the Reset Architectural Protocol.\r
\r
- @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
@param[in] SystemTable A pointer to the EFI System Table.\r
- \r
+\r
@retval EFI_SUCCESS The entry point is executed successfully.\r
@retval other Cannot install ResetArch protocol.\r
\r
)\r
{\r
EFI_STATUS Status;\r
+ EFI_HANDLE Handle;\r
\r
//\r
// Make sure the Reset Architectural Protocol is not already installed in the system\r
//\r
// Hook the runtime service table\r
//\r
- gRT->ResetSystem = ResetSystem;\r
+ gRT->ResetSystem = RuntimeServiceResetSystem;\r
\r
//\r
// Now install the Reset RT AP on a new handle\r
//\r
+ Handle = NULL;\r
Status = gBS->InstallMultipleProtocolInterfaces (\r
- &mResetHandle,\r
+ &Handle,\r
&gEfiResetArchProtocolGuid,\r
NULL,\r
+ &gEfiResetNotificationProtocolGuid,\r
+ &mResetNotification.ResetNotification,\r
+ &gEdkiiPlatformSpecificResetFilterProtocolGuid,\r
+ &mPlatformSpecificResetFilter.ResetNotification,\r
+ &gEdkiiPlatformSpecificResetHandlerProtocolGuid,\r
+ &mPlatformSpecificResetHandler.ResetNotification,\r
NULL\r
);\r
ASSERT_EFI_ERROR (Status);\r
return Status;\r
}\r
\r
-/**\r
- Reset system for capsule update.\r
-\r
- @param[in] CapsuleDataPtr Pointer to the capsule block descriptors.\r
- \r
-**/\r
-VOID\r
-CapsuleReset (\r
- IN UINTN CapsuleDataPtr\r
- )\r
-{\r
- //\r
- // This implementation assumes that we're using a variable\r
- // to indicate capsule updates.\r
- //\r
- gRT->SetVariable (\r
- EFI_CAPSULE_VARIABLE_NAME,\r
- &gEfiCapsuleVendorGuid,\r
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
- sizeof (UINTN),\r
- (VOID *) &CapsuleDataPtr\r
- );\r
-\r
- EnterS3WithImmediateWake ();\r
-\r
- //\r
- // Should not return\r
- //\r
- CpuDeadLoop ();\r
-}\r
-\r
-/**\r
- Put the system into S3 power state. \r
-**/\r
-VOID\r
-DoS3 (\r
- VOID\r
- )\r
-{\r
- EnterS3WithImmediateWake ();\r
-\r
- //\r
- // Should not return\r
- //\r
- CpuDeadLoop ();\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 WatchdogData.\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
-\r
+ The string is a description that the caller may use to further\r
+ indicate the reason for the system reset.\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
-ResetSystem (\r
- IN EFI_RESET_TYPE ResetType,\r
- IN EFI_STATUS ResetStatus,\r
- IN UINTN DataSize,\r
- IN VOID *ResetData OPTIONAL\r
+RuntimeServiceResetSystem (\r
+ IN EFI_RESET_TYPE ResetType,\r
+ IN EFI_STATUS ResetStatus,\r
+ IN UINTN DataSize,\r
+ IN VOID *ResetData OPTIONAL\r
)\r
{\r
- EFI_STATUS Status;\r
- UINTN Size;\r
- UINTN CapsuleDataPtr;\r
-\r
- switch (ResetType) {\r
- case EfiResetWarm:\r
+ LIST_ENTRY *Link;\r
+ RESET_NOTIFY_ENTRY *Entry;\r
\r
+ //\r
+ // Only do REPORT_STATUS_CODE() on first call to RuntimeServiceResetSystem()\r
+ //\r
+ if (mResetNotifyDepth == 0) {\r
//\r
- //Check if there are pending capsules to process\r
+ // Indicate reset system runtime service is called.\r
//\r
- Size = sizeof (CapsuleDataPtr);\r
- Status = EfiGetVariable (\r
- EFI_CAPSULE_VARIABLE_NAME,\r
- &gEfiCapsuleVendorGuid,\r
- NULL,\r
- &Size,\r
- (VOID *) &CapsuleDataPtr\r
- );\r
-\r
- if (Status == EFI_SUCCESS) {\r
+ REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_RESET_SYSTEM));\r
+ }\r
+\r
+ mResetNotifyDepth++;\r
+ DEBUG ((\r
+ DEBUG_INFO,\r
+ "DXE ResetSystem2: ResetType %s, Call Depth = %d.\n",\r
+ mResetTypeStr[ResetType],\r
+ mResetNotifyDepth\r
+ ));\r
+\r
+ if (mResetNotifyDepth <= MAX_RESET_NOTIFY_DEPTH) {\r
+ if (!EfiAtRuntime ()) {\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
+ {\r
+ Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
+ Entry->ResetNotify (ResetType, ResetStatus, DataSize, ResetData);\r
+ }\r
+\r
+ //\r
+ // Call reset notification functions registered through the\r
+ // EFI_RESET_NOTIFICATION_PROTOCOL.\r
//\r
- //Process capsules across a system reset.\r
+ for ( Link = GetFirstNode (&mResetNotification.ResetNotifies)\r
+ ; !IsNull (&mResetNotification.ResetNotifies, Link)\r
+ ; Link = GetNextNode (&mResetNotification.ResetNotifies, Link)\r
+ )\r
+ {\r
+ Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
+ Entry->ResetNotify (ResetType, ResetStatus, DataSize, ResetData);\r
+ }\r
+\r
+ //\r
+ // call reset notification functions registered through the\r
+ // EDKII_PLATFORM_SPECIFIC_RESET_HANDLER_PROTOCOL.\r
//\r
- DoS3();\r
+ for ( Link = GetFirstNode (&mPlatformSpecificResetHandler.ResetNotifies)\r
+ ; !IsNull (&mPlatformSpecificResetHandler.ResetNotifies, Link)\r
+ ; Link = GetNextNode (&mPlatformSpecificResetHandler.ResetNotifies, Link)\r
+ )\r
+ {\r
+ Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
+ Entry->ResetNotify (ResetType, ResetStatus, DataSize, ResetData);\r
+ }\r
}\r
+ } else {\r
+ ASSERT (ResetType < ARRAY_SIZE (mResetTypeStr));\r
+ DEBUG ((DEBUG_ERROR, "DXE 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
\r
- ResetWarm ();\r
+ ResetWarm ();\r
+ break;\r
\r
- break;\r
+ case EfiResetCold:\r
+ ResetCold ();\r
+ break;\r
\r
- case EfiResetCold:\r
- ResetCold ();\r
- break;\r
+ case EfiResetShutdown:\r
+ ResetShutdown ();\r
+ return;\r
\r
- case EfiResetShutdown:\r
- ResetShutdown ();\r
- return ;\r
+ case EfiResetPlatformSpecific:\r
+ ResetPlatformSpecific (DataSize, ResetData);\r
+ return;\r
\r
- default:\r
- return ;\r
+ default:\r
+ return;\r
}\r
\r
//\r