lib: sbi: Detect Sscofpmf extension at run time

Sscofpmf ISA extension introduces PMU counter overflow and filtering support.
It introduces a read only `scountovf` csr that can be used to detect if
a hart supports this extension at runtime. However, this feature is only
useful if the hart already supports mcounteren and mcountinhibit.

Add a dynamic detection mechanism and boot time print message if sscofpmf
is present.

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
Atish Patra 2021-11-08 10:52:58 -08:00 committed by Anup Patel
parent 7084ad9f42
commit 867c65360d
2 changed files with 15 additions and 1 deletions

View File

@ -20,8 +20,10 @@ enum sbi_hart_features {
SBI_HART_HAS_MCOUNTEREN = (1 << 1), SBI_HART_HAS_MCOUNTEREN = (1 << 1),
/** Hart has counter inhibit CSR */ /** Hart has counter inhibit CSR */
SBI_HART_HAS_MCOUNTINHIBIT = (1 << 2), SBI_HART_HAS_MCOUNTINHIBIT = (1 << 2),
/** Hart has sscofpmf extension */
SBI_HART_HAS_SSCOFPMF = (1 << 3),
/** HART has timer csr implementation in hardware */ /** HART has timer csr implementation in hardware */
SBI_HART_HAS_TIME = (1 << 3), SBI_HART_HAS_TIME = (1 << 4),
/** Last index of Hart features*/ /** Last index of Hart features*/
SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_TIME, SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_TIME,

View File

@ -281,6 +281,9 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature)
case SBI_HART_HAS_MCOUNTINHIBIT: case SBI_HART_HAS_MCOUNTINHIBIT:
fstr = "mcountinhibit"; fstr = "mcountinhibit";
break; break;
case SBI_HART_HAS_SSCOFPMF:
fstr = "sscofpmf";
break;
case SBI_HART_HAS_TIME: case SBI_HART_HAS_TIME:
fstr = "time"; fstr = "time";
break; break;
@ -490,6 +493,15 @@ __mhpm_skip:
hfeatures->features |= SBI_HART_HAS_MCOUNTINHIBIT; hfeatures->features |= SBI_HART_HAS_MCOUNTINHIBIT;
} }
/* Counter overflow/filtering is not useful without mcounter/inhibit */
if (hfeatures->features & SBI_HART_HAS_MCOUNTINHIBIT &&
hfeatures->features & SBI_HART_HAS_MCOUNTEREN) {
/* Detect if hart supports sscofpmf */
csr_read_allowed(CSR_SCOUNTOVF, (unsigned long)&trap);
if (!trap.cause)
hfeatures->features |= SBI_HART_HAS_SSCOFPMF;
}
/* Detect if hart supports time CSR */ /* Detect if hart supports time CSR */
csr_read_allowed(CSR_TIME, (unsigned long)&trap); csr_read_allowed(CSR_TIME, (unsigned long)&trap);
if (!trap.cause) if (!trap.cause)