Signed-off-by: Zhu Guihua <zhugh.f...@cn.fujitsu.com> Signed-off-by: Gu Zheng <guz.f...@cn.fujitsu.com> --- hw/acpi/ich9.c | 9 +++++++-- hw/acpi/piix4.c | 2 ++ hw/i386/pc.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c index 5352e19..7600e88 100644 --- a/hw/acpi/ich9.c +++ b/hw/acpi/ich9.c @@ -400,8 +400,13 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp) void ich9_pm_device_unplug_request_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp) { - error_setg(errp, "acpi: device unplug request for not supported device" - " type: %s", object_get_typename(OBJECT(dev))); + if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { + acpi_cpu_unplug_request_cb(&pm->acpi_regs, pm->irq, + &pm->gpe_cpu, dev, errp); + } else { + error_setg(errp, "acpi: device unplug request for not supported device" + " type: %s", object_get_typename(OBJECT(dev))); + } } void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index 14d40a0..23595b6 100644 --- a/hw/acpi/piix4.c +++ b/hw/acpi/piix4.c @@ -364,6 +364,8 @@ static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev, if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { acpi_pcihp_device_unplug_cb(&s->ar, s->irq, &s->acpi_pci_hotplug, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { + acpi_cpu_unplug_request_cb(&s->ar, s->irq, &s->gpe_cpu, dev, errp); } else { error_setg(errp, "acpi: device unplug request for not supported device" " type: %s", object_get_typename(OBJECT(dev))); diff --git a/hw/i386/pc.c b/hw/i386/pc.c index c1ecf08..80dac20 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1653,6 +1653,40 @@ out: error_propagate(errp, local_err); } +static void pc_cpu_unplug_request(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + HotplugHandlerClass *hhc; + Error *local_err = NULL; + PCMachineState *pcms; + CPUState *cpu; + int current_cpus = 0; + + CPU_FOREACH(cpu) { + current_cpus++; + } + + if (current_cpus == 1) { + error_setg(&local_err, + "remove the last cpu is not allowed"); + goto out; + } + + pcms = PC_MACHINE(hotplug_dev); + if (!pcms->acpi_dev) { + if (dev->hotplugged) { + error_setg(&local_err, + "cpu hot unplug is not enabled: missing acpi device"); + } + goto out; + } + + hhc = HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev); + hhc->unplug_request(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &local_err); +out: + error_propagate(errp, local_err); +} + static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { @@ -1666,8 +1700,12 @@ static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev, static void pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { - error_setg(errp, "acpi: device unplug request for not supported device" - " type: %s", object_get_typename(OBJECT(dev))); + if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { + pc_cpu_unplug_request(hotplug_dev, dev, errp); + } else { + error_setg(errp, "acpi: device unplug request for not supported device" + " type: %s", object_get_typename(OBJECT(dev))); + } } static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev, -- 1.9.3