diff options
| author | James Raphael Tiovalen <jamestiotio@gmail.com> | 2025-12-13 18:41:46 +0800 |
|---|---|---|
| committer | Anup Patel <anup@brainfault.org> | 2025-12-27 11:04:43 +0530 |
| commit | f7b81034aa4c19199afac6be4e033270f3755bf5 (patch) | |
| tree | 6385207c00ba167953020b35312283ebe9f3ad15 | |
| parent | 19f0c8351213466cce5c15fdfe35749362fe3469 (diff) | |
| download | opensbi-f7b81034aa4c19199afac6be4e033270f3755bf5.zip opensbi-f7b81034aa4c19199afac6be4e033270f3755bf5.tar.gz opensbi-f7b81034aa4c19199afac6be4e033270f3755bf5.tar.bz2 | |
lib: sbi_pmu: Fix multiple start and stop operations of FW counters
Currently, OpenSBI returns SBI_ERR_ALREADY_STARTED when attempting to
start a HW counter that is already started and SBI_ERR_ALREADY_STOPPED
when attempting to stop a HW counter that is already stopped. However,
this is not yet implemented for FW counters.
Add the necessary checks to return the same error codes when attempting
the same actions on FW counters.
Signed-off-by: James Raphael Tiovalen <jamestiotio@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20251213104146.422972-1-jamestiotio@gmail.com
Signed-off-by: Anup Patel <anup@brainfault.org>
| -rw-r--r-- | lib/sbi/sbi_pmu.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index 2ccf23c..e084005 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); |
