ResetSystemAcpiGed.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /** @file
  2. ResetSystem library implementation.
  3. Copyright (c) 2022 Loongson Technology Corporation Limited. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Base.h>
  7. #include <Uefi.h>
  8. #include <PiPei.h>
  9. #include <Library/BaseLib.h> // CpuDeadLoop()
  10. #include <Library/DebugLib.h>
  11. #include <Library/ResetSystemLib.h> // ResetCold()
  12. #include <Library/IoLib.h>
  13. #include "ResetSystemAcpiGed.h"
  14. POWER_MANAGER mPowerManager;
  15. /**
  16. Calling this function causes a system-wide reset. This sets
  17. all circuitry within the system to its initial state. This type of reset
  18. is asynchronous to system operation and operates without regard to
  19. cycle boundaries.
  20. System reset should not return, if it returns, it means the system does
  21. not support cold reset.
  22. **/
  23. STATIC VOID
  24. AcpiGedReset (
  25. VOID
  26. )
  27. {
  28. MmioWrite8 (
  29. (UINTN)mPowerManager.ResetRegAddr,
  30. mPowerManager.ResetValue
  31. );
  32. CpuDeadLoop ();
  33. }
  34. /**
  35. This function causes the system to enter a power state equivalent
  36. to the ACPI S5 states.
  37. * */
  38. STATIC VOID
  39. AcpiGedShutdown (
  40. VOID
  41. )
  42. {
  43. MmioWrite8 (
  44. (UINTN)mPowerManager.SleepControlRegAddr,
  45. (1 << 5) /* enable bit */ |
  46. (5 << 2) /* typ == S5 */
  47. );
  48. CpuDeadLoop ();
  49. }
  50. /**
  51. This function causes a system-wide reset (cold reset), in which
  52. all circuitry within the system returns to its initial state. This type of
  53. reset is asynchronous to system operation and operates without regard to
  54. cycle boundaries.
  55. If this function returns, it means that the system does not support cold
  56. reset.
  57. **/
  58. VOID EFIAPI
  59. ResetCold (
  60. VOID
  61. )
  62. {
  63. AcpiGedReset ();
  64. }
  65. /**
  66. This function causes a system-wide initialization (warm reset), in which all
  67. processors are set to their initial state. Pending cycles are not corrupted.
  68. If this function returns, it means that the system does not support warm
  69. reset.
  70. **/
  71. VOID EFIAPI
  72. ResetWarm (
  73. VOID
  74. )
  75. {
  76. AcpiGedReset ();
  77. }
  78. /**
  79. This function causes a systemwide reset. The exact type of the reset is
  80. defined by the EFI_GUID that follows the Null-terminated Unicode string passed
  81. into ResetData. If the platform does not recognize the EFI_GUID in ResetData
  82. the platform must pick a supported reset type to perform.The platform may
  83. optionally log the parameters from any non-normal reset that occurs.
  84. @param[in] DataSize The size, in bytes, of ResetData.
  85. @param[in] ResetData The data buffer starts with a Null-terminated string,
  86. followed by the EFI_GUID.
  87. **/
  88. VOID
  89. EFIAPI
  90. ResetPlatformSpecific (
  91. IN UINTN DataSize,
  92. IN VOID *ResetData
  93. )
  94. {
  95. AcpiGedReset ();
  96. }
  97. /**
  98. This function causes the system to enter a power state equivalent
  99. to the ACPI G2/S5 or G3 states.
  100. If this function returns, it means that the system does not support shut down
  101. reset.
  102. **/
  103. VOID EFIAPI
  104. ResetShutdown (
  105. VOID
  106. )
  107. {
  108. AcpiGedShutdown ();
  109. }