Watchdog support for qemu arm and riscv
Subsystems (2)
PATCH v3 1/3 watchdog: Add support for i6300esb
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
While the real hardware might be in the museum now, this allows to test watchdog integrations against QEMU virtual machines (-device i6300esb).
--- drivers/watchdog/Kconfig | 9 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/i6300esb-wdt.c | 152 ++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 drivers/watchdog/i6300esb-wdt.c
drivers/watchdog/Kconfig +9 -0
@@ -494,4 +494,13 @@ config WDT_FTWDT010 help Faraday Technology ftwdt010 watchdog is an architecture independent watchdog. It is usually used in SoC chip design. + +config WDT_I6300ESB + bool "Intel 6300ESB Watchdog" + depends on WDT && PCI + help + Hardware driver for the watchdog timer built into the Intel + 6300ESB controller hub. Also emulated by QEMU, thus useful for + testing watchdog functionality in virtual systems. + endmenu
drivers/watchdog/Makefile +1 -0
@@ -58,3 +58,4 @@ obj-$(CONFIG_WDT_TEGRA) += tegra_wdt.o obj-$(CONFIG_WDT_XILINX) += xilinx_wwdt.o obj-$(CONFIG_WDT_ADI) += adi_wdt.o obj-$(CONFIG_WDT_QCOM) += qcom-wdt.o +obj-$(CONFIG_WDT_I6300ESB) += i6300esb-wdt.o
drivers/watchdog/i6300esb-wdt.c new file +152 -0
152 lines not on this page · raw message
Signature · 1 line
2.47.3
v3 cover Watchdog support for qemu arm and riscv
On non-x86, QEMU only offers a watchdog via the PCI-attached Intel 6300 ESB. Add a driver for it and make sure it is probed during board init.
Background for adding this feature is testing complex system integrations that include watchdog-monitored OTA OS updates, e.g. [1].
Changes in v3:
- reload after timer preload setting
- initialize max_timeout_ms
- null-check register base
- code de-duplication *** BLURB HERE *** style fixes
- prevent reprobing of already activated devices
Changes in v2:
- fix a compilation issue of the driver on riscv
- add late probing to qemu
Jan
[1] https://gitlab.com/cip-project/cip-core/isar-cip-core
Jan Kiszka (3):
watchdog: Add support for i6300esb
watchdog: add support to call initr_watchdog multiple times
board: qemu: arm/riscv: Probe watchdogs late
board/emulation/qemu-arm/qemu-arm.c | 5 + board/emulation/qemu-riscv/qemu-riscv.c | 5 + drivers/watchdog/Kconfig | 9 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/i6300esb-wdt.c | 152 ++++++++++++++++++++++++ drivers/watchdog/wdt-uclass.c | 7 ++ 6 files changed, 179 insertions(+) create mode 100644 drivers/watchdog/i6300esb-wdt.c
Signature · 1 line
2.47.3
PATCH v3 3/3 board: qemu: arm/riscv: Probe watchdogs late
From: Jan Kiszka <[email protected]>
The only watchdog QEMU offers us on non-x86 virt platforms is the i6300esb. This one is PCI-attached, but watchdog probing will happen before PCI, so will miss it. Redo this late so that we gain autostart support.
Deliberately limited to contemporary ARM and RISC-V.
--- board/emulation/qemu-arm/qemu-arm.c | 5 +++++ board/emulation/qemu-riscv/qemu-riscv.c | 5 +++++ 2 files changed, 10 insertions(+)
board/emulation/qemu-arm/qemu-arm.c +5 -0
@@ -14,6 +14,7 @@#include <usb.h> #include <virtio_types.h> #include <virtio.h> +#include <wdt.h> #include <linux/kernel.h> #include <linux/sizes.h>
@@ -114,6 +115,10 @@ int board_late_init(void)if (CONFIG_IS_ENABLED (USB_KEYBOARD ))usb_init (); +/* watchdog may come via PCI but was probed too early */ +if (CONFIG_IS_ENABLED (WDT )) +initr_watchdog (); +return 0 ; }
board/emulation/qemu-riscv/qemu-riscv.c +5 -0
@@ -14,6 +14,7 @@#include <usb.h> #include <virtio_types.h> #include <virtio.h> +#include <wdt.h> #if IS_ENABLED (CONFIG_MTD_NOR_FLASH )int is_flash_available (void )
@@ -38,6 +39,10 @@ int board_late_init(void)*/ virtio_init (); +/* watchdog may come via PCI but was probed too early */ +if (CONFIG_IS_ENABLED (WDT )) +initr_watchdog (); +return 0 ; }
Signature · 1 line
2.47.3
PATCH v3 2/3 watchdog: add support to call initr_watchdog multiple times
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
This allows to invoke it from board init code once more if probe ordering requires this. In that case, avoid to re-add already activated watchdog devices.
--- drivers/watchdog/wdt-uclass.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/watchdog/wdt-uclass.c +7 -0
@@ -105,6 +105,13 @@ int initr_watchdog(void) } uclass_foreach_dev(dev, uc) { +/* +* initr_watchdog might be called multiple times to resolve +* for probe ordering issues. Skip already activated devices. +*/ +if (device_active (dev)) +continue ; + ret =device_probe (dev);if (ret) {log_debug ("Error probing %s: %d\n" , dev->name, ret);
Signature · 1 line
2.47.3
Re: [PATCH v3 3/3] board: qemu: arm/riscv: Probe watchdogs late
In reply to Jan KiszkaHi Jan,
Quoted 4 lines · Jan Kiszka
The only watchdog QEMU offers us on non-x86 virt platforms is the i6300esb. This one is PCI-attached, but watchdog probing will happen before PCI, so will miss it. Redo this late so that we gain autostart support.
I tested the whole series on qemu-riscv64_smode_defconfig with WDT, WATCHDOG and WDT_I6300ESB enabled and WATCHDOG_TIMEOUT_MSECS=5000, on QEMU 11.1.2 with "-M virt -device i6300esb":
- the watchdog autostarts ("WDT: Started i6300esb_wdt with servicing
every 1000ms (5s timeout)") and the machine stays up while idle at the prompt
- "go" to an endless loop resets the machine after about 5 s
- "wdt stop" followed by the same loop: no reset
- without "-device i6300esb": no WDT output and no change in behaviour
- with only 1/3 and 2/3 applied, the device shows up in "wdt list" but is never started, so this patch is what makes autostart work
I did not test qemu-arm.
Thanks,
Hung-Chun
Re: [PATCH v3 1/3] watchdog: Add support for i6300esb
In reply to Jan KiszkaHi Jan,
Two minor things, neither of which needs to block this.
drivers/watchdog/i6300esb-wdt.c line 66
Quoted 1 line · Jan Kiszka
drivers/watchdog/i6300esb-wdt.c new file +1
-0+ val = ms *1000000ULL /983040 ;
On rv32 this is a 64-bit division, so i6300esb-wdt.o ends up with an undefined __udivdi3 (seen with qemu-riscv32_smode_defconfig plus WDT_I6300ESB). lldiv() from <div64.h> avoids depending on libgcc for it (checked that the object then has no __udivdi3 reference):
val = lldiv(ms * 1000000ULL, 983040);
drivers/watchdog/i6300esb-wdt.c line 106
Quoted 2 lines
drivers/watchdog/i6300esb-wdt.c new file +2
-0+if (wdt->base ==NULL ) +return -EINVAL ;
checkpatch suggests "if (!wdt->base)" here.
Otherwise this works fine on qemu-riscv64, see my reply to 3/3:
Thanks,
Hung-Chun
Re: [PATCH v3 3/3] board: qemu: arm/riscv: Probe watchdogs late
In reply to Hung-Chun TsengQuoted 21 lines · Hung-Chun Tseng
Hi Jan,
Quoted 4 lines · Jan Kiszka
The only watchdog QEMU offers us on non-x86 virt platforms is the i6300esb. This one is PCI-attached, but watchdog probing will happen before PCI, so will miss it. Redo this late so that we gain autostart support.
I tested the whole series on qemu-riscv64_smode_defconfig with WDT, WATCHDOG and
WDT_I6300ESBenabled and WATCHDOG_TIMEOUT_MSECS=5000, on QEMU 11.1.2 with "-M virt -device i6300esb":- the watchdog autostarts ("WDT: Started
i6300esb_wdtwith servicing
every 1000ms (5s timeout)") and the machine stays up while idle at the prompt
- "go" to an endless loop resets the machine after about 5 s
- "wdt stop" followed by the same loop: no reset
- without "-device i6300esb": no WDT output and no change in behaviour
- with only 1/3 and 2/3 applied, the device shows up in "wdt list" but is never started, so this patch is what makes autostart work
Quoted 7 lines
I did not test qemu-arm.
Reviewed-by Hung-Chun Tseng <[email protected]>Thanks,
Hung-Chun
Thanks for checking and for the review comments! I'll send out v4 with those addressed soon.
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center