Skip to contentSkip to conversation

Watchdog support for qemu arm and riscv

PATCH In review Jan Kiszka 2 participants 10 messages Oct 18 – Nov 7

Subsystems (2)
lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

v4 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 v4:
- use lldiv64
- style fix

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         | 153 ++++++++++++++++++++++++
 drivers/watchdog/wdt-uclass.c           |   7 ++
 6 files changed, 180 insertions(+)
 create mode 100644 drivers/watchdog/i6300esb-wdt.c
Signature · 1 line
2.47.3
author
#1 lore raw

PATCH v4 1/3 watchdog: Add support for i6300esb

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 | 153 ++++++++++++++++++++++++++++++++
 3 files changed, 163 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 +153 -0

153 lines not on this page · raw message

Signature · 1 line
2.47.3
Reviewed-by on v4 1/3
#2 lore raw

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

Hi Jan,

Quoted 5 lines · Jan Kiszka

While the real hardware might be in the museum now, this allows to test watchdog integrations against QEMU virtual machines (-device i6300esb).

[...]

drivers/watchdog/i6300esb-wdt.c line 38

Quoted 2 lines
drivers/watchdog/i6300esb-wdt.c new file +2 -0
+struct i6300_wdt {
+	void *base;

Nit: void __iomem *base. I'll change this while applying, no need for a v5.

Thanks,
Stefan

#3 lore raw

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

In reply to Jan Kiszka
Quoted 7 lines · 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).

Applied to u-boot-watchdog/main, with a fixup while applying:

[sr: use void __iomem *base]

Thanks,
Stefan

author
#4 lore raw

PATCH v4 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 on v4 2/3
#5 lore raw

Re: [PATCH v4 2/3] watchdog: add support to call initr_watchdog multiple times

Quoted 6 lines · Jan Kiszka

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.

Thanks,
Stefan

#6 lore raw

Re: [PATCH v4 2/3] watchdog: add support to call initr_watchdog multiple times

In reply to Jan Kiszka
Quoted 8 lines · 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.

Applied to u-boot-watchdog/main

Thanks,
Stefan

author
#7 lore raw

PATCH v4 3/3 board: qemu: arm/riscv: Probe watchdogs late

In reply to Jan Kiszka

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
Reviewed-by on v4 3/3
#8 lore raw

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

Quoted 10 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.

Deliberately limited to contemporary ARM and RISC-V.

Thanks,
Stefan

#9 lore raw

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

In reply to Jan Kiszka
Quoted 7 lines · Jan Kiszka

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.

Quoted 5 lines

Deliberately limited to contemporary ARM and RISC-V.

Applied to u-boot-watchdog/main

Thanks,
Stefan