qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: "Alex Bennée" <alex.bennee@linaro.org>, qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Zoltán Baldaszti" <bztemail@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Andrew Baumann" <Andrew.Baumann@microsoft.com>,
	"Esteban Bosse" <estebanbosse@gmail.com>,
	"Cleber Rosa" <crosa@redhat.com>,
	qemu-arm@nongnu.org,
	"Clement Deschamps" <clement.deschamps@antfield.fr>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Laurent Bonnans" <laurent.bonnans@here.com>,
	"Cheng Xiang" <ext-cheng.xiang@here.com>,
	"Pekka Enberg" <penberg@iki.fi>,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Eduardo Habkost" <ehabkost@redhat.com>
Subject: Re: [PATCH 08/19] hw/misc/bcm2835_thermal: Add a dummy BCM2835 thermal sensor
Date: Tue, 8 Oct 2019 13:42:11 +0200	[thread overview]
Message-ID: <e75a3602-496b-107c-8bdb-c847982547be@redhat.com> (raw)
In-Reply-To: <87v9szii4o.fsf@linaro.org>

On 10/8/19 1:36 PM, Alex Bennée wrote:
> Philippe Mathieu-Daudé <f4bug@amsat.org> writes:
> 
>> We will soon implement the SYS_timer. This timer is used by Linux
>> in the thermal subsystem, so once available, the subsystem will be
>> enabled and poll the temperature sensors. We need to provide the
>> minimum required to keep Linux booting.
>>
>> Add a dummy thermal sensor returning ~25°C based on:
>> https://github.com/raspberrypi/linux/blob/rpi-5.3.y/drivers/thermal/broadcom/bcm2835_thermal.c
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>> checkpatch warning:
>> WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
>> This is OK because the regex are:
>>
>>    F: hw/*/bcm283*
>>    F: include/hw/*/bcm283*
>> ---
>>   hw/misc/Makefile.objs             |   1 +
>>   hw/misc/bcm2835_thermal.c         | 109 ++++++++++++++++++++++++++++++
>>   include/hw/misc/bcm2835_thermal.h |  27 ++++++++
>>   3 files changed, 137 insertions(+)
>>   create mode 100644 hw/misc/bcm2835_thermal.c
>>   create mode 100644 include/hw/misc/bcm2835_thermal.h
>>
>> diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
>> index a150680966..c89f3816a5 100644
>> --- a/hw/misc/Makefile.objs
>> +++ b/hw/misc/Makefile.objs
>> @@ -53,6 +53,7 @@ common-obj-$(CONFIG_OMAP) += omap_tap.o
>>   common-obj-$(CONFIG_RASPI) += bcm2835_mbox.o
>>   common-obj-$(CONFIG_RASPI) += bcm2835_property.o
>>   common-obj-$(CONFIG_RASPI) += bcm2835_rng.o
>> +common-obj-$(CONFIG_RASPI) += bcm2835_thermal.o
>>   common-obj-$(CONFIG_SLAVIO) += slavio_misc.o
>>   common-obj-$(CONFIG_ZYNQ) += zynq_slcr.o
>>   common-obj-$(CONFIG_ZYNQ) += zynq-xadc.o
>> diff --git a/hw/misc/bcm2835_thermal.c b/hw/misc/bcm2835_thermal.c
>> new file mode 100644
>> index 0000000000..bac23f21ea
>> --- /dev/null
>> +++ b/hw/misc/bcm2835_thermal.c
>> @@ -0,0 +1,109 @@
>> +/*
>> + * BCM2835 dummy thermal sensor
>> + *
>> + * Copyright (C) 2019 Philippe Mathieu-Daudé <f4bug@amsat.org>
>> + *
>> + * SPDX-License-Identifier: GPL-2.0-or-later
>> + */
>> +#include "qemu/osdep.h"
>> +#include "hw/sysbus.h"
>> +#include "hw/misc/bcm2835_thermal.h"
>> +#include "qemu/log.h"
>> +#include "qapi/error.h"
>> +#include "hw/registerfields.h"
>> +
>> +REG32(CTL, 0)
>> +FIELD(CTL, POWER_DOWN, 0, 1)
>> +FIELD(CTL, RESET, 1, 1)
>> +FIELD(CTL, BANDGAP_CTRL, 2, 3)
>> +FIELD(CTL, INTERRUPT_ENABLE, 5, 1)
>> +FIELD(CTL, DIRECT, 6, 1)
>> +FIELD(CTL, INTERRUPT_CLEAR, 7, 1)
>> +FIELD(CTL, HOLD, 8, 10)
>> +FIELD(CTL, RESET_DELAY, 18, 8)
>> +FIELD(CTL, REGULATOR_ENABLE, 26, 1)
>> +
>> +REG32(STAT, 4)
>> +FIELD(STAT, DATA, 0, 10)
>> +FIELD(STAT, VALID, 10, 1)
>> +FIELD(STAT, INTERRUPT, 11, 1)
>> +
>> +#define THERMAL_OFFSET_C 412
>> +#define THERMAL_COEFF  (-0.538f)
>> +
>> +static uint16_t bcm2835_thermal_temp2adc(int temp_C)
>> +{
>> +    return (temp_C - THERMAL_OFFSET_C) / THERMAL_COEFF;
>> +}
>> +
>> +static uint64_t bcm2835_thermal_read(void *opaque, hwaddr addr, unsigned size)
>> +{
>> +    Bcm2835ThermalState *s = BCM2835_THERMAL(opaque);
>> +    uint32_t val = 0;
>> +
>> +    switch (addr) {
>> +    case A_CTL:
>> +        val = s->ctl;
>> +        break;
>> +    case A_STAT:
>> +        val = FIELD_DP32(bcm2835_thermal_temp2adc(25), STAT, VALID, true);
>> +        break;
>> +    default:
>> +        g_assert_not_reached();
> 
> Will a unaligned read already have faulted and delivered an exception to
> the guest? As this access it controlled by the guest it could
> potentially take down QEMU. Perhaps it should be a LOG_GUEST_ERROR as
> bellow?

MemoryRegionOps::(valid|impl).unaligned default to false, so unaligned 
accesses won't reach this device, the guest will get a MEMTX_DECODE_ERROR.

>> +    }
>> +    return val;
>> +}
>> +
>> +static void bcm2835_thermal_write(void *opaque, hwaddr addr,
>> +                                  uint64_t value, unsigned size)
>> +{
>> +    Bcm2835ThermalState *s = BCM2835_THERMAL(opaque);
>> +
>> +    switch (addr) {
>> +    case A_CTL:
>> +        s->ctl = value;
>> +        break;
>> +    default:
>> +        qemu_log_mask(LOG_GUEST_ERROR, "%s: write 0x%" PRIx64
>> +                                       " to 0x%" HWADDR_PRIx "\n",
>> +                       __func__, value, addr);
>> +    }
>> +}
>> +
>> +static const MemoryRegionOps bcm2835_thermal_ops = {
>> +    .read = bcm2835_thermal_read,
>> +    .write = bcm2835_thermal_write,
>> +    .impl.max_access_size = 4,
>> +    .valid.min_access_size = 4,
>> +    .endianness = DEVICE_NATIVE_ENDIAN,
>> +};
>> +
>> +static void bcm2835_thermal_realize(DeviceState *dev, Error **errp)
>> +{
>> +    Bcm2835ThermalState *s = BCM2835_THERMAL(dev);
>> +
>> +    memory_region_init_io(&s->iomem, OBJECT(s), &bcm2835_thermal_ops,
>> +                          s, TYPE_BCM2835_THERMAL, 8);
>> +    sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
>> +}
>> +
>> +static void bcm2835_thermal_class_init(ObjectClass *klass, void *data)
>> +{
>> +    DeviceClass *dc = DEVICE_CLASS(klass);
>> +
>> +    dc->realize = bcm2835_thermal_realize;
>> +}
>> +
>> +static const TypeInfo bcm2835_thermal_info = {
>> +    .name = TYPE_BCM2835_THERMAL,
>> +    .parent = TYPE_SYS_BUS_DEVICE,
>> +    .instance_size = sizeof(Bcm2835ThermalState),
>> +    .class_init = bcm2835_thermal_class_init,
>> +};
>> +
>> +static void bcm2835_thermal_register_types(void)
>> +{
>> +    type_register_static(&bcm2835_thermal_info);
>> +}
>> +
>> +type_init(bcm2835_thermal_register_types)
>> diff --git a/include/hw/misc/bcm2835_thermal.h b/include/hw/misc/bcm2835_thermal.h
>> new file mode 100644
>> index 0000000000..f85cce7214
>> --- /dev/null
>> +++ b/include/hw/misc/bcm2835_thermal.h
>> @@ -0,0 +1,27 @@
>> +/*
>> + * BCM2835 dummy thermal sensor
>> + *
>> + * Copyright (C) 2019 Philippe Mathieu-Daudé <f4bug@amsat.org>
>> + *
>> + * SPDX-License-Identifier: GPL-2.0-or-later
>> + */
>> +#ifndef HW_MISC_BCM2835_THERMAL_H
>> +#define HW_MISC_BCM2835_THERMAL_H
>> +
>> +#include "hw/qdev-properties.h"
>> +#include "hw/sysbus.h"
>> +
>> +#define TYPE_BCM2835_THERMAL "bcm2835-thermal"
>> +
>> +#define BCM2835_THERMAL(obj) \
>> +    OBJECT_CHECK(Bcm2835ThermalState, (obj), TYPE_BCM2835_THERMAL)
>> +
>> +typedef struct {
>> +    /*< private >*/
>> +    SysBusDevice parent_obj;
>> +    /*< public >*/
>> +    MemoryRegion iomem;
>> +    uint32_t ctl;
>> +} Bcm2835ThermalState;
>> +
>> +#endif
> 
> Otherwise:
> 
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

Thanks :)


  reply	other threads:[~2019-10-08 11:43 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-26 17:34 [PATCH 00/19] hw/arm/raspi: Improve Raspberry Pi 2/3 reliability Philippe Mathieu-Daudé
2019-09-26 17:34 ` [PATCH 01/19] hw/arm/raspi: Use the IEC binary prefix definitions Philippe Mathieu-Daudé
2019-09-27 21:36   ` Alistair Francis
2019-10-08  8:57   ` Alex Bennée
2019-10-09  0:26   ` Cleber Rosa
2019-09-26 17:34 ` [PATCH 02/19] hw/arm/bcm2835_peripherals: Improve logging Philippe Mathieu-Daudé
2019-09-27 21:37   ` Alistair Francis
2019-10-08  9:00   ` Alex Bennée
2019-10-09  1:28     ` Cleber Rosa
2019-09-26 17:34 ` [PATCH 03/19] hw/arm/bcm2835_peripherals: Name various address spaces Philippe Mathieu-Daudé
2019-09-27 21:38   ` Alistair Francis
2019-10-08  9:04   ` Alex Bennée
2019-10-09  1:48   ` Cleber Rosa
2019-09-26 17:34 ` [PATCH 04/19] hw/arm/bcm2835: Rename some definitions Philippe Mathieu-Daudé
2019-09-27 21:40   ` Alistair Francis
2019-10-08 10:40   ` Alex Bennée
2019-09-26 17:34 ` [PATCH 05/19] hw/arm/bcm2835: Add various unimplemented peripherals Philippe Mathieu-Daudé
2019-09-27 21:42   ` Alistair Francis
2019-10-08  9:43     ` Philippe Mathieu-Daudé
2019-10-11 21:55       ` Alistair Francis
2019-10-08 11:09   ` Alex Bennée
2019-09-26 17:34 ` [PATCH 06/19] hw/char/bcm2835_aux: Add trace events Philippe Mathieu-Daudé
2019-10-08 11:22   ` Alex Bennée
2019-10-14 15:36   ` Peter Maydell
2019-10-14 16:03     ` Philippe Mathieu-Daudé
2019-09-26 17:34 ` [PATCH 07/19] hw/misc/bcm2835_mbox: " Philippe Mathieu-Daudé
2019-10-08 11:32   ` Alex Bennée
2019-10-08 11:38     ` Philippe Mathieu-Daudé
2019-09-26 17:34 ` [PATCH 08/19] hw/misc/bcm2835_thermal: Add a dummy BCM2835 thermal sensor Philippe Mathieu-Daudé
2019-10-08 11:36   ` Alex Bennée
2019-10-08 11:42     ` Philippe Mathieu-Daudé [this message]
2019-10-14 15:37   ` Peter Maydell
2019-10-14 16:05     ` Philippe Mathieu-Daudé
2019-09-26 17:34 ` [PATCH 09/19] hw/arm/bcm2835_peripherals: Use the thermal sensor block Philippe Mathieu-Daudé
2019-09-27 21:51   ` Alistair Francis
2019-09-26 17:34 ` [PATCH 10/19] hw/timer/bcm2835: Add the BCM2835 SYS_timer Philippe Mathieu-Daudé
2019-10-08 14:52   ` Alex Bennée
2019-10-08 14:53     ` Philippe Mathieu-Daudé
2019-10-09 11:06       ` Philippe Mathieu-Daudé
2019-09-26 17:34 ` [PATCH 11/19] hw/arm/bcm2835_peripherals: Use the SYS_timer Philippe Mathieu-Daudé
2019-10-08 15:22   ` Alex Bennée
2019-10-09  7:39     ` Philippe Mathieu-Daudé
2019-09-26 17:34 ` [PATCH 12/19] hw/arm/bcm2835_peripherals: Add Clock/Power/Reset Manager blocks Philippe Mathieu-Daudé
2019-10-01  9:51   ` Philippe Mathieu-Daudé
2019-10-07 17:23     ` Philippe Mathieu-Daudé
2019-09-26 17:34 ` [PATCH 13/19] hw/arm/raspi: Define various blocks base addresses Philippe Mathieu-Daudé
2019-10-08 15:32   ` Alex Bennée
2019-09-26 17:34 ` [PATCH 14/19] python/qemu/machine: Allow to use other serial consoles than default Philippe Mathieu-Daudé
2019-09-27 12:54   ` bzt
2019-09-27 13:26     ` Guenter Roeck
2019-09-27 13:36       ` Peter Maydell
2019-09-27 14:44         ` Philippe Mathieu-Daudé
2019-10-09 15:28   ` Cleber Rosa
2019-09-26 17:34 ` [PATCH 15/19] tests/boot_linux_console: Extract the gunzip() helper Philippe Mathieu-Daudé
2019-10-08 15:33   ` Alex Bennée
2019-10-09 15:31   ` Cleber Rosa
2019-10-24  9:23   ` Esteban Bosse
2019-09-26 17:34 ` [PATCH 16/19] tests/boot_linux_console: Add a test for the Raspberry Pi 2 Philippe Mathieu-Daudé
2019-10-08 15:34   ` Alex Bennée
2019-10-09 15:43   ` Cleber Rosa
2019-10-09 15:43     ` Cleber Rosa
2019-09-26 17:34 ` [PATCH 17/19] tests/boot_linux_console: Test the raspi2 UART1 (16550 based) Philippe Mathieu-Daudé
2019-10-08 15:35   ` Alex Bennée
2019-10-09 15:54   ` Cleber Rosa
2019-09-26 17:34 ` [PATCH 18/19] tests/boot_linux_console: Boot Linux and run few commands on raspi3 Philippe Mathieu-Daudé
2019-10-09 16:12   ` Cleber Rosa
2019-10-09 16:21     ` Philippe Mathieu-Daudé
2019-09-26 17:34 ` [PATCH 19/19] tests/boot_linux_console: Test SDHCI and termal sensor " Philippe Mathieu-Daudé
2019-10-09 16:23   ` Cleber Rosa
2019-09-26 20:32 ` [PATCH 00/19] hw/arm/raspi: Improve Raspberry Pi 2/3 reliability BALATON Zoltan
2019-09-27  8:50   ` Philippe Mathieu-Daudé
2019-10-14 15:45 ` Peter Maydell
2019-10-14 16:07   ` Philippe Mathieu-Daudé
2019-10-16  9:57 ` Bonnans, Laurent

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e75a3602-496b-107c-8bdb-c847982547be@redhat.com \
    --to=philmd@redhat.com \
    --cc=Andrew.Baumann@microsoft.com \
    --cc=alex.bennee@linaro.org \
    --cc=alistair@alistair23.me \
    --cc=bztemail@gmail.com \
    --cc=clement.deschamps@antfield.fr \
    --cc=crosa@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=estebanbosse@gmail.com \
    --cc=ext-cheng.xiang@here.com \
    --cc=f4bug@amsat.org \
    --cc=laurent.bonnans@here.com \
    --cc=linux@roeck-us.net \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=penberg@iki.fi \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).