lib: sbi: Always enable access for all counters

OpenSBI doesn't use any counters for its own usage. Thus, all the counters
can be made accessible for lower privilege mode always. However, the
mcountinhibit must be set so that the counter doesn't increment.
As a result, we don't have to enable/disable mcounteren at every start/stop.

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
Atish Patra authored and Anup Patel committed 2021-11-11 17:47:52 +05:30
1 parent 730f01bb41
commit 2363f950bc
2 files changed
+11 -26

No files matched your search

+7 -14
View File
@@ -56,20 +56,13 @@ static void mstatus_init(struct sbi_scratch *scratch)
sbi_hart_has_feature(scratch, SBI_HART_HAS_SCOUNTEREN))
csr_write(CSR_SCOUNTEREN, 7);
if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTEREN)) {
if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
/**
* Just enable the default counters (CY, TM, IR) because
* some OS (e.g FreeBSD) expect them to be enabled.
*
* All other counters will be enabled at runtime after
* S-mode request.
*/
csr_write(CSR_MCOUNTEREN, 7);
else
/* Supervisor mode usage are enabled by default */
csr_write(CSR_MCOUNTEREN, -1);
}
/**
* OpenSBI doesn't use any PMU counters in M-mode.
* Supervisor mode usage for all counters are enabled by default
* But counters will not run until mcountinhibit is set.
*/
if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTEREN))
csr_write(CSR_MCOUNTEREN, -1);
/* All programmable counters will start running at runtime after S-mode request */
if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))