diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-05-23 21:31:48 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-05-23 21:31:48 +0300 |
| commit | 960330c5d843d1aa96aa191fc27f72da563293ea (patch) | |
| tree | 2d7ae69d40fa76aeb4f29d3911b7fc2f9341765d /arch/riscv64/kernel/sbi.h | |
| parent | b096078c282af7233062ba242a213e6f5574cfb1 (diff) | |
| download | kmi-960330c5d843d1aa96aa191fc27f72da563293ea.tar.gz kmi-960330c5d843d1aa96aa191fc27f72da563293ea.zip | |
new include structure, make parse easier for doxy
Diffstat (limited to 'arch/riscv64/kernel/sbi.h')
| -rw-r--r-- | arch/riscv64/kernel/sbi.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/arch/riscv64/kernel/sbi.h b/arch/riscv64/kernel/sbi.h new file mode 100644 index 0000000..44eec4f --- /dev/null +++ b/arch/riscv64/kernel/sbi.h @@ -0,0 +1,57 @@ +#ifndef APOS_RISCV_SBI_H +#define APOS_RISCV_SBI_H + +/** + * @file sbi.h + * riscv64-specific OpenSBI definitions. + */ + +#include <apos/types.h> + +struct sbiret { + long error; + long value; +}; + +enum { + SBI_SUCCESS = 0, + SBI_ERR_FAILED = -1, + SBI_ERR_NOT_SUPPORTED = -2, + SBI_ERR_INVALID_PARAM = -3, + SBI_ERR_DENIED = -4, + SBI_ERR_INVALID_ADDRESS = -5, + SBI_ERR_ALREADY_AVAILABLE = -6, + SBI_ERR_ALREADY_STARTED = -7, + SBI_ERR_ALREADY_STOPEED = -8, +}; + +/* TODO: query which extensions are available */ +struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, + unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, + unsigned long arg5); + +#define EID_TIME 0x54494D45 +#define FID_SET_TIMER 0 +static inline struct sbiret sbi_set_timer(uint64_t stime_value) +{ + /* TODO: read timebase from fdt, seems to be clocks/sec for accurate + * timers */ +#if __riscv_xlen == 32 + return sbi_ecall(EID_TIME, FID_SET_TIMER, stime_value, + stime_value >> 32, 0, 0, 0, 0); +#else + return sbi_ecall(EID_TIME, FID_SET_TIMER, stime_value, 0, 0, 0, 0, 0); +#endif +} + +#define EID_SRST 0x53525354 +#define FID_RESET 0 +static inline struct sbiret sbi_system_reset(uint32_t reset_type, + uint32_t reset_reason) +{ + return sbi_ecall(EID_SRST, FID_RESET, reset_type, reset_reason, 0, 0, 0, + 0); +} + +#endif /* APOS_RISCV_SBI_H */ |
