mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Yicong Yang" <yang.yicong@picoheart.com>
To: "Anup Patel" <anup.patel@oss.qualcomm.com>
Cc: "Sunil V L" <sunilvl@oss.qualcomm.com>,
	 "Rafael J . Wysocki" <rafael@kernel.org>,
	<yang.yicong@picoheart.com>,
	 "Palmer Dabbelt" <palmer@dabbelt.com>,
	 "Paul Walmsley" <paul.walmsley@sifive.com>,
	 "Alexandre Ghiti" <alex@ghiti.fr>, "Len Brown" <lenb@kernel.org>,
	 "Atish Patra" <atish.patra@linux.dev>,
	 "Anup Patel" <anup@brainfault.org>,
	"Will Deacon" <will@kernel.org>,
	 "Mark Rutland" <mark.rutland@arm.com>,
	<linux-acpi@vger.kernel.org>,  <linux-riscv@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>,
	 "Anup Patel" <apatel@ventanamicro.com>,
	 "Sunil V L" <sunilvl@ventanamicro.com>,
	 "Andrew Jones" <ajones@ventanamicro.com>,
	 "Atish Patra" <atishp@rivosinc.com>,
	"Nutty Liu" <nutty.liu@hotmail.com>
Subject: Re: [PATCH v7 1/1] RISC-V: Add common csr_read_num() and csr_write_num() functions
Date: Thu, 5 Nov 2026 20:52:36 +0800	[thread overview]
Message-ID: <51cb0e88-356e-4980-95a2-e4a46695ee9d@picoheart.com> (raw)
In-Reply-To: <20261104161512.883885-2-anup.patel@oss.qualcomm.com>

On 11/5/26 12:15 AM, Anup Patel wrote:
> From: Anup Patel <apatel@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@ventanamicro.com>
> Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
> Reviewed-by: Atish Patra <atishp@rivosinc.com>
> Reviewed-by: Nutty Liu <nutty.liu@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
> 
> diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h
> index 621f84d1898f..ebd82043430b 100644
> --- a/arch/riscv/include/asm/csr.h
> +++ b/arch/riscv/include/asm/csr.h
> @@ -672,6 +672,9 @@
>  			      : "memory");			\
>  })
>  
> +unsigned long csr_read_num(unsigned long csr_num, int *out_err);
> +void csr_write_num(unsigned long csr_num, unsigned long val, int *out_err);
> +
>  #endif /* __ASSEMBLER__ */
>  
>  #endif /* _ASM_RISCV_CSR_H */
> diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
> index f54c336bf547..7f52ae724225 100644
> --- a/arch/riscv/kernel/Makefile
> +++ b/arch/riscv/kernel/Makefile
> @@ -51,6 +51,7 @@ obj-y	+= soc.o
>  obj-y	+= alternative.o
>  obj-y	+= cpu.o
>  obj-y	+= cpufeature.o
> +obj-y	+= csr.o
>  obj-y	+= entry.o
>  obj-y	+= irq.o
>  obj-y	+= process.o
> diff --git a/arch/riscv/kernel/csr.c b/arch/riscv/kernel/csr.c
> new file mode 100644
> index 000000000000..e96b129c1a99
> --- /dev/null
> +++ b/arch/riscv/kernel/csr.c
> @@ -0,0 +1,165 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2025 Ventana Micro Systems Inc.
> + */
should update to 2026?

Now read of CPPC FFH counter succeed on my platform.

Tested-by: Yicong Yang <yang.yicong@picoheart.com>

Thanks.

      reply	other threads:[~2026-11-05 12:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 16:15 [PATCH v7 0/1] Common csr_read_num() and csr_write_num() for RISC-V Anup Patel
2026-11-04 16:15 ` [PATCH v7 1/1] RISC-V: Add common csr_read_num() and csr_write_num() functions Anup Patel
2026-11-05 12:52   ` Yicong Yang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51cb0e88-356e-4980-95a2-e4a46695ee9d@picoheart.com \
    --to=yang.yicong@picoheart.com \
    --cc=ajones@ventanamicro.com \
    --cc=alex@ghiti.fr \
    --cc=anup.patel@oss.qualcomm.com \
    --cc=anup@brainfault.org \
    --cc=apatel@ventanamicro.com \
    --cc=atish.patra@linux.dev \
    --cc=atishp@rivosinc.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=nutty.liu@hotmail.com \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=rafael@kernel.org \
    --cc=sunilvl@oss.qualcomm.com \
    --cc=sunilvl@ventanamicro.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®