Skip to content

Commit

Permalink
[arch][riscv] add SSTC extension support
Browse files Browse the repository at this point in the history
Pretty simple extension, just directly set the supervisor timer compare
register (new) instead of calling through to SBI to set it for you.
  • Loading branch information
travisg committed Jun 2, 2024
1 parent b9c3603 commit c4effae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions arch/riscv/include/arch/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@

#if RISCV_S_MODE // Supervisor-mode only CSRs
#define RISCV_CSR_SATP satp
// sstc feature
#define RISCV_CSR_STIMECMP stimecmp
#define RISCV_CSR_STIMECMPH stimecmph
#endif

#define RISCV_CSR_XSTATUS_IE (1ul << (RISCV_XMODE_OFFSET + 0))
Expand Down
13 changes: 12 additions & 1 deletion arch/riscv/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <lk/err.h>
#include <lk/trace.h>

#include <arch/riscv/feature.h>

#include <arch/riscv.h>
#include <arch/ops.h>

Expand Down Expand Up @@ -39,7 +41,16 @@ status_t platform_set_oneshot_timer (platform_timer_callback callback, void *arg
#if RISCV_M_MODE
clint_set_timer(ticks);
#elif RISCV_S_MODE
sbi_set_timer(ticks);
if (riscv_feature_test(RISCV_FEAT_SSTC)) {
#if __riscv_xlen == 64
riscv_csr_write(RISCV_CSR_STIMECMP, ticks);
#else
riscv_csr_write(RISCV_CSR_STIMECMPH, ticks >> 32);
riscv_csr_write(RISCV_CSR_STIMECMP, ticks);
#endif
} else {
sbi_set_timer(ticks);
}
#endif

return NO_ERROR;
Expand Down

0 comments on commit c4effae

Please sign in to comment.