diff mbox

[RFC,2/7] i386: add cpu device_del support

Message ID 1405072795-14342-3-git-send-email-guz.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Gu Zheng July 11, 2014, 9:59 a.m. UTC
In order to add cpu(i386) device_del support, introduce the cpu hot
unplug hanlde(x86_cpu_unplug) which will trigger the unrealize routine,
and just register it to the cpu class unplug handle.

Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
---
 target-i386/cpu.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 56043fa..06e969b 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2995,6 +2995,27 @@  static Property x86_cpu_properties[] = {
     DEFINE_PROP_END_OF_LIST()
 };
 
+static int x86_cpu_unplug(DeviceState *dev)
+{
+    CPUState *cpu = CPU(dev);
+    X86CPUClass *xcc;
+    Error *err = NULL;
+
+    if (cpu == first_cpu) {
+        error_report("Can not remove the first cpu!\n");
+        return -1;
+    }
+
+    xcc = X86_CPU_GET_CLASS(DEVICE(cpu));
+    xcc->parent_unrealize(DEVICE(cpu), &err);
+    if (err != NULL) {
+        error_report("%s", error_get_pretty(err));
+        error_free(err);
+        return -1;
+    }
+    return 0;
+}
+
 static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
 {
     X86CPUClass *xcc = X86_CPU_CLASS(oc);
@@ -3007,6 +3028,7 @@  static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     dc->unrealize = x86_cpu_unrealizefn;
     dc->bus_type = TYPE_ICC_BUS;
     dc->props = x86_cpu_properties;
+    dc->unplug = x86_cpu_unplug;
 
     xcc->parent_reset = cc->reset;
     cc->reset = x86_cpu_reset;