diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index 2ccf23cb..e084005d 100644 --- a/lib/sbi/sbi_pmu.c +++ b/lib/sbi/sbi_pmu.c @@ -453,6 +453,9 @@ static int pmu_ctr_start_fw(struct sbi_pmu_hart_state *phs, event_code > SBI_PMU_FW_PLATFORM) return SBI_EINVAL; + if (phs->fw_counters_started & BIT(cidx - num_hw_ctrs)) + return SBI_EALREADY_STARTED; + if (SBI_PMU_FW_PLATFORM == event_code) { if (!pmu_dev || !pmu_dev->fw_counter_write_value || @@ -623,6 +626,9 @@ static int pmu_ctr_stop_fw(struct sbi_pmu_hart_state *phs, event_code > SBI_PMU_FW_PLATFORM) return SBI_EINVAL; + if (!(phs->fw_counters_started & BIT(cidx - num_hw_ctrs))) + return SBI_EALREADY_STOPPED; + if (SBI_PMU_FW_PLATFORM == event_code && pmu_dev && pmu_dev->fw_counter_stop) { ret = pmu_dev->fw_counter_stop(phs->hartid, cidx - num_hw_ctrs);