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