[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v4 23/30] dimm: add hot-remove capability
From: |
Vasilis Liaskovitis |
Subject: |
[Qemu-devel] [RFC PATCH v4 23/30] dimm: add hot-remove capability |
Date: |
Tue, 18 Dec 2012 13:41:51 +0100 |
On a succesfull _EJ0 operation unmap the device from the guest by using the new
qdev function qdev_unplug_complete, see:
https://lists.gnu.org/archive/html/qemu-devel/2012-11/msg02699.html
The memory of the device should be freed when the last subsystem using it
unmaps it, see the following two series:
https://lists.gnu.org/archive/html/qemu-devel/2012-11/msg00728.html
https://lists.gnu.org/archive/html/qemu-devel/2012-11/msg02697.html
Needs testing. Other subsystems (e.g. virtio-blk) may have to install new
memorylisteners to complete pending I/O before device memory can be freed.
Signed-off-by: Vasilis Liaskovitis <address@hidden>
---
hw/dimm.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
hw/dimm.h | 1 +
2 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/hw/dimm.c b/hw/dimm.c
index e79f23d..0b4e22d 100644
--- a/hw/dimm.c
+++ b/hw/dimm.c
@@ -120,6 +120,18 @@ static void dimm_populate(DimmDevice *s)
s->mr = new;
}
+static int dimm_depopulate(DeviceState *dev)
+{
+ DimmDevice *s = DIMM(dev);
+ assert(s);
+ vmstate_unregister_ram(s->mr, NULL);
+ memory_region_del_subregion(get_system_memory(), s->mr);
+ memory_region_destroy(s->mr);
+ s->populated = false;
+ s->mr = NULL;
+ return 0;
+}
+
void dimm_config_create(char *id, uint64_t size, const char *bus, uint64_t
node,
uint32_t dimm_idx, uint32_t populated)
{
@@ -159,6 +171,11 @@ static void dimm_plug_device(DimmDevice *slot)
static int dimm_unplug_device(DeviceState *qdev)
{
+ DimmBus *bus = DIMM_BUS(qdev_get_parent_bus(qdev));
+
+ if (bus->dimm_hotplug) {
+ bus->dimm_hotplug(bus->dimm_hotplug_qdev, DIMM(qdev), 0);
+ }
return 1;
}
@@ -186,6 +203,21 @@ static DimmDevice *dimm_find_from_name(DimmBus *bus, const
char *name)
return NULL;
}
+static DimmDevice *dimm_find_from_idx(uint32_t idx)
+{
+ DimmDevice *slot;
+ DimmBus *bus;
+
+ QLIST_FOREACH(bus, &memory_buses, next) {
+ QTAILQ_FOREACH(slot, &bus->dimmlist, nextdimm) {
+ if (slot->idx == idx) {
+ return slot;
+ }
+ }
+ }
+ return NULL;
+}
+
void dimm_setup_fwcfg_layout(uint64_t *fw_cfg_slots)
{
DimmConfig *slot;
@@ -275,6 +307,24 @@ static int dimm_init(DeviceState *s)
return 0;
}
+void dimm_notify(uint32_t idx, uint32_t event)
+{
+ DimmBus *bus;
+ DimmDevice *slot;
+
+ slot = dimm_find_from_idx(idx);
+ assert(slot != NULL);
+ bus = DIMM_BUS(qdev_get_parent_bus(&slot->qdev));
+
+ switch (event) {
+ case DIMM_REMOVE_SUCCESS:
+ qdev_unplug_complete((DeviceState *)slot, NULL);
+ QTAILQ_REMOVE(&bus->dimmlist, slot, nextdimm);
+ break;
+ default:
+ break;
+ }
+}
static void dimm_class_init(ObjectClass *klass, void *data)
{
@@ -283,6 +333,7 @@ static void dimm_class_init(ObjectClass *klass, void *data)
dc->props = dimm_properties;
dc->unplug = dimm_unplug_device;
dc->init = dimm_init;
+ dc->exit = dimm_depopulate;
dc->bus_type = TYPE_DIMM_BUS;
}
diff --git a/hw/dimm.h b/hw/dimm.h
index 5130b2c..86c7cd5 100644
--- a/hw/dimm.h
+++ b/hw/dimm.h
@@ -86,5 +86,6 @@ DimmBus *dimm_bus_create(Object *parent, const char *name,
uint32_t max_dimms,
void dimm_config_create(char *id, uint64_t size, const char *bus, uint64_t
node,
uint32_t dimm_idx, uint32_t populated);
uint64_t get_hp_memory_total(void);
+void dimm_notify(uint32_t idx, uint32_t event);
#endif
--
1.7.9
- [Qemu-devel] [RFC PATCH v4 11/30] acpi_piix4 : Implement memory device hotplug registers, (continued)
- [Qemu-devel] [RFC PATCH v4 11/30] acpi_piix4 : Implement memory device hotplug registers, Vasilis Liaskovitis, 2012/12/18
- [Qemu-devel] [RFC PATCH v4 14/30] piix_pci: Add i440fx dram controller initialization, Vasilis Liaskovitis, 2012/12/18
- [Qemu-devel] [RFC PATCH v4 18/30] Introduce paravirt interface QEMU_CFG_PCI_WINDOW, Vasilis Liaskovitis, 2012/12/18
- [Qemu-devel] [RFC PATCH v4 20/30] balloon: update with hotplugged memory, Vasilis Liaskovitis, 2012/12/18
- [Qemu-devel] [RFC PATCH v4 26/30] Implement qmp and hmp commands for notification lists, Vasilis Liaskovitis, 2012/12/18
- [Qemu-devel] [RFC PATCH v4 29/30] [SeaBIOS] Implement _PS3 method for memory device, Vasilis Liaskovitis, 2012/12/18
- [Qemu-devel] [RFC PATCH v4 30/30] Implement _PS3 for dimm, Vasilis Liaskovitis, 2012/12/18
- [Qemu-devel] [RFC PATCH v4 28/30] Add _OST dimm support, Vasilis Liaskovitis, 2012/12/18
- [Qemu-devel] [RFC PATCH v4 27/30] [SeaBIOS] Add _OST dimm method, Vasilis Liaskovitis, 2012/12/18
- [Qemu-devel] [RFC PATCH v4 21/30] Implement dimm-info, Vasilis Liaskovitis, 2012/12/18
- [Qemu-devel] [RFC PATCH v4 23/30] dimm: add hot-remove capability,
Vasilis Liaskovitis <=
- [Qemu-devel] [RFC PATCH v4 25/30] acpi_ich9: add hot-remove capability, Vasilis Liaskovitis, 2012/12/18
- [Qemu-devel] [RFC PATCH v4 19/30] Implement "info memory-total" and "query-memory-total", Vasilis Liaskovitis, 2012/12/18
- [Qemu-devel] [RFC PATCH v4 22/30] [SeaBIOS] acpi: add _EJ0 operation and eject port for memory devices, Vasilis Liaskovitis, 2012/12/18
- [Qemu-devel] [RFC PATCH v4 24/30] acpi_piix4: add hot-remove capability, Vasilis Liaskovitis, 2012/12/18
- Re: [Qemu-devel] [RFC PATCH v4 00/30] ACPI memory hotplug, Zhi Yong Wu, 2012/12/18
- Re: [Qemu-devel] [RFC PATCH v4 00/30] ACPI memory hotplug, Gerd Hoffmann, 2012/12/19