[PATCH v7 1/1] RISC-V: Add common csr_read_num() and csr_write_num() functions
Zhanpeng Zhang
zhangzhanpeng.jasper at bytedance.com
Wed Nov 11 03:46:11 PST 2026
Hi Anup,
On 11/5/26 12:15 AM, Anup Patel wrote:
> From: Anup Patel <apatel at ventanamicro.com>
>
> In RISC-V, there is no CSR read/write instruction which takes CSR
> number via register so add common csr_read_num() and csr_write_num()
> functions which allow accessing certain CSRs by passing CSR number
> as parameter. These common functions will be first used by the
> ACPI CPPC driver and RISC-V PMU driver.
>
> Also, the RISC-V ACPI FFH specification allows arbitrary CSR number
> as CPPC register and the RISC-V SBI specification allows arbitrary
> CSR number as PMU hardware counter. This means ACPI CPPC driver and
> RISC-V PMU driver no longer need to do sanity checks on CSR number
> which are now done by the common csr_read_num() and csr_write_num()
> functions.
>
> Signed-off-by: Anup Patel <apatel at ventanamicro.com>
> Reviewed-by: Sunil V L <sunilvl at ventanamicro.com>
> Reviewed-by: Andrew Jones <ajones at ventanamicro.com>
> Reviewed-by: Atish Patra <atishp at rivosinc.com>
> Reviewed-by: Nutty Liu <nutty.liu at hotmail.com>
> ---
> arch/riscv/include/asm/csr.h | 3 +
> arch/riscv/kernel/Makefile | 1 +
> arch/riscv/kernel/csr.c | 165 +++++++++++++++++++++++++++++++++++
> drivers/acpi/riscv/cppc.c | 17 ++--
> drivers/perf/riscv_pmu.c | 54 ++----------
> 5 files changed, 184 insertions(+), 56 deletions(-)
> create mode 100644 arch/riscv/kernel/csr.c
>
> [...]
> + switch (csr_num) {
> + switchcase_csr_read_32(CSR_CYCLE);
> + switchcase_csr_read_32(CSR_CYCLEH);
Could we guard the CYCLEH cases with CONFIG_32BIT? They're RV32-only.
> [...]
Thanks,
Zhanpeng
More information about the linux-riscv
mailing list