Patchwork [qom-next,12/12] target-i386: move reset callback to cpu.c and call cpu_reset() in x86_cpu_realize()

login
register
mail settings
Submitter Igor Mammedov
Date May 29, 2012, 10:10 p.m.
Message ID <1338329426-28118-13-git-send-email-imammedo@redhat.com>
Download mbox | patch
Permalink /patch/161811/
State New
Headers show

Comments

Igor Mammedov - May 29, 2012, 10:10 p.m.
Moving reset callback into cpu object from board level and
resetting cpu at the end of x86_cpu_realize() will allow properly
create cpu object during run-time (hotplug).

When reset over QOM hierarchy is implemented, reset callback
should be removed.

Additionally, there is only call to cpu_x86_init() left in pc_new_cpu(),
move it into pc_cpus_init() and delete empty pc_new_cpu().

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/pc.c           |   28 ++++++----------------------
 target-i386/cpu.c |   12 ++++++++++++
 2 files changed, 18 insertions(+), 22 deletions(-)

Patch

diff --git a/hw/pc.c b/hw/pc.c
index 986f119..fda6afc 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -885,32 +885,16 @@  void pc_acpi_smi_interrupt(void *opaque, int irq, int level)
     }
 }
 
-static void pc_cpu_reset(void *opaque)
-{
-    X86CPU *cpu = opaque;
-    cpu_reset(CPU(cpu));
-}
-
-static X86CPU *pc_new_cpu(const char *cpu_model)
-{
-    X86CPU *cpu;
-
-    cpu = cpu_x86_init(cpu_model);
-    if (cpu == NULL) {
-        exit(1);
-    }
-
-    qemu_register_reset(pc_cpu_reset, cpu);
-    pc_cpu_reset(cpu);
-    return cpu;
-}
-
 void pc_cpus_init(const char *cpu_model)
 {
+    X86CPU *cpu;
     int i;
 
-    for(i = 0; i < smp_cpus; i++) {
-        pc_new_cpu(cpu_model);
+    for (i = 0; i < smp_cpus; i++) {
+        cpu = cpu_x86_init(cpu_model);
+        if (cpu == NULL) {
+            exit(1);
+        }
     }
 }
 
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index b649904..8d9729d 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1781,6 +1781,14 @@  static void x86_set_cpu_model(Object *obj, const char *value, Error **errp)
 }
 
 #ifndef CONFIG_USER_ONLY
+
+/* TODO: remove me, when reset over QOM tree is implemented */
+static void x86_cpu_machine_reset_cb(void *opaque)
+{
+    X86CPU *cpu = opaque;
+    cpu_reset(CPU(cpu));
+}
+
 #define MSI_ADDR_BASE 0xfee00000
 
 static void x86_cpu_apic_init(X86CPU *cpu, Error **errp)
@@ -1813,13 +1821,17 @@  void x86_cpu_realize(Object *obj, Error **errp)
 {
     X86CPU *cpu = X86_CPU(obj);
 
+#ifndef CONFIG_USER_ONLY
     x86_cpu_apic_init(cpu, errp);
     if (error_is_set(errp)) {
         return;
     }
+    qemu_register_reset(x86_cpu_machine_reset_cb, cpu);
+#endif
 
     mce_init(cpu);
     qemu_init_vcpu(&cpu->env);
+    cpu_reset(CPU(cpu));
 }
 
 static void x86_cpu_initfn(Object *obj)