[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-arm] [PATCH v5 04/14] i.MX: Add code to emulate i.MX2 watchdog
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [Qemu-arm] [PATCH v5 04/14] i.MX: Add code to emulate i.MX2 watchdog IP block |
Date: |
Wed, 7 Feb 2018 11:26:11 -0300 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 |
Hi Andrey,
On 02/07/2018 01:24 AM, Andrey Smirnov wrote:
> Add enough code to emulate i.MX2 watchdog IP block so it would be
> possible to reboot the machine running Linux Guest.
>
> Cc: Peter Maydell <address@hidden>
> Cc: Jason Wang <address@hidden>
> Cc: Philippe Mathieu-Daudé <address@hidden>
> Cc: Marcel Apfelbaum <address@hidden>
> Cc: Michael S. Tsirkin <address@hidden>
> Cc: address@hidden
> Cc: address@hidden
> Cc: address@hidden
> Reviewed-by: Peter Maydell <address@hidden>
> Signed-off-by: Andrey Smirnov <address@hidden>
> ---
> hw/misc/Makefile.objs | 1 +
> hw/misc/imx2_wdt.c | 89
> ++++++++++++++++++++++++++++++++++++++++++++++
> include/hw/misc/imx2_wdt.h | 33 +++++++++++++++++
I recommend you to setup scripts/git.orderfile to ease review.
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
> 3 files changed, 123 insertions(+)
> create mode 100644 hw/misc/imx2_wdt.c
> create mode 100644 include/hw/misc/imx2_wdt.h
>
> diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
> index a28e5e49b0..4b2b705a6c 100644
> --- a/hw/misc/Makefile.objs
> +++ b/hw/misc/Makefile.objs
> @@ -34,6 +34,7 @@ obj-$(CONFIG_IMX) += imx25_ccm.o
> obj-$(CONFIG_IMX) += imx6_ccm.o
> obj-$(CONFIG_IMX) += imx6_src.o
> obj-$(CONFIG_IMX) += imx7_ccm.o
> +obj-$(CONFIG_IMX) += imx2_wdt.o
> obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o
> obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o
> obj-$(CONFIG_MAINSTONE) += mst_fpga.o
> diff --git a/hw/misc/imx2_wdt.c b/hw/misc/imx2_wdt.c
> new file mode 100644
> index 0000000000..e47e442592
> --- /dev/null
> +++ b/hw/misc/imx2_wdt.c
> @@ -0,0 +1,89 @@
> +/*
> + * Copyright (c) 2018, Impinj, Inc.
> + *
> + * i.MX2 Watchdog IP block
> + *
> + * Author: Andrey Smirnov <address@hidden>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qemu/bitops.h"
> +#include "sysemu/watchdog.h"
> +
> +#include "hw/misc/imx2_wdt.h"
> +
> +#define IMX2_WDT_WCR_WDA BIT(5) /* -> External Reset WDOG_B */
> +#define IMX2_WDT_WCR_SRS BIT(4) /* -> Software Reset Signal */
> +
> +static uint64_t imx2_wdt_read(void *opaque, hwaddr addr,
> + unsigned int size)
> +{
> + return 0;
> +}
> +
> +static void imx2_wdt_write(void *opaque, hwaddr addr,
> + uint64_t value, unsigned int size)
> +{
> + if (addr == IMX2_WDT_WCR &&
> + (value & (IMX2_WDT_WCR_WDA | IMX2_WDT_WCR_SRS))) {
> + watchdog_perform_action();
> + }
> +}
> +
> +static const MemoryRegionOps imx2_wdt_ops = {
> + .read = imx2_wdt_read,
> + .write = imx2_wdt_write,
> + .endianness = DEVICE_NATIVE_ENDIAN,
> + .impl = {
> + /*
> + * Our device would not work correctly if the guest was doing
> + * unaligned access. This might not be a limitation on the
> + * real device but in practice there is no reason for a guest
> + * to access this device unaligned.
> + */
> + .min_access_size = 4,
> + .max_access_size = 4,
> + .unaligned = false,
> + },
> +};
> +
> +static void imx2_wdt_realize(DeviceState *dev, Error **errp)
> +{
> + IMX2WdtState *s = IMX2_WDT(dev);
> +
> + memory_region_init_io(&s->mmio, OBJECT(dev),
> + &imx2_wdt_ops, s,
> + TYPE_IMX2_WDT".mmio",
> + IMX2_WDT_REG_NUM * sizeof(uint16_t));
> + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio);
> +}
> +
> +static void imx2_wdt_class_init(ObjectClass *klass, void *data)
> +{
> + DeviceClass *dc = DEVICE_CLASS(klass);
> +
> + dc->realize = imx2_wdt_realize;
> + set_bit(DEVICE_CATEGORY_MISC, dc->categories);
> +}
> +
> +static const TypeInfo imx2_wdt_info = {
> + .name = TYPE_IMX2_WDT,
> + .parent = TYPE_SYS_BUS_DEVICE,
> + .instance_size = sizeof(IMX2WdtState),
> + .class_init = imx2_wdt_class_init,
> +};
> +
> +static WatchdogTimerModel model = {
> + .wdt_name = "imx2-watchdog",
> + .wdt_description = "i.MX2 Watchdog",
> +};
> +
> +static void imx2_wdt_register_type(void)
> +{
> + watchdog_add_model(&model);
> + type_register_static(&imx2_wdt_info);
> +}
> +type_init(imx2_wdt_register_type)
> diff --git a/include/hw/misc/imx2_wdt.h b/include/hw/misc/imx2_wdt.h
> new file mode 100644
> index 0000000000..8afc99a10e
> --- /dev/null
> +++ b/include/hw/misc/imx2_wdt.h
> @@ -0,0 +1,33 @@
> +/*
> + * Copyright (c) 2017, Impinj, Inc.
> + *
> + * i.MX2 Watchdog IP block
> + *
> + * Author: Andrey Smirnov <address@hidden>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#ifndef IMX2_WDT_H
> +#define IMX2_WDT_H
> +
> +#include "hw/sysbus.h"
> +
> +#define TYPE_IMX2_WDT "imx2.wdt"
> +#define IMX2_WDT(obj) OBJECT_CHECK(IMX2WdtState, (obj), TYPE_IMX2_WDT)
> +
> +enum IMX2WdtRegisters {
> + IMX2_WDT_WCR = 0x0000,
> + IMX2_WDT_REG_NUM = 0x0008 / sizeof(uint16_t) + 1,
> +};
> +
> +
> +typedef struct IMX2WdtState {
> + /* <private> */
> + SysBusDevice parent_obj;
> +
> + MemoryRegion mmio;
> +} IMX2WdtState;
> +
> +#endif /* IMX7_SNVS_H */
>
- [Qemu-arm] [PATCH v5 00/14] Initial i.MX7 support, Andrey Smirnov, 2018/02/06
- [Qemu-arm] [PATCH v5 02/14] hw: i.MX: Convert i.MX6 to use TYPE_IMX_USDHC, Andrey Smirnov, 2018/02/06
- [Qemu-arm] [PATCH v5 01/14] sdhci: Add i.MX specific subtype of SDHCI, Andrey Smirnov, 2018/02/06
- [Qemu-arm] [PATCH v5 03/14] i.MX: Add code to emulate i.MX7 CCM, PMU and ANALOG IP blocks, Andrey Smirnov, 2018/02/06
- [Qemu-arm] [PATCH v5 04/14] i.MX: Add code to emulate i.MX2 watchdog IP block, Andrey Smirnov, 2018/02/06
- Re: [Qemu-arm] [PATCH v5 04/14] i.MX: Add code to emulate i.MX2 watchdog IP block,
Philippe Mathieu-Daudé <=
- [Qemu-arm] [PATCH v5 05/14] i.MX: Add code to emulate i.MX7 SNVS IP-block, Andrey Smirnov, 2018/02/06
- [Qemu-arm] [PATCH v5 07/14] i.MX: Add i.MX7 GPT variant, Andrey Smirnov, 2018/02/06
- [Qemu-arm] [PATCH v5 08/14] i.MX: Add implementation of i.MX7 GPR IP block, Andrey Smirnov, 2018/02/06
- [Qemu-arm] [PATCH v5 06/14] i.MX: Add code to emulate GPCv2 IP block, Andrey Smirnov, 2018/02/06
- [Qemu-arm] [PATCH v5 09/14] pci: Use pci_config_size in pci_data_* accessors, Andrey Smirnov, 2018/02/06