mirror of
https://github.com/Fishwaldo/opensbi.git
synced 2025-07-06 04:59:00 +00:00
lib: sbi: Detect mcountinihibit support at runtime
RISC-V ISA specification v1.11 defined mcountinhibit CSR that allows software to stop any counter from incrementing. The SBI PMU extension depends on this CSR support in hardware. Define mcountinhibit as a hart specific feature and detect it at runtime. Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
parent
3e8b31aca9
commit
fde28fadc2
2 changed files with 14 additions and 1 deletions
|
@ -18,8 +18,10 @@ enum sbi_hart_features {
|
|||
SBI_HART_HAS_SCOUNTEREN = (1 << 0),
|
||||
/** Hart has M-mode counter enable */
|
||||
SBI_HART_HAS_MCOUNTEREN = (1 << 1),
|
||||
/** Hart has counter inhibit CSR */
|
||||
SBI_HART_HAS_MCOUNTINHIBIT = (1 << 2),
|
||||
/** HART has timer csr implementation in hardware */
|
||||
SBI_HART_HAS_TIME = (1 << 2),
|
||||
SBI_HART_HAS_TIME = (1 << 3),
|
||||
|
||||
/** Last index of Hart features*/
|
||||
SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_TIME,
|
||||
|
|
|
@ -259,6 +259,9 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature)
|
|||
case SBI_HART_HAS_MCOUNTEREN:
|
||||
fstr = "mcounteren";
|
||||
break;
|
||||
case SBI_HART_HAS_MCOUNTINHIBIT:
|
||||
fstr = "mcountinhibit";
|
||||
break;
|
||||
case SBI_HART_HAS_TIME:
|
||||
fstr = "time";
|
||||
break;
|
||||
|
@ -421,6 +424,14 @@ __mhpm_skip:
|
|||
hfeatures->features |= SBI_HART_HAS_MCOUNTEREN;
|
||||
}
|
||||
|
||||
/* Detect if hart supports MCOUNTINHIBIT feature */
|
||||
val = csr_read_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap);
|
||||
if (!trap.cause) {
|
||||
csr_write_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap, val);
|
||||
if (!trap.cause)
|
||||
hfeatures->features |= SBI_HART_HAS_MCOUNTINHIBIT;
|
||||
}
|
||||
|
||||
/* Detect if hart supports time CSR */
|
||||
csr_read_allowed(CSR_TIME, (unsigned long)&trap);
|
||||
if (!trap.cause)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue