Aspeed watchdog controller model
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 (1):
aspeed: add a watchdog controller
Joel Stanley (1):
wdt: Add Aspeed watchdog device model
hw/arm/aspeed_soc.c | 13 +++ hw/watchdog/Makefile.objs | 1 + hw/watchdog/wdt_aspeed.c | 214 +++++++++++++++++++++++++++++++++++++++ include/hw/arm/aspeed_soc.h | 2 + include/hw/watchdog/wdt_aspeed.h | 37 +++++++ 5 files changed, 267 insertions(+) create mode 100644 hw/watchdog/wdt_aspeed.c create mode 100644 include/hw/watchdog/wdt_aspeed.h
Signature · 1 line
2.7.4
PATCH 1/2 wdt: Add Aspeed watchdog device model
From: Joel Stanley <[email protected]>
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 ]
--- hw/watchdog/Makefile.objs | 1 + hw/watchdog/wdt_aspeed.c | 214 +++++++++++++++++++++++++++++++++++++++ include/hw/watchdog/wdt_aspeed.h | 37 +++++++ 3 files changed, 252 insertions(+) create mode 100644 hw/watchdog/wdt_aspeed.c create mode 100644 include/hw/watchdog/wdt_aspeed.h
hw/watchdog/Makefile.objs +1 -0
@@ -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 +214 -0
214 lines not on this page · raw message
include/hw/watchdog/wdt_aspeed.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* 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_CLASS (klass) \ + OBJECT_CLASS_CHECK(AspeedWDTClass, (klass), TYPE_ASPEED_WDT) +#define ASPEED_WDT_GET_CLASS (obj) \ + OBJECT_GET_CLASS(AspeedWDTClass, (obj), TYPE_ASPEED_WDT) + +typedef struct AspeedWDTState { +/*< private >*/ +SysBusDevice parent_obj; +QEMUTimer *timer; +bool enabled; + +/*< public >*/ +MemoryRegion iomem; + +uint32_t reg_status; +uint32_t reg_reload_value; +uint32_t reg_restart; +uint32_t reg_ctrl; +}AspeedWDTState ; + +#endif /* ASPEED_WDT_H */
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 1/2] wdt: Add Aspeed watchdog device model
Quoted 101 lines · Cédric Le Goater
From: Joel Stanley <[email protected]>
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.
Signed-off-by Joel Stanley <[email protected]>[clg: - fixed compile breakage
- fixed io region size
- addedwatchdog_perform_action()on timer expiry
- wrote a commit log
- merged fixes from Andrew Jeffery to scale the reload value ]Signed-off-by Cédric Le Goater <[email protected]>--- hw/watchdog/Makefile.objs | 1 + hw/watchdog/wdt_aspeed.c | 214 +++++++++++++++++++++++++++++++++++++++ include/hw/watchdog/wdt_aspeed.h | 37 +++++++ 3 files changed, 252 insertions(+) create mode 100644 hw/watchdog/wdt_aspeed.c create mode 100644 include/hw/watchdog/wdt_aspeed.hhw/watchdog/Makefile.objs +1
-0@@ -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.ohw/watchdog/wdt_aspeed.c new file +58
-0@@ -0,0 +1,214 @@ +/* +* 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. +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "sysemu/watchdog.h" +#include "hw/sysbus.h" +#include "qemu/timer.h" +#include "hw/watchdog/wdt_aspeed.h" + +#define WDT_IO_REGION_SIZE 0x20 + +#define WDT_STATUS 0x00 +#define WDT_RELOAD_VALUE 0x04 +#define WDT_RESTART 0x08 +#define WDT_CTRL 0x0C +#define WDT_TIMEOUT_STATUS 0x10 +#define WDT_TIMEOUT_CLEAR 0x14 +#define WDT_RESET_WDITH 0x18 + +#define WDT_RESTART_MAGIC 0x4755 + +static uint64_t aspeed_wdt_read (void *opaque,hwaddr offset,unsigned size) +{ +AspeedWDTState *s =ASPEED_WDT (opaque); + +switch (offset) { +case WDT_STATUS : +return s->reg_status; +case WDT_RELOAD_VALUE : +return s->reg_reload_value; +case WDT_RESTART : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: read from write-only reg at offset 0x%" + HWADDR_PRIx"\n" , __func__, offset); +return 0 ; +case WDT_CTRL : +return s->reg_ctrl; +case WDT_TIMEOUT_STATUS : +case WDT_TIMEOUT_CLEAR : +case WDT_RESET_WDITH : +qemu_log_mask (LOG_UNIMP , +"%s: uninmplemented read at offset 0x%" HWADDR_PRIx"\n" , + __func__, offset); +return 0 ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Out-of-bounds read at offset 0x%" HWADDR_PRIx"\n" , + __func__, offset); +return 0 ; + } +
hw/watchdog/wdt_aspeed.c line 68
Quoted 10 lines
hw/watchdog/wdt_aspeed.c new file +10
-0+} + +#define PCLK_HZ 24000000 + +static void aspeed_wdt_write (void *opaque,hwaddr offset,uint64_t data, +unsigned size) +{ +AspeedWDTState *s =ASPEED_WDT (opaque); +bool en = data &BIT (0 ); +bool pclk = !(data &BIT (4 ));
These are only valid for WDT_CTRL, right? That being so, initialising them up here is a bit odd.
Quoted 37 lines
hw/watchdog/wdt_aspeed.c new file +37
-0+ +switch (offset) { +case WDT_STATUS : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: write to read-only reg at offset 0x%" + HWADDR_PRIx"\n" , __func__, offset); +break ; +case WDT_RELOAD_VALUE : + s->reg_reload_value = data; +break ; +case WDT_RESTART : +if ((data &0xFFFF ) ==0x4755 ) { +uint32_t reload; + + s->reg_status = s->reg_reload_value; + +if (pclk) { + reload =muldiv64 (s->reg_reload_value,NANOSECONDS_PER_SECOND , +PCLK_HZ ) ; + }else { + reload = s->reg_reload_value *1000 ; + } + +if (s->enabled) { +timer_mod (s->timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + reload); + } + } +break ; +case WDT_CTRL : +if (en && !s->enabled) { +uint32_t reload; + +if (pclk) { + reload =muldiv64 (s->reg_reload_value,NANOSECONDS_PER_SECOND , +PCLK_HZ ); + }else {
hw/watchdog/wdt_aspeed.c line 115
Quoted 10 lines
hw/watchdog/wdt_aspeed.c new file +10
-0+ reload = s->reg_reload_value *1000 ; + } + + s->enabled = true; +timer_mod (s->timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + reload); + }else if (!en && s->enabled) { + s->enabled = false; +timer_del (s->timer); + } +break ;
Shouldn't this write to s->reg_ctrl ?
s->enabled seems to duplicate state also in s->reg_ctrl.
Quoted 17 lines
hw/watchdog/wdt_aspeed.c new file +17
-0+case WDT_TIMEOUT_STATUS : +case WDT_TIMEOUT_CLEAR : +case WDT_RESET_WDITH : +qemu_log_mask (LOG_UNIMP , +"%s: uninmplemented write at offset 0x%" HWADDR_PRIx"\n" , + __func__, offset); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Out-of-bounds write at offset 0x%" HWADDR_PRIx"\n" , + __func__, offset); + } +return ; +} + +static WatchdogTimerModel model = { + .wdt_name =TYPE_ASPEED_WDT ,
hw/watchdog/wdt_aspeed.c line 142
Quoted 10 lines
hw/watchdog/wdt_aspeed.c new file +10
-0+ .wdt_description = "aspeed watchdog device", +}; + +static const VMStateDescription vmstate_aspeed_wdt = { + .name ="vmstate_aspeed_wdt" , + .version_id =0 , + .minimum_version_id =0 , + .fields = (VMStateField []) { +VMSTATE_TIMER_PTR (timer, AspeedWDTState), +VMSTATE_BOOL (enabled, AspeedWDTState),
This doesn't seem to have fields for most of the register state.
hw/watchdog/wdt_aspeed.c line 145
Quoted 3 lines
hw/watchdog/wdt_aspeed.c new file +3
-0+ VMSTATE_END_OF_LIST() + } +};
thanks
-- PMM
Re: [Qemu-devel] [PATCH 1/2] wdt: Add Aspeed watchdog device model
Quoted 107 lines · Peter Maydell
Quoted 106 lines · Cédric Le Goater
From: Joel Stanley <[email protected]>
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.
Signed-off-by Joel Stanley <[email protected]>[clg: - fixed compile breakage
- fixed io region size
- addedwatchdog_perform_action()on timer expiry
- wrote a commit log
- merged fixes from Andrew Jeffery to scale the reload value ]Signed-off-by Cédric Le Goater <[email protected]>--- hw/watchdog/Makefile.objs | 1 + hw/watchdog/wdt_aspeed.c | 214 +++++++++++++++++++++++++++++++++++++++ include/hw/watchdog/wdt_aspeed.h | 37 +++++++ 3 files changed, 252 insertions(+) create mode 100644 hw/watchdog/wdt_aspeed.c create mode 100644 include/hw/watchdog/wdt_aspeed.hhw/watchdog/Makefile.objs +1
-0@@ -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.ohw/watchdog/wdt_aspeed.c new file +63
-0@@ -0,0 +1,214 @@ +/* +* 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. +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "sysemu/watchdog.h" +#include "hw/sysbus.h" +#include "qemu/timer.h" +#include "hw/watchdog/wdt_aspeed.h" + +#define WDT_IO_REGION_SIZE 0x20 + +#define WDT_STATUS 0x00 +#define WDT_RELOAD_VALUE 0x04 +#define WDT_RESTART 0x08 +#define WDT_CTRL 0x0C +#define WDT_TIMEOUT_STATUS 0x10 +#define WDT_TIMEOUT_CLEAR 0x14 +#define WDT_RESET_WDITH 0x18 + +#define WDT_RESTART_MAGIC 0x4755 + +static uint64_t aspeed_wdt_read (void *opaque,hwaddr offset,unsigned size) +{ +AspeedWDTState *s =ASPEED_WDT (opaque); + +switch (offset) { +case WDT_STATUS : +return s->reg_status; +case WDT_RELOAD_VALUE : +return s->reg_reload_value; +case WDT_RESTART : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: read from write-only reg at offset 0x%" + HWADDR_PRIx"\n" , __func__, offset); +return 0 ; +case WDT_CTRL : +return s->reg_ctrl; +case WDT_TIMEOUT_STATUS : +case WDT_TIMEOUT_CLEAR : +case WDT_RESET_WDITH : +qemu_log_mask (LOG_UNIMP , +"%s: uninmplemented read at offset 0x%" HWADDR_PRIx"\n" , + __func__, offset); +return 0 ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Out-of-bounds read at offset 0x%" HWADDR_PRIx"\n" , + __func__, offset); +return 0 ; + } + +} + +#define PCLK_HZ 24000000 + +static void aspeed_wdt_write(void *opaque, hwaddr offset, uint64_t data,
Quoted 8 lines
hw/watchdog/wdt_aspeed.c line 68
Quoted 5 lines
hw/watchdog/wdt_aspeed.c new file +5
-0+ unsigned size) +{ +AspeedWDTState *s =ASPEED_WDT (opaque); +bool en = data &BIT (0 ); +bool pclk = !(data &BIT (4 ));These are only valid for
WDT_CTRL, right? That being so, initialising them up here is a bit odd.
Well, pclk is for the WDT_RESTART reg also. But, yes, it can be improved.
Quoted 50 lines
Quoted 37 lines
hw/watchdog/wdt_aspeed.c new file +37
-0+ +switch (offset) { +case WDT_STATUS : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: write to read-only reg at offset 0x%" + HWADDR_PRIx"\n" , __func__, offset); +break ; +case WDT_RELOAD_VALUE : + s->reg_reload_value = data; +break ; +case WDT_RESTART : +if ((data &0xFFFF ) ==0x4755 ) { +uint32_t reload; + + s->reg_status = s->reg_reload_value; + +if (pclk) { + reload =muldiv64 (s->reg_reload_value,NANOSECONDS_PER_SECOND , +PCLK_HZ ) ; + }else { + reload = s->reg_reload_value *1000 ; + } + +if (s->enabled) { +timer_mod (s->timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + reload); + } + } +break ; +case WDT_CTRL : +if (en && !s->enabled) { +uint32_t reload; + +if (pclk) { + reload =muldiv64 (s->reg_reload_value,NANOSECONDS_PER_SECOND , +PCLK_HZ ); + }else {hw/watchdog/wdt_aspeed.c line 115
Quoted 10 lines
hw/watchdog/wdt_aspeed.c new file +10
-0+ reload = s->reg_reload_value *1000 ; + } + + s->enabled = true; +timer_mod (s->timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + reload); + }else if (!en && s->enabled) { + s->enabled = false; +timer_del (s->timer); + } +break ;Shouldn't this write to
s->reg_ctrl?
Quoted 1 line
s->enabledseems to duplicate state also ins->reg_ctrl.
yes clearly. I will use a regs array in next version, it should be cleaner and also migration friendly. I completely left out that part.
Thanks,
C.
Quoted 37 lines
Quoted 17 lines
hw/watchdog/wdt_aspeed.c new file +17
-0+case WDT_TIMEOUT_STATUS : +case WDT_TIMEOUT_CLEAR : +case WDT_RESET_WDITH : +qemu_log_mask (LOG_UNIMP , +"%s: uninmplemented write at offset 0x%" HWADDR_PRIx"\n" , + __func__, offset); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Out-of-bounds write at offset 0x%" HWADDR_PRIx"\n" , + __func__, offset); + } +return ; +} + +static WatchdogTimerModel model = { + .wdt_name =TYPE_ASPEED_WDT ,hw/watchdog/wdt_aspeed.c line 142
Quoted 10 lines
hw/watchdog/wdt_aspeed.c new file +10
-0+ .wdt_description = "aspeed watchdog device", +}; + +static const VMStateDescription vmstate_aspeed_wdt = { + .name ="vmstate_aspeed_wdt" , + .version_id =0 , + .minimum_version_id =0 , + .fields = (VMStateField []) { +VMSTATE_TIMER_PTR (timer, AspeedWDTState), +VMSTATE_BOOL (enabled, AspeedWDTState),This doesn't seem to have fields for most of the register state.
hw/watchdog/wdt_aspeed.c line 145
Quoted 3 lines
hw/watchdog/wdt_aspeed.c new file +3
-0+ VMSTATE_END_OF_LIST() + } +};thanks
-- PMM
PATCH 2/2 aspeed: add a watchdog controller
In reply to Cédric Le GoaterThis 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
@@ -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 0x1E78A000static 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)
@@ -289,6 +294,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
@@ -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