diff mbox series

[RFC,08/40] target/arm: Pass ARMCPUClass to ARMCPUInfo.class_init

Message ID 20230103181646.55711-9-richard.henderson@linaro.org
State New
Headers show
Series Toward class init of cpu features | expand

Commit Message

Richard Henderson Jan. 3, 2023, 6:16 p.m. UTC
Streamline new instances of this hook, so that we always go
through arm_cpu_leaf_class_init first, performing common tasks,
and have resolved the ARMCPUClass.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/cpu-qom.h |  2 +-
 target/arm/cpu.c     | 10 +++++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

Comments

Philippe Mathieu-Daudé Jan. 5, 2023, 10 p.m. UTC | #1
On 3/1/23 19:16, Richard Henderson wrote:
> Streamline new instances of this hook, so that we always go
> through arm_cpu_leaf_class_init first, performing common tasks,
> and have resolved the ARMCPUClass.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   target/arm/cpu-qom.h |  2 +-
>   target/arm/cpu.c     | 10 +++++++---
>   2 files changed, 8 insertions(+), 4 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff mbox series

Patch

diff --git a/target/arm/cpu-qom.h b/target/arm/cpu-qom.h
index ae31289582..057978b9db 100644
--- a/target/arm/cpu-qom.h
+++ b/target/arm/cpu-qom.h
@@ -36,7 +36,7 @@  OBJECT_DECLARE_CPU_TYPE(ARMCPU, ARMCPUClass, ARM_CPU)
 typedef struct ARMCPUInfo {
     const char *name;
     void (*initfn)(Object *obj);
-    void (*class_init)(ObjectClass *oc, void *data);
+    void (*class_init)(ARMCPUClass *acc);
 } ARMCPUInfo;
 
 void arm_cpu_register_parent(const ARMCPUInfo *info, const char *parent);
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index a2f59ac378..b16d9bbe47 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -2253,11 +2253,15 @@  static void arm_cpu_instance_init(Object *obj)
     arm_cpu_post_init(obj);
 }
 
-static void cpu_register_class_init(ObjectClass *oc, void *data)
+static void arm_cpu_leaf_class_init(ObjectClass *oc, void *data)
 {
     ARMCPUClass *acc = ARM_CPU_CLASS(oc);
+    const ARMCPUInfo *info = data;
 
-    acc->info = data;
+    acc->info = info;
+    if (info->class_init) {
+        info->class_init(acc);
+    }
 }
 
 void arm_cpu_register_parent(const ARMCPUInfo *info, const char *parent)
@@ -2268,7 +2272,7 @@  void arm_cpu_register_parent(const ARMCPUInfo *info, const char *parent)
         .instance_align = __alignof__(ARMCPU),
         .instance_init = arm_cpu_instance_init,
         .class_size = sizeof(ARMCPUClass),
-        .class_init = info->class_init ?: cpu_register_class_init,
+        .class_init = arm_cpu_leaf_class_init,
         .class_data = (void *)info,
     };