]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Add a runtime library instance of ResetSystemLib
authorZhichao Gao <zhichao.gao@intel.com>
Thu, 21 Feb 2019 00:59:43 +0000 (08:59 +0800)
committerLiming Gao <liming.gao@intel.com>
Fri, 22 Feb 2019 01:45:44 +0000 (09:45 +0800)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1461

Implement a runtime library instance of ResetSystemLib. It would
use a internal point instead of gRT and convert it depend on
gEfiEventVirtualAddressChangeGuid.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdeModulePkg/Library/RuntimeResetSystemLib/RuntimeResetSystemLib.c [new file with mode: 0644]
MdeModulePkg/Library/RuntimeResetSystemLib/RuntimeResetSystemLib.inf [new file with mode: 0644]
MdeModulePkg/Library/RuntimeResetSystemLib/RuntimeResetSystemLib.uni [new file with mode: 0644]

diff --git a/MdeModulePkg/Library/RuntimeResetSystemLib/RuntimeResetSystemLib.c b/MdeModulePkg/Library/RuntimeResetSystemLib/RuntimeResetSystemLib.c
new file mode 100644 (file)
index 0000000..17826cd
--- /dev/null
@@ -0,0 +1,216 @@
+/** @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
diff --git a/MdeModulePkg/Library/RuntimeResetSystemLib/RuntimeResetSystemLib.inf b/MdeModulePkg/Library/RuntimeResetSystemLib/RuntimeResetSystemLib.inf
new file mode 100644 (file)
index 0000000..0a43b28
--- /dev/null
@@ -0,0 +1,50 @@
+## @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
diff --git a/MdeModulePkg/Library/RuntimeResetSystemLib/RuntimeResetSystemLib.uni b/MdeModulePkg/Library/RuntimeResetSystemLib/RuntimeResetSystemLib.uni
new file mode 100644 (file)
index 0000000..e560643
--- /dev/null
@@ -0,0 +1,21 @@
+// /** @file\r
+// Runtime Reset System Library instance that calls gRT->ResetSystem().\r
+//\r
+// Runtime Reset System Library instance that calls gRT->ResetSystem().\r
+//\r
+// Copyright (c) 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
+\r
+#string STR_MODULE_ABSTRACT             #language en-US "Runtime Reset System Library instance that calls gRT->ResetSystem()"\r
+\r
+#string STR_MODULE_DESCRIPTION          #language en-US "Runtime Reset System Library instance that calls gRT->ResetSystem()."\r
+\r