[Qemu-devel] [RESEND PATCH v1 3/5] acpi, pc: Add unplug cb for pc machine.

2015-01-07 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds hotunplug cb for pc machine, and memory and CPU
hot unplug will base on it.
---
 hw/i386/pc.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 312f8cf..0f3b1e0 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1717,6 +1717,13 @@ static void 
pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
 type: %s, object_get_typename(OBJECT(dev)));
 }
 
+static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
+DeviceState *dev, Error **errp)
+{
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
+
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
  DeviceState *dev)
 {
@@ -1847,6 +1854,7 @@ static void pc_machine_class_init(ObjectClass *oc, void 
*data)
 mc-get_hotplug_handler = pc_get_hotpug_handler;
 hc-plug = pc_machine_device_plug_cb;
 hc-unplug_request = pc_machine_device_unplug_request_cb;
+hc-unplug = pc_machine_device_unplug_cb;
 }
 
 static const TypeInfo pc_machine_info = {
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 5/5] acpi, piix4: Add unplug cb for piix4.

2015-01-07 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds hotunplug cb for piix4, and memory and CPU
hot unplug will base on it.
---
 hw/acpi/piix4.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 481a16c..4407388 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -370,6 +370,13 @@ static void piix4_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 }
 }
 
+static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
+   DeviceState *dev, Error **errp)
+{
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
+
 static void piix4_update_bus_hotplug(PCIBus *pci_bus, void *opaque)
 {
 PIIX4PMState *s = opaque;
@@ -610,6 +617,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 dc-hotpluggable = false;
 hc-plug = piix4_device_plug_cb;
 hc-unplug_request = piix4_device_unplug_request_cb;
+hc-unplug = piix4_device_unplug_cb;
 adevc-ospm_status = piix4_ospm_status;
 }
 
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 2/5] acpi, ich9: Add hotunplug request cb for ich9.

2015-01-07 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
They both need unplug request cb when the unplug operation happens.

This patch adds hotunplug request cb for ich9, and memory and CPU
hot unplug will base on it.
---
 hw/acpi/ich9.c | 7 +++
 hw/isa/lpc_ich9.c  | 5 +++--
 include/hw/acpi/ich9.h | 2 ++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index ea991a3..5ce3aaf 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -301,6 +301,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)));
+}
+
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
 {
 ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 530b074..d00b223 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -610,8 +610,9 @@ static void ich9_device_plug_cb(HotplugHandler *hotplug_dev,
 static void ich9_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)));
+ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+ich9_pm_device_unplug_request_cb(lpc-pm, dev, errp);
 }
 
 static bool ich9_rst_cnt_needed(void *opaque)
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index fe975e6..86853c3 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -59,6 +59,8 @@ extern const VMStateDescription vmstate_ich9_pm;
 void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp);
 
 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);
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
 #endif /* HW_ACPI_ICH9_H */
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 0/5] Common unplug and unplug request cb for memory and CPU hot-unplug.

2015-01-07 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

They both need pc-machine, piix4 and ich9 unplug and unplug request cb.
So this patch set introduces these commom functions as part1, and memory
and CPU hot-unplug will come soon as part 2 and 3.

This patch-set is based on QEmu 2.2

Tang Chen (5):
  acpi, pc: Add hotunplug request cb for pc machine.
  acpi, ich9: Add hotunplug request cb for ich9.
  acpi, pc: Add unplug cb for pc machine.
  acpi, ich9: Add unplug cb for ich9.
  acpi, piix4: Add unplug cb for piix4.

 hw/acpi/ich9.c | 14 ++
 hw/acpi/piix4.c|  8 
 hw/i386/pc.c   | 16 
 hw/isa/lpc_ich9.c  | 14 --
 include/hw/acpi/ich9.h |  4 
 5 files changed, 54 insertions(+), 2 deletions(-)

-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 01/13] acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().

2015-01-07 Thread Tang Chen
Replace string slot in acpi_memory_plug_cb() with MACRO PC_DIMM_SLOT_PROP.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index ed39241..c6580da 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -168,7 +168,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 {
 MemStatus *mdev;
 Error *local_err = NULL;
-int slot = object_property_get_int(OBJECT(dev), slot, local_err);
+int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
+   local_err);
 
 if (local_err) {
 error_propagate(errp, local_err);
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 00/13] QEmu memory hot unplug support.

2015-01-07 Thread Tang Chen
Memory hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch-set is based on QEmu 2.2

This series depends on the following patchset.
[PATCH] Common unplug and unplug request cb for memory and CPU hot-unplug.
https://www.mail-archive.com/qemu-devel@nongnu.org/msg272745.html

Hu Tao (2):
  acpi, piix4: Add memory hot unplug request support for piix4.
  pc, acpi bios: Add memory hot unplug interface.

Tang Chen (11):
  acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().
  acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to get
MemStatus.
  acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for
memory hotplug.
  acpi, mem-hotplug: Add unplug request cb for memory device.
  acpi, ich9: Add memory hot unplug request support for ich9.
  pc-dimm: Add memory hot unplug request support for pc-dimm.
  acpi, mem-hotplug: Add unplug cb for memory device.
  acpi, piix4: Add memory hot unplug support for piix4.
  acpi, ich9: Add memory hot unplug support for ich9.
  pc-dimm: Add memory hot unplug support for pc-dimm.
  acpi: Add hardware implementation for memory hot unplug.

 docs/specs/acpi_mem_hotplug.txt   |  8 +++-
 hw/acpi/ich9.c| 20 ++--
 hw/acpi/memory_hotplug.c  | 97 ---
 hw/acpi/piix4.c   | 18 ++--
 hw/core/qdev.c|  2 +-
 hw/i386/acpi-dsdt-mem-hotplug.dsl | 11 -
 hw/i386/pc.c  | 53 +++--
 hw/i386/ssdt-mem.dsl  |  5 ++
 include/hw/acpi/memory_hotplug.h  |  6 +++
 include/hw/acpi/pc-hotplug.h  |  2 +
 include/hw/qdev-core.h|  1 +
 11 files changed, 192 insertions(+), 31 deletions(-)

-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 04/13] acpi, mem-hotplug: Add unplug request cb for memory device.

2015-01-07 Thread Tang Chen
Memory hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds unplug request cb for memory device. Add a new bool
member named is_removing to MemStatus indicating that the memory slot
is being removed. Set it to true in acpi_memory_unplug_request_cb(),
and send SCI to guest.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 16 
 include/hw/acpi/memory_hotplug.h |  4 
 2 files changed, 20 insertions(+)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 9839963..3d8e398 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -211,6 +211,22 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 acpi_memory_hotplug_sci(ar, irq);
 }
 
+void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
+   MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
+mdev-is_removing = true;
+
+/* Do ACPI magic */
+acpi_memory_hotplug_sci(ar, irq);
+}
+
 static const VMStateDescription vmstate_memhp_sts = {
 .name = memory hotplug device state,
 .version_id = 1,
diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h
index 7bbf8a0..c437a85 100644
--- a/include/hw/acpi/memory_hotplug.h
+++ b/include/hw/acpi/memory_hotplug.h
@@ -11,6 +11,7 @@ typedef struct MemStatus {
 DeviceState *dimm;
 bool is_enabled;
 bool is_inserting;
+bool is_removing;
 uint32_t ost_event;
 uint32_t ost_status;
 } MemStatus;
@@ -28,6 +29,9 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner,
 
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
  DeviceState *dev, Error **errp);
+void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
+   MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp);
 
 extern const VMStateDescription vmstate_memory_hotplug;
 #define VMSTATE_MEMORY_HOTPLUG(memhp, state) \
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 06/13] acpi, ich9: Add memory hot unplug request support for ich9.

2015-01-07 Thread Tang Chen
Call memory unplug request cb in ich9_pm_device_unplug_request_cb().
---
 hw/acpi/ich9.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index c48d176..841f57d 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -304,8 +304,14 @@ 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 (pm-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_request_cb(pm-acpi_regs, pm-irq,
+  pm-acpi_memory_hotplug, 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,
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 02/13] acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to get MemStatus.

2015-01-07 Thread Tang Chen
Add a new API named acpi_memory_get_slot_status_descriptor() to obtain
a single memory slot status. Doing this is because this procedure will
be used by other functions in the next coming patches.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 27 +++
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index c6580da..ef56bf6 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -163,29 +163,40 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object 
*owner,
 memory_region_add_subregion(as, ACPI_MEMORY_HOTPLUG_BASE, state-io);
 }
 
-void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
- DeviceState *dev, Error **errp)
+static MemStatus *
+acpi_memory_get_slot_status_descriptor(MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
 {
-MemStatus *mdev;
 Error *local_err = NULL;
 int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
local_err);
 
 if (local_err) {
 error_propagate(errp, local_err);
-return;
+return NULL;
 }
 
 if (slot = mem_st-dev_count) {
 char *dev_path = object_get_canonical_path(OBJECT(dev));
-error_setg(errp, acpi_memory_plug_cb: 
+error_setg(errp, acpi_memory_get_slot_status_descriptor: 
device [%s] returned invalid memory slot[%d],
-dev_path, slot);
+   dev_path, slot);
 g_free(dev_path);
-return;
+return NULL;
 }
 
-mdev = mem_st-devs[slot];
+return mem_st-devs[slot];
+}
+
+void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+ DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
 mdev-dimm = dev;
 mdev-is_enabled = true;
 mdev-is_inserting = true;
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 11/13] pc-dimm: Add memory hot unplug support for pc-dimm.

2015-01-07 Thread Tang Chen
Implement unplug cb for pc-dimm. It remove the corresponding
memory region, and unregister vmstat. At last, it calls memory
unplug cb to reset memory status and do unparenting.
---
 hw/i386/pc.c | 25 +++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index f501f1f..3732f67 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1691,6 +1691,23 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_dimm_unplug(HotplugHandler *hotplug_dev,
+   DeviceState *dev, Error **errp)
+{
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+PCDIMMDevice *dimm = PC_DIMM(dev);
+PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
+MemoryRegion *mr = ddc-get_memory_region(dimm);
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+
+memory_region_del_subregion(pcms-hotplug_memory, mr);
+vmstate_unregister_ram(mr, dev);
+
+hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
+hhc-unplug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+}
+
 static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 DeviceState *dev, Error **errp)
 {
@@ -1744,8 +1761,12 @@ static void 
pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
 static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
 DeviceState *dev, Error **errp)
 {
-error_setg(errp, acpi: device unplug for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+pc_dimm_unplug(hotplug_dev, dev, errp);
+} else {
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 07/13] pc-dimm: Add memory hot unplug request support for pc-dimm.

2015-01-07 Thread Tang Chen
Implement memory unplug request cb for pc-dimm, and call it in
pc_machine_device_unplug_request_cb().
---
 hw/i386/pc.c | 28 ++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 0f3b1e0..f501f1f 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1671,6 +1671,26 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_dimm_unplug_request(HotplugHandler *hotplug_dev,
+   DeviceState *dev, Error **errp)
+{
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+if (!pcms-acpi_dev) {
+error_setg(local_err,
+   memory hotplug 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_cpu_plug(HotplugHandler *hotplug_dev,
 DeviceState *dev, Error **errp)
 {
@@ -1713,8 +1733,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_PC_DIMM)) {
+pc_dimm_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.8.4.2




[Qemu-devel] [RESEND PATCH v1 05/13] acpi, piix4: Add memory hot unplug request support for piix4.

2015-01-07 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

Call memory unplug request cb in piix4_device_unplug_request_cb().

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/piix4.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 4407388..f809c3a 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -361,7 +361,11 @@ static void piix4_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 {
 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
 
-if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+if (s-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_request_cb(s-ar, s-irq, s-acpi_memory_hotplug,
+  dev, errp);
+} else 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 {
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 03/13] acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for memory hotplug.

2015-01-07 Thread Tang Chen
Add a new API named acpi_memory_hotplug_sci() to send memory hotplug SCI.
Doing this is because this procedure will be used by other functions in the
next coming patches.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index ef56bf6..9839963 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -188,6 +188,12 @@ acpi_memory_get_slot_status_descriptor(MemHotplugState 
*mem_st,
 return mem_st-devs[slot];
 }
 
+static void acpi_memory_hotplug_sci(ACPIREGS *ar, qemu_irq irq)
+{
+ar-gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
+acpi_update_sci(ar, irq);
+}
+
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
  DeviceState *dev, Error **errp)
 {
@@ -201,10 +207,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 mdev-is_enabled = true;
 mdev-is_inserting = true;
 
-/* do ACPI magic */
-ar-gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
-acpi_update_sci(ar, irq);
-return;
+/* Do ACPI magic */
+acpi_memory_hotplug_sci(ar, irq);
 }
 
 static const VMStateDescription vmstate_memhp_sts = {
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 10/13] acpi, ich9: Add memory hot unplug support for ich9.

2015-01-07 Thread Tang Chen
Call memory unplug cb in ich9_pm_device_unplug_cb().
---
 hw/acpi/ich9.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 841f57d..0a8e757 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -317,8 +317,14 @@ void ich9_pm_device_unplug_request_cb(ICH9LPCPMRegs *pm, 
DeviceState *dev,
 void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
   Error **errp)
 {
-error_setg(errp, acpi: device unplug for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+if (pm-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_cb(pm-acpi_regs, pm-irq,
+  pm-acpi_memory_hotplug, dev, errp);
+} else {
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 12/13] acpi: Add hardware implementation for memory hot unplug.

2015-01-07 Thread Tang Chen
This patch adds a new bit to memory hotplug IO port indicating that
ej0 has been evaluated by guest OS. And call pc-dimm unplug cb to do
the real removal.


Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 docs/specs/acpi_mem_hotplug.txt |  8 ++--
 hw/acpi/memory_hotplug.c| 23 ---
 hw/core/qdev.c  |  2 +-
 include/hw/qdev-core.h  |  1 +
 4 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/docs/specs/acpi_mem_hotplug.txt b/docs/specs/acpi_mem_hotplug.txt
index 1290994..28a1ffa 100644
--- a/docs/specs/acpi_mem_hotplug.txt
+++ b/docs/specs/acpi_mem_hotplug.txt
@@ -19,7 +19,9 @@ Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte 
access):
   1: Device insert event, used to distinguish device for which
  no device check event to OSPM was issued.
  It's valid only when bit 1 is set.
-  2-7: reserved and should be ignored by OSPM
+  2: Device remove event, used to indicate that device is being
+removed.
+  3-7: reserved and should be ignored by OSPM
   [0x15-0x17] reserved
 
   write access:
@@ -35,7 +37,9 @@ Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte 
access):
   1: if set to 1 clears device insert event, set by OSPM
  after it has emitted device check event for the
  selected memory device
-  2-7: reserved, OSPM must clear them before writing to register
+  2: set by hardware after it has emitted device eject event for
+selected memory device
+  3-7: reserved, OSPM must clear them before writing to register
 
 Selecting memory device slot beyond present range has no effect on platform:
- write accesses to memory hot-plug registers not documented above are
diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 2b0c8ca..b9e8752 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -2,6 +2,7 @@
 #include hw/acpi/pc-hotplug.h
 #include hw/mem/pc-dimm.h
 #include hw/boards.h
+#include hw/qdev-core.h
 #include trace.h
 #include qapi-event.h
 
@@ -75,6 +76,7 @@ static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr 
addr,
 case 0x14: /* pack and return is_* fields */
 val |= mdev-is_enabled   ? 1 : 0;
 val |= mdev-is_inserting ? 2 : 0;
+val |= mdev-is_removing  ? 4 : 0;
 trace_mhp_acpi_read_flags(mem_st-selector, val);
 break;
 default:
@@ -90,6 +92,8 @@ static void acpi_memory_hotplug_write(void *opaque, hwaddr 
addr, uint64_t data,
 MemHotplugState *mem_st = opaque;
 MemStatus *mdev;
 ACPIOSTInfo *info;
+DeviceState *dev = NULL;
+HotplugHandler *hotplug_ctrl = NULL;
 
 if (!mem_st-dev_count) {
 return;
@@ -121,21 +125,34 @@ static void acpi_memory_hotplug_write(void *opaque, 
hwaddr addr, uint64_t data,
 mdev = mem_st-devs[mem_st-selector];
 mdev-ost_status = data;
 trace_mhp_acpi_write_ost_status(mem_st-selector, mdev-ost_status);
-/* TODO: implement memory removal on guest signal */
 
 info = acpi_memory_device_status(mem_st-selector, mdev);
 qapi_event_send_acpi_device_ost(info, error_abort);
 qapi_free_ACPIOSTInfo(info);
 break;
-case 0x14:
+case 0x14: /* set is_* fields */
 mdev = mem_st-devs[mem_st-selector];
+
 if (data  2) { /* clear insert event */
 mdev-is_inserting  = false;
 trace_mhp_acpi_clear_insert_evt(mem_st-selector);
+} else if (data  4) { /* request removal of device */
+/*
+ * QEmu memory hot unplug is an asynchronized procedure. QEmu first
+ * calls pc-dimm unplug request cb to send a SCI to guest. When the
+ * Guest OS finished handling the SCI, it evaluates ACPI ej0, and
+ * QEmu calls pc-dimm unplug cb to remove memory device.
+ */
+dev = DEVICE(mdev-dimm);
+hotplug_ctrl = qdev_get_hotplug_handler(dev);
+/* Call pc-dimm unplug cb. */
+hotplug_handler_unplug(hotplug_ctrl, dev, NULL);
 }
+
+break;
+default:
 break;
 }
-
 }
 static const MemoryRegionOps acpi_memory_hotplug_ops = {
 .read = acpi_memory_hotplug_read,
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 901f289..9f08fe6 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -223,7 +223,7 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int 
alias_id,
 dev-alias_required_for_version = required_for_version;
 }
 
-static HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)
+HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)
 {
 HotplugHandler *hotplug_ctrl = NULL;
 
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 589bbe7..60f549e 100644
--- a/include/hw/qdev-core.h
+++ b

[Qemu-devel] [RESEND PATCH v1 13/13] pc, acpi bios: Add memory hot unplug interface.

2015-01-07 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

This patch implements MEMORY_SLOT_EJECT_METHOD according to ACPI spec.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/i386/acpi-dsdt-mem-hotplug.dsl | 11 ++-
 hw/i386/ssdt-mem.dsl  |  5 +
 include/hw/acpi/pc-hotplug.h  |  2 ++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/hw/i386/acpi-dsdt-mem-hotplug.dsl 
b/hw/i386/acpi-dsdt-mem-hotplug.dsl
index 2a36c47..2a35534 100644
--- a/hw/i386/acpi-dsdt-mem-hotplug.dsl
+++ b/hw/i386/acpi-dsdt-mem-hotplug.dsl
@@ -50,6 +50,7 @@
 Offset(20),
 MEMORY_SLOT_ENABLED,  1, // 1 if enabled, read only
 MEMORY_SLOT_INSERT_EVENT, 1, // (read) 1 if has a insert 
event. (write) 1 to clear event
+MEMORY_SLOT_REMOVE_EVENT, 1, // 1 if DIMM has a remove 
request, read only
 }
 
 Mutex (MEMORY_SLOT_LOCK, 0)
@@ -71,8 +72,9 @@
 If (LEqual(MEMORY_SLOT_INSERT_EVENT, One)) { // Memory 
device needs check
 MEMORY_SLOT_NOTIFY_METHOD(Local0, 1)
 Store(1, MEMORY_SLOT_INSERT_EVENT)
+} Elseif (LEqual(MEMORY_SLOT_REMOVE_EVENT, One)) { // 
Ejection request
+MEMORY_SLOT_NOTIFY_METHOD(Local0, 3)
 }
-// TODO: handle memory eject request
 Add(Local0, One, Local0) // goto next DIMM
 }
 Release(MEMORY_SLOT_LOCK)
@@ -172,5 +174,12 @@
 Store(Arg2, MEMORY_SLOT_OST_STATUS)
 Release(MEMORY_SLOT_LOCK)
 }
+
+Method(MEMORY_SLOT_EJECT_METHOD, 2) {
+Acquire(MEMORY_SLOT_LOCK, 0x)
+Store(ToInteger(Arg0), MEMORY_SLOT_SLECTOR) // select DIMM
+Store(One, MEMORY_SLOT_REMOVE_EVENT)
+Release(MEMORY_SLOT_LOCK)
+}
 } // Device()
 } // Scope()
diff --git a/hw/i386/ssdt-mem.dsl b/hw/i386/ssdt-mem.dsl
index 22ff5dd..1416639 100644
--- a/hw/i386/ssdt-mem.dsl
+++ b/hw/i386/ssdt-mem.dsl
@@ -43,6 +43,7 @@ DefinitionBlock (ssdt-mem.aml, SSDT, 0x02, BXPC, 
CSSDT, 0x1)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_STATUS_METHOD, 
MethodObj)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD, MethodObj)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_PROXIMITY_METHOD, 
MethodObj)
+External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD, 
MethodObj)
 
 Scope(\_SB) {
 /*  v-- DO NOT EDIT --v */
@@ -72,6 +73,10 @@ DefinitionBlock (ssdt-mem.aml, SSDT, 0x02, BXPC, 
CSSDT, 0x1)
 Method(_OST, 3) {
 \_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD(_UID, 
Arg0, Arg1, Arg2)
 }
+
+Method(_EJ0, 1) {
+\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD(_UID, 
Arg0)
+}
 }
 }
 }
diff --git a/include/hw/acpi/pc-hotplug.h b/include/hw/acpi/pc-hotplug.h
index b9db295..b61b6ea 100644
--- a/include/hw/acpi/pc-hotplug.h
+++ b/include/hw/acpi/pc-hotplug.h
@@ -42,6 +42,7 @@
 #define MEMORY_SLOT_PROXIMITYMPX
 #define MEMORY_SLOT_ENABLED  MES
 #define MEMORY_SLOT_INSERT_EVENT MINS
+#define MEMORY_SLOT_REMOVE_EVENT MRMV
 #define MEMORY_SLOT_SLECTOR  MSEL
 #define MEMORY_SLOT_OST_EVENTMOEV
 #define MEMORY_SLOT_OST_STATUS   MOSC
@@ -50,6 +51,7 @@
 #define MEMORY_SLOT_CRS_METHOD   MCRS
 #define MEMORY_SLOT_OST_METHOD   MOST
 #define MEMORY_SLOT_PROXIMITY_METHOD MPXM
+#define MEMORY_SLOT_EJECT_METHOD MEJ0
 #define MEMORY_SLOT_NOTIFY_METHODMTFY
 #define MEMORY_SLOT_SCAN_METHOD  MSCN
 
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 09/13] acpi, piix4: Add memory hot unplug support for piix4.

2015-01-07 Thread Tang Chen
Call memory unplug cb in piix4_device_unplug_cb().
---
 hw/acpi/piix4.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index f809c3a..4ae4867 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -377,8 +377,16 @@ static void piix4_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
 {
-error_setg(errp, acpi: device unplug for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+PIIX4PMState *s = PIIX4_PM(hotplug_dev);
+
+if (s-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_cb(s-ar, s-irq, s-acpi_memory_hotplug,
+  dev, errp);
+} else {
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 static void piix4_update_bus_hotplug(PCIBus *pci_bus, void *opaque)
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 08/13] acpi, mem-hotplug: Add unplug cb for memory device.

2015-01-07 Thread Tang Chen
Reset all memory status, and unparent the memory device.
---
 hw/acpi/memory_hotplug.c | 16 
 include/hw/acpi/memory_hotplug.h |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 3d8e398..2b0c8ca 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -227,6 +227,22 @@ void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq 
irq,
 acpi_memory_hotplug_sci(ar, irq);
 }
 
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq,
+   MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
+mdev-is_removing = false;
+mdev-is_enabled = false;
+object_unparent(OBJECT(mdev-dimm));
+mdev-dimm = NULL;
+}
+
 static const VMStateDescription vmstate_memhp_sts = {
 .name = memory hotplug device state,
 .version_id = 1,
diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h
index c437a85..6b8d9f7 100644
--- a/include/hw/acpi/memory_hotplug.h
+++ b/include/hw/acpi/memory_hotplug.h
@@ -32,6 +32,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
MemHotplugState *mem_st,
DeviceState *dev, Error **errp);
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp);
 
 extern const VMStateDescription vmstate_memory_hotplug;
 #define VMSTATE_MEMORY_HOTPLUG(memhp, state) \
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 4/5] acpi, ich9: Add unplug cb for ich9.

2015-01-07 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds hotunplug cb for ich9, and memory and CPU
hot unplug will base on it.
---
 hw/acpi/ich9.c | 7 +++
 hw/isa/lpc_ich9.c  | 9 +
 include/hw/acpi/ich9.h | 2 ++
 3 files changed, 18 insertions(+)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 5ce3aaf..c48d176 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -308,6 +308,13 @@ void ich9_pm_device_unplug_request_cb(ICH9LPCPMRegs *pm, 
DeviceState *dev,
 type: %s, object_get_typename(OBJECT(dev)));
 }
 
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+  Error **errp)
+{
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
+
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
 {
 ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index d00b223..16f5a0d 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -615,6 +615,14 @@ static void ich9_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 ich9_pm_device_unplug_request_cb(lpc-pm, dev, errp);
 }
 
+static void ich9_device_unplug_cb(HotplugHandler *hotplug_dev,
+  DeviceState *dev, Error **errp)
+{
+ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+ich9_pm_device_unplug_cb(lpc-pm, dev, errp);
+}
+
 static bool ich9_rst_cnt_needed(void *opaque)
 {
 ICH9LPCState *lpc = opaque;
@@ -678,6 +686,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void 
*data)
 dc-cannot_instantiate_with_device_add_yet = true;
 hc-plug = ich9_device_plug_cb;
 hc-unplug_request = ich9_device_unplug_request_cb;
+hc-unplug = ich9_device_unplug_cb;
 adevc-ospm_status = ich9_pm_ospm_status;
 }
 
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 86853c3..fc87dad 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -61,6 +61,8 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, 
Error **errp);
 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);
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+  Error **errp);
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
 #endif /* HW_ACPI_ICH9_H */
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v1 1/5] acpi, pc: Add hotunplug request cb for pc machine.

2015-01-07 Thread Tang Chen
Memory and CPU hot unplug are both asynchronous procedures.
They both need unplug request callback to initiate unplug operation.

Add unplug handler to pc machine that will be used by following
CPU and memory unplug patches.
---
 hw/i386/pc.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index e07f1fa..312f8cf 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1710,6 +1710,13 @@ 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)));
+}
+
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
  DeviceState *dev)
 {
@@ -1839,6 +1846,7 @@ static void pc_machine_class_init(ObjectClass *oc, void 
*data)
 pcmc-get_hotplug_handler = mc-get_hotplug_handler;
 mc-get_hotplug_handler = pc_get_hotpug_handler;
 hc-plug = pc_machine_device_plug_cb;
+hc-unplug_request = pc_machine_device_unplug_request_cb;
 }
 
 static const TypeInfo pc_machine_info = {
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part1 1/5] acpi, pc: Add hotunplug request cb for pc machine.

2014-12-10 Thread Tang Chen
Memory and CPU hot unplug are both asynchronous procedures.
They both need unplug request callback to initiate unplug operation.

Add unplug handler to pc machine that will be used by following
CPU and memory unplug patches.
---
 hw/i386/pc.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index f31d55e..765ad3c 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1709,6 +1709,13 @@ 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)));
+}
+
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
  DeviceState *dev)
 {
@@ -1831,6 +1838,7 @@ static void pc_machine_class_init(ObjectClass *oc, void 
*data)
 pcmc-get_hotplug_handler = mc-get_hotplug_handler;
 mc-get_hotplug_handler = pc_get_hotpug_handler;
 hc-plug = pc_machine_device_plug_cb;
+hc-unplug_request = pc_machine_device_unplug_request_cb;
 }
 
 static const TypeInfo pc_machine_info = {
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part1 3/5] acpi, pc: Add unplug cb for pc machine.

2014-12-10 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds hotunplug cb for pc machine, and memory and CPU
hot unplug will base on it.
---
 hw/i386/pc.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 765ad3c..27d82b1 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1716,6 +1716,13 @@ static void 
pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
 type: %s, object_get_typename(OBJECT(dev)));
 }
 
+static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
+DeviceState *dev, Error **errp)
+{
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
+
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
  DeviceState *dev)
 {
@@ -1839,6 +1846,7 @@ static void pc_machine_class_init(ObjectClass *oc, void 
*data)
 mc-get_hotplug_handler = pc_get_hotpug_handler;
 hc-plug = pc_machine_device_plug_cb;
 hc-unplug_request = pc_machine_device_unplug_request_cb;
+hc-unplug = pc_machine_device_unplug_cb;
 }
 
 static const TypeInfo pc_machine_info = {
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part1 2/5] acpi, ich9: Add hotunplug request cb for ich9.

2014-12-10 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
They both need unplug request cb when the unplug operation happens.

This patch adds hotunplug request cb for ich9, and memory and CPU
hot unplug will base on it.
---
 hw/acpi/ich9.c | 7 +++
 hw/isa/lpc_ich9.c  | 5 +++--
 include/hw/acpi/ich9.h | 2 ++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index ea991a3..5ce3aaf 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -301,6 +301,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)));
+}
+
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
 {
 ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 530b074..d00b223 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -610,8 +610,9 @@ static void ich9_device_plug_cb(HotplugHandler *hotplug_dev,
 static void ich9_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)));
+ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+ich9_pm_device_unplug_request_cb(lpc-pm, dev, errp);
 }
 
 static bool ich9_rst_cnt_needed(void *opaque)
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index fe975e6..86853c3 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -59,6 +59,8 @@ extern const VMStateDescription vmstate_ich9_pm;
 void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp);
 
 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);
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
 #endif /* HW_ACPI_ICH9_H */
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 01/13] acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().

2014-12-10 Thread Tang Chen
Replace string slot in acpi_memory_plug_cb() with MACRO PC_DIMM_SLOT_PROP.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index ed39241..c6580da 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -168,7 +168,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 {
 MemStatus *mdev;
 Error *local_err = NULL;
-int slot = object_property_get_int(OBJECT(dev), slot, local_err);
+int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
+   local_err);
 
 if (local_err) {
 error_propagate(errp, local_err);
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part1 0/5] Common unplug and unplug request cb for memory and CPU hot-unplug.

2014-12-10 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

They both need pc-machine, piix4 and ich9 unplug and unplug request cb.
So this patch set introduces these commom functions as part1, and memory
and CPU hot-unplug will come soon as part 2 and 3.

This patch-set is based on QEmu 2.2

Tang Chen (5):
  acpi, pc: Add hotunplug request cb for pc machine.
  acpi, ich9: Add hotunplug request cb for ich9.
  acpi, pc: Add unplug cb for pc machine.
  acpi, ich9: Add unplug cb for ich9.
  acpi, piix4: Add unplug cb for piix4.

 hw/acpi/ich9.c | 14 ++
 hw/acpi/piix4.c|  8 
 hw/i386/pc.c   | 16 
 hw/isa/lpc_ich9.c  | 14 --
 include/hw/acpi/ich9.h |  4 
 5 files changed, 54 insertions(+), 2 deletions(-)

-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part1 5/5] acpi, piix4: Add unplug cb for piix4.

2014-12-10 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds hotunplug cb for piix4, and memory and CPU
hot unplug will base on it.
---
 hw/acpi/piix4.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 481a16c..4407388 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -370,6 +370,13 @@ static void piix4_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 }
 }
 
+static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
+   DeviceState *dev, Error **errp)
+{
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
+
 static void piix4_update_bus_hotplug(PCIBus *pci_bus, void *opaque)
 {
 PIIX4PMState *s = opaque;
@@ -610,6 +617,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 dc-hotpluggable = false;
 hc-plug = piix4_device_plug_cb;
 hc-unplug_request = piix4_device_unplug_request_cb;
+hc-unplug = piix4_device_unplug_cb;
 adevc-ospm_status = piix4_ospm_status;
 }
 
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part1 4/5] acpi, ich9: Add unplug cb for ich9.

2014-12-10 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds hotunplug cb for ich9, and memory and CPU
hot unplug will base on it.
---
 hw/acpi/ich9.c | 7 +++
 hw/isa/lpc_ich9.c  | 9 +
 include/hw/acpi/ich9.h | 2 ++
 3 files changed, 18 insertions(+)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 5ce3aaf..c48d176 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -308,6 +308,13 @@ void ich9_pm_device_unplug_request_cb(ICH9LPCPMRegs *pm, 
DeviceState *dev,
 type: %s, object_get_typename(OBJECT(dev)));
 }
 
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+  Error **errp)
+{
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
+
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
 {
 ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index d00b223..16f5a0d 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -615,6 +615,14 @@ static void ich9_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 ich9_pm_device_unplug_request_cb(lpc-pm, dev, errp);
 }
 
+static void ich9_device_unplug_cb(HotplugHandler *hotplug_dev,
+  DeviceState *dev, Error **errp)
+{
+ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+ich9_pm_device_unplug_cb(lpc-pm, dev, errp);
+}
+
 static bool ich9_rst_cnt_needed(void *opaque)
 {
 ICH9LPCState *lpc = opaque;
@@ -678,6 +686,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void 
*data)
 dc-cannot_instantiate_with_device_add_yet = true;
 hc-plug = ich9_device_plug_cb;
 hc-unplug_request = ich9_device_unplug_request_cb;
+hc-unplug = ich9_device_unplug_cb;
 adevc-ospm_status = ich9_pm_ospm_status;
 }
 
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 86853c3..fc87dad 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -61,6 +61,8 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, 
Error **errp);
 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);
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+  Error **errp);
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
 #endif /* HW_ACPI_ICH9_H */
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 05/13] acpi, piix4: Add memory hot unplug request support for piix4.

2014-12-10 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

Call memory unplug request cb in piix4_device_unplug_request_cb().

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/piix4.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 4407388..f809c3a 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -361,7 +361,11 @@ static void piix4_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 {
 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
 
-if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+if (s-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_request_cb(s-ar, s-irq, s-acpi_memory_hotplug,
+  dev, errp);
+} else 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 {
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 00/13] QEmu memory hot unplug support.

2014-12-10 Thread Tang Chen
Memory hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch-set is based on QEmu 2.2

Hu Tao (2):
  acpi, piix4: Add memory hot unplug request support for piix4.
  pc, acpi bios: Add memory hot unplug interface.

Tang Chen (11):
  acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().
  acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to get
MemStatus.
  acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for
memory hotplug.
  acpi, mem-hotplug: Add unplug request cb for memory device.
  acpi, ich9: Add memory hot unplug request support for ich9.
  pc-dimm: Add memory hot unplug request support for pc-dimm.
  acpi, mem-hotplug: Add unplug cb for memory device.
  acpi, piix4: Add memory hot unplug support for piix4.
  acpi, ich9: Add memory hot unplug support for ich9.
  pc-dimm: Add memory hot unplug support for pc-dimm.
  acpi: Add hardware implementation for memory hot unplug.

 docs/specs/acpi_mem_hotplug.txt   |  8 +++-
 hw/acpi/ich9.c| 20 ++--
 hw/acpi/memory_hotplug.c  | 97 ---
 hw/acpi/piix4.c   | 18 ++--
 hw/core/qdev.c|  2 +-
 hw/i386/acpi-dsdt-mem-hotplug.dsl | 11 -
 hw/i386/pc.c  | 53 +++--
 hw/i386/ssdt-mem.dsl  |  5 ++
 include/hw/acpi/memory_hotplug.h  |  6 +++
 include/hw/acpi/pc-hotplug.h  |  2 +
 include/hw/qdev-core.h|  1 +
 11 files changed, 192 insertions(+), 31 deletions(-)

-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 10/13] acpi, ich9: Add memory hot unplug support for ich9.

2014-12-10 Thread Tang Chen
Call memory unplug cb in ich9_pm_device_unplug_cb().
---
 hw/acpi/ich9.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 841f57d..0a8e757 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -317,8 +317,14 @@ void ich9_pm_device_unplug_request_cb(ICH9LPCPMRegs *pm, 
DeviceState *dev,
 void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
   Error **errp)
 {
-error_setg(errp, acpi: device unplug for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+if (pm-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_cb(pm-acpi_regs, pm-irq,
+  pm-acpi_memory_hotplug, dev, errp);
+} else {
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 02/13] acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to get MemStatus.

2014-12-10 Thread Tang Chen
Add a new API named acpi_memory_get_slot_status_descriptor() to obtain
a single memory slot status. Doing this is because this procedure will
be used by other functions in the next coming patches.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 27 +++
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index c6580da..ef56bf6 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -163,29 +163,40 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object 
*owner,
 memory_region_add_subregion(as, ACPI_MEMORY_HOTPLUG_BASE, state-io);
 }
 
-void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
- DeviceState *dev, Error **errp)
+static MemStatus *
+acpi_memory_get_slot_status_descriptor(MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
 {
-MemStatus *mdev;
 Error *local_err = NULL;
 int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
local_err);
 
 if (local_err) {
 error_propagate(errp, local_err);
-return;
+return NULL;
 }
 
 if (slot = mem_st-dev_count) {
 char *dev_path = object_get_canonical_path(OBJECT(dev));
-error_setg(errp, acpi_memory_plug_cb: 
+error_setg(errp, acpi_memory_get_slot_status_descriptor: 
device [%s] returned invalid memory slot[%d],
-dev_path, slot);
+   dev_path, slot);
 g_free(dev_path);
-return;
+return NULL;
 }
 
-mdev = mem_st-devs[slot];
+return mem_st-devs[slot];
+}
+
+void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+ DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
 mdev-dimm = dev;
 mdev-is_enabled = true;
 mdev-is_inserting = true;
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 06/13] acpi, ich9: Add memory hot unplug request support for ich9.

2014-12-10 Thread Tang Chen
Call memory unplug request cb in ich9_pm_device_unplug_request_cb().
---
 hw/acpi/ich9.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index c48d176..841f57d 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -304,8 +304,14 @@ 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 (pm-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_request_cb(pm-acpi_regs, pm-irq,
+  pm-acpi_memory_hotplug, 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,
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 03/13] acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for memory hotplug.

2014-12-10 Thread Tang Chen
Add a new API named acpi_memory_hotplug_sci() to send memory hotplug SCI.
Doing this is because this procedure will be used by other functions in the
next coming patches.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index ef56bf6..9839963 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -188,6 +188,12 @@ acpi_memory_get_slot_status_descriptor(MemHotplugState 
*mem_st,
 return mem_st-devs[slot];
 }
 
+static void acpi_memory_hotplug_sci(ACPIREGS *ar, qemu_irq irq)
+{
+ar-gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
+acpi_update_sci(ar, irq);
+}
+
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
  DeviceState *dev, Error **errp)
 {
@@ -201,10 +207,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 mdev-is_enabled = true;
 mdev-is_inserting = true;
 
-/* do ACPI magic */
-ar-gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
-acpi_update_sci(ar, irq);
-return;
+/* Do ACPI magic */
+acpi_memory_hotplug_sci(ar, irq);
 }
 
 static const VMStateDescription vmstate_memhp_sts = {
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 08/13] acpi, mem-hotplug: Add unplug cb for memory device.

2014-12-10 Thread Tang Chen
Reset all memory status, and unparent the memory device.
---
 hw/acpi/memory_hotplug.c | 16 
 include/hw/acpi/memory_hotplug.h |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 3d8e398..2b0c8ca 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -227,6 +227,22 @@ void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq 
irq,
 acpi_memory_hotplug_sci(ar, irq);
 }
 
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq,
+   MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
+mdev-is_removing = false;
+mdev-is_enabled = false;
+object_unparent(OBJECT(mdev-dimm));
+mdev-dimm = NULL;
+}
+
 static const VMStateDescription vmstate_memhp_sts = {
 .name = memory hotplug device state,
 .version_id = 1,
diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h
index c437a85..6b8d9f7 100644
--- a/include/hw/acpi/memory_hotplug.h
+++ b/include/hw/acpi/memory_hotplug.h
@@ -32,6 +32,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
MemHotplugState *mem_st,
DeviceState *dev, Error **errp);
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp);
 
 extern const VMStateDescription vmstate_memory_hotplug;
 #define VMSTATE_MEMORY_HOTPLUG(memhp, state) \
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 04/13] acpi, mem-hotplug: Add unplug request cb for memory device.

2014-12-10 Thread Tang Chen
Memory hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds unplug request cb for memory device. Add a new bool
member named is_removing to MemStatus indicating that the memory slot
is being removed. Set it to true in acpi_memory_unplug_request_cb(),
and send SCI to guest.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 16 
 include/hw/acpi/memory_hotplug.h |  4 
 2 files changed, 20 insertions(+)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 9839963..3d8e398 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -211,6 +211,22 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 acpi_memory_hotplug_sci(ar, irq);
 }
 
+void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
+   MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
+mdev-is_removing = true;
+
+/* Do ACPI magic */
+acpi_memory_hotplug_sci(ar, irq);
+}
+
 static const VMStateDescription vmstate_memhp_sts = {
 .name = memory hotplug device state,
 .version_id = 1,
diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h
index 7bbf8a0..c437a85 100644
--- a/include/hw/acpi/memory_hotplug.h
+++ b/include/hw/acpi/memory_hotplug.h
@@ -11,6 +11,7 @@ typedef struct MemStatus {
 DeviceState *dimm;
 bool is_enabled;
 bool is_inserting;
+bool is_removing;
 uint32_t ost_event;
 uint32_t ost_status;
 } MemStatus;
@@ -28,6 +29,9 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner,
 
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
  DeviceState *dev, Error **errp);
+void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
+   MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp);
 
 extern const VMStateDescription vmstate_memory_hotplug;
 #define VMSTATE_MEMORY_HOTPLUG(memhp, state) \
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 09/13] acpi, piix4: Add memory hot unplug support for piix4.

2014-12-10 Thread Tang Chen
Call memory unplug cb in piix4_device_unplug_cb().
---
 hw/acpi/piix4.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index f809c3a..4ae4867 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -377,8 +377,16 @@ static void piix4_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
 {
-error_setg(errp, acpi: device unplug for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+PIIX4PMState *s = PIIX4_PM(hotplug_dev);
+
+if (s-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_cb(s-ar, s-irq, s-acpi_memory_hotplug,
+  dev, errp);
+} else {
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 static void piix4_update_bus_hotplug(PCIBus *pci_bus, void *opaque)
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 07/13] pc-dimm: Add memory hot unplug request support for pc-dimm.

2014-12-10 Thread Tang Chen
Implement memory unplug request cb for pc-dimm, and call it in
pc_machine_device_unplug_request_cb().
---
 hw/i386/pc.c | 28 ++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 27d82b1..fa8bed4 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1670,6 +1670,26 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_dimm_unplug_request(HotplugHandler *hotplug_dev,
+   DeviceState *dev, Error **errp)
+{
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+if (!pcms-acpi_dev) {
+error_setg(local_err,
+   memory hotplug 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_cpu_plug(HotplugHandler *hotplug_dev,
 DeviceState *dev, Error **errp)
 {
@@ -1712,8 +1732,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_PC_DIMM)) {
+pc_dimm_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.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 11/13] pc-dimm: Add memory hot unplug support for pc-dimm.

2014-12-10 Thread Tang Chen
Implement unplug cb for pc-dimm. It remove the corresponding
memory region, and unregister vmstat. At last, it calls memory
unplug cb to reset memory status and do unparenting.
---
 hw/i386/pc.c | 25 +++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index fa8bed4..688579d 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1690,6 +1690,23 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_dimm_unplug(HotplugHandler *hotplug_dev,
+   DeviceState *dev, Error **errp)
+{
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+PCDIMMDevice *dimm = PC_DIMM(dev);
+PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
+MemoryRegion *mr = ddc-get_memory_region(dimm);
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+
+memory_region_del_subregion(pcms-hotplug_memory, mr);
+vmstate_unregister_ram(mr, dev);
+
+hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
+hhc-unplug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+}
+
 static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 DeviceState *dev, Error **errp)
 {
@@ -1743,8 +1760,12 @@ static void 
pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
 static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
 DeviceState *dev, Error **errp)
 {
-error_setg(errp, acpi: device unplug for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+pc_dimm_unplug(hotplug_dev, dev, errp);
+} else {
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 13/13] pc, acpi bios: Add memory hot unplug interface.

2014-12-10 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

This patch implements MEMORY_SLOT_EJECT_METHOD according to ACPI spec.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/i386/acpi-dsdt-mem-hotplug.dsl | 11 ++-
 hw/i386/ssdt-mem.dsl  |  5 +
 include/hw/acpi/pc-hotplug.h  |  2 ++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/hw/i386/acpi-dsdt-mem-hotplug.dsl 
b/hw/i386/acpi-dsdt-mem-hotplug.dsl
index 2a36c47..2a35534 100644
--- a/hw/i386/acpi-dsdt-mem-hotplug.dsl
+++ b/hw/i386/acpi-dsdt-mem-hotplug.dsl
@@ -50,6 +50,7 @@
 Offset(20),
 MEMORY_SLOT_ENABLED,  1, // 1 if enabled, read only
 MEMORY_SLOT_INSERT_EVENT, 1, // (read) 1 if has a insert 
event. (write) 1 to clear event
+MEMORY_SLOT_REMOVE_EVENT, 1, // 1 if DIMM has a remove 
request, read only
 }
 
 Mutex (MEMORY_SLOT_LOCK, 0)
@@ -71,8 +72,9 @@
 If (LEqual(MEMORY_SLOT_INSERT_EVENT, One)) { // Memory 
device needs check
 MEMORY_SLOT_NOTIFY_METHOD(Local0, 1)
 Store(1, MEMORY_SLOT_INSERT_EVENT)
+} Elseif (LEqual(MEMORY_SLOT_REMOVE_EVENT, One)) { // 
Ejection request
+MEMORY_SLOT_NOTIFY_METHOD(Local0, 3)
 }
-// TODO: handle memory eject request
 Add(Local0, One, Local0) // goto next DIMM
 }
 Release(MEMORY_SLOT_LOCK)
@@ -172,5 +174,12 @@
 Store(Arg2, MEMORY_SLOT_OST_STATUS)
 Release(MEMORY_SLOT_LOCK)
 }
+
+Method(MEMORY_SLOT_EJECT_METHOD, 2) {
+Acquire(MEMORY_SLOT_LOCK, 0x)
+Store(ToInteger(Arg0), MEMORY_SLOT_SLECTOR) // select DIMM
+Store(One, MEMORY_SLOT_REMOVE_EVENT)
+Release(MEMORY_SLOT_LOCK)
+}
 } // Device()
 } // Scope()
diff --git a/hw/i386/ssdt-mem.dsl b/hw/i386/ssdt-mem.dsl
index 22ff5dd..1416639 100644
--- a/hw/i386/ssdt-mem.dsl
+++ b/hw/i386/ssdt-mem.dsl
@@ -43,6 +43,7 @@ DefinitionBlock (ssdt-mem.aml, SSDT, 0x02, BXPC, 
CSSDT, 0x1)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_STATUS_METHOD, 
MethodObj)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD, MethodObj)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_PROXIMITY_METHOD, 
MethodObj)
+External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD, 
MethodObj)
 
 Scope(\_SB) {
 /*  v-- DO NOT EDIT --v */
@@ -72,6 +73,10 @@ DefinitionBlock (ssdt-mem.aml, SSDT, 0x02, BXPC, 
CSSDT, 0x1)
 Method(_OST, 3) {
 \_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD(_UID, 
Arg0, Arg1, Arg2)
 }
+
+Method(_EJ0, 1) {
+\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD(_UID, 
Arg0)
+}
 }
 }
 }
diff --git a/include/hw/acpi/pc-hotplug.h b/include/hw/acpi/pc-hotplug.h
index b9db295..b61b6ea 100644
--- a/include/hw/acpi/pc-hotplug.h
+++ b/include/hw/acpi/pc-hotplug.h
@@ -42,6 +42,7 @@
 #define MEMORY_SLOT_PROXIMITYMPX
 #define MEMORY_SLOT_ENABLED  MES
 #define MEMORY_SLOT_INSERT_EVENT MINS
+#define MEMORY_SLOT_REMOVE_EVENT MRMV
 #define MEMORY_SLOT_SLECTOR  MSEL
 #define MEMORY_SLOT_OST_EVENTMOEV
 #define MEMORY_SLOT_OST_STATUS   MOSC
@@ -50,6 +51,7 @@
 #define MEMORY_SLOT_CRS_METHOD   MCRS
 #define MEMORY_SLOT_OST_METHOD   MOST
 #define MEMORY_SLOT_PROXIMITY_METHOD MPXM
+#define MEMORY_SLOT_EJECT_METHOD MEJ0
 #define MEMORY_SLOT_NOTIFY_METHODMTFY
 #define MEMORY_SLOT_SCAN_METHOD  MSCN
 
-- 
1.8.4.2




[Qemu-devel] [PATCH RESEND v1 Part2 12/13] acpi: Add hardware implementation for memory hot unplug.

2014-12-10 Thread Tang Chen
This patch adds a new bit to memory hotplug IO port indicating that
ej0 has been evaluated by guest OS. And call pc-dimm unplug cb to do
the real removal.


Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 docs/specs/acpi_mem_hotplug.txt |  8 ++--
 hw/acpi/memory_hotplug.c| 23 ---
 hw/core/qdev.c  |  2 +-
 include/hw/qdev-core.h  |  1 +
 4 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/docs/specs/acpi_mem_hotplug.txt b/docs/specs/acpi_mem_hotplug.txt
index 1290994..28a1ffa 100644
--- a/docs/specs/acpi_mem_hotplug.txt
+++ b/docs/specs/acpi_mem_hotplug.txt
@@ -19,7 +19,9 @@ Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte 
access):
   1: Device insert event, used to distinguish device for which
  no device check event to OSPM was issued.
  It's valid only when bit 1 is set.
-  2-7: reserved and should be ignored by OSPM
+  2: Device remove event, used to indicate that device is being
+removed.
+  3-7: reserved and should be ignored by OSPM
   [0x15-0x17] reserved
 
   write access:
@@ -35,7 +37,9 @@ Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte 
access):
   1: if set to 1 clears device insert event, set by OSPM
  after it has emitted device check event for the
  selected memory device
-  2-7: reserved, OSPM must clear them before writing to register
+  2: set by hardware after it has emitted device eject event for
+selected memory device
+  3-7: reserved, OSPM must clear them before writing to register
 
 Selecting memory device slot beyond present range has no effect on platform:
- write accesses to memory hot-plug registers not documented above are
diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 2b0c8ca..b9e8752 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -2,6 +2,7 @@
 #include hw/acpi/pc-hotplug.h
 #include hw/mem/pc-dimm.h
 #include hw/boards.h
+#include hw/qdev-core.h
 #include trace.h
 #include qapi-event.h
 
@@ -75,6 +76,7 @@ static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr 
addr,
 case 0x14: /* pack and return is_* fields */
 val |= mdev-is_enabled   ? 1 : 0;
 val |= mdev-is_inserting ? 2 : 0;
+val |= mdev-is_removing  ? 4 : 0;
 trace_mhp_acpi_read_flags(mem_st-selector, val);
 break;
 default:
@@ -90,6 +92,8 @@ static void acpi_memory_hotplug_write(void *opaque, hwaddr 
addr, uint64_t data,
 MemHotplugState *mem_st = opaque;
 MemStatus *mdev;
 ACPIOSTInfo *info;
+DeviceState *dev = NULL;
+HotplugHandler *hotplug_ctrl = NULL;
 
 if (!mem_st-dev_count) {
 return;
@@ -121,21 +125,34 @@ static void acpi_memory_hotplug_write(void *opaque, 
hwaddr addr, uint64_t data,
 mdev = mem_st-devs[mem_st-selector];
 mdev-ost_status = data;
 trace_mhp_acpi_write_ost_status(mem_st-selector, mdev-ost_status);
-/* TODO: implement memory removal on guest signal */
 
 info = acpi_memory_device_status(mem_st-selector, mdev);
 qapi_event_send_acpi_device_ost(info, error_abort);
 qapi_free_ACPIOSTInfo(info);
 break;
-case 0x14:
+case 0x14: /* set is_* fields */
 mdev = mem_st-devs[mem_st-selector];
+
 if (data  2) { /* clear insert event */
 mdev-is_inserting  = false;
 trace_mhp_acpi_clear_insert_evt(mem_st-selector);
+} else if (data  4) { /* request removal of device */
+/*
+ * QEmu memory hot unplug is an asynchronized procedure. QEmu first
+ * calls pc-dimm unplug request cb to send a SCI to guest. When the
+ * Guest OS finished handling the SCI, it evaluates ACPI ej0, and
+ * QEmu calls pc-dimm unplug cb to remove memory device.
+ */
+dev = DEVICE(mdev-dimm);
+hotplug_ctrl = qdev_get_hotplug_handler(dev);
+/* Call pc-dimm unplug cb. */
+hotplug_handler_unplug(hotplug_ctrl, dev, NULL);
 }
+
+break;
+default:
 break;
 }
-
 }
 static const MemoryRegionOps acpi_memory_hotplug_ops = {
 .read = acpi_memory_hotplug_read,
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 35fd00d..ab45b77 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -223,7 +223,7 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int 
alias_id,
 dev-alias_required_for_version = required_for_version;
 }
 
-static HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)
+HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)
 {
 HotplugHandler *hotplug_ctrl = NULL;
 
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 589bbe7..60f549e 100644
--- a/include/hw/qdev-core.h
+++ b

Re: [Qemu-devel] [PATCH Part1 1/5] acpi, pc: Add hotunplug request cb for pc machine.

2014-12-09 Thread Tang Chen

Hi Igor,

On 11/18/2014 08:44 PM, Igor Mammedov wrote:

On Mon, 17 Nov 2014 13:03:13 +0800
Tang Chen tangc...@cn.fujitsu.com wrote:

in subj s/cb/callback|handler/


Memory and CPU hot unplug are both asynchronize procedures.

s/asynchronize/asynchronous/

They both need unplug request cb when the unplug operation happens.

s/cb when the unplug operation happens/callback to initiate unplug operation/


This patch adds hotunplug request cb for pc machine, and memory and CPU
hot unplug will base on it.

Add unplug handler to pc machine that will be used by following
CPU and memory unplug patches.



Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
  hw/i386/pc.c | 8 
  1 file changed, 8 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 1205db8..5c48435 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1647,6 +1647,13 @@ 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)));

it's not necessarily acpi related in general so maybe drop 'acpi:' prefix.
Also it would be nice to add device's ID or use it instead of type name.


Since QEmu 2.2 has been released, I'm now rebasing this patch-set.

Here, you suggested to use device id instead device type name.
But all existing plug handles are using device type name.

Should I send patches to change them all ?

Thanks.




+}
+
  static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
   DeviceState *dev)
  {
@@ -1753,6 +1760,7 @@ static void pc_machine_class_init(ObjectClass *oc, void 
*data)
  pcmc-get_hotplug_handler = mc-get_hotplug_handler;
  mc-get_hotplug_handler = pc_get_hotpug_handler;
  hc-plug = pc_machine_device_plug_cb;
+hc-unplug_request = pc_machine_device_unplug_request_cb;
  }
  
  static const TypeInfo pc_machine_info = {

.






[Qemu-devel] [PATCH Part1 0/5] Common unplug and unplug request cb for memory and CPU hot-unplug.

2014-11-16 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

They both need pc-machine, piix4 and ich9 unplug and unplug request cb.
So this patch set introduces these commom functions as part1, and memory
and CPU hot-unplug will come soon as part 2 and 3.


Tang Chen (5):
  acpi, pc: Add hotunplug request cb for pc machine.
  acpi, ich9: Add hotunplug request cb for ich9.
  acpi, pc: Add unplug cb for pc machine.
  acpi, ich9: Add unplug cb for ich9.
  acpi, piix4: Add unplug cb for piix4.

 hw/acpi/ich9.c | 14 ++
 hw/acpi/piix4.c|  8 
 hw/i386/pc.c   | 16 
 hw/isa/lpc_ich9.c  | 14 --
 include/hw/acpi/ich9.h |  4 
 5 files changed, 54 insertions(+), 2 deletions(-)

-- 
1.8.4.2




[Qemu-devel] [PATCH Part1 1/5] acpi, pc: Add hotunplug request cb for pc machine.

2014-11-16 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
They both need unplug request cb when the unplug operation happens.

This patch adds hotunplug request cb for pc machine, and memory and CPU
hot unplug will base on it.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/i386/pc.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 1205db8..5c48435 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1647,6 +1647,13 @@ 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)));
+}
+
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
  DeviceState *dev)
 {
@@ -1753,6 +1760,7 @@ static void pc_machine_class_init(ObjectClass *oc, void 
*data)
 pcmc-get_hotplug_handler = mc-get_hotplug_handler;
 mc-get_hotplug_handler = pc_get_hotpug_handler;
 hc-plug = pc_machine_device_plug_cb;
+hc-unplug_request = pc_machine_device_unplug_request_cb;
 }
 
 static const TypeInfo pc_machine_info = {
-- 
1.8.4.2




[Qemu-devel] [PATCH Part1 3/5] acpi, pc: Add unplug cb for pc machine.

2014-11-16 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds hotunplug cb for pc machine, and memory and CPU
hot unplug will base on it.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/i386/pc.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 5c48435..d5073df 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1654,6 +1654,13 @@ static void 
pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
 type: %s, object_get_typename(OBJECT(dev)));
 }
 
+static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
+DeviceState *dev, Error **errp)
+{
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
+
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
  DeviceState *dev)
 {
@@ -1761,6 +1768,7 @@ static void pc_machine_class_init(ObjectClass *oc, void 
*data)
 mc-get_hotplug_handler = pc_get_hotpug_handler;
 hc-plug = pc_machine_device_plug_cb;
 hc-unplug_request = pc_machine_device_unplug_request_cb;
+hc-unplug = pc_machine_device_unplug_cb;
 }
 
 static const TypeInfo pc_machine_info = {
-- 
1.8.4.2




[Qemu-devel] [PATCH Part1 5/5] acpi, piix4: Add unplug cb for piix4.

2014-11-16 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds hotunplug cb for piix4, and memory and CPU
hot unplug will base on it.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/piix4.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 78c0a6d..353f91a 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -369,6 +369,13 @@ static void piix4_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 }
 }
 
+static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
+   DeviceState *dev, Error **errp)
+{
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
+
 static void piix4_update_bus_hotplug(PCIBus *pci_bus, void *opaque)
 {
 PIIX4PMState *s = opaque;
@@ -606,6 +613,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 dc-hotpluggable = false;
 hc-plug = piix4_device_plug_cb;
 hc-unplug_request = piix4_device_unplug_request_cb;
+hc-unplug = piix4_device_unplug_cb;
 adevc-ospm_status = piix4_ospm_status;
 }
 
-- 
1.8.4.2




[Qemu-devel] [PATCH Part1 4/5] acpi, ich9: Add unplug cb for ich9.

2014-11-16 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds hotunplug cb for ich9, and memory and CPU
hot unplug will base on it.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/ich9.c | 7 +++
 hw/isa/lpc_ich9.c  | 9 +
 include/hw/acpi/ich9.h | 2 ++
 3 files changed, 18 insertions(+)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 5ce3aaf..c48d176 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -308,6 +308,13 @@ void ich9_pm_device_unplug_request_cb(ICH9LPCPMRegs *pm, 
DeviceState *dev,
 type: %s, object_get_typename(OBJECT(dev)));
 }
 
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+  Error **errp)
+{
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
+
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
 {
 ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index d00b223..16f5a0d 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -615,6 +615,14 @@ static void ich9_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 ich9_pm_device_unplug_request_cb(lpc-pm, dev, errp);
 }
 
+static void ich9_device_unplug_cb(HotplugHandler *hotplug_dev,
+  DeviceState *dev, Error **errp)
+{
+ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+ich9_pm_device_unplug_cb(lpc-pm, dev, errp);
+}
+
 static bool ich9_rst_cnt_needed(void *opaque)
 {
 ICH9LPCState *lpc = opaque;
@@ -678,6 +686,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void 
*data)
 dc-cannot_instantiate_with_device_add_yet = true;
 hc-plug = ich9_device_plug_cb;
 hc-unplug_request = ich9_device_unplug_request_cb;
+hc-unplug = ich9_device_unplug_cb;
 adevc-ospm_status = ich9_pm_ospm_status;
 }
 
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 86853c3..fc87dad 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -61,6 +61,8 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, 
Error **errp);
 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);
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+  Error **errp);
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
 #endif /* HW_ACPI_ICH9_H */
-- 
1.8.4.2




[Qemu-devel] [PATCH Part1 2/5] acpi, ich9: Add hotunplug request cb for ich9.

2014-11-16 Thread Tang Chen
Memory and CPU hot unplug are both asynchronize procedures.
They both need unplug request cb when the unplug operation happens.

This patch adds hotunplug request cb for ich9, and memory and CPU
hot unplug will base on it.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/ich9.c | 7 +++
 hw/isa/lpc_ich9.c  | 5 +++--
 include/hw/acpi/ich9.h | 2 ++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index ea991a3..5ce3aaf 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -301,6 +301,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)));
+}
+
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
 {
 ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 530b074..d00b223 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -610,8 +610,9 @@ static void ich9_device_plug_cb(HotplugHandler *hotplug_dev,
 static void ich9_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)));
+ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+ich9_pm_device_unplug_request_cb(lpc-pm, dev, errp);
 }
 
 static bool ich9_rst_cnt_needed(void *opaque)
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index fe975e6..86853c3 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -59,6 +59,8 @@ extern const VMStateDescription vmstate_ich9_pm;
 void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp);
 
 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);
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
 #endif /* HW_ACPI_ICH9_H */
-- 
1.8.4.2




[Qemu-devel] [PATCH Part2 02/13] acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to get MemStatus.

2014-11-16 Thread Tang Chen
Add a new API named acpi_memory_get_slot_status_descriptor() to obtain
a single memory slot status. Doing this is because this procedure will
be used by other functions in the next coming patches.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 27 +++
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index c6580da..ef56bf6 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -163,29 +163,40 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object 
*owner,
 memory_region_add_subregion(as, ACPI_MEMORY_HOTPLUG_BASE, state-io);
 }
 
-void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
- DeviceState *dev, Error **errp)
+static MemStatus *
+acpi_memory_get_slot_status_descriptor(MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
 {
-MemStatus *mdev;
 Error *local_err = NULL;
 int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
local_err);
 
 if (local_err) {
 error_propagate(errp, local_err);
-return;
+return NULL;
 }
 
 if (slot = mem_st-dev_count) {
 char *dev_path = object_get_canonical_path(OBJECT(dev));
-error_setg(errp, acpi_memory_plug_cb: 
+error_setg(errp, acpi_memory_get_slot_status_descriptor: 
device [%s] returned invalid memory slot[%d],
-dev_path, slot);
+   dev_path, slot);
 g_free(dev_path);
-return;
+return NULL;
 }
 
-mdev = mem_st-devs[slot];
+return mem_st-devs[slot];
+}
+
+void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+ DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
 mdev-dimm = dev;
 mdev-is_enabled = true;
 mdev-is_inserting = true;
-- 
1.8.4.2




[Qemu-devel] [PATCH Part2 04/13] acpi, mem-hotplug: Add unplug request cb for memory device.

2014-11-16 Thread Tang Chen
Memory hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.

This patch adds unplug request cb for memory device. Add a new bool
member named is_removing to MemStatus indicating that the memory slot
is being removed. Set it to true in acpi_memory_unplug_request_cb(),
and send SCI to guest.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 16 
 include/hw/acpi/memory_hotplug.h |  4 
 2 files changed, 20 insertions(+)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 9839963..3d8e398 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -211,6 +211,22 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 acpi_memory_hotplug_sci(ar, irq);
 }
 
+void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
+   MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
+mdev-is_removing = true;
+
+/* Do ACPI magic */
+acpi_memory_hotplug_sci(ar, irq);
+}
+
 static const VMStateDescription vmstate_memhp_sts = {
 .name = memory hotplug device state,
 .version_id = 1,
diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h
index 7bbf8a0..c437a85 100644
--- a/include/hw/acpi/memory_hotplug.h
+++ b/include/hw/acpi/memory_hotplug.h
@@ -11,6 +11,7 @@ typedef struct MemStatus {
 DeviceState *dimm;
 bool is_enabled;
 bool is_inserting;
+bool is_removing;
 uint32_t ost_event;
 uint32_t ost_status;
 } MemStatus;
@@ -28,6 +29,9 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner,
 
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
  DeviceState *dev, Error **errp);
+void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
+   MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp);
 
 extern const VMStateDescription vmstate_memory_hotplug;
 #define VMSTATE_MEMORY_HOTPLUG(memhp, state) \
-- 
1.8.4.2




[Qemu-devel] [PATCH Part2 00/13] QEmu memory hot unplug support.

2014-11-16 Thread Tang Chen
Memory hot unplug are both asynchronize procedures.
When the unplug operation happens, unplug request cb is called first.
And when ghest OS finished handling unplug, unplug cb will be called
to do the real removal of device.


Hu Tao (2):
  acpi, piix4: Add memory hot unplug request support for piix4.
  pc, acpi bios: Add memory hot unplug interface.

Tang Chen (11):
  acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().
  acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to get
MemStatus.
  acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for
memory hotplug.
  acpi, mem-hotplug: Add unplug request cb for memory device.
  acpi, ich9: Add memory hot unplug request support for ich9.
  pc-dimm: Add memory hot unplug request support for pc-dimm.
  acpi, mem-hotplug: Add unplug cb for memory device.
  acpi, piix4: Add memory hot unplug support for piix4.
  acpi, ich9: Add memory hot unplug support for ich9.
  pc-dimm: Add memory hot unplug support for pc-dimm.
  acpi: Add hardware implementation for memory hot unplug.

 docs/specs/acpi_mem_hotplug.txt  |  8 +++-
 hw/acpi/ich9.c   | 20 +++--
 hw/acpi/memory_hotplug.c | 97 +---
 hw/acpi/piix4.c  | 18 ++--
 hw/core/qdev.c   |  2 +-
 hw/i386/pc.c | 53 --
 hw/i386/ssdt-mem.dsl |  5 +++
 hw/i386/ssdt-misc.dsl| 13 +-
 include/hw/acpi/memory_hotplug.h |  6 +++
 include/hw/acpi/pc-hotplug.h |  2 +
 include/hw/qdev-core.h   |  1 +
 11 files changed, 194 insertions(+), 31 deletions(-)

-- 
1.8.4.2




[Qemu-devel] [PATCH Part2 11/13] pc-dimm: Add memory hot unplug support for pc-dimm.

2014-11-16 Thread Tang Chen
Implement unplug cb for pc-dimm. It remove the corresponding
memory region, and unregister vmstat. At last, it calls memory
unplug cb to reset memory status and do unparenting.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/i386/pc.c | 25 +++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index eacf290..d4450cb 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1628,6 +1628,23 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_dimm_unplug(HotplugHandler *hotplug_dev,
+   DeviceState *dev, Error **errp)
+{
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+PCDIMMDevice *dimm = PC_DIMM(dev);
+PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
+MemoryRegion *mr = ddc-get_memory_region(dimm);
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+
+memory_region_del_subregion(pcms-hotplug_memory, mr);
+vmstate_unregister_ram(mr, dev);
+
+hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
+hhc-unplug(HOTPLUG_HANDLER(pcms-acpi_dev), dev, local_err);
+}
+
 static void pc_cpu_plug(HotplugHandler *hotplug_dev,
 DeviceState *dev, Error **errp)
 {
@@ -1681,8 +1698,12 @@ static void 
pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
 static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
 DeviceState *dev, Error **errp)
 {
-error_setg(errp, acpi: device unplug for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+pc_dimm_unplug(hotplug_dev, dev, errp);
+} else {
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
-- 
1.8.4.2




[Qemu-devel] [PATCH Part2 03/13] acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for memory hotplug.

2014-11-16 Thread Tang Chen
Add a new API named acpi_memory_hotplug_sci() to send memory hotplug SCI.
Doing this is because this procedure will be used by other functions in the
next coming patches.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index ef56bf6..9839963 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -188,6 +188,12 @@ acpi_memory_get_slot_status_descriptor(MemHotplugState 
*mem_st,
 return mem_st-devs[slot];
 }
 
+static void acpi_memory_hotplug_sci(ACPIREGS *ar, qemu_irq irq)
+{
+ar-gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
+acpi_update_sci(ar, irq);
+}
+
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
  DeviceState *dev, Error **errp)
 {
@@ -201,10 +207,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 mdev-is_enabled = true;
 mdev-is_inserting = true;
 
-/* do ACPI magic */
-ar-gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
-acpi_update_sci(ar, irq);
-return;
+/* Do ACPI magic */
+acpi_memory_hotplug_sci(ar, irq);
 }
 
 static const VMStateDescription vmstate_memhp_sts = {
-- 
1.8.4.2




[Qemu-devel] [PATCH Part2 05/13] acpi, piix4: Add memory hot unplug request support for piix4.

2014-11-16 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

Call memory unplug request cb in piix4_device_unplug_request_cb().

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/piix4.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 353f91a..6c7dff9 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -360,7 +360,11 @@ static void piix4_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 {
 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
 
-if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+if (s-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_request_cb(s-ar, s-irq, s-acpi_memory_hotplug,
+  dev, errp);
+} else 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 {
-- 
1.8.4.2




[Qemu-devel] [PATCH Part2 10/13] acpi, ich9: Add memory hot unplug support for ich9.

2014-11-16 Thread Tang Chen
Call memory unplug cb in ich9_pm_device_unplug_cb().

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/ich9.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 841f57d..691299f 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -317,8 +317,14 @@ void ich9_pm_device_unplug_request_cb(ICH9LPCPMRegs *pm, 
DeviceState *dev,
 void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
   Error **errp)
 {
-error_setg(errp, acpi: device unplug for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+if (pm-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_request_cb(pm-acpi_regs, pm-irq,
+  pm-acpi_memory_hotplug, dev, errp);
+} else {
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
-- 
1.8.4.2




[Qemu-devel] [PATCH Part2 01/13] acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().

2014-11-16 Thread Tang Chen
Replace string slot in acpi_memory_plug_cb() with MACRO PC_DIMM_SLOT_PROP.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index ed39241..c6580da 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -168,7 +168,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 {
 MemStatus *mdev;
 Error *local_err = NULL;
-int slot = object_property_get_int(OBJECT(dev), slot, local_err);
+int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
+   local_err);
 
 if (local_err) {
 error_propagate(errp, local_err);
-- 
1.8.4.2




[Qemu-devel] [PATCH Part2 06/13] acpi, ich9: Add memory hot unplug request support for ich9.

2014-11-16 Thread Tang Chen
Call memory unplug request cb in ich9_pm_device_unplug_request_cb().

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/ich9.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index c48d176..841f57d 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -304,8 +304,14 @@ 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 (pm-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_request_cb(pm-acpi_regs, pm-irq,
+  pm-acpi_memory_hotplug, 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,
-- 
1.8.4.2




[Qemu-devel] [PATCH Part2 12/13] acpi: Add hardware implementation for memory hot unplug.

2014-11-16 Thread Tang Chen
This patch adds a new bit to memory hotplug IO port indicating that
ej0 has been evaluated by guest OS. And call pc-dimm unplug cb to do
the real removal.


Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 docs/specs/acpi_mem_hotplug.txt |  8 ++--
 hw/acpi/memory_hotplug.c| 23 ---
 hw/core/qdev.c  |  2 +-
 include/hw/qdev-core.h  |  1 +
 4 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/docs/specs/acpi_mem_hotplug.txt b/docs/specs/acpi_mem_hotplug.txt
index 1290994..28a1ffa 100644
--- a/docs/specs/acpi_mem_hotplug.txt
+++ b/docs/specs/acpi_mem_hotplug.txt
@@ -19,7 +19,9 @@ Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte 
access):
   1: Device insert event, used to distinguish device for which
  no device check event to OSPM was issued.
  It's valid only when bit 1 is set.
-  2-7: reserved and should be ignored by OSPM
+  2: Device remove event, used to indicate that device is being
+removed.
+  3-7: reserved and should be ignored by OSPM
   [0x15-0x17] reserved
 
   write access:
@@ -35,7 +37,9 @@ Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte 
access):
   1: if set to 1 clears device insert event, set by OSPM
  after it has emitted device check event for the
  selected memory device
-  2-7: reserved, OSPM must clear them before writing to register
+  2: set by hardware after it has emitted device eject event for
+selected memory device
+  3-7: reserved, OSPM must clear them before writing to register
 
 Selecting memory device slot beyond present range has no effect on platform:
- write accesses to memory hot-plug registers not documented above are
diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 2b0c8ca..b9e8752 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -2,6 +2,7 @@
 #include hw/acpi/pc-hotplug.h
 #include hw/mem/pc-dimm.h
 #include hw/boards.h
+#include hw/qdev-core.h
 #include trace.h
 #include qapi-event.h
 
@@ -75,6 +76,7 @@ static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr 
addr,
 case 0x14: /* pack and return is_* fields */
 val |= mdev-is_enabled   ? 1 : 0;
 val |= mdev-is_inserting ? 2 : 0;
+val |= mdev-is_removing  ? 4 : 0;
 trace_mhp_acpi_read_flags(mem_st-selector, val);
 break;
 default:
@@ -90,6 +92,8 @@ static void acpi_memory_hotplug_write(void *opaque, hwaddr 
addr, uint64_t data,
 MemHotplugState *mem_st = opaque;
 MemStatus *mdev;
 ACPIOSTInfo *info;
+DeviceState *dev = NULL;
+HotplugHandler *hotplug_ctrl = NULL;
 
 if (!mem_st-dev_count) {
 return;
@@ -121,21 +125,34 @@ static void acpi_memory_hotplug_write(void *opaque, 
hwaddr addr, uint64_t data,
 mdev = mem_st-devs[mem_st-selector];
 mdev-ost_status = data;
 trace_mhp_acpi_write_ost_status(mem_st-selector, mdev-ost_status);
-/* TODO: implement memory removal on guest signal */
 
 info = acpi_memory_device_status(mem_st-selector, mdev);
 qapi_event_send_acpi_device_ost(info, error_abort);
 qapi_free_ACPIOSTInfo(info);
 break;
-case 0x14:
+case 0x14: /* set is_* fields */
 mdev = mem_st-devs[mem_st-selector];
+
 if (data  2) { /* clear insert event */
 mdev-is_inserting  = false;
 trace_mhp_acpi_clear_insert_evt(mem_st-selector);
+} else if (data  4) { /* request removal of device */
+/*
+ * QEmu memory hot unplug is an asynchronized procedure. QEmu first
+ * calls pc-dimm unplug request cb to send a SCI to guest. When the
+ * Guest OS finished handling the SCI, it evaluates ACPI ej0, and
+ * QEmu calls pc-dimm unplug cb to remove memory device.
+ */
+dev = DEVICE(mdev-dimm);
+hotplug_ctrl = qdev_get_hotplug_handler(dev);
+/* Call pc-dimm unplug cb. */
+hotplug_handler_unplug(hotplug_ctrl, dev, NULL);
 }
+
+break;
+default:
 break;
 }
-
 }
 static const MemoryRegionOps acpi_memory_hotplug_ops = {
 .read = acpi_memory_hotplug_read,
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 413b413..12a3557 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -223,7 +223,7 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int 
alias_id,
 dev-alias_required_for_version = required_for_version;
 }
 
-static HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)
+HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)
 {
 HotplugHandler *hotplug_ctrl = NULL;
 
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index d3a2940..128fcfc 100644
--- a/include/hw/qdev-core.h
+++ b

[Qemu-devel] [PATCH Part2 07/13] pc-dimm: Add memory hot unplug request support for pc-dimm.

2014-11-16 Thread Tang Chen
Implement memory unplug request cb for pc-dimm, and call it in
pc_machine_device_unplug_request_cb().

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/i386/pc.c | 28 ++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index d5073df..eacf290 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1608,6 +1608,26 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_dimm_unplug_request(HotplugHandler *hotplug_dev,
+   DeviceState *dev, Error **errp)
+{
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+if (!pcms-acpi_dev) {
+error_setg(local_err,
+   memory hotplug 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_cpu_plug(HotplugHandler *hotplug_dev,
 DeviceState *dev, Error **errp)
 {
@@ -1650,8 +1670,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_PC_DIMM)) {
+pc_dimm_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.8.4.2




[Qemu-devel] [PATCH Part2 08/13] acpi, mem-hotplug: Add unplug cb for memory device.

2014-11-16 Thread Tang Chen
Reset all memory status, and unparent the memory device.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 16 
 include/hw/acpi/memory_hotplug.h |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 3d8e398..2b0c8ca 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -227,6 +227,22 @@ void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq 
irq,
 acpi_memory_hotplug_sci(ar, irq);
 }
 
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq,
+   MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
+mdev-is_removing = false;
+mdev-is_enabled = false;
+object_unparent(OBJECT(mdev-dimm));
+mdev-dimm = NULL;
+}
+
 static const VMStateDescription vmstate_memhp_sts = {
 .name = memory hotplug device state,
 .version_id = 1,
diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h
index c437a85..6b8d9f7 100644
--- a/include/hw/acpi/memory_hotplug.h
+++ b/include/hw/acpi/memory_hotplug.h
@@ -32,6 +32,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 void acpi_memory_unplug_request_cb(ACPIREGS *ar, qemu_irq irq,
MemHotplugState *mem_st,
DeviceState *dev, Error **errp);
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp);
 
 extern const VMStateDescription vmstate_memory_hotplug;
 #define VMSTATE_MEMORY_HOTPLUG(memhp, state) \
-- 
1.8.4.2




[Qemu-devel] [PATCH Part2 13/13] pc, acpi bios: Add memory hot unplug interface.

2014-11-16 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

This patch implements MEMORY_SLOT_EJECT_METHOD according to ACPI spec.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/i386/ssdt-mem.dsl |  5 +
 hw/i386/ssdt-misc.dsl| 13 -
 include/hw/acpi/pc-hotplug.h |  2 ++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/hw/i386/ssdt-mem.dsl b/hw/i386/ssdt-mem.dsl
index 22ff5dd..1416639 100644
--- a/hw/i386/ssdt-mem.dsl
+++ b/hw/i386/ssdt-mem.dsl
@@ -43,6 +43,7 @@ DefinitionBlock (ssdt-mem.aml, SSDT, 0x02, BXPC, 
CSSDT, 0x1)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_STATUS_METHOD, 
MethodObj)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD, MethodObj)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_PROXIMITY_METHOD, 
MethodObj)
+External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD, 
MethodObj)
 
 Scope(\_SB) {
 /*  v-- DO NOT EDIT --v */
@@ -72,6 +73,10 @@ DefinitionBlock (ssdt-mem.aml, SSDT, 0x02, BXPC, 
CSSDT, 0x1)
 Method(_OST, 3) {
 \_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD(_UID, 
Arg0, Arg1, Arg2)
 }
+
+Method(_EJ0, 1) {
+\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD(_UID, 
Arg0)
+}
 }
 }
 }
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 0fd4480..7b29539 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -156,6 +156,7 @@ DefinitionBlock (ssdt-misc.aml, SSDT, 0x01, BXPC, 
BXSSDTSUSP, 0x1)
 Offset(20),
 MEMORY_SLOT_ENABLED,  1, // 1 if enabled, read only
 MEMORY_SLOT_INSERT_EVENT, 1, // (read) 1 if has a insert 
event. (write) 1 to clear event
+MEMORY_SLOT_REMOVE_EVENT, 1, // 1 if DIMM has a remove 
request, read only
 }
 
 Mutex (MEMORY_SLOT_LOCK, 0)
@@ -174,11 +175,14 @@ DefinitionBlock (ssdt-misc.aml, SSDT, 0x01, BXPC, 
BXSSDTSUSP, 0x1)
 Acquire(MEMORY_SLOT_LOCK, 0x)
 while (LLess(Local0, MEMORY_SLOTS_NUMBER)) {
 Store(Local0, MEMORY_SLOT_SLECTOR) // select Local0 DIMM
+
 If (LEqual(MEMORY_SLOT_INSERT_EVENT, One)) { // Memory 
device needs check
 MEMORY_SLOT_NOTIFY_METHOD(Local0, 1)
 Store(1, MEMORY_SLOT_INSERT_EVENT)
+} Elseif (LEqual(MEMORY_SLOT_REMOVE_EVENT, One)) { // 
Ejection request
+MEMORY_SLOT_NOTIFY_METHOD(Local0, 3)
 }
-// TODO: handle memory eject request
+
 Add(Local0, One, Local0) // goto next DIMM
 }
 Release(MEMORY_SLOT_LOCK)
@@ -278,6 +282,13 @@ DefinitionBlock (ssdt-misc.aml, SSDT, 0x01, BXPC, 
BXSSDTSUSP, 0x1)
 Store(Arg2, MEMORY_SLOT_OST_STATUS)
 Release(MEMORY_SLOT_LOCK)
 }
+
+Method(MEMORY_SLOT_EJECT_METHOD, 2) {
+Acquire(MEMORY_SLOT_LOCK, 0x)
+Store(ToInteger(Arg0), MEMORY_SLOT_SLECTOR) // select DIMM
+Store(One, MEMORY_SLOT_REMOVE_EVENT)
+Release(MEMORY_SLOT_LOCK)
+}
 } // Device()
 } // Scope()
 }
diff --git a/include/hw/acpi/pc-hotplug.h b/include/hw/acpi/pc-hotplug.h
index b9db295..b61b6ea 100644
--- a/include/hw/acpi/pc-hotplug.h
+++ b/include/hw/acpi/pc-hotplug.h
@@ -42,6 +42,7 @@
 #define MEMORY_SLOT_PROXIMITYMPX
 #define MEMORY_SLOT_ENABLED  MES
 #define MEMORY_SLOT_INSERT_EVENT MINS
+#define MEMORY_SLOT_REMOVE_EVENT MRMV
 #define MEMORY_SLOT_SLECTOR  MSEL
 #define MEMORY_SLOT_OST_EVENTMOEV
 #define MEMORY_SLOT_OST_STATUS   MOSC
@@ -50,6 +51,7 @@
 #define MEMORY_SLOT_CRS_METHOD   MCRS
 #define MEMORY_SLOT_OST_METHOD   MOST
 #define MEMORY_SLOT_PROXIMITY_METHOD MPXM
+#define MEMORY_SLOT_EJECT_METHOD MEJ0
 #define MEMORY_SLOT_NOTIFY_METHODMTFY
 #define MEMORY_SLOT_SCAN_METHOD  MSCN
 
-- 
1.8.4.2




[Qemu-devel] [PATCH Part2 09/13] acpi, piix4: Add memory hot unplug support for piix4.

2014-11-16 Thread Tang Chen
Call memory unplug cb in piix4_device_unplug_cb().

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/piix4.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 6c7dff9..440c9e8 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -376,8 +376,16 @@ static void piix4_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
 {
-error_setg(errp, acpi: device unplug for not supported device
-type: %s, object_get_typename(OBJECT(dev)));
+PIIX4PMState *s = PIIX4_PM(hotplug_dev);
+
+if (s-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_cb(s-ar, s-irq, s-acpi_memory_hotplug,
+  dev, errp);
+} else {
+error_setg(errp, acpi: device unplug for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
 }
 
 static void piix4_update_bus_hotplug(PCIBus *pci_bus, void *opaque)
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 01/10] acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().

2014-11-04 Thread Tang Chen
Replace string slot in acpi_memory_plug_cb() with MACRO PC_DIMM_SLOT_PROP.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index ed39241..c6580da 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -168,7 +168,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 {
 MemStatus *mdev;
 Error *local_err = NULL;
-int slot = object_property_get_int(OBJECT(dev), slot, local_err);
+int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
+   local_err);
 
 if (local_err) {
 error_propagate(errp, local_err);
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 02/10] acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to get MemStatus.

2014-11-04 Thread Tang Chen
Add a new API named acpi_memory_get_slot_status_descriptor() to obtain
a single memory slot status. Doing this is because this procedure will
be used by other functions in the next coming patches.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 27 +++
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index c6580da..ef56bf6 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -163,29 +163,40 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object 
*owner,
 memory_region_add_subregion(as, ACPI_MEMORY_HOTPLUG_BASE, state-io);
 }
 
-void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
- DeviceState *dev, Error **errp)
+static MemStatus *
+acpi_memory_get_slot_status_descriptor(MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
 {
-MemStatus *mdev;
 Error *local_err = NULL;
 int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
local_err);
 
 if (local_err) {
 error_propagate(errp, local_err);
-return;
+return NULL;
 }
 
 if (slot = mem_st-dev_count) {
 char *dev_path = object_get_canonical_path(OBJECT(dev));
-error_setg(errp, acpi_memory_plug_cb: 
+error_setg(errp, acpi_memory_get_slot_status_descriptor: 
device [%s] returned invalid memory slot[%d],
-dev_path, slot);
+   dev_path, slot);
 g_free(dev_path);
-return;
+return NULL;
 }
 
-mdev = mem_st-devs[slot];
+return mem_st-devs[slot];
+}
+
+void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+ DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
 mdev-dimm = dev;
 mdev-is_enabled = true;
 mdev-is_inserting = true;
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 04/10] acpi, mem-hotplug: Add acpi_memory_unplug_cb() to implement memory unplug.

2014-11-04 Thread Tang Chen
Add a new bool member named is_removing to MemStatus indicating that
the memory solt is being removed. Set it to true in acpi_memory_unplug_cb(),
and send SCI to guest.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 15 +++
 include/hw/acpi/memory_hotplug.h |  3 +++
 2 files changed, 18 insertions(+)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 9839963..01dea6c 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -211,6 +211,21 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 acpi_memory_hotplug_sci(ar, irq);
 }
 
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
+mdev-is_removing = true;
+
+/* Do ACPI magic */
+acpi_memory_hotplug_sci(ar, irq);
+}
+
 static const VMStateDescription vmstate_memhp_sts = {
 .name = memory hotplug device state,
 .version_id = 1,
diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h
index 7bbf8a0..fe41268 100644
--- a/include/hw/acpi/memory_hotplug.h
+++ b/include/hw/acpi/memory_hotplug.h
@@ -11,6 +11,7 @@ typedef struct MemStatus {
 DeviceState *dimm;
 bool is_enabled;
 bool is_inserting;
+bool is_removing;
 uint32_t ost_event;
 uint32_t ost_status;
 } MemStatus;
@@ -28,6 +29,8 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner,
 
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
  DeviceState *dev, Error **errp);
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp);
 
 extern const VMStateDescription vmstate_memory_hotplug;
 #define VMSTATE_MEMORY_HOTPLUG(memhp, state) \
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 05/10] acpi, piix4: Add memory hot unplug support for piix4.

2014-11-04 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

Implement acpi_memory_unplug_cb(), sending an sci to guest to trigger
memory hot-remove, and call it in piix4_device_unplug_cb().

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/piix4.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 78c0a6d..92b29b7 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -360,7 +360,11 @@ static void piix4_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 {
 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
 
-if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+if (s-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_cb(s-ar, s-irq, s-acpi_memory_hotplug, dev,
+  errp);
+} else 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 {
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 03/10] acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for memory hotplug.

2014-11-04 Thread Tang Chen
Add a new API named acpi_memory_hotplug_sci() to send memory hotplug SCI.
Doing this is because this procedure will be used by other functions in the
next coming patches.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index ef56bf6..9839963 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -188,6 +188,12 @@ acpi_memory_get_slot_status_descriptor(MemHotplugState 
*mem_st,
 return mem_st-devs[slot];
 }
 
+static void acpi_memory_hotplug_sci(ACPIREGS *ar, qemu_irq irq)
+{
+ar-gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
+acpi_update_sci(ar, irq);
+}
+
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
  DeviceState *dev, Error **errp)
 {
@@ -201,10 +207,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 mdev-is_enabled = true;
 mdev-is_inserting = true;
 
-/* do ACPI magic */
-ar-gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
-acpi_update_sci(ar, irq);
-return;
+/* Do ACPI magic */
+acpi_memory_hotplug_sci(ar, irq);
 }
 
 static const VMStateDescription vmstate_memhp_sts = {
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 06/10] acpi, ich9: Add memory hot unplug support for ich9.

2014-11-04 Thread Tang Chen
Implement ich9_pm_device_unplug_cb() to support memory hot-remove,
calling acpi_memory_unplug_cb(). And itself will be called in
ich9_device_unplug_cb().

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/ich9.c | 12 
 hw/isa/lpc_ich9.c  |  5 +++--
 include/hw/acpi/ich9.h |  2 ++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index ea991a3..68cc169 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -301,6 +301,18 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState 
*dev, Error **errp)
 }
 }
 
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error 
**errp)
+{
+if (pm-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_cb(pm-acpi_regs, pm-irq, 
pm-acpi_memory_hotplug,
+  dev, errp);
+} else {
+error_setg(errp, acpi: device unplug request for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
+}
+
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
 {
 ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 530b074..75f28d1 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -610,8 +610,9 @@ static void ich9_device_plug_cb(HotplugHandler *hotplug_dev,
 static void ich9_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)));
+ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+ich9_pm_device_unplug_cb(lpc-pm, dev, errp);
 }
 
 static bool ich9_rst_cnt_needed(void *opaque)
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index fe975e6..92f19de 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -59,6 +59,8 @@ extern const VMStateDescription vmstate_ich9_pm;
 void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp);
 
 void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp);
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+  Error **errp);
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
 #endif /* HW_ACPI_ICH9_H */
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 00/10] QEmu memory hot unplug support.

2014-11-04 Thread Tang Chen
This patch-set implements memory hot-remove for QEmu. 

Rebased on Igor's asynchronize hotplug framework (qemu v2.1.2, the latest).

Approach: QEmu sets GPE status bit, then triggers SCI to notify guest os.
Guest os checks device status, and free memory resource if possible,
then generate OST.

NOTE: In this version, memory hot-remove is independent from _OST, 
  following Igor's comments. Will implement _OST for memory hot-remove
  soon if this part is OK.

Change log v3 - v4 (RESEND):
1. Add new patch 1 ~ 4, fix some small problems in coding.
2. In patch 9, make memory hot-remove independent from _OST.
3. In patch 9, add comment for is_removing flag to document.
4. In patch 10, use macro instead of number.
5. Remove original patch 8 and 12 to coincident with asynchronize
   hotplug framework.

Hu Tao (4):
  acpi, piix4: Add memory hot unplug support for piix4.
  pc: Add memory hot unplug support for pc machine.
  pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.
  pc, acpi bios: Add memory hot unplug interface.

Tang Chen (6):
  acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().
  acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to get
MemStatus.
  acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for
memory hotplug.
  acpi, mem-hotplug: Add acpi_memory_unplug_cb() to implement memory
unplug.
  acpi, ich9: Add memory hot unplug support for ich9.
  acpi: Add hardware implementation for memory hot unplug.

 docs/specs/acpi_mem_hotplug.txt  |  8 +++--
 hw/acpi/ich9.c   | 12 +++
 hw/acpi/memory_hotplug.c | 71 +++-
 hw/acpi/piix4.c  |  6 +++-
 hw/i386/pc.c | 31 ++
 hw/i386/ssdt-mem.dsl |  5 +++
 hw/i386/ssdt-misc.dsl| 13 +++-
 hw/isa/lpc_ich9.c|  5 +--
 hw/mem/pc-dimm.c | 10 ++
 include/hw/acpi/ich9.h   |  2 ++
 include/hw/acpi/memory_hotplug.h |  3 ++
 include/hw/acpi/pc-hotplug.h |  2 ++
 12 files changed, 146 insertions(+), 22 deletions(-)

-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 10/10] pc, acpi bios: Add memory hot unplug interface.

2014-11-04 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

This patch implements MEMORY_SLOT_EJECT_METHOD according to ACPI spec.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/i386/ssdt-mem.dsl |  5 +
 hw/i386/ssdt-misc.dsl| 13 -
 include/hw/acpi/pc-hotplug.h |  2 ++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/hw/i386/ssdt-mem.dsl b/hw/i386/ssdt-mem.dsl
index 22ff5dd..1416639 100644
--- a/hw/i386/ssdt-mem.dsl
+++ b/hw/i386/ssdt-mem.dsl
@@ -43,6 +43,7 @@ DefinitionBlock (ssdt-mem.aml, SSDT, 0x02, BXPC, 
CSSDT, 0x1)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_STATUS_METHOD, 
MethodObj)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD, MethodObj)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_PROXIMITY_METHOD, 
MethodObj)
+External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD, 
MethodObj)
 
 Scope(\_SB) {
 /*  v-- DO NOT EDIT --v */
@@ -72,6 +73,10 @@ DefinitionBlock (ssdt-mem.aml, SSDT, 0x02, BXPC, 
CSSDT, 0x1)
 Method(_OST, 3) {
 \_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD(_UID, 
Arg0, Arg1, Arg2)
 }
+
+Method(_EJ0, 1) {
+\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD(_UID, 
Arg0)
+}
 }
 }
 }
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 0fd4480..7b29539 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -156,6 +156,7 @@ DefinitionBlock (ssdt-misc.aml, SSDT, 0x01, BXPC, 
BXSSDTSUSP, 0x1)
 Offset(20),
 MEMORY_SLOT_ENABLED,  1, // 1 if enabled, read only
 MEMORY_SLOT_INSERT_EVENT, 1, // (read) 1 if has a insert 
event. (write) 1 to clear event
+MEMORY_SLOT_REMOVE_EVENT, 1, // 1 if DIMM has a remove 
request, read only
 }
 
 Mutex (MEMORY_SLOT_LOCK, 0)
@@ -174,11 +175,14 @@ DefinitionBlock (ssdt-misc.aml, SSDT, 0x01, BXPC, 
BXSSDTSUSP, 0x1)
 Acquire(MEMORY_SLOT_LOCK, 0x)
 while (LLess(Local0, MEMORY_SLOTS_NUMBER)) {
 Store(Local0, MEMORY_SLOT_SLECTOR) // select Local0 DIMM
+
 If (LEqual(MEMORY_SLOT_INSERT_EVENT, One)) { // Memory 
device needs check
 MEMORY_SLOT_NOTIFY_METHOD(Local0, 1)
 Store(1, MEMORY_SLOT_INSERT_EVENT)
+} Elseif (LEqual(MEMORY_SLOT_REMOVE_EVENT, One)) { // 
Ejection request
+MEMORY_SLOT_NOTIFY_METHOD(Local0, 3)
 }
-// TODO: handle memory eject request
+
 Add(Local0, One, Local0) // goto next DIMM
 }
 Release(MEMORY_SLOT_LOCK)
@@ -278,6 +282,13 @@ DefinitionBlock (ssdt-misc.aml, SSDT, 0x01, BXPC, 
BXSSDTSUSP, 0x1)
 Store(Arg2, MEMORY_SLOT_OST_STATUS)
 Release(MEMORY_SLOT_LOCK)
 }
+
+Method(MEMORY_SLOT_EJECT_METHOD, 2) {
+Acquire(MEMORY_SLOT_LOCK, 0x)
+Store(ToInteger(Arg0), MEMORY_SLOT_SLECTOR) // select DIMM
+Store(One, MEMORY_SLOT_REMOVE_EVENT)
+Release(MEMORY_SLOT_LOCK)
+}
 } // Device()
 } // Scope()
 }
diff --git a/include/hw/acpi/pc-hotplug.h b/include/hw/acpi/pc-hotplug.h
index b9db295..b61b6ea 100644
--- a/include/hw/acpi/pc-hotplug.h
+++ b/include/hw/acpi/pc-hotplug.h
@@ -42,6 +42,7 @@
 #define MEMORY_SLOT_PROXIMITYMPX
 #define MEMORY_SLOT_ENABLED  MES
 #define MEMORY_SLOT_INSERT_EVENT MINS
+#define MEMORY_SLOT_REMOVE_EVENT MRMV
 #define MEMORY_SLOT_SLECTOR  MSEL
 #define MEMORY_SLOT_OST_EVENTMOEV
 #define MEMORY_SLOT_OST_STATUS   MOSC
@@ -50,6 +51,7 @@
 #define MEMORY_SLOT_CRS_METHOD   MCRS
 #define MEMORY_SLOT_OST_METHOD   MOST
 #define MEMORY_SLOT_PROXIMITY_METHOD MPXM
+#define MEMORY_SLOT_EJECT_METHOD MEJ0
 #define MEMORY_SLOT_NOTIFY_METHODMTFY
 #define MEMORY_SLOT_SCAN_METHOD  MSCN
 
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 07/10] pc: Add memory hot unplug support for pc machine.

2014-11-04 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

Implement device unplug callback for PCMachine. And it now only support
pc-dimm hot-remove. The callback will call piix4 or ich9 callbacks introduced
in previous patches.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/i386/pc.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 1205db8..2c26749 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -61,6 +61,8 @@
 #include hw/mem/pc-dimm.h
 #include trace.h
 #include qapi/visitor.h
+#include hw/acpi/piix4.h
+#include hw/i386/ich9.h
 
 /* debug PC/ISA interrupts */
 //#define DEBUG_IRQ
@@ -1637,6 +1639,26 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_dimm_unplug(HotplugHandler *hotplug_dev,
+   DeviceState *dev, Error **errp)
+{
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+if (!pcms-acpi_dev) {
+error_setg(local_err,
+   memory hotplug 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)
 {
@@ -1647,6 +1669,14 @@ static void pc_machine_device_plug_cb(HotplugHandler 
*hotplug_dev,
 }
 }
 
+static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
+DeviceState *dev, Error **errp)
+{
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+pc_dimm_unplug(hotplug_dev, dev, errp);
+}
+}
+
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
  DeviceState *dev)
 {
@@ -1753,6 +1783,7 @@ static void pc_machine_class_init(ObjectClass *oc, void 
*data)
 pcmc-get_hotplug_handler = mc-get_hotplug_handler;
 mc-get_hotplug_handler = pc_get_hotpug_handler;
 hc-plug = pc_machine_device_plug_cb;
+hc-unplug = pc_machine_device_unplug_cb;
 }
 
 static const TypeInfo pc_machine_info = {
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 08/10] pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.

2014-11-04 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

Implement unrealize function for pc-dimm device. It remove subregion from
hotplug region, and delete ram address range from guest ram list.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/mem/pc-dimm.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index ee802bb..b105871 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -270,12 +270,22 @@ static MemoryRegion 
*pc_dimm_get_memory_region(PCDIMMDevice *dimm)
 return host_memory_backend_get_memory(dimm-hostmem, error_abort);
 }
 
+static void pc_dimm_unrealize(DeviceState *dev, Error **errp)
+{
+PCDIMMDevice *dimm = PC_DIMM(dev);
+MemoryRegion *mr = pc_dimm_get_memory_region(dimm);
+
+memory_region_del_subregion(mr-container, mr);
+vmstate_unregister_ram(mr, dev);
+}
+
 static void pc_dimm_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
 PCDIMMDeviceClass *ddc = PC_DIMM_CLASS(oc);
 
 dc-realize = pc_dimm_realize;
+dc-unrealize = pc_dimm_unrealize;
 dc-props = pc_dimm_properties;
 
 ddc-get_memory_region = pc_dimm_get_memory_region;
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 09/10] acpi: Add hardware implementation for memory hot unplug.

2014-11-04 Thread Tang Chen
This patch adds a new bit to memory hotplug IO port indicating that
memory device is be removed. And set MemStatus-is_removing to false
when the bit is written.

NOTE: MemStatus-is_removing is set to true in acpi_memory_unplug_cb()
when doing memory hot-remove with device_del command.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 docs/specs/acpi_mem_hotplug.txt |  8 ++--
 hw/acpi/memory_hotplug.c| 14 +++---
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/docs/specs/acpi_mem_hotplug.txt b/docs/specs/acpi_mem_hotplug.txt
index 1290994..5524c30 100644
--- a/docs/specs/acpi_mem_hotplug.txt
+++ b/docs/specs/acpi_mem_hotplug.txt
@@ -19,7 +19,9 @@ Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte 
access):
   1: Device insert event, used to distinguish device for which
  no device check event to OSPM was issued.
  It's valid only when bit 1 is set.
-  2-7: reserved and should be ignored by OSPM
+  2: Device remove event, used to indicate that device is being
+removed.
+  3-7: reserved and should be ignored by OSPM
   [0x15-0x17] reserved
 
   write access:
@@ -35,7 +37,9 @@ Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte 
access):
   1: if set to 1 clears device insert event, set by OSPM
  after it has emitted device check event for the
  selected memory device
-  2-7: reserved, OSPM must clear them before writing to register
+  2: set by hardware after it has emitted devive eject event for
+selected memory device
+  3-7: reserved, OSPM must clear them before writing to register
 
 Selecting memory device slot beyond present range has no effect on platform:
- write accesses to memory hot-plug registers not documented above are
diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 01dea6c..a745bb0 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -75,6 +75,7 @@ static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr 
addr,
 case 0x14: /* pack and return is_* fields */
 val |= mdev-is_enabled   ? 1 : 0;
 val |= mdev-is_inserting ? 2 : 0;
+val |= mdev-is_removing  ? 4 : 0;
 trace_mhp_acpi_read_flags(mem_st-selector, val);
 break;
 default:
@@ -121,21 +122,28 @@ static void acpi_memory_hotplug_write(void *opaque, 
hwaddr addr, uint64_t data,
 mdev = mem_st-devs[mem_st-selector];
 mdev-ost_status = data;
 trace_mhp_acpi_write_ost_status(mem_st-selector, mdev-ost_status);
-/* TODO: implement memory removal on guest signal */
 
 info = acpi_memory_device_status(mem_st-selector, mdev);
 qapi_event_send_acpi_device_ost(info, error_abort);
 qapi_free_ACPIOSTInfo(info);
 break;
-case 0x14:
+case 0x14: /* set is_* fields */
 mdev = mem_st-devs[mem_st-selector];
+
 if (data  2) { /* clear insert event */
 mdev-is_inserting  = false;
 trace_mhp_acpi_clear_insert_evt(mem_st-selector);
+} else if (data  4) { /* request removal of device */
+mdev-is_enabled = false;
+mdev-is_removing = false;
+object_unparent(OBJECT(mdev-dimm));
+mdev-dimm = NULL;
 }
+
+break;
+default:
 break;
 }
-
 }
 static const MemoryRegionOps acpi_memory_hotplug_ops = {
 .read = acpi_memory_hotplug_read,
-- 
1.8.4.2




Re: [Qemu-devel] [RESEND PATCH v4 00/10] QEmu memory hot unplug support.

2014-10-29 Thread Tang Chen


On 10/29/2014 05:37 PM, Igor Mammedov wrote:

On Wed, 22 Oct 2014 18:00:02 +0800
Tang Chen tangc...@cn.fujitsu.com wrote:


This patch-set implements memory hot-remove for QEmu.

Rebased on Igor's asynchronize hotplug framework (qemu v2.1.2, the
latest).

Approach: QEmu sets GPE status bit, then triggers SCI to notify guest
os. Guest os checks device status, and free memory resource if
possible, then generate OST.

NOTE: In this version, memory hot-remove is independent from _OST,
   following Igor's comments.
   Patches _OST handling for platforms supporting _OST will come
   soon when Igor finishes his refacting for framework of hotplug.

Refactoring is complete and in tree since 14/Oct,
Please rebase taking in account changes I've requested before.


Sure, will send a new patch-set soon.

Thanks.




Change log v3 - v4 (RESEND):
1. Add new patch 1 ~ 4, fix some small problems in coding.
2. In patch 9, make memory hot-remove independent from _OST.
3. In patch 9, add comment for is_removing flag to document.
4. In patch 10, use macro instead of number.
5. Remove original patch 8 and 12 to coincident with asynchronize
hotplug framework.

Hu Tao (4):
   acpi, piix4: Add memory hot unplug support for piix4.
   pc: Add memory hot unplug support for pc machine.
   pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.
   pc, acpi bios: Add memory hot unplug interface.

Tang Chen (6):
   acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().
   acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to
get MemStatus.
   acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for
 memory hotplug.
   acpi, mem-hotplug: Add acpi_memory_unplug_cb() to implement memory
 unplug.
   acpi, ich9: Add memory hot unplug support for ich9.
   acpi: Add hardware implementation for memory hot unplug.

  docs/specs/acpi_mem_hotplug.txt  |  8 +++--
  hw/acpi/ich9.c   | 12 +++
  hw/acpi/memory_hotplug.c | 71
+++-
hw/acpi/piix4.c  |  6 +++-
hw/i386/pc.c | 31 ++
hw/i386/ssdt-mem.dsl |  5 +++
hw/i386/ssdt-misc.dsl| 13 +++-
hw/isa/lpc_ich9.c|  5 +--
hw/mem/pc-dimm.c | 10 ++
include/hw/acpi/ich9.h   |  2 ++
include/hw/acpi/memory_hotplug.h |  3 ++
include/hw/acpi/pc-hotplug.h |  2 ++ 12 files changed, 146
insertions(+), 22 deletions(-)


.






[Qemu-devel] [RESEND PATCH v4 03/10] acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for memory hotplug.

2014-10-22 Thread Tang Chen
Add a new API named acpi_memory_hotplug_sci() to send memory hotplug SCI.
Doing this is because this procedure will be used by other functions in the
next coming patches.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index ef56bf6..9839963 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -188,6 +188,12 @@ acpi_memory_get_slot_status_descriptor(MemHotplugState 
*mem_st,
 return mem_st-devs[slot];
 }
 
+static void acpi_memory_hotplug_sci(ACPIREGS *ar, qemu_irq irq)
+{
+ar-gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
+acpi_update_sci(ar, irq);
+}
+
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
  DeviceState *dev, Error **errp)
 {
@@ -201,10 +207,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 mdev-is_enabled = true;
 mdev-is_inserting = true;
 
-/* do ACPI magic */
-ar-gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
-acpi_update_sci(ar, irq);
-return;
+/* Do ACPI magic */
+acpi_memory_hotplug_sci(ar, irq);
 }
 
 static const VMStateDescription vmstate_memhp_sts = {
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 05/10] acpi, piix4: Add memory hot unplug support for piix4.

2014-10-22 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

Implement acpi_memory_unplug_cb(), sending an sci to guest to trigger
memory hot-remove, and call it in piix4_device_unplug_cb().

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/piix4.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 1aa156b..d27fa5f 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -359,7 +359,11 @@ static void piix4_device_unplug_request_cb(HotplugHandler 
*hotplug_dev,
 {
 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
 
-if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+if (s-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_cb(s-ar, s-irq, s-acpi_memory_hotplug, dev,
+  errp);
+} else 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 {
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 00/10] QEmu memory hot unplug support.

2014-10-22 Thread Tang Chen
This patch-set implements memory hot-remove for QEmu. 

Rebased on Igor's asynchronize hotplug framework (qemu v2.1.2, the latest).

Approach: QEmu sets GPE status bit, then triggers SCI to notify guest os.
Guest os checks device status, and free memory resource if possible,
then generate OST.

NOTE: In this version, memory hot-remove is independent from _OST, 
  following Igor's comments.
  Patches _OST handling for platforms supporting _OST will come 
  soon when Igor finishes his refacting for framework of hotplug.

Change log v3 - v4 (RESEND):
1. Add new patch 1 ~ 4, fix some small problems in coding.
2. In patch 9, make memory hot-remove independent from _OST.
3. In patch 9, add comment for is_removing flag to document.
4. In patch 10, use macro instead of number.
5. Remove original patch 8 and 12 to coincident with asynchronize
   hotplug framework.

Hu Tao (4):
  acpi, piix4: Add memory hot unplug support for piix4.
  pc: Add memory hot unplug support for pc machine.
  pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.
  pc, acpi bios: Add memory hot unplug interface.

Tang Chen (6):
  acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().
  acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to get
MemStatus.
  acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for
memory hotplug.
  acpi, mem-hotplug: Add acpi_memory_unplug_cb() to implement memory
unplug.
  acpi, ich9: Add memory hot unplug support for ich9.
  acpi: Add hardware implementation for memory hot unplug.

 docs/specs/acpi_mem_hotplug.txt  |  8 +++--
 hw/acpi/ich9.c   | 12 +++
 hw/acpi/memory_hotplug.c | 71 +++-
 hw/acpi/piix4.c  |  6 +++-
 hw/i386/pc.c | 31 ++
 hw/i386/ssdt-mem.dsl |  5 +++
 hw/i386/ssdt-misc.dsl| 13 +++-
 hw/isa/lpc_ich9.c|  5 +--
 hw/mem/pc-dimm.c | 10 ++
 include/hw/acpi/ich9.h   |  2 ++
 include/hw/acpi/memory_hotplug.h |  3 ++
 include/hw/acpi/pc-hotplug.h |  2 ++
 12 files changed, 146 insertions(+), 22 deletions(-)

-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 01/10] acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().

2014-10-22 Thread Tang Chen
Replace string slot in acpi_memory_plug_cb() with MACRO PC_DIMM_SLOT_PROP.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index ed39241..c6580da 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -168,7 +168,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 {
 MemStatus *mdev;
 Error *local_err = NULL;
-int slot = object_property_get_int(OBJECT(dev), slot, local_err);
+int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
+   local_err);
 
 if (local_err) {
 error_propagate(errp, local_err);
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 04/10] acpi, mem-hotplug: Add acpi_memory_unplug_cb() to implement memory unplug.

2014-10-22 Thread Tang Chen
Add a new bool member named is_removing to MemStatus indicating that
the memory solt is being removed. Set it to true in acpi_memory_unplug_cb(),
and send SCI to guest.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 15 +++
 include/hw/acpi/memory_hotplug.h |  3 +++
 2 files changed, 18 insertions(+)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 9839963..01dea6c 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -211,6 +211,21 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 acpi_memory_hotplug_sci(ar, irq);
 }
 
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
+mdev-is_removing = true;
+
+/* Do ACPI magic */
+acpi_memory_hotplug_sci(ar, irq);
+}
+
 static const VMStateDescription vmstate_memhp_sts = {
 .name = memory hotplug device state,
 .version_id = 1,
diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h
index 7bbf8a0..fe41268 100644
--- a/include/hw/acpi/memory_hotplug.h
+++ b/include/hw/acpi/memory_hotplug.h
@@ -11,6 +11,7 @@ typedef struct MemStatus {
 DeviceState *dimm;
 bool is_enabled;
 bool is_inserting;
+bool is_removing;
 uint32_t ost_event;
 uint32_t ost_status;
 } MemStatus;
@@ -28,6 +29,8 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner,
 
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
  DeviceState *dev, Error **errp);
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp);
 
 extern const VMStateDescription vmstate_memory_hotplug;
 #define VMSTATE_MEMORY_HOTPLUG(memhp, state) \
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 10/10] pc, acpi bios: Add memory hot unplug interface.

2014-10-22 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

This patch implements MEMORY_SLOT_EJECT_METHOD according to ACPI spec.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/i386/ssdt-mem.dsl |  5 +
 hw/i386/ssdt-misc.dsl| 13 -
 include/hw/acpi/pc-hotplug.h |  2 ++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/hw/i386/ssdt-mem.dsl b/hw/i386/ssdt-mem.dsl
index 22ff5dd..1416639 100644
--- a/hw/i386/ssdt-mem.dsl
+++ b/hw/i386/ssdt-mem.dsl
@@ -43,6 +43,7 @@ DefinitionBlock (ssdt-mem.aml, SSDT, 0x02, BXPC, 
CSSDT, 0x1)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_STATUS_METHOD, 
MethodObj)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD, MethodObj)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_PROXIMITY_METHOD, 
MethodObj)
+External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD, 
MethodObj)
 
 Scope(\_SB) {
 /*  v-- DO NOT EDIT --v */
@@ -72,6 +73,10 @@ DefinitionBlock (ssdt-mem.aml, SSDT, 0x02, BXPC, 
CSSDT, 0x1)
 Method(_OST, 3) {
 \_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD(_UID, 
Arg0, Arg1, Arg2)
 }
+
+Method(_EJ0, 1) {
+\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD(_UID, 
Arg0)
+}
 }
 }
 }
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 0fd4480..7b29539 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -156,6 +156,7 @@ DefinitionBlock (ssdt-misc.aml, SSDT, 0x01, BXPC, 
BXSSDTSUSP, 0x1)
 Offset(20),
 MEMORY_SLOT_ENABLED,  1, // 1 if enabled, read only
 MEMORY_SLOT_INSERT_EVENT, 1, // (read) 1 if has a insert 
event. (write) 1 to clear event
+MEMORY_SLOT_REMOVE_EVENT, 1, // 1 if DIMM has a remove 
request, read only
 }
 
 Mutex (MEMORY_SLOT_LOCK, 0)
@@ -174,11 +175,14 @@ DefinitionBlock (ssdt-misc.aml, SSDT, 0x01, BXPC, 
BXSSDTSUSP, 0x1)
 Acquire(MEMORY_SLOT_LOCK, 0x)
 while (LLess(Local0, MEMORY_SLOTS_NUMBER)) {
 Store(Local0, MEMORY_SLOT_SLECTOR) // select Local0 DIMM
+
 If (LEqual(MEMORY_SLOT_INSERT_EVENT, One)) { // Memory 
device needs check
 MEMORY_SLOT_NOTIFY_METHOD(Local0, 1)
 Store(1, MEMORY_SLOT_INSERT_EVENT)
+} Elseif (LEqual(MEMORY_SLOT_REMOVE_EVENT, One)) { // 
Ejection request
+MEMORY_SLOT_NOTIFY_METHOD(Local0, 3)
 }
-// TODO: handle memory eject request
+
 Add(Local0, One, Local0) // goto next DIMM
 }
 Release(MEMORY_SLOT_LOCK)
@@ -278,6 +282,13 @@ DefinitionBlock (ssdt-misc.aml, SSDT, 0x01, BXPC, 
BXSSDTSUSP, 0x1)
 Store(Arg2, MEMORY_SLOT_OST_STATUS)
 Release(MEMORY_SLOT_LOCK)
 }
+
+Method(MEMORY_SLOT_EJECT_METHOD, 2) {
+Acquire(MEMORY_SLOT_LOCK, 0x)
+Store(ToInteger(Arg0), MEMORY_SLOT_SLECTOR) // select DIMM
+Store(One, MEMORY_SLOT_REMOVE_EVENT)
+Release(MEMORY_SLOT_LOCK)
+}
 } // Device()
 } // Scope()
 }
diff --git a/include/hw/acpi/pc-hotplug.h b/include/hw/acpi/pc-hotplug.h
index b9db295..b61b6ea 100644
--- a/include/hw/acpi/pc-hotplug.h
+++ b/include/hw/acpi/pc-hotplug.h
@@ -42,6 +42,7 @@
 #define MEMORY_SLOT_PROXIMITYMPX
 #define MEMORY_SLOT_ENABLED  MES
 #define MEMORY_SLOT_INSERT_EVENT MINS
+#define MEMORY_SLOT_REMOVE_EVENT MRMV
 #define MEMORY_SLOT_SLECTOR  MSEL
 #define MEMORY_SLOT_OST_EVENTMOEV
 #define MEMORY_SLOT_OST_STATUS   MOSC
@@ -50,6 +51,7 @@
 #define MEMORY_SLOT_CRS_METHOD   MCRS
 #define MEMORY_SLOT_OST_METHOD   MOST
 #define MEMORY_SLOT_PROXIMITY_METHOD MPXM
+#define MEMORY_SLOT_EJECT_METHOD MEJ0
 #define MEMORY_SLOT_NOTIFY_METHODMTFY
 #define MEMORY_SLOT_SCAN_METHOD  MSCN
 
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 02/10] acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to get MemStatus.

2014-10-22 Thread Tang Chen
Add a new API named acpi_memory_get_slot_status_descriptor() to obtain
a single memory slot status. Doing this is because this procedure will
be used by other functions in the next coming patches.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 27 +++
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index c6580da..ef56bf6 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -163,29 +163,40 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object 
*owner,
 memory_region_add_subregion(as, ACPI_MEMORY_HOTPLUG_BASE, state-io);
 }
 
-void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
- DeviceState *dev, Error **errp)
+static MemStatus *
+acpi_memory_get_slot_status_descriptor(MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
 {
-MemStatus *mdev;
 Error *local_err = NULL;
 int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
local_err);
 
 if (local_err) {
 error_propagate(errp, local_err);
-return;
+return NULL;
 }
 
 if (slot = mem_st-dev_count) {
 char *dev_path = object_get_canonical_path(OBJECT(dev));
-error_setg(errp, acpi_memory_plug_cb: 
+error_setg(errp, acpi_memory_get_slot_status_descriptor: 
device [%s] returned invalid memory slot[%d],
-dev_path, slot);
+   dev_path, slot);
 g_free(dev_path);
-return;
+return NULL;
 }
 
-mdev = mem_st-devs[slot];
+return mem_st-devs[slot];
+}
+
+void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+ DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
 mdev-dimm = dev;
 mdev-is_enabled = true;
 mdev-is_inserting = true;
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 08/10] pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.

2014-10-22 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

Implement unrealize function for pc-dimm device. It remove subregion from
hotplug region, and delete ram address range from guest ram list.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/mem/pc-dimm.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index ee802bb..b105871 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -270,12 +270,22 @@ static MemoryRegion 
*pc_dimm_get_memory_region(PCDIMMDevice *dimm)
 return host_memory_backend_get_memory(dimm-hostmem, error_abort);
 }
 
+static void pc_dimm_unrealize(DeviceState *dev, Error **errp)
+{
+PCDIMMDevice *dimm = PC_DIMM(dev);
+MemoryRegion *mr = pc_dimm_get_memory_region(dimm);
+
+memory_region_del_subregion(mr-container, mr);
+vmstate_unregister_ram(mr, dev);
+}
+
 static void pc_dimm_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
 PCDIMMDeviceClass *ddc = PC_DIMM_CLASS(oc);
 
 dc-realize = pc_dimm_realize;
+dc-unrealize = pc_dimm_unrealize;
 dc-props = pc_dimm_properties;
 
 ddc-get_memory_region = pc_dimm_get_memory_region;
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 06/10] acpi, ich9: Add memory hot unplug support for ich9.

2014-10-22 Thread Tang Chen
Implement ich9_pm_device_unplug_cb() to support memory hot-remove,
calling acpi_memory_unplug_cb(). And itself will be called in
ich9_device_unplug_cb().

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/ich9.c | 12 
 hw/isa/lpc_ich9.c  |  5 +++--
 include/hw/acpi/ich9.h |  2 ++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 7b14bbb..d369151 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -310,6 +310,18 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState 
*dev, Error **errp)
 }
 }
 
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error 
**errp)
+{
+if (pm-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_cb(pm-acpi_regs, pm-irq, 
pm-acpi_memory_hotplug,
+  dev, errp);
+} else {
+error_setg(errp, acpi: device unplug request for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
+}
+
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
 {
 ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 530b074..75f28d1 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -610,8 +610,9 @@ static void ich9_device_plug_cb(HotplugHandler *hotplug_dev,
 static void ich9_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)));
+ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+ich9_pm_device_unplug_cb(lpc-pm, dev, errp);
 }
 
 static bool ich9_rst_cnt_needed(void *opaque)
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 7e42448..029576f 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -60,6 +60,8 @@ extern const VMStateDescription vmstate_ich9_pm;
 void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp);
 
 void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp);
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+  Error **errp);
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
 #endif /* HW_ACPI_ICH9_H */
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 09/10] acpi: Add hardware implementation for memory hot unplug.

2014-10-22 Thread Tang Chen
This patch adds a new bit to memory hotplug IO port indicating that
memory device is be removed. And set MemStatus-is_removing to false
when the bit is written.

NOTE: MemStatus-is_removing is set to true in acpi_memory_unplug_cb()
when doing memory hot-remove with device_del command.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 docs/specs/acpi_mem_hotplug.txt |  8 ++--
 hw/acpi/memory_hotplug.c| 14 +++---
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/docs/specs/acpi_mem_hotplug.txt b/docs/specs/acpi_mem_hotplug.txt
index 1290994..5524c30 100644
--- a/docs/specs/acpi_mem_hotplug.txt
+++ b/docs/specs/acpi_mem_hotplug.txt
@@ -19,7 +19,9 @@ Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte 
access):
   1: Device insert event, used to distinguish device for which
  no device check event to OSPM was issued.
  It's valid only when bit 1 is set.
-  2-7: reserved and should be ignored by OSPM
+  2: Device remove event, used to indicate that device is being
+removed.
+  3-7: reserved and should be ignored by OSPM
   [0x15-0x17] reserved
 
   write access:
@@ -35,7 +37,9 @@ Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte 
access):
   1: if set to 1 clears device insert event, set by OSPM
  after it has emitted device check event for the
  selected memory device
-  2-7: reserved, OSPM must clear them before writing to register
+  2: set by hardware after it has emitted devive eject event for
+selected memory device
+  3-7: reserved, OSPM must clear them before writing to register
 
 Selecting memory device slot beyond present range has no effect on platform:
- write accesses to memory hot-plug registers not documented above are
diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 01dea6c..a745bb0 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -75,6 +75,7 @@ static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr 
addr,
 case 0x14: /* pack and return is_* fields */
 val |= mdev-is_enabled   ? 1 : 0;
 val |= mdev-is_inserting ? 2 : 0;
+val |= mdev-is_removing  ? 4 : 0;
 trace_mhp_acpi_read_flags(mem_st-selector, val);
 break;
 default:
@@ -121,21 +122,28 @@ static void acpi_memory_hotplug_write(void *opaque, 
hwaddr addr, uint64_t data,
 mdev = mem_st-devs[mem_st-selector];
 mdev-ost_status = data;
 trace_mhp_acpi_write_ost_status(mem_st-selector, mdev-ost_status);
-/* TODO: implement memory removal on guest signal */
 
 info = acpi_memory_device_status(mem_st-selector, mdev);
 qapi_event_send_acpi_device_ost(info, error_abort);
 qapi_free_ACPIOSTInfo(info);
 break;
-case 0x14:
+case 0x14: /* set is_* fields */
 mdev = mem_st-devs[mem_st-selector];
+
 if (data  2) { /* clear insert event */
 mdev-is_inserting  = false;
 trace_mhp_acpi_clear_insert_evt(mem_st-selector);
+} else if (data  4) { /* request removal of device */
+mdev-is_enabled = false;
+mdev-is_removing = false;
+object_unparent(OBJECT(mdev-dimm));
+mdev-dimm = NULL;
 }
+
+break;
+default:
 break;
 }
-
 }
 static const MemoryRegionOps acpi_memory_hotplug_ops = {
 .read = acpi_memory_hotplug_read,
-- 
1.8.4.2




[Qemu-devel] [RESEND PATCH v4 07/10] pc: Add memory hot unplug support for pc machine.

2014-10-22 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

Implement device unplug callback for PCMachine. And it now only support
pc-dimm hot-remove. The callback will call piix4 or ich9 callbacks introduced
in previous patches.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/i386/pc.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index d045e8b..9cdbcae 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -61,6 +61,8 @@
 #include hw/mem/pc-dimm.h
 #include trace.h
 #include qapi/visitor.h
+#include hw/acpi/piix4.h
+#include hw/i386/ich9.h
 
 /* debug PC/ISA interrupts */
 //#define DEBUG_IRQ
@@ -1617,6 +1619,26 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_dimm_unplug(HotplugHandler *hotplug_dev,
+   DeviceState *dev, Error **errp)
+{
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+if (!pcms-acpi_dev) {
+error_setg(local_err,
+   memory hotplug 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)
 {
@@ -1625,6 +1647,14 @@ static void pc_machine_device_plug_cb(HotplugHandler 
*hotplug_dev,
 }
 }
 
+static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
+DeviceState *dev, Error **errp)
+{
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+pc_dimm_unplug(hotplug_dev, dev, errp);
+}
+}
+
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
  DeviceState *dev)
 {
@@ -1711,6 +1741,7 @@ static void pc_machine_class_init(ObjectClass *oc, void 
*data)
 pcmc-get_hotplug_handler = mc-get_hotplug_handler;
 mc-get_hotplug_handler = pc_get_hotpug_handler;
 hc-plug = pc_machine_device_plug_cb;
+hc-unplug = pc_machine_device_unplug_cb;
 }
 
 static const TypeInfo pc_machine_info = {
-- 
1.8.4.2




[Qemu-devel] [PATCH v4 00/12] QEmu memory hot unplug support.

2014-10-15 Thread Tang Chen
This patch-set implements memory hot-remove for QEmu.

Approach: QEmu sets GPE status bit, then triggers SCI to notify guest os.
Guest os checks device status, and free memory resource if possible,
then generate OST.

NOTE: In this version, memory hot-remove is independent from _OST, 
  following Igor's comments.
  Patches _OST handling for platforms supporting _OST will come 
  soon when Igor finishes his refacting for framework of hotplug.

Change log v3 - v4:
1. Add new patch 1 ~ 4, fix some small problems in coding.
2. In patch 10, make memory hot-remove independent from _OST.
3. In patch 10, add comment for is_removing flag to document.
4. In patch 11, use macro instead of number.
5. In patch 12, do not access internal fields of Object outside of object.c

Hu Tao (6):
  acpi, piix4: Add memory hot unplug support for piix4.
  pc: Add memory hot unplug support for pc machine.
  qdev: Add memory hot unplug support for bus-less devices.
  pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.
  pc, acpi bios: Add memory hot unplug interface.
  monitor: Add memory hot unplug support for device_del command.

Tang Chen (6):
  acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().
  acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to get
MemStatus.
  acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for
memory hotplug.
  acpi, mem-hotplug: Add acpi_memory_unplug_cb() to implement memory
unplug.
  acpi, ich9: Add memory hot unplug support for ich9.
  acpi: Add hardware implementation for memory hot unplug.

 docs/specs/acpi_mem_hotplug.txt  |  8 +++--
 hw/acpi/ich9.c   | 12 +++
 hw/acpi/memory_hotplug.c | 71 +++-
 hw/acpi/piix4.c  |  6 +++-
 hw/core/qdev.c   |  8 +
 hw/i386/pc.c | 31 ++
 hw/i386/ssdt-mem.dsl |  5 +++
 hw/i386/ssdt-misc.dsl| 13 +++-
 hw/isa/lpc_ich9.c|  5 +--
 hw/mem/pc-dimm.c | 10 ++
 include/hw/acpi/ich9.h   |  2 ++
 include/hw/acpi/memory_hotplug.h |  3 ++
 include/hw/acpi/pc-hotplug.h |  2 ++
 qdev-monitor.c   | 46 ++
 14 files changed, 200 insertions(+), 22 deletions(-)

-- 
1.8.4.2




[Qemu-devel] [PATCH v4 05/12] acpi, piix4: Add memory hot unplug support for piix4.

2014-10-15 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

Implement acpi_memory_unplug_cb(), sending an sci to guest to trigger
memory hot-remove, and call it in piix4_device_unplug_cb().

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/piix4.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 48a0174..f12bb9d 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -359,7 +359,11 @@ static void piix4_device_unplug_cb(HotplugHandler 
*hotplug_dev,
 {
 PIIX4PMState *s = PIIX4_PM(hotplug_dev);
 
-if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
+if (s-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_cb(s-ar, s-irq, s-acpi_memory_hotplug, dev,
+  errp);
+} else 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 {
-- 
1.8.4.2




[Qemu-devel] [PATCH v4 07/12] pc: Add memory hot unplug support for pc machine.

2014-10-15 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

Implement device unplug callback for PCMachine. And it now only support
pc-dimm hot-remove. The callback will call piix4 or ich9 callbacks introduced
in previous patches.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/i386/pc.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index d045e8b..4b7cfe0 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -61,6 +61,8 @@
 #include hw/mem/pc-dimm.h
 #include trace.h
 #include qapi/visitor.h
+#include hw/acpi/piix4.h
+#include hw/i386/ich9.h
 
 /* debug PC/ISA interrupts */
 //#define DEBUG_IRQ
@@ -1617,6 +1619,26 @@ out:
 error_propagate(errp, local_err);
 }
 
+static void pc_dimm_unplug(HotplugHandler *hotplug_dev,
+   DeviceState *dev, Error **errp)
+{
+HotplugHandlerClass *hhc;
+Error *local_err = NULL;
+PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+
+if (!pcms-acpi_dev) {
+error_setg(local_err,
+   memory hotplug is not enabled: missing acpi device);
+   goto out;
+}
+
+hhc = HOTPLUG_HANDLER_GET_CLASS(pcms-acpi_dev);
+hhc-unplug(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)
 {
@@ -1625,6 +1647,14 @@ static void pc_machine_device_plug_cb(HotplugHandler 
*hotplug_dev,
 }
 }
 
+static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
+DeviceState *dev, Error **errp)
+{
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+pc_dimm_unplug(hotplug_dev, dev, errp);
+}
+}
+
 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine,
  DeviceState *dev)
 {
@@ -1711,6 +1741,7 @@ static void pc_machine_class_init(ObjectClass *oc, void 
*data)
 pcmc-get_hotplug_handler = mc-get_hotplug_handler;
 mc-get_hotplug_handler = pc_get_hotpug_handler;
 hc-plug = pc_machine_device_plug_cb;
+hc-unplug = pc_machine_device_unplug_cb;
 }
 
 static const TypeInfo pc_machine_info = {
-- 
1.8.4.2




[Qemu-devel] [PATCH v4 01/12] acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().

2014-10-15 Thread Tang Chen
Replace string slot in acpi_memory_plug_cb() with MACRO PC_DIMM_SLOT_PROP.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index ed39241..c6580da 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -168,7 +168,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 {
 MemStatus *mdev;
 Error *local_err = NULL;
-int slot = object_property_get_int(OBJECT(dev), slot, local_err);
+int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
+   local_err);
 
 if (local_err) {
 error_propagate(errp, local_err);
-- 
1.8.4.2




[Qemu-devel] [PATCH v4 02/12] acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to get MemStatus.

2014-10-15 Thread Tang Chen
Add a new API named acpi_memory_get_slot_status_descriptor() to obtain
a single memory slot status. Doing this is because this procedure will
be used by other functions in the next coming patches.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 27 +++
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index c6580da..ef56bf6 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -163,29 +163,40 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object 
*owner,
 memory_region_add_subregion(as, ACPI_MEMORY_HOTPLUG_BASE, state-io);
 }
 
-void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
- DeviceState *dev, Error **errp)
+static MemStatus *
+acpi_memory_get_slot_status_descriptor(MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
 {
-MemStatus *mdev;
 Error *local_err = NULL;
 int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
local_err);
 
 if (local_err) {
 error_propagate(errp, local_err);
-return;
+return NULL;
 }
 
 if (slot = mem_st-dev_count) {
 char *dev_path = object_get_canonical_path(OBJECT(dev));
-error_setg(errp, acpi_memory_plug_cb: 
+error_setg(errp, acpi_memory_get_slot_status_descriptor: 
device [%s] returned invalid memory slot[%d],
-dev_path, slot);
+   dev_path, slot);
 g_free(dev_path);
-return;
+return NULL;
 }
 
-mdev = mem_st-devs[slot];
+return mem_st-devs[slot];
+}
+
+void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+ DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
 mdev-dimm = dev;
 mdev-is_enabled = true;
 mdev-is_inserting = true;
-- 
1.8.4.2




[Qemu-devel] [PATCH v4 03/12] acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for memory hotplug.

2014-10-15 Thread Tang Chen
Add a new API named acpi_memory_hotplug_sci() to send memory hotplug SCI.
Doing this is because this procedure will be used by other functions in the
next coming patches.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index ef56bf6..9839963 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -188,6 +188,12 @@ acpi_memory_get_slot_status_descriptor(MemHotplugState 
*mem_st,
 return mem_st-devs[slot];
 }
 
+static void acpi_memory_hotplug_sci(ACPIREGS *ar, qemu_irq irq)
+{
+ar-gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
+acpi_update_sci(ar, irq);
+}
+
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
  DeviceState *dev, Error **errp)
 {
@@ -201,10 +207,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 mdev-is_enabled = true;
 mdev-is_inserting = true;
 
-/* do ACPI magic */
-ar-gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
-acpi_update_sci(ar, irq);
-return;
+/* Do ACPI magic */
+acpi_memory_hotplug_sci(ar, irq);
 }
 
 static const VMStateDescription vmstate_memhp_sts = {
-- 
1.8.4.2




[Qemu-devel] [PATCH v4 04/12] acpi, mem-hotplug: Add acpi_memory_unplug_cb() to implement memory unplug.

2014-10-15 Thread Tang Chen
Add a new bool member named is_removing to MemStatus indicating that
the memory solt is being removed. Set it to true in acpi_memory_unplug_cb(),
and send SCI to guest.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/memory_hotplug.c | 15 +++
 include/hw/acpi/memory_hotplug.h |  3 +++
 2 files changed, 18 insertions(+)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 9839963..01dea6c 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -211,6 +211,21 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 acpi_memory_hotplug_sci(ar, irq);
 }
 
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp)
+{
+MemStatus *mdev;
+
+mdev = acpi_memory_get_slot_status_descriptor(mem_st, dev, errp);
+if (!mdev)
+return;
+
+mdev-is_removing = true;
+
+/* Do ACPI magic */
+acpi_memory_hotplug_sci(ar, irq);
+}
+
 static const VMStateDescription vmstate_memhp_sts = {
 .name = memory hotplug device state,
 .version_id = 1,
diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotplug.h
index 7bbf8a0..fe41268 100644
--- a/include/hw/acpi/memory_hotplug.h
+++ b/include/hw/acpi/memory_hotplug.h
@@ -11,6 +11,7 @@ typedef struct MemStatus {
 DeviceState *dimm;
 bool is_enabled;
 bool is_inserting;
+bool is_removing;
 uint32_t ost_event;
 uint32_t ost_status;
 } MemStatus;
@@ -28,6 +29,8 @@ void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner,
 
 void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
  DeviceState *dev, Error **errp);
+void acpi_memory_unplug_cb(ACPIREGS *ar, qemu_irq irq, MemHotplugState *mem_st,
+   DeviceState *dev, Error **errp);
 
 extern const VMStateDescription vmstate_memory_hotplug;
 #define VMSTATE_MEMORY_HOTPLUG(memhp, state) \
-- 
1.8.4.2




[Qemu-devel] [PATCH v4 11/12] pc, acpi bios: Add memory hot unplug interface.

2014-10-15 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

This patch implements MEMORY_SLOT_EJECT_METHOD according to ACPI spec.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/i386/ssdt-mem.dsl |  5 +
 hw/i386/ssdt-misc.dsl| 13 -
 include/hw/acpi/pc-hotplug.h |  2 ++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/hw/i386/ssdt-mem.dsl b/hw/i386/ssdt-mem.dsl
index 22ff5dd..1416639 100644
--- a/hw/i386/ssdt-mem.dsl
+++ b/hw/i386/ssdt-mem.dsl
@@ -43,6 +43,7 @@ DefinitionBlock (ssdt-mem.aml, SSDT, 0x02, BXPC, 
CSSDT, 0x1)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_STATUS_METHOD, 
MethodObj)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD, MethodObj)
 External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_PROXIMITY_METHOD, 
MethodObj)
+External(\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD, 
MethodObj)
 
 Scope(\_SB) {
 /*  v-- DO NOT EDIT --v */
@@ -72,6 +73,10 @@ DefinitionBlock (ssdt-mem.aml, SSDT, 0x02, BXPC, 
CSSDT, 0x1)
 Method(_OST, 3) {
 \_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_OST_METHOD(_UID, 
Arg0, Arg1, Arg2)
 }
+
+Method(_EJ0, 1) {
+\_SB.PCI0.MEMORY_HOTPLUG_DEVICE.MEMORY_SLOT_EJECT_METHOD(_UID, 
Arg0)
+}
 }
 }
 }
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
index 0fd4480..7b29539 100644
--- a/hw/i386/ssdt-misc.dsl
+++ b/hw/i386/ssdt-misc.dsl
@@ -156,6 +156,7 @@ DefinitionBlock (ssdt-misc.aml, SSDT, 0x01, BXPC, 
BXSSDTSUSP, 0x1)
 Offset(20),
 MEMORY_SLOT_ENABLED,  1, // 1 if enabled, read only
 MEMORY_SLOT_INSERT_EVENT, 1, // (read) 1 if has a insert 
event. (write) 1 to clear event
+MEMORY_SLOT_REMOVE_EVENT, 1, // 1 if DIMM has a remove 
request, read only
 }
 
 Mutex (MEMORY_SLOT_LOCK, 0)
@@ -174,11 +175,14 @@ DefinitionBlock (ssdt-misc.aml, SSDT, 0x01, BXPC, 
BXSSDTSUSP, 0x1)
 Acquire(MEMORY_SLOT_LOCK, 0x)
 while (LLess(Local0, MEMORY_SLOTS_NUMBER)) {
 Store(Local0, MEMORY_SLOT_SLECTOR) // select Local0 DIMM
+
 If (LEqual(MEMORY_SLOT_INSERT_EVENT, One)) { // Memory 
device needs check
 MEMORY_SLOT_NOTIFY_METHOD(Local0, 1)
 Store(1, MEMORY_SLOT_INSERT_EVENT)
+} Elseif (LEqual(MEMORY_SLOT_REMOVE_EVENT, One)) { // 
Ejection request
+MEMORY_SLOT_NOTIFY_METHOD(Local0, 3)
 }
-// TODO: handle memory eject request
+
 Add(Local0, One, Local0) // goto next DIMM
 }
 Release(MEMORY_SLOT_LOCK)
@@ -278,6 +282,13 @@ DefinitionBlock (ssdt-misc.aml, SSDT, 0x01, BXPC, 
BXSSDTSUSP, 0x1)
 Store(Arg2, MEMORY_SLOT_OST_STATUS)
 Release(MEMORY_SLOT_LOCK)
 }
+
+Method(MEMORY_SLOT_EJECT_METHOD, 2) {
+Acquire(MEMORY_SLOT_LOCK, 0x)
+Store(ToInteger(Arg0), MEMORY_SLOT_SLECTOR) // select DIMM
+Store(One, MEMORY_SLOT_REMOVE_EVENT)
+Release(MEMORY_SLOT_LOCK)
+}
 } // Device()
 } // Scope()
 }
diff --git a/include/hw/acpi/pc-hotplug.h b/include/hw/acpi/pc-hotplug.h
index b9db295..b61b6ea 100644
--- a/include/hw/acpi/pc-hotplug.h
+++ b/include/hw/acpi/pc-hotplug.h
@@ -42,6 +42,7 @@
 #define MEMORY_SLOT_PROXIMITYMPX
 #define MEMORY_SLOT_ENABLED  MES
 #define MEMORY_SLOT_INSERT_EVENT MINS
+#define MEMORY_SLOT_REMOVE_EVENT MRMV
 #define MEMORY_SLOT_SLECTOR  MSEL
 #define MEMORY_SLOT_OST_EVENTMOEV
 #define MEMORY_SLOT_OST_STATUS   MOSC
@@ -50,6 +51,7 @@
 #define MEMORY_SLOT_CRS_METHOD   MCRS
 #define MEMORY_SLOT_OST_METHOD   MOST
 #define MEMORY_SLOT_PROXIMITY_METHOD MPXM
+#define MEMORY_SLOT_EJECT_METHOD MEJ0
 #define MEMORY_SLOT_NOTIFY_METHODMTFY
 #define MEMORY_SLOT_SCAN_METHOD  MSCN
 
-- 
1.8.4.2




[Qemu-devel] [PATCH v4 06/12] acpi, ich9: Add memory hot unplug support for ich9.

2014-10-15 Thread Tang Chen
Implement ich9_pm_device_unplug_cb() to support memory hot-remove,
calling acpi_memory_unplug_cb(). And itself will be called in
ich9_device_unplug_cb().

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/acpi/ich9.c | 12 
 hw/isa/lpc_ich9.c  |  5 +++--
 include/hw/acpi/ich9.h |  2 ++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 7b14bbb..d369151 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -310,6 +310,18 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState 
*dev, Error **errp)
 }
 }
 
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error 
**errp)
+{
+if (pm-acpi_memory_hotplug.is_enabled 
+object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+acpi_memory_unplug_cb(pm-acpi_regs, pm-irq, 
pm-acpi_memory_hotplug,
+  dev, errp);
+} else {
+error_setg(errp, acpi: device unplug request for not supported device
+type: %s, object_get_typename(OBJECT(dev)));
+}
+}
+
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
 {
 ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index 177023b..2c0761a 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -610,8 +610,9 @@ static void ich9_device_plug_cb(HotplugHandler *hotplug_dev,
 static void ich9_device_unplug_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)));
+ICH9LPCState *lpc = ICH9_LPC_DEVICE(hotplug_dev);
+
+ich9_pm_device_unplug_cb(lpc-pm, dev, errp);
 }
 
 static bool ich9_rst_cnt_needed(void *opaque)
diff --git a/include/hw/acpi/ich9.h b/include/hw/acpi/ich9.h
index 7e42448..029576f 100644
--- a/include/hw/acpi/ich9.h
+++ b/include/hw/acpi/ich9.h
@@ -60,6 +60,8 @@ extern const VMStateDescription vmstate_ich9_pm;
 void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp);
 
 void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp);
+void ich9_pm_device_unplug_cb(ICH9LPCPMRegs *pm, DeviceState *dev,
+  Error **errp);
 
 void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
 #endif /* HW_ACPI_ICH9_H */
-- 
1.8.4.2




[Qemu-devel] [PATCH v4 08/12] qdev: Add memory hot unplug support for bus-less devices.

2014-10-15 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

Implement bus-less device hot-remove in qdev_unplug().
For now, only pc-dimm is bus-less device, but this is generic handling
that applies to other devices.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/core/qdev.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index fcb1638..01d89a8 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -228,6 +228,14 @@ void qdev_unplug(DeviceState *dev, Error **errp)
 
 if (dev-parent_bus  dev-parent_bus-hotplug_handler) {
 hotplug_handler_unplug(dev-parent_bus-hotplug_handler, dev, errp);
+} else if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) {
+HotplugHandler *hotplug_ctrl;
+MachineState *machine = MACHINE(qdev_get_machine());
+MachineClass *mc = MACHINE_GET_CLASS(machine);
+
+hotplug_ctrl = mc-get_hotplug_handler(machine, dev);
+if (hotplug_ctrl)
+hotplug_handler_unplug(hotplug_ctrl, dev, errp);
 } else {
 assert(dc-unplug != NULL);
 if (dc-unplug(dev)  0) { /* legacy handler */
-- 
1.8.4.2




[Qemu-devel] [PATCH v4 09/12] pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.

2014-10-15 Thread Tang Chen
From: Hu Tao hu...@cn.fujitsu.com

Implement unrealize function for pc-dimm device. It remove subregion from
hotplug region, and delete ram address range from guest ram list.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 hw/mem/pc-dimm.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index ee802bb..b105871 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -270,12 +270,22 @@ static MemoryRegion 
*pc_dimm_get_memory_region(PCDIMMDevice *dimm)
 return host_memory_backend_get_memory(dimm-hostmem, error_abort);
 }
 
+static void pc_dimm_unrealize(DeviceState *dev, Error **errp)
+{
+PCDIMMDevice *dimm = PC_DIMM(dev);
+MemoryRegion *mr = pc_dimm_get_memory_region(dimm);
+
+memory_region_del_subregion(mr-container, mr);
+vmstate_unregister_ram(mr, dev);
+}
+
 static void pc_dimm_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
 PCDIMMDeviceClass *ddc = PC_DIMM_CLASS(oc);
 
 dc-realize = pc_dimm_realize;
+dc-unrealize = pc_dimm_unrealize;
 dc-props = pc_dimm_properties;
 
 ddc-get_memory_region = pc_dimm_get_memory_region;
-- 
1.8.4.2




[Qemu-devel] [PATCH v4 10/12] acpi: Add hardware implementation for memory hot unplug.

2014-10-15 Thread Tang Chen
This patch adds a new bit to memory hotplug IO port indicating that
memory device is be removed. And set MemStatus-is_removing to false
when the bit is written.

NOTE: MemStatus-is_removing is set to true in acpi_memory_unplug_cb()
when doing memory hot-remove with device_del command.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 docs/specs/acpi_mem_hotplug.txt |  8 ++--
 hw/acpi/memory_hotplug.c| 14 +++---
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/docs/specs/acpi_mem_hotplug.txt b/docs/specs/acpi_mem_hotplug.txt
index 1290994..5524c30 100644
--- a/docs/specs/acpi_mem_hotplug.txt
+++ b/docs/specs/acpi_mem_hotplug.txt
@@ -19,7 +19,9 @@ Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte 
access):
   1: Device insert event, used to distinguish device for which
  no device check event to OSPM was issued.
  It's valid only when bit 1 is set.
-  2-7: reserved and should be ignored by OSPM
+  2: Device remove event, used to indicate that device is being
+removed.
+  3-7: reserved and should be ignored by OSPM
   [0x15-0x17] reserved
 
   write access:
@@ -35,7 +37,9 @@ Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte 
access):
   1: if set to 1 clears device insert event, set by OSPM
  after it has emitted device check event for the
  selected memory device
-  2-7: reserved, OSPM must clear them before writing to register
+  2: set by hardware after it has emitted devive eject event for
+selected memory device
+  3-7: reserved, OSPM must clear them before writing to register
 
 Selecting memory device slot beyond present range has no effect on platform:
- write accesses to memory hot-plug registers not documented above are
diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index 01dea6c..a745bb0 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -75,6 +75,7 @@ static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr 
addr,
 case 0x14: /* pack and return is_* fields */
 val |= mdev-is_enabled   ? 1 : 0;
 val |= mdev-is_inserting ? 2 : 0;
+val |= mdev-is_removing  ? 4 : 0;
 trace_mhp_acpi_read_flags(mem_st-selector, val);
 break;
 default:
@@ -121,21 +122,28 @@ static void acpi_memory_hotplug_write(void *opaque, 
hwaddr addr, uint64_t data,
 mdev = mem_st-devs[mem_st-selector];
 mdev-ost_status = data;
 trace_mhp_acpi_write_ost_status(mem_st-selector, mdev-ost_status);
-/* TODO: implement memory removal on guest signal */
 
 info = acpi_memory_device_status(mem_st-selector, mdev);
 qapi_event_send_acpi_device_ost(info, error_abort);
 qapi_free_ACPIOSTInfo(info);
 break;
-case 0x14:
+case 0x14: /* set is_* fields */
 mdev = mem_st-devs[mem_st-selector];
+
 if (data  2) { /* clear insert event */
 mdev-is_inserting  = false;
 trace_mhp_acpi_clear_insert_evt(mem_st-selector);
+} else if (data  4) { /* request removal of device */
+mdev-is_enabled = false;
+mdev-is_removing = false;
+object_unparent(OBJECT(mdev-dimm));
+mdev-dimm = NULL;
 }
+
+break;
+default:
 break;
 }
-
 }
 static const MemoryRegionOps acpi_memory_hotplug_ops = {
 .read = acpi_memory_hotplug_read,
-- 
1.8.4.2




Re: [Qemu-devel] [RESEND PATCH v3 5/8] pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.

2014-09-24 Thread Tang Chen

Hi Igor, Zhang,

On 09/12/2014 09:17 PM, Igor Mammedov wrote:

..
Actually, this patch also fix the bug *when hotplug memory failing in
the place where after pc_dimm_plug but before the end of device_set_realized,
it does not clear the work done by pc_dimm_plug*.

For there is no callback like pc_dimm_plug_fail_cb for us to call when fail,
Maybe pc_dimm_unrealize is the only place where we can do the clear work...
Looking at device_set_realized() and pc-dimm case in patrticular
there is no point where it could fail after hotplug_handler_plug() is called.

But even if there where, one should use pc_dimm_unplug() first to
reverse actions performed by successful pc_dimm_plug().

The problem here is that currently unplug callback is actually
doing only unplug request part asking guest to eject memory,
but we also have destroy device when guest tells via ACPI to
ejct memory. You are doing it implicitly by unparenting pc-dimm
from ACPI code and pulling in pc-dimm.unrealize() unrelated
stuff that should be done by PCMachine.

I'm suggesting that we extend hotplug-handler API to handle
this async/split unplug workflow. By converting current
hotplug_handler_unplug() and related code to
hotplug_handler_unplug_request() that would do the first part
of unplug sequence (see/review http://patchwork.ozlabs.org/patch/387018/)


I've read the above patch.

1. I think you proposal would help to resolve the following problem:

If guest OS failed to handle hoplug sci, QEmu does not know it, and 
could

release resources incorrectly.

Would you please have a look at the following patch.
https://www.mail-archive.com/qemu-devel%40nongnu.org/msg253025.html

I added a pthread wait condition to synchronize :
sci request - guest OS handling - _OST - QEmu handling
(Of course, according to the previous discussing, _OST is optional.)

And IIUC, your proposal may be :
hotplug request - guest OS handling - real hotplug handling

right ?

I think it is the same. How do you think synchronize it with a wait 
condition ?

Or you have any better idea ?
Since no one has replied the patch, I'm not sure if it is OK.


2. Let's finish memory and cpu hotplug job based on the current 
framework, shall we ?
In the above patch, it renames a lot of functions that are being 
used in memory and
cpu hotplug patches. I think we can push memory and cpu hotplug 
jobs, and in the

next phase, let's improve the framework.

And of course, the problem I mentioned above should also be put in 
the next phase.


So I want to submit the next version memory hotplug patches based 
on the original

framework, and help to improve it in the next phase.

How do you think ?



And then on top of it add hotplug_handler_unplug() that would
handle actual device removal when ACPI asks for it.

I'm working now on doing above for PCIDevices since they have
the same workflow (expect to submit patches next week) and
it looks like we would need to use the same approach for CPU
unplug as well.








Re: [Qemu-devel] [PATCH 11/30] qdev: HotplugHandler: provide unplug callback

2014-09-24 Thread Tang Chen


On 09/24/2014 07:48 PM, Igor Mammedov wrote:

it to be called for actual device removal and
will allow to separate request and removal handling
phases of x86-CPU devices and also it's a handler
to be called for synchronously removable devices.

Signed-off-by: Igor Mammedov imamm...@redhat.com
---
unplug handling for bus-less devices will be added
later in this series.
---
  hw/core/hotplug.c| 11 +++
  hw/core/qdev.c   | 13 +++--
  include/hw/hotplug.h | 12 
  3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/hw/core/hotplug.c b/hw/core/hotplug.c
index 2ec4736..4e01074 100644
--- a/hw/core/hotplug.c
+++ b/hw/core/hotplug.c
@@ -34,6 +34,17 @@ void hotplug_handler_unplug_request(HotplugHandler 
*plug_handler,
  }
  }
  
+void hotplug_handler_unplug(HotplugHandler *plug_handler,

+DeviceState *plugged_dev,
+Error **errp)
+{
+HotplugHandlerClass *hdc = HOTPLUG_HANDLER_GET_CLASS(plug_handler);
+
+if (hdc-unplug) {
+hdc-unplug(plug_handler, plugged_dev, errp);
+}
+}
+
  static const TypeInfo hotplug_handler_info = {
  .name  = TYPE_HOTPLUG_HANDLER,
  .parent= TYPE_INTERFACE,
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index c98e5db..c89d781 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -227,8 +227,17 @@ void qdev_unplug(DeviceState *dev, Error **errp)
  qdev_hot_removed = true;
  
  if (dev-parent_bus  dev-parent_bus-hotplug_handler) {

-hotplug_handler_unplug_request(dev-parent_bus-hotplug_handler,
-   dev, errp);
+HotplugHandlerClass *hdc;
+
+/* If device supports async unplug just request it to be done,
+ * otherwise just remove it synchronously */
+hdc = HOTPLUG_HANDLER_GET_CLASS(dev-parent_bus-hotplug_handler);
+if (hdc-unplug_request) {
+hotplug_handler_unplug_request(dev-parent_bus-hotplug_handler,
+   dev, errp);
+} else {
+hotplug_handler_unplug(dev-parent_bus-hotplug_handler, dev, 
errp);
+}
  } else {
  assert(dc-unplug != NULL);
  if (dc-unplug(dev)  0) { /* legacy handler */
diff --git a/include/hw/hotplug.h b/include/hw/hotplug.h
index e397d08..451d522 100644
--- a/include/hw/hotplug.h
+++ b/include/hw/hotplug.h
@@ -50,6 +50,9 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler,
   * @unplug_request: unplug request callback.
   *  Used as a means to initiate device unplug for devices that
   *  require asynchronous unplug handling.
+ * @unplug_request: unplug callback.


Typo, s/unplug_request/unplug ?

Thanks.


+ *  Used for device removal with devices that implement
+ *  asynchronous and synchronous (suprise) removal.
   */
  typedef struct HotplugHandlerClass {
  /* private */
@@ -58,6 +61,7 @@ typedef struct HotplugHandlerClass {
  /* public */
  hotplug_fn plug;
  hotplug_fn unplug_request;
+hotplug_fn unplug;
  } HotplugHandlerClass;
  
  /**

@@ -77,4 +81,12 @@ void hotplug_handler_plug(HotplugHandler *plug_handler,
  void hotplug_handler_unplug_request(HotplugHandler *plug_handler,
  DeviceState *plugged_dev,
  Error **errp);
+/**
+ * hotplug_handler_unplug:
+ *
+ * Calls #HotplugHandlerClass.unplug callback of @plug_handler.
+ */
+void hotplug_handler_unplug(HotplugHandler *plug_handler,
+DeviceState *plugged_dev,
+Error **errp);
  #endif





Re: [Qemu-devel] [PATCH 09/30] access BusState.allow_hotplug using wraper qbus_is_hotpluggable()

2014-09-24 Thread Tang Chen


On 09/24/2014 07:47 PM, Igor Mammedov wrote:

it would allow transparently switch detection if Bus
is hotpluggable from allow_hotplug field to hotplug_handler
link and drop allow_hotplug field once all users are
converted to hotplug handler API.

Signed-off-by: Igor Mammedov imamm...@redhat.com
---
  hw/core/qdev.c   | 6 +++---
  hw/i386/acpi-build.c | 2 +-
  hw/pci/pci-hotplug-old.c | 4 ++--
  include/hw/qdev-core.h   | 5 +
  qdev-monitor.c   | 2 +-
  5 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index fcb1638..5e5b963 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -86,7 +86,7 @@ static void bus_add_child(BusState *bus, DeviceState *child)
  BusChild *kid = g_malloc0(sizeof(*kid));
  
  if (qdev_hotplug) {

-assert(bus-allow_hotplug);
+assert(qbus_is_hotpluggable(bus));
  }
  
  kid-index = bus-max_index++;

@@ -213,7 +213,7 @@ void qdev_unplug(DeviceState *dev, Error **errp)
  {
  DeviceClass *dc = DEVICE_GET_CLASS(dev);
  
-if (dev-parent_bus  !dev-parent_bus-allow_hotplug) {

+if (dev-parent_bus  !qbus_is_hotpluggable(dev-parent_bus)) {
  error_set(errp, QERR_BUS_NO_HOTPLUG, dev-parent_bus-name);
  return;
  }
@@ -925,7 +925,7 @@ static bool device_get_hotpluggable(Object *obj, Error 
**errp)
  DeviceState *dev = DEVICE(obj);
  
  return dc-hotpluggable  (dev-parent_bus == NULL ||

-dev-parent_bus-allow_hotplug);
+qbus_is_hotpluggable(dev-parent_bus));
  }
  
  static bool device_get_hotplugged(Object *obj, Error **err)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index a313321..00be4bb 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -774,7 +774,7 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque)
  unsigned *bsel_alloc = opaque;
  unsigned *bus_bsel;
  
-if (bus-qbus.allow_hotplug) {

+if (qbus_is_hotpluggable(BUS(bus))) {
  bus_bsel = g_malloc(sizeof *bus_bsel);
  
  *bus_bsel = (*bsel_alloc)++;

diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
index cf2caeb..f9b7398 100644
--- a/hw/pci/pci-hotplug-old.c
+++ b/hw/pci/pci-hotplug-old.c
@@ -77,7 +77,7 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
  monitor_printf(mon, Invalid PCI device address %s\n, devaddr);
  return NULL;
  }
-if (!((BusState*)bus)-allow_hotplug) {
+if (!qbus_is_hotpluggable(BUS(bus))) {
  monitor_printf(mon, PCI bus doesn't support hotplug\n);
  return NULL;
  }
@@ -224,7 +224,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
  monitor_printf(mon, Invalid PCI device address %s\n, devaddr);
  return NULL;
  }
-if (!((BusState*)bus)-allow_hotplug) {
+if (!qbus_is_hotpluggable(BUS(bus))) {
  monitor_printf(mon, PCI bus doesn't support hotplug\n);
  return NULL;
  }
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 178fee2..48a96d2 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -368,4 +368,9 @@ static inline void qbus_set_hotplug_handler(BusState *bus, 
DeviceState *handler,
   QDEV_HOTPLUG_HANDLER_PROPERTY, errp);
  bus-allow_hotplug = 1;
  }
+
+static inline bool qbus_is_hotpluggable(BusState *bus)
+{
+   return bus-allow_hotplug || bus-hotplug_handler;


Why not synchronize these two members ?  What is the case that bus has
a hotplug_handler but allow_hotplug is false ?

BTW, I think there are other places that using bus-allow_hotplug 
directly, right ?


eg:
s390_virtio_bus_init()
{
..
_bus-allow_hotplug = 1;
..
}

Thanks.


+}
  #endif
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 5ec6606..f6db461 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -515,7 +515,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
  return NULL;
  }
  }
-if (qdev_hotplug  bus  !bus-allow_hotplug) {
+if (qdev_hotplug  bus  !qbus_is_hotpluggable(bus)) {
  qerror_report(QERR_BUS_NO_HOTPLUG, bus-name);
  return NULL;
  }





Re: [Qemu-devel] [PATCH 13/30] qdev: hotplug: set handler only if HOTPLUG_HANDLER interface is supported

2014-09-24 Thread Tang Chen


On 09/24/2014 07:48 PM, Igor Mammedov wrote:

Check if 'handler' implements HOTPLUG_HANDLER interface
before setting it, if it's not then do nothing and leave
bus not hotpluggable.

That would allow to reuse the same code for creating bus
for example 'scsi_bus_new()' for both hotpluggable and not
hotpluggable controllers.

Signed-off-by: Igor Mammedov imamm...@redhat.com
---
PS:
Keep allow_hotplug = 1 before check to preserve legacy
behaviour for incremental conversion without breaking
bisect-ability. I will be removed later in series.
---
  include/hw/qdev-core.h | 7 ++-
  1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index ba812c5..653ff4a 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -366,9 +366,14 @@ char *qdev_get_dev_path(DeviceState *dev);
  static inline void qbus_set_hotplug_handler(BusState *bus, DeviceState 
*handler,
  Error **errp)
  {
+bus-allow_hotplug = 1;


BTW, why not make allow_hotplug a bool ?

Thanks.


+
+if (!object_dynamic_cast(OBJECT(handler), TYPE_HOTPLUG_HANDLER)) {
+return;
+}
+
  object_property_set_link(OBJECT(bus), OBJECT(handler),
   QDEV_HOTPLUG_HANDLER_PROPERTY, errp);
-bus-allow_hotplug = 1;
  }
  
  static inline bool qbus_is_hotpluggable(BusState *bus)





  1   2   >