* [RFC PATCH 01/17] hw/misc: Introduce the temperature sensor interface
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensors' QMP command Philippe Mathieu-Daudé
` (15 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
Introduce an interface to set and get temperature from devices.
A device can have multiple temperature sensors.
Each sensor might have a custom name.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/misc/temp-sensor.h | 69 +++++++++++++++++++++++++++++++++++
hw/misc/temp-sensor.c | 25 +++++++++++++
MAINTAINERS | 6 +++
hw/misc/Makefile.objs | 1 +
4 files changed, 101 insertions(+)
create mode 100644 include/hw/misc/temp-sensor.h
create mode 100644 hw/misc/temp-sensor.c
diff --git a/include/hw/misc/temp-sensor.h b/include/hw/misc/temp-sensor.h
new file mode 100644
index 0000000000..3067b1dd2e
--- /dev/null
+++ b/include/hw/misc/temp-sensor.h
@@ -0,0 +1,69 @@
+/*
+ * Generic interface for temperature sensors
+ *
+ * Copyright (c) 2020 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef HW_MISC_TEMP_SENSOR_H
+#define HW_MISC_TEMP_SENSOR_H
+
+#include "qom/object.h"
+
+#define TYPE_TEMPSENSOR_INTERFACE "temp-sensor-interface"
+#define TEMPSENSOR_INTERFACE(obj) \
+ INTERFACE_CHECK(TempSensor, (obj), TYPE_TEMPSENSOR_INTERFACE)
+#define TEMPSENSOR_INTERFACE_CLASS(class) \
+ OBJECT_CLASS_CHECK(TempSensorClass, (class), TYPE_TEMPSENSOR_INTERFACE)
+#define TEMPSENSOR_INTERFACE_GET_CLASS(class) \
+ OBJECT_GET_CLASS(TempSensorClass, (class), TYPE_TEMPSENSOR_INTERFACE)
+
+typedef struct TempSensor TempSensor;
+
+typedef struct TempSensorClass {
+ /* <private> */
+ InterfaceClass parent;
+ /* <public> */
+
+ /** Number of temperature sensors */
+ size_t sensor_count;
+
+ /**
+ * get_name:
+ * @obj: opaque pointer to Object
+ * @sensor_id: sensor index
+ *
+ * Returns: name of a temperature sensor.
+ */
+ const char *(*get_name)(TempSensor *obj, unsigned sensor_id);
+
+ /**
+ * set_temperature:
+ * @obj: opaque pointer to Object
+ * @sensor_id: sensor index
+ * @temp_C: sensor temperature, in degree Celsius
+ * @errp: pointer to a NULL-initialized error object
+ *
+ * Set a sensor temperature.
+ *
+ * If an error occurs @errp will contain the details
+ * (likely temperature out of range).
+ */
+ void (*set_temperature)(TempSensor *obj,
+ unsigned sensor_id, float temp_C, Error **errp);
+
+ /**
+ * get_temperature:
+ * @obj: opaque pointer to Object
+ * @sensor_id: sensor index
+ *
+ * Get a sensor temperature.
+ *
+ * Returns: sensor temperature in °C.
+ */
+ float (*get_temperature)(TempSensor *obj, unsigned sensor_id);
+} TempSensorClass;
+
+#endif /* HW_MISC_TEMP_SENSOR_H */
diff --git a/hw/misc/temp-sensor.c b/hw/misc/temp-sensor.c
new file mode 100644
index 0000000000..b7c1eb2d87
--- /dev/null
+++ b/hw/misc/temp-sensor.c
@@ -0,0 +1,25 @@
+/*
+ * Generic interface for temperature sensors
+ *
+ * Copyright (c) 2020 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "hw/misc/temp-sensor.h"
+
+static TypeInfo tempsensor_interface_type_info = {
+ .name = TYPE_TEMPSENSOR_INTERFACE,
+ .parent = TYPE_INTERFACE,
+ .class_size = sizeof(TempSensorClass),
+};
+
+static void tempsensor_register_types(void)
+{
+ type_register_static(&tempsensor_interface_type_info);
+}
+
+type_init(tempsensor_register_types)
diff --git a/MAINTAINERS b/MAINTAINERS
index 8cbc1fac2b..5559110c56 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1575,6 +1575,12 @@ F: hw/sd/sd*
F: hw/sd/ssi-sd.c
F: tests/qtest/sd*
+Temperature Sensors
+M: Philippe Mathieu-Daudé <f4bug@amsat.org>
+S: Odd Fixes
+F: hw/misc/temp-sensor.c
+F: include/hw/misc/temp-sensor.h
+
USB
M: Gerd Hoffmann <kraxel@redhat.com>
S: Maintained
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
index 68aae2eabb..4f90efb06d 100644
--- a/hw/misc/Makefile.objs
+++ b/hw/misc/Makefile.objs
@@ -90,3 +90,4 @@ common-obj-$(CONFIG_NRF51_SOC) += nrf51_rng.o
obj-$(CONFIG_MAC_VIA) += mac_via.o
common-obj-$(CONFIG_GRLIB) += grlib_ahb_apb_pnp.o
+common-obj-y += temp-sensor.o
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensors' QMP command
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 01/17] hw/misc: Introduce the " Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 16:27 ` Dr. David Alan Gilbert
2020-04-21 12:16 ` [RFC PATCH 03/17] hw/misc/temp-sensor: Add 'info temp' HMP command Philippe Mathieu-Daudé
` (14 subsequent siblings)
16 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
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é <f4bug@amsat.org>
---
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
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensors' QMP command
2020-04-21 12:16 ` [RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensors' QMP command Philippe Mathieu-Daudé
@ 2020-04-21 16:27 ` Dr. David Alan Gilbert
0 siblings, 0 replies; 20+ messages in thread
From: Dr. David Alan Gilbert @ 2020-04-21 16:27 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, qemu-devel, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Markus Armbruster
* Philippe Mathieu-Daudé (f4bug@amsat.org) wrote:
> 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é <f4bug@amsat.org>
> ---
> 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);
> + }
How do the names work if you've got multiple of the same device; e.g.
is the get_name() method supposed to return the device path as well as
the sensor name? if I have an emulated PCI device with two sensors on
and I then instantiate two of the PCI devices, do I get a name with the
PCI path in?
Dave
> + 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
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 20+ messages in thread
* [RFC PATCH 03/17] hw/misc/temp-sensor: Add 'info temp' HMP command
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 01/17] hw/misc: Introduce the " Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensors' QMP command Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 18:00 ` Dr. David Alan Gilbert
2020-04-21 12:16 ` [RFC PATCH 04/17] hw/misc/tmp105: Extract get_temp_mC() and set_temp_mC() helpers Philippe Mathieu-Daudé
` (13 subsequent siblings)
16 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
Add a command to display current devices temperature in the monitor:
(qemu) info temp
Temperatures (in C):
videocore 25.00
bcm2835-thermal-0 25.00
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/monitor/hmp.h | 1 +
hw/misc/temp-sensor.c | 29 +++++++++++++++++++++++++++++
hmp-commands-info.hx | 11 +++++++++++
3 files changed, 41 insertions(+)
diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
index e33ca5a911..f023230bd1 100644
--- a/include/monitor/hmp.h
+++ b/include/monitor/hmp.h
@@ -129,5 +129,6 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict);
void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict);
void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict);
void hmp_info_sev(Monitor *mon, const QDict *qdict);
+void hmp_info_temp(Monitor *mon, const QDict *qdict);
#endif
diff --git a/hw/misc/temp-sensor.c b/hw/misc/temp-sensor.c
index 27750c533d..5f591bd9c3 100644
--- a/hw/misc/temp-sensor.c
+++ b/hw/misc/temp-sensor.c
@@ -12,6 +12,8 @@
#include "hw/misc/temp-sensor.h"
#include "qapi/qapi-commands-misc.h"
#include "qapi/error.h"
+#include "monitor/monitor.h"
+#include "monitor/hmp.h"
static int query_temperature_sensors_foreach(Object *obj, void *opaque)
{
@@ -59,6 +61,33 @@ TemperatureSensorList *qmp_query_temperature_sensors(Error **errp)
return list;
}
+void hmp_info_temp(Monitor *mon, const QDict *qdict)
+{
+ TemperatureSensorList *list, *sensor;
+ Error *err = NULL;
+
+ list = qmp_query_temperature_sensors(&err);
+ if (!list) {
+ monitor_printf(mon, "No temperature sensors\n");
+ return;
+ }
+ if (err) {
+ monitor_printf(mon, "Error while getting temperatures: %s\n",
+ error_get_pretty(err));
+ error_free(err);
+ goto out;
+ }
+
+ monitor_printf(mon, "Temperatures (in C):\n");
+ for (sensor = list; sensor; sensor = sensor->next) {
+ monitor_printf(mon, "%-33s %6.2f\n", sensor->value->name,
+ sensor->value->temperature);
+ }
+
+out:
+ qapi_free_TemperatureSensorList(list);
+}
+
static TypeInfo tempsensor_interface_type_info = {
.name = TYPE_TEMPSENSOR_INTERFACE,
.parent = TYPE_INTERFACE,
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index ca5198438d..77f1c43ce3 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -880,4 +880,15 @@ SRST
Show SEV information.
ERST
+ {
+ .name = "temp",
+ .args_type = "",
+ .params = "",
+ .help = "show device temperatures",
+ .cmd = hmp_info_temp,
+ },
+SRST
+ ``info temp``
+ Show device temperatures.
+ERST
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [RFC PATCH 03/17] hw/misc/temp-sensor: Add 'info temp' HMP command
2020-04-21 12:16 ` [RFC PATCH 03/17] hw/misc/temp-sensor: Add 'info temp' HMP command Philippe Mathieu-Daudé
@ 2020-04-21 18:00 ` Dr. David Alan Gilbert
0 siblings, 0 replies; 20+ messages in thread
From: Dr. David Alan Gilbert @ 2020-04-21 18:00 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, qemu-devel, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Markus Armbruster
* Philippe Mathieu-Daudé (f4bug@amsat.org) wrote:
> Add a command to display current devices temperature in the monitor:
>
> (qemu) info temp
> Temperatures (in C):
> videocore 25.00
> bcm2835-thermal-0 25.00
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
How do I set the temperature?
> ---
> include/monitor/hmp.h | 1 +
> hw/misc/temp-sensor.c | 29 +++++++++++++++++++++++++++++
> hmp-commands-info.hx | 11 +++++++++++
> 3 files changed, 41 insertions(+)
>
> diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
> index e33ca5a911..f023230bd1 100644
> --- a/include/monitor/hmp.h
> +++ b/include/monitor/hmp.h
> @@ -129,5 +129,6 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict);
> void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict);
> void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict);
> void hmp_info_sev(Monitor *mon, const QDict *qdict);
> +void hmp_info_temp(Monitor *mon, const QDict *qdict);
>
> #endif
> diff --git a/hw/misc/temp-sensor.c b/hw/misc/temp-sensor.c
> index 27750c533d..5f591bd9c3 100644
> --- a/hw/misc/temp-sensor.c
> +++ b/hw/misc/temp-sensor.c
> @@ -12,6 +12,8 @@
> #include "hw/misc/temp-sensor.h"
> #include "qapi/qapi-commands-misc.h"
> #include "qapi/error.h"
> +#include "monitor/monitor.h"
> +#include "monitor/hmp.h"
>
> static int query_temperature_sensors_foreach(Object *obj, void *opaque)
> {
> @@ -59,6 +61,33 @@ TemperatureSensorList *qmp_query_temperature_sensors(Error **errp)
> return list;
> }
>
> +void hmp_info_temp(Monitor *mon, const QDict *qdict)
> +{
> + TemperatureSensorList *list, *sensor;
> + Error *err = NULL;
> +
> + list = qmp_query_temperature_sensors(&err);
> + if (!list) {
> + monitor_printf(mon, "No temperature sensors\n");
> + return;
> + }
> + if (err) {
> + monitor_printf(mon, "Error while getting temperatures: %s\n",
> + error_get_pretty(err));
> + error_free(err);
Maybe use hmp_handle_error
> + goto out;
> + }
> +
> + monitor_printf(mon, "Temperatures (in C):\n");
> + for (sensor = list; sensor; sensor = sensor->next) {
> + monitor_printf(mon, "%-33s %6.2f\n", sensor->value->name,
> + sensor->value->temperature);
See my question on the earlier patch; I'm curious here whether we want
device name, and then subname within that device.
Dave
> + }
> +
> +out:
> + qapi_free_TemperatureSensorList(list);
> +}
> +
> static TypeInfo tempsensor_interface_type_info = {
> .name = TYPE_TEMPSENSOR_INTERFACE,
> .parent = TYPE_INTERFACE,
> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
> index ca5198438d..77f1c43ce3 100644
> --- a/hmp-commands-info.hx
> +++ b/hmp-commands-info.hx
> @@ -880,4 +880,15 @@ SRST
> Show SEV information.
> ERST
>
> + {
> + .name = "temp",
> + .args_type = "",
> + .params = "",
> + .help = "show device temperatures",
> + .cmd = hmp_info_temp,
> + },
>
> +SRST
> + ``info temp``
> + Show device temperatures.
> +ERST
> --
> 2.21.1
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
^ permalink raw reply [flat|nested] 20+ messages in thread
* [RFC PATCH 04/17] hw/misc/tmp105: Extract get_temp_mC() and set_temp_mC() helpers
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 03/17] hw/misc/temp-sensor: Add 'info temp' HMP command Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 05/17] hw/misc/tmp105: Implement the 'temperature-sensor' qdev interface Philippe Mathieu-Daudé
` (12 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
Since we are going to reuse this code, extract it as helpers.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/misc/tmp105.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/hw/misc/tmp105.c b/hw/misc/tmp105.c
index 75ddad3a12..754c8a6eb4 100644
--- a/hw/misc/tmp105.c
+++ b/hw/misc/tmp105.c
@@ -56,11 +56,28 @@ static void tmp105_alarm_update(TMP105State *s)
tmp105_interrupt_update(s);
}
+static int64_t get_temp_mC(TMP105State *s)
+{
+ return s->temperature * 1000 / 256;
+}
+
+static void set_temp_mC(TMP105State *s, int64_t temp_mC, Error **errp)
+{
+ if (temp_mC >= 128000 || temp_mC < -128000) {
+ error_setg(errp, "value %" PRId64 ".%03" PRIu64 " C is out of range",
+ temp_mC / 1000, temp_mC % 1000);
+ return;
+ }
+
+ s->temperature = (int16_t) (temp_mC * 256 / 1000);
+
+ tmp105_alarm_update(s);
+}
+
static void tmp105_get_temperature(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- TMP105State *s = TMP105(obj);
- int64_t value = s->temperature * 1000 / 256;
+ int64_t value = get_temp_mC(TMP105(obj));
visit_type_int(v, name, &value, errp);
}
@@ -71,7 +88,6 @@ static void tmp105_get_temperature(Object *obj, Visitor *v, const char *name,
static void tmp105_set_temperature(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- TMP105State *s = TMP105(obj);
Error *local_err = NULL;
int64_t temp;
@@ -80,15 +96,8 @@ static void tmp105_set_temperature(Object *obj, Visitor *v, const char *name,
error_propagate(errp, local_err);
return;
}
- if (temp >= 128000 || temp < -128000) {
- error_setg(errp, "value %" PRId64 ".%03" PRIu64 " C is out of range",
- temp / 1000, temp % 1000);
- return;
- }
- s->temperature = (int16_t) (temp * 256 / 1000);
-
- tmp105_alarm_update(s);
+ set_temp_mC(TMP105(obj), temp, errp);
}
static const int tmp105_faultq[4] = { 1, 2, 4, 6 };
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 05/17] hw/misc/tmp105: Implement the 'temperature-sensor' qdev interface
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 04/17] hw/misc/tmp105: Extract get_temp_mC() and set_temp_mC() helpers Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 06/17] hw/misc/tmp421: Add definition for SENSORS_COUNT Philippe Mathieu-Daudé
` (11 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
The TMP105 is an I2C temperature sensor.
Let it implement the 'temperature-sensor' interface.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/misc/tmp105.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/hw/misc/tmp105.c b/hw/misc/tmp105.c
index 754c8a6eb4..1f0cb28012 100644
--- a/hw/misc/tmp105.c
+++ b/hw/misc/tmp105.c
@@ -26,6 +26,7 @@
#include "qapi/error.h"
#include "qapi/visitor.h"
#include "qemu/module.h"
+#include "hw/misc/temp-sensor.h"
static void tmp105_interrupt_update(TMP105State *s)
{
@@ -74,6 +75,17 @@ static void set_temp_mC(TMP105State *s, int64_t temp_mC, Error **errp)
tmp105_alarm_update(s);
}
+static float tmp105_get_temp(TempSensor *obj, unsigned sensor_id)
+{
+ return get_temp_mC(TMP105(obj)) / 1000.f;
+}
+
+static void tmp105_set_temp(TempSensor *obj, unsigned sensor_id,
+ float temp_C, Error **errp)
+{
+ set_temp_mC(TMP105(obj), temp_C * 1000.f, errp);
+}
+
static void tmp105_get_temperature(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
@@ -261,12 +273,16 @@ static void tmp105_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
+ TempSensorClass *tc = TEMPSENSOR_INTERFACE_CLASS(klass);
dc->realize = tmp105_realize;
k->event = tmp105_event;
k->recv = tmp105_rx;
k->send = tmp105_tx;
dc->vmsd = &vmstate_tmp105;
+ tc->sensor_count = 1;
+ tc->set_temperature = tmp105_set_temp;
+ tc->get_temperature = tmp105_get_temp;
}
static const TypeInfo tmp105_info = {
@@ -275,6 +291,10 @@ static const TypeInfo tmp105_info = {
.instance_size = sizeof(TMP105State),
.instance_init = tmp105_initfn,
.class_init = tmp105_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_TEMPSENSOR_INTERFACE },
+ { }
+ },
};
static void tmp105_register_types(void)
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 06/17] hw/misc/tmp421: Add definition for SENSORS_COUNT
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 05/17] hw/misc/tmp105: Implement the 'temperature-sensor' qdev interface Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 07/17] hw/misc/tmp421: Extract get_temp_mC() helper Philippe Mathieu-Daudé
` (10 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
Use a definition instead of a magic value.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/misc/tmp421.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c
index c0bc150bca..04c3b3ca6e 100644
--- a/hw/misc/tmp421.c
+++ b/hw/misc/tmp421.c
@@ -37,6 +37,8 @@
#define TMP422_DEVICE_ID 0x22
#define TMP423_DEVICE_ID 0x23
+#define SENSORS_COUNT 4
+
typedef struct DeviceInfo {
int model;
const char *name;
@@ -53,7 +55,7 @@ typedef struct TMP421State {
I2CSlave i2c;
/*< public >*/
- int16_t temperature[4];
+ int16_t temperature[SENSORS_COUNT];
uint8_t status;
uint8_t config[2];
@@ -124,7 +126,7 @@ static void tmp421_get_temperature(Object *obj, Visitor *v, const char *name,
return;
}
- if (tempid >= 4 || tempid < 0) {
+ if (tempid >= SENSORS_COUNT || tempid < 0) {
error_setg(errp, "error reading %s", name);
return;
}
@@ -164,7 +166,7 @@ static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name,
return;
}
- if (tempid >= 4 || tempid < 0) {
+ if (tempid >= SENSORS_COUNT || tempid < 0) {
error_setg(errp, "error reading %s", name);
return;
}
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 07/17] hw/misc/tmp421: Extract get_temp_mC() helper
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 06/17] hw/misc/tmp421: Add definition for SENSORS_COUNT Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 08/17] hw/misc/tmp421: Extract set_temp_mC() helper Philippe Mathieu-Daudé
` (9 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
Since we are going to reuse this code, extract it first.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/misc/tmp421.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c
index 04c3b3ca6e..8003356307 100644
--- a/hw/misc/tmp421.c
+++ b/hw/misc/tmp421.c
@@ -112,12 +112,19 @@ typedef struct TMP421Class {
static const int32_t mins[2] = { -40000, -55000 };
static const int32_t maxs[2] = { 127000, 150000 };
+static int64_t get_temp_mC(TMP421State *s, unsigned int id)
+{
+ bool ext_range = (s->config[0] & TMP421_CONFIG_RANGE);
+ int offset = ext_range * 64 * 256;
+
+ assert(id < SENSORS_COUNT);
+
+ return ((s->temperature[id] - offset) * 1000 + 128) / 256;
+}
+
static void tmp421_get_temperature(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- TMP421State *s = TMP421(obj);
- bool ext_range = (s->config[0] & TMP421_CONFIG_RANGE);
- int offset = ext_range * 64 * 256;
int64_t value;
int tempid;
@@ -131,7 +138,7 @@ static void tmp421_get_temperature(Object *obj, Visitor *v, const char *name,
return;
}
- value = ((s->temperature[tempid] - offset) * 1000 + 128) / 256;
+ value = get_temp_mC(TMP421(obj), tempid);
visit_type_int(v, name, &value, errp);
}
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 08/17] hw/misc/tmp421: Extract set_temp_mC() helper
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 07/17] hw/misc/tmp421: Extract get_temp_mC() helper Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 09/17] hw/misc/tmp421: Implement the 'temperature-sensor' qdev interface Philippe Mathieu-Daudé
` (8 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
Since we are going to reuse this code, extract it first.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/misc/tmp421.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c
index 8003356307..270e7d5510 100644
--- a/hw/misc/tmp421.c
+++ b/hw/misc/tmp421.c
@@ -122,6 +122,22 @@ static int64_t get_temp_mC(TMP421State *s, unsigned int id)
return ((s->temperature[id] - offset) * 1000 + 128) / 256;
}
+static void set_temp_mC(TMP421State *s, unsigned int id,
+ int64_t temp, Error **errp)
+{
+ bool ext_range = (s->config[0] & TMP421_CONFIG_RANGE);
+ int offset = ext_range * 64 * 256;
+
+ assert(id < SENSORS_COUNT);
+ if (temp >= maxs[ext_range] || temp < mins[ext_range]) {
+ error_setg(errp, "value %" PRId64 ".%03" PRIu64 " C is out of range",
+ temp / 1000, temp % 1000);
+ return;
+ }
+
+ s->temperature[id] = (int16_t) ((temp * 256 - 128) / 1000) + offset;
+}
+
static void tmp421_get_temperature(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
@@ -149,11 +165,8 @@ static void tmp421_get_temperature(Object *obj, Visitor *v, const char *name,
static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- TMP421State *s = TMP421(obj);
Error *local_err = NULL;
int64_t temp;
- bool ext_range = (s->config[0] & TMP421_CONFIG_RANGE);
- int offset = ext_range * 64 * 256;
int tempid;
visit_type_int(v, name, &temp, &local_err);
@@ -162,12 +175,6 @@ static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name,
return;
}
- if (temp >= maxs[ext_range] || temp < mins[ext_range]) {
- error_setg(errp, "value %" PRId64 ".%03" PRIu64 " C is out of range",
- temp / 1000, temp % 1000);
- return;
- }
-
if (sscanf(name, "temperature%d", &tempid) != 1) {
error_setg(errp, "error reading %s: %s", name, g_strerror(errno));
return;
@@ -178,7 +185,7 @@ static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name,
return;
}
- s->temperature[tempid] = (int16_t) ((temp * 256 - 128) / 1000) + offset;
+ set_temp_mC(TMP421(obj), tempid, temp, errp);
}
static void tmp421_read(TMP421State *s)
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 09/17] hw/misc/tmp421: Implement the 'temperature-sensor' qdev interface
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (7 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 08/17] hw/misc/tmp421: Extract set_temp_mC() helper Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 10/17] hw/misc/bcm2835_thermal: Hold the temperature in the device state Philippe Mathieu-Daudé
` (7 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
The TMP421 is an I2C device with multiple temperature sensors.
Let it implement the 'temperature-sensor' interface.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/misc/tmp421.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c
index 270e7d5510..31bfbecb1d 100644
--- a/hw/misc/tmp421.c
+++ b/hw/misc/tmp421.c
@@ -30,6 +30,7 @@
#include "qapi/error.h"
#include "qapi/visitor.h"
#include "qemu/module.h"
+#include "hw/misc/temp-sensor.h"
/* Manufacturer / Device ID's */
#define TMP421_MANUFACTURER_ID 0x55
@@ -138,6 +139,21 @@ static void set_temp_mC(TMP421State *s, unsigned int id,
s->temperature[id] = (int16_t) ((temp * 256 - 128) / 1000) + offset;
}
+static float tmp421_get_temp(TempSensor *obj, unsigned sensor_id)
+{
+ TMP421State *s = TMP421(obj);
+
+ return get_temp_mC(s, sensor_id) / 1000.f;
+}
+
+static void tmp421_set_temp(TempSensor *obj, unsigned sensor_id,
+ float temp_C, Error **errp)
+{
+ TMP421State *s = TMP421(obj);
+
+ set_temp_mC(s, sensor_id, temp_C * 1000.f, errp);
+}
+
static void tmp421_get_temperature(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
@@ -380,6 +396,7 @@ static void tmp421_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
TMP421Class *sc = TMP421_CLASS(klass);
+ TempSensorClass *tc = TEMPSENSOR_INTERFACE_CLASS(klass);
dc->realize = tmp421_realize;
k->event = tmp421_event;
@@ -387,6 +404,9 @@ static void tmp421_class_init(ObjectClass *klass, void *data)
k->send = tmp421_tx;
dc->vmsd = &vmstate_tmp421;
sc->dev = (DeviceInfo *) data;
+ tc->sensor_count = SENSORS_COUNT;
+ tc->set_temperature = tmp421_set_temp;
+ tc->get_temperature = tmp421_get_temp;
}
static const TypeInfo tmp421_info = {
@@ -396,6 +416,10 @@ static const TypeInfo tmp421_info = {
.class_size = sizeof(TMP421Class),
.instance_init = tmp421_initfn,
.abstract = true,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_TEMPSENSOR_INTERFACE },
+ { }
+ },
};
static void tmp421_register_types(void)
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 10/17] hw/misc/bcm2835_thermal: Hold the temperature in the device state
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (8 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 09/17] hw/misc/tmp421: Implement the 'temperature-sensor' qdev interface Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 11/17] hw/misc/bcm2835_thermal: Implement the 'temperature-sensor' interface Philippe Mathieu-Daudé
` (6 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
We are going to modify this variable, move it to the device state.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/misc/bcm2835_thermal.h | 1 +
hw/misc/bcm2835_thermal.c | 18 +++++++++++++-----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/include/hw/misc/bcm2835_thermal.h b/include/hw/misc/bcm2835_thermal.h
index c3651b27ec..df6a7b86c3 100644
--- a/include/hw/misc/bcm2835_thermal.h
+++ b/include/hw/misc/bcm2835_thermal.h
@@ -22,6 +22,7 @@ typedef struct {
/*< public >*/
MemoryRegion iomem;
uint32_t ctl;
+ float64 temp;
} Bcm2835ThermalState;
#endif
diff --git a/hw/misc/bcm2835_thermal.c b/hw/misc/bcm2835_thermal.c
index c6f3b1ad60..6ee149de20 100644
--- a/hw/misc/bcm2835_thermal.c
+++ b/hw/misc/bcm2835_thermal.c
@@ -32,7 +32,7 @@ FIELD(STAT, INTERRUPT, 11, 1)
#define THERMAL_OFFSET_C 412
#define THERMAL_COEFF (-0.538f)
-static uint16_t bcm2835_thermal_temp2adc(int temp_C)
+static uint16_t bcm2835_thermal_temp2adc(float64 temp_C)
{
return (temp_C - THERMAL_OFFSET_C) / THERMAL_COEFF;
}
@@ -47,8 +47,7 @@ static uint64_t bcm2835_thermal_read(void *opaque, hwaddr addr, unsigned size)
val = s->ctl;
break;
case A_STAT:
- /* Temperature is constantly 25°C. */
- val = FIELD_DP32(bcm2835_thermal_temp2adc(25), STAT, VALID, true);
+ val = FIELD_DP32(bcm2835_thermal_temp2adc(s->temp), STAT, VALID, true);
break;
default:
/* MemoryRegionOps are aligned, so this can not happen. */
@@ -85,6 +84,13 @@ static const MemoryRegionOps bcm2835_thermal_ops = {
.endianness = DEVICE_NATIVE_ENDIAN,
};
+static void bcm2835_thermal_init(Object *obj)
+{
+ Bcm2835ThermalState *s = BCM2835_THERMAL(obj);
+
+ s->temp = 25.0;
+}
+
static void bcm2835_thermal_reset(DeviceState *dev)
{
Bcm2835ThermalState *s = BCM2835_THERMAL(dev);
@@ -103,10 +109,11 @@ static void bcm2835_thermal_realize(DeviceState *dev, Error **errp)
static const VMStateDescription bcm2835_thermal_vmstate = {
.name = "bcm2835_thermal",
- .version_id = 1,
- .minimum_version_id = 1,
+ .version_id = 2,
+ .minimum_version_id = 2,
.fields = (VMStateField[]) {
VMSTATE_UINT32(ctl, Bcm2835ThermalState),
+ VMSTATE_FLOAT64(temp, Bcm2835ThermalState),
VMSTATE_END_OF_LIST()
}
};
@@ -124,6 +131,7 @@ static const TypeInfo bcm2835_thermal_info = {
.name = TYPE_BCM2835_THERMAL,
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(Bcm2835ThermalState),
+ .instance_init = bcm2835_thermal_init,
.class_init = bcm2835_thermal_class_init,
};
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 11/17] hw/misc/bcm2835_thermal: Implement the 'temperature-sensor' interface
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (9 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 10/17] hw/misc/bcm2835_thermal: Hold the temperature in the device state Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 12/17] hw/misc/bcm2835_property: Hold the temperature in the device state Philippe Mathieu-Daudé
` (5 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
The BCM2835 has a block that reports its temperature.
Let it implement the 'temperature-sensor' interface.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/misc/bcm2835_thermal.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/hw/misc/bcm2835_thermal.c b/hw/misc/bcm2835_thermal.c
index 6ee149de20..6b85cf9705 100644
--- a/hw/misc/bcm2835_thermal.c
+++ b/hw/misc/bcm2835_thermal.c
@@ -12,6 +12,7 @@
#include "hw/misc/bcm2835_thermal.h"
#include "hw/registerfields.h"
#include "migration/vmstate.h"
+#include "hw/misc/temp-sensor.h"
REG32(CTL, 0)
FIELD(CTL, POWER_DOWN, 0, 1)
@@ -32,6 +33,21 @@ FIELD(STAT, INTERRUPT, 11, 1)
#define THERMAL_OFFSET_C 412
#define THERMAL_COEFF (-0.538f)
+static void bcm2835_set_temperature(TempSensor *obj, unsigned int sensor_id,
+ float temp, Error **errp)
+{
+ Bcm2835ThermalState *s = BCM2835_THERMAL(obj);
+
+ s->temp = temp;
+}
+
+static float bcm2835_get_temperature(TempSensor *obj, unsigned int sensor_id)
+{
+ Bcm2835ThermalState *s = BCM2835_THERMAL(obj);
+
+ return s->temp;
+}
+
static uint16_t bcm2835_thermal_temp2adc(float64 temp_C)
{
return (temp_C - THERMAL_OFFSET_C) / THERMAL_COEFF;
@@ -121,10 +137,14 @@ static const VMStateDescription bcm2835_thermal_vmstate = {
static void bcm2835_thermal_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
+ TempSensorClass *tc = TEMPSENSOR_INTERFACE_CLASS(klass);
dc->realize = bcm2835_thermal_realize;
dc->reset = bcm2835_thermal_reset;
dc->vmsd = &bcm2835_thermal_vmstate;
+ tc->sensor_count = 1;
+ tc->set_temperature = bcm2835_set_temperature;
+ tc->get_temperature = bcm2835_get_temperature;
}
static const TypeInfo bcm2835_thermal_info = {
@@ -133,6 +153,10 @@ static const TypeInfo bcm2835_thermal_info = {
.instance_size = sizeof(Bcm2835ThermalState),
.instance_init = bcm2835_thermal_init,
.class_init = bcm2835_thermal_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_TEMPSENSOR_INTERFACE },
+ { }
+ },
};
static void bcm2835_thermal_register_types(void)
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 12/17] hw/misc/bcm2835_property: Hold the temperature in the device state
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (10 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 11/17] hw/misc/bcm2835_thermal: Implement the 'temperature-sensor' interface Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 13/17] hw/misc/bcm2835_property: Implement the 'temperature-sensor' interface Philippe Mathieu-Daudé
` (4 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
We are going to modify this variable, move it to the device state.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/misc/bcm2835_property.h | 1 +
hw/misc/bcm2835_property.c | 8 +++++---
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/include/hw/misc/bcm2835_property.h b/include/hw/misc/bcm2835_property.h
index b321f22499..010ad39ed0 100644
--- a/include/hw/misc/bcm2835_property.h
+++ b/include/hw/misc/bcm2835_property.h
@@ -31,6 +31,7 @@ typedef struct {
uint32_t board_rev;
uint32_t addr;
bool pending;
+ float64 temp_mC;
} BCM2835PropertyState;
#endif
diff --git a/hw/misc/bcm2835_property.c b/hw/misc/bcm2835_property.c
index 3e228ca0ae..bbe80affd4 100644
--- a/hw/misc/bcm2835_property.c
+++ b/hw/misc/bcm2835_property.c
@@ -143,7 +143,7 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
/* Temperature */
case 0x00030006: /* Get temperature */
- stl_le_phys(&s->dma_as, value + 16, 25000);
+ stl_le_phys(&s->dma_as, value + 16, s->temp_mC);
resplen = 8;
break;
@@ -361,12 +361,13 @@ static const MemoryRegionOps bcm2835_property_ops = {
static const VMStateDescription vmstate_bcm2835_property = {
.name = TYPE_BCM2835_PROPERTY,
- .version_id = 1,
- .minimum_version_id = 1,
+ .version_id = 2,
+ .minimum_version_id = 2,
.fields = (VMStateField[]) {
VMSTATE_MACADDR(macaddr, BCM2835PropertyState),
VMSTATE_UINT32(addr, BCM2835PropertyState),
VMSTATE_BOOL(pending, BCM2835PropertyState),
+ VMSTATE_FLOAT64(temp_mC, BCM2835PropertyState),
VMSTATE_END_OF_LIST()
}
};
@@ -375,6 +376,7 @@ static void bcm2835_property_init(Object *obj)
{
BCM2835PropertyState *s = BCM2835_PROPERTY(obj);
+ s->temp_mC = 25e3;
memory_region_init_io(&s->iomem, OBJECT(s), &bcm2835_property_ops, s,
TYPE_BCM2835_PROPERTY, 0x10);
sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 13/17] hw/misc/bcm2835_property: Implement the 'temperature-sensor' interface
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (11 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 12/17] hw/misc/bcm2835_property: Hold the temperature in the device state Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 14/17] hw/display/ads7846: Implement the 'temperature-sensor' qdev interface Philippe Mathieu-Daudé
` (3 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
The BCM2835 'property' QEMU device models the serialized responses
from the VideoCore firmware. As we can query the VC for its current
temperatyre, let this model implement the 'temperature-sensor'
interface.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/misc/bcm2835_property.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/hw/misc/bcm2835_property.c b/hw/misc/bcm2835_property.c
index bbe80affd4..dd1e9a2e03 100644
--- a/hw/misc/bcm2835_property.c
+++ b/hw/misc/bcm2835_property.c
@@ -12,6 +12,7 @@
#include "migration/vmstate.h"
#include "hw/irq.h"
#include "hw/misc/bcm2835_mbox_defs.h"
+#include "hw/misc/temp-sensor.h"
#include "sysemu/dma.h"
#include "qemu/log.h"
#include "qemu/module.h"
@@ -372,6 +373,27 @@ static const VMStateDescription vmstate_bcm2835_property = {
}
};
+static const char *bcm2835_property_get_temp_sensor_name(TempSensor *obj,
+ unsigned sensor_id)
+{
+ return "videocore";
+}
+
+static float bcm2835_property_get_temp(TempSensor *obj, unsigned sensor_id)
+{
+ BCM2835PropertyState *s = BCM2835_PROPERTY(obj);
+
+ return s->temp_mC / 1000;
+}
+
+static void bcm2835_property_set_temp(TempSensor *obj, unsigned sensor_id,
+ float temp_C, Error **errp)
+{
+ BCM2835PropertyState *s = BCM2835_PROPERTY(obj);
+
+ s->temp_mC = temp_C * 1000;
+}
+
static void bcm2835_property_init(Object *obj)
{
BCM2835PropertyState *s = BCM2835_PROPERTY(obj);
@@ -429,10 +451,15 @@ static Property bcm2835_property_props[] = {
static void bcm2835_property_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
+ TempSensorClass *tc = TEMPSENSOR_INTERFACE_CLASS(klass);
device_class_set_props(dc, bcm2835_property_props);
dc->realize = bcm2835_property_realize;
dc->vmsd = &vmstate_bcm2835_property;
+ tc->sensor_count = 1;
+ tc->get_name = bcm2835_property_get_temp_sensor_name;
+ tc->set_temperature = bcm2835_property_set_temp;
+ tc->get_temperature = bcm2835_property_get_temp;
}
static TypeInfo bcm2835_property_info = {
@@ -441,6 +468,10 @@ static TypeInfo bcm2835_property_info = {
.instance_size = sizeof(BCM2835PropertyState),
.class_init = bcm2835_property_class_init,
.instance_init = bcm2835_property_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_TEMPSENSOR_INTERFACE },
+ { }
+ },
};
static void bcm2835_property_register_types(void)
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 14/17] hw/display/ads7846: Implement the 'temperature-sensor' qdev interface
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (12 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 13/17] hw/misc/bcm2835_property: Implement the 'temperature-sensor' interface Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 15/17] hw/ide/qdev: " Philippe Mathieu-Daudé
` (2 subsequent siblings)
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
The 4-wire ADS7846 Touch Screen Controller is able to report a
pair of temperatures. Let it implement the 'temperature-sensor'
interface.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/display/ads7846.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/hw/display/ads7846.c b/hw/display/ads7846.c
index 9228b40b1a..e37e99f5ec 100644
--- a/hw/display/ads7846.c
+++ b/hw/display/ads7846.c
@@ -16,6 +16,7 @@
#include "migration/vmstate.h"
#include "qemu/module.h"
#include "ui/console.h"
+#include "hw/misc/temp-sensor.h"
typedef struct {
SSISlave ssidev;
@@ -53,6 +54,12 @@ typedef struct {
#define ADS_Z1POS(x, y) 600
#define ADS_Z2POS(x, y) (600 + 6000 / ADS_XPOS(x, y))
+/* TI Datasheet SBAS125H "TEMP DIODE VOLTAGE vs TEMPERATURE (2.7V SUPPLY)" */
+#define ADS_TEMP0_OFS_MILLIV 666.f
+#define ADS_TEMP1_OFS_MILLIV 761.f
+#define ADS_TEMP0_COEFF 2.08f
+#define ADS_TEMP1_COEFF 1.60f
+
static void ads7846_int_update(ADS7846State *s)
{
if (s->interrupt)
@@ -157,12 +164,39 @@ static void ads7846_realize(SSISlave *d, Error **errp)
vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_ads7846, s);
}
+static float ads7846_get_temp(TempSensor *obj, unsigned sensor_id)
+{
+ ADS7846State *s = (ADS7846State *)obj;
+
+ if (sensor_id) {
+ return (ADS_TEMP1_OFS_MILLIV - s->input[7]) / ADS_TEMP1_COEFF;
+ } else {
+ return (ADS_TEMP0_OFS_MILLIV - s->input[0]) / ADS_TEMP0_COEFF;
+ }
+}
+
+static void ads7846_set_temp(TempSensor *obj, unsigned sensor_id,
+ float temp_C, Error **errp)
+{
+ ADS7846State *s = (ADS7846State *)obj;
+
+ if (sensor_id) {
+ s->input[7] = ADS_TEMP1_OFS_MILLIV - ADS_TEMP1_COEFF * temp_C;
+ } else {
+ s->input[0] = ADS_TEMP0_OFS_MILLIV - ADS_TEMP0_COEFF * temp_C;
+ }
+}
+
static void ads7846_class_init(ObjectClass *klass, void *data)
{
SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+ TempSensorClass *tc = TEMPSENSOR_INTERFACE_CLASS(klass);
k->realize = ads7846_realize;
k->transfer = ads7846_transfer;
+ tc->sensor_count = 2;
+ tc->set_temperature = ads7846_set_temp;
+ tc->get_temperature = ads7846_get_temp;
}
static const TypeInfo ads7846_info = {
@@ -170,6 +204,10 @@ static const TypeInfo ads7846_info = {
.parent = TYPE_SSI_SLAVE,
.instance_size = sizeof(ADS7846State),
.class_init = ads7846_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_TEMPSENSOR_INTERFACE },
+ { }
+ },
};
static void ads7846_register_types(void)
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 15/17] hw/ide/qdev: Implement the 'temperature-sensor' qdev interface
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (13 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 14/17] hw/display/ads7846: Implement the 'temperature-sensor' qdev interface Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 16/17] hw/misc/imx6ul_ccm: " Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 17/17] tests/qtest/tmp105-test: Trivial test for TempSensorClass Philippe Mathieu-Daudé
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
IDE drives exposing a SMART interface report the air flow
temperature. Let them implement the 'temperature-sensor'
interface.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/ide/qdev.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index c22afdb8ee..144d6ab533 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -32,6 +32,7 @@
#include "sysemu/sysemu.h"
#include "sysemu/runstate.h"
#include "qapi/visitor.h"
+#include "hw/misc/temp-sensor.h"
/* --------------------------------- */
@@ -270,6 +271,12 @@ static void ide_dev_instance_init(Object *obj)
object_property_set_int(obj, -1, "bootindex", NULL);
}
+static float ide_hd_get_temp(TempSensor *obj, unsigned sensor_id)
+{
+ /* See airflow-temperature-celsius in smart_attributes[] */
+ return 100.f - 0x45;
+}
+
static void ide_hd_realize(IDEDevice *dev, Error **errp)
{
ide_dev_initfn(dev, IDE_HD, errp);
@@ -315,11 +322,14 @@ static void ide_hd_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
+ TempSensorClass *tc = TEMPSENSOR_INTERFACE_CLASS(klass);
k->realize = ide_hd_realize;
dc->fw_name = "drive";
dc->desc = "virtual IDE disk";
device_class_set_props(dc, ide_hd_properties);
+ tc->sensor_count = 1;
+ tc->get_temperature = ide_hd_get_temp;
}
static const TypeInfo ide_hd_info = {
@@ -327,6 +337,10 @@ static const TypeInfo ide_hd_info = {
.parent = TYPE_IDE_DEVICE,
.instance_size = sizeof(IDEDrive),
.class_init = ide_hd_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_TEMPSENSOR_INTERFACE },
+ { }
+ },
};
static Property ide_cd_properties[] = {
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 16/17] hw/misc/imx6ul_ccm: Implement the 'temperature-sensor' qdev interface
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (14 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 15/17] hw/ide/qdev: " Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
2020-04-21 12:16 ` [RFC PATCH 17/17] tests/qtest/tmp105-test: Trivial test for TempSensorClass Philippe Mathieu-Daudé
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
The IMX6UL Clock Control Module can report few temperatures.
While the model doesn't implement it, we can still let it
implement the 'temperature-sensor' interface.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/misc/imx6ul_ccm.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/hw/misc/imx6ul_ccm.c b/hw/misc/imx6ul_ccm.c
index a2fc1d0364..2711cdaf09 100644
--- a/hw/misc/imx6ul_ccm.c
+++ b/hw/misc/imx6ul_ccm.c
@@ -16,6 +16,7 @@
#include "hw/misc/imx6ul_ccm.h"
#include "qemu/log.h"
#include "qemu/module.h"
+#include "hw/misc/temp-sensor.h"
#include "trace.h"
@@ -864,12 +865,14 @@ static void imx6ul_ccm_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
IMXCCMClass *ccm = IMX_CCM_CLASS(klass);
+ TempSensorClass *tc = TEMPSENSOR_INTERFACE_CLASS(klass);
dc->reset = imx6ul_ccm_reset;
dc->vmsd = &vmstate_imx6ul_ccm;
dc->desc = "i.MX6UL Clock Control Module";
ccm->get_clock_frequency = imx6ul_ccm_get_clock_frequency;
+ tc->sensor_count = 3;
}
static const TypeInfo imx6ul_ccm_info = {
@@ -878,6 +881,10 @@ static const TypeInfo imx6ul_ccm_info = {
.instance_size = sizeof(IMX6ULCCMState),
.instance_init = imx6ul_ccm_init,
.class_init = imx6ul_ccm_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_TEMPSENSOR_INTERFACE },
+ { }
+ },
};
static void imx6ul_ccm_register_types(void)
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [RFC PATCH 17/17] tests/qtest/tmp105-test: Trivial test for TempSensorClass
2020-04-21 12:16 [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface Philippe Mathieu-Daudé
` (15 preceding siblings ...)
2020-04-21 12:16 ` [RFC PATCH 16/17] hw/misc/imx6ul_ccm: " Philippe Mathieu-Daudé
@ 2020-04-21 12:16 ` Philippe Mathieu-Daudé
16 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-21 12:16 UTC (permalink / raw)
To: qemu-devel
Cc: Laurent Vivier, Peter Maydell, Thomas Huth, qemu-block,
qemu-trivial, Michael Tokarev, Markus Armbruster, Andrew Baumann,
Philippe Mathieu-Daudé,
qemu-arm, Paolo Bonzini, Jean-Christophe Dubois, John Snow,
Dr. David Alan Gilbert, Philippe Mathieu-Daudé
The qmp_tmp105_set_temperature() call will trigger
TempSensorClass::set_temperature(), then hmp_info_temperature()
triggers TempSensorClass::get_temperature().
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
tests/qtest/tmp105-test.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/tests/qtest/tmp105-test.c b/tests/qtest/tmp105-test.c
index f930a96b83..db7e505cbe 100644
--- a/tests/qtest/tmp105-test.c
+++ b/tests/qtest/tmp105-test.c
@@ -41,11 +41,26 @@ static void qmp_tmp105_set_temperature(const char *id, int value)
qobject_unref(response);
}
+static char *hmp_info_temperature(const char *id)
+{
+ QDict *response;
+ char *output;
+
+ response = qmp("{'execute': 'human-monitor-command',"
+ " 'arguments': {'command-line': 'info temp'}}");
+ g_assert(qdict_haskey(response, "return"));
+ output = g_strdup(qdict_get_try_str(response, "return"));
+ qobject_unref(response);
+
+ return output;
+}
+
#define TMP105_PRECISION (1000/16)
static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc)
{
uint16_t value;
QI2CDevice *i2cdev = (QI2CDevice *)obj;
+ g_autofree char *s = NULL;
value = qmp_tmp105_get_temperature(TMP105_TEST_ID);
g_assert_cmpuint(value, ==, 0);
@@ -56,6 +71,9 @@ static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc)
qmp_tmp105_set_temperature(TMP105_TEST_ID, 20000);
value = qmp_tmp105_get_temperature(TMP105_TEST_ID);
g_assert_cmpuint(value, ==, 20000);
+ /* Test TempSensorClass via 'info temp' */
+ s = hmp_info_temperature(TMP105_TEST_ID);
+ g_assert(strstr(s, "tmp105-0 20.00"));
value = i2c_get16(i2cdev, TMP105_REG_TEMPERATURE);
g_assert_cmphex(value, ==, 0x1400);
--
2.21.1
^ permalink raw reply related [flat|nested] 20+ messages in thread