All of lore.kernel.org
 help / color / mirror / Atom feed
From: Drew Fustini <fustini@kernel.org>
To: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Alistair Francis" <alistair.francis@wdc.com>,
	"Sunil V L" <sunilvl@oss.qualcomm.com>,
	"Anup Patel" <anup.patel@oss.qualcomm.com>,
	"Weiwei Li" <liwei1518@gmail.com>,
	"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
	"Chao Liu" <chao.liu@processmission.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Nicolas Pitre" <npitre@baylibre.com>,
	"Kornel Dulęba" <mindal@semihalf.com>,
	"Atish Patra" <atish.patra@linux.dev>,
	"Radim Krčmář" <radim.krcmar@oss.qualcomm.com>,
	"yunhui cui" <cuiyunhui@bytedance.com>,
	"Chen Pei" <cp0613@linux.alibaba.com>,
	guo.wenjia23@zte.com.cn, liu.qingtao2@zte.com.cn,
	"Jinjie Ruan" <ruanjinjie@huawei.com>,
	"Jinjie Ruan" <2118537295@qq.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Ani Sinha" <anisinha@redhat.com>,
	"Vasudevan Srinivasan" <vasu@rivosinc.com>
Subject: Re: [PATCH v2 1/2] hw/riscv: add cache_level and node properties to CBQRI controllers
Date: Mon, 23 Nov 2026 11:19:34 -0800	[thread overview]
Message-ID: <awSRxt903KEHUHYQ@thelio> (raw)
In-Reply-To: <51e50192-328b-4780-aea1-06dbd89be222@oss.qualcomm.com>

On Mon, Nov 23, 2026 at 11:03:15AM -0300, Daniel Henrique Barboza wrote:
> 
> 
> On 11/13/2026 8:12 PM, Drew Fustini wrote:
> > The ACPI RQSC table specifies which cache a capacity controller backs
> > and which proximity domain a bandwidth controller serves.
> > 
> > Add a cache_level property to the capacity controller. It accepts 2 or
> > 3, the unified cache levels that the smp-cache option can place and the
> > PPTT can describe, and defaults to 2. Add a node property to the
> > bandwidth controller. It defaults to 0 and rejects a node the machine
> > does not have.
> > 
> > Signed-off-by: Drew Fustini <fustini@kernel.org>
> > ---
> >   hw/riscv/cbqri_bandwidth.c | 13 +++++++++++++
> >   hw/riscv/cbqri_capacity.c  |  8 ++++++++
> >   2 files changed, 21 insertions(+)
> > 
> > diff --git a/hw/riscv/cbqri_bandwidth.c b/hw/riscv/cbqri_bandwidth.c
> > index bd8cf2b50e4c..6c33d1738d27 100644
> > --- a/hw/riscv/cbqri_bandwidth.c
> > +++ b/hw/riscv/cbqri_bandwidth.c
> > @@ -17,7 +17,9 @@
> >   #include "hw/core/sysbus.h"
> >   #include "migration/vmstate.h"
> >   #include "target/riscv/cpu.h"
> > +#include "hw/core/boards.h"
> >   #include "hw/riscv/cbqri.h"
> > +#include "system/numa.h"
> >   /* Property defaults, shared with riscv_cbqri_bc_caps_init() */
> >   #define BC_DEFAULT_MAX_MCIDS    256
> > @@ -139,6 +141,7 @@ typedef struct RiscvCbqriBandwidthState {
> >       uint16_t nbwblks;
> >       uint16_t mrbwb;
> > +    uint32_t node;
> >       bool supports_at_code;
> > @@ -542,12 +545,21 @@ static const MemoryRegionOps riscv_cbqri_bc_ops = {
> >   static void riscv_cbqri_bc_realize(DeviceState *dev, Error **errp)
> >   {
> >       RiscvCbqriBandwidthState *bc = RISCV_CBQRI_BC(dev);
> > +    MachineState *ms = MACHINE(qdev_get_machine());
> > +    unsigned int nb_nodes = ms->numa_state ? ms->numa_state->num_nodes : 0;
> >       if (!bc->mmio_base) {
> >           error_setg(errp, "mmio_base property not set");
> >           return;
> >       }
> > +    /* Without -numa there is a single implicit node 0. */
> > +    if (bc->node >= MAX(nb_nodes, 1)) {
> > +        error_setg(errp, "node %u out of range, %u NUMA node(s)",
> > +                   bc->node, MAX(nb_nodes, 1));
> > +        return;
> > +    }
> > +
> >       if (bc->nb_rcids == 0) {
> >           error_setg(errp, "max_rcids must be at least 1");
> >           return;
> > @@ -638,6 +650,7 @@ static const Property riscv_cbqri_bc_properties[] = {
> >                          BC_DEFAULT_NBWBLKS),
> >       DEFINE_PROP_UINT16("mrbwb", RiscvCbqriBandwidthState, mrbwb,
> >                          BC_DEFAULT_MRBWB),
> > +    DEFINE_PROP_UINT32("node", RiscvCbqriBandwidthState, node, 0),
> >       DEFINE_PROP_BOOL("at_code", RiscvCbqriBandwidthState,
> >                        supports_at_code, true),
> > diff --git a/hw/riscv/cbqri_capacity.c b/hw/riscv/cbqri_capacity.c
> > index 0c572aa8b02f..1585cad1d073 100644
> > --- a/hw/riscv/cbqri_capacity.c
> > +++ b/hw/riscv/cbqri_capacity.c
> > @@ -127,6 +127,7 @@ typedef struct RiscvCbqriCapacityState {
> >       uint16_t nb_rcids;
> >       uint16_t ncblks;
> > +    uint8_t cache_level;
> >       bool supports_at_code;
> > @@ -591,6 +592,11 @@ static void riscv_cbqri_cc_realize(DeviceState *dev, Error **errp)
> >           return;
> >       }
> > +    if (cc->cache_level != 2 && cc->cache_level != 3) {
> > +        error_setg(errp, "cache_level must be 2 or 3");
> > +        return;
> > +    }
> > +
> 
> For this kind of property that has a very specific and restrictive value range (i.e.
> we'll abort if we don't get what we want), I suggest not using DEFINE_PROP_UINT8()
> to declare the prop in the array.
> 
> What we do in target/riscv/cpu.c in for 'num-pmp-regions':
> 
> 
> static void prop_num_pmp_regions_set(Object *obj, Visitor *v, const char *name,
>                                      void *opaque, Error **errp)
> {
>     RISCVCPU *cpu = RISCV_CPU(obj);
>     uint8_t value;
> 
>     visit_type_uint8(v, name, &value, errp);
> 
>     (... a bunch of checks ....)
> }
> 
> static void prop_num_pmp_regions_get(Object *obj, Visitor *v, const char *name,
>                                      void *opaque, Error **errp)
> {
>     uint8_t value = RISCV_CPU(obj)->cfg.pmp_regions;
> 
>     visit_type_uint8(v, name, &value, errp);
> }
> 
> static const PropertyInfo prop_num_pmp_regions = {
>     .type = "uint8",
>     .qapi_type = &uint8_type_info,
>     .description = "num-pmp-regions",
>     .get = prop_num_pmp_regions_get,
>     .set = prop_num_pmp_regions_set,
> };
> 
> 
> And this is added in a property array like this:
> 
> {.name = "num-pmp-regions", .info = &prop_num_pmp_regions},
> 
> 
> This is more verbose but it will make realize() easier since the property
> is guaranteed to be valid. 'cache_level' seems like a good candidate for
> this kind of pattern.

That makes sense. I'll change cache_level to a custom PropertyInfo and
remove the check from realize.

Drew


  reply	other threads:[~2026-11-23 19:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 23:12 [PATCH v2 0/2] RISC-V: Add support for ACPI RQSC table Drew Fustini
2026-11-13 23:12 ` [PATCH v2 1/2] hw/riscv: add cache_level and node properties to CBQRI controllers Drew Fustini
2026-11-23 14:03   ` Daniel Henrique Barboza
2026-11-23 19:19     ` Drew Fustini [this message]
2026-11-13 23:12 ` [PATCH v2 2/2] hw/riscv: add support for ACPI RQSC table Drew Fustini
2026-11-23 14:15   ` Daniel Henrique Barboza
2026-11-23 19:01     ` Drew Fustini

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=awSRxt903KEHUHYQ@thelio \
    --to=fustini@kernel.org \
    --cc=2118537295@qq.com \
    --cc=alistair.francis@wdc.com \
    --cc=anisinha@redhat.com \
    --cc=anup.patel@oss.qualcomm.com \
    --cc=atish.patra@linux.dev \
    --cc=chao.liu@processmission.com \
    --cc=cp0613@linux.alibaba.com \
    --cc=cuiyunhui@bytedance.com \
    --cc=daniel.barboza@oss.qualcomm.com \
    --cc=guo.wenjia23@zte.com.cn \
    --cc=imammedo@redhat.com \
    --cc=liu.qingtao2@zte.com.cn \
    --cc=liwei1518@gmail.com \
    --cc=mindal@semihalf.com \
    --cc=mst@redhat.com \
    --cc=npitre@baylibre.com \
    --cc=palmer@dabbelt.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=radim.krcmar@oss.qualcomm.com \
    --cc=ruanjinjie@huawei.com \
    --cc=sunilvl@oss.qualcomm.com \
    --cc=vasu@rivosinc.com \
    --cc=zhiwei_liu@linux.alibaba.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.