TianoCore EDK2 master
Loading...
Searching...
No Matches
BaseRiscVSbiLib.c
Go to the documentation of this file.
1
13#include <Library/BaseLib.h>
15#include <Library/DebugLib.h>
17
18//
19// Maximum arguments for SBI ecall
20#define SBI_CALL_MAX_ARGS 6
21
36EFIAPI
38 IN UINTN ExtId,
39 IN UINTN FuncId,
40 IN UINTN NumArgs,
41 ...
42 )
43{
44 UINTN I;
45 SBI_RET Ret;
46 UINTN Args[SBI_CALL_MAX_ARGS];
47 VA_LIST ArgList;
48
49 VA_START (ArgList, NumArgs);
50
51 if (NumArgs > SBI_CALL_MAX_ARGS) {
52 Ret.Error = SBI_ERR_INVALID_PARAM;
53 Ret.Value = -1;
54 return Ret;
55 }
56
57 for (I = 0; I < SBI_CALL_MAX_ARGS; I++) {
58 if (I < NumArgs) {
59 Args[I] = VA_ARG (ArgList, UINTN);
60 } else {
61 // Default to 0 for all arguments that are not given
62 Args[I] = 0;
63 }
64 }
65
66 VA_END (ArgList);
67
68 // ECALL updates the a0 and a1 registers as return values.
70 &Args[0],
71 &Args[1],
72 Args[2],
73 Args[3],
74 Args[4],
75 Args[5],
76 (UINTN)(FuncId),
77 (UINTN)(ExtId)
78 );
79
80 Ret.Error = Args[0];
81 Ret.Value = Args[1];
82 return Ret;
83}
84
92EFIAPI
94 IN UINTN SbiError
95 )
96{
97 switch (SbiError) {
98 case SBI_SUCCESS:
99 return EFI_SUCCESS;
100 case SBI_ERR_FAILED:
101 return EFI_DEVICE_ERROR;
102 break;
103 case SBI_ERR_NOT_SUPPORTED:
104 return EFI_UNSUPPORTED;
105 break;
106 case SBI_ERR_INVALID_PARAM:
107 return EFI_INVALID_PARAMETER;
108 break;
109 case SBI_ERR_DENIED:
110 return EFI_ACCESS_DENIED;
111 break;
112 case SBI_ERR_INVALID_ADDRESS:
113 return EFI_LOAD_ERROR;
114 break;
115 case SBI_ERR_ALREADY_AVAILABLE:
116 return EFI_ALREADY_STARTED;
117 break;
118 default:
119 //
120 // Reaches here only if SBI has defined a new error type
121 //
122 ASSERT (FALSE);
123 return EFI_UNSUPPORTED;
124 break;
125 }
126}
127
136VOID
137EFIAPI
139 IN UINT64 Time
140 )
141{
142 SbiCall (SBI_EXT_TIME, SBI_EXT_TIME_SET_TIMER, 1, Time);
143}
144
152EFIAPI
154 IN UINTN ResetType,
155 IN UINTN ResetReason
156 )
157{
158 SBI_RET Ret;
159
160 Ret = SbiCall (
161 SBI_EXT_SRST,
162 SBI_EXT_SRST_RESET,
163 2,
164 ResetType,
165 ResetReason
166 );
167
168 return TranslateError (Ret.Error);
169}
170
176VOID
177EFIAPI
179 OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContext
180 )
181{
182 *FirmwareContext = (EFI_RISCV_FIRMWARE_CONTEXT *)RiscVGetSupervisorScratch ();
183}
184
190VOID
191EFIAPI
193 IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext
194 )
195{
196 RiscVSetSupervisorScratch ((UINT64)FirmwareContext);
197}
198
207VOID
208EFIAPI
210 IN OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContextPtr
211 )
212{
213 GetFirmwareContext (FirmwareContextPtr);
214}
215
223VOID
224EFIAPI
226 IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContextPtr
227 )
228{
229 SetFirmwareContext (FirmwareContextPtr);
230}
UINT64 UINTN
EFI_STATUS EFIAPI SbiSystemReset(IN UINTN ResetType, IN UINTN ResetReason)
VOID EFIAPI SetFirmwareContextPointer(IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContextPtr)
VOID EFIAPI SbiSetTimer(IN UINT64 Time)
VOID EFIAPI SetFirmwareContext(IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext)
VOID EFIAPI GetFirmwareContext(OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContext)
VOID EFIAPI GetFirmwareContextPointer(IN OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContextPtr)
SBI_RET EFIAPI SbiCall(IN UINTN ExtId, IN UINTN FuncId, IN UINTN NumArgs,...)
EFI_STATUS EFIAPI TranslateError(IN UINTN SbiError)
VOID EFIAPI RiscVSbiEcall(IN OUT UINTN *Arg0, IN OUT UINTN *Arg1, IN UINTN Arg2, IN UINTN Arg3, IN UINTN Arg4, IN UINTN Arg5, IN UINTN Fid, IN UINTN Ext)
#define VA_ARG(Marker, TYPE)
Definition: Base.h:679
#define VA_START(Marker, Parameter)
Definition: Base.h:661
#define FALSE
Definition: Base.h:307
CHAR8 * VA_LIST
Definition: Base.h:643
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define VA_END(Marker)
Definition: Base.h:691
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
UINTN Error
SBI status code.
UINTN Value
Value returned.