aboutsummaryrefslogtreecommitdiff
path: root/lib/sbi/sbi_hart.c
diff options
context:
space:
mode:
authorAtish Patra <atish.patra@wdc.com>2021-11-08 10:53:01 -0800
committerAnup Patel <anup@brainfault.org>2021-11-11 17:47:52 +0530
commit2363f950bcc497d8bd42654d32d05522fd24b9d7 (patch)
treef85660fbd4a4c6ed04cb93a70b7fbc889641da84 /lib/sbi/sbi_hart.c
parent730f01bb41a603cf03d2cfd9c27317389962ffee (diff)
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>
Diffstat (limited to 'lib/sbi/sbi_hart.c')
-rw-r--r--lib/sbi/sbi_hart.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index 8a98d4d..a4e9bf5 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -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))