Zephyr Project API 4.5.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
sbi.h File Reference

RISC-V Supervisor Binary Interface (SBI) definitions. More...

#include <errno.h>

Go to the source code of this file.

Data Structures

struct  sbiret

Macros

#define SBI_EXT_TIME   0x54494D45
 SBI extension ID for the Timer extension (TIME).
#define SBI_FUNC_SET_TIMER   0
 SBI_EXT_TIME function ID: set the next timer deadline.
#define SBI_EXT_SRST   0x53525354
 SBI extension ID for the System Reset extension (SRST).
#define SBI_FUNC_SYSTEM_RESET   0
 SBI_EXT_SRST function ID: reset or power off the system.
#define SBI_SRST_RESET_TYPE_SHUTDOWN   0
 SBI_EXT_SRST reset type: clean shutdown (power off).
#define SBI_SRST_RESET_TYPE_COLD_REBOOT   1
 SBI_EXT_SRST reset type: cold reboot.
#define SBI_SRST_RESET_TYPE_WARM_REBOOT   2
 SBI_EXT_SRST reset type: warm reboot.
#define SBI_SRST_RESET_REASON_NONE   0
 SBI_EXT_SRST reset reason: no specific reason.
#define SBI_EXT_HSM   0x48534D
 SBI extension ID for the Hart State Management extension (HSM).
#define SBI_FUNC_HART_START   0
 SBI_EXT_HSM function ID: start a stopped hart.
#define SBI_FUNC_HART_STOP   1
 SBI_EXT_HSM function ID: stop the calling hart.
#define SBI_EXT_IPI   0x735049
 SBI extension ID for the IPI extension (sPI).
#define SBI_FUNC_SEND_IPI   0
 SBI_EXT_IPI function ID: send an IPI to a set of harts.
#define SBI_SUCCESS   0
 SBI return code: call completed successfully.
#define SBI_ERR_FAILED   -1
 SBI return code: the call failed for an unspecified reason.
#define SBI_ERR_NOT_SUPPORTED   -2
 SBI return code: requested extension/function is not available.
#define SBI_ERR_INVALID_PARAM   -3
 SBI return code: one or more arguments were invalid.
#define SBI_ERR_DENIED   -4
 SBI return code: the caller is not permitted to perform the operation.
#define SBI_ERR_INVALID_ADDRESS   -5
 SBI return code: an address argument was invalid or inaccessible.
#define SBI_ERR_ALREADY_AVAILABLE   -6
 SBI return code: the resource is already available.
#define SBI_ERR_ALREADY_STARTED   -7
 SBI return code: the target has already been started.
#define SBI_ERR_ALREADY_STOPPED   -8
 SBI return code: the target has already been stopped.
#define SBI_ERR_NO_SHMEM   -9
 SBI return code: no shared memory region has been set up.
#define SBI_ERR_INVALID_STATE   -10
 SBI return code: the operation is not valid in the current state.
#define SBI_ERR_BAD_RANGE   -11
 SBI return code: the supplied range is malformed or out of bounds.
#define SBI_ERR_TIMEOUT   -12
 SBI return code: the operation did not complete in time.
#define SBI_ERR_IO   -13
 SBI return code: an I/O error occurred during the operation.
#define SBI_ERR_DENIED_LOCKED   -14
 SBI return code: denied because the resource is locked.

Functions

static int sbi_err_to_errno (unsigned long err)
 Translate an SBI return code into a negative errno value.
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)

Detailed Description

RISC-V Supervisor Binary Interface (SBI) definitions.

Defines SBI extension IDs, function IDs, and error codes used by S-mode code to request M-mode firmware services via the ecall instruction. The subset defined here covers only the extensions used by Zephyr's in-tree minimal SBI runtime (arch/riscv/core/sbi.S).

References: RISC-V SBI Specification v2.0 (https://github.com/riscv-non-isa/riscv-sbi-doc)

Macro Definition Documentation

◆ SBI_ERR_ALREADY_AVAILABLE

#define SBI_ERR_ALREADY_AVAILABLE   -6

SBI return code: the resource is already available.

◆ SBI_ERR_ALREADY_STARTED

#define SBI_ERR_ALREADY_STARTED   -7

SBI return code: the target has already been started.

◆ SBI_ERR_ALREADY_STOPPED

#define SBI_ERR_ALREADY_STOPPED   -8

SBI return code: the target has already been stopped.

◆ SBI_ERR_BAD_RANGE

#define SBI_ERR_BAD_RANGE   -11

SBI return code: the supplied range is malformed or out of bounds.

◆ SBI_ERR_DENIED

#define SBI_ERR_DENIED   -4

SBI return code: the caller is not permitted to perform the operation.

◆ SBI_ERR_DENIED_LOCKED

#define SBI_ERR_DENIED_LOCKED   -14

SBI return code: denied because the resource is locked.

◆ SBI_ERR_FAILED

#define SBI_ERR_FAILED   -1

SBI return code: the call failed for an unspecified reason.

◆ SBI_ERR_INVALID_ADDRESS

#define SBI_ERR_INVALID_ADDRESS   -5

SBI return code: an address argument was invalid or inaccessible.

◆ SBI_ERR_INVALID_PARAM

#define SBI_ERR_INVALID_PARAM   -3

SBI return code: one or more arguments were invalid.

◆ SBI_ERR_INVALID_STATE

#define SBI_ERR_INVALID_STATE   -10

SBI return code: the operation is not valid in the current state.

◆ SBI_ERR_IO

#define SBI_ERR_IO   -13

SBI return code: an I/O error occurred during the operation.

◆ SBI_ERR_NO_SHMEM

#define SBI_ERR_NO_SHMEM   -9

SBI return code: no shared memory region has been set up.

◆ SBI_ERR_NOT_SUPPORTED

#define SBI_ERR_NOT_SUPPORTED   -2

SBI return code: requested extension/function is not available.

◆ SBI_ERR_TIMEOUT

#define SBI_ERR_TIMEOUT   -12

SBI return code: the operation did not complete in time.

◆ SBI_EXT_HSM

#define SBI_EXT_HSM   0x48534D

SBI extension ID for the Hart State Management extension (HSM).

◆ SBI_EXT_IPI

#define SBI_EXT_IPI   0x735049

SBI extension ID for the IPI extension (sPI).

◆ SBI_EXT_SRST

#define SBI_EXT_SRST   0x53525354

SBI extension ID for the System Reset extension (SRST).

◆ SBI_EXT_TIME

#define SBI_EXT_TIME   0x54494D45

SBI extension ID for the Timer extension (TIME).

◆ SBI_FUNC_HART_START

#define SBI_FUNC_HART_START   0

SBI_EXT_HSM function ID: start a stopped hart.

◆ SBI_FUNC_HART_STOP

#define SBI_FUNC_HART_STOP   1

SBI_EXT_HSM function ID: stop the calling hart.

◆ SBI_FUNC_SEND_IPI

#define SBI_FUNC_SEND_IPI   0

SBI_EXT_IPI function ID: send an IPI to a set of harts.

◆ SBI_FUNC_SET_TIMER

#define SBI_FUNC_SET_TIMER   0

SBI_EXT_TIME function ID: set the next timer deadline.

◆ SBI_FUNC_SYSTEM_RESET

#define SBI_FUNC_SYSTEM_RESET   0

SBI_EXT_SRST function ID: reset or power off the system.

◆ SBI_SRST_RESET_REASON_NONE

#define SBI_SRST_RESET_REASON_NONE   0

SBI_EXT_SRST reset reason: no specific reason.

◆ SBI_SRST_RESET_TYPE_COLD_REBOOT

#define SBI_SRST_RESET_TYPE_COLD_REBOOT   1

SBI_EXT_SRST reset type: cold reboot.

◆ SBI_SRST_RESET_TYPE_SHUTDOWN

#define SBI_SRST_RESET_TYPE_SHUTDOWN   0

SBI_EXT_SRST reset type: clean shutdown (power off).

◆ SBI_SRST_RESET_TYPE_WARM_REBOOT

#define SBI_SRST_RESET_TYPE_WARM_REBOOT   2

SBI_EXT_SRST reset type: warm reboot.

◆ SBI_SUCCESS

#define SBI_SUCCESS   0

SBI return code: call completed successfully.

Function Documentation

◆ sbi_ecall()

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 )
inlinestatic

◆ sbi_err_to_errno()

int sbi_err_to_errno ( unsigned long err)
inlinestatic

Translate an SBI return code into a negative errno value.

Parameters
errValue taken from the error field of an SBI call's return struct (i.e. register a0).
Returns
0 on SBI_SUCCESS, otherwise a negative errno. Unknown codes are reported as -EOPNOTSUPP, since an unrecognised code most likely comes from an SBI version newer than this header.