Zephyr Project API 4.5.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
sbi.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Alexios Lyrakis <alexios.lyrakis@gmail.com>
3 * Copyright (c) 2026 BeagleBoard.org Foundation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
21
22#ifndef ZEPHYR_INCLUDE_ARCH_RISCV_SBI_H_
23#define ZEPHYR_INCLUDE_ARCH_RISCV_SBI_H_
24
25#ifndef _ASMLANGUAGE
26#include <errno.h>
27#endif /* _ASMLANGUAGE */
28
30#define SBI_EXT_TIME 0x54494D45
31
33#define SBI_FUNC_SET_TIMER 0
34
36#define SBI_EXT_SRST 0x53525354
37
39#define SBI_FUNC_SYSTEM_RESET 0
40
42#define SBI_SRST_RESET_TYPE_SHUTDOWN 0
44#define SBI_SRST_RESET_TYPE_COLD_REBOOT 1
46#define SBI_SRST_RESET_TYPE_WARM_REBOOT 2
47
49#define SBI_SRST_RESET_REASON_NONE 0
50
52#define SBI_EXT_HSM 0x48534D
53
55#define SBI_FUNC_HART_START 0
57#define SBI_FUNC_HART_STOP 1
58
60#define SBI_EXT_IPI 0x735049
61
63#define SBI_FUNC_SEND_IPI 0
64
66#define SBI_SUCCESS 0
68#define SBI_ERR_FAILED -1
70#define SBI_ERR_NOT_SUPPORTED -2
72#define SBI_ERR_INVALID_PARAM -3
74#define SBI_ERR_DENIED -4
76#define SBI_ERR_INVALID_ADDRESS -5
78#define SBI_ERR_ALREADY_AVAILABLE -6
80#define SBI_ERR_ALREADY_STARTED -7
82#define SBI_ERR_ALREADY_STOPPED -8
84#define SBI_ERR_NO_SHMEM -9
86#define SBI_ERR_INVALID_STATE -10
88#define SBI_ERR_BAD_RANGE -11
90#define SBI_ERR_TIMEOUT -12
92#define SBI_ERR_IO -13
94#define SBI_ERR_DENIED_LOCKED -14
95
96#ifndef _ASMLANGUAGE
106static inline int sbi_err_to_errno(unsigned long err)
107{
108 switch ((long)err) {
109 case SBI_SUCCESS:
110 return 0;
111 case SBI_ERR_FAILED:
112 return -EIO;
115 return -EINVAL;
116 case SBI_ERR_DENIED:
118 return -EPERM;
120 return -EFAULT;
124 return -EALREADY;
125 case SBI_ERR_NO_SHMEM:
126 return -ENOMEM;
128 return -ERANGE;
129 case SBI_ERR_TIMEOUT:
130 return -ETIMEDOUT;
131 case SBI_ERR_IO:
132 return -EIO;
134 default:
135 return -ENOTSUP;
136 }
137}
138
139struct sbiret {
140 long error;
141 union {
142 long value;
143 unsigned long uvalue;
144 };
145};
146
147static inline struct sbiret sbi_ecall(unsigned long arg0, unsigned long arg1, unsigned long arg2,
148 unsigned long arg3, unsigned long arg4, unsigned long arg5,
149 unsigned long fid, unsigned long ext)
150{
151 struct sbiret ret;
152
153 register unsigned long a0 __asm__("a0") = (arg0);
154 register unsigned long a1 __asm__("a1") = (arg1);
155 register unsigned long a2 __asm__("a2") = (arg2);
156 register unsigned long a3 __asm__("a3") = (arg3);
157 register unsigned long a4 __asm__("a4") = (arg4);
158 register unsigned long a5 __asm__("a5") = (arg5);
159 register unsigned long a6 __asm__("a6") = (fid);
160 register unsigned long a7 __asm__("a7") = (ext);
161
162 __asm__ volatile("ecall"
163 : "+r"(a0), "+r"(a1)
164 : "r"(a2), "r"(a3), "r"(a4), "r"(a5), "r"(a6), "r"(a7)
165 : "memory");
166
167 ret.error = a0;
168 ret.value = a1;
169
170 return ret;
171}
172#endif /* _ASMLANGUAGE */
173
174#endif /* ZEPHYR_INCLUDE_ARCH_RISCV_SBI_H_ */
System error numbers.
#define EINVAL
Invalid argument.
Definition errno.h:61
#define EFAULT
Bad address.
Definition errno.h:53
#define ETIMEDOUT
Connection timed out.
Definition errno.h:101
#define ENOMEM
Not enough core.
Definition errno.h:51
#define EIO
I/O error.
Definition errno.h:44
#define ENOTSUP
Unsupported value.
Definition errno.h:115
#define ERANGE
Result too large.
Definition errno.h:73
#define EALREADY
Operation already in progress.
Definition errno.h:105
#define EPERM
Not owner.
Definition errno.h:40
#define unsigned
Definition types.h:27
#define SBI_ERR_ALREADY_STOPPED
SBI return code: the target has already been stopped.
Definition sbi.h:82
#define SBI_ERR_IO
SBI return code: an I/O error occurred during the operation.
Definition sbi.h:92
#define SBI_ERR_ALREADY_STARTED
SBI return code: the target has already been started.
Definition sbi.h:80
static struct sbiret sbi_ecall(unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long fid, unsigned long ext)
Definition sbi.h:147
#define SBI_ERR_FAILED
SBI return code: the call failed for an unspecified reason.
Definition sbi.h:68
#define SBI_ERR_DENIED
SBI return code: the caller is not permitted to perform the operation.
Definition sbi.h:74
#define SBI_ERR_DENIED_LOCKED
SBI return code: denied because the resource is locked.
Definition sbi.h:94
#define SBI_ERR_INVALID_STATE
SBI return code: the operation is not valid in the current state.
Definition sbi.h:86
#define SBI_ERR_BAD_RANGE
SBI return code: the supplied range is malformed or out of bounds.
Definition sbi.h:88
#define SBI_ERR_NO_SHMEM
SBI return code: no shared memory region has been set up.
Definition sbi.h:84
#define SBI_ERR_NOT_SUPPORTED
SBI return code: requested extension/function is not available.
Definition sbi.h:70
#define SBI_SUCCESS
SBI return code: call completed successfully.
Definition sbi.h:66
#define SBI_ERR_INVALID_ADDRESS
SBI return code: an address argument was invalid or inaccessible.
Definition sbi.h:76
#define SBI_ERR_TIMEOUT
SBI return code: the operation did not complete in time.
Definition sbi.h:90
#define SBI_ERR_ALREADY_AVAILABLE
SBI return code: the resource is already available.
Definition sbi.h:78
#define SBI_ERR_INVALID_PARAM
SBI return code: one or more arguments were invalid.
Definition sbi.h:72
static int sbi_err_to_errno(unsigned long err)
Translate an SBI return code into a negative errno value.
Definition sbi.h:106
Definition sbi.h:139
long value
Definition sbi.h:142
long error
Definition sbi.h:140
unsigned long uvalue
Definition sbi.h:143