ResetSystemLib.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /** @file
  2. Reset System Library functions for RISC-V
  3. Copyright (c) 2021, Hewlett Packard Development LP. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Library/DebugLib.h>
  7. #include <Library/ResetSystemLib.h>
  8. #include <Library/BaseRiscVSbiLib.h>
  9. /**
  10. This function causes a system-wide reset (cold reset), in which
  11. all circuitry within the system returns to its initial state. This type of reset
  12. is asynchronous to system operation and operates without regard to
  13. cycle boundaries.
  14. If this function returns, it means that the system does not support cold reset.
  15. **/
  16. VOID
  17. EFIAPI
  18. ResetCold (
  19. VOID
  20. )
  21. {
  22. // Warm Reset via SBI ecall
  23. SbiSystemReset (SBI_SRST_RESET_TYPE_COLD_REBOOT, SBI_SRST_RESET_REASON_NONE);
  24. }
  25. /**
  26. This function causes a system-wide initialization (warm reset), in which all processors
  27. are set to their initial state. Pending cycles are not corrupted.
  28. If this function returns, it means that the system does not support warm reset.
  29. **/
  30. VOID
  31. EFIAPI
  32. ResetWarm (
  33. VOID
  34. )
  35. {
  36. // Warm Reset via SBI ecall
  37. SbiSystemReset (SBI_SRST_RESET_TYPE_WARM_REBOOT, SBI_SRST_RESET_REASON_NONE);
  38. }
  39. /**
  40. This function causes the system to enter a power state equivalent
  41. to the ACPI G2/S5 or G3 states.
  42. If this function returns, it means that the system does not support shutdown reset.
  43. **/
  44. VOID
  45. EFIAPI
  46. ResetShutdown (
  47. VOID
  48. )
  49. {
  50. // Shut down via SBI ecall
  51. SbiSystemReset (SBI_SRST_RESET_TYPE_SHUTDOWN, SBI_SRST_RESET_REASON_NONE);
  52. }
  53. /**
  54. This function causes a systemwide reset. The exact type of the reset is
  55. defined by the EFI_GUID that follows the Null-terminated Unicode string passed
  56. into ResetData. If the platform does not recognize the EFI_GUID in ResetData
  57. the platform must pick a supported reset type to perform. The platform may
  58. optionally log the parameters from any non-normal reset that occurs.
  59. @param[in] DataSize The size, in bytes, of ResetData.
  60. @param[in] ResetData The data buffer starts with a Null-terminated string,
  61. followed by the EFI_GUID.
  62. **/
  63. VOID
  64. EFIAPI
  65. ResetPlatformSpecific (
  66. IN UINTN DataSize,
  67. IN VOID *ResetData
  68. )
  69. {
  70. //
  71. // Can map to OpenSBI vendor or platform specific reset type.
  72. //
  73. return;
  74. }
  75. /**
  76. The ResetSystem function resets the entire platform.
  77. @param[in] ResetType The type of reset to perform.
  78. @param[in] ResetStatus The status code for the reset.
  79. @param[in] DataSize The size, in bytes, of ResetData.
  80. @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown
  81. the data buffer starts with a Null-terminated string, optionally
  82. followed by additional binary data. The string is a description
  83. that the caller may use to further indicate the reason for the
  84. system reset.
  85. **/
  86. VOID
  87. EFIAPI
  88. ResetSystem (
  89. IN EFI_RESET_TYPE ResetType,
  90. IN EFI_STATUS ResetStatus,
  91. IN UINTN DataSize,
  92. IN VOID *ResetData OPTIONAL
  93. )
  94. {
  95. switch (ResetType) {
  96. case EfiResetWarm:
  97. ResetWarm ();
  98. break;
  99. case EfiResetCold:
  100. ResetCold ();
  101. break;
  102. case EfiResetShutdown:
  103. ResetShutdown ();
  104. return;
  105. case EfiResetPlatformSpecific:
  106. ResetPlatformSpecific (DataSize, ResetData);
  107. return;
  108. default:
  109. return;
  110. }
  111. }