Patchwork [v2,3/5] target-ppc: QOM'ify CPU init

login
register
mail settings
Submitter Andreas Färber
Date April 6, 2012, 4:17 p.m.
Message ID <1333729032-24441-5-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/151211/
State New
Headers show

Comments

Andreas Färber - April 6, 2012, 4:17 p.m.
Move code from cpu_ppc_init() into an initfn.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 target-ppc/helper.c         |   10 +---------
 target-ppc/translate_init.c |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 9 deletions(-)
David Gibson - April 11, 2012, 1:01 a.m.
On Fri, Apr 06, 2012 at 06:17:10PM +0200, Andreas Färber wrote:
> Move code from cpu_ppc_init() into an initfn.
> 
> Signed-off-by: Andreas Färber <afaerber@suse.de>

This will conflict with my patch which factors out the fiddling with
the thread numbers into a hook function.  Were you planning to update
that, or will I need to?

Otherwise,

Acked-by: David Gibson <david@gibson.dropbear.id.au>
Andreas Färber - April 11, 2012, 10:15 a.m.
Am 11.04.2012 03:01, schrieb David Gibson:
> On Fri, Apr 06, 2012 at 06:17:10PM +0200, Andreas Färber wrote:
>> Move code from cpu_ppc_init() into an initfn.
>>
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
> 
> This will conflict with my patch which factors out the fiddling with
> the thread numbers into a hook function.  Were you planning to update
> that, or will I need to?

Yeah, I've noticed that and therefore not applied it yet. I'm still
thinking about how to best resolve the conflict...

> Otherwise,
> 
> Acked-by: David Gibson <david@gibson.dropbear.id.au>

Thanks,
Andreas

Patch

diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index fa9494b..f2994ca 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -3196,19 +3196,11 @@  CPUPPCState *cpu_ppc_init (const char *cpu_model)
 
     cpu = POWERPC_CPU(object_new(TYPE_POWERPC_CPU));
     env = &cpu->env;
-    cpu_exec_init(env);
+
     if (tcg_enabled()) {
         ppc_translate_init();
     }
-    /* Adjust cpu index for SMT */
-#if !defined(CONFIG_USER_ONLY)
-    if (kvm_enabled()) {
-        int smt = kvmppc_smt_threads();
 
-        env->cpu_index = (env->cpu_index / smp_threads)*smt
-            + (env->cpu_index % smp_threads);
-    }
-#endif /* !CONFIG_USER_ONLY */
     env->cpu_model_str = cpu_model;
     cpu_ppc_register_internal(env, def);
 
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index 24817ef..860a226 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -25,6 +25,7 @@ 
 
 #include "dis-asm.h"
 #include "gdbstub.h"
+#include "cpus.h"
 #include <kvm.h>
 #include "kvm_ppc.h"
 
@@ -10198,6 +10199,24 @@  static void ppc_cpu_reset(CPUState *s)
     cpu_state_reset(env);
 }
 
+static void ppc_cpu_initfn(Object *obj)
+{
+    PowerPCCPU *cpu = POWERPC_CPU(obj);
+    CPUPPCState *env = &cpu->env;
+
+    cpu_exec_init(env);
+
+    /* Adjust cpu index for SMT */
+#if !defined(CONFIG_USER_ONLY)
+    if (kvm_enabled()) {
+        int smt = kvmppc_smt_threads();
+
+        env->cpu_index = (env->cpu_index / smp_threads) * smt
+            + (env->cpu_index % smp_threads);
+    }
+#endif /* !CONFIG_USER_ONLY */
+}
+
 static void ppc_cpu_class_init(ObjectClass *oc, void *data)
 {
     PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc);
@@ -10211,6 +10230,7 @@  static const TypeInfo ppc_cpu_type_info = {
     .name = TYPE_POWERPC_CPU,
     .parent = TYPE_CPU,
     .instance_size = sizeof(PowerPCCPU),
+    .instance_init = ppc_cpu_initfn,
     .abstract = false,
     .class_size = sizeof(PowerPCCPUClass),
     .class_init = ppc_cpu_class_init,