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 <[email protected]>
---
 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;
+    }
+
     if (cc->nb_rcids == 0) {
         error_setg(errp, "max_rcids must be at least 1");
         return;
@@ -666,6 +672,8 @@ static const Property riscv_cbqri_cc_properties[] = {
                        CC_DEFAULT_MAX_RCIDS),
     DEFINE_PROP_UINT16("ncblks", RiscvCbqriCapacityState, ncblks,
                        CC_DEFAULT_NCBLKS),
+    DEFINE_PROP_UINT8("cache_level", RiscvCbqriCapacityState,
+                      cache_level, 2),
 
     DEFINE_PROP_BOOL("at_code", RiscvCbqriCapacityState,
                      supports_at_code, true),

-- 
2.43.0


Reply via email to