QEmu memory hot unplug support.
v4 cover QEmu memory hot unplug support.
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(-)
Signature · 1 line
1.8.4.2
PATCH v4 1/12 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 v4 2/12 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 v4 3/12 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 v4 4/12 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 v4 5/12 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
@@ -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 {
Signature · 1 line
1.8.4.2
PATCH v4 6/12 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
@@ -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);
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_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
@@ -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 */
Signature · 1 line
1.8.4.2
PATCH v4 7/12 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
@@ -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 = {
Signature · 1 line
1.8.4.2
PATCH v4 8/12 qdev: Add memory hot unplug support for bus-less devices.
In reply to Tang ChenFrom: Hu Tao <[email protected]>
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.
--- hw/core/qdev.c | 8 ++++++++ 1 file changed, 8 insertions(+)
hw/core/qdev.c +8 -0
@@ -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 */
Signature · 1 line
1.8.4.2
PATCH v4 9/12 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
PATCH v4 10/12 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
PATCH v4 11/12 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
PATCH v4 12/12 monitor: Add memory hot unplug support for device_del command.
In reply to Tang ChenFrom: Hu Tao <[email protected]>
Implement find_peripheral_device() to find bus-less device, and call it in qmp_device_del() so that device_del command will be able to remove memory device.
--- qdev-monitor.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
qdev-monitor.c +46 -0
@@ -51,6 +51,13 @@ static const QDevAlias qdev_alias_table[] = { { } }; +/* Used as the type of parameter opaque in object_child_foreach(). */ +typedef struct QPeripheralDev +{ +const char *id; +DeviceState *dev; +}QPeripheralDev ; +static const char *qdev_class_get_alias (DeviceClass *dc) {const char *typename =object_class_get_name (OBJECT_CLASS (dc));
@@ -683,12 +690,51 @@ int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)return 0 ; } +static int query_peripheral_device (Object *obj,void *opaque) +{ +QPeripheralDev *pdev = (QPeripheralDev *)opaque; +DeviceState *dev = (DeviceState *)obj; + +if (!strcmp (pdev->id, dev->id)) { + pdev->dev = dev; +return 1 ; + } + +return 0 ; +} + +static DeviceState *find_peripheral_device (const char *id) +{ +Object *peripheral =NULL ; +QPeripheralDev pdev = { + .id = id, + .dev =NULL + }; + + peripheral =qdev_get_peripheral (); +if (!peripheral) +return NULL ; + +/* +* No need to check return value of object_child_foreach() because when +* query_peripheral_device() returns, pdev->dev is the device we are +* looking for, or NULL. +*/ +object_child_foreach (peripheral, query_peripheral_device, &pdev); + +return pdev.dev; +} +void qmp_device_del (const char *id,Error **errp) {DeviceState *dev; dev =qdev_find_recursive (sysbus_get_default (), id);if (!dev) { + dev =find_peripheral_device (id); + } + +if (!dev) {error_set (errp,QERR_DEVICE_NOT_FOUND , id);return ; }
Signature · 1 line
1.8.4.2