mbox series

[RFC,00/17] hw/misc: Introduce a temperature sensor interface

Message ID 20200421121626.23791-1-f4bug@amsat.org
Headers show
Series hw/misc: Introduce a temperature sensor interface | expand

Message

Philippe Mathieu-Daudé April 21, 2020, 12:16 p.m. UTC
Hi,

This series is part of a bigger one I was preparing for a GSoC
project, but unfortunately no student got interested.

The idea is to allow device with temperature sensors to use a
common API with temperature operations.

While guest are running, you can modify the temperatures to check
the guest reactions. Some devices can trigger IRQ when temperature
pass thresholds. Somehow similar to inject NMI.

Some devices could also modify their temperature regarding their
workload.

The tsc2xxxx devices are interesting but can't be converted as
they predate QOM/QDev.

Temperature changes rate is <1Hz (not enforced in this model) so
using a QMP to get/set is acceptable.
The query-temperature-sensors command is for informative purpose,
also acceptable for QMP use.

Next step might be to publish QMP events when temperature change.

The original goal is to better interface ADCs with real world data.
Here using QMP is not an option. Here the idea is to use the
AudioState and audio_sample API from "audio.h" but it seems not
very used, see: https://bugs.launchpad.net/qemu/+bug/1861677

What is not clear yet to me is what's the best way to externally
set a specific sensor temperature. The TMPxxx I2C sensors use
object_property_set_int(). I could move that to the temp-sensor
interface but it seems a bit overkill. Any simpler idea?

Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Keith Busch <keith.busch@intel.com>
Cc: Cédric Le Goater <clg@kaod.org>
Cc: Joel Stanley <joel@jms.id.au>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Joaquin de Andres <me@xcancerberox.com.ar>

Philippe Mathieu-Daudé (17):
  hw/misc: Introduce the temperature sensor interface
  hw/misc/temp-sensor: Add 'query-temperature-sensors' QMP command
  hw/misc/temp-sensor: Add 'info temp' HMP command
  hw/misc/tmp105: Extract get_temp_mC() and set_temp_mC() helpers
  hw/misc/tmp105: Implement the 'temperature-sensor' qdev interface
  hw/misc/tmp421: Add definition for SENSORS_COUNT
  hw/misc/tmp421: Extract get_temp_mC() helper
  hw/misc/tmp421: Extract set_temp_mC() helper
  hw/misc/tmp421: Implement the 'temperature-sensor' qdev interface
  hw/misc/bcm2835_thermal: Hold the temperature in the device state
  hw/misc/bcm2835_thermal: Implement the 'temperature-sensor' interface
  hw/misc/bcm2835_property: Hold the temperature in the device state
  hw/misc/bcm2835_property: Implement the 'temperature-sensor' interface
  hw/display/ads7846: Implement the 'temperature-sensor' qdev interface
  hw/ide/qdev: Implement the 'temperature-sensor' qdev interface
  hw/misc/imx6ul_ccm: Implement the 'temperature-sensor' qdev interface
  tests/qtest/tmp105-test: Trivial test for TempSensorClass

 qapi/misc.json                     |  24 +++++++
 include/hw/misc/bcm2835_property.h |   1 +
 include/hw/misc/bcm2835_thermal.h  |   1 +
 include/hw/misc/temp-sensor.h      |  69 +++++++++++++++++++
 include/monitor/hmp.h              |   1 +
 hw/display/ads7846.c               |  38 +++++++++++
 hw/ide/qdev.c                      |  14 ++++
 hw/misc/bcm2835_property.c         |  39 ++++++++++-
 hw/misc/bcm2835_thermal.c          |  42 ++++++++++--
 hw/misc/imx6ul_ccm.c               |   7 ++
 hw/misc/temp-sensor.c              | 102 +++++++++++++++++++++++++++++
 hw/misc/tmp105.c                   |  51 +++++++++++----
 hw/misc/tmp421.c                   |  74 ++++++++++++++++-----
 tests/qtest/tmp105-test.c          |  18 +++++
 MAINTAINERS                        |   6 ++
 hmp-commands-info.hx               |  11 ++++
 hw/misc/Makefile.objs              |   1 +
 17 files changed, 463 insertions(+), 36 deletions(-)
 create mode 100644 include/hw/misc/temp-sensor.h
 create mode 100644 hw/misc/temp-sensor.c