Skip to contentSkip to conversation

Aspeed watchdog controller model

PATCH Applied Cédric Le Goater 2 participants 4 messages Jan 26, 2017 – Feb 3, 2017 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

v2 cover Aspeed watchdog controller model

Hello,

The Aspeed SoC includes a set of watchdog timers using 32-bit decrement counters. This patchset provides a model for this controller and adds the first watchdog to the Aspeed SoC model. A second watchdog exists and is used on real HW to boot from a second flash module containing a golden image of the firmware. This is not supported yet in qemu.

The main benefit today of this model is to enables reboot/reset of a guest from U-Boot and Linux.

Thanks,

C.

Cédric Le Goater (2):
wdt: Add Aspeed watchdog device model
aspeed: add a watchdog controller

 hw/arm/aspeed_soc.c              |  13 +++
 hw/watchdog/Makefile.objs        |   1 +
 hw/watchdog/wdt_aspeed.c         | 225 +++++++++++++++++++++++++++++++++++++++
 include/hw/arm/aspeed_soc.h      |   2 +
 include/hw/watchdog/wdt_aspeed.h |  32 ++++++
 5 files changed, 273 insertions(+)
 create mode 100644 hw/watchdog/wdt_aspeed.c
 create mode 100644 include/hw/watchdog/wdt_aspeed.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/2 wdt: Add Aspeed watchdog device model

The Aspeed SoC includes a set of watchdog timers using 32-bit decrement counters, which can be based either on the APB clock or a 1 MHz clock.

The watchdog timer is designed to prevent system deadlock and, in general, it should be restarted before timeout. When a timeout occurs, different types of signals can be generated, ARM reset, SOC reset, System reset, CPU Interrupt, external signal or boot from alternate block. The current model only performs the system reset function as this is used by U-Boot and Linux.

[clg: - fixed compile breakage
- fixed io region size
- added watchdog_perform_action() on timer expiry
- wrote a commit log
- merged fixes from Andrew Jeffery to scale the reload value ]

---

Changes since v1:
- added bits definitions
- added a register array
- fixed vmstate
- added initial pclk support
- added a reload routine
- took ownership

 hw/watchdog/Makefile.objs        |   1 +
 hw/watchdog/wdt_aspeed.c         | 225 +++++++++++++++++++++++++++++++++++++++
 include/hw/watchdog/wdt_aspeed.h |  32 ++++++
 3 files changed, 258 insertions(+)
 create mode 100644 hw/watchdog/wdt_aspeed.c
 create mode 100644 include/hw/watchdog/wdt_aspeed.h
hw/watchdog/Makefile.objs +1 -0
index 72e3ffd93c59..9589bed63a3d 100644
@@ -2,3 +2,4 @@ common-obj-y += watchdog.o
 common-obj-$(CONFIG_WDT_IB6300ESB) += wdt_i6300esb.o
 common-obj-$(CONFIG_WDT_IB700) += wdt_ib700.o
 common-obj-$(CONFIG_WDT_DIAG288) += wdt_diag288.o
+common-obj-$(CONFIG_ASPEED_SOC) += wdt_aspeed.o
hw/watchdog/wdt_aspeed.c new file +225 -0

225 lines not on this page · raw message

include/hw/watchdog/wdt_aspeed.h new file +32 -0
new file mode 100644
index 000000000000..080c2231222e
@@ -0,0 +1,32 @@
+/*
+ * ASPEED Watchdog Controller
+ *
+ * Copyright (C) 2016-2017 IBM Corp.
+ *
+ * This code is licensed under the GPL version 2 or later. See the
+ * COPYING file in the top-level directory.
+ */
+#ifndef ASPEED_WDT_H
+#define ASPEED_WDT_H
+
+#include "hw/sysbus.h"
+
+#define TYPE_ASPEED_WDT "aspeed.wdt"
+#define ASPEED_WDT(obj) \
+    OBJECT_CHECK(AspeedWDTState, (obj), TYPE_ASPEED_WDT)
+
+#define ASPEED_WDT_REGS_MAX        (0x20 / 4)
+
+typedef struct AspeedWDTState {
+    /*< private >*/
+    SysBusDevice parent_obj;
+    QEMUTimer *timer;
+
+    /*< public >*/
+    MemoryRegion iomem;
+    uint32_t regs[ASPEED_WDT_REGS_MAX];
+
+    uint32_t pclk_freq;
+} AspeedWDTState;
+
+#endif  /* ASPEED_WDT_H */
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/2 aspeed: add a watchdog controller

In reply to Cédric Le Goater

This enables reboot of a guest from U-Boot and Linux.

---
 hw/arm/aspeed_soc.c         | 13 +++++++++++++
 include/hw/arm/aspeed_soc.h |  2 ++
 2 files changed, 15 insertions(+)
hw/arm/aspeed_soc.c +13 -0
index b3e7f07b615d..571e4f097b02 100644
@@ -31,6 +31,7 @@
 #define ASPEED_SOC_SCU_BASE         0x1E6E2000
 #define ASPEED_SOC_SRAM_BASE        0x1E720000
 #define ASPEED_SOC_TIMER_BASE       0x1E782000
+#define ASPEED_SOC_WDT_BASE         0x1E785000
 #define ASPEED_SOC_I2C_BASE         0x1E78A000
 
 static const int uart_irqs[] = { 9, 32, 33, 34, 10 };
@@ -170,6 +171,10 @@ static void aspeed_soc_init(Object *obj)
                          sc->info->silicon_rev);
     object_property_add_alias(obj, "ram-size", OBJECT(&s->sdmc),
                               "ram-size", &error_abort);
+
+    object_initialize(&s->wdt, sizeof(s->wdt), TYPE_ASPEED_WDT);
+    object_property_add_child(obj, "wdt", OBJECT(&s->wdt), NULL);
+    qdev_set_parent_bus(DEVICE(&s->wdt), sysbus_get_default());
 }
 
 static void aspeed_soc_realize(DeviceState *dev, Error **errp)
@@ -286,6 +291,14 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
         return;
     }
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdmc), 0, ASPEED_SOC_SDMC_BASE);
+
+    /* Watch dog */
+    object_property_set_bool(OBJECT(&s->wdt), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->wdt), 0, ASPEED_SOC_WDT_BASE);
 }
 
 static void aspeed_soc_class_init(ObjectClass *oc, void *data)
include/hw/arm/aspeed_soc.h +2 -0
index 1ab5deaa0813..dbec0c159885 100644
@@ -19,6 +19,7 @@
 #include "hw/timer/aspeed_timer.h"
 #include "hw/i2c/aspeed_i2c.h"
 #include "hw/ssi/aspeed_smc.h"
+#include "hw/watchdog/wdt_aspeed.h"
 
 #define ASPEED_SPIS_NUM  2
 
@@ -37,6 +38,7 @@ typedef struct AspeedSoCState {
     AspeedSMCState fmc;
     AspeedSMCState spi[ASPEED_SPIS_NUM];
     AspeedSDMCState sdmc;
+    AspeedWDTState wdt;
 } AspeedSoCState;
 
 #define TYPE_ASPEED_SOC "aspeed-soc"
Signature · 1 line
2.7.4
#3 lore raw
In reply to Cédric Le Goater
Quoted 12 lines · Cédric Le Goater

Hello,

The Aspeed SoC includes a set of watchdog timers using 32-bit decrement counters. This patchset provides a model for this controller and adds the first watchdog to the Aspeed SoC model. A second watchdog exists and is used on real HW to boot from a second flash module containing a golden image of the firmware. This is not supported yet in qemu.

The main benefit today of this model is to enables reboot/reset of a guest from U-Boot and Linux.

Quoted 7 lines

Thanks,

C.

Cédric Le Goater (2):
wdt: Add Aspeed watchdog device model
aspeed: add a watchdog controller

Applied to target-arm.next, thanks.

-- PMM