diff mbox

[v2,02/11] acpi/cpu: add cpu hot unplug request callback function

Message ID fd31c097a909189ef7d569b6d00585cfccb08772.1421214664.git.zhugh.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Zhu Guihua Jan. 14, 2015, 7:44 a.m. UTC
From: Gu Zheng <guz.fnst@cn.fujitsu.com>

Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
---
 hw/acpi/cpu_hotplug.c         | 38 +++++++++++++++++++++++++++++++++-----
 include/hw/acpi/cpu_hotplug.h |  4 ++++
 2 files changed, 37 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index 4047294..f8a10d2 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -12,6 +12,11 @@ 
 #include "hw/hw.h"
 #include "hw/acpi/cpu_hotplug.h"
 
+typedef enum STS_OPT {
+    SET,
+    CLEAR,
+} STS_OPT;
+
 static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size)
 {
     AcpiCpuHotplug *cpus = opaque;
@@ -36,8 +41,8 @@  static const MemoryRegionOps AcpiCpuHotplug_ops = {
     },
 };
 
-static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
-                                     Error **errp)
+static void acpi_update_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
+                                        STS_OPT opt, Error **errp)
 {
     CPUClass *k = CPU_GET_CLASS(cpu);
     int64_t cpu_id;
@@ -48,13 +53,23 @@  static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
         return;
     }
 
-    g->sts[cpu_id / 8] |= (1 << (cpu_id % 8));
+    switch (opt) {
+    case SET:
+        g->sts[cpu_id / 8] |= (1 << (cpu_id % 8));
+        break;
+    case CLEAR:
+        g->sts[cpu_id / 8] &= ~(1 << (cpu_id % 8));
+        break;
+    default:
+        g_assert(0);
+        break;
+    }
 }
 
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
                       AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
 {
-    acpi_set_cpu_present_bit(g, CPU(dev), errp);
+    acpi_update_cpu_present_bit(g, CPU(dev), SET, errp);
     if (*errp != NULL) {
         return;
     }
@@ -66,13 +81,26 @@  void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
     }
 }
 
+void acpi_cpu_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
+                                AcpiCpuHotplug *g, DeviceState *dev,
+                                Error **errp)
+{
+    acpi_update_cpu_present_bit(g, CPU(dev), CLEAR, errp);
+    if (*errp != NULL) {
+        return;
+    }
+
+    ar->gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
+    acpi_update_sci(ar, irq);
+}
+
 void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
                            AcpiCpuHotplug *gpe_cpu, uint16_t base)
 {
     CPUState *cpu;
 
     CPU_FOREACH(cpu) {
-        acpi_set_cpu_present_bit(gpe_cpu, cpu, &error_abort);
+        acpi_update_cpu_present_bit(gpe_cpu, cpu, SET, &error_abort);
     }
     memory_region_init_io(&gpe_cpu->io, owner, &AcpiCpuHotplug_ops,
                           gpe_cpu, "acpi-cpu-hotplug", ACPI_GPE_PROC_LEN);
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index f6d358d..8b15a3d 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -23,6 +23,10 @@  typedef struct AcpiCpuHotplug {
 void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
                       AcpiCpuHotplug *g, DeviceState *dev, Error **errp);
 
+void acpi_cpu_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
+                                AcpiCpuHotplug *g, DeviceState *dev,
+                                Error **errp);
+
 void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
                            AcpiCpuHotplug *gpe_cpu, uint16_t base);
 #endif