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