Re: [RFC PATCH 09/18] hw/arm/xlnx-zynqmp: convert cpu clusters to arm_cpus

2022-04-16 Thread Philippe Mathieu-Daudé

On 30/3/22 14:56, Damien Hedde wrote:

qom-path of cpus are changed:
+ "apu-cluster/apu-cpu[n]" to "apu/cpu[n]"
+ "rpu-cluster/rpu-cpu[n]" to "rpu/cpu[n]"

Signed-off-by: Damien Hedde 
---
  include/hw/arm/xlnx-zynqmp.h |   8 +--
  hw/arm/xlnx-zynqmp.c | 121 +--
  2 files changed, 48 insertions(+), 81 deletions(-)



  static void xlnx_zynqmp_create_bbram(XlnxZynqMPState *s, qemu_irq *gic)
@@ -296,7 +282,8 @@ static void xlnx_zynqmp_create_apu_ctrl(XlnxZynqMPState *s, 
qemu_irq *gic)
  g_autofree gchar *name = g_strdup_printf("cpu%d", i);
  
  object_property_set_link(OBJECT(>apu_ctrl), name,

- OBJECT(>apu_cpu[i]), _abort);
+ OBJECT(arm_cpus_get_cpu(>apu, i)),
+ _abort);
  }


Possible further improvement, XlnxZynqMPAPUCtrl can now take a link to
one ArmCpusGroup, instead of array of ARMCPU.



[RFC PATCH 09/18] hw/arm/xlnx-zynqmp: convert cpu clusters to arm_cpus

2022-03-30 Thread Damien Hedde
qom-path of cpus are changed:
+ "apu-cluster/apu-cpu[n]" to "apu/cpu[n]"
+ "rpu-cluster/rpu-cpu[n]" to "rpu/cpu[n]"

Signed-off-by: Damien Hedde 
---
 include/hw/arm/xlnx-zynqmp.h |   8 +--
 hw/arm/xlnx-zynqmp.c | 121 +--
 2 files changed, 48 insertions(+), 81 deletions(-)

diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h
index 9d9a9d0bf9..1bcc3f9356 100644
--- a/include/hw/arm/xlnx-zynqmp.h
+++ b/include/hw/arm/xlnx-zynqmp.h
@@ -31,7 +31,7 @@
 #include "hw/display/xlnx_dp.h"
 #include "hw/intc/xlnx-zynqmp-ipi.h"
 #include "hw/rtc/xlnx-zynqmp-rtc.h"
-#include "hw/cpu/cluster.h"
+#include "hw/arm/arm_cpus.h"
 #include "target/arm/cpu.h"
 #include "qom/object.h"
 #include "net/can_emu.h"
@@ -94,10 +94,8 @@ struct XlnxZynqMPState {
 DeviceState parent_obj;
 
 /*< public >*/
-CPUClusterState apu_cluster;
-CPUClusterState rpu_cluster;
-ARMCPU apu_cpu[XLNX_ZYNQMP_NUM_APU_CPUS];
-ARMCPU rpu_cpu[XLNX_ZYNQMP_NUM_RPU_CPUS];
+ArmCpusState apu;
+ArmCpusState rpu;
 GICState gic;
 MemoryRegion gic_mr[XLNX_ZYNQMP_GIC_REGIONS][XLNX_ZYNQMP_GIC_ALIASES];
 
diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c
index 5bfe285a19..fa0c093733 100644
--- a/hw/arm/xlnx-zynqmp.c
+++ b/hw/arm/xlnx-zynqmp.c
@@ -25,6 +25,7 @@
 #include "sysemu/kvm.h"
 #include "sysemu/sysemu.h"
 #include "kvm_arm.h"
+#include "hw/arm/arm_cpus.h"
 
 #define GIC_NUM_SPI_INTR 160
 
@@ -201,7 +202,7 @@ static inline int arm_gic_ppi_index(int cpu_nr, int 
ppi_index)
 static void xlnx_zynqmp_create_rpu(MachineState *ms, XlnxZynqMPState *s,
const char *boot_cpu, Error **errp)
 {
-int i;
+unsigned boot_idx;
 int num_rpus = MIN(ms->smp.cpus - XLNX_ZYNQMP_NUM_APU_CPUS,
XLNX_ZYNQMP_NUM_RPU_CPUS);
 
@@ -210,36 +211,21 @@ static void xlnx_zynqmp_create_rpu(MachineState *ms, 
XlnxZynqMPState *s,
 return;
 }
 
-object_initialize_child(OBJECT(s), "rpu-cluster", >rpu_cluster,
-TYPE_CPU_CLUSTER);
-qdev_prop_set_uint32(DEVICE(>rpu_cluster), "cluster-id", 1);
-
-for (i = 0; i < num_rpus; i++) {
-const char *name;
-
-object_initialize_child(OBJECT(>rpu_cluster), "rpu-cpu[*]",
->rpu_cpu[i],
-ARM_CPU_TYPE_NAME("cortex-r5f"));
-
-name = object_get_canonical_path_component(OBJECT(>rpu_cpu[i]));
-if (strcmp(name, boot_cpu)) {
-/*
- * Secondary CPUs start in powered-down state.
- */
-object_property_set_bool(OBJECT(>rpu_cpu[i]),
- "start-powered-off", true, _abort);
-} else {
-s->boot_cpu_ptr = >rpu_cpu[i];
-}
-
-object_property_set_bool(OBJECT(>rpu_cpu[i]), "reset-hivecs", true,
- _abort);
-if (!qdev_realize(DEVICE(>rpu_cpu[i]), NULL, errp)) {
-return;
-}
+/* apus are already created, rpus will have cluster-id 1 */
+object_initialize_child(OBJECT(s), "rpu", >rpu, TYPE_ARM_CPUS);
+qdev_prop_set_uint32(DEVICE(>rpu), "num-cpus", num_rpus);
+qdev_prop_set_string(DEVICE(>rpu), "cpu-type",
+ ARM_CPU_TYPE_NAME("cortex-r5f"));
+qdev_prop_set_bit(DEVICE(>rpu), "reset-hivecs", true);
+qdev_prop_set_bit(DEVICE(>rpu), "start-powered-off", true);
+
+qdev_realize(DEVICE(>rpu), NULL, _fatal);
+
+if (sscanf(boot_cpu, "rpu-cpu[%u]", _idx) && boot_idx < num_rpus) {
+s->boot_cpu_ptr = arm_cpus_get_cpu(>rpu, boot_idx);
+object_property_set_bool(OBJECT(s->boot_cpu_ptr), "start-powered-on",
+ true, _abort);
 }
-
-qdev_realize(DEVICE(>rpu_cluster), NULL, _fatal);
 }
 
 static void xlnx_zynqmp_create_bbram(XlnxZynqMPState *s, qemu_irq *gic)
@@ -296,7 +282,8 @@ static void xlnx_zynqmp_create_apu_ctrl(XlnxZynqMPState *s, 
qemu_irq *gic)
 g_autofree gchar *name = g_strdup_printf("cpu%d", i);
 
 object_property_set_link(OBJECT(>apu_ctrl), name,
- OBJECT(>apu_cpu[i]), _abort);
+ OBJECT(arm_cpus_get_cpu(>apu, i)),
+ _abort);
 }
 
 sysbus_realize(sbd, _fatal);
@@ -349,15 +336,10 @@ static void xlnx_zynqmp_init(Object *obj)
 int i;
 int num_apus = MIN(ms->smp.cpus, XLNX_ZYNQMP_NUM_APU_CPUS);
 
-object_initialize_child(obj, "apu-cluster", >apu_cluster,
-TYPE_CPU_CLUSTER);
-qdev_prop_set_uint32(DEVICE(>apu_cluster), "cluster-id", 0);
-
-for (i = 0; i < num_apus; i++) {
-object_initialize_child(OBJECT(>apu_cluster), "apu-cpu[*]",
->apu_cpu[i],
-ARM_CPU_TYPE_NAME("cortex-a53"));
-}
+object_initialize_child(obj, "apu", >apu, TYPE_ARM_CPUS);
+