ResetSystemLib.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /** @file
  2. Reset System Library functions for coreboot
  3. Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiDxe.h>
  7. #include <Library/BaseLib.h>
  8. #include <Library/DebugLib.h>
  9. #include <Library/IoLib.h>
  10. #include <Library/HobLib.h>
  11. #include <Guid/AcpiBoardInfoGuid.h>
  12. VOID
  13. AcpiPmControl (
  14. UINTN SuspendType
  15. )
  16. {
  17. EFI_HOB_GUID_TYPE *GuidHob;
  18. ACPI_BOARD_INFO *pAcpiBoardInfo;
  19. UINTN PmCtrlReg = 0;
  20. ASSERT (SuspendType <= 7);
  21. //
  22. // Find the acpi board information guid hob
  23. //
  24. GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);
  25. ASSERT (GuidHob != NULL);
  26. pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);
  27. PmCtrlReg = (UINTN)pAcpiBoardInfo->PmCtrlRegBase;
  28. IoAndThenOr16 (PmCtrlReg, (UINT16) ~0x3c00, (UINT16) (SuspendType << 10));
  29. IoOr16 (PmCtrlReg, BIT13);
  30. CpuDeadLoop ();
  31. }
  32. /**
  33. Calling this function causes a system-wide reset. This sets
  34. all circuitry within the system to its initial state. This type of reset
  35. is asynchronous to system operation and operates without regard to
  36. cycle boundaries.
  37. System reset should not return, if it returns, it means the system does
  38. not support cold reset.
  39. **/
  40. VOID
  41. EFIAPI
  42. ResetCold (
  43. VOID
  44. )
  45. {
  46. EFI_HOB_GUID_TYPE *GuidHob;
  47. ACPI_BOARD_INFO *pAcpiBoardInfo;
  48. //
  49. // Find the acpi board information guid hob
  50. //
  51. GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);
  52. ASSERT (GuidHob != NULL);
  53. pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);
  54. IoWrite8 ((UINTN)pAcpiBoardInfo->ResetRegAddress, pAcpiBoardInfo->ResetValue);
  55. CpuDeadLoop ();
  56. }
  57. /**
  58. Calling this function causes a system-wide initialization. The processors
  59. are set to their initial state, and pending cycles are not corrupted.
  60. System reset should not return, if it returns, it means the system does
  61. not support warm reset.
  62. **/
  63. VOID
  64. EFIAPI
  65. ResetWarm (
  66. VOID
  67. )
  68. {
  69. EFI_HOB_GUID_TYPE *GuidHob;
  70. ACPI_BOARD_INFO *pAcpiBoardInfo;
  71. //
  72. // Find the acpi board information guid hob
  73. //
  74. GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);
  75. ASSERT (GuidHob != NULL);
  76. pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);
  77. IoWrite8 ((UINTN)pAcpiBoardInfo->ResetRegAddress, pAcpiBoardInfo->ResetValue);
  78. CpuDeadLoop ();
  79. }
  80. /**
  81. Calling this function causes the system to enter a power state equivalent
  82. to the ACPI G2/S5 or G3 states.
  83. System shutdown should not return, if it returns, it means the system does
  84. not support shut down reset.
  85. **/
  86. VOID
  87. EFIAPI
  88. ResetShutdown (
  89. VOID
  90. )
  91. {
  92. EFI_HOB_GUID_TYPE *GuidHob;
  93. ACPI_BOARD_INFO *pAcpiBoardInfo;
  94. UINTN PmCtrlReg;
  95. //
  96. // Find the acpi board information guid hob
  97. //
  98. GuidHob = GetFirstGuidHob (&gUefiAcpiBoardInfoGuid);
  99. ASSERT (GuidHob != NULL);
  100. pAcpiBoardInfo = (ACPI_BOARD_INFO *)GET_GUID_HOB_DATA (GuidHob);
  101. //
  102. // GPE0_EN should be disabled to avoid any GPI waking up the system from S5
  103. //
  104. IoWrite16 ((UINTN)pAcpiBoardInfo->PmGpeEnBase, 0);
  105. //
  106. // Clear Power Button Status
  107. //
  108. IoWrite16((UINTN) pAcpiBoardInfo->PmEvtBase, BIT8);
  109. //
  110. // Transform system into S5 sleep state
  111. //
  112. PmCtrlReg = (UINTN)pAcpiBoardInfo->PmCtrlRegBase;
  113. IoAndThenOr16 (PmCtrlReg, (UINT16) ~0x3c00, (UINT16) (7 << 10));
  114. IoOr16 (PmCtrlReg, BIT13);
  115. CpuDeadLoop ();
  116. ASSERT (FALSE);
  117. }
  118. /**
  119. Calling this function causes the system to enter a power state for capsule
  120. update.
  121. Reset update should not return, if it returns, it means the system does
  122. not support capsule update.
  123. **/
  124. VOID
  125. EFIAPI
  126. EnterS3WithImmediateWake (
  127. VOID
  128. )
  129. {
  130. AcpiPmControl (5);
  131. ASSERT (FALSE);
  132. }
  133. /**
  134. This function causes a systemwide reset. The exact type of the reset is
  135. defined by the EFI_GUID that follows the Null-terminated Unicode string passed
  136. into ResetData. If the platform does not recognize the EFI_GUID in ResetData
  137. the platform must pick a supported reset type to perform.The platform may
  138. optionally log the parameters from any non-normal reset that occurs.
  139. @param[in] DataSize The size, in bytes, of ResetData.
  140. @param[in] ResetData The data buffer starts with a Null-terminated string,
  141. followed by the EFI_GUID.
  142. **/
  143. VOID
  144. EFIAPI
  145. ResetPlatformSpecific (
  146. IN UINTN DataSize,
  147. IN VOID *ResetData
  148. )
  149. {
  150. ResetCold ();
  151. }
  152. /**
  153. The ResetSystem function resets the entire platform.
  154. @param[in] ResetType The type of reset to perform.
  155. @param[in] ResetStatus The status code for the reset.
  156. @param[in] DataSize The size, in bytes, of ResetData.
  157. @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown
  158. the data buffer starts with a Null-terminated string, optionally
  159. followed by additional binary data. The string is a description
  160. that the caller may use to further indicate the reason for the
  161. system reset.
  162. **/
  163. VOID
  164. EFIAPI
  165. ResetSystem (
  166. IN EFI_RESET_TYPE ResetType,
  167. IN EFI_STATUS ResetStatus,
  168. IN UINTN DataSize,
  169. IN VOID *ResetData OPTIONAL
  170. )
  171. {
  172. switch (ResetType) {
  173. case EfiResetWarm:
  174. ResetWarm ();
  175. break;
  176. case EfiResetCold:
  177. ResetCold ();
  178. break;
  179. case EfiResetShutdown:
  180. ResetShutdown ();
  181. return;
  182. case EfiResetPlatformSpecific:
  183. ResetPlatformSpecific (DataSize, ResetData);
  184. return;
  185. default:
  186. return;
  187. }
  188. }