Skip to contentSkip to conversation

Watchdog support for qemu arm and riscv

PATCH Superseded Jan Kiszka 2 participants 7 messages Oct 15 – Oct 18

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
author
#1 lore raw

PATCH v3 1/3 watchdog: Add support for i6300esb

In reply to Jan Kiszka

From: 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
index 3c56c541505..225e23ce247 100644
@@ -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
index 84faefdb4c2..cfe3f3dac5a 100644
@@ -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

Jan Kiszka

author
#0 lore raw

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
author
#4 lore raw

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
index 38f0ec5f2fb..529bffa3e49 100644
@@ -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
index ce5bc34ca71..5ed21b286ee 100644
@@ -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
author
#3 lore raw

PATCH v3 2/3 watchdog: add support to call initr_watchdog multiple times

In reply to Jan Kiszka

From: 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
index 88c5cbdf508..338b03f0121 100644
@@ -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
Reviewed-by Tested-by on v3 3/3
#5 lore raw

Re: [PATCH v3 3/3] board: qemu: arm/riscv: Probe watchdogs late

In reply to Jan Kiszka

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_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

Tested-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] watchdog: Add support for i6300esb

In reply to Jan Kiszka

Hi 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

author
#6 lore raw

Re: [PATCH v3 3/3] board: qemu: arm/riscv: Probe watchdogs late

In reply to Hung-Chun Tseng
Quoted 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_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

Quoted 7 lines

I did not test qemu-arm.

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