Skip to contentSkip to conversation

kernel: Add support for poweroff handler call chain

RFC PATCH In review Guenter Roeck 6 participants 49 messages Sep 30, 2014 – Oct 3, 2014

Subsystems (11)
Arm (32-bit) x86 MIPS arm64 +7 more subsystems
lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

cover kernel: Add support for poweroff handler call chain

Various drivers implement architecture and/or device specific means to remove power from the system. For the most part, those drivers set the global variable pm_power_off to point to a function within the driver.

This mechanism has a number of drawbacks. Typically only one scheme to remove power is supported (at least if pm_power_off is used). At least in theory there can be multiple means remove power, some of which may be less desirable. For example, some mechanisms may only power off the CPU or the CPU card, while another may power off the entire system. Others may really just execute a restart sequence or drop into the ROM monitor. Using pm_power_off can also be racy if the function pointer is set from a driver built as module, as the driver may be in the process of being unloaded when pm_power_off is called. If there are multiple poweroff handlers in the system, removing a module with such a handler may inadvertently reset the pointer to pm_power_off to NULL, leaving the system with no means to remove power.

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

The poweroff handler is introduced in multiple steps

1) Implement poweroff handler API.
Patch 01/16.
2) Ensure that pm_power_off is only called from machine_restart. Patches 02/16 and 03/16.
3) Implement call to poweroff handler in architecture specific machine_restart code.
Patches 03/16 to 13/16.
4) Convert all drivers to register with poweroff handler instead of setting pm_power_off directly.
Patches 15/16 and 16/16 (examples).
This can be done in two steps: First convert all drivers which can be built as modules, then convert the remaining drivers (possibly after unexporting pm_powr_off).
5) Unexport pm_power_off for all architectures,
and drop it entirely for architectures where it is not really used.
6) [optional] Convert machine specific architecture code to register with poweroff handler instead of setting pm_power_off directly, and remove pm_power_off entirely from the system.

Cc Andrew Morton <[email protected]>
Cc Heiko Stuebner <[email protected]>
Cc Romain Perier <[email protected]>
Cc James E.J. Bottomley <[email protected]>
Cc Helge Deller <[email protected]>
Cc Russell King <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Haavard Skinnemoen <[email protected]>
Cc Hans-Christian Egtvedt <[email protected]>
Cc Mark Salter <[email protected]>
Cc Aurelien Jacquiot <[email protected]>
Cc Tony Luck <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc James Hogan <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Guan Xuetao <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>

----------------------------------------------------------------
Guenter Roeck (16):
kernel: Add support for poweroff handler call chain
hwmon: (ab8500) Call kernel_power_off instead of pm_power_off
parisc: support poweroff through poweroff handler call chain
arm: support poweroff through poweroff handler call chain
arm64: support poweroff through poweroff handler call chain
avr32: support poweroff through poweroff handler call chain
c6x: support poweroff through poweroff handler call chain
ia64: support poweroff through poweroff handler call chain
metag: support poweroff through poweroff handler call chain
mips: support poweroff through poweroff handler call chain
sh: support poweroff through poweroff handler call chain
unicore32: support poweroff through poweroff handler call chain
x86: support poweroff through poweroff handler call chain x86/xen: support poweroff through poweroff handler call chain power/reset: restart-poweroff: Register with kernel poweroff handler
mfd: palmas: Register with kernel poweroff handler

 arch/arm/kernel/process.c              |  2 +
 arch/arm64/kernel/process.c            |  2 +
 arch/avr32/kernel/process.c            |  2 +
 arch/c6x/kernel/process.c              |  2 +
 arch/ia64/kernel/process.c             |  2 +
 arch/metag/kernel/process.c            |  2 +
 arch/mips/kernel/reset.c               |  2 +
 arch/parisc/kernel/process.c           |  7 ++-
 arch/sh/kernel/reboot.c                |  2 +
 arch/unicore32/kernel/process.c        |  2 +
 arch/x86/kernel/reboot.c               |  4 ++
 arch/x86/xen/enlighten.c               |  2 +
 drivers/hwmon/ab8500.c                 |  5 ++-
 drivers/mfd/palmas.c                   | 30 +++++++------
 drivers/parisc/power.c                 |  3 +-
 drivers/power/reset/restart-poweroff.c | 24 +++++-----
 include/linux/mfd/palmas.h             |  3 ++
 include/linux/reboot.h                 |  4 ++
 kernel/reboot.c                        | 81 ++++++++++++++++++++++++++++++++++
 19 files changed, 149 insertions(+), 32 deletions(-)
author maintainer
#1 lore raw

RFC PATCH 1/16 kernel: Add support for poweroff handler call chain

Various drivers implement architecture and/or device specific means to remove power from the system. For the most part, those drivers set the global variable pm_power_off to point to a function within the driver.

This mechanism has a number of drawbacks. Typically only one scheme to remove power is supported (at least if pm_power_off is used). At least in theory there can be multiple means remove power, some of which may be less desirable. For example, some mechanisms may only power off the CPU or the CPU card, while another may power off the entire system. Others may really just execute a restart sequence or drop into the ROM monitor. Using pm_power_off can also be racy if the function pointer is set from a driver built as module, as the driver may be in the process of being unloaded when pm_power_off is called. If there are multiple poweroff handlers in the system, removing a module with such a handler may inadvertently reset the pointer to pm_power_off to NULL, leaving the system with no means to remove power.

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

Cc Andrew Morton <[email protected]>
cc Heiko Stuebner <[email protected]>
Cc Romain Perier <[email protected]>
Cc James E.J. Bottomley <[email protected]>
Cc Helge Deller <[email protected]>
Cc Russell King <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Haavard Skinnemoen <[email protected]>
Cc Hans-Christian Egtvedt <[email protected]>
Cc Mark Salter <[email protected]>
Cc Aurelien Jacquiot <[email protected]>
Cc Tony Luck <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc James Hogan <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Guan Xuetao <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 include/linux/reboot.h |  4 +++
 kernel/reboot.c        | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+)
include/linux/reboot.h +4 -0
index 67fc8fc..b172951 100644
@@ -38,6 +38,10 @@ extern int reboot_force;
 extern int register_reboot_notifier(struct notifier_block *);
 extern int unregister_reboot_notifier(struct notifier_block *);
 
+extern int register_poweroff_handler(struct notifier_block *);
+extern int unregister_poweroff_handler(struct notifier_block *);
+extern void do_kernel_poweroff(void);
+
 extern int register_restart_handler(struct notifier_block *);
 extern int unregister_restart_handler(struct notifier_block *);
 extern void do_kernel_restart(char *cmd);
kernel/reboot.c +81 -0

87 lines not on this page · raw message

Signature · 1 line
1.9.1
author maintainer
#2 lore raw

RFC PATCH 1/16 kernel: Add support for poweroff handler call chain

In reply to Guenter Roeck

Various drivers implement architecture and/or device specific means to remove power from the system. For the most part, those drivers set the global variable pm_power_off to point to a function within the driver.

This mechanism has a number of drawbacks. Typically only one scheme to remove power is supported (at least if pm_power_off is used). At least in theory there can be multiple means remove power, some of which may be less desirable. For example, some mechanisms may only power off the CPU or the CPU card, while another may power off the entire system. Others may really just execute a restart sequence or drop into the ROM monitor. Using pm_power_off can also be racy if the function pointer is set from a driver built as module, as the driver may be in the process of being unloaded when pm_power_off is called. If there are multiple poweroff handlers in the system, removing a module with such a handler may inadvertently reset the pointer to pm_power_off to NULL, leaving the system with no means to remove power.

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

Cc Andrew Morton <[email protected]>
cc Heiko Stuebner <[email protected]>
Cc Romain Perier <[email protected]>
Cc James E.J. Bottomley <[email protected]>
Cc Helge Deller <[email protected]>
Cc Russell King <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Haavard Skinnemoen <[email protected]>
Cc Hans-Christian Egtvedt <[email protected]>
Cc Mark Salter <[email protected]>
Cc Aurelien Jacquiot <[email protected]>
Cc Tony Luck <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc James Hogan <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Guan Xuetao <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 include/linux/reboot.h |  4 +++
 kernel/reboot.c        | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+)
include/linux/reboot.h +4 -0
index 67fc8fc..b172951 100644
@@ -38,6 +38,10 @@ extern int reboot_force;
 extern int register_reboot_notifier(struct notifier_block *);
 extern int unregister_reboot_notifier(struct notifier_block *);
 
+extern int register_poweroff_handler(struct notifier_block *);
+extern int unregister_poweroff_handler(struct notifier_block *);
+extern void do_kernel_poweroff(void);
+
 extern int register_restart_handler(struct notifier_block *);
 extern int unregister_restart_handler(struct notifier_block *);
 extern void do_kernel_restart(char *cmd);
kernel/reboot.c +81 -0

87 lines not on this page · raw message

Signature · 1 line
1.9.1
author maintainer
#3 lore raw

RFC PATCH 2/16 hwmon: (ab8500) Call kernel_power_off instead of pm_power_off

In reply to Guenter Roeck

Drivers should not call pm_power_off directly; it is not guaranteed to be non-NULL. Call kernel_power_off instead.

---
I already submitted this patch separately as non-RFC. It is included in this series for completeness.

 drivers/hwmon/ab8500.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hwmon/ab8500.c +3 -2
index d844dc8..8b6a4f4 100644
@@ -6,7 +6,7 @@
  *
  * When the AB8500 thermal warning temperature is reached (threshold cannot
  * be changed by SW), an interrupt is set, and if no further action is taken
- * within a certain time frame, pm_power off will be called.
+ * within a certain time frame, kernel_power_off will be called.
  *
  * When AB8500 thermal shutdown temperature is reached a hardware shutdown of
  * the AB8500 will occur.
@@ -21,6 +21,7 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/power/ab8500.h>
+#include <linux/reboot.h>
 #include <linux/slab.h>
 #include <linux/sysfs.h>
 #include "abx500.h"
@@ -106,7 +107,7 @@ static void ab8500_thermal_power_off(struct work_struct *work)
 
 	dev_warn(&abx500_data->pdev->dev, "Power off due to critical temp\n");
 
-	pm_power_off();
+	kernel_power_off();
 }
 
 static ssize_t ab8500_show_name(struct device *dev,
Signature · 1 line
1.9.1
author maintainer
#4 lore raw

RFC PATCH 2/16 hwmon: (ab8500) Call kernel_power_off instead of pm_power_off

In reply to Guenter Roeck

Drivers should not call pm_power_off directly; it is not guaranteed to be non-NULL. Call kernel_power_off instead.

---
I already submitted this patch separately as non-RFC. It is included in this series for completeness.

 drivers/hwmon/ab8500.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hwmon/ab8500.c +3 -2
index d844dc8..8b6a4f4 100644
@@ -6,7 +6,7 @@
  *
  * When the AB8500 thermal warning temperature is reached (threshold cannot
  * be changed by SW), an interrupt is set, and if no further action is taken
- * within a certain time frame, pm_power off will be called.
+ * within a certain time frame, kernel_power_off will be called.
  *
  * When AB8500 thermal shutdown temperature is reached a hardware shutdown of
  * the AB8500 will occur.
@@ -21,6 +21,7 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/power/ab8500.h>
+#include <linux/reboot.h>
 #include <linux/slab.h>
 #include <linux/sysfs.h>
 #include "abx500.h"
@@ -106,7 +107,7 @@ static void ab8500_thermal_power_off(struct work_struct *work)
 
 	dev_warn(&abx500_data->pdev->dev, "Power off due to critical temp\n");
 
-	pm_power_off();
+	kernel_power_off();
 }
 
 static ssize_t ab8500_show_name(struct device *dev,
Signature · 1 line
1.9.1
author maintainer
#5 lore raw

RFC PATCH 3/16 parisc: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it from machine_power_off.

Also, do not use pm_power_off as alternate pointer to machine_power_off. Have the parisc/power driver call kernel_power_off() which in turn will call machine_power_off().

Cc James E.J. Bottomley <[email protected]>
Cc Helge Deller <[email protected]>
---
 arch/parisc/kernel/process.c | 7 +++++--
 drivers/parisc/power.c       | 3 +--
 2 files changed, 6 insertions(+), 4 deletions(-)
arch/parisc/kernel/process.c +5 -2
index 0bbbf0d..21d1ab3 100644
@@ -42,6 +42,7 @@
 #include <linux/module.h>
 #include <linux/personality.h>
 #include <linux/ptrace.h>
+#include <linux/reboot.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/stddef.h>
@@ -133,7 +134,9 @@ void machine_power_off(void)
 	pdc_soft_power_button(0);
 	
 	pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
-		
+
+	do_kernel_poweroff();
+
 	/* It seems we have no way to power the system off via
 	 * software. The user has to press the button himself. */
 
@@ -141,7 +144,7 @@ void machine_power_off(void)
 	       "Please power this system off now.");
 }
 
-void (*pm_power_off)(void) = machine_power_off;
+void (*pm_power_off)(void);
 EXPORT_SYMBOL(pm_power_off);
 
 /*
drivers/parisc/power.c +1 -2
index 90cca5e..de5b2ff 100644
@@ -95,8 +95,7 @@ static void process_shutdown(void)
 		/* send kill signal */
 		if (kill_cad_pid(SIGINT, 1)) {
 			/* just in case killing init process failed */
-			if (pm_power_off)
-				pm_power_off();
+			kernel_power_off();
 		}
 	}
 }
Signature · 1 line
1.9.1
author maintainer
#6 lore raw

RFC PATCH 3/16 parisc: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it from machine_power_off.

Also, do not use pm_power_off as alternate pointer to machine_power_off. Have the parisc/power driver call kernel_power_off() which in turn will call machine_power_off().

Cc James E.J. Bottomley <[email protected]>
Cc Helge Deller <[email protected]>
---
 arch/parisc/kernel/process.c | 7 +++++--
 drivers/parisc/power.c       | 3 +--
 2 files changed, 6 insertions(+), 4 deletions(-)
arch/parisc/kernel/process.c +5 -2
index 0bbbf0d..21d1ab3 100644
@@ -42,6 +42,7 @@
 #include <linux/module.h>
 #include <linux/personality.h>
 #include <linux/ptrace.h>
+#include <linux/reboot.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/stddef.h>
@@ -133,7 +134,9 @@ void machine_power_off(void)
 	pdc_soft_power_button(0);
 	
 	pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
-		
+
+	do_kernel_poweroff();
+
 	/* It seems we have no way to power the system off via
 	 * software. The user has to press the button himself. */
 
@@ -141,7 +144,7 @@ void machine_power_off(void)
 	       "Please power this system off now.");
 }
 
-void (*pm_power_off)(void) = machine_power_off;
+void (*pm_power_off)(void);
 EXPORT_SYMBOL(pm_power_off);
 
 /*
drivers/parisc/power.c +1 -2
index 90cca5e..de5b2ff 100644
@@ -95,8 +95,7 @@ static void process_shutdown(void)
 		/* send kill signal */
 		if (kill_cad_pid(SIGINT, 1)) {
 			/* just in case killing init process failed */
-			if (pm_power_off)
-				pm_power_off();
+			kernel_power_off();
 		}
 	}
 }
Signature · 1 line
1.9.1
author maintainer
#7 lore raw

RFC PATCH 4/16 arm: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/arm/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/kernel/process.c +2 -0
index 250b6f6..848c578 100644
@@ -207,6 +207,8 @@ void machine_power_off(void)
 
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
 
 /*
Signature · 1 line
1.9.1
author maintainer
#8 lore raw

RFC PATCH 4/16 arm: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/arm/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/kernel/process.c +2 -0
index 250b6f6..848c578 100644
@@ -207,6 +207,8 @@ void machine_power_off(void)
 
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
 
 /*
Signature · 1 line
1.9.1
author maintainer
#9 lore raw

RFC PATCH 5/16 arm64: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/kernel/process.c +2 -0
index 398ab05..cc0c63e 100644
@@ -157,6 +157,8 @@ void machine_power_off(void)
 	smp_send_stop();
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
 
 /*
Signature · 1 line
1.9.1
maintainer Acked-by on v1 5/16
#10 lore raw

Re: [RFC PATCH 05/16] arm64: support poweroff through poweroff handler call chain

Quoted 16 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/kernel/process.c +0 -0
index 398ab05..cc0c63e 100644

arch/arm64/kernel/process.c void machine_power_off(void) · line 161

Quoted 5 lines
arch/arm64/kernel/process.c +2 -0
@@ -157,6 +157,8 @@ void machine_power_off(void)
 	smp_send_stop();
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();

As others already stated, I think we should eventually remove pm_power_off entirely.

Catalin

author maintainer
#11 lore raw

Re: [RFC PATCH 05/16] arm64: support poweroff through poweroff handler call chain

Quoted 25 lines · Catalin Marinas
Quoted 16 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
  arch/arm64/kernel/process.c | 2 ++
  1 file changed, 2 insertions(+)
arch/arm64/kernel/process.c +0 -0
index 398ab05..cc0c63e 100644

arch/arm64/kernel/process.c void machine_power_off(void) · line 161

Quoted 5 lines
arch/arm64/kernel/process.c +2 -0
@@ -157,6 +157,8 @@ void machine_power_off(void)
  	smp_send_stop();
  	if (pm_power_off)
  		pm_power_off();
+	else
+		do_kernel_poweroff();
Quoted 3 lines

As others already stated, I think we should eventually remove pm_power_off entirely.

Hi Catalin,
yes, already working on it. As suggested by others, I'll move pm_power_off to a central location (no need to declare the same variable for each architecture) and hide the call to it in do_kernel_poweroff() as a first step. You'll see this in the next version of the series. This will make it much easier to remove it later on.

Thanks,
Guenter

author maintainer
#12 lore raw

Re: [RFC PATCH 05/16] arm64: support poweroff through poweroff handler call chain

In reply to Catalin Marinas
Quoted 25 lines · Catalin Marinas
Quoted 16 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
  arch/arm64/kernel/process.c | 2 ++
  1 file changed, 2 insertions(+)
arch/arm64/kernel/process.c +0 -0
index 398ab05..cc0c63e 100644

arch/arm64/kernel/process.c void machine_power_off(void) · line 161

Quoted 5 lines
arch/arm64/kernel/process.c +2 -0
@@ -157,6 +157,8 @@ void machine_power_off(void)
  	smp_send_stop();
  	if (pm_power_off)
  		pm_power_off();
+	else
+		do_kernel_poweroff();
Quoted 3 lines

As others already stated, I think we should eventually remove pm_power_off entirely.

Hi Catalin,
yes, already working on it. As suggested by others, I'll move pm_power_off to a central location (no need to declare the same variable for each architecture) and hide the call to it in do_kernel_poweroff() as a first step. You'll see this in the next version of the series. This will make it much easier to remove it later on.

Thanks,
Guenter

maintainer Acked-by on v1 5/16
#13 lore raw

Re: [RFC PATCH 05/16] arm64: support poweroff through poweroff handler call chain

In reply to Guenter Roeck
Quoted 16 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/kernel/process.c +0 -0
index 398ab05..cc0c63e 100644

arch/arm64/kernel/process.c void machine_power_off(void) · line 161

Quoted 5 lines
arch/arm64/kernel/process.c +2 -0
@@ -157,6 +157,8 @@ void machine_power_off(void)
 	smp_send_stop();
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();

As others already stated, I think we should eventually remove pm_power_off entirely.

Catalin

author maintainer
#14 lore raw

RFC PATCH 5/16 arm64: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
---
 arch/arm64/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/kernel/process.c +2 -0
index 398ab05..cc0c63e 100644
@@ -157,6 +157,8 @@ void machine_power_off(void)
 	smp_send_stop();
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
 
 /*
Signature · 1 line
1.9.1
author maintainer
#15 lore raw

RFC PATCH 6/16 avr32: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Haavard Skinnemoen <[email protected]>
Cc Hans-Christian Egtvedt <[email protected]>
---
 arch/avr32/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/avr32/kernel/process.c +2 -0
index 42a53e74..6bd6289 100644
@@ -50,6 +50,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
 
 void machine_restart(char *cmd)
Signature · 1 line
1.9.1
author maintainer
#16 lore raw

RFC PATCH 6/16 avr32: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Haavard Skinnemoen <[email protected]>
Cc Hans-Christian Egtvedt <[email protected]>
---
 arch/avr32/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/avr32/kernel/process.c +2 -0
index 42a53e74..6bd6289 100644
@@ -50,6 +50,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
 
 void machine_restart(char *cmd)
Signature · 1 line
1.9.1
author maintainer
#17 lore raw

RFC PATCH 7/16 c6x: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Mark Salter <[email protected]>
Cc Aurelien Jacquiot <[email protected]>
---
 arch/c6x/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/c6x/kernel/process.c +2 -0
index 57d2ea8..ddf088e 100644
@@ -75,6 +75,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	halt_loop();
 }
 
Signature · 1 line
1.9.1
Acked-by on v1 7/16
#18 lore raw

Re: [RFC PATCH 07/16] c6x: support poweroff through poweroff handler call chain

Quoted 8 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Mark Salter <[email protected]>
Cc Aurelien Jacquiot <[email protected]>

---

Quoted 16 lines
 arch/c6x/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/c6x/kernel/process.c +2 -0
index 57d2ea8..ddf088e 100644
@@ -75,6 +75,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	halt_loop();
 }
 
Acked-by on v1 7/16
#19 lore raw

Re: [RFC PATCH 07/16] c6x: support poweroff through poweroff handler call chain

In reply to Guenter Roeck
Quoted 8 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Mark Salter <[email protected]>
Cc Aurelien Jacquiot <[email protected]>

---

Quoted 16 lines
 arch/c6x/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/c6x/kernel/process.c +2 -0
index 57d2ea8..ddf088e 100644
@@ -75,6 +75,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	halt_loop();
 }
 
author maintainer
#20 lore raw

RFC PATCH 7/16 c6x: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Mark Salter <[email protected]>
Cc Aurelien Jacquiot <[email protected]>
---
 arch/c6x/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/c6x/kernel/process.c +2 -0
index 57d2ea8..ddf088e 100644
@@ -75,6 +75,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	halt_loop();
 }
 
Signature · 1 line
1.9.1
author maintainer
#21 lore raw

RFC PATCH 8/16 ia64: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/ia64/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/ia64/kernel/process.c +2 -0
index deed6fa..489b0d8 100644
@@ -677,6 +677,8 @@ machine_power_off (void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	machine_halt();
 }
 
Signature · 1 line
1.9.1
author maintainer
#22 lore raw

RFC PATCH 8/16 ia64: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/ia64/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/ia64/kernel/process.c +2 -0
index deed6fa..489b0d8 100644
@@ -677,6 +677,8 @@ machine_power_off (void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	machine_halt();
 }
 
Signature · 1 line
1.9.1
author maintainer
#23 lore raw

RFC PATCH 9/16 metag: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/metag/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/metag/kernel/process.c +2 -0
index 483dff9..ff7f3eb 100644
@@ -92,6 +92,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	smp_send_stop();
 	hard_processor_halt(HALT_OK);
 }
Signature · 1 line
1.9.1
author maintainer
#24 lore raw

RFC PATCH 9/16 metag: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/metag/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/metag/kernel/process.c +2 -0
index 483dff9..ff7f3eb 100644
@@ -92,6 +92,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	smp_send_stop();
 	hard_processor_halt(HALT_OK);
 }
Signature · 1 line
1.9.1
author maintainer
#25 lore raw

RFC PATCH 10/16 mips: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/mips/kernel/reset.c | 2 ++
 1 file changed, 2 insertions(+)
arch/mips/kernel/reset.c +2 -0
index 07fc524..c3391d7 100644
@@ -41,4 +41,6 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
Signature · 1 line
1.9.1
#26 lore raw

Re: [RFC PATCH 10/16] mips: support poweroff through poweroff handler call chain

Quoted 15 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/mips/kernel/reset.c | 2 ++
 1 file changed, 2 insertions(+)
arch/mips/kernel/reset.c +0 -0
index 07fc524..c3391d7 100644

arch/mips/kernel/reset.c void machine_power_off(void) · line 45

Quoted 5 lines
arch/mips/kernel/reset.c +2 -0
@@ -41,4 +41,6 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();

I'm happy with this as long as in a later version pm_power_off indeed goes away.

Ralf

author maintainer
#27 lore raw

Re: [RFC PATCH 10/16] mips: support poweroff through poweroff handler call chain

Quoted 12 lines · Ralf Baechle
Quoted 10 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/mips/kernel/reset.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 14 lines

arch/mips/kernel/reset.c void machine_power_off(void) · line 45

Quoted 10 lines
arch/mips/kernel/reset.c +2 -0
index 07fc524..c3391d7 100644
@@ -41,4 +41,6 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();

I'm happy with this as long as in a later version pm_power_off indeed goes away.

Yes, that would be the ultimate goal. Hope we can get there.

Guenter

author maintainer
#28 lore raw

Re: [RFC PATCH 10/16] mips: support poweroff through poweroff handler call chain

In reply to Ralf Baechle
Quoted 12 lines · Ralf Baechle
Quoted 10 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/mips/kernel/reset.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 14 lines

arch/mips/kernel/reset.c void machine_power_off(void) · line 45

Quoted 10 lines
arch/mips/kernel/reset.c +2 -0
index 07fc524..c3391d7 100644
@@ -41,4 +41,6 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();

I'm happy with this as long as in a later version pm_power_off indeed goes away.

Yes, that would be the ultimate goal. Hope we can get there.

Guenter

#29 lore raw

Re: [RFC PATCH 10/16] mips: support poweroff through poweroff handler call chain

In reply to Guenter Roeck
Quoted 15 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/mips/kernel/reset.c | 2 ++
 1 file changed, 2 insertions(+)
arch/mips/kernel/reset.c +0 -0
index 07fc524..c3391d7 100644

arch/mips/kernel/reset.c void machine_power_off(void) · line 45

Quoted 5 lines
arch/mips/kernel/reset.c +2 -0
@@ -41,4 +41,6 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();

I'm happy with this as long as in a later version pm_power_off indeed goes away.

Ralf

author maintainer
#30 lore raw

RFC PATCH 10/16 mips: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/mips/kernel/reset.c | 2 ++
 1 file changed, 2 insertions(+)
arch/mips/kernel/reset.c +2 -0
index 07fc524..c3391d7 100644
@@ -41,4 +41,6 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
Signature · 1 line
1.9.1
author maintainer
#31 lore raw

RFC PATCH 11/16 sh: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/sh/kernel/reboot.c | 2 ++
 1 file changed, 2 insertions(+)
arch/sh/kernel/reboot.c +2 -0
index 04afe5b..8e68926 100644
@@ -53,6 +53,8 @@ static void native_machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
 
 static void native_machine_halt(void)
Signature · 1 line
1.9.1
author maintainer
#32 lore raw

RFC PATCH 11/16 sh: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/sh/kernel/reboot.c | 2 ++
 1 file changed, 2 insertions(+)
arch/sh/kernel/reboot.c +2 -0
index 04afe5b..8e68926 100644
@@ -53,6 +53,8 @@ static void native_machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 }
 
 static void native_machine_halt(void)
Signature · 1 line
1.9.1
author maintainer
#33 lore raw

RFC PATCH 12/16 unicore32: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/unicore32/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/unicore32/kernel/process.c +2 -0
index b008e99..421fde6 100644
@@ -66,6 +66,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	machine_halt();
 }
 
Signature · 1 line
1.9.1
author maintainer
#34 lore raw

RFC PATCH 12/16 unicore32: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

---
 arch/unicore32/kernel/process.c | 2 ++
 1 file changed, 2 insertions(+)
arch/unicore32/kernel/process.c +2 -0
index b008e99..421fde6 100644
@@ -66,6 +66,8 @@ void machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	machine_halt();
 }
 
Signature · 1 line
1.9.1
author maintainer
#35 lore raw

RFC PATCH 13/16 x86: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
---
 arch/x86/kernel/reboot.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kernel/reboot.c +4 -0
index 17962e6..c5514aa 100644
@@ -651,6 +651,10 @@ static void native_machine_power_off(void)
 		if (!reboot_force)
 			machine_shutdown();
 		pm_power_off();
+	} else {
+		if (!reboot_force)
+			machine_shutdown();
+		do_kernel_poweroff();
 	}
 	/* A fallback in case there is no PM info available */
 	tboot_shutdown(TB_SHUTDOWN_HALT);
Signature · 1 line
1.9.1
author maintainer
#36 lore raw

RFC PATCH 13/16 x86: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
---
 arch/x86/kernel/reboot.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kernel/reboot.c +4 -0
index 17962e6..c5514aa 100644
@@ -651,6 +651,10 @@ static void native_machine_power_off(void)
 		if (!reboot_force)
 			machine_shutdown();
 		pm_power_off();
+	} else {
+		if (!reboot_force)
+			machine_shutdown();
+		do_kernel_poweroff();
 	}
 	/* A fallback in case there is no PM info available */
 	tboot_shutdown(TB_SHUTDOWN_HALT);
Signature · 1 line
1.9.1
author maintainer
#37 lore raw

RFC PATCH 14/16 x86/xen: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
---
 arch/x86/xen/enlighten.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/xen/enlighten.c +2 -0
index c0cb11f..645d00f 100644
@@ -1322,6 +1322,8 @@ static void xen_machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	xen_reboot(SHUTDOWN_poweroff);
 }
 
Signature · 1 line
1.9.1
#38 lore raw

Re: [Xen-devel] [RFC PATCH 14/16] x86/xen: support poweroff through poweroff handler call chain

Quoted 19 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
---
 arch/x86/xen/enlighten.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/xen/enlighten.c +0 -0
index c0cb11f..645d00f 100644

arch/x86/xen/enlighten.c static void xen_machine_power_off(void) · line 1326

Quoted 5 lines
arch/x86/xen/enlighten.c +2 -0
@@ -1322,6 +1322,8 @@ static void xen_machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();

Why isn't this if (pm_power_off) check in do_kernel_poweroff()?

That way when you finally remove pm_power_off you need only update one place. A quick skim of the other archs suggest this would work for them too.

David

author maintainer
#39 lore raw

Re: [Xen-devel] [RFC PATCH 14/16] x86/xen: support poweroff through poweroff handler call chain

Quoted 28 lines · David Vrabel
Quoted 19 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
---
  arch/x86/xen/enlighten.c | 2 ++
  1 file changed, 2 insertions(+)
arch/x86/xen/enlighten.c +0 -0
index c0cb11f..645d00f 100644

arch/x86/xen/enlighten.c static void xen_machine_power_off(void) · line 1326

Quoted 5 lines
arch/x86/xen/enlighten.c +2 -0
@@ -1322,6 +1322,8 @@ static void xen_machine_power_off(void)
  {
  	if (pm_power_off)
  		pm_power_off();
+	else
+		do_kernel_poweroff();

Why isn't this if (pm_power_off) check in do_kernel_poweroff()?

Quoted 4 lines

That way when you finally remove pm_power_off you need only update one place. A quick skim of the other archs suggest this would work for them too.

Good idea. I'll do that for the next version of the patch set.

Guenter

author maintainer
#40 lore raw

Re: [RFC PATCH 14/16] x86/xen: support poweroff through poweroff handler call chain

In reply to David Vrabel
Quoted 28 lines · David Vrabel
Quoted 19 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
---
  arch/x86/xen/enlighten.c | 2 ++
  1 file changed, 2 insertions(+)
arch/x86/xen/enlighten.c +0 -0
index c0cb11f..645d00f 100644

arch/x86/xen/enlighten.c static void xen_machine_power_off(void) · line 1326

Quoted 5 lines
arch/x86/xen/enlighten.c +2 -0
@@ -1322,6 +1322,8 @@ static void xen_machine_power_off(void)
  {
  	if (pm_power_off)
  		pm_power_off();
+	else
+		do_kernel_poweroff();

Why isn't this if (pm_power_off) check in do_kernel_poweroff()?

Quoted 4 lines

That way when you finally remove pm_power_off you need only update one place. A quick skim of the other archs suggest this would work for them too.

Good idea. I'll do that for the next version of the patch set.

Guenter

#41 lore raw

Re: [RFC PATCH 14/16] x86/xen: support poweroff through poweroff handler call chain

In reply to Guenter Roeck
Quoted 19 lines · Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
---
 arch/x86/xen/enlighten.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/xen/enlighten.c +0 -0
index c0cb11f..645d00f 100644

arch/x86/xen/enlighten.c static void xen_machine_power_off(void) · line 1326

Quoted 5 lines
arch/x86/xen/enlighten.c +2 -0
@@ -1322,6 +1322,8 @@ static void xen_machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();

Why isn't this if (pm_power_off) check in do_kernel_poweroff()?

That way when you finally remove pm_power_off you need only update one place. A quick skim of the other archs suggest this would work for them too.

David

author maintainer
#42 lore raw

RFC PATCH 14/16 x86/xen: support poweroff through poweroff handler call chain

In reply to Guenter Roeck

The kernel core now supports a poweroff handler call chain to remove power from the system. Call it if pm_power_off is set to NULL.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
---
 arch/x86/xen/enlighten.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/xen/enlighten.c +2 -0
index c0cb11f..645d00f 100644
@@ -1322,6 +1322,8 @@ static void xen_machine_power_off(void)
 {
 	if (pm_power_off)
 		pm_power_off();
+	else
+		do_kernel_poweroff();
 	xen_reboot(SHUTDOWN_poweroff);
 }
 
Signature · 1 line
1.9.1
author maintainer
#43 lore raw

RFC PATCH 15/16 power/reset: restart-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of seting pm_power_off directly. Register as poweroff handler of last resort since the driver does not really power off the system but executes a restart.

Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/restart-poweroff.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
drivers/power/reset/restart-poweroff.c +11 -13
index edd707e..82d058f 100644
@@ -12,35 +12,33 @@
  */
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/notifier.h>
 #include <linux/platform_device.h>
 #include <linux/of_platform.h>
 #include <linux/module.h>
 #include <linux/reboot.h>
-#include <asm/system_misc.h>
 
-static void restart_poweroff_do_poweroff(void)
+static int restart_poweroff_do_poweroff(struct notifier_block *this,
+					unsigned long unused1, void *unused2)
 {
 	reboot_mode = REBOOT_HARD;
 	machine_restart(NULL);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block restart_poweroff_handler = {
+	.notifier_call = restart_poweroff_do_poweroff,
+};
+
 static int restart_poweroff_probe(struct platform_device *pdev)
 {
-	/* If a pm_power_off function has already been added, leave it alone */
-	if (pm_power_off != NULL) {
-		dev_err(&pdev->dev,
-			"pm_power_off function already registered");
-		return -EBUSY;
-	}
-
-	pm_power_off = &restart_poweroff_do_poweroff;
-	return 0;
+	return register_restart_handler(&restart_poweroff_handler);
 }
 
 static int restart_poweroff_remove(struct platform_device *pdev)
 {
-	if (pm_power_off == &restart_poweroff_do_poweroff)
-		pm_power_off = NULL;
+	unregister_restart_handler(&restart_poweroff_handler);
 
 	return 0;
 }
Signature · 1 line
1.9.1
maintainer Acked-by on v1 15/16
#44 lore raw

Re: [RFC PATCH 15/16] power/reset: restart-poweroff: Register with kernel poweroff handler

Hi,

Quoted 8 lines · Guenter Roeck

Register with kernel poweroff handler instead of seting pm_power_off directly. Register as poweroff handler of last resort since the driver does not really power off the system but executes a restart.

Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>

-- 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/20141003/3e06131f/attachment.sig>

maintainer Acked-by on v1 15/16
#45 lore raw

Re: [RFC PATCH 15/16] power/reset: restart-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Hi,

Quoted 8 lines · Guenter Roeck

Register with kernel poweroff handler instead of seting pm_power_off directly. Register as poweroff handler of last resort since the driver does not really power off the system but executes a restart.

Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>

-- Sebastian

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author maintainer
#46 lore raw

RFC PATCH 15/16 power/reset: restart-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of seting pm_power_off directly. Register as poweroff handler of last resort since the driver does not really power off the system but executes a restart.

Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>
---
 drivers/power/reset/restart-poweroff.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
drivers/power/reset/restart-poweroff.c +11 -13
index edd707e..82d058f 100644
@@ -12,35 +12,33 @@
  */
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/notifier.h>
 #include <linux/platform_device.h>
 #include <linux/of_platform.h>
 #include <linux/module.h>
 #include <linux/reboot.h>
-#include <asm/system_misc.h>
 
-static void restart_poweroff_do_poweroff(void)
+static int restart_poweroff_do_poweroff(struct notifier_block *this,
+					unsigned long unused1, void *unused2)
 {
 	reboot_mode = REBOOT_HARD;
 	machine_restart(NULL);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block restart_poweroff_handler = {
+	.notifier_call = restart_poweroff_do_poweroff,
+};
+
 static int restart_poweroff_probe(struct platform_device *pdev)
 {
-	/* If a pm_power_off function has already been added, leave it alone */
-	if (pm_power_off != NULL) {
-		dev_err(&pdev->dev,
-			"pm_power_off function already registered");
-		return -EBUSY;
-	}
-
-	pm_power_off = &restart_poweroff_do_poweroff;
-	return 0;
+	return register_restart_handler(&restart_poweroff_handler);
 }
 
 static int restart_poweroff_remove(struct platform_device *pdev)
 {
-	if (pm_power_off == &restart_poweroff_do_poweroff)
-		pm_power_off = NULL;
+	unregister_restart_handler(&restart_poweroff_handler);
 
 	return 0;
 }
Signature · 1 line
1.9.1
author maintainer
#47 lore raw

RFC PATCH 16/16 mfd: palmas: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/palmas.c       | 30 +++++++++++++++++-------------
 include/linux/mfd/palmas.h |  3 +++
 2 files changed, 20 insertions(+), 13 deletions(-)
drivers/mfd/palmas.c +17 -13
index 28cb048..e8ef345a 100644
@@ -19,6 +19,7 @@
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
+#include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/err.h>
 #include <linux/mfd/core.h>
@@ -425,20 +426,18 @@ static void palmas_dt_to_pdata(struct i2c_client *i2c,
 			"ti,system-power-controller");
 }
 
-static struct palmas *palmas_dev;
-static void palmas_power_off(void)
+static int palmas_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
+	struct palmas *palmas = container_of(this, struct palmas, poweroff_nb);
 	unsigned int addr;
 	int ret, slave;
 
-	if (!palmas_dev)
-		return;
-
 	slave = PALMAS_BASE_TO_SLAVE(PALMAS_PMU_CONTROL_BASE);
 	addr = PALMAS_BASE_TO_REG(PALMAS_PMU_CONTROL_BASE, PALMAS_DEV_CTRL);
 
 	ret = regmap_update_bits(
-			palmas_dev->regmap[slave],
+			palmas->regmap[slave],
 			addr,
 			PALMAS_DEV_CTRL_DEV_ON,
 			0);
@@ -446,6 +445,8 @@ static void palmas_power_off(void)
 	if (ret)
 		pr_err("%s: Unable to write to DEV_CTRL_DEV_ON: %d\n",
 				__func__, ret);
+
+	return NOTIFY_DONE;
 }
 
 static unsigned int palmas_features = PALMAS_PMIC_FEATURE_SMPS10_BOOST;
@@ -668,9 +669,15 @@ no_irq:
 		ret = of_platform_populate(node, NULL, NULL, &i2c->dev);
 		if (ret < 0) {
 			goto err_irq;
-		} else if (pdata->pm_off && !pm_power_off) {
-			palmas_dev = palmas;
-			pm_power_off = palmas_power_off;
+		} else if (pdata->pm_off) {
+			palmas->poweroff_nb.notifier_call = palmas_power_off;
+			palmas->poweroff_nb.priority = 128;
+			ret = register_poweroff_handler(&palmas->poweroff_nb);
+			if (ret) {
+				dev_err(palmas->dev,
+					"cannot register poweroff handler");
+				ret = 0;
+			}
 		}
 	}
 
@@ -698,10 +705,7 @@ static int palmas_i2c_remove(struct i2c_client *i2c)
 			i2c_unregister_device(palmas->i2c_clients[i]);
 	}
 
-	if (palmas == palmas_dev) {
-		pm_power_off = NULL;
-		palmas_dev = NULL;
-	}
+	unregister_poweroff_handler(&palmas->poweroff_nb);
 
 	return 0;
 }
include/linux/mfd/palmas.h +3 -0
index fb0390a..4715057 100644
@@ -18,6 +18,7 @@
 
 #include <linux/usb/otg.h>
 #include <linux/leds.h>
+#include <linux/notifier.h>
 #include <linux/regmap.h>
 #include <linux/regulator/driver.h>
 #include <linux/extcon.h>
@@ -68,6 +69,8 @@ struct palmas {
 	struct i2c_client *i2c_clients[PALMAS_NUM_CLIENTS];
 	struct regmap *regmap[PALMAS_NUM_CLIENTS];
 
+	struct notifier_block poweroff_nb;
+
 	/* Stored chip id */
 	int id;
 
Signature · 1 line
1.9.1
author maintainer
#48 lore raw

RFC PATCH 16/16 mfd: palmas: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>
---
 drivers/mfd/palmas.c       | 30 +++++++++++++++++-------------
 include/linux/mfd/palmas.h |  3 +++
 2 files changed, 20 insertions(+), 13 deletions(-)
drivers/mfd/palmas.c +17 -13
index 28cb048..e8ef345a 100644
@@ -19,6 +19,7 @@
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
+#include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/err.h>
 #include <linux/mfd/core.h>
@@ -425,20 +426,18 @@ static void palmas_dt_to_pdata(struct i2c_client *i2c,
 			"ti,system-power-controller");
 }
 
-static struct palmas *palmas_dev;
-static void palmas_power_off(void)
+static int palmas_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
+	struct palmas *palmas = container_of(this, struct palmas, poweroff_nb);
 	unsigned int addr;
 	int ret, slave;
 
-	if (!palmas_dev)
-		return;
-
 	slave = PALMAS_BASE_TO_SLAVE(PALMAS_PMU_CONTROL_BASE);
 	addr = PALMAS_BASE_TO_REG(PALMAS_PMU_CONTROL_BASE, PALMAS_DEV_CTRL);
 
 	ret = regmap_update_bits(
-			palmas_dev->regmap[slave],
+			palmas->regmap[slave],
 			addr,
 			PALMAS_DEV_CTRL_DEV_ON,
 			0);
@@ -446,6 +445,8 @@ static void palmas_power_off(void)
 	if (ret)
 		pr_err("%s: Unable to write to DEV_CTRL_DEV_ON: %d\n",
 				__func__, ret);
+
+	return NOTIFY_DONE;
 }
 
 static unsigned int palmas_features = PALMAS_PMIC_FEATURE_SMPS10_BOOST;
@@ -668,9 +669,15 @@ no_irq:
 		ret = of_platform_populate(node, NULL, NULL, &i2c->dev);
 		if (ret < 0) {
 			goto err_irq;
-		} else if (pdata->pm_off && !pm_power_off) {
-			palmas_dev = palmas;
-			pm_power_off = palmas_power_off;
+		} else if (pdata->pm_off) {
+			palmas->poweroff_nb.notifier_call = palmas_power_off;
+			palmas->poweroff_nb.priority = 128;
+			ret = register_poweroff_handler(&palmas->poweroff_nb);
+			if (ret) {
+				dev_err(palmas->dev,
+					"cannot register poweroff handler");
+				ret = 0;
+			}
 		}
 	}
 
@@ -698,10 +705,7 @@ static int palmas_i2c_remove(struct i2c_client *i2c)
 			i2c_unregister_device(palmas->i2c_clients[i]);
 	}
 
-	if (palmas == palmas_dev) {
-		pm_power_off = NULL;
-		palmas_dev = NULL;
-	}
+	unregister_poweroff_handler(&palmas->poweroff_nb);
 
 	return 0;
 }
include/linux/mfd/palmas.h +3 -0
index fb0390a..4715057 100644
@@ -18,6 +18,7 @@
 
 #include <linux/usb/otg.h>
 #include <linux/leds.h>
+#include <linux/notifier.h>
 #include <linux/regmap.h>
 #include <linux/regulator/driver.h>
 #include <linux/extcon.h>
@@ -68,6 +69,8 @@ struct palmas {
 	struct i2c_client *i2c_clients[PALMAS_NUM_CLIENTS];
 	struct regmap *regmap[PALMAS_NUM_CLIENTS];
 
+	struct notifier_block poweroff_nb;
+
 	/* Stored chip id */
 	int id;
 
Signature · 1 line
1.9.1