]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c
OvmfPkg/ResetSystemLib: improve coding style in ResetSystem()
[mirror_edk2.git] / OvmfPkg / Library / ResetSystemLib / ResetSystemLib.c
index d075fbef0a542ef1310518e6bc0c75c1ab481c7e..0fc142325ecead8aa6998a2295e808102a712c26 100644 (file)
@@ -1,33 +1,47 @@
 /** @file\r
   Reset System Library functions for OVMF\r
 \r
-  Copyright (c) 2006 - 2011, 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
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
-#include <Base.h>\r
+#include <Base.h>                   // BIT1\r
 \r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/IoLib.h>\r
-#include <Library/TimerLib.h>\r
+#include <Library/BaseLib.h>        // CpuDeadLoop()\r
+#include <Library/DebugLib.h>       // ASSERT()\r
+#include <Library/IoLib.h>          // IoWrite8()\r
+#include <Library/PciLib.h>         // PciRead16()\r
+#include <Library/ResetSystemLib.h> // ResetCold()\r
+#include <Library/TimerLib.h>       // MicroSecondDelay()\r
+#include <OvmfPlatforms.h>          // OVMF_HOSTBRIDGE_DID\r
 \r
 VOID\r
 AcpiPmControl (\r
   UINTN SuspendType\r
   )\r
 {\r
+  UINT16 AcpiPmBaseAddress;\r
+  UINT16 HostBridgeDevId;\r
+\r
   ASSERT (SuspendType < 6);\r
 \r
-  IoAndThenOr16 (0x404, (UINT16) ~0x3c00, (UINT16) (SuspendType << 10));\r
-  IoOr16 (0x404, BIT13);\r
+  AcpiPmBaseAddress = 0;\r
+  HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);\r
+  switch (HostBridgeDevId) {\r
+  case INTEL_82441_DEVICE_ID:\r
+    AcpiPmBaseAddress = PIIX4_PMBA_VALUE;\r
+    break;\r
+  case INTEL_Q35_MCH_DEVICE_ID:\r
+    AcpiPmBaseAddress = ICH9_PMBASE_VALUE;\r
+    break;\r
+  default:\r
+    ASSERT (FALSE);\r
+    CpuDeadLoop ();\r
+  }\r
+\r
+  IoBitFieldWrite16 (AcpiPmBaseAddress + 4, 10, 13, (UINT16) SuspendType);\r
+  IoOr16 (AcpiPmBaseAddress + 4, BIT13);\r
   CpuDeadLoop ();\r
 }\r
 \r
@@ -89,19 +103,67 @@ ResetShutdown (
 \r
 \r
 /**\r
-  Calling this function causes the system to enter a power state for capsule\r
-  update.\r
-\r
-  Reset update should not return, if it returns, it means the system does\r
-  not support capsule update.\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\r
+  passed into ResetData. If the platform does not recognize the EFI_GUID in\r
+  ResetData the platform must pick a supported reset type to perform.The\r
+  platform may optionally log the parameters from any non-normal reset that\r
+  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
+  ResetCold ();\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\r
+                            EfiResetShutdown the data buffer starts with a\r
+                            Null-terminated string, optionally followed by\r
+                            additional binary data. The string is a description\r
+                            that the caller may use to further indicate the\r
+                            reason for the system reset.\r
 **/\r
 VOID\r
 EFIAPI\r
-EnterS3WithImmediateWake (\r
-  VOID\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
-  AcpiPmControl (1);\r
-  ASSERT (FALSE);\r
+  switch (ResetType) {\r
+  case EfiResetWarm:\r
+    ResetWarm ();\r
+    break;\r
+\r
+  case EfiResetCold:\r
+    ResetCold ();\r
+    break;\r
+\r
+  case EfiResetShutdown:\r
+    ResetShutdown ();\r
+    break;\r
+\r
+  case EfiResetPlatformSpecific:\r
+    ResetPlatformSpecific (DataSize, ResetData);\r
+    break;\r
+\r
+  default:\r
+    break;\r
+  }\r
 }\r