mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 0/4] add (U)EFI watchdog
@ 2019-02-15 12:43 Oleksij Rempel
  2019-02-15 12:43 ` [PATCH v2 1/4] efi: add prototype and definition for set_watchdog_timer Oleksij Rempel
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Oleksij Rempel @ 2019-02-15 12:43 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

changes v2:
- efi_wdt_set_timeout() should return error if we get error from (U)EFI
- use device_platform_driver()
- spelling and formatting fixes in the documentation.

Oleksij Rempel (4):
  efi: add prototype and definition for set_watchdog_timer
  watchdog: add (U)EFI driver
  efi_defconfig: enable watchdog support
  Documentation: efi: provide (U)EFI watchdog documentation

 Documentation/boards/efi.rst   | 36 ++++++++++++++++++-
 arch/x86/configs/efi_defconfig |  3 ++
 common/efi/efi.c               |  9 ++++-
 drivers/watchdog/Kconfig       |  6 ++++
 drivers/watchdog/Makefile      |  1 +
 drivers/watchdog/efi_wdt.c     | 64 ++++++++++++++++++++++++++++++++++
 include/efi.h                  |  5 ++-
 7 files changed, 121 insertions(+), 3 deletions(-)
 create mode 100644 drivers/watchdog/efi_wdt.c

-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/4] efi: add prototype and definition for set_watchdog_timer
  2019-02-15 12:43 [PATCH v2 0/4] add (U)EFI watchdog Oleksij Rempel
@ 2019-02-15 12:43 ` Oleksij Rempel
  2019-02-15 12:43 ` [PATCH v2 2/4] watchdog: add (U)EFI driver Oleksij Rempel
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Oleksij Rempel @ 2019-02-15 12:43 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 include/efi.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/efi.h b/include/efi.h
index 7cc5fe05fa..218333f824 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -234,7 +234,10 @@ typedef struct {
 	efi_status_t (EFIAPI *exit_boot_services)(efi_handle_t, unsigned long);
 	void *get_next_monotonic_count;
 	efi_status_t (EFIAPI *stall)(unsigned long usecs);
-	void *set_watchdog_timer;
+	efi_status_t (EFIAPI *set_watchdog_timer)(unsigned long timeout,
+						  uint64_t watchdog_code,
+						  unsigned long data_size,
+						  s16 *watchdog_data);
 	efi_status_t(EFIAPI *connect_controller)(efi_handle_t controller_handle,
 			efi_handle_t *driver_image_handle,
 			struct efi_device_path *remaining_device_path,
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 2/4] watchdog: add (U)EFI driver
  2019-02-15 12:43 [PATCH v2 0/4] add (U)EFI watchdog Oleksij Rempel
  2019-02-15 12:43 ` [PATCH v2 1/4] efi: add prototype and definition for set_watchdog_timer Oleksij Rempel
@ 2019-02-15 12:43 ` Oleksij Rempel
  2019-02-15 12:43 ` [PATCH v2 3/4] efi_defconfig: enable watchdog support Oleksij Rempel
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Oleksij Rempel @ 2019-02-15 12:43 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

This driver is using SetWatchdogTimer() UEFI interface and was
tested on iBASE MI991AF Mini-ITX motherboard.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 common/efi/efi.c           |  9 +++++-
 drivers/watchdog/Kconfig   |  6 ++++
 drivers/watchdog/Makefile  |  1 +
 drivers/watchdog/efi_wdt.c | 64 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 1 deletion(-)
 create mode 100644 drivers/watchdog/efi_wdt.c

diff --git a/common/efi/efi.c b/common/efi/efi.c
index 1f451a157e..a7b25cbbe2 100644
--- a/common/efi/efi.c
+++ b/common/efi/efi.c
@@ -367,8 +367,15 @@ efi_status_t efi_main(efi_handle_t image, efi_system_table_t *sys_table)
 
 static int efi_core_init(void)
 {
-	struct device_d *dev = device_alloc("efi-cs", DEVICE_ID_SINGLE);
+	struct device_d *dev;
+	int ret;
+
+	dev = device_alloc("efi-cs", DEVICE_ID_SINGLE);
+	ret = platform_device_register(dev);
+	if (ret)
+		return ret;
 
+	dev = device_alloc("efi-wdt", DEVICE_ID_SINGLE);
 	return platform_device_register(dev);
 }
 core_initcall(efi_core_init);
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 02cc0feb61..2793ee93d9 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -22,6 +22,12 @@ config WATCHDOG_AR9344
 	help
 	  Add support for watchdog on the QCA AR9344 SoC.
 
+config WATCHDOG_EFI
+	bool "Generic EFI Watchdog Driver"
+	depends on EFI_BOOTUP
+	help
+	  Add support for the EFI watchdog.
+
 config WATCHDOG_DAVINCI
 	bool "TI Davinci"
 	depends on ARCH_DAVINCI
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index faf06110a3..69189ba1f3 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -1,5 +1,6 @@
 obj-$(CONFIG_WATCHDOG) += wd_core.o
 obj-$(CONFIG_WATCHDOG_AR9344) += ar9344_wdt.o
+obj-$(CONFIG_WATCHDOG_EFI) += efi_wdt.o
 obj-$(CONFIG_WATCHDOG_DAVINCI) += davinci_wdt.o
 obj-$(CONFIG_WATCHDOG_OMAP) += omap_wdt.o
 obj-$(CONFIG_WATCHDOG_MXS28) += im28wd.o
diff --git a/drivers/watchdog/efi_wdt.c b/drivers/watchdog/efi_wdt.c
new file mode 100644
index 0000000000..8e3e51b7a9
--- /dev/null
+++ b/drivers/watchdog/efi_wdt.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ *  Copyright (C) 2019 Oleksij Rempel <o.rempel@pengutronix.de>, Pengutronix
+ */
+
+#include <common.h>
+#include <init.h>
+#include <driver.h>
+#include <efi.h>
+#include <efi/efi.h>
+#include <watchdog.h>
+
+struct efi_wdt_priv {
+	struct watchdog		wd;
+	struct device_d		*dev;
+};
+
+#define to_efi_wdt(h) container_of(h, struct efi_wdt_priv, wd)
+
+static int efi_wdt_set_timeout(struct watchdog *wd, unsigned timeout)
+{
+	struct efi_wdt_priv *priv = to_efi_wdt(wd);
+	efi_status_t efiret;
+
+	efiret = BS->set_watchdog_timer(timeout, 0, 0, NULL);
+	if (EFI_ERROR(efiret)) {
+		dev_err(priv->dev, "filed to set EFI watchdog: %lx\n", efiret);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int efi_wdt_probe(struct device_d *dev)
+{
+	struct efi_wdt_priv *priv;
+	int ret;
+
+	priv = xzalloc(sizeof(*priv));
+
+	priv->wd.set_timeout = efi_wdt_set_timeout;
+	priv->wd.hwdev = dev;
+	priv->dev = dev;
+
+	dev->priv = priv;
+
+	priv->wd.timeout_max = U32_MAX;
+
+	ret = watchdog_register(&priv->wd);
+	if (ret)
+		goto on_error;
+
+	return 0;
+
+on_error:
+	free(priv);
+	return ret;
+}
+
+static struct driver_d efi_wdt_driver = {
+	.name = "efi-wdt",
+	.probe = efi_wdt_probe,
+};
+device_platform_driver(efi_wdt_driver);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 3/4] efi_defconfig: enable watchdog support
  2019-02-15 12:43 [PATCH v2 0/4] add (U)EFI watchdog Oleksij Rempel
  2019-02-15 12:43 ` [PATCH v2 1/4] efi: add prototype and definition for set_watchdog_timer Oleksij Rempel
  2019-02-15 12:43 ` [PATCH v2 2/4] watchdog: add (U)EFI driver Oleksij Rempel
@ 2019-02-15 12:43 ` Oleksij Rempel
  2019-02-15 12:43 ` [PATCH v2 4/4] Documentation: efi: provide (U)EFI watchdog documentation Oleksij Rempel
  2019-02-18  8:54 ` [PATCH v2 0/4] add (U)EFI watchdog Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Oleksij Rempel @ 2019-02-15 12:43 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 arch/x86/configs/efi_defconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/configs/efi_defconfig b/arch/x86/configs/efi_defconfig
index fdf092e9ba..f489770eba 100644
--- a/arch/x86/configs/efi_defconfig
+++ b/arch/x86/configs/efi_defconfig
@@ -56,6 +56,7 @@ CONFIG_CMD_MM=y
 CONFIG_CMD_DETECT=y
 CONFIG_CMD_FLASH=y
 CONFIG_CMD_POWEROFF=y
+CONFIG_CMD_WD=y
 CONFIG_CMD_2048=y
 CONFIG_CMD_BAREBOX_UPDATE=y
 CONFIG_CMD_OF_NODE=y
@@ -71,6 +72,8 @@ CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_NET_EFI_SNP=y
 # CONFIG_SPI is not set
 CONFIG_DISK=y
+CONFIG_WATCHDOG=y
+CONFIG_WATCHDOG_EFI=y
 CONFIG_FS_EXT4=y
 CONFIG_FS_TFTP=y
 CONFIG_FS_NFS=y
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 4/4] Documentation: efi: provide (U)EFI watchdog documentation
  2019-02-15 12:43 [PATCH v2 0/4] add (U)EFI watchdog Oleksij Rempel
                   ` (2 preceding siblings ...)
  2019-02-15 12:43 ` [PATCH v2 3/4] efi_defconfig: enable watchdog support Oleksij Rempel
@ 2019-02-15 12:43 ` Oleksij Rempel
  2019-02-18  8:54 ` [PATCH v2 0/4] add (U)EFI watchdog Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Oleksij Rempel @ 2019-02-15 12:43 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 Documentation/boards/efi.rst | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/Documentation/boards/efi.rst b/Documentation/boards/efi.rst
index f59bb1d5ba..749acce811 100644
--- a/Documentation/boards/efi.rst
+++ b/Documentation/boards/efi.rst
@@ -216,7 +216,6 @@ has a device parameter ``devpath`` which contains its device path:
   barebox:/ echo ${handle-00000000d0012198.devpath}
   pci_root(0)/Pci(0x1d,0x0)/Usb(0x1,0x0)/Usb(0x2,0x0)
 
-
 EFI variables
 -------------
 
@@ -327,3 +326,38 @@ compile EDK2.
                    mov     %fs, %rax
                    pushq   %rax
 
+(U)EFI Watchdog
+---------------
+
+(U)EFI provides basic watchdog support. Depending on the system implementation
+it can be a software or hardware watchdog. Within the (U)EFI specification it
+is described as follows:
+
+.. epigraph::
+
+   If the watchdog timer expires, the event is logged by the firmware. The system
+   may then either reset with the Runtime Service ResetSystem(), or perform a
+   platform specific action that must eventually cause the platform to be reset.
+   The watchdog timer is armed before the firmware's boot manager invokes an EFI
+   boot option.  The watchdog must be set to a period of 5 minutes. The EFI Image
+   may reset or disable the watchdog timer as needed. If control is returned to
+   the firmware's boot manager, the watchdog timer must be disabled.  The watchdog
+   timer is only used during boot services. On successful completion of
+   ExitBootServices() the watchdog timer is disabled.
+
+See page 186:
+https://uefi.org/sites/default/files/resources/UEFI_Spec_2_1_D.pdf
+
+Current linux kernel (v5.0) will execute ExitBootServices() during the early
+boot stage and thus will automatically disable the (U)EFI watchdog. Since it is
+a proper behavior according to the (U)EFI specification, it is impossible to
+protect full boot chain by using this watchdog only. It is recommended to use
+an alternative hardware watchdog, preferably started before the bootloader. If (U)EFI
+firmware lacks this feature, the bootloader should be able to start an alternative
+hardware watchdog on its own. Before implementing this kind of workaround
+please make sure (U)EFI watchdog is not using the same hardware as the alternative
+watchdog.
+
+Nevertheless, barebox provides access to the (U)EFI SetWatchdogTimer()
+interface over its internal watchdog framework.
+
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/4] add (U)EFI watchdog
  2019-02-15 12:43 [PATCH v2 0/4] add (U)EFI watchdog Oleksij Rempel
                   ` (3 preceding siblings ...)
  2019-02-15 12:43 ` [PATCH v2 4/4] Documentation: efi: provide (U)EFI watchdog documentation Oleksij Rempel
@ 2019-02-18  8:54 ` Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2019-02-18  8:54 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox

On Fri, Feb 15, 2019 at 01:43:47PM +0100, Oleksij Rempel wrote:
> changes v2:
> - efi_wdt_set_timeout() should return error if we get error from (U)EFI
> - use device_platform_driver()
> - spelling and formatting fixes in the documentation.
> 
> Oleksij Rempel (4):
>   efi: add prototype and definition for set_watchdog_timer
>   watchdog: add (U)EFI driver
>   efi_defconfig: enable watchdog support
>   Documentation: efi: provide (U)EFI watchdog documentation

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-02-18  8:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-15 12:43 [PATCH v2 0/4] add (U)EFI watchdog Oleksij Rempel
2019-02-15 12:43 ` [PATCH v2 1/4] efi: add prototype and definition for set_watchdog_timer Oleksij Rempel
2019-02-15 12:43 ` [PATCH v2 2/4] watchdog: add (U)EFI driver Oleksij Rempel
2019-02-15 12:43 ` [PATCH v2 3/4] efi_defconfig: enable watchdog support Oleksij Rempel
2019-02-15 12:43 ` [PATCH v2 4/4] Documentation: efi: provide (U)EFI watchdog documentation Oleksij Rempel
2019-02-18  8:54 ` [PATCH v2 0/4] add (U)EFI watchdog Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox