xref: /optee_os/core/arch/riscv/include/sbi.h (revision cc967d3f1128cd24d44b0560877ebd8ba884e037)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2022, 2025 NXP
4  */
5 
6 #ifndef __SBI_H
7 #define __SBI_H
8 
9 #if defined(CFG_RISCV_SBI)
10 
11 /* SBI return error codes */
12 #define SBI_SUCCESS			 0
13 #define SBI_ERR_FAILURE			-1
14 #define SBI_ERR_NOT_SUPPORTED		-2
15 #define SBI_ERR_INVALID_PARAM		-3
16 #define SBI_ERR_DENIED			-4
17 #define SBI_ERR_INVALID_ADDRESS		-5
18 #define SBI_ERR_ALREADY_AVAILABLE	-6
19 #define SBI_ERR_ALREADY_STARTED		-7
20 #define SBI_ERR_ALREADY_STOPPED		-8
21 #define SBI_ERR_NO_SHMEM		-9
22 #define SBI_ERR_INVALID_STATE		-10
23 #define SBI_ERR_BAD_RANGE		-11
24 #define SBI_ERR_TIMEOUT			-12
25 #define SBI_ERR_IO			-13
26 #define SBI_ERR_DENIED_LOCKED		-14
27 
28 #define SBI_LAST_ERR			SBI_ERR_DENIED_LOCKED
29 
30 /* SBI Extension IDs */
31 #define SBI_EXT_0_1_CONSOLE_PUTCHAR	0x01
32 #define SBI_EXT_BASE			0x10
33 #define SBI_EXT_HSM			0x48534D
34 #define SBI_EXT_DBCN			0x4442434E
35 #define SBI_EXT_TEE			0x544545
36 #define SBI_EXT_MPXY                    0x4D505859
37 
38 #ifndef __ASSEMBLER__
39 
40 /* SBI function IDs for Base extension */
41 enum sbi_ext_base_fid {
42 	SBI_EXT_BASE_GET_SPEC_VERSION = 0,
43 	SBI_EXT_BASE_GET_IMP_ID,
44 	SBI_EXT_BASE_GET_IMP_VERSION,
45 	SBI_EXT_BASE_PROBE_EXT,
46 	SBI_EXT_BASE_GET_MVENDORID,
47 	SBI_EXT_BASE_GET_MARCHID,
48 	SBI_EXT_BASE_GET_MIMPID,
49 };
50 
51 /* SBI function IDs for HSM extension */
52 enum sbi_ext_hsm_fid {
53 	SBI_EXT_HSM_HART_START = 0,
54 	SBI_EXT_HSM_HART_STOP,
55 	SBI_EXT_HSM_HART_GET_STATUS,
56 	SBI_EXT_HSM_HART_SUSPEND,
57 };
58 
59 /* SBI function IDs for Debug Console extension */
60 enum sbi_ext_dbcn_fid {
61 	SBI_EXT_DBCN_CONSOLE_WRITE = 0,
62 	SBI_EXT_DBCN_CONSOLE_READ = 1,
63 	SBI_EXT_DBCN_CONSOLE_WRITE_BYTE = 2,
64 };
65 
66 enum sbi_hsm_hart_state {
67 	SBI_HSM_STATE_STARTED = 0,
68 	SBI_HSM_STATE_STOPPED,
69 	SBI_HSM_STATE_START_PENDING,
70 	SBI_HSM_STATE_STOP_PENDING,
71 	SBI_HSM_STATE_SUSPENDED,
72 	SBI_HSM_STATE_SUSPEND_PENDING,
73 	SBI_HSM_STATE_RESUME_PENDING,
74 };
75 
76 #include <compiler.h>
77 #include <encoding.h>
78 #include <stdint.h>
79 #include <sys/cdefs.h>
80 #include <types_ext.h>
81 #include <util.h>
82 
83 int sbi_probe_extension(int extid);
84 void sbi_console_putchar(int ch);
85 int sbi_dbcn_write_byte(unsigned char ch);
86 int sbi_hsm_hart_start(uint32_t hartid, paddr_t start_addr, unsigned long arg);
87 int sbi_hsm_hart_get_status(uint32_t hartid, enum sbi_hsm_hart_state *status);
88 
89 #endif /*__ASSEMBLER__*/
90 #endif /*defined(CFG_RISCV_SBI)*/
91 #endif /*__SBI_H*/
92