xref: /openbmc/linux/arch/riscv/include/asm/sbi.h (revision 2f293651)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2015 Regents of the University of California
4  * Copyright (c) 2020 Western Digital Corporation or its affiliates.
5  */
6 
7 #ifndef _ASM_RISCV_SBI_H
8 #define _ASM_RISCV_SBI_H
9 
10 #include <linux/types.h>
11 #include <linux/cpumask.h>
12 
13 #ifdef CONFIG_RISCV_SBI
14 enum sbi_ext_id {
15 #ifdef CONFIG_RISCV_SBI_V01
16 	SBI_EXT_0_1_SET_TIMER = 0x0,
17 	SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1,
18 	SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2,
19 	SBI_EXT_0_1_CLEAR_IPI = 0x3,
20 	SBI_EXT_0_1_SEND_IPI = 0x4,
21 	SBI_EXT_0_1_REMOTE_FENCE_I = 0x5,
22 	SBI_EXT_0_1_REMOTE_SFENCE_VMA = 0x6,
23 	SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID = 0x7,
24 	SBI_EXT_0_1_SHUTDOWN = 0x8,
25 #endif
26 	SBI_EXT_BASE = 0x10,
27 	SBI_EXT_TIME = 0x54494D45,
28 	SBI_EXT_IPI = 0x735049,
29 	SBI_EXT_RFENCE = 0x52464E43,
30 	SBI_EXT_HSM = 0x48534D,
31 	SBI_EXT_SRST = 0x53525354,
32 
33 	/* Experimentals extensions must lie within this range */
34 	SBI_EXT_EXPERIMENTAL_START = 0x08000000,
35 	SBI_EXT_EXPERIMENTAL_END = 0x08FFFFFF,
36 
37 	/* Vendor extensions must lie within this range */
38 	SBI_EXT_VENDOR_START = 0x09000000,
39 	SBI_EXT_VENDOR_END = 0x09FFFFFF,
40 };
41 
42 enum sbi_ext_base_fid {
43 	SBI_EXT_BASE_GET_SPEC_VERSION = 0,
44 	SBI_EXT_BASE_GET_IMP_ID,
45 	SBI_EXT_BASE_GET_IMP_VERSION,
46 	SBI_EXT_BASE_PROBE_EXT,
47 	SBI_EXT_BASE_GET_MVENDORID,
48 	SBI_EXT_BASE_GET_MARCHID,
49 	SBI_EXT_BASE_GET_MIMPID,
50 };
51 
52 enum sbi_ext_time_fid {
53 	SBI_EXT_TIME_SET_TIMER = 0,
54 };
55 
56 enum sbi_ext_ipi_fid {
57 	SBI_EXT_IPI_SEND_IPI = 0,
58 };
59 
60 enum sbi_ext_rfence_fid {
61 	SBI_EXT_RFENCE_REMOTE_FENCE_I = 0,
62 	SBI_EXT_RFENCE_REMOTE_SFENCE_VMA,
63 	SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID,
64 	SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA_VMID,
65 	SBI_EXT_RFENCE_REMOTE_HFENCE_GVMA,
66 	SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID,
67 	SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA,
68 };
69 
70 enum sbi_ext_hsm_fid {
71 	SBI_EXT_HSM_HART_START = 0,
72 	SBI_EXT_HSM_HART_STOP,
73 	SBI_EXT_HSM_HART_STATUS,
74 };
75 
76 enum sbi_hsm_hart_status {
77 	SBI_HSM_HART_STATUS_STARTED = 0,
78 	SBI_HSM_HART_STATUS_STOPPED,
79 	SBI_HSM_HART_STATUS_START_PENDING,
80 	SBI_HSM_HART_STATUS_STOP_PENDING,
81 };
82 
83 enum sbi_ext_srst_fid {
84 	SBI_EXT_SRST_RESET = 0,
85 };
86 
87 enum sbi_srst_reset_type {
88 	SBI_SRST_RESET_TYPE_SHUTDOWN = 0,
89 	SBI_SRST_RESET_TYPE_COLD_REBOOT,
90 	SBI_SRST_RESET_TYPE_WARM_REBOOT,
91 };
92 
93 enum sbi_srst_reset_reason {
94 	SBI_SRST_RESET_REASON_NONE = 0,
95 	SBI_SRST_RESET_REASON_SYS_FAILURE,
96 };
97 
98 #define SBI_SPEC_VERSION_DEFAULT	0x1
99 #define SBI_SPEC_VERSION_MAJOR_SHIFT	24
100 #define SBI_SPEC_VERSION_MAJOR_MASK	0x7f
101 #define SBI_SPEC_VERSION_MINOR_MASK	0xffffff
102 
103 /* SBI return error codes */
104 #define SBI_SUCCESS		0
105 #define SBI_ERR_FAILURE		-1
106 #define SBI_ERR_NOT_SUPPORTED	-2
107 #define SBI_ERR_INVALID_PARAM	-3
108 #define SBI_ERR_DENIED		-4
109 #define SBI_ERR_INVALID_ADDRESS	-5
110 #define SBI_ERR_ALREADY_AVAILABLE -6
111 
112 extern unsigned long sbi_spec_version;
113 struct sbiret {
114 	long error;
115 	long value;
116 };
117 
118 void sbi_init(void);
119 struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
120 			unsigned long arg1, unsigned long arg2,
121 			unsigned long arg3, unsigned long arg4,
122 			unsigned long arg5);
123 
124 void sbi_console_putchar(int ch);
125 int sbi_console_getchar(void);
126 long sbi_get_mvendorid(void);
127 long sbi_get_marchid(void);
128 long sbi_get_mimpid(void);
129 void sbi_set_timer(uint64_t stime_value);
130 void sbi_shutdown(void);
131 void sbi_clear_ipi(void);
132 int sbi_send_ipi(const struct cpumask *cpu_mask);
133 int sbi_remote_fence_i(const struct cpumask *cpu_mask);
134 int sbi_remote_sfence_vma(const struct cpumask *cpu_mask,
135 			   unsigned long start,
136 			   unsigned long size);
137 
138 int sbi_remote_sfence_vma_asid(const struct cpumask *cpu_mask,
139 				unsigned long start,
140 				unsigned long size,
141 				unsigned long asid);
142 int sbi_remote_hfence_gvma(const struct cpumask *cpu_mask,
143 			   unsigned long start,
144 			   unsigned long size);
145 int sbi_remote_hfence_gvma_vmid(const struct cpumask *cpu_mask,
146 				unsigned long start,
147 				unsigned long size,
148 				unsigned long vmid);
149 int sbi_remote_hfence_vvma(const struct cpumask *cpu_mask,
150 			   unsigned long start,
151 			   unsigned long size);
152 int sbi_remote_hfence_vvma_asid(const struct cpumask *cpu_mask,
153 				unsigned long start,
154 				unsigned long size,
155 				unsigned long asid);
156 int sbi_probe_extension(int ext);
157 
158 /* Check if current SBI specification version is 0.1 or not */
159 static inline int sbi_spec_is_0_1(void)
160 {
161 	return (sbi_spec_version == SBI_SPEC_VERSION_DEFAULT) ? 1 : 0;
162 }
163 
164 /* Get the major version of SBI */
165 static inline unsigned long sbi_major_version(void)
166 {
167 	return (sbi_spec_version >> SBI_SPEC_VERSION_MAJOR_SHIFT) &
168 		SBI_SPEC_VERSION_MAJOR_MASK;
169 }
170 
171 /* Get the minor version of SBI */
172 static inline unsigned long sbi_minor_version(void)
173 {
174 	return sbi_spec_version & SBI_SPEC_VERSION_MINOR_MASK;
175 }
176 
177 /* Make SBI version */
178 static inline unsigned long sbi_mk_version(unsigned long major,
179 					    unsigned long minor)
180 {
181 	return ((major & SBI_SPEC_VERSION_MAJOR_MASK) <<
182 		SBI_SPEC_VERSION_MAJOR_SHIFT) | minor;
183 }
184 
185 int sbi_err_map_linux_errno(int err);
186 #else /* CONFIG_RISCV_SBI */
187 static inline int sbi_remote_fence_i(const struct cpumask *cpu_mask) { return -1; }
188 static inline void sbi_init(void) {}
189 #endif /* CONFIG_RISCV_SBI */
190 #endif /* _ASM_RISCV_SBI_H */
191