2 Library to call the RISC-V SBI ecalls
4 Copyright (c) 2021-2022, Hewlett Packard Development LP. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
9 - Hart - Hardware Thread, similar to a CPU core
11 Currently, EDK2 needs to call SBI only to set the time and to do system reset.
15 #ifndef RISCV_SBI_LIB_H_
16 #define RISCV_SBI_LIB_H_
20 /* SBI Extension IDs */
21 #define SBI_EXT_TIME 0x54494D45
22 #define SBI_EXT_SRST 0x53525354
24 /* SBI function IDs for TIME extension*/
25 #define SBI_EXT_TIME_SET_TIMER 0x0
27 /* SBI function IDs for SRST extension */
28 #define SBI_EXT_SRST_RESET 0x0
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
34 #define SBI_SRST_RESET_REASON_NONE 0x0
35 #define SBI_SRST_RESET_REASON_SYSFAIL 0x1
37 /* SBI return error codes */
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
48 #define SBI_LAST_ERR SBI_ERR_ALREADY_STOPPED
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
;
58 // EDK2 OpenSBI firmware extension return status.
61 UINTN Error
; ///< SBI status code
62 UINTN Value
; ///< Value returned
79 Get firmware context of the calling hart.
81 @param[out] FirmwareContext The firmware context pointer.
86 OUT EFI_RISCV_FIRMWARE_CONTEXT
**FirmwareContext
90 Set firmware context of the calling hart.
92 @param[in] FirmwareContext The firmware context pointer.
97 IN EFI_RISCV_FIRMWARE_CONTEXT
*FirmwareContext
101 Get pointer to OpenSBI Firmware Context
103 Get the pointer of firmware context.
105 @param FirmwareContextPtr Pointer to retrieve pointer to the
110 GetFirmwareContextPointer (
111 IN OUT EFI_RISCV_FIRMWARE_CONTEXT
**FirmwareContextPtr
115 Set pointer to OpenSBI Firmware Context
117 Set the pointer of firmware context.
119 @param FirmwareContextPtr Pointer to Firmware Context.
123 SetFirmwareContextPointer (
124 IN EFI_RISCV_FIRMWARE_CONTEXT
*FirmwareContextPtr
128 Make ECALL in assembly