QEmu memory hot unplug support.
v4 cover QEmu memory hot unplug support.
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(-)
Signature · 1 line
1.8.4.2
PATCH RESEND v4 1/10 acpi, mem-hotplug: Use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().
Replace string "slot" in acpi_memory_plug_cb() with MACRO PC_DIMM_SLOT_PROP.
--- hw/acpi/memory_hotplug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/acpi/memory_hotplug.c +2 -1
@@ -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);
Signature · 1 line
1.8.4.2
PATCH RESEND v4 2/10 acpi, mem-hotplug: Add acpi_memory_get_slot_status_descriptor() to get MemStatus.
In reply to Tang ChenAdd 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.
--- hw/acpi/memory_hotplug.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
hw/acpi/memory_hotplug.c +19 -8
@@ -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;
Signature · 1 line
1.8.4.2
PATCH RESEND v4 3/10 acpi, mem-hotplug: Add acpi_memory_hotplug_sci() to rise sci for memory hotplug.
In reply to Tang ChenAdd 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.
--- hw/acpi/memory_hotplug.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
hw/acpi/memory_hotplug.c +8 -4
@@ -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 = {
Signature · 1 line
1.8.4.2
PATCH RESEND v4 4/10 acpi, mem-hotplug: Add acpi_memory_unplug_cb() to implement memory unplug.
In reply to Tang ChenAdd 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.
--- hw/acpi/memory_hotplug.c | 15 +++++++++++++++ include/hw/acpi/memory_hotplug.h | 3 +++ 2 files changed, 18 insertions(+)
hw/acpi/memory_hotplug.c +15 -0
@@ -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 ,
include/hw/acpi/memory_hotplug.h +3 -0
@@ -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) \
Signature · 1 line
1.8.4.2
PATCH RESEND v4 5/10 acpi, piix4: Add memory hot unplug support for piix4.
In reply to Tang ChenFrom: Hu Tao <[email protected]>
Implement acpi_memory_unplug_cb(), sending an sci to guest to trigger memory hot-remove, and call it in piix4_device_unplug_cb().
--- hw/acpi/piix4.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
hw/acpi/piix4.c +5 -1
@@ -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 {
Signature · 1 line
1.8.4.2
PATCH RESEND v4 6/10 acpi, ich9: Add memory hot unplug support for ich9.
In reply to Tang ChenImplement 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().
--- hw/acpi/ich9.c | 12 ++++++++++++ hw/isa/lpc_ich9.c | 5 +++-- include/hw/acpi/ich9.h | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-)
hw/acpi/ich9.c +12 -0
@@ -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);
hw/isa/lpc_ich9.c +3 -2
@@ -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)
include/hw/acpi/ich9.h +2 -0
@@ -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 */
Signature · 1 line
1.8.4.2
PATCH RESEND v4 7/10 pc: Add memory hot unplug support for pc machine.
In reply to Tang ChenFrom: Hu Tao <[email protected]>
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.
--- hw/i386/pc.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
hw/i386/pc.c +31 -0
@@ -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 = {
Signature · 1 line
1.8.4.2
PATCH RESEND v4 8/10 pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.
In reply to Tang ChenFrom: Hu Tao <[email protected]>
Implement unrealize function for pc-dimm device. It remove subregion from hotplug region, and delete ram address range from guest ram list.
--- hw/mem/pc-dimm.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
hw/mem/pc-dimm.c +10 -0
@@ -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;
Signature · 1 line
1.8.4.2
Re: [Qemu-devel] [RESEND PATCH v4 08/10] pc-dimm: Add pc_dimm_unrealize() for memory hot unplug support.
Quoted 4 lines · On Wed, 5 Nov 2014 13:49:53 +0800 Tang Chen <[email protected]> wrote:
From: Hu Tao <[email protected]>
Implement unrealize function for pc-dimm device. It remove subregion from hotplug region, and delete ram address range from guest ram list.
This still doesn't address comments made in V3
looks like there isn't any need for unrealize so far
Quoted 12 lines
Signed-off-by Hu Tao <[email protected]>Signed-off-by Tang Chen <[email protected]>--- hw/mem/pc-dimm.c | 10 ++++++++++ 1 file changed, 10 insertions(+)hw/mem/pc-dimm.c +0
-0
hw/mem/pc-dimm.c static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm) · line 278
Quoted 9 lines
hw/mem/pc-dimm.c +6
-0@@ -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);
you wouldn't need to access fields if it's done in unplug handler and you shouldn't access MemoryRegion fields directly in the first place
hw/mem/pc-dimm.c static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm) · line 279
Quoted 1 line
hw/mem/pc-dimm.c +1
-0+vmstate_unregister_ram (mr, dev);
all above should be done unplug handler by pc-machine
Quoted 12 lines
hw/mem/pc-dimm.c +3
-0+} +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;
PATCH RESEND v4 9/10 acpi: Add hardware implementation for memory hot unplug.
In reply to Tang ChenThis 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.
--- docs/specs/acpi_mem_hotplug.txt | 8 ++++++-- hw/acpi/memory_hotplug.c | 14 +++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-)
docs/specs/acpi_mem_hotplug.txt +6 -2
@@ -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
hw/acpi/memory_hotplug.c +11 -3
@@ -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,
Signature · 1 line
1.8.4.2
Re: [Qemu-devel] [RESEND PATCH v4 09/10] acpi: Add hardware implementation for memory hot unplug.
On Wed, Nov 05, 2014 at 01:49:54PM +0800, Tang Chen wrote:
<...>
docs/specs/acpi_mem_hotplug.txt Memory hot-plug interface (IO port 0xa00-0xa17, 1-4 byte access): · line 40
Quoted 2 lines
docs/specs/acpi_mem_hotplug.txt +1
-1- 2-7: reserved, OSPM must clear them before writing to register + 2: set by hardware after it has emitted devive eject event for
s/devive/device/
Regards,
Hu
PATCH RESEND v4 10/10 pc, acpi bios: Add memory hot unplug interface.
In reply to Tang ChenFrom: Hu Tao <[email protected]>
This patch implements MEMORY_SLOT_EJECT_METHOD according to ACPI spec.
--- 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(-)
hw/i386/ssdt-mem.dsl +5 -0
@@ -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) + } } } }
hw/i386/ssdt-misc.dsl +12 -1
@@ -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, 0xFFFF) 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, 0xFFFF) + Store(ToInteger(Arg0), MEMORY_SLOT_SLECTOR) // select DIMM + Store(One, MEMORY_SLOT_REMOVE_EVENT) + Release(MEMORY_SLOT_LOCK) + } } // Device() } // Scope() }
include/hw/acpi/pc-hotplug.h +2 -0
@@ -42,6 +42,7 @@#define MEMORY_SLOT_PROXIMITY MPX#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_EVENT MOEV#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_METHOD MTFY#define MEMORY_SLOT_SCAN_METHOD MSCN
Signature · 1 line
1.8.4.2
Quoted 3 lines · On Wed, 5 Nov 2014 13:49:45 +0800 Tang Chen <[email protected]> wrote:
This patch-set implements memory hot-remove for QEmu.
Rebased on Igor's asynchronize hotplug framework (qemu v2.1.2, the latest).
As I've wrote before, there were hot-unplug patches merged last month, see for reference http://lists.nongnu.org/archive/html/qemu-devel/2014-09/msg05195.html
and this series could benefit from them.
So please look take in account not addressed yet comments on V3 and rebase on current master instead of stable 2.1.2.
Quoted 48 lines
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_OSTfor 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 foris_removingflag 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: Addpc_dimm_unrealize()for memory hot unplug support. pc, acpi bios: Add memory hot unplug interface.Tang Chen (6):
acpi, mem-hotplug: UsePC_DIMM_SLOT_PROPinacpi_memory_plug_cb(). acpi, mem-hotplug: Addacpi_memory_get_slot_status_descriptor()to get
MemStatus.
acpi, mem-hotplug: Addacpi_memory_hotplug_sci()to rise sci for
memory hotplug.
acpi, mem-hotplug: Addacpi_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(-)