[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 04/18] hw/cpu/cluster: make _cpu-cluster_ a subclass of _cpus
From: |
Damien Hedde |
Subject: |
[RFC PATCH 04/18] hw/cpu/cluster: make _cpu-cluster_ a subclass of _cpus_ |
Date: |
Wed, 30 Mar 2022 14:56:25 +0200 |
Drop the cluster-id property as base class defines one.
cluster_id field is temporarily kept until gdbstub
is updated.
Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
---
include/hw/cpu/cluster.h | 17 ++++++++++--
hw/cpu/cluster.c | 58 +++++++++++++++++++++-------------------
2 files changed, 46 insertions(+), 29 deletions(-)
diff --git a/include/hw/cpu/cluster.h b/include/hw/cpu/cluster.h
index 09a2b86832..2125765f21 100644
--- a/include/hw/cpu/cluster.h
+++ b/include/hw/cpu/cluster.h
@@ -22,6 +22,7 @@
#include "hw/qdev-core.h"
#include "qom/object.h"
+#include "hw/cpu/cpus.h"
/*
* CPU Cluster type
@@ -55,7 +56,7 @@
*/
#define TYPE_CPU_CLUSTER "cpu-cluster"
-OBJECT_DECLARE_SIMPLE_TYPE(CPUClusterState, CPU_CLUSTER)
+OBJECT_DECLARE_TYPE(CPUClusterState, CPUClusterClass, CPU_CLUSTER)
/**
* CPUClusterState:
@@ -66,10 +67,22 @@ OBJECT_DECLARE_SIMPLE_TYPE(CPUClusterState, CPU_CLUSTER)
*/
struct CPUClusterState {
/*< private >*/
- DeviceState parent_obj;
+ CpusState parent_obj;
/*< public >*/
uint32_t cluster_id;
};
+/**
+ * CPUClusterClass:
+ * @parent_realize: to store base class realize method
+ */
+struct CPUClusterClass {
+ /*< private >*/
+ CpusClass parent_class;
+
+ /*< public >*/
+ DeviceRealize parent_realize;
+};
+
#endif
diff --git a/hw/cpu/cluster.c b/hw/cpu/cluster.c
index e444b7c29d..3daf897bd9 100644
--- a/hw/cpu/cluster.c
+++ b/hw/cpu/cluster.c
@@ -20,50 +20,39 @@
#include "qemu/osdep.h"
#include "hw/cpu/cluster.h"
+#include "hw/cpu/cpus.h"
#include "hw/qdev-properties.h"
#include "hw/core/cpu.h"
#include "qapi/error.h"
#include "qemu/module.h"
#include "qemu/cutils.h"
-static Property cpu_cluster_properties[] = {
- DEFINE_PROP_UINT32("cluster-id", CPUClusterState, cluster_id, 0),
- DEFINE_PROP_END_OF_LIST()
-};
-
-typedef struct CallbackData {
- CPUClusterState *cluster;
- int cpu_count;
-} CallbackData;
-
static int add_cpu_to_cluster(Object *obj, void *opaque)
{
- CallbackData *cbdata = opaque;
+ CpusState *base = CPUS(opaque);
CPUState *cpu = (CPUState *)object_dynamic_cast(obj, TYPE_CPU);
if (cpu) {
- cpu->cluster_index = cbdata->cluster->cluster_id;
- cbdata->cpu_count++;
+ cpu->cluster_index = base->cluster_index;
+ base->topology.cpus++;
}
return 0;
}
static void cpu_cluster_realize(DeviceState *dev, Error **errp)
{
- /* Iterate through all our CPU children and set their cluster_index */
+ CPUClusterClass *ccc = CPU_CLUSTER_GET_CLASS(dev);
CPUClusterState *cluster = CPU_CLUSTER(dev);
+ CpusState *base = CPUS(dev);
Object *cluster_obj = OBJECT(dev);
- CallbackData cbdata = {
- .cluster = cluster,
- .cpu_count = 0,
- };
- if (cluster->cluster_id >= MAX_CLUSTERS) {
- error_setg(errp, "cluster-id must be less than %d", MAX_CLUSTERS);
- return;
- }
+ /* This is a special legacy case */
+ assert(base->topology.cpus == 0);
+ assert(base->cpu_type == NULL);
+ assert(base->is_cluster);
- object_child_foreach_recursive(cluster_obj, add_cpu_to_cluster, &cbdata);
+ /* Iterate through all our CPU children and set their cluster_index */
+ object_child_foreach_recursive(cluster_obj, add_cpu_to_cluster, base);
/*
* A cluster with no CPUs is a bug in the board/SoC code that created it;
@@ -71,24 +60,39 @@ static void cpu_cluster_realize(DeviceState *dev, Error
**errp)
* created the CPUs and parented them into the cluster object before
* realizing the cluster object.
*/
- assert(cbdata.cpu_count > 0);
+ assert(base->topology.cpus > 0);
+
+ /* realize base class (will set cluster field to true) */
+ ccc->parent_realize(dev, errp);
+
+ /*
+ * Temporarily copy the cluster id from the base class as
+ * gdbstub still uses our field.
+ */
+ cluster->cluster_id = base->cluster_index;
}
static void cpu_cluster_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
+ CPUClusterClass *ccc = CPU_CLUSTER_CLASS(klass);
+ CpusClass *cc = CPUS_CLASS(klass);
- device_class_set_props(dc, cpu_cluster_properties);
- dc->realize = cpu_cluster_realize;
+ device_class_set_parent_realize(dc, cpu_cluster_realize,
+ &ccc->parent_realize);
/* This is not directly for users, CPU children must be attached by code */
dc->user_creatable = false;
+
+ /* Cpus are created by external code */
+ cc->skip_cpus_creation = true;
}
static const TypeInfo cpu_cluster_type_info = {
.name = TYPE_CPU_CLUSTER,
- .parent = TYPE_DEVICE,
+ .parent = TYPE_CPUS,
.instance_size = sizeof(CPUClusterState),
+ .class_size = sizeof(CPUClusterClass),
.class_init = cpu_cluster_class_init,
};
--
2.35.1
- [RFC PATCH 00/18] user-creatable cpu clusters, Damien Hedde, 2022/03/30
- [RFC PATCH 01/18] define MAX_CLUSTERS in cpu.h instead of cluster.h, Damien Hedde, 2022/03/30
- [RFC PATCH 03/18] hw/cpu/cpus: prepare to handle cpu clusters, Damien Hedde, 2022/03/30
- [RFC PATCH 02/18] hw/cpu/cpus: introduce _cpus_ device, Damien Hedde, 2022/03/30
- [RFC PATCH 04/18] hw/cpu/cluster: make _cpu-cluster_ a subclass of _cpus_,
Damien Hedde <=
- [RFC PATCH 05/18] gdbstub: deal with _cpus_ object instead of _cpu-cluster_, Damien Hedde, 2022/03/30
- [RFC PATCH 06/18] hw/cpu/cluster: remove cluster_id now that gdbstub is updated, Damien Hedde, 2022/03/30
- [RFC PATCH 09/18] hw/arm/xlnx-zynqmp: convert cpu clusters to arm_cpus, Damien Hedde, 2022/03/30
- [RFC PATCH 08/18] hw/arm/arm_cpus: add arm_cpus device, Damien Hedde, 2022/03/30
- [RFC PATCH 07/18] hw/cpu/cpus: add a common start-powered-off property, Damien Hedde, 2022/03/30
- [RFC PATCH 11/18] hw/riscv: prepare riscv_hart transition to cpus, Damien Hedde, 2022/03/30
- [RFC PATCH 13/18] hw/riscv/spike: prepare riscv_hart transition to cpus, Damien Hedde, 2022/03/30
- [RFC PATCH 10/18] hw/riscv/riscv_hart: prepare transition to cpus, Damien Hedde, 2022/03/30
- [RFC PATCH 15/18] hw/riscv/sifive_uµchip_pfsoc: apply riscv_hart_array update, Damien Hedde, 2022/03/30
- [RFC PATCH 17/18] hw/riscv/riscv_hart: remove temporary features, Damien Hedde, 2022/03/30