--- /dev/null
+/** @file\r
+ DXE Reset System Library instance that calls gRT->ResetSystem().\r
+\r
+ Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>\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 <PiDxe.h>\r
+#include <Library/ResetSystemLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+EFI_EVENT mRuntimeResetSystemLibVirtualAddressChangeEvent;\r
+EFI_RUNTIME_SERVICES *mInternalRT;\r
+\r
+/**\r
+ This function causes a system-wide reset (cold reset), in which\r
+ all circuitry within the system returns to its initial state. This type of reset\r
+ is asynchronous to system operation and operates without regard to\r
+ cycle boundaries.\r
+\r
+ If this function returns, it means that the system does not support cold reset.\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetCold (\r
+ VOID\r
+ )\r
+{\r
+ mInternalRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
+}\r
+\r
+/**\r
+ This function causes a system-wide initialization (warm reset), in which all processors\r
+ are set to their initial state. Pending cycles are not corrupted.\r
+\r
+ If this function returns, it means that the system does not support warm reset.\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetWarm (\r
+ VOID\r
+ )\r
+{\r
+ mInternalRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
+}\r
+\r
+/**\r
+ This function causes the system to enter a power state equivalent\r
+ to the ACPI G2/S5 or G3 states.\r
+\r
+ If this function returns, it means that the system does not support shut down reset.\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetShutdown (\r
+ VOID\r
+ )\r
+{\r
+ mInternalRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, 0, NULL);\r
+}\r
+\r
+/**\r
+ This function causes the system to enter S3 and then wake up immediately.\r
+\r
+ If this function returns, it means that the system does not support S3 feature.\r
+**/\r
+VOID\r
+EFIAPI\r
+EnterS3WithImmediateWake (\r
+ VOID\r
+ )\r
+{\r
+}\r
+\r
+/**\r
+ This function causes a systemwide reset. The exact type of the reset is\r
+ defined by the EFI_GUID that follows the Null-terminated Unicode string passed\r
+ into ResetData. If the platform does not recognize the EFI_GUID in ResetData\r
+ the platform must pick a supported reset type to perform.The platform may\r
+ optionally log the parameters from any non-normal reset that occurs.\r
+\r
+ @param[in] DataSize The size, in bytes, of ResetData.\r
+ @param[in] ResetData The data buffer starts with a Null-terminated string,\r
+ followed by the EFI_GUID.\r
+**/\r
+VOID\r
+EFIAPI\r
+ResetPlatformSpecific (\r
+ IN UINTN DataSize,\r
+ IN VOID *ResetData\r
+ )\r
+{\r
+ mInternalRT->ResetSystem (EfiResetPlatformSpecific, EFI_SUCCESS, DataSize, ResetData);\r
+}\r
+\r
+/**\r
+ The ResetSystem function 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 EfiResetShutdown\r
+ the data buffer starts with a Null-terminated string, optionally\r
+ followed by additional binary data. The string is a description\r
+ that the caller may use to further indicate the reason for the\r
+ system reset. ResetData is only valid if ResetStatus is something\r
+ other than EFI_SUCCESS unless the ResetType is EfiResetPlatformSpecific\r
+ where a minimum amount of ResetData is always required.\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
+ )\r
+{\r
+ mInternalRT->ResetSystem (ResetType, ResetStatus, DataSize, ResetData);\r
+}\r
+\r
+/**\r
+ Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
+\r
+ @param Event Event whose notification function is being invoked.\r
+ @param Context Pointer to the notification function's context\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+RuntimeResetSystemLibVirtualAddressChange (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+{\r
+ mInternalRT->ConvertPointer (0, (VOID **) &mInternalRT);\r
+}\r
+\r
+/**\r
+ The constructor function of Runtime Reset System Lib.\r
+\r
+ This function allocates memory for extended status code data, caches\r
+ the report status code service, and registers events.\r
+\r
+ @param ImageHandle The firmware allocated handle for the EFI image.\r
+ @param SystemTable A pointer to the EFI System Table.\r
+\r
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RuntimeResetSystemLibConstruct (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ //\r
+ // Library should not use the gRT directly, for it may be converted by other library instance.\r
+ //\r
+ mInternalRT = gRT;\r
+\r
+ //\r
+ // Register notify function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE\r
+ //\r
+ Status = gBS->CreateEventEx (\r
+ EVT_NOTIFY_SIGNAL,\r
+ TPL_NOTIFY,\r
+ RuntimeResetSystemLibVirtualAddressChange,\r
+ NULL,\r
+ &gEfiEventVirtualAddressChangeGuid,\r
+ &mRuntimeResetSystemLibVirtualAddressChangeEvent\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ The Deconstructor function of Runtime Reset System Lib.\r
+\r
+ The destructor function frees memory allocated by constructor, and closes related events.\r
+ It will ASSERT() if that related operation fails and it will always return EFI_SUCCESS.\r
+\r
+ @param ImageHandle The firmware allocated handle for the EFI image.\r
+ @param SystemTable A pointer to the EFI System Table.\r
+\r
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RuntimeResetSystemLibDeconstruct (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ ASSERT (gBS != NULL);\r
+ Status = gBS->CloseEvent (mRuntimeResetSystemLibVirtualAddressChangeEvent);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
--- /dev/null
+## @file\r
+# Runtime Reset System Library instance that calls gRT->ResetSystem().\r
+#\r
+# Copyright (c) 2017 - 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
+# 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 = RuntimeResetSystemLib\r
+ MODULE_UNI_FILE = RuntimeResetSystemLib.uni\r
+ FILE_GUID = DD5D0821-F343-4C85-9CD9-54B3C1A19CEA\r
+ MODULE_TYPE = DXE_RUNTIME_DRIVER\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = ResetSystemLib|DXE_RUNTIME_DRIVER\r
+\r
+ CONSTRUCTOR = RuntimeResetSystemLibConstruct\r
+ DESTRUCTOR = RuntimeResetSystemLibDeconstruct\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64 EBC\r
+#\r
+\r
+[Sources]\r
+ RuntimeResetSystemLib.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+ UefiRuntimeServicesTableLib\r
+ UefiBootServicesTableLib\r
+ DebugLib\r
+\r
+[Guids]\r
+ gEfiEventVirtualAddressChangeGuid ## CONSUMES ## Event\r
+\r
+[Depex]\r
+ gEfiResetArchProtocolGuid\r