diff mbox

[RFC,4/5] qmp: add query-acpi-ospm-status command

Message ID 1401289056-28171-5-git-send-email-imammedo@redhat.com
State New
Headers show

Commit Message

Igor Mammedov May 28, 2014, 2:57 p.m. UTC
... to get ACPI OSPM status reported by ACPI devices
via _OST method.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 qapi-schema.json |    9 +++++++++
 qmp-commands.hx  |   22 ++++++++++++++++++++++
 qmp.c            |   20 ++++++++++++++++++++
 3 files changed, 51 insertions(+), 0 deletions(-)

Comments

Eric Blake May 30, 2014, 3:22 p.m. UTC | #1
On 05/28/2014 08:57 AM, Igor Mammedov wrote:
> ... to get ACPI OSPM status reported by ACPI devices
> via _OST method.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  qapi-schema.json |    9 +++++++++
>  qmp-commands.hx  |   22 ++++++++++++++++++++++
>  qmp.c            |   20 ++++++++++++++++++++
>  3 files changed, 51 insertions(+), 0 deletions(-)

Interface review:


> +Example:
> +-> { "execute": "query-acpi-ospm-status" }
> +<- { 'return': [ { 'device': 'd1', 'slot': 0, 'source': 1, 'status': 0},

Should 'status' be represented as an enum type, rather than an
open-coded integer?

> +                 { 'device': '', 'slot': 1, 'source': 0, 'status': 0},
> +                 { 'device': '', 'slot': 2, 'source': 0, 'status': 0},

Why not make 'device' optional, and omit it when there is no associated
device string?
Igor Mammedov May 30, 2014, 3:45 p.m. UTC | #2
On Fri, 30 May 2014 09:22:56 -0600
Eric Blake <eblake@redhat.com> wrote:

> On 05/28/2014 08:57 AM, Igor Mammedov wrote:
> > ... to get ACPI OSPM status reported by ACPI devices
> > via _OST method.
> > 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >  qapi-schema.json |    9 +++++++++
> >  qmp-commands.hx  |   22 ++++++++++++++++++++++
> >  qmp.c            |   20 ++++++++++++++++++++
> >  3 files changed, 51 insertions(+), 0 deletions(-)
> 
> Interface review:
> 
> 
> > +Example:
> > +-> { "execute": "query-acpi-ospm-status" }
> > +<- { 'return': [ { 'device': 'd1', 'slot': 0, 'source': 1, 'status': 0},
> 
> Should 'status' be represented as an enum type, rather than an
> open-coded integer?
it takes values from ACPI spec, which potentially could be anything
in 32bit range, it would be better to stick to spec.

> 
> > +                 { 'device': '', 'slot': 1, 'source': 0, 'status': 0},
> > +                 { 'device': '', 'slot': 2, 'source': 0, 'status': 0},
> 
> Why not make 'device' optional, and omit it when there is no associated
> device string?
Could you point to an example of an optional field?
 
> 
> -- 
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
Eric Blake May 30, 2014, 4:03 p.m. UTC | #3
On 05/30/2014 09:45 AM, Igor Mammedov wrote:
>>> +-> { "execute": "query-acpi-ospm-status" }
>>> +<- { 'return': [ { 'device': 'd1', 'slot': 0, 'source': 1, 'status': 0},
>>
>> Should 'status' be represented as an enum type, rather than an
>> open-coded integer?
> it takes values from ACPI spec, which potentially could be anything
> in 32bit range, it would be better to stick to spec.
> 
>>
>>> +                 { 'device': '', 'slot': 1, 'source': 0, 'status': 0},
>>> +                 { 'device': '', 'slot': 2, 'source': 0, 'status': 0},
>>
>> Why not make 'device' optional, and omit it when there is no associated
>> device string?
> Could you point to an example of an optional field?

Use this in the .json file:
'data' { '*device': 'str', 'slot': 'int', ... }

to set up the C code to have a 'has_device' bool parameter; when that
parameter is false, 'device' is omitted from the output.  (Well, we've
been arguing that has_device is redundant for pointers, when NULL serves
just as well, but that's a bigger code scrub).
diff mbox

Patch

diff --git a/qapi-schema.json b/qapi-schema.json
index 834ec59..5fa0766 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4793,3 +4793,12 @@ 
               'source': 'int',
               'status': 'int',
               'slot': 'int' } }
+
+##
+# @query-acpi-ospm-status
+#
+# Lists ACPI OSPM device statuses reported via _OST method
+#
+# Since: 2.1
+##
+{ 'command': 'query-acpi-ospm-status', 'returns': ['ACPIOSTInfo'] }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 45cb980..a757b39 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -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, 'source': 1, 'status': 0},
+                 { 'device': '', 'slot': 1, 'source': 0, 'status': 0},
+                 { 'device': '', 'slot': 2, 'source': 0, 'status': 0},
+                 { 'device': '', 'slot': 3, 'source': 0, 'status': 0}
+   ]}
+EQMP
diff --git a/qmp.c b/qmp.c
index 045d477..478710a 100644
--- a/qmp.c
+++ b/qmp.c
@@ -29,6 +29,7 @@ 
 #include "hw/boards.h"
 #include "qom/object_interfaces.h"
 #include "hw/mem/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;
+}