lib: sbi: Fix sbi_pmu_exit() for systems not having MCOUNTINHIBIT csr

The sbi_pmu_exit() crashes on systems not having MCOUNTINHIBIT csr
so to fix this we check SBI_HART_HAS_MCOUNTINHIBIT feature in
sbi_pmu_exit() and do nothing if it is not available.

Fixes: 13d40f21d5 ("lib: sbi: Add PMU support")
Signed-off-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
Anup Patel
2021-07-11 14:28:19 +05:30
committed by Anup Patel
parent b88b3661d4
commit a76ac4449b

View File

@@ -583,6 +583,10 @@ void sbi_pmu_exit(struct sbi_scratch *scratch)
{ {
u32 hartid = current_hartid(); u32 hartid = current_hartid();
/* SBI PMU is not supported if mcountinhibit is not available */
if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
return;
csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8); csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8);
csr_write(CSR_MCOUNTEREN, 7); csr_write(CSR_MCOUNTEREN, 7);
pmu_reset_event_map(hartid); pmu_reset_event_map(hartid);