Skip to contentSkip to conversation

ACPI memory hotplug: QMP interfaces

PATCH Superseded Igor Mammedov 3 participants 14 messages Jun 5, 2014 – Jun 16, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ACPI memory hotplug: QMP interfaces

this is implemented on top of v4 memory hotplug series:
http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg00129.html

Series adds following QMP commands:
- query-memory-devices
- query-acpi-ospm-status
and event:
- ACPI_DEVICE_OST

Which could be used by management tools to query current state of memory devices (implemented only for PCDIMMDevice so far) and a related ACPI view of corresponding status of slots (ACPI Memory Device objects).

git tree for testing:
https://github.com/imammedo/qemu/commits/memory-hotplug-OST

Igor Mammedov (5):
qmp: add query-memory-devices command
acpi: introduce TYPE_ACPI_DEVICE_IF interface
acpi: implement ospm_status() method for PIIX4/ICH9_LPC devices
qmp: add query-acpi-ospm-status command
qmp: add ACPI_DEVICE_OST event handling

 docs/qmp/qmp-events.txt              |   10 ++++
 hw/acpi/Makefile.objs                |    1 +
 hw/acpi/acpi_interface.c             |   15 +++++
 hw/acpi/ich9.c                       |    7 +++
 hw/acpi/memory_hotplug.c             |   60 +++++++++++++++++++++-
 hw/acpi/piix4.c                      |   11 ++++
 hw/isa/lpc_ich9.c                    |    3 +
 hw/mem/pc-dimm.c                     |   39 ++++++++++++++
 include/hw/acpi/acpi_dev_interface.h |   43 +++++++++++++++
 include/hw/acpi/ich9.h               |    3 +
 include/hw/acpi/memory_hotplug.h     |    1 +
 include/hw/mem/pc-dimm.h             |    2 +
 include/monitor/monitor.h            |    1 +
 monitor.c                            |    1 +
 qapi-schema.json                     |   94 ++++++++++++++++++++++++++++++++++
 qmp-commands.hx                      |   49 ++++++++++++++++++
 qmp.c                                |   31 +++++++++++
 stubs/Makefile.objs                  |    1 +
 stubs/qmp_pc_dimm_device_list.c      |    7 +++
 19 files changed, 378 insertions(+), 1 deletions(-)
 create mode 100644 hw/acpi/acpi_interface.c
 create mode 100644 include/hw/acpi/acpi_dev_interface.h
 create mode 100644 stubs/qmp_pc_dimm_device_list.c
#1 lore raw

PATCH 1/5 qmp: add query-memory-devices command

... allowing to get state of present memory devices. Currently implemented only for PCDIMMDevice.

---
v2:
* fix typos an json syntax in QMP example
* make 'id' optional to allow command work with
anonymous memory devices

---
 hw/mem/pc-dimm.c                |   39 ++++++++++++++++++++++++++++
 include/hw/mem/pc-dimm.h        |    2 +
 qapi-schema.json                |   53 +++++++++++++++++++++++++++++++++++++++
 qmp-commands.hx                 |   27 ++++++++++++++++++++
 qmp.c                           |   11 ++++++++
 stubs/Makefile.objs             |    1 +
 stubs/qmp_pc_dimm_device_list.c |    7 +++++
 7 files changed, 140 insertions(+), 0 deletions(-)
 create mode 100644 stubs/qmp_pc_dimm_device_list.c
hw/mem/pc-dimm.c +39 -0
index 9f091c6..361071f 100644
@@ -23,6 +23,45 @@
 #include "qapi/visitor.h"
 #include "qemu/range.h"
 
+int qmp_pc_dimm_device_list(Object *obj, void *opaque)
+{
+    MemoryDeviceInfoList ***prev = opaque;
+
+    if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
+        DeviceState *dev = DEVICE(obj);
+
+        if (dev->realized) {
+            MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1);
+            MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1);
+            PCDIMMDeviceInfo *di = g_new0(PCDIMMDeviceInfo, 1);
+            DeviceClass *dc = DEVICE_GET_CLASS(obj);
+            PCDIMMDevice *dimm = PC_DIMM(obj);
+
+            if (dev->id) {
+                di->has_id = true;
+                di->id = g_strdup(dev->id);
+            }
+            di->hotplugged = dev->hotplugged;
+            di->hotpluggable = dc->hotpluggable;
+            di->addr = dimm->addr;
+            di->slot = dimm->slot;
+            di->node = dimm->node;
+            di->size = object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP,
+                                               NULL);
+            di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem));
+
+            info->dimm = di;
+            elem->value = info;
+            elem->next = NULL;
+            **prev = elem;
+            *prev = &elem->next;
+        }
+    }
+
+    object_child_foreach(obj, qmp_pc_dimm_device_list, opaque);
+    return 0;
+}
+
 static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
 {
     unsigned long *bitmap = opaque;
include/hw/mem/pc-dimm.h +2 -0
index 5f80d14..fa4cdd3 100644
@@ -76,4 +76,6 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
                                Error **errp);
 
 int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);
+
+int qmp_pc_dimm_device_list(Object *obj, void *opaque);
 #endif
qapi-schema.json +53 -0

56 lines not on this page · raw message

qmp-commands.hx +27 -0
index d8aa4ed..c0e0d9e 100644
@@ -3572,3 +3572,30 @@ Example:
                    } } ] }
 
 EQMP
+
+    {
+        .name       = "query-memory-devices",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_memory_devices,
+    },
+
+SQMP
+@query-memory-devices
+--------------------
+
+Return a list of memory devices.
+
+Example:
+-> { "execute": "query-memory-devices" }
+<- { "return": [ { "data":
+                      { "addr": 5368709120,
+                        "hotpluggable": true,
+                        "hotplugged": true,
+                        "id": "d1",
+                        "memdev": "/objects/memX",
+                        "node": 0,
+                        "size": 1073741824,
+                        "slot": 0},
+                   "type": "dimm"
+                 } ] }
+EQMP
qmp.c +11 -0
index b722dbe..66d2d67 100644
@@ -28,6 +28,7 @@
 #include "qapi/qmp-input-visitor.h"
 #include "hw/boards.h"
 #include "qom/object_interfaces.h"
+#include "hw/mem/pc-dimm.h"
 
 NameInfo *qmp_query_name(Error **errp)
 {
@@ -628,3 +629,13 @@ void qmp_object_del(const char *id, Error **errp)
     }
     object_unparent(obj);
 }
+
+MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
+{
+    MemoryDeviceInfoList *head = NULL;
+    MemoryDeviceInfoList **prev = &head;
+
+    qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
+
+    return head;
+}
stubs/Makefile.objs +1 -0
index d99e2b9..6a95122 100644
@@ -29,3 +29,4 @@ stub-obj-y += vmstate.o
 stub-obj-$(CONFIG_WIN32) += fd-register.o
 stub-obj-y += cpus.o
 stub-obj-y += kvm.o
+stub-obj-y += qmp_pc_dimm_device_list.o
stubs/qmp_pc_dimm_device_list.c new file +7 -0
new file mode 100644
index 0000000..5cb220c
@@ -0,0 +1,7 @@
+#include "qom/object.h"
+#include "hw/mem/pc-dimm.h"
+
+int qmp_pc_dimm_device_list(Object *obj, void *opaque)
+{
+   return 0;
+}
Signature · 1 line
1.7.1
Reviewed-by on v1 1/5
#2 lore raw

Re: [Qemu-devel] [PATCH 1/5] qmp: add query-memory-devices command

Quoted 23 lines · Igor Mammedov

... allowing to get state of present memory devices. Currently implemented only for PCDIMMDevice.

---
v2:
* fix typos an json syntax in QMP example
* make 'id' optional to allow command work with
anonymous memory devices

---
 hw/mem/pc-dimm.c                |   39 ++++++++++++++++++++++++++++
 include/hw/mem/pc-dimm.h        |    2 +
 qapi-schema.json                |   53 +++++++++++++++++++++++++++++++++++++++
 qmp-commands.hx                 |   27 ++++++++++++++++++++
 qmp.c                           |   11 ++++++++
 stubs/Makefile.objs             |    1 +
 stubs/qmp_pc_dimm_device_list.c |    7 +++++
 7 files changed, 140 insertions(+), 0 deletions(-)
 create mode 100644 stubs/qmp_pc_dimm_device_list.c

+++ b/qapi-schema.json

qapi-schema.json line 4731

Quoted 10 lines
qapi-schema.json +7 -0
@@ -4722,3 +4722,56 @@
               'btn'     : 'InputBtnEvent',
               'rel'     : 'InputMoveEvent',
               'abs'     : 'InputMoveEvent' } }
+
+##
+# @PCDIMMDeviceInfo:
+#
+# PCDIMMDevice state information
+#
+# @id: the device's ID

Might be worth annotating this as #optional

qapi-schema.json line 4735

Quoted 4 lines
qapi-schema.json +4 -0
+#
+# @addr: physical address, where device is mapped
+#
+# @size: size of memory device provides

grammar reads awkwardly; maybe 's/device/that the device/

qapi-schema.json line 4759

Quoted 11 lines
qapi-schema.json +11 -0
+{ 'type': 'PCDIMMDeviceInfo',
+  'data': { '*id': 'str',
+            'addr': 'int',
+            'size': 'int',
+            'slot': 'int',
+            'node': 'int',
+            'memdev': 'str',
+            'hotplugged': 'bool',
+            'hotpluggable': 'bool'
+          }
+}

Looks okay.

qapi-schema.json line 4769

Quoted 10 lines
qapi-schema.json +10 -0
+
+##
+# @MemoryDeviceInfo:
+#
+# Union containing information about a memory device
+#
+# Since: 2.1
+##
+{ 'union': 'MemoryDeviceInfo', 'data': {'dimm': 'PCDIMMDeviceInfo'} }
+

This command works, but it is a bit verbose. A flat union would be a bit more compact over the wire, but we don't yet have support for a flat union with an empty base class. So I'll live with this.

The two tweaks to the .json file only affect comments, so they are minor enough that I'm okay with:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw

PATCH 2/5 acpi: introduce TYPE_ACPI_DEVICE_IF interface

In reply to Igor Mammedov

... it will be used to abstract generic ACPI bits from device that implements ACPI interface.

ACPIOSTInfo type is used for passing-through raw _OST event/status codes reported by guest OS to a management layer. It lets management tools to interpret values as specified by ACPI spec if it interested in it.

QEMU doesn't encode these values as enum, since it doesn't need to handle them and it allows interface to scale well without any changes in QEMU while guest OS and management evolves in time.

---
v2:
- fix doc comments, describe not described fields
- add slot-type field with DIMM type for now, which later we could extend to PCI slots and probably to CPUs
- extend commit message describing why source/status are raw integers vs enum.

---
 hw/acpi/Makefile.objs                |    1 +
 hw/acpi/acpi_interface.c             |   15 ++++++++++++
 include/hw/acpi/acpi_dev_interface.h |   43 ++++++++++++++++++++++++++++++++++
 qapi-schema.json                     |   31 ++++++++++++++++++++++++
 4 files changed, 90 insertions(+), 0 deletions(-)
 create mode 100644 hw/acpi/acpi_interface.c
 create mode 100644 include/hw/acpi/acpi_dev_interface.h
hw/acpi/Makefile.objs +1 -0
index 004e1b2..acd2389 100644
@@ -1,2 +1,3 @@
 common-obj-$(CONFIG_ACPI) += core.o piix4.o ich9.o pcihp.o cpu_hotplug.o
 common-obj-$(CONFIG_ACPI) += memory_hotplug.o
+common-obj-$(CONFIG_ACPI) += acpi_interface.o
hw/acpi/acpi_interface.c new file +15 -0
new file mode 100644
index 0000000..c181bb2
@@ -0,0 +1,15 @@
+#include "hw/acpi/acpi_dev_interface.h"
+#include "qemu/module.h"
+
+static void register_types(void)
+{
+    static const TypeInfo acpi_dev_if_info = {
+        .name          = TYPE_ACPI_DEVICE_IF,
+        .parent        = TYPE_INTERFACE,
+        .class_size = sizeof(AcpiDeviceIfClass),
+    };
+
+    type_register_static(&acpi_dev_if_info);
+}
+
+type_init(register_types)
include/hw/acpi/acpi_dev_interface.h new file +43 -0

43 lines not on this page · raw message

qapi-schema.json +31 -0
index beb2de8..6d5651e 100644
@@ -4775,3 +4775,34 @@
 # Since: 2.1
 ##
 { 'command': 'query-memory-devices', 'returns': ['MemoryDeviceInfo'] }
+
+## @ACPISlotType
+#
+# @DIMM: memory slot
+#
+{ 'enum': 'ACPISlotType', 'data': [ 'DIMM' ] }
+
+## @ACPIOSTInfo
+#
+# OSPM Status Indication for a device
+# For description of possible values of @source and @status fields
+# see "_OST (OSPM Status Indication)" chapter of ACPI5.0 spec.
+#
+# @device: device ID accossiated with slot
+#
+# @slot: slot ID, unique per slot of a given @slot-type
+#
+# @slot-type: type of the slot
+#
+# @source: an integer containing the source event
+#
+# @status: an integer containing the status code
+#
+# Since: 2.1
+##
+{ 'type': 'ACPIOSTInfo',
+  'data'  : { '*device': 'str',
+              'slot': 'str',
+              'slot-type': 'ACPISlotType',
+              'source': 'int',
+              'status': 'int' } }
Signature · 1 line
1.7.1
Reviewed-by on v1 2/5
#4 lore raw

Re: [Qemu-devel] [PATCH 2/5] acpi: introduce TYPE_ACPI_DEVICE_IF interface

Quoted 6 lines · Igor Mammedov

... it will be used to abstract generic ACPI bits from device that implements ACPI interface.

ACPIOSTInfo type is used for passing-through raw _OST event/status codes reported by guest OS to a management layer. It lets management tools to interpret values

s/to //

Quoted 1 line

as specified by ACPI spec if it interested in it.

s/if it/if it is/

Quoted 24 lines

QEMU doesn't encode these values as enum, since it doesn't need to handle them and it allows interface to scale well without any changes in QEMU while guest OS and management evolves in time.

---
v2:
- fix doc comments, describe not described fields
- add slot-type field with DIMM type for now, which later we could extend to PCI slots and probably to CPUs
- extend commit message describing why source/status are raw integers vs enum.

---
 hw/acpi/Makefile.objs                |    1 +
 hw/acpi/acpi_interface.c             |   15 ++++++++++++
 include/hw/acpi/acpi_dev_interface.h |   43 ++++++++++++++++++++++++++++++++++
 qapi-schema.json                     |   31 ++++++++++++++++++++++++
 4 files changed, 90 insertions(+), 0 deletions(-)
 create mode 100644 hw/acpi/acpi_interface.c
 create mode 100644 include/hw/acpi/acpi_dev_interface.h

qapi-schema.json line 4791

Quoted 7 lines
qapi-schema.json +7 -0
+## @ACPIOSTInfo
+#
+# OSPM Status Indication for a device
+# For description of possible values of @source and @status fields
+# see "_OST (OSPM Status Indication)" chapter of ACPI5.0 spec.
+#
+# @device: device ID accossiated with slot

s/accossiated/associated/

Missing #optional annotation

Quoted 8 lines
qapi-schema.json +7 -0
+#
+# @slot: slot ID, unique per slot of a given @slot-type
+#
+# @slot-type: type of the slot
+#
+# @source: an integer containing the source event
+#

qapi-schema.json line 4808

Quoted 10 lines
qapi-schema.json +10 -0
+# @status: an integer containing the status code
+#
+# Since: 2.1
+##
+{ 'type': 'ACPIOSTInfo',
+  'data'  : { '*device': 'str',
+              'slot': 'str',
+              'slot-type': 'ACPISlotType',
+              'source': 'int',
+              'status': 'int' } }

Fix the docs, and you can add:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw

PATCH 3/5 acpi: implement ospm_status() method for PIIX4/ICH9_LPC devices

In reply to Igor Mammedov

... using TYPE_ACPI_DEVICE_IF interface.
Which provides status reporting of ACPI declared memory devices

---
v2:
- set slot-type to DIMM
- take into account that 'device' field could be optional

---
 hw/acpi/ich9.c                   |    7 +++++++
 hw/acpi/memory_hotplug.c         |   31 +++++++++++++++++++++++++++++++
 hw/acpi/piix4.c                  |   11 +++++++++++
 hw/isa/lpc_ich9.c                |    3 +++
 include/hw/acpi/ich9.h           |    3 +++
 include/hw/acpi/memory_hotplug.h |    1 +
 6 files changed, 56 insertions(+), 0 deletions(-)
hw/acpi/ich9.c +7 -0
index 2f66524..b9ebf63 100644
@@ -310,3 +310,10 @@ void ich9_pm_device_plug_cb(ICH9LPCPMRegs *pm, DeviceState *dev, Error **errp)
                    " type: %s", object_get_typename(OBJECT(dev)));
     }
 }
+
+void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
+{
+    ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
+
+    acpi_memory_ospm_status(&s->pm.acpi_memory_hotplug, list);
+}
hw/acpi/memory_hotplug.c +31 -0
index 71c7a5e..e7009bc 100644
@@ -4,6 +4,37 @@
 #include "hw/boards.h"
 #include "trace.h"
 
+static ACPIOSTInfo *acpi_memory_device_status(int slot, MemStatus *mdev)
+{
+    ACPIOSTInfo *info = g_new0(ACPIOSTInfo, 1);
+
+    info->slot_type = ACPI_SLOT_TYPE_DIMM;
+    info->slot = g_strdup_printf("%d", slot);
+    info->source = mdev->ost_event;
+    info->status = mdev->ost_status;
+    if (mdev->dimm) {
+        DeviceState *dev = DEVICE(mdev->dimm);
+        if (dev->id) {
+            info->device = g_strdup(dev->id);
+            info->has_device = true;
+        }
+    }
+    return info;
+}
+
+void acpi_memory_ospm_status(MemHotplugState *mem_st, ACPIOSTInfoList ***list)
+{
+    int i;
+
+    for (i = 0; i < mem_st->dev_count; i++) {
+        ACPIOSTInfoList *elem = g_new0(ACPIOSTInfoList, 1);
+        elem->value = acpi_memory_device_status(i, &mem_st->devs[i]);
+        elem->next = NULL;
+        **list = elem;
+        *list = &elem->next;
+    }
+}
+
 static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr addr,
                                          unsigned int size)
 {
hw/acpi/piix4.c +11 -0
index 7473485..6e2587f 100644
@@ -35,6 +35,7 @@
 #include "hw/hotplug.h"
 #include "hw/mem/pc-dimm.h"
 #include "hw/acpi/memory_hotplug.h"
+#include "hw/acpi/acpi_dev_interface.h"
 
 //#define DEBUG
 
@@ -574,6 +575,13 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
     }
 }
 
+static void piix4_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
+{
+    PIIX4PMState *s = PIIX4_PM(adev);
+
+    acpi_memory_ospm_status(&s->acpi_memory_hotplug, list);
+}
+
 static Property piix4_pm_properties[] = {
     DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0),
     DEFINE_PROP_UINT8(ACPI_PM_PROP_S3_DISABLED, PIIX4PMState, disable_s3, 0),
@@ -591,6 +599,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
+    AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_CLASS(klass);
 
     k->init = piix4_pm_initfn;
     k->config_write = pm_write_config;
@@ -609,6 +618,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
     dc->hotpluggable = false;
     hc->plug = piix4_device_plug_cb;
     hc->unplug = piix4_device_unplug_cb;
+    adevc->ospm_status = piix4_ospm_status;
 }
 
 static const TypeInfo piix4_pm_info = {
@@ -618,6 +628,7 @@ static const TypeInfo piix4_pm_info = {
     .class_init    = piix4_pm_class_init,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_HOTPLUG_HANDLER },
+        { TYPE_ACPI_DEVICE_IF },
         { }
     }
 };
hw/isa/lpc_ich9.c +3 -0
index 2adf29a..048653d 100644
@@ -657,6 +657,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
+    AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_CLASS(klass);
 
     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
     dc->reset = ich9_lpc_reset;
@@ -675,6 +676,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 = ich9_device_unplug_cb;
+    adevc->ospm_status = ich9_pm_ospm_status;
 }
 
 static const TypeInfo ich9_lpc_info = {
@@ -685,6 +687,7 @@ static const TypeInfo ich9_lpc_info = {
     .class_init  = ich9_lpc_class_init,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_HOTPLUG_HANDLER },
+        { TYPE_ACPI_DEVICE_IF },
         { }
     }
 };
include/hw/acpi/ich9.h +3 -0
index 1977f1b..7e42448 100644
@@ -24,6 +24,7 @@
 #include "hw/acpi/acpi.h"
 #include "hw/acpi/cpu_hotplug.h"
 #include "hw/acpi/memory_hotplug.h"
+#include "hw/acpi/acpi_dev_interface.h"
 
 typedef struct ICH9LPCPMRegs {
     /*
@@ -59,4 +60,6 @@ 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_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
 #endif /* HW_ACPI_ICH9_H */
include/hw/acpi/memory_hotplug.h +1 -0
index 4588459..7bbf8a0 100644
@@ -34,4 +34,5 @@ extern const VMStateDescription vmstate_memory_hotplug;
     VMSTATE_STRUCT(memhp, state, 1, \
                    vmstate_memory_hotplug, MemHotplugState)
 
+void acpi_memory_ospm_status(MemHotplugState *mem_st, ACPIOSTInfoList ***list);
 #endif
Signature · 1 line
1.7.1
Reviewed-by on v1 3/5
#6 lore raw

Re: [Qemu-devel] [PATCH 3/5] acpi: implement ospm_status() method for PIIX4/ICH9_LPC devices

Quoted 18 lines · Igor Mammedov

... using TYPE_ACPI_DEVICE_IF interface.
Which provides status reporting of ACPI declared memory devices

---
v2:
- set slot-type to DIMM
- take into account that 'device' field could be optional

---
 hw/acpi/ich9.c                   |    7 +++++++
 hw/acpi/memory_hotplug.c         |   31 +++++++++++++++++++++++++++++++
 hw/acpi/piix4.c                  |   11 +++++++++++
 hw/isa/lpc_ich9.c                |    3 +++
 include/hw/acpi/ich9.h           |    3 +++
 include/hw/acpi/memory_hotplug.h |    1 +
 6 files changed, 56 insertions(+), 0 deletions(-)
Quoted 1 line

+void acpi_memory_ospm_status(MemHotplugState *mem_st, ACPIOSTInfoList ***list);

Triple indirection looks unusual, but that doesn't make it wrong :)

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#7 lore raw

Re: [Qemu-devel] [PATCH 3/5] acpi: implement ospm_status() method for PIIX4/ICH9_LPC devices

Quoted 19 lines · On Mon, 16 Jun 2014 10:14:16 -0600 Eric Blake <[email protected]> wrote:
Quoted 17 lines · Igor Mammedov

... using TYPE_ACPI_DEVICE_IF interface.
Which provides status reporting of ACPI declared memory devices

---
v2:
- set slot-type to DIMM
- take into account that 'device' field could be optional

---
 hw/acpi/ich9.c                   |    7 +++++++
 hw/acpi/memory_hotplug.c         |   31 +++++++++++++++++++++++++++++++
 hw/acpi/piix4.c                  |   11 +++++++++++
 hw/isa/lpc_ich9.c                |    3 +++
 include/hw/acpi/ich9.h           |    3 +++
 include/hw/acpi/memory_hotplug.h |    1 +
 6 files changed, 56 insertions(+), 0 deletions(-)
Quoted 3 lines
Quoted 1 line

+void acpi_memory_ospm_status(MemHotplugState *mem_st, ACPIOSTInfoList ***list);

Triple indirection looks unusual, but that doesn't make it wrong :)

I plan to move ACPI code inside of interface handlers and drop piix4/ich9 stubs in favor of using QOM casting directly. So it would be -1 layer of indirection and not only for ospm_status().

In addition interface allows to avoid adding global function + stub where functionality is not implemented.

Quoted 3 lines
#8 lore raw

PATCH 4/5 qmp: add query-acpi-ospm-status command

In reply to Igor Mammedov

... to get ACPI OSPM status reported by ACPI devices via _OST method.

---
 qapi-schema.json |   10 ++++++++++
 qmp-commands.hx  |   22 ++++++++++++++++++++++
 qmp.c            |   20 ++++++++++++++++++++
 3 files changed, 52 insertions(+), 0 deletions(-)
qapi-schema.json +10 -0
index 6d5651e..39052ae 100644
@@ -4806,3 +4806,13 @@
               'slot-type': 'ACPISlotType',
               'source': 'int',
               'status': 'int' } }
+
+##
+# @query-acpi-ospm-status
+#
+# Lists ACPI OSPM status of ACPI device objects,
+# which might be reported via _OST method
+#
+# Since: 2.1
+##
+{ 'command': 'query-acpi-ospm-status', 'returns': ['ACPIOSTInfo'] }
qmp-commands.hx +22 -0
index c0e0d9e..1a0cfb3 100644
@@ -3599,3 +3599,25 @@ Example:
                    "type": "dimm"
                  } ] }
 EQMP
+
+    {
+        .name       = "query-acpi-ospm-status",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_acpi_ospm_status,
+    },
+
+SQMP
+@query-acpi-ospm-status
+--------------------
+
+Return list of ACPIOSTInfo for devices that support status reporting
+via ACPI _OST method.
+
+Example:
+-> { "execute": "query-acpi-ospm-status" }
+<- { "return": [ { "device": "d1", "slot": "0", "slot-type": "DIMM", "source": 1, "status": 0},
+                 { "slot": "1", "slot-type": "DIMM", "source": 0, "status": 0},
+                 { "slot": "2", "slot-type": "DIMM", "source": 0, "status": 0},
+                 { "slot": "3", "slot-type": "DIMM", "source": 0, "status": 0}
+   ]}
+EQMP
qmp.c +20 -0
index 66d2d67..3adcc6a 100644
@@ -29,6 +29,7 @@
 #include "hw/boards.h"
 #include "qom/object_interfaces.h"
 #include "hw/mem/pc-dimm.h"
+#include "hw/acpi/acpi_dev_interface.h"
 
 NameInfo *qmp_query_name(Error **errp)
 {
@@ -639,3 +640,22 @@ MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
 
     return head;
 }
+
+ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
+{
+    bool ambig;
+    ACPIOSTInfoList *head = NULL;
+    ACPIOSTInfoList **prev = &head;
+    Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig);
+
+    if (obj) {
+        AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
+        AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
+
+        adevc->ospm_status(adev, &prev);
+    } else {
+        error_setg(errp, "command is not supported, missing ACPI device");
+    }
+
+    return head;
+}
Signature · 1 line
1.7.1
Reviewed-by on v1 4/5
#9 lore raw

Re: [Qemu-devel] [PATCH 4/5] qmp: add query-acpi-ospm-status command

Quoted 10 lines · Igor Mammedov

... to get ACPI OSPM status reported by ACPI devices via _OST method.

---
 qapi-schema.json |   10 ++++++++++
 qmp-commands.hx  |   22 ++++++++++++++++++++++
 qmp.c            |   20 ++++++++++++++++++++
 3 files changed, 52 insertions(+), 0 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#10 lore raw

PATCH 5/5 qmp: add ACPI_DEVICE_OST event handling

In reply to Igor Mammedov

emmits event when ACPI OSPM evaluates _OST method
of ACPI device.

---
v2:
- move event decription at the beginning of file
to preserve alphabet ordering in file
- fix example json

---
 docs/qmp/qmp-events.txt   |   10 ++++++++++
 hw/acpi/memory_hotplug.c  |   29 ++++++++++++++++++++++++++++-
 include/monitor/monitor.h |    1 +
 monitor.c                 |    1 +
 4 files changed, 40 insertions(+), 1 deletions(-)
docs/qmp/qmp-events.txt +10 -0
index 145402e..019db53 100644
@@ -1,6 +1,16 @@
                    QEMU Machine Protocol Events
                    ============================
 
+ACPI_DEVICE_OST
+---------------
+
+Emitted when guest executes ACPI _OST method.
+
+ - data: ACPIOSTInfo type as described in qapi-schema.json
+
+{ "event": "ACPI_DEVICE_OST",
+     "data": { "device": "d1", "slot": "0", "slot-type": "DIMM", "source": 1, "status": 0 } }
+
 BALLOON_CHANGE
 --------------
 
hw/acpi/memory_hotplug.c +28 -1
index e7009bc..de4ddc2 100644
@@ -3,6 +3,10 @@
 #include "hw/mem/pc-dimm.h"
 #include "hw/boards.h"
 #include "trace.h"
+#include "qapi-visit.h"
+#include "monitor/monitor.h"
+#include "qapi/dealloc-visitor.h"
+#include "qapi/qmp-output-visitor.h"
 
 static ACPIOSTInfo *acpi_memory_device_status(int slot, MemStatus *mdev)
 {
@@ -35,6 +39,29 @@ void acpi_memory_ospm_status(MemHotplugState *mem_st, ACPIOSTInfoList ***list)
     }
 }
 
+static void acpi_memory_ost_mon_event(const MemHotplugState *mem_st)
+{
+    Visitor *v;
+    QObject *out_info;
+    QapiDeallocVisitor *md;
+    QmpOutputVisitor *mo = qmp_output_visitor_new();
+    MemStatus *mdev = &mem_st->devs[mem_st->selector];
+    ACPIOSTInfo *info = acpi_memory_device_status(mem_st->selector, mdev);
+
+    v = qmp_output_get_visitor(mo);
+    visit_type_ACPIOSTInfo(v, &info, "unused", NULL);
+
+    out_info = qmp_output_get_qobject(mo);
+    monitor_protocol_event(QEVENT_ACPI_OST, out_info);
+    qobject_decref(out_info);
+
+    qmp_output_visitor_cleanup(mo);
+    md = qapi_dealloc_visitor_new();
+    v = qapi_dealloc_get_visitor(md);
+    visit_type_ACPIOSTInfo(v, &info, "unused", NULL);
+    qapi_dealloc_visitor_cleanup(md);
+}
+
 static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr addr,
                                          unsigned int size)
 {
@@ -119,8 +146,8 @@ 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: report async error */
         /* TODO: implement memory removal on guest signal */
+        acpi_memory_ost_mon_event(mem_st);
         break;
     case 0x14:
         mdev = &mem_st->devs[mem_st->selector];
include/monitor/monitor.h +1 -0
index 1c1f56f..97696ea 100644
@@ -51,6 +51,7 @@ typedef enum MonitorEvent {
     QEVENT_BLOCK_IMAGE_CORRUPTED,
     QEVENT_QUORUM_FAILURE,
     QEVENT_QUORUM_REPORT_BAD,
+    QEVENT_ACPI_OST,
 
     /* Add to 'monitor_event_names' array in monitor.c when
      * defining new events here */
monitor.c +1 -0
index 593679a..c9717c2 100644
@@ -485,6 +485,7 @@ static const char *monitor_event_names[] = {
     [QEVENT_BLOCK_IMAGE_CORRUPTED] = "BLOCK_IMAGE_CORRUPTED",
     [QEVENT_QUORUM_FAILURE] = "QUORUM_FAILURE",
     [QEVENT_QUORUM_REPORT_BAD] = "QUORUM_REPORT_BAD",
+    [QEVENT_ACPI_OST] = "ACPI_DEVICE_OST",
 };
 QEMU_BUILD_BUG_ON(ARRAY_SIZE(monitor_event_names) != QEVENT_MAX)
 
Signature · 1 line
1.7.1
Reviewed-by on v1 5/5
#11 lore raw

Re: [Qemu-devel] [PATCH 5/5] qmp: add ACPI_DEVICE_OST event handling

Quoted 1 line · Igor Mammedov

emmits event when ACPI OSPM evaluates _OST method

s/emmits/emits/

Quoted 6 lines

of ACPI device.

---
v2:
- move event decription at the beginning of file

s/decription/description/ (but typos in the changelog don't matter :)

Quoted 8 lines

to preserve alphabet ordering in file
- fix example json

---
 docs/qmp/qmp-events.txt   |   10 ++++++++++
 hw/acpi/memory_hotplug.c  |   29 ++++++++++++++++++++++++++++-
 include/monitor/monitor.h |    1 +
 monitor.c                 |    1 +
 4 files changed, 40 insertions(+), 1 deletions(-)

It's a race to see whether this gets merged first, or whether Wenchao's event-as-QAPI series gets merged first (still waiting for v7 on that series; v6 was here[1]). Loser has to rebase :)

[1]https://lists.gnu.org/archive/html/qemu-devel/2014-06/msg01222.html

If this goes in first, and you can fix the typo in the commit message,

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#12 lore raw
In reply to Igor Mammedov
Quoted 9 lines · On Thu, 5 Jun 2014 16:36:03 +0200 Igor Mammedov <[email protected]> wrote:

this is implemented on top of v4 memory hotplug series:
http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg00129.html

Series adds following QMP commands:
- query-memory-devices
- query-acpi-ospm-status
and event:
- ACPI_DEVICE_OST

Quoted 4 lines

Which could be used by management tools to query current state of memory devices (implemented only for PCDIMMDevice so far) and a related ACPI view of corresponding status of slots (ACPI Memory Device objects).

ping

Quoted 36 lines

git tree for testing:
https://github.com/imammedo/qemu/commits/memory-hotplug-OST

Igor Mammedov (5):
qmp: add query-memory-devices command
acpi: introduce TYPE_ACPI_DEVICE_IF interface
acpi: implement ospm_status() method for PIIX4/ICH9_LPC devices
qmp: add query-acpi-ospm-status command
qmp: add ACPI_DEVICE_OST event handling

 docs/qmp/qmp-events.txt              |   10 ++++
 hw/acpi/Makefile.objs                |    1 +
 hw/acpi/acpi_interface.c             |   15 +++++
 hw/acpi/ich9.c                       |    7 +++
 hw/acpi/memory_hotplug.c             |   60 +++++++++++++++++++++-
 hw/acpi/piix4.c                      |   11 ++++
 hw/isa/lpc_ich9.c                    |    3 +
 hw/mem/pc-dimm.c                     |   39 ++++++++++++++
 include/hw/acpi/acpi_dev_interface.h |   43 +++++++++++++++
 include/hw/acpi/ich9.h               |    3 +
 include/hw/acpi/memory_hotplug.h     |    1 +
 include/hw/mem/pc-dimm.h             |    2 +
 include/monitor/monitor.h            |    1 +
 monitor.c                            |    1 +
 qapi-schema.json                     |   94 ++++++++++++++++++++++++++++++++++
 qmp-commands.hx                      |   49 ++++++++++++++++++
 qmp.c                                |   31 +++++++++++
 stubs/Makefile.objs                  |    1 +
 stubs/qmp_pc_dimm_device_list.c      |    7 +++
 19 files changed, 378 insertions(+), 1 deletions(-)
 create mode 100644 hw/acpi/acpi_interface.c
 create mode 100644 include/hw/acpi/acpi_dev_interface.h
 create mode 100644 stubs/qmp_pc_dimm_device_list.c
#13 lore raw
In reply to Igor Mammedov
Quoted 9 lines · Igor Mammedov

this is implemented on top of v4 memory hotplug series:
http://lists.gnu.org/archive/html/qemu-devel/2014-06/msg00129.html

Series adds following QMP commands:
- query-memory-devices
- query-acpi-ospm-status
and event:
- ACPI_DEVICE_OST

Quoted 7 lines

Which could be used by management tools to query current state of memory devices (implemented only for PCDIMMDevice so far) and a related ACPI view of corresponding status of slots (ACPI Memory Device objects).

git tree for testing:
https://github.com/imammedo/qemu/commits/memory-hotplug-OST

Could you please address Eric's comments
(once all of them are in) and rebase
on top of latest?

I think these will be ok post soft freeze.
Thanks.

Quoted 30 lines

Igor Mammedov (5):
qmp: add query-memory-devices command
acpi: introduce TYPE_ACPI_DEVICE_IF interface
acpi: implement ospm_status() method for PIIX4/ICH9_LPC devices
qmp: add query-acpi-ospm-status command
qmp: add ACPI_DEVICE_OST event handling

 docs/qmp/qmp-events.txt              |   10 ++++
 hw/acpi/Makefile.objs                |    1 +
 hw/acpi/acpi_interface.c             |   15 +++++
 hw/acpi/ich9.c                       |    7 +++
 hw/acpi/memory_hotplug.c             |   60 +++++++++++++++++++++-
 hw/acpi/piix4.c                      |   11 ++++
 hw/isa/lpc_ich9.c                    |    3 +
 hw/mem/pc-dimm.c                     |   39 ++++++++++++++
 include/hw/acpi/acpi_dev_interface.h |   43 +++++++++++++++
 include/hw/acpi/ich9.h               |    3 +
 include/hw/acpi/memory_hotplug.h     |    1 +
 include/hw/mem/pc-dimm.h             |    2 +
 include/monitor/monitor.h            |    1 +
 monitor.c                            |    1 +
 qapi-schema.json                     |   94 ++++++++++++++++++++++++++++++++++
 qmp-commands.hx                      |   49 ++++++++++++++++++
 qmp.c                                |   31 +++++++++++
 stubs/Makefile.objs                  |    1 +
 stubs/qmp_pc_dimm_device_list.c      |    7 +++
 19 files changed, 378 insertions(+), 1 deletions(-)
 create mode 100644 hw/acpi/acpi_interface.c
 create mode 100644 include/hw/acpi/acpi_dev_interface.h
 create mode 100644 stubs/qmp_pc_dimm_device_list.c