[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensors' Q
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensors' QMP command |
Date: |
Tue, 21 Apr 2020 14:16:11 +0200 |
Add a command to query current temperature from all sensors able
to report it:
{ "execute": "query-temperature-sensors" }
{
"return": [
{
"temperature": 25,
"name": "videocore"
},
{
"temperature": 25,
"name": "bcm2835-thermal-0"
}
]
}
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
qapi/misc.json | 24 ++++++++++++++++++++++
hw/misc/temp-sensor.c | 48 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/qapi/misc.json b/qapi/misc.json
index 99b90ac80b..51881931e2 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -1550,3 +1550,27 @@
##
{ 'command': 'query-vm-generation-id', 'returns': 'GuidInfo' }
+##
+# @TemperatureSensor:
+#
+# Temperature sensor information.
+#
+# @name: the name of the sensor
+#
+# @temperature: the current temperature of the sensor (in C)
+#
+# Since: 5.1
+##
+{ 'struct': 'TemperatureSensor',
+ 'data': { 'name': 'str',
+ 'temperature': 'number' } }
+
+##
+# @query-temperature-sensors:
+#
+# Return a list of TemperatureSensor for devices that support
+# the TYPE_TEMPSENSOR_INTERFACE.
+#
+# Since: 5.1
+##
+{ 'command': 'query-temperature-sensors', 'returns': ['TemperatureSensor']}
diff --git a/hw/misc/temp-sensor.c b/hw/misc/temp-sensor.c
index b7c1eb2d87..27750c533d 100644
--- a/hw/misc/temp-sensor.c
+++ b/hw/misc/temp-sensor.c
@@ -10,6 +10,54 @@
#include "qemu/osdep.h"
#include "hw/misc/temp-sensor.h"
+#include "qapi/qapi-commands-misc.h"
+#include "qapi/error.h"
+
+static int query_temperature_sensors_foreach(Object *obj, void *opaque)
+{
+ TemperatureSensorList **list = opaque;
+ TempSensor *sensor;
+ TempSensorClass *k;
+
+ if (!object_dynamic_cast(obj, TYPE_TEMPSENSOR_INTERFACE)) {
+ return 0;
+ }
+
+ k = TEMPSENSOR_INTERFACE_GET_CLASS(obj);
+ if (!k->get_temperature) {
+ return 0;
+ }
+
+ sensor = TEMPSENSOR_INTERFACE(obj);
+ for (size_t i = 0; i < k->sensor_count; i++) {
+ TemperatureSensorList *info = g_malloc0(sizeof(*info));
+ TemperatureSensor *value = g_malloc0(sizeof(*value));
+
+ if (k->get_name) {
+ value->name = g_strdup(k->get_name(sensor, i));
+ } else {
+ value->name = g_strdup_printf("%s-%zu",
+ object_get_typename(obj), i);
+ }
+ value->temperature = k->get_temperature(sensor, i);
+
+ info->value = value;
+ info->next = *list;
+ *list = info;
+ }
+
+ return 0;
+}
+
+TemperatureSensorList *qmp_query_temperature_sensors(Error **errp)
+{
+ TemperatureSensorList *list = NULL;
+
+ object_child_foreach_recursive(object_get_root(),
+ query_temperature_sensors_foreach,
+ &list);
+ return list;
+}
static TypeInfo tempsensor_interface_type_info = {
.name = TYPE_TEMPSENSOR_INTERFACE,
--
2.21.1
- [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensors' QMP command,
Philippe Mathieu-Daudé <=
- [RFC PATCH 03/17] hw/misc/temp-sensor: Add 'info temp' HMP command, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 01/17] hw/misc: Introduce the temperature sensor interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 06/17] hw/misc/tmp421: Add definition for SENSORS_COUNT, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 08/17] hw/misc/tmp421: Extract set_temp_mC() helper, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 04/17] hw/misc/tmp105: Extract get_temp_mC() and set_temp_mC() helpers, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 05/17] hw/misc/tmp105: Implement the 'temperature-sensor' qdev interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 09/17] hw/misc/tmp421: Implement the 'temperature-sensor' qdev interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 10/17] hw/misc/bcm2835_thermal: Hold the temperature in the device state, Philippe Mathieu-Daudé, 2020/04/21