Skip to contentSkip to conversation

kernel: Add support for restart handler call chain

PATCH Superseded Guenter Roeck 11 participants 44 messages Aug 20, 2014 – Dec 4, 2014

Subsystems (9)
lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

v7 cover kernel: Add support for restart handler call chain

Various drivers implement architecture and/or device specific means to restart (reset) the system. Various mechanisms have been implemented to support those schemes. The best known mechanism is arm_pm_restart, which is a function pointer to be set either from platform specific code or from drivers. Another mechanism is to use hardware watchdogs to issue a reset; this mechanism is used if there is no other method available to reset a board or system. Two examples are alim7101_wdt, which currently uses the reboot notifier to trigger a reset, and moxart_wdt, which registers the arm_pm_restart function. Several other restart drivers for arm, all directly calling arm_pm_restart, are in the process of being integrated into the kernel. All those drivers would benefit from the new API.

The existing mechanisms have a number of drawbacks. Typically only one scheme to restart the system is supported (at least if arm_pm_restart is used). At least in theory there can be multiple means to restart the system, some of which may be less desirable (for example one mechanism may only reset the CPU, while another may reset the entire system). Using arm_pm_restart can also be racy if the function pointer is set from a driver, as the driver may be in the process of being unloaded when arm_pm_restart is called. Using the reboot notifier is always racy, as it is unknown if and when other functions using the reboot notifier have completed execution by the time the watchdog fires.

Introduce a system restart handler call chain to solve the described problems. This call chain is expected to be executed from the architecture specific machine_restart() function. Drivers providing system restart functionality (such as the watchdog drivers mentioned above) are expected to register with this call chain. By using the priority field in the notifier block, callers can control restart handler execution sequence and thus ensure that the restart handler with the optimal restart capabilities for a given system is called first.

Since the first revision of this patchset, a number of separate patch submissions have been made which either depend on it or could make use of it.

http://www.spinics.net/linux/lists/arm-kernel/msg344796.html
registers three notifiers.
https://lkml.org/lkml/2014/7/8/962
would benefit from it.

Patch 1 of this series implements the restart handler function. Patches 2 and 3 implement calling the restart handler chain from arm and arm64 restart code.

Patch 4 modifies the restart-poweroff driver to no longer call arm_pm_restart directly but machine_restart. This is done to avoid calling arm_pm_restart from more than one place. The change makes the driver architecture independent, so it would be possible to drop the arm dependency from its Kconfig entry.

Patch 5 and 6 convert existing restart handlers in the watchdog subsystem to use the restart handler. Patch 7 unexports arm_pm_restart to ensure that no one gets the idea to implement a restart handler as module.

The entire patch series, including additional patches depending on it, is available from
https://git.kernel.org/cgit/linux/kernel/git/groeck/linux-staging.git/
in branch 'restart-staging'.

---
v7: Rebased to v3.17-rc1
Dropped null_restart from arm code to make arm_pm_restart truly optional Reordered series. power/restart must be patched to not use arm_pm_restart prior to making arm_pm_restart optional.
Added all pending patches to series
v6: Use atomic notifier call chain
Rebased series to v3.16
v5: Rebased series to v3.16-rc5

    Function renames:
    register_restart_notifier -> register_restart_handler
    unregister_restart_notifier -> unregister_restart_handler
    kernel_restart_notify -> do_kernel_restart

v4: Document restart notifier priorities
Select 128 as default priority for newly introduced notifiers Fix checkpatch warning (line too long) in moxart patch
v3: Drop RFC.
Add kernel_restart_notify wrapper function to execute notifier Improve documentation.
Move restart_notifier_list into kernel/reboot.c and make it static.
v2: Add patch 4.
Only call blocking notifier call chain if arm_pm_restart was not set.

author maintainer
#1 lore raw

PATCH v7 1/11 kernel: Add support for kernel restart handler call chain

Various drivers implement architecture and/or device specific means to restart (reset) the system. Various mechanisms have been implemented to support those schemes. The best known mechanism is arm_pm_restart, which is a function pointer to be set either from platform specific code or from drivers. Another mechanism is to use hardware watchdogs to issue a reset; this mechanism is used if there is no other method available to reset a board or system. Two examples are alim7101_wdt, which currently uses the reboot notifier to trigger a reset, and moxart_wdt, which registers the arm_pm_restart function.

The existing mechanisms have a number of drawbacks. Typically only one scheme to restart the system is supported (at least if arm_pm_restart is used). At least in theory there can be multiple means to restart the system, some of which may be less desirable (for example one mechanism may only reset the CPU, while another may reset the entire system). Using arm_pm_restart can also be racy if the function pointer is set from a driver, as the driver may be in the process of being unloaded when arm_pm_restart is called. Using the reboot notifier is always racy, as it is unknown if and when other functions using the reboot notifier have completed execution by the time the watchdog fires.

Introduce a system restart handler call chain to solve the described problems. This call chain is expected to be executed from the architecture specific machine_restart() function. Drivers providing system restart functionality (such as the watchdog drivers mentioned above) are expected to register with this call chain. By using the priority field in the notifier block, callers can control restart handler execution sequence and thus ensure that the restart handler with the optimal restart capabilities for a given system is called first.

---
v7: Rebased to v3.17-rc1
v6: Use atomic notifier call chain
v5: Function renames:

    register_restart_notifier -> register_restart_handler
    unregister_restart_notifier -> unregister_restart_handler
    kernel_restart_notify -> do_kernel_restart

v4: Document and suggest values for notifier priorities
v3: Add kernel_restart_notify wrapper function to execute notifier.
Improve documentation.
Move restart_notifier_list into kernel/reboot.c and make it static.
v2: No change.

 include/linux/reboot.h |  3 ++
 kernel/reboot.c        | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)
include/linux/reboot.h +3 -0
index 48bf152..67fc8fc 100644
@@ -38,6 +38,9 @@ extern int reboot_force;
 extern int register_reboot_notifier(struct notifier_block *);
 extern int unregister_reboot_notifier(struct notifier_block *);
 
+extern int register_restart_handler(struct notifier_block *);
+extern int unregister_restart_handler(struct notifier_block *);
+extern void do_kernel_restart(char *cmd);
 
 /*
  * Architecture-specific implementations of sys_reboot commands.
kernel/reboot.c +81 -0

87 lines not on this page · raw message

Signature · 1 line
1.9.1
author maintainer
#3 lore raw

PATCH v7 2/11 power/restart: Call machine_restart instead of arm_pm_restart

In reply to Guenter Roeck

machine_restart is supported on non-ARM platforms, and and ultimately calls arm_pm_restart, so dont call arm_pm_restart directly but use the more generic function.

---
v7: No change.
v6: No change.
v5: No change.
v4: No change.
v3: No change.
v2: Added patch.

 drivers/power/reset/restart-poweroff.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/power/reset/restart-poweroff.c +2 -1
index 3e51f8d..edd707e 100644
@@ -20,7 +20,8 @@
 
 static void restart_poweroff_do_poweroff(void)
 {
-	arm_pm_restart(REBOOT_HARD, NULL);
+	reboot_mode = REBOOT_HARD;
+	machine_restart(NULL);
 }
 
 static int restart_poweroff_probe(struct platform_device *pdev)
Signature · 1 line
1.9.1
author maintainer
#10 lore raw

PATCH v7 3/11 arm64: Support restart through restart handler call chain

In reply to Guenter Roeck

The kernel core now supports a restart handler call chain to restart the system. Call it if arm_pm_restart is not set.

---
v7: No change.
v6: No change.
v5: Renamed restart function to do_kernel_restart
v4: No change.
v3: Use wrapper function to execute notifier call chain.
v2: Only call notifier call chain if arm_pm_restart is not set.
Do not include linux/watchdog.h.

 arch/arm64/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/kernel/process.c +2 -0
index 1309d64..0d3fb9f 100644
@@ -180,6 +180,8 @@ void machine_restart(char *cmd)
 	/* Now call the architecture specific reboot code. */
 	if (arm_pm_restart)
 		arm_pm_restart(reboot_mode, cmd);
+	else
+		do_kernel_restart(cmd);
 
 	/*
 	 * Whoops - the architecture was unable to reboot.
Signature · 1 line
1.9.1
author maintainer
#12 lore raw

PATCH v7 4/11 arm: Support restart through restart handler call chain

In reply to Guenter Roeck

The kernel core now supports a restart handler call chain for system restart functions.

With this change, the arm_pm_restart callback is now optional, so drop its initialization and check if it is set before calling it. Only call the kernel restart handler if arm_pm_restart is not set.

---
v7: Dropped null_restart and made arm_pm_restart truly optional.
v6: No change.
v5: Renamed restart function to do_kernel_restart
v4: No change.
v3: Use wrapper function to execute notifier call chain.
v2: Only call notifier call chain if arm_pm_restart is not set.
Do not include linux/watchdog.h.

 arch/arm/kernel/process.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
arch/arm/kernel/process.c +5 -6
index 81ef686..ea279f7 100644
@@ -114,17 +114,13 @@ void soft_restart(unsigned long addr)
 	BUG();
 }
 
-static void null_restart(enum reboot_mode reboot_mode, const char *cmd)
-{
-}
-
 /*
  * Function pointers to optional machine specific functions
  */
 void (*pm_power_off)(void);
 EXPORT_SYMBOL(pm_power_off);
 
-void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd) = null_restart;
+void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
 EXPORT_SYMBOL_GPL(arm_pm_restart);
 
 /*
@@ -230,7 +226,10 @@ void machine_restart(char *cmd)
 	local_irq_disable();
 	smp_send_stop();
 
-	arm_pm_restart(reboot_mode, cmd);
+	if (arm_pm_restart)
+		arm_pm_restart(reboot_mode, cmd);
+	else
+		do_kernel_restart(cmd);
 
 	/* Give a grace period for failure to restart of 1s */
 	mdelay(1000);
Signature · 1 line
1.9.1
author maintainer
#17 lore raw

PATCH v7 5/11 watchdog: moxart: Register restart handler with kernel restart handler

In reply to Guenter Roeck

The kernel now provides an API to trigger a system restart. Register with it instead of setting arm_pm_restart.

---
v7: No change.
v6: No change.
v5: Functions and variables renamed: *notifier -> *handler
v4: Set notifier priority to 128.
v3: Move struct notifier_block into struct moxart_wdt_dev.
Drop static variable previously needed to access struct moxart_wdt_dev from notifier function; use container_of instead.
v2: No change.

 drivers/watchdog/moxart_wdt.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)
drivers/watchdog/moxart_wdt.c +20 -12
index 4aa3a8a..a64405b 100644
@@ -15,12 +15,12 @@
 #include <linux/module.h>
 #include <linux/err.h>
 #include <linux/kernel.h>
+#include <linux/notifier.h>
 #include <linux/platform_device.h>
+#include <linux/reboot.h>
 #include <linux/watchdog.h>
 #include <linux/moduleparam.h>
 
-#include <asm/system_misc.h>
-
 #define REG_COUNT			0x4
 #define REG_MODE			0x8
 #define REG_ENABLE			0xC
@@ -29,17 +29,22 @@ struct moxart_wdt_dev {
 	struct watchdog_device dev;
 	void __iomem *base;
 	unsigned int clock_frequency;
+	struct notifier_block restart_handler;
 };
 
-static struct moxart_wdt_dev *moxart_restart_ctx;
-
 static int heartbeat;
 
-static void moxart_wdt_restart(enum reboot_mode reboot_mode, const char *cmd)
+static int moxart_restart_handle(struct notifier_block *this,
+				 unsigned long mode, void *cmd)
 {
-	writel(1, moxart_restart_ctx->base + REG_COUNT);
-	writel(0x5ab9, moxart_restart_ctx->base + REG_MODE);
-	writel(0x03, moxart_restart_ctx->base + REG_ENABLE);
+	struct moxart_wdt_dev *moxart_wdt = container_of(this,
+							 struct moxart_wdt_dev,
+							 restart_handler);
+	writel(1, moxart_wdt->base + REG_COUNT);
+	writel(0x5ab9, moxart_wdt->base + REG_MODE);
+	writel(0x03, moxart_wdt->base + REG_ENABLE);
+
+	return NOTIFY_DONE;
 }
 
 static int moxart_wdt_stop(struct watchdog_device *wdt_dev)
@@ -136,8 +141,12 @@ static int moxart_wdt_probe(struct platform_device *pdev)
 	if (err)
 		return err;
 
-	moxart_restart_ctx = moxart_wdt;
-	arm_pm_restart = moxart_wdt_restart;
+	moxart_wdt->restart_handler.notifier_call = moxart_restart_handle;
+	moxart_wdt->restart_handler.priority = 128;
+	err = register_restart_handler(&moxart_wdt->restart_handler);
+	if (err)
+		dev_err(dev, "cannot register restart notifier (err=%d)\n",
+			err);
 
 	dev_dbg(dev, "Watchdog enabled (heartbeat=%d sec, nowayout=%d)\n",
 		moxart_wdt->dev.timeout, nowayout);
@@ -149,9 +158,8 @@ static int moxart_wdt_remove(struct platform_device *pdev)
 {
 	struct moxart_wdt_dev *moxart_wdt = platform_get_drvdata(pdev);
 
-	arm_pm_restart = NULL;
+	unregister_restart_handler(&moxart_wdt->restart_handler);
 	moxart_wdt_stop(&moxart_wdt->dev);
-	watchdog_unregister_device(&moxart_wdt->dev);
 
 	return 0;
 }
Signature · 1 line
1.9.1
author maintainer
#18 lore raw

PATCH v7 6/11 watchdog: alim7101: Register restart handler with kernel restart handler

In reply to Guenter Roeck

The kernel core now provides an API to trigger a system restart. Register with it to restart the system instead of misusing the reboot notifier.

---
v7: No change.
v6: No change.
v5: Function and variable renames: *notifier -> *handler.
v4: Set restart notifier priority to 128.
v3: No change.
v2: No change.

 drivers/watchdog/alim7101_wdt.c | 42 +++++++++++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 10 deletions(-)
drivers/watchdog/alim7101_wdt.c +32 -10
index 996b2f7..665e0e7 100644
@@ -301,6 +301,28 @@ static struct miscdevice wdt_miscdev = {
 	.fops	=	&wdt_fops,
 };
 
+static int wdt_restart_handle(struct notifier_block *this, unsigned long mode,
+			      void *cmd)
+{
+	/*
+	 * Cobalt devices have no way of rebooting themselves other
+	 * than getting the watchdog to pull reset, so we restart the
+	 * watchdog on reboot with no heartbeat.
+	 */
+	wdt_change(WDT_ENABLE);
+
+	/* loop until the watchdog fires */
+	while (true)
+		;
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block wdt_restart_handler = {
+	.notifier_call = wdt_restart_handle,
+	.priority = 128,
+};
+
 /*
  *	Notifier for system down
  */
@@ -311,15 +333,6 @@ static int wdt_notify_sys(struct notifier_block *this,
 	if (code == SYS_DOWN || code == SYS_HALT)
 		wdt_turnoff();
 
-	if (code == SYS_RESTART) {
-		/*
-		 * Cobalt devices have no way of rebooting themselves other
-		 * than getting the watchdog to pull reset, so we restart the
-		 * watchdog on reboot with no heartbeat
-		 */
-		wdt_change(WDT_ENABLE);
-		pr_info("Watchdog timer is now enabled with no heartbeat - should reboot in ~1 second\n");
-	}
 	return NOTIFY_DONE;
 }
 
@@ -338,6 +351,7 @@ static void __exit alim7101_wdt_unload(void)
 	/* Deregister */
 	misc_deregister(&wdt_miscdev);
 	unregister_reboot_notifier(&wdt_notifier);
+	unregister_restart_handler(&wdt_restart_handler);
 	pci_dev_put(alim7101_pmu);
 }
 
@@ -390,11 +404,17 @@ static int __init alim7101_wdt_init(void)
 		goto err_out;
 	}
 
+	rc = register_restart_handler(&wdt_restart_handler);
+	if (rc) {
+		pr_err("cannot register restart handler (err=%d)\n", rc);
+		goto err_out_reboot;
+	}
+
 	rc = misc_register(&wdt_miscdev);
 	if (rc) {
 		pr_err("cannot register miscdev on minor=%d (err=%d)\n",
 		       wdt_miscdev.minor, rc);
-		goto err_out_reboot;
+		goto err_out_restart;
 	}
 
 	if (nowayout)
@@ -404,6 +424,8 @@ static int __init alim7101_wdt_init(void)
 		timeout, nowayout);
 	return 0;
 
+err_out_restart:
+	unregister_restart_handler(&wdt_restart_handler);
 err_out_reboot:
 	unregister_reboot_notifier(&wdt_notifier);
 err_out:
Signature · 1 line
1.9.1
author maintainer
#19 lore raw

PATCH v7 7/11 watchdog: sunxi: Register restart handler with kernel restart handler

In reply to Guenter Roeck

The kernel core now provides an API to trigger a system restart. Register with it instead of setting arm_pm_restart.

---
v7: Added patch to series. Necessary since the restart handler in the driver
is now available upstream.

 drivers/watchdog/sunxi_wdt.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
drivers/watchdog/sunxi_wdt.c +20 -11
index 60deb9d..480bb55 100644
@@ -21,14 +21,13 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/notifier.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/reboot.h>
 #include <linux/types.h>
 #include <linux/watchdog.h>
 
-#include <asm/system_misc.h>
-
 #define WDT_MAX_TIMEOUT         16
 #define WDT_MIN_TIMEOUT         1
 #define WDT_MODE_TIMEOUT(n)     ((n) << 3)
@@ -50,6 +49,7 @@ static unsigned int timeout = WDT_MAX_TIMEOUT;
 struct sunxi_wdt_dev {
 	struct watchdog_device wdt_dev;
 	void __iomem *wdt_base;
+	struct notifier_block restart_handler;
 };
 
 /*
@@ -74,24 +74,29 @@ static const int wdt_timeout_map[] = {
 	[16] = 0xB, /* 16s */
 };
 
-static void __iomem *reboot_wdt_base;
 
-static void sun4i_wdt_restart(enum reboot_mode mode, const char *cmd)
+static int sunxi_restart_handle(struct notifier_block *this, unsigned long mode,
+				void *cmd)
 {
+	struct sunxi_wdt_dev *sunxi_wdt = container_of(this,
+						       struct sunxi_wdt_dev,
+						       restart_handler);
+	void __iomem *wdt_base = sunxi_wdt->wdt_base;
+
 	/* Enable timer and set reset bit in the watchdog */
-	writel(WDT_MODE_EN | WDT_MODE_RST_EN, reboot_wdt_base + WDT_MODE);
+	writel(WDT_MODE_EN | WDT_MODE_RST_EN, wdt_base + WDT_MODE);
 
 	/*
 	 * Restart the watchdog. The default (and lowest) interval
 	 * value for the watchdog is 0.5s.
 	 */
-	writel(WDT_CTRL_RELOAD, reboot_wdt_base + WDT_CTRL);
+	writel(WDT_CTRL_RELOAD, wdt_base + WDT_CTRL);
 
 	while (1) {
 		mdelay(5);
-		writel(WDT_MODE_EN | WDT_MODE_RST_EN,
-		       reboot_wdt_base + WDT_MODE);
+		writel(WDT_MODE_EN | WDT_MODE_RST_EN, wdt_base + WDT_MODE);
 	}
+	return NOTIFY_DONE;
 }
 
 static int sunxi_wdt_ping(struct watchdog_device *wdt_dev)
@@ -205,8 +210,12 @@ static int sunxi_wdt_probe(struct platform_device *pdev)
 	if (unlikely(err))
 		return err;
 
-	reboot_wdt_base = sunxi_wdt->wdt_base;
-	arm_pm_restart = sun4i_wdt_restart;
+	sunxi_wdt->restart_handler.notifier_call = sunxi_restart_handle;
+	sunxi_wdt->restart_handler.priority = 128;
+	err = register_restart_handler(&sunxi_wdt->restart_handler);
+	if (err)
+		dev_err(&pdev->dev,
+			"cannot register restart handler (err=%d)\n", err);
 
 	dev_info(&pdev->dev, "Watchdog enabled (timeout=%d sec, nowayout=%d)",
 			sunxi_wdt->wdt_dev.timeout, nowayout);
@@ -218,7 +227,7 @@ static int sunxi_wdt_remove(struct platform_device *pdev)
 {
 	struct sunxi_wdt_dev *sunxi_wdt = platform_get_drvdata(pdev);
 
-	arm_pm_restart = NULL;
+	unregister_restart_handler(&sunxi_wdt->restart_handler);
 
 	watchdog_unregister_device(&sunxi_wdt->wdt_dev);
 	watchdog_set_drvdata(&sunxi_wdt->wdt_dev, NULL);
Signature · 1 line
1.9.1
author maintainer
#20 lore raw

PATCH v7 8/11 arm/arm64: Unexport restart handlers

In reply to Guenter Roeck

Implementing a restart handler in a module don't make sense as there would be no guarantee that the module is loaded when a restart is needed. Unexport arm_pm_restart to ensure that no one gets the idea to do it anyway.

---
v7: No change
v6: No change
v5: No change
v4: No change
v3: No change
v2: No change

 arch/arm/kernel/process.c   | 1 -
 arch/arm64/kernel/process.c | 1 -
 2 files changed, 2 deletions(-)
arch/arm/kernel/process.c +0 -1
index ea279f7..250b6f6 100644
@@ -121,7 +121,6 @@ void (*pm_power_off)(void);
 EXPORT_SYMBOL(pm_power_off);
 
 void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
-EXPORT_SYMBOL_GPL(arm_pm_restart);
 
 /*
  * This is our default idle handler.
arch/arm64/kernel/process.c +0 -1
index 0d3fb9f..398ab05 100644
@@ -98,7 +98,6 @@ void (*pm_power_off)(void);
 EXPORT_SYMBOL_GPL(pm_power_off);
 
 void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
-EXPORT_SYMBOL_GPL(arm_pm_restart);
 
 /*
  * This is our default idle handler.
Signature · 1 line
1.9.1
author maintainer
#28 lore raw

PATCH v7 9/11 watchdog: s3c2410: add restart handler

In reply to Guenter Roeck

From: Heiko St?bner <[email protected]>

On a lot of Samsung systems the watchdog is responsible for restarting the system and until now this code was contained in plat-samsung/watchdog-reset.c.

With the introduction of the restart handlers, this code can now move into driver itself, removing the need for arch-specific code.

Tested on a S3C2442 based GTA02

---
v7: Added patch to series.

 drivers/watchdog/s3c2410_wdt.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/watchdog/s3c2410_wdt.c +36 -0
index 7c6ccd0..2955aef 100644
@@ -41,6 +41,8 @@
 #include <linux/of.h>
 #include <linux/mfd/syscon.h>
 #include <linux/regmap.h>
+#include <linux/reboot.h>
+#include <linux/delay.h>
 
 #define S3C2410_WTCON		0x00
 #define S3C2410_WTDAT		0x04
@@ -128,6 +130,7 @@ struct s3c2410_wdt {
 	unsigned long		wtdat_save;
 	struct watchdog_device	wdt_device;
 	struct notifier_block	freq_transition;
+	struct notifier_block	restart_handler;
 	struct s3c2410_wdt_variant *drv_data;
 	struct regmap *pmureg;
 };
@@ -438,6 +441,31 @@ static inline void s3c2410wdt_cpufreq_deregister(struct s3c2410_wdt *wdt)
 }
 #endif
 
+static int s3c2410wdt_restart(struct notifier_block *this,
+			      unsigned long mode, void *cmd)
+{
+	struct s3c2410_wdt *wdt = container_of(this, struct s3c2410_wdt,
+					       restart_handler);
+	void __iomem *wdt_base = wdt->reg_base;
+
+	/* disable watchdog, to be safe  */
+	writel(0, wdt_base + S3C2410_WTCON);
+
+	/* put initial values into count and data */
+	writel(0x80, wdt_base + S3C2410_WTCNT);
+	writel(0x80, wdt_base + S3C2410_WTDAT);
+
+	/* set the watchdog to go and reset... */
+	writel(S3C2410_WTCON_ENABLE | S3C2410_WTCON_DIV16 |
+		S3C2410_WTCON_RSTEN | S3C2410_WTCON_PRESCALE(0x20),
+		wdt_base + S3C2410_WTCON);
+
+	/* wait for reset to assert... */
+	mdelay(500);
+
+	return NOTIFY_DONE;
+}
+
 static inline unsigned int s3c2410wdt_get_bootstatus(struct s3c2410_wdt *wdt)
 {
 	unsigned int rst_stat;
@@ -592,6 +620,12 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, wdt);
 
+	wdt->restart_handler.notifier_call = s3c2410wdt_restart;
+	wdt->restart_handler.priority = 128;
+	ret = register_restart_handler(&wdt->restart_handler);
+	if (ret)
+		pr_err("cannot register restart handler, %d\n", ret);
+
 	/* print out a statement of readiness */
 
 	wtcon = readl(wdt->reg_base + S3C2410_WTCON);
@@ -621,6 +655,8 @@ static int s3c2410wdt_remove(struct platform_device *dev)
 	int ret;
 	struct s3c2410_wdt *wdt = platform_get_drvdata(dev);
 
+	unregister_restart_handler(&wdt->restart_handler);
+
 	ret = s3c2410wdt_mask_and_disable_reset(wdt, true);
 	if (ret < 0)
 		return ret;
Signature · 1 line
1.9.1
author maintainer
#29 lore raw

PATCH v7 10/11 clk: samsung: register restart handlers for s3c2412 and s3c2443

In reply to Guenter Roeck

From: Heiko St?bner <[email protected]>

S3C2412, S3C2443 and their derivatives contain a special software-reset register in their system-controller.

Therefore register a restart handler for those.

Tested on a s3c2416-based board, s3c2412 compile-tested.

---
v7: Added patch to series.

 drivers/clk/samsung/clk-s3c2412.c | 29 +++++++++++++++++++++++++++++
 drivers/clk/samsung/clk-s3c2443.c | 19 +++++++++++++++++++
 2 files changed, 48 insertions(+)
drivers/clk/samsung/clk-s3c2412.c +29 -0
index 34af09f..2ceedaf 100644
@@ -14,6 +14,7 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/syscore_ops.h>
+#include <linux/reboot.h>
 
 #include <dt-bindings/clock/s3c2412.h>
 
@@ -26,6 +27,7 @@
 #define CLKCON		0x0c
 #define CLKDIVN		0x14
 #define CLKSRC		0x1c
+#define SWRST		0x30
 
 /* list of PLLs to be registered */
 enum s3c2412_plls {
@@ -204,6 +206,28 @@ struct samsung_clock_alias s3c2412_aliases[] __initdata = {
 	ALIAS(MSYSCLK, NULL, "fclk"),
 };
 
+static int s3c2412_restart(struct notifier_block *this,
+			   unsigned long mode, void *cmd)
+{
+	/* errata "Watch-dog/Software Reset Problem" specifies that
+	 * this reset must be done with the SYSCLK sourced from
+	 * EXTCLK instead of FOUT to avoid a glitch in the reset
+	 * mechanism.
+	 *
+	 * See the watchdog section of the S3C2412 manual for more
+	 * information on this fix.
+	 */
+
+	__raw_writel(0x00, reg_base + CLKSRC);
+	__raw_writel(0x533C2412, reg_base + SWRST);
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block s3c2412_restart_handler = {
+	.notifier_call = s3c2412_restart,
+	.priority = 129,
+};
+
 /*
  * fixed rate clocks generated outside the soc
  * Only necessary until the devicetree-move is complete
@@ -233,6 +257,7 @@ void __init s3c2412_common_clk_init(struct device_node *np, unsigned long xti_f,
 				    unsigned long ext_f, void __iomem *base)
 {
 	struct samsung_clk_provider *ctx;
+	int ret;
 	reg_base = base;
 
 	if (np) {
@@ -267,6 +292,10 @@ void __init s3c2412_common_clk_init(struct device_node *np, unsigned long xti_f,
 	s3c2412_clk_sleep_init();
 
 	samsung_clk_of_add_provider(np, ctx);
+
+	ret = register_restart_handler(&s3c2412_restart_handler);
+	if (ret)
+		pr_warn("cannot register restart handler, %d\n", ret);
 }
 
 static void __init s3c2412_clk_init(struct device_node *np)
drivers/clk/samsung/clk-s3c2443.c +19 -0
index c92f853..0c3c182 100644
@@ -14,6 +14,7 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/syscore_ops.h>
+#include <linux/reboot.h>
 
 #include <dt-bindings/clock/s3c2443.h>
 
@@ -33,6 +34,7 @@
 #define HCLKCON		0x30
 #define PCLKCON		0x34
 #define SCLKCON		0x38
+#define SWRST		0x44
 
 /* the soc types */
 enum supported_socs {
@@ -354,6 +356,18 @@ struct samsung_clock_alias s3c2450_aliases[] __initdata = {
 	ALIAS(PCLK_I2C1, "s3c2410-i2c.1", "i2c"),
 };
 
+static int s3c2443_restart(struct notifier_block *this,
+			   unsigned long mode, void *cmd)
+{
+	__raw_writel(0x533c2443, reg_base + SWRST);
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block s3c2443_restart_handler = {
+	.notifier_call = s3c2443_restart,
+	.priority = 129,
+};
+
 /*
  * fixed rate clocks generated outside the soc
  * Only necessary until the devicetree-move is complete
@@ -378,6 +392,7 @@ void __init s3c2443_common_clk_init(struct device_node *np, unsigned long xti_f,
 				    void __iomem *base)
 {
 	struct samsung_clk_provider *ctx;
+	int ret;
 	reg_base = base;
 
 	if (np) {
@@ -447,6 +462,10 @@ void __init s3c2443_common_clk_init(struct device_node *np, unsigned long xti_f,
 	s3c2443_clk_sleep_init();
 
 	samsung_clk_of_add_provider(np, ctx);
+
+	ret = register_restart_handler(&s3c2443_restart_handler);
+	if (ret)
+		pr_warn("cannot register restart handler, %d\n", ret);
 }
 
 static void __init s3c2416_clk_init(struct device_node *np)
Signature · 1 line
1.9.1
author maintainer
#31 lore raw

PATCH v7 11/11 clk: rockchip: add restart handler

In reply to Guenter Roeck

From: Heiko St?bner <[email protected]>

Add infrastructure to write the correct value to the restart register and register the restart notifier for both rk3188 (including rk3066) and rk3288.

---
v7: Added patch to series.

 drivers/clk/rockchip/clk-rk3188.c |  2 ++
 drivers/clk/rockchip/clk-rk3288.c |  2 ++
 drivers/clk/rockchip/clk.c        | 25 +++++++++++++++++++++++++
 drivers/clk/rockchip/clk.h        |  1 +
 4 files changed, 30 insertions(+)
drivers/clk/rockchip/clk-rk3188.c +2 -0
index a83a6d8..71b661a 100644
@@ -631,6 +631,8 @@ static void __init rk3188_common_clk_init(struct device_node *np)
 
 	rockchip_register_softrst(np, 9, reg_base + RK2928_SOFTRST_CON(0),
 				  ROCKCHIP_SOFTRST_HIWORD_MASK);
+
+	rockchip_register_restart_notifier(RK2928_GLB_SRST_FST);
 }
 
 static void __init rk3066a_clk_init(struct device_node *np)
drivers/clk/rockchip/clk-rk3288.c +2 -0
index 0d8c6c5..b604217 100644
@@ -713,5 +713,7 @@ static void __init rk3288_clk_init(struct device_node *np)
 
 	rockchip_register_softrst(np, 9, reg_base + RK3288_SOFTRST_CON(0),
 				  ROCKCHIP_SOFTRST_HIWORD_MASK);
+
+	rockchip_register_restart_notifier(RK3288_GLB_SRST_FST);
 }
 CLK_OF_DECLARE(rk3288_cru, "rockchip,rk3288-cru", rk3288_clk_init);
drivers/clk/rockchip/clk.c +25 -0
index 278cf9d..aa41433 100644
@@ -25,6 +25,7 @@
 #include <linux/clk-provider.h>
 #include <linux/mfd/syscon.h>
 #include <linux/regmap.h>
+#include <linux/reboot.h>
 #include "clk.h"
 
 /**
@@ -242,3 +243,27 @@ void __init rockchip_clk_register_branches(
 		rockchip_clk_add_lookup(clk, list->id);
 	}
 }
+
+static unsigned int reg_restart;
+static int rockchip_restart_notify(struct notifier_block *this,
+				   unsigned long mode, void *cmd)
+{
+	writel(0xfdb9, reg_base + reg_restart);
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block rockchip_restart_handler = {
+	.notifier_call = rockchip_restart_notify,
+	.priority = 128,
+};
+
+void __init rockchip_register_restart_notifier(unsigned int reg)
+{
+	int ret;
+
+	reg_restart = reg;
+	ret = register_restart_handler(&rockchip_restart_handler);
+	if (ret)
+		pr_err("%s: cannot register restart handler, %d\n",
+		       __func__, ret);
+}
drivers/clk/rockchip/clk.h +1 -0
index 887cbde..0b5eab5 100644
@@ -329,6 +329,7 @@ void rockchip_clk_register_branches(struct rockchip_clk_branch *clk_list,
 				    unsigned int nr_clk);
 void rockchip_clk_register_plls(struct rockchip_pll_clock *pll_list,
 				unsigned int nr_pll, int grf_lock_offset);
+void rockchip_register_restart_notifier(unsigned int reg);
 
 #define ROCKCHIP_SOFTRST_HIWORD_MASK	BIT(0)
 
Signature · 1 line
1.9.1
Reviewed-by Tested-by on v7 1/11
#2 lore raw

Re: [PATCH v7 01/11] kernel: Add support for kernel restart handler call chain

In reply to Guenter Roeck

Guenter,

Quoted 46 lines · Guenter Roeck

Various drivers implement architecture and/or device specific means to restart (reset) the system. Various mechanisms have been implemented to support those schemes. The best known mechanism is arm_pm_restart, which is a function pointer to be set either from platform specific code or from drivers. Another mechanism is to use hardware watchdogs to issue a reset; this mechanism is used if there is no other method available to reset a board or system. Two examples are alim7101_wdt, which currently uses the reboot notifier to trigger a reset, and moxart_wdt, which registers the arm_pm_restart function.

The existing mechanisms have a number of drawbacks. Typically only one scheme to restart the system is supported (at least if arm_pm_restart is used). At least in theory there can be multiple means to restart the system, some of which may be less desirable (for example one mechanism may only reset the CPU, while another may reset the entire system). Using arm_pm_restart can also be racy if the function pointer is set from a driver, as the driver may be in the process of being unloaded when arm_pm_restart is called. Using the reboot notifier is always racy, as it is unknown if and when other functions using the reboot notifier have completed execution by the time the watchdog fires.

Introduce a system restart handler call chain to solve the described problems. This call chain is expected to be executed from the architecture specific machine_restart() function. Drivers providing system restart functionality (such as the watchdog drivers mentioned above) are expected to register with this call chain. By using the priority field in the notifier block, callers can control restart handler execution sequence and thus ensure that the restart handler with the optimal restart capabilities for a given system is called first.

---
v7: Rebased to v3.17-rc1
v6: Use atomic notifier call chain
v5: Function renames:

    register_restart_notifier -> register_restart_handler
    unregister_restart_notifier -> unregister_restart_handler
    kernel_restart_notify -> do_kernel_restart

v4: Document and suggest values for notifier priorities
v3: Add kernel_restart_notify wrapper function to execute notifier.
Improve documentation.
Move restart_notifier_list into kernel/reboot.c and make it static.
v2: No change.

Quoted 3 lines
 include/linux/reboot.h |  3 ++
 kernel/reboot.c        | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)
Reviewed-by Tested-by on v7 2/11
#4 lore raw

Re: [PATCH v7 02/11] power/restart: Call machine_restart instead of arm_pm_restart

In reply to Guenter Roeck

Guenter,

Quoted 5 lines · Guenter Roeck

machine_restart is supported on non-ARM platforms, and and ultimately calls arm_pm_restart, so dont call arm_pm_restart directly but use the more generic function.

Cc Russell King <[email protected]>

Do you need to submit this to his patch tracker to get him to pick it up? How are you envisioning that this series land? It crosses a lot of boundaries so I guess will need a reasonable amount of coordination between maintainers...

Quoted 11 lines

---
v7: No change.
v6: No change.
v5: No change.
v4: No change.
v3: No change.
v2: Added patch.

Quoted 2 lines
 drivers/power/reset/restart-poweroff.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Reviewed-by Tested-by on v7 4/11
#13 lore raw

Re: [PATCH v7 04/11] arm: Support restart through restart handler call chain

In reply to Guenter Roeck

Guenter,

Quoted 19 lines · Guenter Roeck

The kernel core now supports a restart handler call chain for system restart functions.

With this change, the arm_pm_restart callback is now optional, so drop its initialization and check if it is set before calling it. Only call the kernel restart handler if arm_pm_restart is not set.

---
v7: Dropped null_restart and made arm_pm_restart truly optional.
v6: No change.
v5: Renamed restart function to do_kernel_restart
v4: No change.
v3: Use wrapper function to execute notifier call chain.
v2: Only call notifier call chain if arm_pm_restart is not set.
Do not include linux/watchdog.h.

Quoted 2 lines
 arch/arm/kernel/process.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
Reviewed-by Tested-by on v7 8/11
#21 lore raw

Re: [PATCH v7 08/11] arm/arm64: Unexport restart handlers

In reply to Guenter Roeck

Guenter,

Quoted 16 lines · Guenter Roeck

Implementing a restart handler in a module don't make sense as there would be no guarantee that the module is loaded when a restart is needed. Unexport arm_pm_restart to ensure that no one gets the idea to do it anyway.

---
v7: No change
v6: No change
v5: No change
v4: No change
v3: No change
v2: No change

Quoted 3 lines
 arch/arm/kernel/process.c   | 1 -
 arch/arm64/kernel/process.c | 1 -
 2 files changed, 2 deletions(-)

(FYI: all patches tested by me were tested on rk3288-evb)

Reviewed-by on v7 3/11
#11 lore raw

Re: [PATCH v7 03/11] arm64: Support restart through restart handler call chain

In reply to Guenter Roeck

Guenter,

Quoted 15 lines · Guenter Roeck

The kernel core now supports a restart handler call chain to restart the system. Call it if arm_pm_restart is not set.

---
v7: No change.
v6: No change.
v5: Renamed restart function to do_kernel_restart
v4: No change.
v3: Use wrapper function to execute notifier call chain.
v2: Only call notifier call chain if arm_pm_restart is not set.
Do not include linux/watchdog.h.

Quoted 2 lines
 arch/arm64/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
Reviewed-by Tested-by on v7 11/11
#32 lore raw

Re: [PATCH v7 11/11] clk: rockchip: add restart handler

In reply to Guenter Roeck

Guenter / Heiko,

Quoted 7 lines · Guenter Roeck

From: Heiko St?bner <[email protected]>

Add infrastructure to write the correct value to the restart register and register the restart notifier for both rk3188 (including rk3066) and rk3288.

Quoted 8 lines

---
v7: Added patch to series.

 drivers/clk/rockchip/clk-rk3188.c |  2 ++
 drivers/clk/rockchip/clk-rk3288.c |  2 ++
 drivers/clk/rockchip/clk.c        | 25 +++++++++++++++++++++++++
 drivers/clk/rockchip/clk.h        |  1 +
 4 files changed, 30 insertions(+)

This patch doesn't apply cleanly with the in-flight (clk: rockchip:
protect critical clocks from getting disabled) patch from Heiko. It's trivial to resolve and unclear which will land first, so I think it's fine...

(FYI: all patches tested by me were tested on rk3288-evb)

author maintainer
#5 lore raw

Re: [PATCH v7 02/11] power/restart: Call machine_restart instead of arm_pm_restart

In reply to Doug Anderson
Quoted 7 lines · Doug Anderson

Guenter,

Quoted 4 lines · Guenter Roeck

machine_restart is supported on non-ARM platforms, and and ultimately calls arm_pm_restart, so dont call arm_pm_restart directly but use the more generic function.

Quoted 8 lines
Quoted 1 line
Cc Russell King <[email protected]>

Do you need to submit this to his patch tracker to get him to pick it up? How are you envisioning that this series land? It crosses a lot of boundaries so I guess will need a reasonable amount of coordination between maintainers...

If I get an Acked-by: from all maintainers, I could send a pull request to Linus directly. How do I send a patch to Russell's patch tracker ? I thought I copied all mailing lists suggested by get_maintainer.pl, but maybe I missed one.

Thanks,
Guenter

maintainer
#33 lore raw

Re: [PATCH v7 11/11] clk: rockchip: add restart handler

In reply to Doug Anderson

Am Mittwoch, 20. August 2014, 21:15:10 schrieb Doug Anderson:

Quoted 20 lines

Guenter / Heiko,

Quoted 8 lines · Guenter Roeck

From: Heiko St?bner <[email protected]>

Add infrastructure to write the correct value to the restart register and register the restart notifier for both rk3188 (including rk3066) and rk3288.

Quoted 8 lines

---
v7: Added patch to series.

 drivers/clk/rockchip/clk-rk3188.c |  2 ++
 drivers/clk/rockchip/clk-rk3288.c |  2 ++
 drivers/clk/rockchip/clk.c        | 25 +++++++++++++++++++++++++
 drivers/clk/rockchip/clk.h        |  1 +
 4 files changed, 30 insertions(+)
Quoted 4 lines

This patch doesn't apply cleanly with the in-flight (clk: rockchip:
protect critical clocks from getting disabled) patch from Heiko. It's trivial to resolve and unclear which will land first, so I think it's fine...

This should be expected :-) .

The patch about critical clocks will (hopefully soon) go through Mike's tree, while this series will most likely go through somewhere else (Linus' tree directly or something), so I guess the merge conflic will be resolved by Linus when both trees meet each other during the merge window.
So both this patch as well as the other one should stay independent of each other.

Heiko

#6 lore raw

Re: [PATCH v7 02/11] power/restart: Call machine_restart instead of arm_pm_restart

In reply to Guenter Roeck

Guenter,

Quoted 16 lines · Guenter Roeck
Quoted 7 lines · Doug Anderson

Guenter,

Quoted 4 lines · Guenter Roeck

machine_restart is supported on non-ARM platforms, and and ultimately calls arm_pm_restart, so dont call arm_pm_restart directly but use the more generic function.

Quoted 8 lines
Quoted 1 line
Cc Russell King <[email protected]>

Do you need to submit this to his patch tracker to get him to pick it up? How are you envisioning that this series land? It crosses a lot of boundaries so I guess will need a reasonable amount of coordination between maintainers...

Quoted 4 lines

If I get an Acked-by: from all maintainers, I could send a pull request to Linus directly. How do I send a patch to Russell's patch tracker ? I thought I copied all mailing lists suggested by get_maintainer.pl, but maybe I missed one.

Ah, OK. Perhaps it's best to ignore me, then. ;) FYI: Russell's Patch System is at <http://www.arm.linux.org.uk/developer/patches/>
and is used for getting individual patches into branches maintained by Russel. If you're just going to send a pull request for the series then I don't think you need it.

author maintainer
#7 lore raw

Re: [PATCH v7 02/11] power/restart: Call machine_restart instead of arm_pm_restart

Quoted 19 lines · Doug Anderson

Guenter,

Quoted 16 lines · Guenter Roeck
Quoted 15 lines · Doug Anderson

Guenter,

Quoted 5 lines · Guenter Roeck

machine_restart is supported on non-ARM platforms, and and ultimately calls arm_pm_restart, so dont call arm_pm_restart directly but use the more generic function.

Cc Russell King <[email protected]>

Do you need to submit this to his patch tracker to get him to pick it up? How are you envisioning that this series land? It crosses a lot of boundaries so I guess will need a reasonable amount of coordination between maintainers...

Quoted 6 lines
Quoted 4 lines

If I get an Acked-by: from all maintainers, I could send a pull request to Linus directly. How do I send a patch to Russell's patch tracker ? I thought I copied all mailing lists suggested by get_maintainer.pl, but maybe I missed one.

Ah, OK. Perhaps it's best to ignore me, then. ;) FYI: Russell's

No, I appreciate the information.

Quoted 5 lines

Patch System is at <http://www.arm.linux.org.uk/developer/patches/>
and is used for getting individual patches into branches maintained by Russel. If you're just going to send a pull request for the series then I don't think you need it.

I copied both linux-arm-kernel and Russell himself, so hopefully he is aware of the series and can let me know if he wants me to make any further changes to it, if it is ready to go, or if I need to do anything else.

Thanks,
Guenter

maintainer Acked-by on v7 2/11
#8 lore raw

Re: [PATCH v7 02/11] power/restart: Call machine_restart instead of arm_pm_restart

In reply to Guenter Roeck

Hi,

Quoted 8 lines · Guenter Roeck

machine_restart is supported on non-ARM platforms, and and ultimately calls arm_pm_restart, so dont call arm_pm_restart directly but use the more generic function.

Do you want me to take the patch via battery-2.6.git?

-- Sebastian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140821/9a65832c/attachment.sig>

#14 lore raw

Re: [PATCH v7 04/11] arm: Support restart through restart handler call chain

In reply to Guenter Roeck

Hi,

Am 20.08.2014 02:45, schrieb Guenter Roeck:

Quoted 6 lines

The kernel core now supports a restart handler call chain for system restart functions.

With this change, the arm_pm_restart callback is now optional, so drop its initialization and check if it is set before calling it. Only call the kernel restart handler if arm_pm_restart is not set.

[...]

Quoted 10 lines
arch/arm/kernel/process.c +0 -2
index 81ef686..ea279f7 100644
@@ -114,17 +114,13 @@ void soft_restart(unsigned long addr)
 	BUG();
 }
 
-static void null_restart(enum reboot_mode reboot_mode, const char *cmd)
-{

arch/arm/kernel/process.c void soft_restart(unsigned long addr) · line 123

Quoted 10 lines
arch/arm/kernel/process.c +1 -3
-}
-
 /*
  * Function pointers to optional machine specific functions
  */
 void (*pm_power_off)(void);
 EXPORT_SYMBOL(pm_power_off);
 
-void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd) = null_restart;
+void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);

Stupid newbie question maybe, but isn't this variable uninitialized now, like any non-static variable in C99? Or does the kernel assure that all such "fields" are zero-initialized?

arch/arm/kernel/process.c void soft_restart(unsigned long addr) · line 124

Quoted 1 line
arch/arm/kernel/process.c +0 -0
 EXPORT_SYMBOL_GPL(arm_pm_restart);

(This doesn't seem to be affecting the value of arm_pm_restart, just redeclaring it extern and adding further derived symbols.)

arch/arm/kernel/process.c void machine_restart(char *cmd) · line 229

Quoted 8 lines
arch/arm/kernel/process.c +1 -1
 /*
@@ -230,7 +226,10 @@ void machine_restart(char *cmd)
 	local_irq_disable();
 	smp_send_stop();
 
-	arm_pm_restart(reboot_mode, cmd);
+	if (arm_pm_restart)

Here we seem to be relying on arm_pm_restart to be NULL when not callable. I.e., wondering whether it's ruled out that the following line is triggered due to non-zero garbage in arm_pm_restart?

Thanks,
Andreas

Quoted 6 lines
arch/arm/kernel/process.c +3 -0
+		arm_pm_restart(reboot_mode, cmd);
+	else
+		do_kernel_restart(cmd);
 
 	/* Give a grace period for failure to restart of 1s */
 	mdelay(1000);
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imend?rffer; HRB 16746 AG N?rnberg
author maintainer
#15 lore raw

Re: [PATCH v7 04/11] arm: Support restart through restart handler call chain

Quoted 28 lines · Andreas F?rber

Hi,

Am 20.08.2014 02:45, schrieb Guenter Roeck:

Quoted 6 lines

The kernel core now supports a restart handler call chain for system restart functions.

With this change, the arm_pm_restart callback is now optional, so drop its initialization and check if it is set before calling it. Only call the kernel restart handler if arm_pm_restart is not set.

[...]

Quoted 18 lines
arch/arm/kernel/process.c +0 -4
index 81ef686..ea279f7 100644
@@ -114,17 +114,13 @@ void soft_restart(unsigned long addr)
 	BUG();
 }
 
-static void null_restart(enum reboot_mode reboot_mode, const char *cmd)
-{
-}
-
 /*
  * Function pointers to optional machine specific functions
  */
 void (*pm_power_off)(void);
 EXPORT_SYMBOL(pm_power_off);
 
Quoted 7 lines

arch/arm/kernel/process.c void soft_restart(unsigned long addr) · line 123

Quoted 2 lines
arch/arm/kernel/process.c +1 -1
-void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd) = null_restart;
+void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);

Stupid newbie question maybe, but isn't this variable uninitialized now, like any non-static variable in C99? Or does the kernel assure that all such "fields" are zero-initialized?

It is initialized with NULL, like all other global and static variables in the kernel (and like pm_power_off a few lines above).

Guenter

author maintainer
#35 lore raw

v7 cover kernel: Add support for restart handler call chain

In reply to Guenter Roeck
Quoted 48 lines · Guenter Roeck

Various drivers implement architecture and/or device specific means to restart (reset) the system. Various mechanisms have been implemented to support those schemes. The best known mechanism is arm_pm_restart, which is a function pointer to be set either from platform specific code or from drivers. Another mechanism is to use hardware watchdogs to issue a reset; this mechanism is used if there is no other method available to reset a board or system. Two examples are alim7101_wdt, which currently uses the reboot notifier to trigger a reset, and moxart_wdt, which registers the arm_pm_restart function. Several other restart drivers for arm, all directly calling arm_pm_restart, are in the process of being integrated into the kernel. All those drivers would benefit from the new API.

The existing mechanisms have a number of drawbacks. Typically only one scheme to restart the system is supported (at least if arm_pm_restart is used). At least in theory there can be multiple means to restart the system, some of which may be less desirable (for example one mechanism may only reset the CPU, while another may reset the entire system). Using arm_pm_restart can also be racy if the function pointer is set from a driver, as the driver may be in the process of being unloaded when arm_pm_restart is called. Using the reboot notifier is always racy, as it is unknown if and when other functions using the reboot notifier have completed execution by the time the watchdog fires.

Introduce a system restart handler call chain to solve the described problems. This call chain is expected to be executed from the architecture specific machine_restart() function. Drivers providing system restart functionality (such as the watchdog drivers mentioned above) are expected to register with this call chain. By using the priority field in the notifier block, callers can control restart handler execution sequence and thus ensure that the restart handler with the optimal restart capabilities for a given system is called first.

Since the first revision of this patchset, a number of separate patch submissions have been made which either depend on it or could make use of it.

http://www.spinics.net/linux/lists/arm-kernel/msg344796.html
registers three notifiers.
https://lkml.org/lkml/2014/7/8/962
would benefit from it.

Patch 1 of this series implements the restart handler function. Patches 2 and 3 implement calling the restart handler chain from arm and arm64 restart code.

Patch 4 modifies the restart-poweroff driver to no longer call arm_pm_restart directly but machine_restart. This is done to avoid calling arm_pm_restart from more than one place. The change makes the driver architecture independent, so it would be possible to drop the arm dependency from its Kconfig entry.

Quoted 9 lines

Patch 5 and 6 convert existing restart handlers in the watchdog subsystem to use the restart handler. Patch 7 unexports arm_pm_restart to ensure that no one gets the idea to implement a restart handler as module.

The entire patch series, including additional patches depending on it, is available from
https://git.kernel.org/cgit/linux/kernel/git/groeck/linux-staging.git/
in branch 'restart-staging'.

Hi Andrew,

I think this series is ready for upstream integration. Question now is how we should proceed to get it actually integrated.

I can see a number of options:
- You take patch #1, the rest goes in through maintainer trees.
- You take all patches after we get missing maintainer Acks.
- I send a pull request directly to Linus after we get missing maintainer Acks.

What do you think would be the best way to proceed ?

Thanks,
Guenter

Reviewed-by
#16 lore raw

Re: [PATCH v7 04/11] arm: Support restart through restart handler call chain

In reply to Guenter Roeck

Am 22.08.2014 04:19, schrieb Guenter Roeck:

Quoted 34 lines · Andreas F?rber
Quoted 26 lines

Am 20.08.2014 02:45, schrieb Guenter Roeck:

Quoted 6 lines

The kernel core now supports a restart handler call chain for system restart functions.

With this change, the arm_pm_restart callback is now optional, so drop its initialization and check if it is set before calling it. Only call the kernel restart handler if arm_pm_restart is not set.

[...]

Quoted 18 lines
arch/arm/kernel/process.c +0 -4
index 81ef686..ea279f7 100644
@@ -114,17 +114,13 @@ void soft_restart(unsigned long addr)
 	BUG();
 }
 
-static void null_restart(enum reboot_mode reboot_mode, const char *cmd)
-{
-}
-
 /*
  * Function pointers to optional machine specific functions
  */
 void (*pm_power_off)(void);
 EXPORT_SYMBOL(pm_power_off);
 
Quoted 7 lines

arch/arm/kernel/process.c void soft_restart(unsigned long addr) · line 123

Quoted 2 lines
arch/arm/kernel/process.c +1 -1
-void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd) = null_restart;
+void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);

Stupid newbie question maybe, but isn't this variable uninitialized now, like any non-static variable in C99? Or does the kernel assure that all such "fields" are zero-initialized?

Quoted 2 lines

It is initialized with NULL, like all other global and static variables in the kernel (and like pm_power_off a few lines above).

Thanks for the explanation. In that case FWIW

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N?rnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imend?rffer; HRB 16746 AG N?rnberg
author maintainer
#9 lore raw

Re: [PATCH v7 02/11] power/restart: Call machine_restart instead of arm_pm_restart

In reply to Sebastian Reichel
Quoted 7 lines · Sebastian Reichel

Hi,

Quoted 4 lines · Guenter Roeck

machine_restart is supported on non-ARM platforms, and and ultimately calls arm_pm_restart, so dont call arm_pm_restart directly but use the more generic function.

Quoted 9 lines
Quoted 4 lines

Do you want me to take the patch via battery-2.6.git?

Hi Sebastian,

thanks a lot for the Ack. I am not sure if it is better to submit all patches together or through individual maintainer trees. Let's wait for Andrew's suggestion how we should proceed.

Thanks,
Guenter

maintainer
#36 lore raw

v7 cover kernel: Add support for restart handler call chain

In reply to Guenter Roeck

Am Samstag, 23. August 2014, 09:35:05 schrieb Guenter Roeck:

Quoted 66 lines · Guenter Roeck
Quoted 56 lines

Various drivers implement architecture and/or device specific means to restart (reset) the system. Various mechanisms have been implemented to support those schemes. The best known mechanism is arm_pm_restart, which is a function pointer to be set either from platform specific code or from drivers. Another mechanism is to use hardware watchdogs to issue a reset; this mechanism is used if there is no other method available to reset a board or system. Two examples are alim7101_wdt, which currently uses the reboot notifier to trigger a reset, and moxart_wdt, which registers the arm_pm_restart function. Several other restart drivers for arm, all directly calling arm_pm_restart, are in the process of being integrated into the kernel. All those drivers would benefit from the new API.

The existing mechanisms have a number of drawbacks. Typically only one scheme to restart the system is supported (at least if arm_pm_restart is used). At least in theory there can be multiple means to restart the system, some of which may be less desirable (for example one mechanism may only reset the CPU, while another may reset the entire system). Using arm_pm_restart can also be racy if the function pointer is set from a driver, as the driver may be in the process of being unloaded when arm_pm_restart is called.
Using the reboot notifier is always racy, as it is unknown if and when other functions using the reboot notifier have completed execution by the time the watchdog fires.

Introduce a system restart handler call chain to solve the described problems. This call chain is expected to be executed from the architecture specific machine_restart() function. Drivers providing system restart functionality (such as the watchdog drivers mentioned above) are expected to register with this call chain. By using the priority field in the notifier block, callers can control restart handler execution sequence and thus ensure that the restart handler with the optimal restart capabilities for a given system is called first.

Since the first revision of this patchset, a number of separate patch submissions have been made which either depend on it or could make use of it.

http://www.spinics.net/linux/lists/arm-kernel/msg344796.html

registers three notifiers.

https://lkml.org/lkml/2014/7/8/962

would benefit from it.

Patch 1 of this series implements the restart handler function. Patches 2 and 3 implement calling the restart handler chain from arm and arm64 restart code.

Patch 4 modifies the restart-poweroff driver to no longer call arm_pm_restart directly but machine_restart. This is done to avoid calling arm_pm_restart from more than one place. The change makes the driver architecture independent, so it would be possible to drop the arm dependency from its Kconfig entry.

Quoted 8 lines

Patch 5 and 6 convert existing restart handlers in the watchdog subsystem to use the restart handler. Patch 7 unexports arm_pm_restart to ensure that no one gets the idea to implement a restart handler as module.

The entire patch series, including additional patches depending on it, is available from
https://git.kernel.org/cgit/linux/kernel/git/groeck/linux-staging.git/
in branch 'restart-staging'.

Quoted 7 lines

Hi Andrew,

I think this series is ready for upstream integration. Question now is how we should proceed to get it actually integrated.

I can see a number of options:
- You take patch #1, the rest goes in through maintainer trees.

I don't think you can split the patches like this. Patch1 introduces (un)register_restart_handler functions used by later patches in the series. You therefore cannot really split the series, as otherwise you would get build failures in the individual trees.

Heiko

Quoted 8 lines

- You take all patches after we get missing maintainer Acks.
- I send a pull request directly to Linus after we get missing maintainer Acks.

What do you think would be the best way to proceed ?

Thanks,
Guenter

author maintainer
#37 lore raw

v7 cover kernel: Add support for restart handler call chain

Quoted 72 lines · Heiko St?bner

Am Samstag, 23. August 2014, 09:35:05 schrieb Guenter Roeck:

Quoted 71 lines · Guenter Roeck
Quoted 56 lines

Various drivers implement architecture and/or device specific means to restart (reset) the system. Various mechanisms have been implemented to support those schemes. The best known mechanism is arm_pm_restart, which is a function pointer to be set either from platform specific code or from drivers. Another mechanism is to use hardware watchdogs to issue a reset; this mechanism is used if there is no other method available to reset a board or system. Two examples are alim7101_wdt, which currently uses the reboot notifier to trigger a reset, and moxart_wdt, which registers the arm_pm_restart function. Several other restart drivers for arm, all directly calling arm_pm_restart, are in the process of being integrated into the kernel. All those drivers would benefit from the new API.

The existing mechanisms have a number of drawbacks. Typically only one scheme to restart the system is supported (at least if arm_pm_restart is used). At least in theory there can be multiple means to restart the system, some of which may be less desirable (for example one mechanism may only reset the CPU, while another may reset the entire system). Using arm_pm_restart can also be racy if the function pointer is set from a driver, as the driver may be in the process of being unloaded when arm_pm_restart is called.
Using the reboot notifier is always racy, as it is unknown if and when other functions using the reboot notifier have completed execution by the time the watchdog fires.

Introduce a system restart handler call chain to solve the described problems. This call chain is expected to be executed from the architecture specific machine_restart() function. Drivers providing system restart functionality (such as the watchdog drivers mentioned above) are expected to register with this call chain. By using the priority field in the notifier block, callers can control restart handler execution sequence and thus ensure that the restart handler with the optimal restart capabilities for a given system is called first.

Since the first revision of this patchset, a number of separate patch submissions have been made which either depend on it or could make use of it.

http://www.spinics.net/linux/lists/arm-kernel/msg344796.html

registers three notifiers.

https://lkml.org/lkml/2014/7/8/962

would benefit from it.

Patch 1 of this series implements the restart handler function. Patches 2 and 3 implement calling the restart handler chain from arm and arm64 restart code.

Patch 4 modifies the restart-poweroff driver to no longer call arm_pm_restart directly but machine_restart. This is done to avoid calling arm_pm_restart from more than one place. The change makes the driver architecture independent, so it would be possible to drop the arm dependency from its Kconfig entry.

Quoted 8 lines

Patch 5 and 6 convert existing restart handlers in the watchdog subsystem to use the restart handler. Patch 7 unexports arm_pm_restart to ensure that no one gets the idea to implement a restart handler as module.

The entire patch series, including additional patches depending on it, is available from
https://git.kernel.org/cgit/linux/kernel/git/groeck/linux-staging.git/
in branch 'restart-staging'.

Hi Andrew,

I think this series is ready for upstream integration. Question now is how we should proceed to get it actually integrated.

Quoted 8 lines
Quoted 2 lines

I can see a number of options:
- You take patch #1, the rest goes in through maintainer trees.

I don't think you can split the patches like this. Patch1 introduces (un)register_restart_handler functions used by later patches in the series. You therefore cannot really split the series, as otherwise you would get build failures in the individual trees.

No, it would simply delay integration of the entire series by a release or two. First two patches go in first, then #3 and #4, then the rest.

I don't like that option too much either, but it is better than nothing.

Guenter

Acked-by on v7 10/11
#30 lore raw

Re: [PATCH v7 10/11] clk: samsung: register restart handlers for s3c2412 and s3c2443

In reply to Guenter Roeck

Quoting Guenter Roeck (2014-08-19 17:45:37)

Quoted 11 lines

From: Heiko St?bner <[email protected]>

S3C2412, S3C2443 and their derivatives contain a special software-reset register in their system-controller.

Therefore register a restart handler for those.

Tested on a s3c2416-based board, s3c2412 compile-tested.

Quoted 141 lines

---
v7: Added patch to series.

 drivers/clk/samsung/clk-s3c2412.c | 29 +++++++++++++++++++++++++++++
 drivers/clk/samsung/clk-s3c2443.c | 19 +++++++++++++++++++
 2 files changed, 48 insertions(+)
drivers/clk/samsung/clk-s3c2412.c +29 -0
index 34af09f..2ceedaf 100644
@@ -14,6 +14,7 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/syscore_ops.h>
+#include <linux/reboot.h>
 
 #include <dt-bindings/clock/s3c2412.h>
 
@@ -26,6 +27,7 @@
 #define CLKCON         0x0c
 #define CLKDIVN                0x14
 #define CLKSRC         0x1c
+#define SWRST          0x30
 
 /* list of PLLs to be registered */
 enum s3c2412_plls {
@@ -204,6 +206,28 @@ struct samsung_clock_alias s3c2412_aliases[] __initdata = {
        ALIAS(MSYSCLK, NULL, "fclk"),
 };
 
+static int s3c2412_restart(struct notifier_block *this,
+                          unsigned long mode, void *cmd)
+{
+       /* errata "Watch-dog/Software Reset Problem" specifies that
+        * this reset must be done with the SYSCLK sourced from
+        * EXTCLK instead of FOUT to avoid a glitch in the reset
+        * mechanism.
+        *
+        * See the watchdog section of the S3C2412 manual for more
+        * information on this fix.
+        */
+
+       __raw_writel(0x00, reg_base + CLKSRC);
+       __raw_writel(0x533C2412, reg_base + SWRST);
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block s3c2412_restart_handler = {
+       .notifier_call = s3c2412_restart,
+       .priority = 129,
+};
+
 /*
  * fixed rate clocks generated outside the soc
  * Only necessary until the devicetree-move is complete
@@ -233,6 +257,7 @@ void __init s3c2412_common_clk_init(struct device_node *np, unsigned long xti_f,
                                    unsigned long ext_f, void __iomem *base)
 {
        struct samsung_clk_provider *ctx;
+       int ret;
        reg_base = base;
 
        if (np) {
@@ -267,6 +292,10 @@ void __init s3c2412_common_clk_init(struct device_node *np, unsigned long xti_f,
        s3c2412_clk_sleep_init();
 
        samsung_clk_of_add_provider(np, ctx);
+
+       ret = register_restart_handler(&s3c2412_restart_handler);
+       if (ret)
+               pr_warn("cannot register restart handler, %d\n", ret);
 }
 
 static void __init s3c2412_clk_init(struct device_node *np)
drivers/clk/samsung/clk-s3c2443.c +19 -0
index c92f853..0c3c182 100644
@@ -14,6 +14,7 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/syscore_ops.h>
+#include <linux/reboot.h>
 
 #include <dt-bindings/clock/s3c2443.h>
 
@@ -33,6 +34,7 @@
 #define HCLKCON                0x30
 #define PCLKCON                0x34
 #define SCLKCON                0x38
+#define SWRST          0x44
 
 /* the soc types */
 enum supported_socs {
@@ -354,6 +356,18 @@ struct samsung_clock_alias s3c2450_aliases[] __initdata = {
        ALIAS(PCLK_I2C1, "s3c2410-i2c.1", "i2c"),
 };
 
+static int s3c2443_restart(struct notifier_block *this,
+                          unsigned long mode, void *cmd)
+{
+       __raw_writel(0x533c2443, reg_base + SWRST);
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block s3c2443_restart_handler = {
+       .notifier_call = s3c2443_restart,
+       .priority = 129,
+};
+
 /*
  * fixed rate clocks generated outside the soc
  * Only necessary until the devicetree-move is complete
@@ -378,6 +392,7 @@ void __init s3c2443_common_clk_init(struct device_node *np, unsigned long xti_f,
                                    void __iomem *base)
 {
        struct samsung_clk_provider *ctx;
+       int ret;
        reg_base = base;
 
        if (np) {
@@ -447,6 +462,10 @@ void __init s3c2443_common_clk_init(struct device_node *np, unsigned long xti_f,
        s3c2443_clk_sleep_init();
 
        samsung_clk_of_add_provider(np, ctx);
+
+       ret = register_restart_handler(&s3c2443_restart_handler);
+       if (ret)
+               pr_warn("cannot register restart handler, %d\n", ret);
 }
 
 static void __init s3c2416_clk_init(struct device_node *np)
Signature · 7 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Acked-by on v7 11/11
#34 lore raw

Re: [PATCH v7 11/11] clk: rockchip: add restart handler

In reply to Guenter Roeck

Quoting Guenter Roeck (2014-08-19 17:45:38)

Quoted 7 lines

From: Heiko St?bner <[email protected]>

Add infrastructure to write the correct value to the restart register and register the restart notifier for both rk3188 (including rk3066) and rk3288.

Quoted 94 lines

---
v7: Added patch to series.

 drivers/clk/rockchip/clk-rk3188.c |  2 ++
 drivers/clk/rockchip/clk-rk3288.c |  2 ++
 drivers/clk/rockchip/clk.c        | 25 +++++++++++++++++++++++++
 drivers/clk/rockchip/clk.h        |  1 +
 4 files changed, 30 insertions(+)
drivers/clk/rockchip/clk-rk3188.c +2 -0
index a83a6d8..71b661a 100644
@@ -631,6 +631,8 @@ static void __init rk3188_common_clk_init(struct device_node *np)
 
        rockchip_register_softrst(np, 9, reg_base + RK2928_SOFTRST_CON(0),
                                  ROCKCHIP_SOFTRST_HIWORD_MASK);
+
+       rockchip_register_restart_notifier(RK2928_GLB_SRST_FST);
 }
 
 static void __init rk3066a_clk_init(struct device_node *np)
drivers/clk/rockchip/clk-rk3288.c +2 -0
index 0d8c6c5..b604217 100644
@@ -713,5 +713,7 @@ static void __init rk3288_clk_init(struct device_node *np)
 
        rockchip_register_softrst(np, 9, reg_base + RK3288_SOFTRST_CON(0),
                                  ROCKCHIP_SOFTRST_HIWORD_MASK);
+
+       rockchip_register_restart_notifier(RK3288_GLB_SRST_FST);
 }
 CLK_OF_DECLARE(rk3288_cru, "rockchip,rk3288-cru", rk3288_clk_init);
drivers/clk/rockchip/clk.c +25 -0
index 278cf9d..aa41433 100644
@@ -25,6 +25,7 @@
 #include <linux/clk-provider.h>
 #include <linux/mfd/syscon.h>
 #include <linux/regmap.h>
+#include <linux/reboot.h>
 #include "clk.h"
 
 /**
@@ -242,3 +243,27 @@ void __init rockchip_clk_register_branches(
                rockchip_clk_add_lookup(clk, list->id);
        }
 }
+
+static unsigned int reg_restart;
+static int rockchip_restart_notify(struct notifier_block *this,
+                                  unsigned long mode, void *cmd)
+{
+       writel(0xfdb9, reg_base + reg_restart);
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block rockchip_restart_handler = {
+       .notifier_call = rockchip_restart_notify,
+       .priority = 128,
+};
+
+void __init rockchip_register_restart_notifier(unsigned int reg)
+{
+       int ret;
+
+       reg_restart = reg;
+       ret = register_restart_handler(&rockchip_restart_handler);
+       if (ret)
+               pr_err("%s: cannot register restart handler, %d\n",
+                      __func__, ret);
+}
drivers/clk/rockchip/clk.h +1 -0
index 887cbde..0b5eab5 100644
@@ -329,6 +329,7 @@ void rockchip_clk_register_branches(struct rockchip_clk_branch *clk_list,
                                    unsigned int nr_clk);
 void rockchip_clk_register_plls(struct rockchip_pll_clock *pll_list,
                                unsigned int nr_pll, int grf_lock_offset);
+void rockchip_register_restart_notifier(unsigned int reg);
 
 #define ROCKCHIP_SOFTRST_HIWORD_MASK   BIT(0)
 
Signature · 7 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Tested-by on the v7 series
#38 lore raw
In reply to Guenter Roeck

Hello Guenter,

Thanks for the patches.
Tested patches 1,2 & 4 from this series on qcom apq8064 based IFC6410 with Josh's patches which replace arm restart with restart notifier for this target.

Quoted 85 lines · Guenter Roeck

Various drivers implement architecture and/or device specific means to restart (reset) the system. Various mechanisms have been implemented to support those schemes. The best known mechanism is arm_pm_restart, which is a function pointer to be set either from platform specific code or from drivers. Another mechanism is to use hardware watchdogs to issue a reset; this mechanism is used if there is no other method available to reset a board or system. Two examples are alim7101_wdt, which currently uses the reboot notifier to trigger a reset, and moxart_wdt, which registers the arm_pm_restart function. Several other restart drivers for arm, all directly calling arm_pm_restart, are in the process of being integrated into the kernel. All those drivers would benefit from the new API.

The existing mechanisms have a number of drawbacks. Typically only one scheme to restart the system is supported (at least if arm_pm_restart is used). At least in theory there can be multiple means to restart the system, some of which may be less desirable (for example one mechanism may only reset the CPU, while another may reset the entire system). Using arm_pm_restart can also be racy if the function pointer is set from a driver, as the driver may be in the process of being unloaded when arm_pm_restart is called. Using the reboot notifier is always racy, as it is unknown if and when other functions using the reboot notifier have completed execution by the time the watchdog fires.

Introduce a system restart handler call chain to solve the described problems. This call chain is expected to be executed from the architecture specific machine_restart() function. Drivers providing system restart functionality (such as the watchdog drivers mentioned above) are expected to register with this call chain. By using the priority field in the notifier block, callers can control restart handler execution sequence and thus ensure that the restart handler with the optimal restart capabilities for a given system is called first.

Since the first revision of this patchset, a number of separate patch submissions have been made which either depend on it or could make use of it.

http://www.spinics.net/linux/lists/arm-kernel/msg344796.html
registers three notifiers.
https://lkml.org/lkml/2014/7/8/962
would benefit from it.

Patch 1 of this series implements the restart handler function. Patches 2 and 3 implement calling the restart handler chain from arm and arm64 restart code.

Patch 4 modifies the restart-poweroff driver to no longer call arm_pm_restart directly but machine_restart. This is done to avoid calling arm_pm_restart from more than one place. The change makes the driver architecture independent, so it would be possible to drop the arm dependency from its Kconfig entry.

Patch 5 and 6 convert existing restart handlers in the watchdog subsystem to use the restart handler. Patch 7 unexports arm_pm_restart to ensure that no one gets the idea to implement a restart handler as module.

The entire patch series, including additional patches depending on it, is available from
https://git.kernel.org/cgit/linux/kernel/git/groeck/linux-staging.git/
in branch 'restart-staging'.

---
v7: Rebased to v3.17-rc1
Dropped null_restart from arm code to make arm_pm_restart truly optional Reordered series. power/restart must be patched to not use arm_pm_restart prior to making arm_pm_restart optional.
Added all pending patches to series
v6: Use atomic notifier call chain
Rebased series to v3.16
v5: Rebased series to v3.16-rc5

    Function renames:
    register_restart_notifier -> register_restart_handler
    unregister_restart_notifier -> unregister_restart_handler
    kernel_restart_notify -> do_kernel_restart

v4: Document restart notifier priorities
Select 128 as default priority for newly introduced notifiers Fix checkpatch warning (line too long) in moxart patch
v3: Drop RFC.
Add kernel_restart_notify wrapper function to execute notifier Improve documentation.
Move restart_notifier_list into kernel/reboot.c and make it static.
v2: Add patch 4.
Only call blocking notifier call chain if arm_pm_restart was not set.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#39 lore raw
In reply to Guenter Roeck
Quoted 1 line · On Tue, 19 Aug 2014 17:45:27 -0700 Guenter Roeck <[email protected]> wrote:

Introduce a system restart handler call chain to solve the described problems.

So someone has merged eight of these patches into linux-next but these three:

watchdog-s3c2410-add-restart-handler.patch clk-samsung-register-restart-handlers-for-s3c2412-and-s3c2443.patch clk-rockchip-add-restart-handler.patch

were omitted. What's up?

author maintainer
#40 lore raw
Quoted 4 lines · Andrew Morton
Quoted 1 line · On Tue, 19 Aug 2014 17:45:27 -0700 Guenter Roeck <[email protected]> wrote:

Introduce a system restart handler call chain to solve the described problems.

Quoted 8 lines

So someone has merged eight of these patches into linux-next but these three:

watchdog-s3c2410-add-restart-handler.patch clk-samsung-register-restart-handlers-for-s3c2412-and-s3c2443.patch clk-rockchip-add-restart-handler.patch

were omitted. What's up?

Most likely PBKC on my side; Looks like I forgot to add those when I created the immutable branch for others to merge. Sorry for that :-(.

Having said that, I somehow thought that the clock patches would go in through the clock tree. Heiko, did I get that wrong ? Separately, I sent a pull request that includes the watchdog patch to Wim.

Thanks,
Guenter

#41 lore raw

Hi Guenter,

Quoted 13 lines · On Tue, 30 Sep 2014 15:30:00 -0700 Guenter Roeck <[email protected]> wrote:
Quoted 11 lines · Andrew Morton
Quoted 1 line · On Tue, 19 Aug 2014 17:45:27 -0700 Guenter Roeck <[email protected]> wrote:

Introduce a system restart handler call chain to solve the described problems.

So someone has merged eight of these patches into linux-next but these three:

watchdog-s3c2410-add-restart-handler.patch clk-samsung-register-restart-handlers-for-s3c2412-and-s3c2443.patch clk-rockchip-add-restart-handler.patch

Quoted 8 lines
Quoted 1 line

were omitted. What's up?

Most likely PBKC on my side; Looks like I forgot to add those when I created the immutable branch for others to merge. Sorry for that :-(.

Having said that, I somehow thought that the clock patches would go in through the clock tree. Heiko, did I get that wrong ? Separately, I sent a pull request that includes the watchdog patch to Wim.

So far, that immutable branch has been merged into the battery tree (and thus into linux-next) by Sebastian in order to add (I assume):

18a702e0de98 power: reset: use restart_notifier mechanism for msm-poweroff 371bb20d6927 power: Add simple gpio-restart driver

on top of it.

So, I guess the watchdog and clk trees also need to merge that immutable branch and then add their respective patches from the mmotm series to their trees.

Signature · 9 lines
Cheers,
Stephen Rothwell                    sfr at canb.auug.org.au
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141001/874b8c8b/attachment.sig>
author maintainer
#42 lore raw
Quoted 28 lines · Stephen Rothwell

Hi Guenter,

Quoted 13 lines · On Tue, 30 Sep 2014 15:30:00 -0700 Guenter Roeck <[email protected]> wrote:
Quoted 11 lines · Andrew Morton
Quoted 1 line · On Tue, 19 Aug 2014 17:45:27 -0700 Guenter Roeck <[email protected]> wrote:

Introduce a system restart handler call chain to solve the described problems.

So someone has merged eight of these patches into linux-next but these three:

watchdog-s3c2410-add-restart-handler.patch clk-samsung-register-restart-handlers-for-s3c2412-and-s3c2443.patch clk-rockchip-add-restart-handler.patch

Quoted 8 lines
Quoted 1 line

were omitted. What's up?

Most likely PBKC on my side; Looks like I forgot to add those when I created the immutable branch for others to merge. Sorry for that :-(.

Having said that, I somehow thought that the clock patches would go in through the clock tree. Heiko, did I get that wrong ? Separately, I sent a pull request that includes the watchdog patch to Wim.

So far, that immutable branch has been merged into the battery tree (and thus into linux-next) by Sebastian in order to add (I assume):

Quoted 9 lines

18a702e0de98 power: reset: use restart_notifier mechanism for msm-poweroff 371bb20d6927 power: Add simple gpio-restart driver

on top of it.

So, I guess the watchdog and clk trees also need to merge that immutable branch and then add their respective patches from the mmotm series to their trees.

Yes, and now I remember why I did not include those patches: They are not authored by myself. I thought it was not appropriate for me to include them in the branch I created. Maybe flawed thinking, but that was my reasoning.

Guenter

maintainer
#43 lore raw
In reply to Guenter Roeck

Am Dienstag, 30. September 2014, 15:30:00 schrieb Guenter Roeck:

Quoted 2 lines · Andrew Morton
Quoted 1 line

On Tue, 19 Aug 2014 17:45:27 -0700 Guenter Roeck <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 2 lines

Introduce a system restart handler call chain to solve the described problems.>

So someone has merged eight of these patches into linux-next but these three:

watchdog-s3c2410-add-restart-handler.patch clk-samsung-register-restart-handlers-for-s3c2412-and-s3c2443.patch clk-rockchip-add-restart-handler.patch

Quoted 8 lines
Quoted 1 line

were omitted. What's up?

Most likely PBKC on my side; Looks like I forgot to add those when I created the immutable branch for others to merge. Sorry for that :-(.

Having said that, I somehow thought that the clock patches would go in through the clock tree. Heiko, did I get that wrong ? Separately, I sent a pull request that includes the watchdog patch to Wim.

I didn't realise that the patches would get dropped from -mm until I the removal notices this morning. So meanwhile I've send a pull to Mike for the Rockchip and S3C2412/2416/2443 restart handling.

So, as your pull includes the samsung watchdog restart, we should be hopefully all set again :-) .

Heiko

#22 lore raw

Re: [PATCH v7 08/11] arm/arm64: Unexport restart handlers

In reply to Guenter Roeck

Hi G?nther,

Quoted 4 lines · Guenter Roeck

Implementing a restart handler in a module don't make sense as there would be no guarantee that the module is loaded when a restart is needed. Unexport arm_pm_restart to ensure that no one gets the idea to do it anyway.

Why not? I was just going to do that, but I got greeted by:

ERROR: "arm_pm_restart" [drivers/power/reset/rmobile-reset.ko] undefined!

So now we have to make sure all reset drivers for a zillion different hardware devices are builtin, and can't be modular?

Quoted 32 lines

---
v7: No change
v6: No change
v5: No change
v4: No change
v3: No change
v2: No change

 arch/arm/kernel/process.c   | 1 -
 arch/arm64/kernel/process.c | 1 -
 2 files changed, 2 deletions(-)
arch/arm/kernel/process.c +0 -1
index ea279f7..250b6f6 100644
@@ -121,7 +121,6 @@ void (*pm_power_off)(void);
 EXPORT_SYMBOL(pm_power_off);
 
 void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
-EXPORT_SYMBOL_GPL(arm_pm_restart);
 
 /*
  * This is our default idle handler.
arch/arm64/kernel/process.c +0 -0
index 0d3fb9f..398ab05 100644

arch/arm64/kernel/process.c void (*pm_power_off)(void); · line 103

Quoted 7 lines
arch/arm64/kernel/process.c +0 -1
@@ -98,7 +98,6 @@ void (*pm_power_off)(void);
 EXPORT_SYMBOL_GPL(pm_power_off);
 
 void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
-EXPORT_SYMBOL_GPL(arm_pm_restart);
 
 /*
  * This is our default idle handler.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author maintainer
#23 lore raw

Re: [PATCH v7 08/11] arm/arm64: Unexport restart handlers

Quoted 10 lines · Geert Uytterhoeven

Hi G?nther,

Quoted 4 lines · Guenter Roeck

Implementing a restart handler in a module don't make sense as there would be no guarantee that the module is loaded when a restart is needed. Unexport arm_pm_restart to ensure that no one gets the idea to do it anyway.

Why not? I was just going to do that, but I got greeted by:

Because you should register a restart handler instead, like the other drivers in the same directory now do.

Quoted 5 lines

ERROR: "arm_pm_restart" [drivers/power/reset/rmobile-reset.ko] undefined!

So now we have to make sure all reset drivers for a zillion different hardware devices are builtin, and can't be modular?

No. All those drivers need to do is to register a restart handler using the API provided in the patch series.

Ultimately all restart handlers should do that and arm_pm_restart should go away entirely. That was the point of the patch series.

Guenter

#24 lore raw

Re: [PATCH v7 08/11] arm/arm64: Unexport restart handlers

Hi G?nther,

Quoted 11 lines · Guenter Roeck
Quoted 7 lines · Geert Uytterhoeven
Quoted 4 lines · Guenter Roeck

Implementing a restart handler in a module don't make sense as there would be no guarantee that the module is loaded when a restart is needed. Unexport arm_pm_restart to ensure that no one gets the idea to do it anyway.

Why not? I was just going to do that, but I got greeted by:

Because you should register a restart handler instead, like the other drivers in the same directory now do.

That's a different thing. "there would be no guarantee that the module is loaded when a restart is needed" is also valid for restart handlers...

Quoted 10 lines
Quoted 5 lines

ERROR: "arm_pm_restart" [drivers/power/reset/rmobile-reset.ko] undefined!

So now we have to make sure all reset drivers for a zillion different hardware devices are builtin, and can't be modular?

No. All those drivers need to do is to register a restart handler using the API provided in the patch series.

Ultimately all restart handlers should do that and arm_pm_restart should go away entirely. That was the point of the patch series.

Good. That's what I'm doing right know ;-)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author maintainer
#25 lore raw

Re: [PATCH v7 08/11] arm/arm64: Unexport restart handlers

Quoted 10 lines · Geert Uytterhoeven

Hi G?nther,

Quoted 7 lines · Guenter Roeck
Quoted 6 lines · Geert Uytterhoeven
Quoted 4 lines · Guenter Roeck

Implementing a restart handler in a module don't make sense as there would be no guarantee that the module is loaded when a restart is needed. Unexport arm_pm_restart to ensure that no one gets the idea to do it anyway.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Why not? I was just going to do that, but I got greeted by:

Because you should register a restart handler instead, like the other drivers in the same directory now do.

That's a different thing. "there would be no guarantee that the module is loaded when a restart is needed" is also valid for restart handlers...

Not really, because you are supposed to unregister the restart handler on unload. Sure, you can instead clear arm_pm_reastart and leave the system with no means to restart ...

Guenter

Quoted 24 lines
Quoted 10 lines
Quoted 5 lines

ERROR: "arm_pm_restart" [drivers/power/reset/rmobile-reset.ko] undefined!

So now we have to make sure all reset drivers for a zillion different hardware devices are builtin, and can't be modular?

No. All those drivers need to do is to register a restart handler using the API provided in the patch series.

Ultimately all restart handlers should do that and arm_pm_restart should go away entirely. That was the point of the patch series.

Good. That's what I'm doing right know ;-)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#26 lore raw

Re: [PATCH v7 08/11] arm/arm64: Unexport restart handlers

Quoted 14 lines · On Thursday 04 December 2014 06:51:49 Guenter Roeck wrote:
Quoted 13 lines · Geert Uytterhoeven
Quoted 11 lines · Guenter Roeck
Quoted 7 lines · Geert Uytterhoeven
Quoted 4 lines · Guenter Roeck

Implementing a restart handler in a module don't make sense as there would be no guarantee that the module is loaded when a restart is needed. Unexport arm_pm_restart to ensure that no one gets the idea to do it anyway.

Why not? I was just going to do that, but I got greeted by:

Because you should register a restart handler instead, like the other drivers in the same directory now do.

Quoted 7 lines
Quoted 3 lines

That's a different thing. "there would be no guarantee that the module is loaded when a restart is needed" is also valid for restart handlers...

Not really, because you are supposed to unregister the restart handler on unload. Sure, you can instead clear arm_pm_reastart and leave the system with no means to restart ...

I agree with Geert that your commit message was confusing, it sounds like you were referring to drivers that are not yet loaded, while the problem that you are really address is drivers that have been unloaded later.

Arnd

author maintainer
#27 lore raw

Re: [PATCH v7 08/11] arm/arm64: Unexport restart handlers

Quoted 19 lines · Arnd Bergmann
Quoted 18 lines · On Thursday 04 December 2014 06:51:49 Guenter Roeck wrote:
Quoted 16 lines · Geert Uytterhoeven
Quoted 11 lines · Guenter Roeck
Quoted 7 lines · Geert Uytterhoeven
Quoted 4 lines · Guenter Roeck

Implementing a restart handler in a module don't make sense as there would be no guarantee that the module is loaded when a restart is needed. Unexport arm_pm_restart to ensure that no one gets the idea to do it anyway.

Why not? I was just going to do that, but I got greeted by:

Because you should register a restart handler instead, like the other drivers in the same directory now do.

That's a different thing. "there would be no guarantee that the module is loaded when a restart is needed" is also valid for restart handlers...

Quoted 8 lines
Quoted 3 lines

Not really, because you are supposed to unregister the restart handler on unload. Sure, you can instead clear arm_pm_reastart and leave the system with no means to restart ...

I agree with Geert that your commit message was confusing, it sounds like you were referring to drivers that are not yet loaded, while the problem that you are really address is drivers that have been unloaded later.

Yes, I realize that now. I should probably have added the rationale for the entire series to this commit. I'll try to do better next time.

Guenter