lib: sbi_pmu: Add FW counter index validation when reading high bits on RV64

Currently, when we attempt to read the upper 32 bits of a firmware
counter on RV64 or higher, we just set `sbiret.value` to 0 without
validating the counter index. The SBI specification requires us to set
`sbiret.error` to `SBI_ERR_INVALID_PARAM` if the counter index points to
a hardware counter or an invalid counter. Add a validation check to
ensure compliance with the specification on RV64 or higher.

Fixes: 51951d9e9a ("lib: sbi_pmu: Implement sbi_pmu_counter_fw_read_hi")
Signed-off-by: James Raphael Tiovalen <jamestiotio@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260125090643.190748-1-jamestiotio@gmail.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
James Raphael Tiovalen
2026-01-25 17:06:43 +08:00
committed by Anup Patel
parent a95c36f165
commit 9656943bd3
3 changed files with 12 additions and 4 deletions

View File

@@ -50,12 +50,12 @@ static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid,
break;
case SBI_EXT_PMU_COUNTER_FW_READ:
ret = sbi_pmu_ctr_fw_read(regs->a0, &temp);
ret = sbi_pmu_ctr_fw_read(regs->a0, &temp, false);
out->value = temp;
break;
case SBI_EXT_PMU_COUNTER_FW_READ_HI:
ret = sbi_pmu_ctr_fw_read(regs->a0, &temp, true);
#if __riscv_xlen == 32
ret = sbi_pmu_ctr_fw_read(regs->a0, &temp);
out->value = temp >> 32;
#else
out->value = 0;