BaseRiscVSbiLib.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /** @file
  2. Library to call the RISC-V SBI ecalls
  3. Copyright (c) 2021-2022, Hewlett Packard Development LP. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. @par Glossary:
  6. - Hart - Hardware Thread, similar to a CPU core
  7. Currently, EDK2 needs to call SBI only to set the time and to do system reset.
  8. **/
  9. #ifndef RISCV_SBI_LIB_H_
  10. #define RISCV_SBI_LIB_H_
  11. #include <Uefi.h>
  12. /* SBI Extension IDs */
  13. #define SBI_EXT_TIME 0x54494D45
  14. #define SBI_EXT_SRST 0x53525354
  15. /* SBI function IDs for TIME extension*/
  16. #define SBI_EXT_TIME_SET_TIMER 0x0
  17. /* SBI function IDs for SRST extension */
  18. #define SBI_EXT_SRST_RESET 0x0
  19. #define SBI_SRST_RESET_TYPE_SHUTDOWN 0x0
  20. #define SBI_SRST_RESET_TYPE_COLD_REBOOT 0x1
  21. #define SBI_SRST_RESET_TYPE_WARM_REBOOT 0x2
  22. #define SBI_SRST_RESET_REASON_NONE 0x0
  23. #define SBI_SRST_RESET_REASON_SYSFAIL 0x1
  24. /* SBI return error codes */
  25. #define SBI_SUCCESS 0
  26. #define SBI_ERR_FAILED -1
  27. #define SBI_ERR_NOT_SUPPORTED -2
  28. #define SBI_ERR_INVALID_PARAM -3
  29. #define SBI_ERR_DENIED -4
  30. #define SBI_ERR_INVALID_ADDRESS -5
  31. #define SBI_ERR_ALREADY_AVAILABLE -6
  32. #define SBI_ERR_ALREADY_STARTED -7
  33. #define SBI_ERR_ALREADY_STOPPED -8
  34. #define SBI_LAST_ERR SBI_ERR_ALREADY_STOPPED
  35. typedef struct {
  36. UINT64 BootHartId;
  37. VOID *PeiServiceTable; // PEI Service table
  38. VOID *PrePiHobList; // Pre PI Hob List
  39. UINT64 FlattenedDeviceTree; // Pointer to Flattened Device tree
  40. } EFI_RISCV_FIRMWARE_CONTEXT;
  41. //
  42. // EDK2 OpenSBI firmware extension return status.
  43. //
  44. typedef struct {
  45. UINTN Error; ///< SBI status code
  46. UINTN Value; ///< Value returned
  47. } SBI_RET;
  48. VOID
  49. EFIAPI
  50. SbiSetTimer (
  51. IN UINT64 Time
  52. );
  53. EFI_STATUS
  54. EFIAPI
  55. SbiSystemReset (
  56. IN UINTN ResetType,
  57. IN UINTN ResetReason
  58. );
  59. /**
  60. Get firmware context of the calling hart.
  61. @param[out] FirmwareContext The firmware context pointer.
  62. **/
  63. VOID
  64. EFIAPI
  65. GetFirmwareContext (
  66. OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContext
  67. );
  68. /**
  69. Set firmware context of the calling hart.
  70. @param[in] FirmwareContext The firmware context pointer.
  71. **/
  72. VOID
  73. EFIAPI
  74. SetFirmwareContext (
  75. IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext
  76. );
  77. /**
  78. Get pointer to OpenSBI Firmware Context
  79. Get the pointer of firmware context.
  80. @param FirmwareContextPtr Pointer to retrieve pointer to the
  81. Firmware Context.
  82. **/
  83. VOID
  84. EFIAPI
  85. GetFirmwareContextPointer (
  86. IN OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContextPtr
  87. );
  88. /**
  89. Set pointer to OpenSBI Firmware Context
  90. Set the pointer of firmware context.
  91. @param FirmwareContextPtr Pointer to Firmware Context.
  92. **/
  93. VOID
  94. EFIAPI
  95. SetFirmwareContextPointer (
  96. IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContextPtr
  97. );
  98. /**
  99. Make ECALL in assembly
  100. Switch to M-mode
  101. @param[in,out] Arg0
  102. @param[in,out] Arg1
  103. @param[in] Arg2
  104. @param[in] Arg3
  105. @param[in] Arg4
  106. @param[in] Arg5
  107. @param[in] FID
  108. @param[in] EXT
  109. **/
  110. VOID
  111. EFIAPI
  112. RiscVSbiEcall (
  113. IN OUT UINTN *Arg0,
  114. IN OUT UINTN *Arg1,
  115. IN UINTN Arg2,
  116. IN UINTN Arg3,
  117. IN UINTN Arg4,
  118. IN UINTN Arg5,
  119. IN UINTN Fid,
  120. IN UINTN Ext
  121. );
  122. #endif