Skip to content

Commit

Permalink
MdePkg/BaseLib: RISC-V: Add function to update stimecmp register
Browse files Browse the repository at this point in the history
stimecmp is a CSR supported only when Sstc extension is supported by the
platform. This register can be used to set the timer interrupt directly in
S-mode instead of going via SBI call. Add a function to update this
register.

Cc: Michael D Kinney <[email protected]>
Cc: Liming Gao <[email protected]>
Cc: Zhiguang Liu <[email protected]>
Cc: Andrei Warkentin <[email protected]>
Signed-off-by: Sunil V L <[email protected]>
Reviewed-by: Andrei Warkentin <[email protected]>
  • Loading branch information
vlsunil authored and mergify[bot] committed Jan 11, 2024
1 parent fd629ef commit 8ae17a7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions MdePkg/Include/Library/BaseLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ RiscVReadTimer (
VOID
);

VOID
RiscVSetSupervisorTimeCompareRegister (
IN UINT64
);

VOID
RiscVEnableTimerInterrupt (
VOID
Expand Down
3 changes: 3 additions & 0 deletions MdePkg/Include/Register/RiscV64/RiscVEncoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
/* Supervisor Protection and Translation */
#define CSR_SATP 0x180

/* Sstc extension */
#define CSR_STIMECMP 0x14D

/* Trap/Exception Causes */
#define CAUSE_MISALIGNED_FETCH 0x0
#define CAUSE_FETCH_ACCESS 0x1
Expand Down
7 changes: 7 additions & 0 deletions MdePkg/Library/BaseLib/RiscV64/ReadTimer.S
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@
ASM_FUNC (RiscVReadTimer)
csrr a0, CSR_TIME
ret

//
// Set Supervisor Time Compare Register
//
ASM_FUNC (RiscVSetSupervisorTimeCompareRegister)
csrw CSR_STIMECMP, a0
ret

0 comments on commit 8ae17a7

Please sign in to comment.