Skip to contentSkip to conversation

kernel: Add support for poweroff handler call chain

PATCH Superseded Guenter Roeck 16 participants 103 messages Oct 21, 2014 – Oct 27, 2014 Page 1 of 2

Subsystems (58)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 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 means to remove power is supported (at least if pm_power_off is used). At least in theory there can be multiple means to remove power, some of which may be less desirable. For example, one mechanism might power off the entire system through an I/O port or gpio pin, while another might power off a board by disabling its power controller. Other mechanisms may really just execute a restart sequence or drop into the ROM monitor, or put the CPU into sleep mode. 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.

Patch 01/47 implements the poweroff handler API.

Patches 02/47 to 04/47 are cleanup patches to prepare for the move of pm_power_off to a common location.

Patches 05/47 to 07/47 remove references to pm_power_off from devicetree bindings descriptions.

Patch 08/47 moves the pm_power_off variable from architecture code to kernel/reboot.c.

Patches 09/47 to 34/47 convert various drivers to register with the kernel poweroff handler instead of setting pm_power_off directly.

Patches 35/47 to 46/47 do the same for architecture code.

Patch 47/47 finally removes pm_power_off.

For the most part, the individual patches include explanations why specific priorities were chosen, at least if the selected priority is not the default priority. Subsystem and architecture maintainers are encouraged to have a look at the selected priorities and suggest improvements.

I ran the final code through my normal build and qemu tests. Results are available at http://server.roeck-us.net:8010/builders in the 'poweroff-handler' column. I also built all available configurations for arm, mips, powerpc, m68k, and sh architectures.

The series is available in branch poweroff-handler of my repository at
git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git.
It is based on 3.18-rc1.

A note on Cc: In the initial submission I had way too many Cc:, causing the patchset to be treated as spam by many mailers and mailing list handlers, which of course defeated the purpose. This time around I am cutting down the distribution list down significantly. My apologies to anyone I may have failed to copy this time around.

Important changes since v1:
- Rebased series to v3.18-rc1.
- Use raw notifier with spinlock protection instead of atomic notifiers, since some poweroff handlers need to have interrupts enabled.
- Renamed API functions from _poweroff to _power_off.
- Added various Acks.
- Build tested all configurations for arm, powerpc, and mips architectures.
- Fixed two compile errors in mips patch.
- Replaced dev_err and pr_err with dev_warn and pr_warn if an error is not fatal.
- Provide managed resources API and use where appropriate.
- Provide and use definitions for standard priorities.
- Added patches to convert newly introduced poweroff handlers.
- Various minor changes.

Important changes since RFC:
- Move API to new file kernel/power/power_off_handler.c.
- Move pm_power_off pointer to kernel/power/power_off_handler.c. Call pm_power_off from do_kernel_power_off, and only call do_kernel_power_off from architecture code instead of calling both pm_power_off and do_kernel_power_off.
- Provide additional API function register_power_off_handler_simple to simplify conversion of architecture code.
- Provide additional API function have_kernel_power_off to check if a poweroff handler was installed.
- Convert all drivers and architecture code to use the new API.
- Remove pm_power_off as last patch of the series.

Cc Alan Cox <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
cc Heiko Stuebner <[email protected]>
Cc Lee Jones <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Rafael J. Wysocki <[email protected]>
Cc Romain Perier <[email protected]>

----------------------------------------------------------------
Guenter Roeck (47):
kernel: Add support for poweroff handler call chain
memory: emif: Use API function to determine poweroff capability
hibernate: Call have_kernel_power_off instead of checking pm_power_off
m68k: Replace mach_power_off with pm_power_off
mfd: as3722: Drop reference to pm_power_off from devicetree bindings
gpio-poweroff: Drop reference to pm_power_off from devicetree bindings
qnap-poweroff: Drop reference to pm_power_off from devicetree bindings
kernel: Move pm_power_off to common code
mfd: palmas: Register with kernel poweroff handler
mfd: axp20x: Register with kernel poweroff handler
mfd: retu: Register with kernel poweroff handler
mfd: ab8500-sysctrl: Register with kernel poweroff handler
mfd: max8907: Register with kernel poweroff handler
mfd: tps80031: Register with kernel poweroff handler
mfd: dm355evm_msp: Register with kernel poweroff handler
mfd: tps6586x: Register with kernel poweroff handler
mfd: tps65910: Register with kernel poweroff handler
mfd: twl4030-power: Register with kernel poweroff handler
mfd: rk808: Register poweroff handler with kernel poweroff handler
mfd: rn5t618: Register poweroff handler with kernel poweroff handler
ipmi: Register with kernel poweroff handler
power/reset: restart-poweroff: Register with kernel poweroff handler power/reset: gpio-poweroff: Register with kernel poweroff handler power/reset: as3722-poweroff: Register with kernel poweroff handler power/reset: qnap-poweroff: Register with kernel poweroff handler power/reset: msm-poweroff: Register with kernel poweroff handler power/reset: vexpress-poweroff: Register with kernel poweroff handler power/reset: at91-poweroff: Register with kernel poweroff handler power/reset: ltc2952-poweroff: Register with kernel poweroff handler
x86: iris: Register with kernel poweroff handler
x86: apm: Register with kernel poweroff handler
x86: olpc: Register xo1 poweroff handler with kernel poweroff handler
staging: nvec: Register with kernel poweroff handler
acpi: Register poweroff handler with kernel poweroff handler
arm: Register with kernel poweroff handler
arm64: psci: Register with kernel poweroff handler
avr32: atngw100: Register with kernel poweroff handler
ia64: Register with kernel poweroff handler
m68k: Register with kernel poweroff handler
mips: Register with kernel poweroff handler
sh: Register with kernel poweroff handler
x86: lguest: Register with kernel poweroff handler
x86: ce4100: Register with kernel poweroff handler
x86: intel-mid: Drop registration of dummy poweroff handlers
x86: pmc_atom: Register poweroff handler with kernel poweroff handler
efi: Register poweroff handler with kernel poweroff handler
kernel: Remove pm_power_off

 .../devicetree/bindings/gpio/gpio-poweroff.txt     |  10 +-
 Documentation/devicetree/bindings/mfd/as3722.txt   |   3 +-
 .../bindings/power_supply/qnap-poweroff.txt        |   3 +-
 arch/alpha/kernel/process.c                        |   9 +-
 arch/arc/kernel/reset.c                            |   5 +-
 arch/arm/kernel/process.c                          |   5 +-
 arch/arm/kernel/psci.c                             |   3 +-
 arch/arm/mach-at91/board-gsia18s.c                 |   3 +-
 arch/arm/mach-bcm/board_bcm2835.c                  |   3 +-
 arch/arm/mach-cns3xxx/cns3420vb.c                  |   3 +-
 arch/arm/mach-cns3xxx/core.c                       |   3 +-
 arch/arm/mach-highbank/highbank.c                  |   3 +-
 arch/arm/mach-imx/mach-mx31moboard.c               |   3 +-
 arch/arm/mach-iop32x/em7210.c                      |   3 +-
 arch/arm/mach-iop32x/glantank.c                    |   3 +-
 arch/arm/mach-iop32x/iq31244.c                     |   3 +-
 arch/arm/mach-iop32x/n2100.c                       |   3 +-
 arch/arm/mach-ixp4xx/dsmg600-setup.c               |   3 +-
 arch/arm/mach-ixp4xx/nas100d-setup.c               |   3 +-
 arch/arm/mach-ixp4xx/nslu2-setup.c                 |   3 +-
 arch/arm/mach-omap2/board-omap3touchbook.c         |   3 +-
 arch/arm/mach-orion5x/board-mss2.c                 |   3 +-
 arch/arm/mach-orion5x/dns323-setup.c               |   9 +-
 arch/arm/mach-orion5x/kurobox_pro-setup.c          |   3 +-
 arch/arm/mach-orion5x/ls-chl-setup.c               |   3 +-
 arch/arm/mach-orion5x/ls_hgl-setup.c               |   3 +-
 arch/arm/mach-orion5x/lsmini-setup.c               |   3 +-
 arch/arm/mach-orion5x/mv2120-setup.c               |   3 +-
 arch/arm/mach-orion5x/net2big-setup.c              |   3 +-
 arch/arm/mach-orion5x/terastation_pro2-setup.c     |   3 +-
 arch/arm/mach-orion5x/ts209-setup.c                |   3 +-
 arch/arm/mach-orion5x/ts409-setup.c                |   3 +-
 arch/arm/mach-pxa/corgi.c                          |   3 +-
 arch/arm/mach-pxa/mioa701.c                        |   3 +-
 arch/arm/mach-pxa/poodle.c                         |   3 +-
 arch/arm/mach-pxa/spitz.c                          |   3 +-
 arch/arm/mach-pxa/tosa.c                           |   3 +-
 arch/arm/mach-pxa/viper.c                          |   3 +-
 arch/arm/mach-pxa/z2.c                             |   7 +-
 arch/arm/mach-pxa/zeus.c                           |   7 +-
 arch/arm/mach-s3c24xx/mach-gta02.c                 |   3 +-
 arch/arm/mach-s3c24xx/mach-jive.c                  |   3 +-
 arch/arm/mach-s3c24xx/mach-vr1000.c                |   3 +-
 arch/arm/mach-s3c64xx/mach-smartq.c                |   3 +-
 arch/arm/mach-sa1100/generic.c                     |   3 +-
 arch/arm/mach-sa1100/simpad.c                      |   3 +-
 arch/arm/mach-u300/regulator.c                     |   3 +-
 arch/arm/mach-vt8500/vt8500.c                      |   3 +-
 arch/arm/xen/enlighten.c                           |   3 +-
 arch/arm64/kernel/process.c                        |   5 +-
 arch/arm64/kernel/psci.c                           |   3 +-
 arch/avr32/boards/atngw100/mrmt.c                  |   3 +-
 arch/avr32/kernel/process.c                        |   6 +-
 arch/blackfin/kernel/process.c                     |   3 -
 arch/blackfin/kernel/reboot.c                      |   2 +
 arch/c6x/kernel/process.c                          |   9 +-
 arch/cris/kernel/process.c                         |   4 +-
 arch/frv/kernel/process.c                          |   5 +-
 arch/hexagon/kernel/reset.c                        |   5 +-
 arch/ia64/kernel/process.c                         |   5 +-
 arch/ia64/sn/kernel/setup.c                        |   5 +-
 arch/m32r/kernel/process.c                         |   8 +-
 arch/m68k/emu/natfeat.c                            |   4 +-
 arch/m68k/include/asm/machdep.h                    |   1 -
 arch/m68k/kernel/process.c                         |   7 +-
 arch/m68k/kernel/setup_mm.c                        |   1 -
 arch/m68k/kernel/setup_no.c                        |   1 -
 arch/m68k/mac/config.c                             |   4 +-
 arch/metag/kernel/process.c                        |   6 +-
 arch/microblaze/kernel/process.c                   |   3 -
 arch/microblaze/kernel/reset.c                     |   1 +
 arch/mips/alchemy/board-gpr.c                      |   3 +-
 arch/mips/alchemy/board-mtx1.c                     |   3 +-
 arch/mips/alchemy/board-xxs1500.c                  |   3 +-
 arch/mips/alchemy/devboards/platform.c             |  17 +-
 arch/mips/ar7/setup.c                              |   3 +-
 arch/mips/ath79/setup.c                            |   3 +-
 arch/mips/bcm47xx/setup.c                          |   3 +-
 arch/mips/bcm63xx/setup.c                          |   3 +-
 arch/mips/cobalt/setup.c                           |   3 +-
 arch/mips/dec/setup.c                              |   3 +-
 arch/mips/emma/markeins/setup.c                    |   3 +-
 arch/mips/jz4740/reset.c                           |   3 +-
 arch/mips/kernel/reset.c                           |   6 +-
 arch/mips/lantiq/falcon/reset.c                    |   3 +-
 arch/mips/lantiq/xway/reset.c                      |   3 +-
 arch/mips/lasat/reset.c                            |   3 +-
 arch/mips/loongson/common/reset.c                  |   3 +-
 arch/mips/loongson1/common/reset.c                 |   3 +-
 arch/mips/mti-malta/malta-reset.c                  |   3 +-
 arch/mips/mti-sead3/sead3-reset.c                  |   3 +-
 arch/mips/netlogic/xlp/setup.c                     |   3 +-
 arch/mips/netlogic/xlr/setup.c                     |   3 +-
 arch/mips/pmcs-msp71xx/msp_setup.c                 |   3 +-
 arch/mips/pnx833x/common/setup.c                   |   3 +-
 arch/mips/ralink/reset.c                           |   3 +-
 arch/mips/rb532/setup.c                            |   3 +-
 arch/mips/sgi-ip22/ip22-reset.c                    |   3 +-
 arch/mips/sgi-ip27/ip27-reset.c                    |   3 +-
 arch/mips/sgi-ip32/ip32-reset.c                    |   3 +-
 arch/mips/sibyte/common/cfe.c                      |   3 +-
 arch/mips/sni/setup.c                              |   3 +-
 arch/mips/txx9/generic/setup.c                     |   3 +-
 arch/mips/vr41xx/common/pmu.c                      |   3 +-
 arch/mn10300/kernel/process.c                      |   8 +-
 arch/openrisc/kernel/process.c                     |   8 +-
 arch/parisc/kernel/process.c                       |   8 +-
 arch/powerpc/kernel/setup-common.c                 |   6 +-
 arch/s390/kernel/setup.c                           |   8 +-
 arch/score/kernel/process.c                        |   8 +-
 arch/sh/boards/board-sh7785lcr.c                   |   3 +-
 arch/sh/boards/board-urquell.c                     |   3 +-
 arch/sh/boards/mach-highlander/setup.c             |   3 +-
 arch/sh/boards/mach-landisk/setup.c                |   3 +-
 arch/sh/boards/mach-r2d/setup.c                    |   3 +-
 arch/sh/boards/mach-sdk7786/setup.c                |   3 +-
 arch/sh/kernel/reboot.c                            |   6 +-
 arch/sparc/kernel/process_32.c                     |  10 +-
 arch/sparc/kernel/reboot.c                         |   8 +-
 arch/tile/kernel/reboot.c                          |   7 +-
 arch/um/kernel/reboot.c                            |   2 -
 arch/unicore32/kernel/process.c                    |   9 +-
 arch/x86/kernel/apm_32.c                           |  20 +-
 arch/x86/kernel/pmc_atom.c                         |  20 +-
 arch/x86/kernel/reboot.c                           |  11 +-
 arch/x86/lguest/boot.c                             |   3 +-
 arch/x86/platform/ce4100/ce4100.c                  |   3 +-
 arch/x86/platform/intel-mid/intel-mid.c            |   5 -
 arch/x86/platform/intel-mid/mfld.c                 |   5 -
 arch/x86/platform/iris/iris.c                      |  24 +-
 arch/x86/platform/olpc/olpc-xo1-pm.c               |  20 +-
 arch/x86/xen/enlighten.c                           |   3 +-
 arch/xtensa/kernel/process.c                       |   4 -
 drivers/acpi/sleep.c                               |  15 +-
 drivers/char/ipmi/ipmi_poweroff.c                  |  29 ++-
 drivers/firmware/efi/reboot.c                      |  23 +-
 drivers/memory/emif.c                              |   4 +-
 drivers/mfd/ab8500-sysctrl.c                       |  22 +-
 drivers/mfd/axp20x.c                               |  30 +--
 drivers/mfd/dm355evm_msp.c                         |  18 +-
 drivers/mfd/max8907.c                              |  24 +-
 drivers/mfd/palmas.c                               |  31 +--
 drivers/mfd/retu-mfd.c                             |  33 +--
 drivers/mfd/rk808.c                                |  30 +--
 drivers/mfd/rn5t618.c                              |  32 +--
 drivers/mfd/tps6586x.c                             |  31 ++-
 drivers/mfd/tps65910.c                             |  27 ++-
 drivers/mfd/tps80031.c                             |  30 ++-
 drivers/mfd/twl4030-power.c                        |  29 ++-
 drivers/parisc/power.c                             |   3 +-
 drivers/power/reset/as3722-poweroff.c              |  39 ++--
 drivers/power/reset/at91-poweroff.c                |  16 +-
 drivers/power/reset/gpio-poweroff.c                |  40 ++--
 drivers/power/reset/ltc2952-poweroff.c             |  27 ++-
 drivers/power/reset/msm-poweroff.c                 |  13 +-
 drivers/power/reset/qnap-poweroff.c                |  32 +--
 drivers/power/reset/restart-poweroff.c             |  33 ++-
 drivers/power/reset/vexpress-poweroff.c            |  19 +-
 drivers/staging/nvec/nvec.c                        |  24 +-
 drivers/staging/nvec/nvec.h                        |   2 +
 include/linux/i2c/twl.h                            |   1 -
 include/linux/mfd/axp20x.h                         |   1 +
 include/linux/mfd/max8907.h                        |   2 +
 include/linux/mfd/palmas.h                         |   3 +
 include/linux/mfd/rk808.h                          |   2 +
 include/linux/mfd/rn5t618.h                        |   2 +
 include/linux/mfd/tps65910.h                       |   3 +
 include/linux/mfd/tps80031.h                       |   2 +
 include/linux/pm.h                                 |  23 +-
 kernel/power/Makefile                              |   1 +
 kernel/power/hibernate.c                           |   2 +-
 kernel/power/poweroff_handler.c                    | 252 +++++++++++++++++++++
 kernel/reboot.c                                    |   4 +-
 173 files changed, 1017 insertions(+), 546 deletions(-)
 create mode 100644 kernel/power/poweroff_handler.c
#1 lore raw

PATCH v2 1/47 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 Alan Cox <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
cc Heiko Stuebner <[email protected]>
Cc Lee Jones <[email protected]>
Cc Len Brown <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Philippe Rétornaz <[email protected]>
Cc Rafael J. Wysocki <[email protected]>
Cc Romain Perier <[email protected]>

---
v2:
- poweroff -> power_off
- Add defines for default priorities
- Use raw notifiers protected by spinlocks instead of atomic notifiers
- Add register_poweroff_handler_simple
- Add devm_register_power_off_handler

 include/linux/pm.h              |  22 ++++
 kernel/power/Makefile           |   1 +
 kernel/power/poweroff_handler.c | 252 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 275 insertions(+)
 create mode 100644 kernel/power/poweroff_handler.c
include/linux/pm.h +22 -0
index 383fd68..7e0cb36 100644
@@ -34,7 +34,29 @@
 extern void (*pm_power_off)(void);
 extern void (*pm_power_off_prepare)(void);
 
+/*
+ * Callbacks to manage poweroff handlers
+ */
+
+struct notifier_block;
 struct device; /* we have a circular dep with device.h */
+
+int register_power_off_handler(struct notifier_block *);
+int devm_register_power_off_handler(struct device *, struct notifier_block *);
+int register_power_off_handler_simple(void (*function)(void), int priority);
+int unregister_power_off_handler(struct notifier_block *);
+void do_kernel_power_off(void);
+bool have_kernel_power_off(void);
+
+/*
+ * Pre-defined poweroff handler priorities
+ */
+#define POWEROFF_PRIORITY_FALLBACK	0
+#define POWEROFF_PRIORITY_LOW		64
+#define POWEROFF_PRIORITY_DEFAULT	128
+#define POWEROFF_PRIORITY_HIGH		192
+#define POWEROFF_PRIORITY_HIGHEST	255
+
 #ifdef CONFIG_VT_CONSOLE_SLEEP
 extern void pm_vt_switch_required(struct device *dev, bool required);
 extern void pm_vt_switch_unregister(struct device *dev);
kernel/power/Makefile +1 -0
index 29472bf..4d9f0c7 100644
@@ -2,6 +2,7 @@
 ccflags-$(CONFIG_PM_DEBUG)	:= -DDEBUG
 
 obj-y				+= qos.o
+obj-y				+= poweroff_handler.o
 obj-$(CONFIG_PM)		+= main.o
 obj-$(CONFIG_VT_CONSOLE_SLEEP)	+= console.o
 obj-$(CONFIG_FREEZER)		+= process.o
kernel/power/poweroff_handler.c new file +252 -0

252 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

Hello

[...]

Quoted 1 line

- Use raw notifiers protected by spinlocks instead of atomic notifiers

[...]

Quoted 7 lines
kernel/power/poweroff_handler.c new file +7 -0
+/**
+ *	do_kernel_power_off - Execute kernel poweroff handler call chain
+ *
+ *	Calls functions registered with register_power_off_handler.
+ *
+ *	Expected to be called from machine_power_off as last step of
+ *	the poweroff sequence.

kernel/power/poweroff_handler.c line 241

Quoted 10 lines
kernel/power/poweroff_handler.c new file +10 -0
+ *
+ *	Powers off the system immediately if a poweroff handler function
+ *	has been registered. Otherwise does nothing.
+ */
+void do_kernel_power_off(void)
+{
+	spin_lock(&power_off_handler_lock);
+	raw_notifier_call_chain(&power_off_handler_list, 0, NULL);
+	spin_unlock(&power_off_handler_lock);
+}

I don't get it. You are still in atomic context inside the poweroff callback since you lock it with a spinlock.

It does not change much from the atomic notifier which was doing exactly the same thing but with RCU:

   rcu_read_lock();
   ret = notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls);
   rcu_read_unlock();

Why not using the blocking_notifier_* family ?
It will lock with a read-write semaphore under which you can sleep.

For instance, twl4030_power_off will sleep, since it is doing I2C access. So you cannot call it in atomic context.

Thanks,

Philippe

#3 lore raw
Quoted 34 lines · Philippe Rétornaz

Hello

[...]

Quoted 1 line

- Use raw notifiers protected by spinlocks instead of atomic notifiers

[...]

Quoted 7 lines
kernel/power/poweroff_handler.c new file +7 -0
+/**
+ *    do_kernel_power_off - Execute kernel poweroff handler call chain
+ *
+ *    Calls functions registered with register_power_off_handler.
+ *
+ *    Expected to be called from machine_power_off as last step of
+ *    the poweroff sequence.

kernel/power/poweroff_handler.c line 241

Quoted 10 lines
kernel/power/poweroff_handler.c new file +10 -0
+ *
+ *    Powers off the system immediately if a poweroff handler function
+ *    has been registered. Otherwise does nothing.
+ */
+void do_kernel_power_off(void)
+{
+    spin_lock(&power_off_handler_lock);
+    raw_notifier_call_chain(&power_off_handler_list, 0, NULL);
+    spin_unlock(&power_off_handler_lock);
+}

I don't get it. You are still in atomic context inside the poweroff callback since you lock it with a spinlock.

It does not change much from the atomic notifier which was doing exactly the same thing but with RCU:

    rcu_read_lock();
    ret = notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls);
    rcu_read_unlock();
Quoted 6 lines

Why not using the blocking_notifier_* family ?
It will lock with a read-write semaphore under which you can sleep.

For instance, twl4030_power_off will sleep, since it is doing I2C access. So you cannot call it in atomic context.

Learning something new all the time. I assumed that spin_lock (unlike spin_lock_irqsafe) would not run in atomic context.

I did not want to use a sleeping lock because I am not sure if that works for all architectures; some disable (local) interrupts before calling the function (eg arm and arm64), and I don't want to change that semantics.

I have another idea how to get there without changing the lock situation while executing the call chain - just set a flag indicating that it is running and execute it without lock. Would that work ?

Guenter

#4 lore raw
Quoted 28 lines · Guenter Roeck
Quoted 27 lines · Philippe Rétornaz

Hello

[...]

Quoted 1 line

- Use raw notifiers protected by spinlocks instead of atomic notifiers

[...]

Quoted 7 lines
kernel/power/poweroff_handler.c new file +7 -0
+/**
+ *    do_kernel_power_off - Execute kernel poweroff handler call chain
+ *
+ *    Calls functions registered with register_power_off_handler.
+ *
+ *    Expected to be called from machine_power_off as last step of
+ *    the poweroff sequence.

kernel/power/poweroff_handler.c line 241

Quoted 10 lines
kernel/power/poweroff_handler.c new file +10 -0
+ *
+ *    Powers off the system immediately if a poweroff handler function
+ *    has been registered. Otherwise does nothing.
+ */
+void do_kernel_power_off(void)
+{
+    spin_lock(&power_off_handler_lock);
+    raw_notifier_call_chain(&power_off_handler_list, 0, NULL);
+    spin_unlock(&power_off_handler_lock);
+}

I don't get it. You are still in atomic context inside the poweroff callback
since you lock it with a spinlock.

[...]

Quoted 8 lines
Quoted 7 lines

Why not using the blocking_notifier_* family ?
It will lock with a read-write semaphore under which you can sleep.

For instance, twl4030_power_off will sleep, since it is doing I2C access. So you cannot call it in atomic context.

Quoted 7 lines

Learning something new all the time. I assumed that spin_lock (unlike spin_lock_irqsafe) would not run in atomic context.

I did not want to use a sleeping lock because I am not sure if that works for all architectures; some disable (local) interrupts before calling the function (eg arm and arm64), and I don't want to change that semantics.

You're right and it even disable all others CPUs (if any). I don't understand why it needs to disable local interrupts since the code path to pm_power_off is simply doing:

syscall -> migrate to reboot cpu -> disable local interrupt -> disable others cpu -> pm_power_off().

I don't understand why we cannot re-enable interrupts right before pm_power_off(). And it looks like that all pm_power_off callbacks which can sleep are broken. I still wonder how i2c communication can works without local interrupts ... it looks like somebody is re-enabling them (or the code was never run)

Quoted 3 lines

I have another idea how to get there without changing the lock situation while executing the call chain - just set a flag indicating that it is running and execute it without lock. Would that work ?

I don't think inventing a new locking mechanism is a good solution. We need first to know for sure if we can sleep or not in pm_power_off. If yes then we need to re-enable local interrupts and we can use a mutex. If not then the atomic notifier is fine and a lots of drivers are wrong.

Thanks,

Philippe

#5 lore raw
Quoted 50 lines · Philippe Rétornaz
Quoted 28 lines · Guenter Roeck
Quoted 27 lines · Philippe Rétornaz

Hello

[...]

Quoted 1 line

- Use raw notifiers protected by spinlocks instead of atomic notifiers

[...]

Quoted 7 lines
kernel/power/poweroff_handler.c new file +7 -0
+/**
+ *    do_kernel_power_off - Execute kernel poweroff handler call chain
+ *
+ *    Calls functions registered with register_power_off_handler.
+ *
+ *    Expected to be called from machine_power_off as last step of
+ *    the poweroff sequence.

kernel/power/poweroff_handler.c line 241

Quoted 10 lines
kernel/power/poweroff_handler.c new file +10 -0
+ *
+ *    Powers off the system immediately if a poweroff handler function
+ *    has been registered. Otherwise does nothing.
+ */
+void do_kernel_power_off(void)
+{
+    spin_lock(&power_off_handler_lock);
+    raw_notifier_call_chain(&power_off_handler_list, 0, NULL);
+    spin_unlock(&power_off_handler_lock);
+}

I don't get it. You are still in atomic context inside the poweroff callback
since you lock it with a spinlock.

[...]

Quoted 8 lines
Quoted 7 lines

Why not using the blocking_notifier_* family ?
It will lock with a read-write semaphore under which you can sleep.

For instance, twl4030_power_off will sleep, since it is doing I2C access. So you cannot call it in atomic context.

Quoted 7 lines

Learning something new all the time. I assumed that spin_lock (unlike spin_lock_irqsafe) would not run in atomic context.

I did not want to use a sleeping lock because I am not sure if that works for all architectures; some disable (local) interrupts before calling the function (eg arm and arm64), and I don't want to change that semantics.

You're right and it even disable all others CPUs (if any). I don't understand why it needs to disable local interrupts since the code path to pm_power_off is simply doing:

Quoted 7 lines

syscall -> migrate to reboot cpu -> disable local interrupt -> disable others cpu -> pm_power_off().

I don't understand why we cannot re-enable interrupts right before pm_power_off(). And it looks like that all pm_power_off callbacks which can sleep are broken. I still wonder how i2c communication can works without local interrupts ... it looks like somebody is re-enabling them (or the code was never run)

Good question. Or the code was never run under arm, or the drivers have a polling fallback if interrupts are disabled.

Quoted 9 lines
Quoted 3 lines

I have another idea how to get there without changing the lock situation while executing the call chain - just set a flag indicating that it is running and execute it without lock. Would that work ?

I don't think inventing a new locking mechanism is a good solution. We need first to know for sure if we can sleep or not in pm_power_off. If yes then we need to re-enable local interrupts and we can use a mutex. If not then the atomic notifier is fine and a lots of drivers are wrong.

I had another look into the kernel, checking all the callers of machine_power_off(). In some cases, the function is called directly from interrupt handlers, meaning there is no guarantee that interrupts are enabled to start with when it is called. So there is more to fix if the semantics of pm_power_off requires interrupts to be enabled.

My current solution is to use a spinlock with disabled interrupts during poweroff handler registration and unregistration, and no lock at all while executing the call chain. That is not perfect, but it retains the current situation and thus guarantees that existing code works as before. This disconnects the sleep vs. no sleep problem from the current patch series, and we can solve that problem separately.

Thanks,
Guenter

#6 lore raw
In reply to Guenter Roeck
Quoted 2 lines · Guenter Roeck

v2:
- poweroff -> power_off

Do you want to stick to power[-_ ]off consistently throughout?

Quoted 16 lines

- Add defines for default priorities
- Use raw notifiers protected by spinlocks instead of atomic notifiers
- Add register_poweroff_handler_simple
- Add devm_register_power_off_handler

 include/linux/pm.h              |  22 ++++
 kernel/power/Makefile           |   1 +
 kernel/power/poweroff_handler.c | 252 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 275 insertions(+)
 create mode 100644 kernel/power/poweroff_handler.c
include/linux/pm.h +0 -0
index 383fd68..7e0cb36 100644

include/linux/pm.h line 38

Quoted 5 lines
include/linux/pm.h +2 -0
@@ -34,7 +34,29 @@
 extern void (*pm_power_off)(void);
 extern void (*pm_power_off_prepare)(void);
 
+/*
+ * Callbacks to manage poweroff handlers

power-off

Quoted 4 lines
include/linux/pm.h +3 -0
+ */
+
+struct notifier_block;
 struct device; /* we have a circular dep with device.h */

include/linux/pm.h line 52

Quoted 10 lines
include/linux/pm.h +10 -0
+
+int register_power_off_handler(struct notifier_block *);
+int devm_register_power_off_handler(struct device *, struct notifier_block *);
+int register_power_off_handler_simple(void (*function)(void), int priority);
+int unregister_power_off_handler(struct notifier_block *);
+void do_kernel_power_off(void);
+bool have_kernel_power_off(void);
+
+/*
+ * Pre-defined poweroff handler priorities

power-off

include/linux/pm.h line 58

Quoted 6 lines
include/linux/pm.h +6 -0
+ */
+#define POWEROFF_PRIORITY_FALLBACK	0
+#define POWEROFF_PRIORITY_LOW		64
+#define POWEROFF_PRIORITY_DEFAULT	128
+#define POWEROFF_PRIORITY_HIGH		192
+#define POWEROFF_PRIORITY_HIGHEST	255

I think at least these ones should match the interface function and have a POWER_OFF_PRIORITY_ prefix.

kernel/power/poweroff_handler.c

Quoted 21 lines
include/linux/pm.h +1 -0
+
 #ifdef CONFIG_VT_CONSOLE_SLEEP
 extern void pm_vt_switch_required(struct device *dev, bool required);
 extern void pm_vt_switch_unregister(struct device *dev);
kernel/power/Makefile +1 -0
index 29472bf..4d9f0c7 100644
@@ -2,6 +2,7 @@
 ccflags-$(CONFIG_PM_DEBUG)	:= -DDEBUG
 
 obj-y				+= qos.o
+obj-y				+= poweroff_handler.o
 obj-$(CONFIG_PM)		+= main.o
 obj-$(CONFIG_VT_CONSOLE_SLEEP)	+= console.o
 obj-$(CONFIG_FREEZER)		+= process.o
kernel/power/poweroff_handler.c new file +0 -0
new file mode 100644
index 0000000..aeb4736

power_off_handler.c?

kernel/power/poweroff_handler.c line 12

Quoted 13 lines
kernel/power/poweroff_handler.c new file +12 -0
@@ -0,0 +1,252 @@
+/*
+ * linux/kernel/power/poweroff_handler.c - Poweroff handling functions
+ *
+ * Copyright (c) 2014 Guenter Roeck
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#define pr_fmt(fmt)	"poweroff: " fmt

power-off:?

There's a bunch of these introduced by the driver patches as well (e.g. poweroff_nb).

Johan

#7 lore raw
Quoted 6 lines · Johan Hovold
Quoted 2 lines · Guenter Roeck

v2:
- poweroff -> power_off

Do you want to stick to power[-_ ]off consistently throughout?

I guess you'll want to fix all of these before I review the MFD patches?

Quoted 19 lines
Quoted 19 lines

- Add defines for default priorities
- Use raw notifiers protected by spinlocks instead of atomic notifiers
- Add register_poweroff_handler_simple
- Add devm_register_power_off_handler

 include/linux/pm.h              |  22 ++++
 kernel/power/Makefile           |   1 +
 kernel/power/poweroff_handler.c | 252 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 275 insertions(+)
 create mode 100644 kernel/power/poweroff_handler.c
include/linux/pm.h +0 -0
index 383fd68..7e0cb36 100644
@@ -34,7 +34,29 @@
 extern void (*pm_power_off)(void);
 extern void (*pm_power_off_prepare)(void);
 
Quoted 4 lines

include/linux/pm.h line 38

Quoted 2 lines
include/linux/pm.h +2 -0
+/*
+ * Callbacks to manage poweroff handlers

power-off

power_off, no?

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#8 lore raw
Quoted 31 lines · Lee Jones
Quoted 6 lines · Johan Hovold
Quoted 2 lines · Guenter Roeck

v2:
- poweroff -> power_off

Do you want to stick to power[-_ ]off consistently throughout?

I guess you'll want to fix all of these before I review the MFD patches?

Quoted 19 lines
Quoted 19 lines

- Add defines for default priorities
- Use raw notifiers protected by spinlocks instead of atomic notifiers
- Add register_poweroff_handler_simple
- Add devm_register_power_off_handler

  include/linux/pm.h              |  22 ++++
  kernel/power/Makefile           |   1 +
  kernel/power/poweroff_handler.c | 252 ++++++++++++++++++++++++++++++++++++++++
  3 files changed, 275 insertions(+)

create mode 100644 kernel/power/poweroff_handler.c

include/linux/pm.h +0 -0
index 383fd68..7e0cb36 100644
@@ -34,7 +34,29 @@
  extern void (*pm_power_off)(void);
  extern void (*pm_power_off_prepare)(void);
 
Quoted 7 lines
Quoted 4 lines

include/linux/pm.h line 38

Quoted 2 lines
include/linux/pm.h +2 -0
+/*
+ * Callbacks to manage poweroff handlers

power-off

power_off, no?

That is describing text, so hopefully I can use real words here and don't have to use a term derived from variable and function names.

Sure, I can change poweroff in all describing text to power-off if that is preferred, no big deal.

Thanks,
Guenter

#9 lore raw
In reply to Johan Hovold
Quoted 98 lines · Johan Hovold
Quoted 2 lines · Guenter Roeck

v2:
- poweroff -> power_off

Do you want to stick to power[-_ ]off consistently throughout?

Quoted 16 lines

- Add defines for default priorities
- Use raw notifiers protected by spinlocks instead of atomic notifiers
- Add register_poweroff_handler_simple
- Add devm_register_power_off_handler

  include/linux/pm.h              |  22 ++++
  kernel/power/Makefile           |   1 +
  kernel/power/poweroff_handler.c | 252 ++++++++++++++++++++++++++++++++++++++++
  3 files changed, 275 insertions(+)

create mode 100644 kernel/power/poweroff_handler.c

include/linux/pm.h +0 -0
index 383fd68..7e0cb36 100644

include/linux/pm.h line 38

Quoted 5 lines
include/linux/pm.h +2 -0
@@ -34,7 +34,29 @@
  extern void (*pm_power_off)(void);
  extern void (*pm_power_off_prepare)(void);
 
+/*
+ * Callbacks to manage poweroff handlers

power-off

Quoted 4 lines
include/linux/pm.h +3 -0
+ */
+
+struct notifier_block;
  struct device; /* we have a circular dep with device.h */

include/linux/pm.h line 52

Quoted 10 lines
include/linux/pm.h +10 -0
+
+int register_power_off_handler(struct notifier_block *);
+int devm_register_power_off_handler(struct device *, struct notifier_block *);
+int register_power_off_handler_simple(void (*function)(void), int priority);
+int unregister_power_off_handler(struct notifier_block *);
+void do_kernel_power_off(void);
+bool have_kernel_power_off(void);
+
+/*
+ * Pre-defined poweroff handler priorities

power-off

include/linux/pm.h line 58

Quoted 6 lines
include/linux/pm.h +6 -0
+ */
+#define POWEROFF_PRIORITY_FALLBACK	0
+#define POWEROFF_PRIORITY_LOW		64
+#define POWEROFF_PRIORITY_DEFAULT	128
+#define POWEROFF_PRIORITY_HIGH		192
+#define POWEROFF_PRIORITY_HIGHEST	255

I think at least these ones should match the interface function and have a POWER_OFF_PRIORITY_ prefix.

kernel/power/poweroff_handler.c

Quoted 21 lines
include/linux/pm.h +1 -0
+
  #ifdef CONFIG_VT_CONSOLE_SLEEP
  extern void pm_vt_switch_required(struct device *dev, bool required);
  extern void pm_vt_switch_unregister(struct device *dev);
kernel/power/Makefile +1 -0
index 29472bf..4d9f0c7 100644
@@ -2,6 +2,7 @@
  ccflags-$(CONFIG_PM_DEBUG)	:= -DDEBUG
 
  obj-y				+= qos.o
+obj-y				+= poweroff_handler.o
  obj-$(CONFIG_PM)		+= main.o
  obj-$(CONFIG_VT_CONSOLE_SLEEP)	+= console.o
  obj-$(CONFIG_FREEZER)		+= process.o
kernel/power/poweroff_handler.c new file +0 -0
new file mode 100644
index 0000000..aeb4736

power_off_handler.c?

kernel/power/poweroff_handler.c line 12

Quoted 13 lines
kernel/power/poweroff_handler.c new file +12 -0
@@ -0,0 +1,252 @@
+/*
+ * linux/kernel/power/poweroff_handler.c - Poweroff handling functions
+ *
+ * Copyright (c) 2014 Guenter Roeck
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#define pr_fmt(fmt)	"poweroff: " fmt

power-off:?

Quoted 3 lines

There's a bunch of these introduced by the driver patches as well (e.g. poweroff_nb).

I personally don't see a value in those changes, but sure, I can change all of it. Just hope that this won't cause someone else to request it to be changed back ;-).

Guenter

#10 lore raw
In reply to Johan Hovold
Quoted 7 lines · Johan Hovold
Quoted 2 lines · Guenter Roeck

v2:
- poweroff -> power_off

Do you want to stick to power[-_ ]off consistently throughout?

The string "poweroff" is used 819 times in today's upstream kernel. "power_off" is used 1,496 times, presumably mostly in variable names. "power-off" is used 145 times.

So, yes, I can change all newly introduced variable and function names from poweroff to power_off, and all newly introduced descriptive text from poweroff to power-off if that makes you happy. It won't improve consistency, though, since many of the current poweroff functions are named "something_poweroff". Hope you don't expect me to change all those function names as well.

Guenter

#11 lore raw
Quoted 13 lines · Guenter Roeck
Quoted 7 lines · Johan Hovold
Quoted 2 lines · Guenter Roeck

v2:
- poweroff -> power_off

Do you want to stick to power[-_ ]off consistently throughout?

The string "poweroff" is used 819 times in today's upstream kernel. "power_off" is used 1,496 times, presumably mostly in variable names. "power-off" is used 145 times.

Quoted 6 lines

So, yes, I can change all newly introduced variable and function names from poweroff to power_off, and all newly introduced descriptive text from poweroff to power-off if that makes you happy. It won't improve consistency, though, since many of the current poweroff functions are named "something_poweroff". Hope you don't expect me to change all those function names as well.

Consistency is always nice, even if it's just within the files and infrastructure you're adding.

But as already mentioned, the most important thing is that the interface is consistent (e.g. function and constant names).

Johan

#12 lore raw
In reply to Guenter Roeck
Quoted 17 lines · 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.

Quoted 8 lines

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.

Well, I must admit to having second thoughts regarding this particular mechanism. Namely, notifiers don't seem to be the best way of expressing what's needed from the design standpoint.

It looks like we need a list of power off methods and a way to select one of them, so it seems that using a plist would be a natural choice here?

Rafael

#13 lore raw

Am Dienstag, 21. Oktober 2014, 14:26:10 schrieb Rafael J. Wysocki:

Quoted 27 lines · Guenter Roeck
Quoted 17 lines

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.

Quoted 8 lines

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.

Quoted 6 lines

Well, I must admit to having second thoughts regarding this particular mechanism. Namely, notifiers don't seem to be the best way of expressing what's needed from the design standpoint.

It looks like we need a list of power off methods and a way to select one of them, so it seems that using a plist would be a natural choice here?

I actually like Guenter's approach of traversing a sorted list of poweroff methods until one of them really turns off the device.

For example, one device I work on has this strange mechanism where the device stays powered on while either a gpio is high or the device is connected to a host via usb - it cannot be turned off at all while it is connected via usb.

So the established way of handling poweroff there is to check the usb connection and either shutdown or restart [where the bootloader will enter a charging cycle and really poweroff the device once it gets disconnected].

If there is only one method to shutdown possible this device-specific behaviour would need to be encoded in some sort of poweroff driver, while with Guenter's current approach I could just register the gpio-poweroff at a higher priority which would then fall down to the lower priority restart if the device stays powered due to the usb connection.

Heiko

#14 lore raw
In reply to Rafael J. Wysocki
Quoted 27 lines · Rafael J. Wysocki
Quoted 17 lines · 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.

Quoted 8 lines

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.

Quoted 7 lines

Well, I must admit to having second thoughts regarding this particular mechanism. Namely, notifiers don't seem to be the best way of expressing what's needed from the design standpoint.

It looks like we need a list of power off methods and a way to select one of them, so it seems that using a plist would be a natural choice here?

Isn't a notifier call chain nothing but a list of methods, with its priority the means to select which one to use (first) ?

The only difference I can see is that you would only select one of them, meaning the one with the highest priority, and not try the others. Am I missing something ?

Thanks,
Guenter

#15 lore raw
Quoted 32 lines · Guenter Roeck
Quoted 31 lines · Rafael J. Wysocki
Quoted 17 lines · 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.

Quoted 8 lines

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.

Well, I must admit to having second thoughts regarding this particular mechanism. Namely, notifiers don't seem to be the best way of expressing what's needed from the design standpoint.

Quoted 5 lines
Quoted 3 lines

It looks like we need a list of power off methods and a way to select one of them, so it seems that using a plist would be a natural choice here?

Isn't a notifier call chain nothing but a list of methods, with its priority the means to select which one to use (first) ?

Traditionally, the idea behind notifier call chains has been to call all of the supplied methods (meaning whoever supplied them wants to be notified of events) where the higher-priority ones are called first.

In this particular case, though, we call them until one succeeds to power off the system it seems.

Quoted 2 lines

The only difference I can see is that you would only select one of them, meaning the one with the highest priority, and not try the others.

Yes, this was my thought.

But if you want a fallback mechanism, then I agree that using notifiers makes sense, although it is not exactly about notifications this time.

I would probably use something along the lines of syscore_ops, but with added execution priority.

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#16 lore raw
Quoted 46 lines · Rafael J. Wysocki
Quoted 32 lines · Guenter Roeck
Quoted 31 lines · Rafael J. Wysocki
Quoted 17 lines · 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.

Quoted 8 lines

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.

Well, I must admit to having second thoughts regarding this particular mechanism. Namely, notifiers don't seem to be the best way of expressing what's needed from the design standpoint.

Quoted 5 lines
Quoted 3 lines

It looks like we need a list of power off methods and a way to select one of them, so it seems that using a plist would be a natural choice here?

Isn't a notifier call chain nothing but a list of methods, with its priority the means to select which one to use (first) ?

Traditionally, the idea behind notifier call chains has been to call all of the supplied methods (meaning whoever supplied them wants to be notified of events) where the higher-priority ones are called first.

In this particular case, though, we call them until one succeeds to power off the system it seems.

Quoted 8 lines
Quoted 2 lines

The only difference I can see is that you would only select one of them, meaning the one with the highest priority, and not try the others.

Yes, this was my thought.

But if you want a fallback mechanism, then I agree that using notifiers makes sense, although it is not exactly about notifications this time.

It is the same machanism we are using for the newly introduced restart handler, with the same logic. Notifiers come handy, because the infrastructure is already there, but I consider that to be more of an implementation detail. It is useful in many cases, though, since the notifier_block can be part of a local data structure which can be referenced from the callback using container_of.

If I don't use notifiers, and the callback function doesn't get a reference to its control block, I don't get that reference, and another means to pass context data into the notifier function would be necessary - either a static variable, as widely used so far, or another parameter. While the current code of course permits the use of a static variable, I very much like that it is possible to avoid that by using notifiers.

Quoted 2 lines

I would probably use something along the lines of syscore_ops, but with added execution priority.

But wouldn't that mean to, for all practical purposes, re-implement a notifier call chain in syscore just for the purpose of naming it differently ?

Quoted 1 line

From a practical side, it would also be a bit awkward since syscore_ops are

typically not installed from the same file as the poweroff handler. So I would either have to rearrange code significantly, or install two sysore_ops handlers for the same architecture / platform. Hope it would be ok to do the latter; if the first approach is asked for, I'd rather only implement the core code and not do the full conversion, as it would add more risk than I think it adds value.

Guenter

#17 lore raw

PATCH v2 2/47 memory: emif: Use API function to determine poweroff capability

In reply to Guenter Roeck

Use have_kernel_power_off() to determine if the kernel is able to power off the system.

Cc Santosh Shilimkar <[email protected]>

---
v2:
- poweroff -> power_off

 drivers/memory/emif.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/memory/emif.c +2 -2
index 04644e7..874403a 100644
@@ -1053,10 +1053,10 @@ static irqreturn_t emif_threaded_isr(int irq, void *dev_id)
 		dev_emerg(emif->dev, "SDRAM temperature exceeds operating limit.. Needs shut down!!!\n");
 
 		/* If we have Power OFF ability, use it, else try restarting */
-		if (pm_power_off) {
+		if (have_kernel_power_off()) {
 			kernel_power_off();
 		} else {
-			WARN(1, "FIXME: NO pm_power_off!!! trying restart\n");
+			WARN(1, "FIXME: NO kernel poweroff capability!!! trying restart\n");
 			kernel_restart("SDRAM Over-temp Emergency restart");
 		}
 		return IRQ_HANDLED;
Signature · 1 line
1.9.1
#19 lore raw

Re: [PATCH v2 02/47] memory: emif: Use API function to determine poweroff capability

Quoted 6 lines · Santosh Shilimkar
Quoted 3 lines · Guenter Roeck

Use have_kernel_power_off() to determine if the kernel is able to power off the system.

Quoted 8 lines
Quoted 6 lines
Cc Santosh Shilimkar <[email protected]>

---
v2:
- poweroff -> power_off

Thanks!

Guenter

#20 lore raw

PATCH v2 3/47 hibernate: Call have_kernel_power_off instead of checking pm_power_off

In reply to Guenter Roeck

Poweroff handlers may now be installed with register_power_off_handler. Use the new API function have_kernel_power_off to determine if a poweroff handler has been installed.

---
v2:
- have_kernel_poweroff -> have_kernel_power_off

 kernel/power/hibernate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/hibernate.c +1 -1
index a9dfa79..69225b7 100644
@@ -602,7 +602,7 @@ static void power_down(void)
 	case HIBERNATION_PLATFORM:
 		hibernation_platform_enter();
 	case HIBERNATION_SHUTDOWN:
-		if (pm_power_off)
+		if (have_kernel_power_off())
 			kernel_power_off();
 		break;
 #ifdef CONFIG_SUSPEND
Signature · 1 line
1.9.1
#21 lore raw

PATCH v2 4/47 m68k: Replace mach_power_off with pm_power_off

In reply to Guenter Roeck

Replace mach_power_off with pm_power_off to simplify the subsequent move of pm_power_off to generic code.

Cc Geert Uytterhoeven <[email protected]>
Cc Greg Ungerer <[email protected]>
Cc Joshua Thompson <[email protected]>

---
v2:
- have_kernel_poweroff -> have_kernel_power_off

 arch/m68k/emu/natfeat.c         | 3 ++-
 arch/m68k/include/asm/machdep.h | 1 -
 arch/m68k/kernel/process.c      | 5 +++--
 arch/m68k/kernel/setup_mm.c     | 1 -
 arch/m68k/kernel/setup_no.c     | 1 -
 arch/m68k/mac/config.c          | 3 ++-
 6 files changed, 7 insertions(+), 7 deletions(-)
arch/m68k/emu/natfeat.c +2 -1
index 71b78ec..91e2ae7 100644
@@ -15,6 +15,7 @@
 #include <linux/string.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/io.h>
 #include <asm/machdep.h>
 #include <asm/natfeat.h>
@@ -90,5 +91,5 @@ void __init nf_init(void)
 	pr_info("NatFeats found (%s, %lu.%lu)\n", buf, version >> 16,
 		version & 0xffff);
 
-	mach_power_off = nf_poweroff;
+	pm_power_off = nf_poweroff;
 }
arch/m68k/include/asm/machdep.h +0 -1
index 953ca21..f9fac51 100644
@@ -24,7 +24,6 @@ extern int (*mach_set_rtc_pll)(struct rtc_pll_info *);
 extern int (*mach_set_clock_mmss)(unsigned long);
 extern void (*mach_reset)( void );
 extern void (*mach_halt)( void );
-extern void (*mach_power_off)( void );
 extern unsigned long (*mach_hd_init) (unsigned long, unsigned long);
 extern void (*mach_hd_setup)(char *, int *);
 extern long mach_max_dma_address;
arch/m68k/kernel/process.c +3 -2
index c55ff71..afe3d6e 100644
@@ -22,6 +22,7 @@
 #include <linux/unistd.h>
 #include <linux/ptrace.h>
 #include <linux/user.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/init_task.h>
 #include <linux/mqueue.h>
@@ -77,8 +78,8 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (mach_power_off)
-		mach_power_off();
+	if (pm_power_off)
+		pm_power_off();
 	for (;;);
 }
 
arch/m68k/kernel/setup_mm.c +0 -1
index 5b8ec4d..002fea6 100644
@@ -96,7 +96,6 @@ EXPORT_SYMBOL(mach_get_rtc_pll);
 EXPORT_SYMBOL(mach_set_rtc_pll);
 void (*mach_reset)( void );
 void (*mach_halt)( void );
-void (*mach_power_off)( void );
 long mach_max_dma_address = 0x00ffffff; /* default set to the lower 16MB */
 #ifdef CONFIG_HEARTBEAT
 void (*mach_heartbeat) (int);
arch/m68k/kernel/setup_no.c +0 -1
index 88c27d9..1520156 100644
@@ -55,7 +55,6 @@ int (*mach_hwclk) (int, struct rtc_time*);
 /* machine dependent reboot functions */
 void (*mach_reset)(void);
 void (*mach_halt)(void);
-void (*mach_power_off)(void);
 
 #ifdef CONFIG_M68000
 #if defined(CONFIG_M68328)
arch/m68k/mac/config.c +2 -1
index a471eab..677913ff 100644
@@ -16,6 +16,7 @@
 #include <linux/tty.h>
 #include <linux/console.h>
 #include <linux/interrupt.h>
+#include <linux/pm.h>
 /* keyb */
 #include <linux/random.h>
 #include <linux/delay.h>
@@ -159,7 +160,7 @@ void __init config_mac(void)
 	mach_set_clock_mmss = mac_set_clock_mmss;
 	mach_reset = mac_reset;
 	mach_halt = mac_poweroff;
-	mach_power_off = mac_poweroff;
+	pm_power_off = mac_poweroff;
 	mach_max_dma_address = 0xffffffff;
 #if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
 	mach_beep = mac_mksound;
Signature · 1 line
1.9.1
Acked-by on v2 4/47
#22 lore raw

Re: [PATCH v2 04/47] m68k: Replace mach_power_off with pm_power_off

Hi Guenter,

Quoted 8 lines · Guenter Roeck

Replace mach_power_off with pm_power_off to simplify the subsequent move of pm_power_off to generic code.

Cc Geert Uytterhoeven <[email protected]>
Cc Greg Ungerer <[email protected]>
Cc Joshua Thompson <[email protected]>

I have no problem with the non-MMU affected parts.

Regards
Greg

Quoted 112 lines

---
v2:
- have_kernel_poweroff -> have_kernel_power_off

 arch/m68k/emu/natfeat.c         | 3 ++-
 arch/m68k/include/asm/machdep.h | 1 -
 arch/m68k/kernel/process.c      | 5 +++--
 arch/m68k/kernel/setup_mm.c     | 1 -
 arch/m68k/kernel/setup_no.c     | 1 -
 arch/m68k/mac/config.c          | 3 ++-
 6 files changed, 7 insertions(+), 7 deletions(-)
arch/m68k/emu/natfeat.c +2 -1
index 71b78ec..91e2ae7 100644
@@ -15,6 +15,7 @@
 #include <linux/string.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/io.h>
 #include <asm/machdep.h>
 #include <asm/natfeat.h>
@@ -90,5 +91,5 @@ void __init nf_init(void)
 	pr_info("NatFeats found (%s, %lu.%lu)\n", buf, version >> 16,
 		version & 0xffff);
 
-	mach_power_off = nf_poweroff;
+	pm_power_off = nf_poweroff;
 }
arch/m68k/include/asm/machdep.h +0 -1
index 953ca21..f9fac51 100644
@@ -24,7 +24,6 @@ extern int (*mach_set_rtc_pll)(struct rtc_pll_info *);
 extern int (*mach_set_clock_mmss)(unsigned long);
 extern void (*mach_reset)( void );
 extern void (*mach_halt)( void );
-extern void (*mach_power_off)( void );
 extern unsigned long (*mach_hd_init) (unsigned long, unsigned long);
 extern void (*mach_hd_setup)(char *, int *);
 extern long mach_max_dma_address;
arch/m68k/kernel/process.c +3 -2
index c55ff71..afe3d6e 100644
@@ -22,6 +22,7 @@
 #include <linux/unistd.h>
 #include <linux/ptrace.h>
 #include <linux/user.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/init_task.h>
 #include <linux/mqueue.h>
@@ -77,8 +78,8 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (mach_power_off)
-		mach_power_off();
+	if (pm_power_off)
+		pm_power_off();
 	for (;;);
 }
 
arch/m68k/kernel/setup_mm.c +0 -1
index 5b8ec4d..002fea6 100644
@@ -96,7 +96,6 @@ EXPORT_SYMBOL(mach_get_rtc_pll);
 EXPORT_SYMBOL(mach_set_rtc_pll);
 void (*mach_reset)( void );
 void (*mach_halt)( void );
-void (*mach_power_off)( void );
 long mach_max_dma_address = 0x00ffffff; /* default set to the lower 16MB */
 #ifdef CONFIG_HEARTBEAT
 void (*mach_heartbeat) (int);
arch/m68k/kernel/setup_no.c +0 -1
index 88c27d9..1520156 100644
@@ -55,7 +55,6 @@ int (*mach_hwclk) (int, struct rtc_time*);
 /* machine dependent reboot functions */
 void (*mach_reset)(void);
 void (*mach_halt)(void);
-void (*mach_power_off)(void);
 
 #ifdef CONFIG_M68000
 #if defined(CONFIG_M68328)
arch/m68k/mac/config.c +2 -1
index a471eab..677913ff 100644
@@ -16,6 +16,7 @@
 #include <linux/tty.h>
 #include <linux/console.h>
 #include <linux/interrupt.h>
+#include <linux/pm.h>
 /* keyb */
 #include <linux/random.h>
 #include <linux/delay.h>
@@ -159,7 +160,7 @@ void __init config_mac(void)
 	mach_set_clock_mmss = mac_set_clock_mmss;
 	mach_reset = mac_reset;
 	mach_halt = mac_poweroff;
-	mach_power_off = mac_poweroff;
+	pm_power_off = mac_poweroff;
 	mach_max_dma_address = 0xffffffff;
 #if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
 	mach_beep = mac_mksound;
Acked-by on v2 4/47
#23 lore raw

Re: [PATCH v2 04/47] m68k: Replace mach_power_off with pm_power_off

In reply to Guenter Roeck

Hi Guenter,

Quoted 8 lines · Guenter Roeck

Replace mach_power_off with pm_power_off to simplify the subsequent move of pm_power_off to generic code.

Cc Geert Uytterhoeven <[email protected]>
Cc Greg Ungerer <[email protected]>
Cc Joshua Thompson <[email protected]>

I have no problem with the non-MMU affected parts.

Regards
Greg

Quoted 112 lines

---
v2:
- have_kernel_poweroff -> have_kernel_power_off

 arch/m68k/emu/natfeat.c         | 3 ++-
 arch/m68k/include/asm/machdep.h | 1 -
 arch/m68k/kernel/process.c      | 5 +++--
 arch/m68k/kernel/setup_mm.c     | 1 -
 arch/m68k/kernel/setup_no.c     | 1 -
 arch/m68k/mac/config.c          | 3 ++-
 6 files changed, 7 insertions(+), 7 deletions(-)
arch/m68k/emu/natfeat.c +2 -1
index 71b78ec..91e2ae7 100644
@@ -15,6 +15,7 @@
 #include <linux/string.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/io.h>
 #include <asm/machdep.h>
 #include <asm/natfeat.h>
@@ -90,5 +91,5 @@ void __init nf_init(void)
 	pr_info("NatFeats found (%s, %lu.%lu)\n", buf, version >> 16,
 		version & 0xffff);
 
-	mach_power_off = nf_poweroff;
+	pm_power_off = nf_poweroff;
 }
arch/m68k/include/asm/machdep.h +0 -1
index 953ca21..f9fac51 100644
@@ -24,7 +24,6 @@ extern int (*mach_set_rtc_pll)(struct rtc_pll_info *);
 extern int (*mach_set_clock_mmss)(unsigned long);
 extern void (*mach_reset)( void );
 extern void (*mach_halt)( void );
-extern void (*mach_power_off)( void );
 extern unsigned long (*mach_hd_init) (unsigned long, unsigned long);
 extern void (*mach_hd_setup)(char *, int *);
 extern long mach_max_dma_address;
arch/m68k/kernel/process.c +3 -2
index c55ff71..afe3d6e 100644
@@ -22,6 +22,7 @@
 #include <linux/unistd.h>
 #include <linux/ptrace.h>
 #include <linux/user.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/init_task.h>
 #include <linux/mqueue.h>
@@ -77,8 +78,8 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (mach_power_off)
-		mach_power_off();
+	if (pm_power_off)
+		pm_power_off();
 	for (;;);
 }
 
arch/m68k/kernel/setup_mm.c +0 -1
index 5b8ec4d..002fea6 100644
@@ -96,7 +96,6 @@ EXPORT_SYMBOL(mach_get_rtc_pll);
 EXPORT_SYMBOL(mach_set_rtc_pll);
 void (*mach_reset)( void );
 void (*mach_halt)( void );
-void (*mach_power_off)( void );
 long mach_max_dma_address = 0x00ffffff; /* default set to the lower 16MB */
 #ifdef CONFIG_HEARTBEAT
 void (*mach_heartbeat) (int);
arch/m68k/kernel/setup_no.c +0 -1
index 88c27d9..1520156 100644
@@ -55,7 +55,6 @@ int (*mach_hwclk) (int, struct rtc_time*);
 /* machine dependent reboot functions */
 void (*mach_reset)(void);
 void (*mach_halt)(void);
-void (*mach_power_off)(void);
 
 #ifdef CONFIG_M68000
 #if defined(CONFIG_M68328)
arch/m68k/mac/config.c +2 -1
index a471eab..677913ff 100644
@@ -16,6 +16,7 @@
 #include <linux/tty.h>
 #include <linux/console.h>
 #include <linux/interrupt.h>
+#include <linux/pm.h>
 /* keyb */
 #include <linux/random.h>
 #include <linux/delay.h>
@@ -159,7 +160,7 @@ void __init config_mac(void)
 	mach_set_clock_mmss = mac_set_clock_mmss;
 	mach_reset = mac_reset;
 	mach_halt = mac_poweroff;
-	mach_power_off = mac_poweroff;
+	pm_power_off = mac_poweroff;
 	mach_max_dma_address = 0xffffffff;
 #if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
 	mach_beep = mac_mksound;
#24 lore raw

PATCH v2 5/47 mfd: as3722: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck

Devicetree bindings are supposed to be operating system independent and should thus not describe how a specific functionality is implemented in Linux.

---
v2: No change

 Documentation/devicetree/bindings/mfd/as3722.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Documentation/devicetree/bindings/mfd/as3722.txt +1 -2
index 4f64b2a..0b2a609 100644
@@ -122,8 +122,7 @@ Following are properties of regulator subnode.
 
 Power-off:
 =========
-AS3722 supports the system power off by turning off all its rail. This
-is provided through pm_power_off.
+AS3722 supports the system power off by turning off all its rails.
 The device node should have the following properties to enable this
 functionality
 ams,system-power-controller: Boolean, to enable the power off functionality
Signature · 1 line
1.9.1
Acked-by on v2 5/47
#25 lore raw

Re: [PATCH v2 05/47] mfd: as3722: Drop reference to pm_power_off from devicetree bindings

Quoted 9 lines · Guenter Roeck

Devicetree bindings are supposed to be operating system independent and should thus not describe how a specific functionality is implemented in Linux.

Quoted 5 lines

---
v2: No change

 Documentation/devicetree/bindings/mfd/as3722.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 14 lines
Documentation/devicetree/bindings/mfd/as3722.txt +1 -2
index 4f64b2a..0b2a609 100644
@@ -122,8 +122,7 @@ Following are properties of regulator subnode.
 
 Power-off:
 =========
-AS3722 supports the system power off by turning off all its rail. This
-is provided through pm_power_off.
+AS3722 supports the system power off by turning off all its rails.
 The device node should have the following properties to enable this
 functionality
 ams,system-power-controller: Boolean, to enable the power off functionality
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#26 lore raw

PATCH v2 6/47 gpio-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck

pm_power_off is an implementation detail. Replace it with a more generic description of the driver's functionality.

---
v2: No change

 Documentation/devicetree/bindings/gpio/gpio-poweroff.txt | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +5 -5
index d4eab92..c95a1a6 100644
@@ -2,12 +2,12 @@ Driver a GPIO line that can be used to turn the power off.
 
 The driver supports both level triggered and edge triggered power off.
 At driver load time, the driver will request the given gpio line and
-install a pm_power_off handler. If the optional properties 'input' is
-not found, the GPIO line will be driven in the inactive
+install a handler to power off the system. If the optional properties
+'input' is not found, the GPIO line will be driven in the inactive
 state. Otherwise its configured as an input.
 
-When the pm_power_off is called, the gpio is configured as an output,
-and drive active, so triggering a level triggered power off
+When the the poweroff handler is called, the gpio is configured as an
+output, and drive active, so triggering a level triggered power off
 condition. This will also cause an inactive->active edge condition, so
 triggering positive edge triggered power off. After a delay of 100ms,
 the GPIO is set to inactive, thus causing an active->inactive edge,
@@ -24,7 +24,7 @@ Required properties:
 
 Optional properties:
 - input : Initially configure the GPIO line as an input. Only reconfigure
-  it to an output when the pm_power_off function is called. If this optional
+  it to an output when the poweroff handler is called. If this optional
   property is not specified, the GPIO is initialized as an output in its
   inactive state.
 
Signature · 1 line
1.9.1
#27 lore raw

PATCH v2 7/47 qnap-poweroff: Drop reference to pm_power_off from devicetree bindings

In reply to Guenter Roeck

Replace reference to pm_power_off (which is an implementation detail) and replace it with a more generic description of the driver's functionality.

---
v2: Drop implementation details

 Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Documentation/devicetree/bindings/power_supply/qnap-poweroff.txt +1 -2
index af25e77..c363d71 100644
@@ -3,8 +3,7 @@
 QNAP NAS devices have a microcontroller controlling the main power
 supply. This microcontroller is connected to UART1 of the Kirkwood and
 Orion5x SoCs. Sending the character 'A', at 19200 baud, tells the
-microcontroller to turn the power off. This driver adds a handler to
-pm_power_off which is called to turn the power off.
+microcontroller to turn the power off.
 
 Synology NAS devices use a similar scheme, but a different baud rate,
 9600, and a different character, '1'.
Signature · 1 line
1.9.1
#28 lore raw

PATCH v2 8/47 kernel: Move pm_power_off to common code

In reply to Guenter Roeck

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

---
v2:
- do_kernel_poweroff -> do_kernel_power_off
- have_kernel_poweroff -> have_kernel_power_off

 arch/alpha/kernel/process.c        |  9 +++------
 arch/arc/kernel/reset.c            |  5 +----
 arch/arm/kernel/process.c          |  5 +----
 arch/arm64/kernel/process.c        |  5 +----
 arch/avr32/kernel/process.c        |  6 +-----
 arch/blackfin/kernel/process.c     |  3 ---
 arch/blackfin/kernel/reboot.c      |  2 ++
 arch/c6x/kernel/process.c          |  9 +--------
 arch/cris/kernel/process.c         |  4 +---
 arch/frv/kernel/process.c          |  5 ++---
 arch/hexagon/kernel/reset.c        |  5 ++---
 arch/ia64/kernel/process.c         |  5 +----
 arch/m32r/kernel/process.c         |  8 ++++----
 arch/m68k/kernel/process.c         |  6 +-----
 arch/metag/kernel/process.c        |  6 +-----
 arch/microblaze/kernel/process.c   |  3 ---
 arch/microblaze/kernel/reset.c     |  1 +
 arch/mips/kernel/reset.c           |  6 +-----
 arch/mn10300/kernel/process.c      |  8 ++------
 arch/openrisc/kernel/process.c     |  8 +++++---
 arch/parisc/kernel/process.c       |  8 ++++----
 arch/powerpc/kernel/setup-common.c |  6 +++---
 arch/s390/kernel/setup.c           |  8 ++------
 arch/score/kernel/process.c        |  8 ++++----
 arch/sh/kernel/reboot.c            |  6 +-----
 arch/sparc/kernel/process_32.c     | 10 ++--------
 arch/sparc/kernel/reboot.c         |  8 ++------
 arch/tile/kernel/reboot.c          |  7 +++----
 arch/um/kernel/reboot.c            |  2 --
 arch/unicore32/kernel/process.c    |  9 +--------
 arch/x86/kernel/reboot.c           | 11 +++--------
 arch/x86/xen/enlighten.c           |  3 +--
 arch/xtensa/kernel/process.c       |  4 ----
 drivers/parisc/power.c             |  3 +--
 kernel/power/poweroff_handler.c    |  8 ++++++++
 kernel/reboot.c                    |  4 ++--
 36 files changed, 68 insertions(+), 146 deletions(-)
arch/alpha/kernel/process.c +3 -6
index 1941a07..81c43f8 100644
@@ -24,6 +24,7 @@
 #include <linux/vt.h>
 #include <linux/mman.h>
 #include <linux/elfcore.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/tty.h>
 #include <linux/console.h>
@@ -40,12 +41,6 @@
 #include "proto.h"
 #include "pci_impl.h"
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_ALPHA_WTINT
 /*
  * Sleep the CPU.
@@ -184,6 +179,8 @@ machine_halt(void)
 void
 machine_power_off(void)
 {
+	do_kernel_power_off();
+
 	common_shutdown(LINUX_REBOOT_CMD_POWER_OFF, NULL);
 }
 
arch/arc/kernel/reset.c +1 -4
index 2768fa1..0758d9d 100644
@@ -26,9 +26,6 @@ void machine_restart(char *__unused)
 
 void machine_power_off(void)
 {
-	/* FIXME ::  power off ??? */
+	do_kernel_power_off();
 	machine_halt();
 }
-
-void (*pm_power_off) (void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/arm/kernel/process.c +1 -4
index fe972a2..aa3f656 100644
@@ -117,8 +117,6 @@ void soft_restart(unsigned long addr)
 /*
  * 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);
 
@@ -205,8 +203,7 @@ void machine_power_off(void)
 	local_irq_disable();
 	smp_send_stop();
 
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 /*
arch/arm64/kernel/process.c +1 -4
index c3065db..46a483a 100644
@@ -68,8 +68,6 @@ void soft_restart(unsigned long addr)
 /*
  * Function pointers to optional machine specific functions
  */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL_GPL(pm_power_off);
 
 void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
 
@@ -129,8 +127,7 @@ void machine_power_off(void)
 {
 	local_irq_disable();
 	smp_send_stop();
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 /*
arch/avr32/kernel/process.c +1 -5
index 42a53e74..529c1f6 100644
@@ -23,9 +23,6 @@
 
 #include <mach/pm.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * This file handles the architecture-dependent parts of process handling..
  */
@@ -48,8 +45,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 void machine_restart(char *cmd)
arch/blackfin/kernel/process.c +0 -3
index 4aa5545..812dd83 100644
@@ -39,9 +39,6 @@ int nr_l1stack_tasks;
 void *l1_stack_base;
 unsigned long l1_stack_len;
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * The idle loop on BFIN
  */
arch/blackfin/kernel/reboot.c +2 -0
index c4f50a3..387d610 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/interrupt.h>
+#include <linux/pm.h>
 #include <asm/bfin-global.h>
 #include <asm/reboot.h>
 #include <asm/bfrom.h>
@@ -106,6 +107,7 @@ void machine_halt(void)
 __attribute__((weak))
 void native_machine_power_off(void)
 {
+	do_kernel_power_off();
 	idle_with_irq_disabled();
 }
 
arch/c6x/kernel/process.c +1 -8
index 57d2ea8..edf7e5a 100644
@@ -27,12 +27,6 @@ void	(*c6x_halt)(void);
 extern asmlinkage void ret_from_fork(void);
 extern asmlinkage void ret_from_kernel_thread(void);
 
-/*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
 	unsigned long tmp;
@@ -73,8 +67,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	halt_loop();
 }
 
arch/cris/kernel/process.c +1 -3
index b78498e..9ebd76b 100644
@@ -31,9 +31,6 @@
 
 extern void default_idle(void);
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
 	default_idle();
@@ -60,6 +57,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
+	do_kernel_power_off();
 }
 
 /*
arch/frv/kernel/process.c +2 -3
index 5d40aeb77..502dabb 100644
@@ -42,9 +42,6 @@ asmlinkage void ret_from_kernel_thread(void);
 
 #include <asm/pgalloc.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static void core_sleep_idle(void)
 {
 #ifdef LED_DEBUG_SLEEP
@@ -107,6 +104,8 @@ void machine_power_off(void)
 	gdbstub_exit(0);
 #endif
 
+	do_kernel_power_off();
+
 	for (;;);
 }
 
arch/hexagon/kernel/reset.c +2 -3
index 76483c1..6f607b6 100644
@@ -16,11 +16,13 @@
  * 02110-1301, USA.
  */
 
+#include <linux/pm.h>
 #include <linux/smp.h>
 #include <asm/hexagon_vm.h>
 
 void machine_power_off(void)
 {
+	do_kernel_power_off();
 	smp_send_stop();
 	__vmstop();
 }
@@ -32,6 +34,3 @@ void machine_halt(void)
 void machine_restart(char *cmd)
 {
 }
-
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/ia64/kernel/process.c +1 -4
index b515149..88121a2 100644
@@ -57,8 +57,6 @@ void (*ia64_mark_idle)(int);
 
 unsigned long boot_option_idle_override = IDLE_NO_OVERRIDE;
 EXPORT_SYMBOL(boot_option_idle_override);
-void (*pm_power_off) (void);
-EXPORT_SYMBOL(pm_power_off);
 
 void
 ia64_do_show_stack (struct unw_frame_info *info, void *arg)
@@ -675,8 +673,7 @@ machine_halt (void)
 void
 machine_power_off (void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	machine_halt();
 }
 
arch/m32r/kernel/process.c +4 -4
index e69221d..65a037e 100644
@@ -23,6 +23,7 @@
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/unistd.h>
 #include <linux/hardirq.h>
@@ -44,9 +45,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
 	return tsk->thread.lr;
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_restart(char *__unused)
 {
 #if defined(CONFIG_PLAT_MAPPI3)
@@ -67,7 +65,9 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	/* M32R_FIXME */
+	do_kernel_power_off();
+	for (;;)
+		;
 }
 
 void show_regs(struct pt_regs * regs)
arch/m68k/kernel/process.c +1 -5
index afe3d6e..bbc0a63 100644
@@ -78,14 +78,10 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	for (;;);
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void show_regs(struct pt_regs * regs)
 {
 	printk("\n");
arch/metag/kernel/process.c +1 -5
index 483dff9..8d95773 100644
@@ -67,9 +67,6 @@ void arch_cpu_idle_dead(void)
 }
 #endif
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void (*soc_restart)(char *cmd);
 void (*soc_halt)(void);
 
@@ -90,8 +87,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	smp_send_stop();
 	hard_processor_halt(HALT_OK);
 }
arch/microblaze/kernel/process.c +0 -3
index b2dd371..0ebca36 100644
@@ -44,9 +44,6 @@ void show_regs(struct pt_regs *regs)
 				regs->msr, regs->ear, regs->esr, regs->fsr);
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void flush_thread(void)
 {
 }
arch/microblaze/kernel/reset.c +1 -0
index fbe58c6..2c6b32c 100644
@@ -103,6 +103,7 @@ void machine_halt(void)
 void machine_power_off(void)
 {
 	pr_notice("Machine power off...\n");
+	do_kernel_power_off();
 	while (1)
 		;
 }
arch/mips/kernel/reset.c +1 -5
index 07fc524..09e74d2 100644
@@ -21,9 +21,6 @@
  */
 void (*_machine_restart)(char *command);
 void (*_machine_halt)(void);
-void (*pm_power_off)(void);
-
-EXPORT_SYMBOL(pm_power_off);
 
 void machine_restart(char *command)
 {
@@ -39,6 +36,5 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
arch/mn10300/kernel/process.c +2 -6
index 3707da5..c78b2eb 100644
@@ -20,6 +20,7 @@
 #include <linux/user.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/percpu.h>
 #include <linux/err.h>
@@ -45,12 +46,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
 }
 
 /*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
-/*
  * On SMP it's slightly faster (but much more power-consuming!)
  * to poll the ->work.need_resched flag instead of waiting for the
  * cross-CPU IPI to arrive. Use this option with caution.
@@ -93,6 +88,7 @@ void machine_power_off(void)
 #ifdef CONFIG_KERNEL_DEBUGGER
 	gdbstub_exit(0);
 #endif
+	do_kernel_power_off();
 }
 
 void show_regs(struct pt_regs *regs)
arch/openrisc/kernel/process.c +5 -3
index 386af25..494afd2 100644
@@ -25,6 +25,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mm.h>
+#include <linux/pm.h>
 #include <linux/stddef.h>
 #include <linux/unistd.h>
 #include <linux/ptrace.h>
@@ -51,7 +52,7 @@
  */
 struct thread_info *current_thread_info_set[NR_CPUS] = { &init_thread_info, };
 
-void machine_restart(void)
+void machine_restart(char *cmd)
 {
 	printk(KERN_INFO "*** MACHINE RESTART ***\n");
 	__asm__("l.nop 1");
@@ -72,11 +73,12 @@ void machine_halt(void)
 void machine_power_off(void)
 {
 	printk(KERN_INFO "*** MACHINE POWER OFF ***\n");
+
+	do_kernel_power_off();
+
 	__asm__("l.nop 1");
 }
 
-void (*pm_power_off) (void) = machine_power_off;
-
 /*
  * When a process does an "exec", machine state like FPU and debug
  * registers need to be reset.  This is a hook function for that.
arch/parisc/kernel/process.c +4 -4
index 0bbbf0d..3f5d14a 100644
@@ -41,6 +41,7 @@
 #include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/personality.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/sched.h>
 #include <linux/slab.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_power_off();
+
 	/* It seems we have no way to power the system off via
 	 * software. The user has to press the button himself. */
 
@@ -141,9 +144,6 @@ void machine_power_off(void)
 	       "Please power this system off now.");
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * Free current thread data structures etc..
  */
arch/powerpc/kernel/setup-common.c +3 -3
index 1362cd6..5b7a851 100644
@@ -141,6 +141,9 @@ void machine_power_off(void)
 	machine_shutdown();
 	if (ppc_md.power_off)
 		ppc_md.power_off();
+
+	do_kernel_power_off();
+
 #ifdef CONFIG_SMP
 	smp_send_stop();
 #endif
@@ -151,9 +154,6 @@ void machine_power_off(void)
 /* Used by the G5 thermal driver */
 EXPORT_SYMBOL_GPL(machine_power_off);
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
-
 void machine_halt(void)
 {
 	machine_shutdown();
arch/s390/kernel/setup.c +2 -6
index e80d9ff..267e025 100644
@@ -263,13 +263,9 @@ void machine_power_off(void)
 		 */
 		console_unblank();
 	_machine_power_off();
-}
 
-/*
- * Dummy power off function.
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
+	do_kernel_power_off();
+}
 
 static int __init early_parse_mem(char *p)
 {
arch/score/kernel/process.c +4 -4
index a1519ad3..b76ea67 100644
@@ -29,9 +29,6 @@
 #include <linux/pm.h>
 #include <linux/rcupdate.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /* If or when software machine-restart is implemented, add code here. */
 void machine_restart(char *command) {}
 
@@ -39,7 +36,10 @@ void machine_restart(char *command) {}
 void machine_halt(void) {}
 
 /* If or when software machine-power-off is implemented, add code here. */
-void machine_power_off(void) {}
+void machine_power_off(void)
+{
+	do_kernel_power_off();
+}
 
 void ret_from_fork(void);
 void ret_from_kernel_thread(void);
arch/sh/kernel/reboot.c +1 -5
index 04afe5b..065de12 100644
@@ -11,9 +11,6 @@
 #include <asm/tlbflush.h>
 #include <asm/traps.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_SUPERH32
 static void watchdog_trigger_immediate(void)
 {
@@ -51,8 +48,7 @@ static void native_machine_shutdown(void)
 
 static void native_machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 static void native_machine_halt(void)
arch/sparc/kernel/process_32.c +2 -8
index 50e7b62..cb8148a 100644
@@ -48,14 +48,6 @@
  */
 void (*sparc_idle)(void);
 
-/* 
- * Power-off handler instantiation for pm.h compliance
- * This is done via auxio, but could be used as a fallback
- * handler when auxio is not present-- unused for now...
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * sysctl - toggle power-off restriction for serial console 
  * systems in machine_power_off()
@@ -112,6 +104,8 @@ void machine_power_off(void)
 		sbus_writeb(power_register, auxio_power_register);
 	}
 
+	do_kernel_power_off();
+
 	machine_halt();
 }
 
arch/sparc/kernel/reboot.c +2 -6
index eba7d91..3c0bb03 100644
@@ -16,17 +16,13 @@
  */
 int scons_pwroff = 1;
 
-/* This isn't actually used, it exists merely to satisfy the
- * reference in kernel/sys.c
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
 	if (strcmp(of_console_device->type, "serial") || scons_pwroff)
 		prom_halt_power_off();
 
+	do_kernel_power_off();
+
 	prom_halt();
 }
 
arch/tile/kernel/reboot.c +3 -4
index 6c5d2c0..8ff4a7f 100644
@@ -36,6 +36,9 @@ void machine_power_off(void)
 {
 	arch_local_irq_disable_all();
 	smp_send_stop();
+
+	do_kernel_power_off();
+
 	hv_power_off();
 }
 
@@ -45,7 +48,3 @@ void machine_restart(char *cmd)
 	smp_send_stop();
 	hv_restart((HV_VirtAddr) "vmlinux", (HV_VirtAddr) cmd);
 }
-
-/* No interesting distinction to be made here. */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/um/kernel/reboot.c +0 -2
index ced8903..a82ef28 100644
@@ -11,8 +11,6 @@
 #include <os.h>
 #include <skas.h>
 
-void (*pm_power_off)(void);
-
 static void kill_off_processes(void)
 {
 	if (proc_mm)
arch/unicore32/kernel/process.c +1 -8
index b008e99..9490dd5 100644
@@ -56,16 +56,9 @@ void machine_halt(void)
 	gpio_set_value(GPO_SOFT_OFF, 0);
 }
 
-/*
- * Function pointers to optional machine specific functions
- */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	machine_halt();
 }
 
arch/x86/kernel/reboot.c +3 -8
index 17962e6..5c09e28 100644
@@ -30,12 +30,6 @@
 #include <asm/x86_init.h>
 #include <asm/efi.h>
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static const struct desc_ptr no_idt = {};
 
 /*
@@ -647,11 +641,12 @@ static void native_machine_halt(void)
 
 static void native_machine_power_off(void)
 {
-	if (pm_power_off) {
+	if (have_kernel_power_off()) {
 		if (!reboot_force)
 			machine_shutdown();
-		pm_power_off();
+		do_kernel_power_off();
 	}
+
 	/* A fallback in case there is no PM info available */
 	tboot_shutdown(TB_SHUTDOWN_HALT);
 }
arch/x86/xen/enlighten.c +1 -2
index 1a3f044..c2c1d74 100644
@@ -1320,8 +1320,7 @@ static void xen_machine_halt(void)
 
 static void xen_machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	xen_reboot(SHUTDOWN_poweroff);
 }
 
arch/xtensa/kernel/process.c +0 -4
index 1c85323..c487296 100644
@@ -49,10 +49,6 @@ extern void ret_from_kernel_thread(void);
 
 struct task_struct *current_set[NR_CPUS] = {&init_task, };
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
-
 #if XTENSA_HAVE_COPROCESSORS
 
 void coprocessor_release_all(struct thread_info *ti)
drivers/parisc/power.c +1 -2
index ef31b77..f10cf92 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();
 		}
 	}
 }
kernel/power/poweroff_handler.c +8 -0
index aeb4736..37f0b88 100644
@@ -22,6 +22,12 @@
 #include <linux/types.h>
 
 /*
+ * If set, calling this function will power off the system immediately.
+ */
+void (*pm_power_off)(void);
+EXPORT_SYMBOL(pm_power_off);
+
+/*
  *	Notifier list for kernel code which wants to be called
  *	to power off the system.
  */
@@ -236,6 +242,8 @@ EXPORT_SYMBOL(devm_register_power_off_handler);
 void do_kernel_power_off(void)
 {
 	spin_lock(&power_off_handler_lock);
+	if (pm_power_off)
+		pm_power_off();
 	raw_notifier_call_chain(&power_off_handler_list, 0, NULL);
 	spin_unlock(&power_off_handler_lock);
 }
kernel/reboot.c +2 -2
index 5925f5a..0930851 100644
@@ -306,9 +306,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 		return ret;
 
 	/* Instead of trying to make the power_off code look like
-	 * halt when pm_power_off is not set do it the easy way.
+	 * halt when no poweroff handler exists do it the easy way.
 	 */
-	if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
+	if (cmd == LINUX_REBOOT_CMD_POWER_OFF && !have_kernel_power_off())
 		cmd = LINUX_REBOOT_CMD_HALT;
 
 	mutex_lock(&reboot_mutex);
Signature · 1 line
1.9.1
Acked-by on v2 8/47
#29 lore raw

Re: [PATCH v2 08/47] kernel: Move pm_power_off to common code

Quoted 6 lines · Guenter Roeck

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

Quoted 9 lines
#30 lore raw

Re: [PATCH v2 08/47] kernel: Move pm_power_off to common code

Quoted 18 lines · Ralf Baechle
Quoted 6 lines · Guenter Roeck

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

Quoted 9 lines
Quoted 1 line

Thanks!

Guenter

#31 lore raw

Re: [PATCH v2 08/47] kernel: Move pm_power_off to common code

In reply to Ralf Baechle
Quoted 18 lines · Ralf Baechle
Quoted 6 lines · Guenter Roeck

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

Quoted 9 lines
Quoted 1 line

Thanks!

Guenter

Acked-by on v2 8/47
#32 lore raw

Re: [PATCH v2 08/47] kernel: Move pm_power_off to common code

In reply to Guenter Roeck
Quoted 6 lines · Guenter Roeck

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

Quoted 9 lines
Acked-by on v2 8/47
#33 lore raw

Re: [PATCH v2 08/47] kernel: Move pm_power_off to common code

In reply to Guenter Roeck

Hi Guenter,

Quoted 6 lines · Guenter Roeck

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

Quoted 8 lines

For metag:

Thanks
James

Quoted 24 lines
arch/metag/kernel/process.c +1 -5
index 483dff9..8d95773 100644
@@ -67,9 +67,6 @@ void arch_cpu_idle_dead(void)
 }
 #endif
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void (*soc_restart)(char *cmd);
 void (*soc_halt)(void);
 
@@ -90,8 +87,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	smp_send_stop();
 	hard_processor_halt(HALT_OK);
 }
#34 lore raw

Re: [PATCH v2 08/47] kernel: Move pm_power_off to common code

Quoted 18 lines · James Hogan

Hi Guenter,

Quoted 6 lines · Guenter Roeck

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

Quoted 8 lines
Quoted 3 lines

For metag:

Thanks!

Guenter

#35 lore raw

Re: [PATCH v2 08/47] kernel: Move pm_power_off to common code

In reply to James Hogan
Quoted 18 lines · James Hogan

Hi Guenter,

Quoted 6 lines · Guenter Roeck

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

Quoted 8 lines
Quoted 3 lines

For metag:

Thanks!

Guenter

Acked-by on v2 8/47
#36 lore raw

Re: [PATCH v2 08/47] kernel: Move pm_power_off to common code

In reply to Guenter Roeck

Hi Guenter,

Quoted 6 lines · Guenter Roeck

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

Quoted 8 lines

For metag:

Thanks
James

Quoted 24 lines
arch/metag/kernel/process.c +1 -5
index 483dff9..8d95773 100644
@@ -67,9 +67,6 @@ void arch_cpu_idle_dead(void)
 }
 #endif
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void (*soc_restart)(char *cmd);
 void (*soc_halt)(void);
 
@@ -90,8 +87,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	smp_send_stop();
 	hard_processor_halt(HALT_OK);
 }
Acked-by on v2 8/47
#37 lore raw

Re: [uml-user] [PATCH v2 08/47] kernel: Move pm_power_off to common code

In reply to Guenter Roeck

2014-10-21 12:12 GMT+08:00 Guenter Roeck <[email protected]>:

Quoted 890 lines

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

---
v2:
- do_kernel_poweroff -> do_kernel_power_off
- have_kernel_poweroff -> have_kernel_power_off

 arch/alpha/kernel/process.c        |  9 +++------
 arch/arc/kernel/reset.c            |  5 +----
 arch/arm/kernel/process.c          |  5 +----
 arch/arm64/kernel/process.c        |  5 +----
 arch/avr32/kernel/process.c        |  6 +-----
 arch/blackfin/kernel/process.c     |  3 ---
 arch/blackfin/kernel/reboot.c      |  2 ++
 arch/c6x/kernel/process.c          |  9 +--------
 arch/cris/kernel/process.c         |  4 +---
 arch/frv/kernel/process.c          |  5 ++---
 arch/hexagon/kernel/reset.c        |  5 ++---
 arch/ia64/kernel/process.c         |  5 +----
 arch/m32r/kernel/process.c         |  8 ++++----
 arch/m68k/kernel/process.c         |  6 +-----
 arch/metag/kernel/process.c        |  6 +-----
 arch/microblaze/kernel/process.c   |  3 ---
 arch/microblaze/kernel/reset.c     |  1 +
 arch/mips/kernel/reset.c           |  6 +-----
 arch/mn10300/kernel/process.c      |  8 ++------
 arch/openrisc/kernel/process.c     |  8 +++++---
 arch/parisc/kernel/process.c       |  8 ++++----
 arch/powerpc/kernel/setup-common.c |  6 +++---
 arch/s390/kernel/setup.c           |  8 ++------
 arch/score/kernel/process.c        |  8 ++++----
 arch/sh/kernel/reboot.c            |  6 +-----
 arch/sparc/kernel/process_32.c     | 10 ++--------
 arch/sparc/kernel/reboot.c         |  8 ++------
 arch/tile/kernel/reboot.c          |  7 +++----
 arch/um/kernel/reboot.c            |  2 --
 arch/unicore32/kernel/process.c    |  9 +--------
 arch/x86/kernel/reboot.c           | 11 +++--------
 arch/x86/xen/enlighten.c           |  3 +--
 arch/xtensa/kernel/process.c       |  4 ----
 drivers/parisc/power.c             |  3 +--
 kernel/power/poweroff_handler.c    |  8 ++++++++
 kernel/reboot.c                    |  4 ++--
 36 files changed, 68 insertions(+), 146 deletions(-)
arch/alpha/kernel/process.c +3 -6
index 1941a07..81c43f8 100644
@@ -24,6 +24,7 @@
 #include <linux/vt.h>
 #include <linux/mman.h>
 #include <linux/elfcore.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/tty.h>
 #include <linux/console.h>
@@ -40,12 +41,6 @@
 #include "proto.h"
 #include "pci_impl.h"
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_ALPHA_WTINT
 /*
  * Sleep the CPU.
@@ -184,6 +179,8 @@ machine_halt(void)
 void
 machine_power_off(void)
 {
+       do_kernel_power_off();
+
        common_shutdown(LINUX_REBOOT_CMD_POWER_OFF, NULL);
 }
 
arch/arc/kernel/reset.c +1 -4
index 2768fa1..0758d9d 100644
@@ -26,9 +26,6 @@ void machine_restart(char *__unused)
 
 void machine_power_off(void)
 {
-       /* FIXME ::  power off ??? */
+       do_kernel_power_off();
        machine_halt();
 }
-
-void (*pm_power_off) (void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/arm/kernel/process.c +1 -4
index fe972a2..aa3f656 100644
@@ -117,8 +117,6 @@ void soft_restart(unsigned long addr)
 /*
  * 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);
 
@@ -205,8 +203,7 @@ void machine_power_off(void)
        local_irq_disable();
        smp_send_stop();
 
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 /*
arch/arm64/kernel/process.c +1 -4
index c3065db..46a483a 100644
@@ -68,8 +68,6 @@ void soft_restart(unsigned long addr)
 /*
  * Function pointers to optional machine specific functions
  */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL_GPL(pm_power_off);
 
 void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
 
@@ -129,8 +127,7 @@ void machine_power_off(void)
 {
        local_irq_disable();
        smp_send_stop();
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 /*
arch/avr32/kernel/process.c +0 -3
index 42a53e74..529c1f6 100644
@@ -23,9 +23,6 @@
 
 #include <mach/pm.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * This file handles the architecture-dependent parts of process

handling..
*/

arch/avr32/kernel/process.c +1 -2
@@ -48,8 +45,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 void machine_restart(char *cmd)
arch/blackfin/kernel/process.c +0 -3
index 4aa5545..812dd83 100644
@@ -39,9 +39,6 @@ int nr_l1stack_tasks;
 void *l1_stack_base;
 unsigned long l1_stack_len;
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * The idle loop on BFIN
  */
arch/blackfin/kernel/reboot.c +2 -0
index c4f50a3..387d610 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/interrupt.h>
+#include <linux/pm.h>
 #include <asm/bfin-global.h>
 #include <asm/reboot.h>
 #include <asm/bfrom.h>
@@ -106,6 +107,7 @@ void machine_halt(void)
 __attribute__((weak))
 void native_machine_power_off(void)
 {
+       do_kernel_power_off();
        idle_with_irq_disabled();
 }
 
arch/c6x/kernel/process.c +1 -8
index 57d2ea8..edf7e5a 100644
@@ -27,12 +27,6 @@ void (*c6x_halt)(void);
 extern asmlinkage void ret_from_fork(void);
 extern asmlinkage void ret_from_kernel_thread(void);
 
-/*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
        unsigned long tmp;
@@ -73,8 +67,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        halt_loop();
 }
 
arch/cris/kernel/process.c +1 -3
index b78498e..9ebd76b 100644
@@ -31,9 +31,6 @@
 
 extern void default_idle(void);
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
        default_idle();
@@ -60,6 +57,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
+       do_kernel_power_off();
 }
 
 /*
arch/frv/kernel/process.c +2 -3
index 5d40aeb77..502dabb 100644
@@ -42,9 +42,6 @@ asmlinkage void ret_from_kernel_thread(void);
 
 #include <asm/pgalloc.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static void core_sleep_idle(void)
 {
 #ifdef LED_DEBUG_SLEEP
@@ -107,6 +104,8 @@ void machine_power_off(void)
        gdbstub_exit(0);
 #endif
 
+       do_kernel_power_off();
+
        for (;;);
 }
 
arch/hexagon/kernel/reset.c +2 -3
index 76483c1..6f607b6 100644
@@ -16,11 +16,13 @@
  * 02110-1301, USA.
  */
 
+#include <linux/pm.h>
 #include <linux/smp.h>
 #include <asm/hexagon_vm.h>
 
 void machine_power_off(void)
 {
+       do_kernel_power_off();
        smp_send_stop();
        __vmstop();
 }
@@ -32,6 +34,3 @@ void machine_halt(void)
 void machine_restart(char *cmd)
 {
 }
-
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/ia64/kernel/process.c +1 -4
index b515149..88121a2 100644
@@ -57,8 +57,6 @@ void (*ia64_mark_idle)(int);
 
 unsigned long boot_option_idle_override = IDLE_NO_OVERRIDE;
 EXPORT_SYMBOL(boot_option_idle_override);
-void (*pm_power_off) (void);
-EXPORT_SYMBOL(pm_power_off);
 
 void
 ia64_do_show_stack (struct unw_frame_info *info, void *arg)
@@ -675,8 +673,7 @@ machine_halt (void)
 void
 machine_power_off (void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        machine_halt();
 }
 
arch/m32r/kernel/process.c +4 -4
index e69221d..65a037e 100644
@@ -23,6 +23,7 @@
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/unistd.h>
 #include <linux/hardirq.h>
@@ -44,9 +45,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
        return tsk->thread.lr;
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_restart(char *__unused)
 {
 #if defined(CONFIG_PLAT_MAPPI3)
@@ -67,7 +65,9 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       /* M32R_FIXME */
+       do_kernel_power_off();
+       for (;;)
+               ;
 }
 
 void show_regs(struct pt_regs * regs)
arch/m68k/kernel/process.c +1 -5
index afe3d6e..bbc0a63 100644
@@ -78,14 +78,10 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        for (;;);
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void show_regs(struct pt_regs * regs)
 {
        printk("\n");
arch/metag/kernel/process.c +1 -5
index 483dff9..8d95773 100644
@@ -67,9 +67,6 @@ void arch_cpu_idle_dead(void)
 }
 #endif
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void (*soc_restart)(char *cmd);
 void (*soc_halt)(void);
 
@@ -90,8 +87,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        smp_send_stop();
        hard_processor_halt(HALT_OK);
 }
arch/microblaze/kernel/process.c +0 -3
index b2dd371..0ebca36 100644
@@ -44,9 +44,6 @@ void show_regs(struct pt_regs *regs)
                                regs->msr, regs->ear, regs->esr,
 regs->fsr);
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void flush_thread(void)
 {

}

arch/microblaze/kernel/reset.c +1 -0
index fbe58c6..2c6b32c 100644
@@ -103,6 +103,7 @@ void machine_halt(void)
 void machine_power_off(void)
 {
        pr_notice("Machine power off...\n");
+       do_kernel_power_off();
        while (1)
                ;
 }
arch/mips/kernel/reset.c +1 -5
index 07fc524..09e74d2 100644
@@ -21,9 +21,6 @@
  */
 void (*_machine_restart)(char *command);
 void (*_machine_halt)(void);
-void (*pm_power_off)(void);
-
-EXPORT_SYMBOL(pm_power_off);
 
 void machine_restart(char *command)
 {
@@ -39,6 +36,5 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
arch/mn10300/kernel/process.c +2 -6
index 3707da5..c78b2eb 100644
@@ -20,6 +20,7 @@
 #include <linux/user.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/percpu.h>
 #include <linux/err.h>
@@ -45,12 +46,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
 }
 
 /*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
-/*
  * On SMP it's slightly faster (but much more power-consuming!)
  * to poll the ->work.need_resched flag instead of waiting for the
  * cross-CPU IPI to arrive. Use this option with caution.
@@ -93,6 +88,7 @@ void machine_power_off(void)
 #ifdef CONFIG_KERNEL_DEBUGGER
        gdbstub_exit(0);
 #endif
+       do_kernel_power_off();
 }
 
 void show_regs(struct pt_regs *regs)
arch/openrisc/kernel/process.c +2 -1
index 386af25..494afd2 100644
@@ -25,6 +25,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mm.h>
+#include <linux/pm.h>
 #include <linux/stddef.h>
 #include <linux/unistd.h>
 #include <linux/ptrace.h>
@@ -51,7 +52,7 @@
  */
 struct thread_info *current_thread_info_set[NR_CPUS] = {
 &init_thread_info, };
 
-void machine_restart(void)
+void machine_restart(char *cmd)
 {
        printk(KERN_INFO "*** MACHINE RESTART ***\n");
        __asm__("l.nop 1");
arch/openrisc/kernel/process.c +3 -2
@@ -72,11 +73,12 @@ void machine_halt(void)
 void machine_power_off(void)
 {
        printk(KERN_INFO "*** MACHINE POWER OFF ***\n");
+
+       do_kernel_power_off();
+
        __asm__("l.nop 1");
 }
 
-void (*pm_power_off) (void) = machine_power_off;
-
 /*
  * When a process does an "exec", machine state like FPU and debug
  * registers need to be reset.  This is a hook function for that.
arch/parisc/kernel/process.c +4 -4
index 0bbbf0d..3f5d14a 100644
@@ -41,6 +41,7 @@
 #include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/personality.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/sched.h>
 #include <linux/slab.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_power_off();
+
        /* It seems we have no way to power the system off via
         * software. The user has to press the button himself. */
 
@@ -141,9 +144,6 @@ void machine_power_off(void)
               "Please power this system off now.");
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * Free current thread data structures etc..
  */
arch/powerpc/kernel/setup-common.c +3 -3
index 1362cd6..5b7a851 100644
@@ -141,6 +141,9 @@ void machine_power_off(void)
        machine_shutdown();
        if (ppc_md.power_off)
                ppc_md.power_off();
+
+       do_kernel_power_off();
+
 #ifdef CONFIG_SMP
        smp_send_stop();
 #endif
@@ -151,9 +154,6 @@ void machine_power_off(void)
 /* Used by the G5 thermal driver */
 EXPORT_SYMBOL_GPL(machine_power_off);
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
-
 void machine_halt(void)
 {
        machine_shutdown();
arch/s390/kernel/setup.c +2 -6
index e80d9ff..267e025 100644
@@ -263,13 +263,9 @@ void machine_power_off(void)
                 */
                console_unblank();
        _machine_power_off();
-}
 
-/*
- * Dummy power off function.
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
+       do_kernel_power_off();
+}
 
 static int __init early_parse_mem(char *p)
 {
arch/score/kernel/process.c +4 -4
index a1519ad3..b76ea67 100644
@@ -29,9 +29,6 @@
 #include <linux/pm.h>
 #include <linux/rcupdate.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /* If or when software machine-restart is implemented, add code here. */
 void machine_restart(char *command) {}
 
@@ -39,7 +36,10 @@ void machine_restart(char *command) {}
 void machine_halt(void) {}
 
 /* If or when software machine-power-off is implemented, add code here. */
-void machine_power_off(void) {}
+void machine_power_off(void)
+{
+       do_kernel_power_off();
+}
 
 void ret_from_fork(void);
 void ret_from_kernel_thread(void);
arch/sh/kernel/reboot.c +1 -5
index 04afe5b..065de12 100644
@@ -11,9 +11,6 @@
 #include <asm/tlbflush.h>
 #include <asm/traps.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_SUPERH32
 static void watchdog_trigger_immediate(void)
 {
@@ -51,8 +48,7 @@ static void native_machine_shutdown(void)
 
 static void native_machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 static void native_machine_halt(void)
arch/sparc/kernel/process_32.c +2 -8
index 50e7b62..cb8148a 100644
@@ -48,14 +48,6 @@
  */
 void (*sparc_idle)(void);
 
-/*
- * Power-off handler instantiation for pm.h compliance
- * This is done via auxio, but could be used as a fallback
- * handler when auxio is not present-- unused for now...
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * sysctl - toggle power-off restriction for serial console
  * systems in machine_power_off()
@@ -112,6 +104,8 @@ void machine_power_off(void)
                sbus_writeb(power_register, auxio_power_register);
        }
 
+       do_kernel_power_off();
+
        machine_halt();
 }
 
arch/sparc/kernel/reboot.c +2 -6
index eba7d91..3c0bb03 100644
@@ -16,17 +16,13 @@
  */
 int scons_pwroff = 1;
 
-/* This isn't actually used, it exists merely to satisfy the
- * reference in kernel/sys.c
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
        if (strcmp(of_console_device->type, "serial") || scons_pwroff)
                prom_halt_power_off();
 
+       do_kernel_power_off();
+
        prom_halt();
 }
 
arch/tile/kernel/reboot.c +3 -4
index 6c5d2c0..8ff4a7f 100644
@@ -36,6 +36,9 @@ void machine_power_off(void)
 {
        arch_local_irq_disable_all();
        smp_send_stop();
+
+       do_kernel_power_off();
+
        hv_power_off();
 }
 
@@ -45,7 +48,3 @@ void machine_restart(char *cmd)
        smp_send_stop();
        hv_restart((HV_VirtAddr) "vmlinux", (HV_VirtAddr) cmd);
 }
-
-/* No interesting distinction to be made here. */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/um/kernel/reboot.c +0 -2
index ced8903..a82ef28 100644
@@ -11,8 +11,6 @@
 #include <os.h>
 #include <skas.h>
 
-void (*pm_power_off)(void);
-
 static void kill_off_processes(void)
 {
        if (proc_mm)
arch/unicore32/kernel/process.c +1 -8
index b008e99..9490dd5 100644
@@ -56,16 +56,9 @@ void machine_halt(void)
        gpio_set_value(GPO_SOFT_OFF, 0);
 }
 
-/*
- * Function pointers to optional machine specific functions
- */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        machine_halt();
 }
 
arch/x86/kernel/reboot.c +3 -8
index 17962e6..5c09e28 100644
@@ -30,12 +30,6 @@
 #include <asm/x86_init.h>
 #include <asm/efi.h>
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static const struct desc_ptr no_idt = {};
 
 /*
@@ -647,11 +641,12 @@ static void native_machine_halt(void)
 
 static void native_machine_power_off(void)
 {
-       if (pm_power_off) {
+       if (have_kernel_power_off()) {
                if (!reboot_force)
                        machine_shutdown();
-               pm_power_off();
+               do_kernel_power_off();
        }
+
        /* A fallback in case there is no PM info available */
        tboot_shutdown(TB_SHUTDOWN_HALT);
 }
arch/x86/xen/enlighten.c +1 -2
index 1a3f044..c2c1d74 100644
@@ -1320,8 +1320,7 @@ static void xen_machine_halt(void)
 
 static void xen_machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        xen_reboot(SHUTDOWN_poweroff);
 }
 
arch/xtensa/kernel/process.c +0 -4
index 1c85323..c487296 100644
@@ -49,10 +49,6 @@ extern void ret_from_kernel_thread(void);
 
 struct task_struct *current_set[NR_CPUS] = {&init_task, };
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
-
 #if XTENSA_HAVE_COPROCESSORS
 
 void coprocessor_release_all(struct thread_info *ti)
drivers/parisc/power.c +1 -2
index ef31b77..f10cf92 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();
                }
        }
 }
kernel/power/poweroff_handler.c +8 -0
index aeb4736..37f0b88 100644
@@ -22,6 +22,12 @@
 #include <linux/types.h>
 
 /*
+ * If set, calling this function will power off the system immediately.
+ */
+void (*pm_power_off)(void);
+EXPORT_SYMBOL(pm_power_off);
+
+/*
  *     Notifier list for kernel code which wants to be called
  *     to power off the system.
  */
@@ -236,6 +242,8 @@ EXPORT_SYMBOL(devm_register_power_off_handler);
 void do_kernel_power_off(void)
 {
        spin_lock(&power_off_handler_lock);
+       if (pm_power_off)
+               pm_power_off();
        raw_notifier_call_chain(&power_off_handler_list, 0, NULL);
        spin_unlock(&power_off_handler_lock);
 }
kernel/reboot.c +2 -2
index 5925f5a..0930851 100644
@@ -306,9 +306,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2,
 unsigned int, cmd,
                return ret;
 
        /* Instead of trying to make the power_off code look like
-        * halt when pm_power_off is not set do it the easy way.
+        * halt when no poweroff handler exists do it the easy way.
         */
-       if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
+       if (cmd == LINUX_REBOOT_CMD_POWER_OFF && !have_kernel_power_off())
                cmd = LINUX_REBOOT_CMD_HALT;
 
        mutex_lock(&reboot_mutex);
Quoted 9 lines

--
1.9.1

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

------------------------------------------------------------------------------

_______________________________________________
User-mode-linux-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-user

Acked-by on v2 8/47
#38 lore raw

Re: [PATCH v2 08/47] kernel: Move pm_power_off to common code

In reply to Guenter Roeck

2014-10-21 12:12 GMT+08:00 Guenter Roeck <[email protected]>:

Quoted 890 lines

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

---
v2:
- do_kernel_poweroff -> do_kernel_power_off
- have_kernel_poweroff -> have_kernel_power_off

 arch/alpha/kernel/process.c        |  9 +++------
 arch/arc/kernel/reset.c            |  5 +----
 arch/arm/kernel/process.c          |  5 +----
 arch/arm64/kernel/process.c        |  5 +----
 arch/avr32/kernel/process.c        |  6 +-----
 arch/blackfin/kernel/process.c     |  3 ---
 arch/blackfin/kernel/reboot.c      |  2 ++
 arch/c6x/kernel/process.c          |  9 +--------
 arch/cris/kernel/process.c         |  4 +---
 arch/frv/kernel/process.c          |  5 ++---
 arch/hexagon/kernel/reset.c        |  5 ++---
 arch/ia64/kernel/process.c         |  5 +----
 arch/m32r/kernel/process.c         |  8 ++++----
 arch/m68k/kernel/process.c         |  6 +-----
 arch/metag/kernel/process.c        |  6 +-----
 arch/microblaze/kernel/process.c   |  3 ---
 arch/microblaze/kernel/reset.c     |  1 +
 arch/mips/kernel/reset.c           |  6 +-----
 arch/mn10300/kernel/process.c      |  8 ++------
 arch/openrisc/kernel/process.c     |  8 +++++---
 arch/parisc/kernel/process.c       |  8 ++++----
 arch/powerpc/kernel/setup-common.c |  6 +++---
 arch/s390/kernel/setup.c           |  8 ++------
 arch/score/kernel/process.c        |  8 ++++----
 arch/sh/kernel/reboot.c            |  6 +-----
 arch/sparc/kernel/process_32.c     | 10 ++--------
 arch/sparc/kernel/reboot.c         |  8 ++------
 arch/tile/kernel/reboot.c          |  7 +++----
 arch/um/kernel/reboot.c            |  2 --
 arch/unicore32/kernel/process.c    |  9 +--------
 arch/x86/kernel/reboot.c           | 11 +++--------
 arch/x86/xen/enlighten.c           |  3 +--
 arch/xtensa/kernel/process.c       |  4 ----
 drivers/parisc/power.c             |  3 +--
 kernel/power/poweroff_handler.c    |  8 ++++++++
 kernel/reboot.c                    |  4 ++--
 36 files changed, 68 insertions(+), 146 deletions(-)
arch/alpha/kernel/process.c +3 -6
index 1941a07..81c43f8 100644
@@ -24,6 +24,7 @@
 #include <linux/vt.h>
 #include <linux/mman.h>
 #include <linux/elfcore.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/tty.h>
 #include <linux/console.h>
@@ -40,12 +41,6 @@
 #include "proto.h"
 #include "pci_impl.h"
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_ALPHA_WTINT
 /*
  * Sleep the CPU.
@@ -184,6 +179,8 @@ machine_halt(void)
 void
 machine_power_off(void)
 {
+       do_kernel_power_off();
+
        common_shutdown(LINUX_REBOOT_CMD_POWER_OFF, NULL);
 }
 
arch/arc/kernel/reset.c +1 -4
index 2768fa1..0758d9d 100644
@@ -26,9 +26,6 @@ void machine_restart(char *__unused)
 
 void machine_power_off(void)
 {
-       /* FIXME ::  power off ??? */
+       do_kernel_power_off();
        machine_halt();
 }
-
-void (*pm_power_off) (void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/arm/kernel/process.c +1 -4
index fe972a2..aa3f656 100644
@@ -117,8 +117,6 @@ void soft_restart(unsigned long addr)
 /*
  * 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);
 
@@ -205,8 +203,7 @@ void machine_power_off(void)
        local_irq_disable();
        smp_send_stop();
 
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 /*
arch/arm64/kernel/process.c +1 -4
index c3065db..46a483a 100644
@@ -68,8 +68,6 @@ void soft_restart(unsigned long addr)
 /*
  * Function pointers to optional machine specific functions
  */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL_GPL(pm_power_off);
 
 void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
 
@@ -129,8 +127,7 @@ void machine_power_off(void)
 {
        local_irq_disable();
        smp_send_stop();
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 /*
arch/avr32/kernel/process.c +0 -3
index 42a53e74..529c1f6 100644
@@ -23,9 +23,6 @@
 
 #include <mach/pm.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * This file handles the architecture-dependent parts of process

handling..
*/

arch/avr32/kernel/process.c +1 -2
@@ -48,8 +45,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 void machine_restart(char *cmd)
arch/blackfin/kernel/process.c +0 -3
index 4aa5545..812dd83 100644
@@ -39,9 +39,6 @@ int nr_l1stack_tasks;
 void *l1_stack_base;
 unsigned long l1_stack_len;
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * The idle loop on BFIN
  */
arch/blackfin/kernel/reboot.c +2 -0
index c4f50a3..387d610 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/interrupt.h>
+#include <linux/pm.h>
 #include <asm/bfin-global.h>
 #include <asm/reboot.h>
 #include <asm/bfrom.h>
@@ -106,6 +107,7 @@ void machine_halt(void)
 __attribute__((weak))
 void native_machine_power_off(void)
 {
+       do_kernel_power_off();
        idle_with_irq_disabled();
 }
 
arch/c6x/kernel/process.c +1 -8
index 57d2ea8..edf7e5a 100644
@@ -27,12 +27,6 @@ void (*c6x_halt)(void);
 extern asmlinkage void ret_from_fork(void);
 extern asmlinkage void ret_from_kernel_thread(void);
 
-/*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
        unsigned long tmp;
@@ -73,8 +67,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        halt_loop();
 }
 
arch/cris/kernel/process.c +1 -3
index b78498e..9ebd76b 100644
@@ -31,9 +31,6 @@
 
 extern void default_idle(void);
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
        default_idle();
@@ -60,6 +57,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
+       do_kernel_power_off();
 }
 
 /*
arch/frv/kernel/process.c +2 -3
index 5d40aeb77..502dabb 100644
@@ -42,9 +42,6 @@ asmlinkage void ret_from_kernel_thread(void);
 
 #include <asm/pgalloc.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static void core_sleep_idle(void)
 {
 #ifdef LED_DEBUG_SLEEP
@@ -107,6 +104,8 @@ void machine_power_off(void)
        gdbstub_exit(0);
 #endif
 
+       do_kernel_power_off();
+
        for (;;);
 }
 
arch/hexagon/kernel/reset.c +2 -3
index 76483c1..6f607b6 100644
@@ -16,11 +16,13 @@
  * 02110-1301, USA.
  */
 
+#include <linux/pm.h>
 #include <linux/smp.h>
 #include <asm/hexagon_vm.h>
 
 void machine_power_off(void)
 {
+       do_kernel_power_off();
        smp_send_stop();
        __vmstop();
 }
@@ -32,6 +34,3 @@ void machine_halt(void)
 void machine_restart(char *cmd)
 {
 }
-
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/ia64/kernel/process.c +1 -4
index b515149..88121a2 100644
@@ -57,8 +57,6 @@ void (*ia64_mark_idle)(int);
 
 unsigned long boot_option_idle_override = IDLE_NO_OVERRIDE;
 EXPORT_SYMBOL(boot_option_idle_override);
-void (*pm_power_off) (void);
-EXPORT_SYMBOL(pm_power_off);
 
 void
 ia64_do_show_stack (struct unw_frame_info *info, void *arg)
@@ -675,8 +673,7 @@ machine_halt (void)
 void
 machine_power_off (void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        machine_halt();
 }
 
arch/m32r/kernel/process.c +4 -4
index e69221d..65a037e 100644
@@ -23,6 +23,7 @@
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/unistd.h>
 #include <linux/hardirq.h>
@@ -44,9 +45,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
        return tsk->thread.lr;
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_restart(char *__unused)
 {
 #if defined(CONFIG_PLAT_MAPPI3)
@@ -67,7 +65,9 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       /* M32R_FIXME */
+       do_kernel_power_off();
+       for (;;)
+               ;
 }
 
 void show_regs(struct pt_regs * regs)
arch/m68k/kernel/process.c +1 -5
index afe3d6e..bbc0a63 100644
@@ -78,14 +78,10 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        for (;;);
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void show_regs(struct pt_regs * regs)
 {
        printk("\n");
arch/metag/kernel/process.c +1 -5
index 483dff9..8d95773 100644
@@ -67,9 +67,6 @@ void arch_cpu_idle_dead(void)
 }
 #endif
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void (*soc_restart)(char *cmd);
 void (*soc_halt)(void);
 
@@ -90,8 +87,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        smp_send_stop();
        hard_processor_halt(HALT_OK);
 }
arch/microblaze/kernel/process.c +0 -3
index b2dd371..0ebca36 100644
@@ -44,9 +44,6 @@ void show_regs(struct pt_regs *regs)
                                regs->msr, regs->ear, regs->esr,
 regs->fsr);
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void flush_thread(void)
 {

}

arch/microblaze/kernel/reset.c +1 -0
index fbe58c6..2c6b32c 100644
@@ -103,6 +103,7 @@ void machine_halt(void)
 void machine_power_off(void)
 {
        pr_notice("Machine power off...\n");
+       do_kernel_power_off();
        while (1)
                ;
 }
arch/mips/kernel/reset.c +1 -5
index 07fc524..09e74d2 100644
@@ -21,9 +21,6 @@
  */
 void (*_machine_restart)(char *command);
 void (*_machine_halt)(void);
-void (*pm_power_off)(void);
-
-EXPORT_SYMBOL(pm_power_off);
 
 void machine_restart(char *command)
 {
@@ -39,6 +36,5 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
arch/mn10300/kernel/process.c +2 -6
index 3707da5..c78b2eb 100644
@@ -20,6 +20,7 @@
 #include <linux/user.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/percpu.h>
 #include <linux/err.h>
@@ -45,12 +46,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
 }
 
 /*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
-/*
  * On SMP it's slightly faster (but much more power-consuming!)
  * to poll the ->work.need_resched flag instead of waiting for the
  * cross-CPU IPI to arrive. Use this option with caution.
@@ -93,6 +88,7 @@ void machine_power_off(void)
 #ifdef CONFIG_KERNEL_DEBUGGER
        gdbstub_exit(0);
 #endif
+       do_kernel_power_off();
 }
 
 void show_regs(struct pt_regs *regs)
arch/openrisc/kernel/process.c +2 -1
index 386af25..494afd2 100644
@@ -25,6 +25,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mm.h>
+#include <linux/pm.h>
 #include <linux/stddef.h>
 #include <linux/unistd.h>
 #include <linux/ptrace.h>
@@ -51,7 +52,7 @@
  */
 struct thread_info *current_thread_info_set[NR_CPUS] = {
 &init_thread_info, };
 
-void machine_restart(void)
+void machine_restart(char *cmd)
 {
        printk(KERN_INFO "*** MACHINE RESTART ***\n");
        __asm__("l.nop 1");
arch/openrisc/kernel/process.c +3 -2
@@ -72,11 +73,12 @@ void machine_halt(void)
 void machine_power_off(void)
 {
        printk(KERN_INFO "*** MACHINE POWER OFF ***\n");
+
+       do_kernel_power_off();
+
        __asm__("l.nop 1");
 }
 
-void (*pm_power_off) (void) = machine_power_off;
-
 /*
  * When a process does an "exec", machine state like FPU and debug
  * registers need to be reset.  This is a hook function for that.
arch/parisc/kernel/process.c +4 -4
index 0bbbf0d..3f5d14a 100644
@@ -41,6 +41,7 @@
 #include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/personality.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/sched.h>
 #include <linux/slab.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_power_off();
+
        /* It seems we have no way to power the system off via
         * software. The user has to press the button himself. */
 
@@ -141,9 +144,6 @@ void machine_power_off(void)
               "Please power this system off now.");
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * Free current thread data structures etc..
  */
arch/powerpc/kernel/setup-common.c +3 -3
index 1362cd6..5b7a851 100644
@@ -141,6 +141,9 @@ void machine_power_off(void)
        machine_shutdown();
        if (ppc_md.power_off)
                ppc_md.power_off();
+
+       do_kernel_power_off();
+
 #ifdef CONFIG_SMP
        smp_send_stop();
 #endif
@@ -151,9 +154,6 @@ void machine_power_off(void)
 /* Used by the G5 thermal driver */
 EXPORT_SYMBOL_GPL(machine_power_off);
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
-
 void machine_halt(void)
 {
        machine_shutdown();
arch/s390/kernel/setup.c +2 -6
index e80d9ff..267e025 100644
@@ -263,13 +263,9 @@ void machine_power_off(void)
                 */
                console_unblank();
        _machine_power_off();
-}
 
-/*
- * Dummy power off function.
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
+       do_kernel_power_off();
+}
 
 static int __init early_parse_mem(char *p)
 {
arch/score/kernel/process.c +4 -4
index a1519ad3..b76ea67 100644
@@ -29,9 +29,6 @@
 #include <linux/pm.h>
 #include <linux/rcupdate.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /* If or when software machine-restart is implemented, add code here. */
 void machine_restart(char *command) {}
 
@@ -39,7 +36,10 @@ void machine_restart(char *command) {}
 void machine_halt(void) {}
 
 /* If or when software machine-power-off is implemented, add code here. */
-void machine_power_off(void) {}
+void machine_power_off(void)
+{
+       do_kernel_power_off();
+}
 
 void ret_from_fork(void);
 void ret_from_kernel_thread(void);
arch/sh/kernel/reboot.c +1 -5
index 04afe5b..065de12 100644
@@ -11,9 +11,6 @@
 #include <asm/tlbflush.h>
 #include <asm/traps.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_SUPERH32
 static void watchdog_trigger_immediate(void)
 {
@@ -51,8 +48,7 @@ static void native_machine_shutdown(void)
 
 static void native_machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 static void native_machine_halt(void)
arch/sparc/kernel/process_32.c +2 -8
index 50e7b62..cb8148a 100644
@@ -48,14 +48,6 @@
  */
 void (*sparc_idle)(void);
 
-/*
- * Power-off handler instantiation for pm.h compliance
- * This is done via auxio, but could be used as a fallback
- * handler when auxio is not present-- unused for now...
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * sysctl - toggle power-off restriction for serial console
  * systems in machine_power_off()
@@ -112,6 +104,8 @@ void machine_power_off(void)
                sbus_writeb(power_register, auxio_power_register);
        }
 
+       do_kernel_power_off();
+
        machine_halt();
 }
 
arch/sparc/kernel/reboot.c +2 -6
index eba7d91..3c0bb03 100644
@@ -16,17 +16,13 @@
  */
 int scons_pwroff = 1;
 
-/* This isn't actually used, it exists merely to satisfy the
- * reference in kernel/sys.c
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
        if (strcmp(of_console_device->type, "serial") || scons_pwroff)
                prom_halt_power_off();
 
+       do_kernel_power_off();
+
        prom_halt();
 }
 
arch/tile/kernel/reboot.c +3 -4
index 6c5d2c0..8ff4a7f 100644
@@ -36,6 +36,9 @@ void machine_power_off(void)
 {
        arch_local_irq_disable_all();
        smp_send_stop();
+
+       do_kernel_power_off();
+
        hv_power_off();
 }
 
@@ -45,7 +48,3 @@ void machine_restart(char *cmd)
        smp_send_stop();
        hv_restart((HV_VirtAddr) "vmlinux", (HV_VirtAddr) cmd);
 }
-
-/* No interesting distinction to be made here. */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/um/kernel/reboot.c +0 -2
index ced8903..a82ef28 100644
@@ -11,8 +11,6 @@
 #include <os.h>
 #include <skas.h>
 
-void (*pm_power_off)(void);
-
 static void kill_off_processes(void)
 {
        if (proc_mm)
arch/unicore32/kernel/process.c +1 -8
index b008e99..9490dd5 100644
@@ -56,16 +56,9 @@ void machine_halt(void)
        gpio_set_value(GPO_SOFT_OFF, 0);
 }
 
-/*
- * Function pointers to optional machine specific functions
- */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        machine_halt();
 }
 
arch/x86/kernel/reboot.c +3 -8
index 17962e6..5c09e28 100644
@@ -30,12 +30,6 @@
 #include <asm/x86_init.h>
 #include <asm/efi.h>
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static const struct desc_ptr no_idt = {};
 
 /*
@@ -647,11 +641,12 @@ static void native_machine_halt(void)
 
 static void native_machine_power_off(void)
 {
-       if (pm_power_off) {
+       if (have_kernel_power_off()) {
                if (!reboot_force)
                        machine_shutdown();
-               pm_power_off();
+               do_kernel_power_off();
        }
+
        /* A fallback in case there is no PM info available */
        tboot_shutdown(TB_SHUTDOWN_HALT);
 }
arch/x86/xen/enlighten.c +1 -2
index 1a3f044..c2c1d74 100644
@@ -1320,8 +1320,7 @@ static void xen_machine_halt(void)
 
 static void xen_machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        xen_reboot(SHUTDOWN_poweroff);
 }
 
arch/xtensa/kernel/process.c +0 -4
index 1c85323..c487296 100644
@@ -49,10 +49,6 @@ extern void ret_from_kernel_thread(void);
 
 struct task_struct *current_set[NR_CPUS] = {&init_task, };
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
-
 #if XTENSA_HAVE_COPROCESSORS
 
 void coprocessor_release_all(struct thread_info *ti)
drivers/parisc/power.c +1 -2
index ef31b77..f10cf92 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();
                }
        }
 }
kernel/power/poweroff_handler.c +8 -0
index aeb4736..37f0b88 100644
@@ -22,6 +22,12 @@
 #include <linux/types.h>
 
 /*
+ * If set, calling this function will power off the system immediately.
+ */
+void (*pm_power_off)(void);
+EXPORT_SYMBOL(pm_power_off);
+
+/*
  *     Notifier list for kernel code which wants to be called
  *     to power off the system.
  */
@@ -236,6 +242,8 @@ EXPORT_SYMBOL(devm_register_power_off_handler);
 void do_kernel_power_off(void)
 {
        spin_lock(&power_off_handler_lock);
+       if (pm_power_off)
+               pm_power_off();
        raw_notifier_call_chain(&power_off_handler_list, 0, NULL);
        spin_unlock(&power_off_handler_lock);
 }
kernel/reboot.c +2 -2
index 5925f5a..0930851 100644
@@ -306,9 +306,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2,
 unsigned int, cmd,
                return ret;
 
        /* Instead of trying to make the power_off code look like
-        * halt when pm_power_off is not set do it the easy way.
+        * halt when no poweroff handler exists do it the easy way.
         */
-       if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
+       if (cmd == LINUX_REBOOT_CMD_POWER_OFF && !have_kernel_power_off())
                cmd = LINUX_REBOOT_CMD_HALT;
 
        mutex_lock(&reboot_mutex);
Quoted 9 lines

--
1.9.1

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

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

Acked-by on v2 8/47
#39 lore raw

Re: [PATCH v2 08/47] kernel: Move pm_power_off to common code

In reply to Guenter Roeck

2014-10-21 12:12 GMT+08:00 Guenter Roeck <[email protected]>:

Quoted 886 lines

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

---
v2:
- do_kernel_poweroff -> do_kernel_power_off
- have_kernel_poweroff -> have_kernel_power_off

 arch/alpha/kernel/process.c        |  9 +++------
 arch/arc/kernel/reset.c            |  5 +----
 arch/arm/kernel/process.c          |  5 +----
 arch/arm64/kernel/process.c        |  5 +----
 arch/avr32/kernel/process.c        |  6 +-----
 arch/blackfin/kernel/process.c     |  3 ---
 arch/blackfin/kernel/reboot.c      |  2 ++
 arch/c6x/kernel/process.c          |  9 +--------
 arch/cris/kernel/process.c         |  4 +---
 arch/frv/kernel/process.c          |  5 ++---
 arch/hexagon/kernel/reset.c        |  5 ++---
 arch/ia64/kernel/process.c         |  5 +----
 arch/m32r/kernel/process.c         |  8 ++++----
 arch/m68k/kernel/process.c         |  6 +-----
 arch/metag/kernel/process.c        |  6 +-----
 arch/microblaze/kernel/process.c   |  3 ---
 arch/microblaze/kernel/reset.c     |  1 +
 arch/mips/kernel/reset.c           |  6 +-----
 arch/mn10300/kernel/process.c      |  8 ++------
 arch/openrisc/kernel/process.c     |  8 +++++---
 arch/parisc/kernel/process.c       |  8 ++++----
 arch/powerpc/kernel/setup-common.c |  6 +++---
 arch/s390/kernel/setup.c           |  8 ++------
 arch/score/kernel/process.c        |  8 ++++----
 arch/sh/kernel/reboot.c            |  6 +-----
 arch/sparc/kernel/process_32.c     | 10 ++--------
 arch/sparc/kernel/reboot.c         |  8 ++------
 arch/tile/kernel/reboot.c          |  7 +++----
 arch/um/kernel/reboot.c            |  2 --
 arch/unicore32/kernel/process.c    |  9 +--------
 arch/x86/kernel/reboot.c           | 11 +++--------
 arch/x86/xen/enlighten.c           |  3 +--
 arch/xtensa/kernel/process.c       |  4 ----
 drivers/parisc/power.c             |  3 +--
 kernel/power/poweroff_handler.c    |  8 ++++++++
 kernel/reboot.c                    |  4 ++--
 36 files changed, 68 insertions(+), 146 deletions(-)
arch/alpha/kernel/process.c +3 -6
index 1941a07..81c43f8 100644
@@ -24,6 +24,7 @@
 #include <linux/vt.h>
 #include <linux/mman.h>
 #include <linux/elfcore.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/tty.h>
 #include <linux/console.h>
@@ -40,12 +41,6 @@
 #include "proto.h"
 #include "pci_impl.h"
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_ALPHA_WTINT
 /*
  * Sleep the CPU.
@@ -184,6 +179,8 @@ machine_halt(void)
 void
 machine_power_off(void)
 {
+       do_kernel_power_off();
+
        common_shutdown(LINUX_REBOOT_CMD_POWER_OFF, NULL);
 }
 
arch/arc/kernel/reset.c +1 -4
index 2768fa1..0758d9d 100644
@@ -26,9 +26,6 @@ void machine_restart(char *__unused)
 
 void machine_power_off(void)
 {
-       /* FIXME ::  power off ??? */
+       do_kernel_power_off();
        machine_halt();
 }
-
-void (*pm_power_off) (void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/arm/kernel/process.c +1 -4
index fe972a2..aa3f656 100644
@@ -117,8 +117,6 @@ void soft_restart(unsigned long addr)
 /*
  * 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);
 
@@ -205,8 +203,7 @@ void machine_power_off(void)
        local_irq_disable();
        smp_send_stop();
 
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 /*
arch/arm64/kernel/process.c +1 -4
index c3065db..46a483a 100644
@@ -68,8 +68,6 @@ void soft_restart(unsigned long addr)
 /*
  * Function pointers to optional machine specific functions
  */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL_GPL(pm_power_off);
 
 void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
 
@@ -129,8 +127,7 @@ void machine_power_off(void)
 {
        local_irq_disable();
        smp_send_stop();
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 /*
arch/avr32/kernel/process.c +1 -5
index 42a53e74..529c1f6 100644
@@ -23,9 +23,6 @@
 
 #include <mach/pm.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * This file handles the architecture-dependent parts of process handling..
  */
@@ -48,8 +45,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 void machine_restart(char *cmd)
arch/blackfin/kernel/process.c +0 -3
index 4aa5545..812dd83 100644
@@ -39,9 +39,6 @@ int nr_l1stack_tasks;
 void *l1_stack_base;
 unsigned long l1_stack_len;
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * The idle loop on BFIN
  */
arch/blackfin/kernel/reboot.c +2 -0
index c4f50a3..387d610 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/interrupt.h>
+#include <linux/pm.h>
 #include <asm/bfin-global.h>
 #include <asm/reboot.h>
 #include <asm/bfrom.h>
@@ -106,6 +107,7 @@ void machine_halt(void)
 __attribute__((weak))
 void native_machine_power_off(void)
 {
+       do_kernel_power_off();
        idle_with_irq_disabled();
 }
 
arch/c6x/kernel/process.c +1 -8
index 57d2ea8..edf7e5a 100644
@@ -27,12 +27,6 @@ void (*c6x_halt)(void);
 extern asmlinkage void ret_from_fork(void);
 extern asmlinkage void ret_from_kernel_thread(void);
 
-/*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
        unsigned long tmp;
@@ -73,8 +67,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        halt_loop();
 }
 
arch/cris/kernel/process.c +1 -3
index b78498e..9ebd76b 100644
@@ -31,9 +31,6 @@
 
 extern void default_idle(void);
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
        default_idle();
@@ -60,6 +57,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
+       do_kernel_power_off();
 }
 
 /*
arch/frv/kernel/process.c +2 -3
index 5d40aeb77..502dabb 100644
@@ -42,9 +42,6 @@ asmlinkage void ret_from_kernel_thread(void);
 
 #include <asm/pgalloc.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static void core_sleep_idle(void)
 {
 #ifdef LED_DEBUG_SLEEP
@@ -107,6 +104,8 @@ void machine_power_off(void)
        gdbstub_exit(0);
 #endif
 
+       do_kernel_power_off();
+
        for (;;);
 }
 
arch/hexagon/kernel/reset.c +2 -3
index 76483c1..6f607b6 100644
@@ -16,11 +16,13 @@
  * 02110-1301, USA.
  */
 
+#include <linux/pm.h>
 #include <linux/smp.h>
 #include <asm/hexagon_vm.h>
 
 void machine_power_off(void)
 {
+       do_kernel_power_off();
        smp_send_stop();
        __vmstop();
 }
@@ -32,6 +34,3 @@ void machine_halt(void)
 void machine_restart(char *cmd)
 {
 }
-
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/ia64/kernel/process.c +1 -4
index b515149..88121a2 100644
@@ -57,8 +57,6 @@ void (*ia64_mark_idle)(int);
 
 unsigned long boot_option_idle_override = IDLE_NO_OVERRIDE;
 EXPORT_SYMBOL(boot_option_idle_override);
-void (*pm_power_off) (void);
-EXPORT_SYMBOL(pm_power_off);
 
 void
 ia64_do_show_stack (struct unw_frame_info *info, void *arg)
@@ -675,8 +673,7 @@ machine_halt (void)
 void
 machine_power_off (void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        machine_halt();
 }
 
arch/m32r/kernel/process.c +4 -4
index e69221d..65a037e 100644
@@ -23,6 +23,7 @@
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/unistd.h>
 #include <linux/hardirq.h>
@@ -44,9 +45,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
        return tsk->thread.lr;
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_restart(char *__unused)
 {
 #if defined(CONFIG_PLAT_MAPPI3)
@@ -67,7 +65,9 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       /* M32R_FIXME */
+       do_kernel_power_off();
+       for (;;)
+               ;
 }
 
 void show_regs(struct pt_regs * regs)
arch/m68k/kernel/process.c +1 -5
index afe3d6e..bbc0a63 100644
@@ -78,14 +78,10 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        for (;;);
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void show_regs(struct pt_regs * regs)
 {
        printk("\n");
arch/metag/kernel/process.c +1 -5
index 483dff9..8d95773 100644
@@ -67,9 +67,6 @@ void arch_cpu_idle_dead(void)
 }
 #endif
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void (*soc_restart)(char *cmd);
 void (*soc_halt)(void);
 
@@ -90,8 +87,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        smp_send_stop();
        hard_processor_halt(HALT_OK);
 }
arch/microblaze/kernel/process.c +0 -3
index b2dd371..0ebca36 100644
@@ -44,9 +44,6 @@ void show_regs(struct pt_regs *regs)
                                regs->msr, regs->ear, regs->esr, regs->fsr);
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void flush_thread(void)
 {
 }
arch/microblaze/kernel/reset.c +1 -0
index fbe58c6..2c6b32c 100644
@@ -103,6 +103,7 @@ void machine_halt(void)
 void machine_power_off(void)
 {
        pr_notice("Machine power off...\n");
+       do_kernel_power_off();
        while (1)
                ;
 }
arch/mips/kernel/reset.c +1 -5
index 07fc524..09e74d2 100644
@@ -21,9 +21,6 @@
  */
 void (*_machine_restart)(char *command);
 void (*_machine_halt)(void);
-void (*pm_power_off)(void);
-
-EXPORT_SYMBOL(pm_power_off);
 
 void machine_restart(char *command)
 {
@@ -39,6 +36,5 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
arch/mn10300/kernel/process.c +2 -6
index 3707da5..c78b2eb 100644
@@ -20,6 +20,7 @@
 #include <linux/user.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/percpu.h>
 #include <linux/err.h>
@@ -45,12 +46,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
 }
 
 /*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
-/*
  * On SMP it's slightly faster (but much more power-consuming!)
  * to poll the ->work.need_resched flag instead of waiting for the
  * cross-CPU IPI to arrive. Use this option with caution.
@@ -93,6 +88,7 @@ void machine_power_off(void)
 #ifdef CONFIG_KERNEL_DEBUGGER
        gdbstub_exit(0);
 #endif
+       do_kernel_power_off();
 }
 
 void show_regs(struct pt_regs *regs)
arch/openrisc/kernel/process.c +5 -3
index 386af25..494afd2 100644
@@ -25,6 +25,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mm.h>
+#include <linux/pm.h>
 #include <linux/stddef.h>
 #include <linux/unistd.h>
 #include <linux/ptrace.h>
@@ -51,7 +52,7 @@
  */
 struct thread_info *current_thread_info_set[NR_CPUS] = { &init_thread_info, };
 
-void machine_restart(void)
+void machine_restart(char *cmd)
 {
        printk(KERN_INFO "*** MACHINE RESTART ***\n");
        __asm__("l.nop 1");
@@ -72,11 +73,12 @@ void machine_halt(void)
 void machine_power_off(void)
 {
        printk(KERN_INFO "*** MACHINE POWER OFF ***\n");
+
+       do_kernel_power_off();
+
        __asm__("l.nop 1");
 }
 
-void (*pm_power_off) (void) = machine_power_off;
-
 /*
  * When a process does an "exec", machine state like FPU and debug
  * registers need to be reset.  This is a hook function for that.
arch/parisc/kernel/process.c +4 -4
index 0bbbf0d..3f5d14a 100644
@@ -41,6 +41,7 @@
 #include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/personality.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/sched.h>
 #include <linux/slab.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_power_off();
+
        /* It seems we have no way to power the system off via
         * software. The user has to press the button himself. */
 
@@ -141,9 +144,6 @@ void machine_power_off(void)
               "Please power this system off now.");
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * Free current thread data structures etc..
  */
arch/powerpc/kernel/setup-common.c +3 -3
index 1362cd6..5b7a851 100644
@@ -141,6 +141,9 @@ void machine_power_off(void)
        machine_shutdown();
        if (ppc_md.power_off)
                ppc_md.power_off();
+
+       do_kernel_power_off();
+
 #ifdef CONFIG_SMP
        smp_send_stop();
 #endif
@@ -151,9 +154,6 @@ void machine_power_off(void)
 /* Used by the G5 thermal driver */
 EXPORT_SYMBOL_GPL(machine_power_off);
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
-
 void machine_halt(void)
 {
        machine_shutdown();
arch/s390/kernel/setup.c +2 -6
index e80d9ff..267e025 100644
@@ -263,13 +263,9 @@ void machine_power_off(void)
                 */
                console_unblank();
        _machine_power_off();
-}
 
-/*
- * Dummy power off function.
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
+       do_kernel_power_off();
+}
 
 static int __init early_parse_mem(char *p)
 {
arch/score/kernel/process.c +4 -4
index a1519ad3..b76ea67 100644
@@ -29,9 +29,6 @@
 #include <linux/pm.h>
 #include <linux/rcupdate.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /* If or when software machine-restart is implemented, add code here. */
 void machine_restart(char *command) {}
 
@@ -39,7 +36,10 @@ void machine_restart(char *command) {}
 void machine_halt(void) {}
 
 /* If or when software machine-power-off is implemented, add code here. */
-void machine_power_off(void) {}
+void machine_power_off(void)
+{
+       do_kernel_power_off();
+}
 
 void ret_from_fork(void);
 void ret_from_kernel_thread(void);
arch/sh/kernel/reboot.c +1 -5
index 04afe5b..065de12 100644
@@ -11,9 +11,6 @@
 #include <asm/tlbflush.h>
 #include <asm/traps.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_SUPERH32
 static void watchdog_trigger_immediate(void)
 {
@@ -51,8 +48,7 @@ static void native_machine_shutdown(void)
 
 static void native_machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 static void native_machine_halt(void)
arch/sparc/kernel/process_32.c +2 -8
index 50e7b62..cb8148a 100644
@@ -48,14 +48,6 @@
  */
 void (*sparc_idle)(void);
 
-/*
- * Power-off handler instantiation for pm.h compliance
- * This is done via auxio, but could be used as a fallback
- * handler when auxio is not present-- unused for now...
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * sysctl - toggle power-off restriction for serial console
  * systems in machine_power_off()
@@ -112,6 +104,8 @@ void machine_power_off(void)
                sbus_writeb(power_register, auxio_power_register);
        }
 
+       do_kernel_power_off();
+
        machine_halt();
 }
 
arch/sparc/kernel/reboot.c +2 -6
index eba7d91..3c0bb03 100644
@@ -16,17 +16,13 @@
  */
 int scons_pwroff = 1;
 
-/* This isn't actually used, it exists merely to satisfy the
- * reference in kernel/sys.c
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
        if (strcmp(of_console_device->type, "serial") || scons_pwroff)
                prom_halt_power_off();
 
+       do_kernel_power_off();
+
        prom_halt();
 }
 
arch/tile/kernel/reboot.c +3 -4
index 6c5d2c0..8ff4a7f 100644
@@ -36,6 +36,9 @@ void machine_power_off(void)
 {
        arch_local_irq_disable_all();
        smp_send_stop();
+
+       do_kernel_power_off();
+
        hv_power_off();
 }
 
@@ -45,7 +48,3 @@ void machine_restart(char *cmd)
        smp_send_stop();
        hv_restart((HV_VirtAddr) "vmlinux", (HV_VirtAddr) cmd);
 }
-
-/* No interesting distinction to be made here. */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/um/kernel/reboot.c +0 -2
index ced8903..a82ef28 100644
@@ -11,8 +11,6 @@
 #include <os.h>
 #include <skas.h>
 
-void (*pm_power_off)(void);
-
 static void kill_off_processes(void)
 {
        if (proc_mm)
arch/unicore32/kernel/process.c +1 -8
index b008e99..9490dd5 100644
@@ -56,16 +56,9 @@ void machine_halt(void)
        gpio_set_value(GPO_SOFT_OFF, 0);
 }
 
-/*
- * Function pointers to optional machine specific functions
- */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        machine_halt();
 }
 
arch/x86/kernel/reboot.c +3 -8
index 17962e6..5c09e28 100644
@@ -30,12 +30,6 @@
 #include <asm/x86_init.h>
 #include <asm/efi.h>
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static const struct desc_ptr no_idt = {};
 
 /*
@@ -647,11 +641,12 @@ static void native_machine_halt(void)
 
 static void native_machine_power_off(void)
 {
-       if (pm_power_off) {
+       if (have_kernel_power_off()) {
                if (!reboot_force)
                        machine_shutdown();
-               pm_power_off();
+               do_kernel_power_off();
        }
+
        /* A fallback in case there is no PM info available */
        tboot_shutdown(TB_SHUTDOWN_HALT);
 }
arch/x86/xen/enlighten.c +1 -2
index 1a3f044..c2c1d74 100644
@@ -1320,8 +1320,7 @@ static void xen_machine_halt(void)
 
 static void xen_machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        xen_reboot(SHUTDOWN_poweroff);
 }
 
arch/xtensa/kernel/process.c +0 -4
index 1c85323..c487296 100644
@@ -49,10 +49,6 @@ extern void ret_from_kernel_thread(void);
 
 struct task_struct *current_set[NR_CPUS] = {&init_task, };
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
-
 #if XTENSA_HAVE_COPROCESSORS
 
 void coprocessor_release_all(struct thread_info *ti)
drivers/parisc/power.c +1 -2
index ef31b77..f10cf92 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();
                }
        }
 }
kernel/power/poweroff_handler.c +8 -0
index aeb4736..37f0b88 100644
@@ -22,6 +22,12 @@
 #include <linux/types.h>
 
 /*
+ * If set, calling this function will power off the system immediately.
+ */
+void (*pm_power_off)(void);
+EXPORT_SYMBOL(pm_power_off);
+
+/*
  *     Notifier list for kernel code which wants to be called
  *     to power off the system.
  */
@@ -236,6 +242,8 @@ EXPORT_SYMBOL(devm_register_power_off_handler);
 void do_kernel_power_off(void)
 {
        spin_lock(&power_off_handler_lock);
+       if (pm_power_off)
+               pm_power_off();
        raw_notifier_call_chain(&power_off_handler_list, 0, NULL);
        spin_unlock(&power_off_handler_lock);
 }
kernel/reboot.c +2 -3
index 5925f5a..0930851 100644
@@ -306,9 +306,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
                return ret;
 
        /* Instead of trying to make the power_off code look like
-        * halt when pm_power_off is not set do it the easy way.
+        * halt when no poweroff handler exists do it the easy way.
         */
-       if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
+       if (cmd == LINUX_REBOOT_CMD_POWER_OFF && !have_kernel_power_off())
                cmd = LINUX_REBOOT_CMD_HALT;
 
        mutex_lock(&reboot_mutex);
--

1.9.1

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

Acked-by on v2 8/47
#40 lore raw

Re: [PATCH v2 08/47] kernel: Move pm_power_off to common code

In reply to Guenter Roeck

2014-10-21 12:12 GMT+08:00 Guenter Roeck <[email protected]>:

Quoted 886 lines

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

---
v2:
- do_kernel_poweroff -> do_kernel_power_off
- have_kernel_poweroff -> have_kernel_power_off

 arch/alpha/kernel/process.c        |  9 +++------
 arch/arc/kernel/reset.c            |  5 +----
 arch/arm/kernel/process.c          |  5 +----
 arch/arm64/kernel/process.c        |  5 +----
 arch/avr32/kernel/process.c        |  6 +-----
 arch/blackfin/kernel/process.c     |  3 ---
 arch/blackfin/kernel/reboot.c      |  2 ++
 arch/c6x/kernel/process.c          |  9 +--------
 arch/cris/kernel/process.c         |  4 +---
 arch/frv/kernel/process.c          |  5 ++---
 arch/hexagon/kernel/reset.c        |  5 ++---
 arch/ia64/kernel/process.c         |  5 +----
 arch/m32r/kernel/process.c         |  8 ++++----
 arch/m68k/kernel/process.c         |  6 +-----
 arch/metag/kernel/process.c        |  6 +-----
 arch/microblaze/kernel/process.c   |  3 ---
 arch/microblaze/kernel/reset.c     |  1 +
 arch/mips/kernel/reset.c           |  6 +-----
 arch/mn10300/kernel/process.c      |  8 ++------
 arch/openrisc/kernel/process.c     |  8 +++++---
 arch/parisc/kernel/process.c       |  8 ++++----
 arch/powerpc/kernel/setup-common.c |  6 +++---
 arch/s390/kernel/setup.c           |  8 ++------
 arch/score/kernel/process.c        |  8 ++++----
 arch/sh/kernel/reboot.c            |  6 +-----
 arch/sparc/kernel/process_32.c     | 10 ++--------
 arch/sparc/kernel/reboot.c         |  8 ++------
 arch/tile/kernel/reboot.c          |  7 +++----
 arch/um/kernel/reboot.c            |  2 --
 arch/unicore32/kernel/process.c    |  9 +--------
 arch/x86/kernel/reboot.c           | 11 +++--------
 arch/x86/xen/enlighten.c           |  3 +--
 arch/xtensa/kernel/process.c       |  4 ----
 drivers/parisc/power.c             |  3 +--
 kernel/power/poweroff_handler.c    |  8 ++++++++
 kernel/reboot.c                    |  4 ++--
 36 files changed, 68 insertions(+), 146 deletions(-)
arch/alpha/kernel/process.c +3 -6
index 1941a07..81c43f8 100644
@@ -24,6 +24,7 @@
 #include <linux/vt.h>
 #include <linux/mman.h>
 #include <linux/elfcore.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/tty.h>
 #include <linux/console.h>
@@ -40,12 +41,6 @@
 #include "proto.h"
 #include "pci_impl.h"
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_ALPHA_WTINT
 /*
  * Sleep the CPU.
@@ -184,6 +179,8 @@ machine_halt(void)
 void
 machine_power_off(void)
 {
+       do_kernel_power_off();
+
        common_shutdown(LINUX_REBOOT_CMD_POWER_OFF, NULL);
 }
 
arch/arc/kernel/reset.c +1 -4
index 2768fa1..0758d9d 100644
@@ -26,9 +26,6 @@ void machine_restart(char *__unused)
 
 void machine_power_off(void)
 {
-       /* FIXME ::  power off ??? */
+       do_kernel_power_off();
        machine_halt();
 }
-
-void (*pm_power_off) (void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/arm/kernel/process.c +1 -4
index fe972a2..aa3f656 100644
@@ -117,8 +117,6 @@ void soft_restart(unsigned long addr)
 /*
  * 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);
 
@@ -205,8 +203,7 @@ void machine_power_off(void)
        local_irq_disable();
        smp_send_stop();
 
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 /*
arch/arm64/kernel/process.c +1 -4
index c3065db..46a483a 100644
@@ -68,8 +68,6 @@ void soft_restart(unsigned long addr)
 /*
  * Function pointers to optional machine specific functions
  */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL_GPL(pm_power_off);
 
 void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
 
@@ -129,8 +127,7 @@ void machine_power_off(void)
 {
        local_irq_disable();
        smp_send_stop();
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 /*
arch/avr32/kernel/process.c +1 -5
index 42a53e74..529c1f6 100644
@@ -23,9 +23,6 @@
 
 #include <mach/pm.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * This file handles the architecture-dependent parts of process handling..
  */
@@ -48,8 +45,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 void machine_restart(char *cmd)
arch/blackfin/kernel/process.c +0 -3
index 4aa5545..812dd83 100644
@@ -39,9 +39,6 @@ int nr_l1stack_tasks;
 void *l1_stack_base;
 unsigned long l1_stack_len;
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * The idle loop on BFIN
  */
arch/blackfin/kernel/reboot.c +2 -0
index c4f50a3..387d610 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/interrupt.h>
+#include <linux/pm.h>
 #include <asm/bfin-global.h>
 #include <asm/reboot.h>
 #include <asm/bfrom.h>
@@ -106,6 +107,7 @@ void machine_halt(void)
 __attribute__((weak))
 void native_machine_power_off(void)
 {
+       do_kernel_power_off();
        idle_with_irq_disabled();
 }
 
arch/c6x/kernel/process.c +1 -8
index 57d2ea8..edf7e5a 100644
@@ -27,12 +27,6 @@ void (*c6x_halt)(void);
 extern asmlinkage void ret_from_fork(void);
 extern asmlinkage void ret_from_kernel_thread(void);
 
-/*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
        unsigned long tmp;
@@ -73,8 +67,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        halt_loop();
 }
 
arch/cris/kernel/process.c +1 -3
index b78498e..9ebd76b 100644
@@ -31,9 +31,6 @@
 
 extern void default_idle(void);
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
        default_idle();
@@ -60,6 +57,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
+       do_kernel_power_off();
 }
 
 /*
arch/frv/kernel/process.c +2 -3
index 5d40aeb77..502dabb 100644
@@ -42,9 +42,6 @@ asmlinkage void ret_from_kernel_thread(void);
 
 #include <asm/pgalloc.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static void core_sleep_idle(void)
 {
 #ifdef LED_DEBUG_SLEEP
@@ -107,6 +104,8 @@ void machine_power_off(void)
        gdbstub_exit(0);
 #endif
 
+       do_kernel_power_off();
+
        for (;;);
 }
 
arch/hexagon/kernel/reset.c +2 -3
index 76483c1..6f607b6 100644
@@ -16,11 +16,13 @@
  * 02110-1301, USA.
  */
 
+#include <linux/pm.h>
 #include <linux/smp.h>
 #include <asm/hexagon_vm.h>
 
 void machine_power_off(void)
 {
+       do_kernel_power_off();
        smp_send_stop();
        __vmstop();
 }
@@ -32,6 +34,3 @@ void machine_halt(void)
 void machine_restart(char *cmd)
 {
 }
-
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/ia64/kernel/process.c +1 -4
index b515149..88121a2 100644
@@ -57,8 +57,6 @@ void (*ia64_mark_idle)(int);
 
 unsigned long boot_option_idle_override = IDLE_NO_OVERRIDE;
 EXPORT_SYMBOL(boot_option_idle_override);
-void (*pm_power_off) (void);
-EXPORT_SYMBOL(pm_power_off);
 
 void
 ia64_do_show_stack (struct unw_frame_info *info, void *arg)
@@ -675,8 +673,7 @@ machine_halt (void)
 void
 machine_power_off (void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        machine_halt();
 }
 
arch/m32r/kernel/process.c +4 -4
index e69221d..65a037e 100644
@@ -23,6 +23,7 @@
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/unistd.h>
 #include <linux/hardirq.h>
@@ -44,9 +45,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
        return tsk->thread.lr;
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_restart(char *__unused)
 {
 #if defined(CONFIG_PLAT_MAPPI3)
@@ -67,7 +65,9 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       /* M32R_FIXME */
+       do_kernel_power_off();
+       for (;;)
+               ;
 }
 
 void show_regs(struct pt_regs * regs)
arch/m68k/kernel/process.c +1 -5
index afe3d6e..bbc0a63 100644
@@ -78,14 +78,10 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        for (;;);
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void show_regs(struct pt_regs * regs)
 {
        printk("\n");
arch/metag/kernel/process.c +1 -5
index 483dff9..8d95773 100644
@@ -67,9 +67,6 @@ void arch_cpu_idle_dead(void)
 }
 #endif
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void (*soc_restart)(char *cmd);
 void (*soc_halt)(void);
 
@@ -90,8 +87,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        smp_send_stop();
        hard_processor_halt(HALT_OK);
 }
arch/microblaze/kernel/process.c +0 -3
index b2dd371..0ebca36 100644
@@ -44,9 +44,6 @@ void show_regs(struct pt_regs *regs)
                                regs->msr, regs->ear, regs->esr, regs->fsr);
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void flush_thread(void)
 {
 }
arch/microblaze/kernel/reset.c +1 -0
index fbe58c6..2c6b32c 100644
@@ -103,6 +103,7 @@ void machine_halt(void)
 void machine_power_off(void)
 {
        pr_notice("Machine power off...\n");
+       do_kernel_power_off();
        while (1)
                ;
 }
arch/mips/kernel/reset.c +1 -5
index 07fc524..09e74d2 100644
@@ -21,9 +21,6 @@
  */
 void (*_machine_restart)(char *command);
 void (*_machine_halt)(void);
-void (*pm_power_off)(void);
-
-EXPORT_SYMBOL(pm_power_off);
 
 void machine_restart(char *command)
 {
@@ -39,6 +36,5 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
arch/mn10300/kernel/process.c +2 -6
index 3707da5..c78b2eb 100644
@@ -20,6 +20,7 @@
 #include <linux/user.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/percpu.h>
 #include <linux/err.h>
@@ -45,12 +46,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
 }
 
 /*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
-/*
  * On SMP it's slightly faster (but much more power-consuming!)
  * to poll the ->work.need_resched flag instead of waiting for the
  * cross-CPU IPI to arrive. Use this option with caution.
@@ -93,6 +88,7 @@ void machine_power_off(void)
 #ifdef CONFIG_KERNEL_DEBUGGER
        gdbstub_exit(0);
 #endif
+       do_kernel_power_off();
 }
 
 void show_regs(struct pt_regs *regs)
arch/openrisc/kernel/process.c +5 -3
index 386af25..494afd2 100644
@@ -25,6 +25,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mm.h>
+#include <linux/pm.h>
 #include <linux/stddef.h>
 #include <linux/unistd.h>
 #include <linux/ptrace.h>
@@ -51,7 +52,7 @@
  */
 struct thread_info *current_thread_info_set[NR_CPUS] = { &init_thread_info, };
 
-void machine_restart(void)
+void machine_restart(char *cmd)
 {
        printk(KERN_INFO "*** MACHINE RESTART ***\n");
        __asm__("l.nop 1");
@@ -72,11 +73,12 @@ void machine_halt(void)
 void machine_power_off(void)
 {
        printk(KERN_INFO "*** MACHINE POWER OFF ***\n");
+
+       do_kernel_power_off();
+
        __asm__("l.nop 1");
 }
 
-void (*pm_power_off) (void) = machine_power_off;
-
 /*
  * When a process does an "exec", machine state like FPU and debug
  * registers need to be reset.  This is a hook function for that.
arch/parisc/kernel/process.c +4 -4
index 0bbbf0d..3f5d14a 100644
@@ -41,6 +41,7 @@
 #include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/personality.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/sched.h>
 #include <linux/slab.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_power_off();
+
        /* It seems we have no way to power the system off via
         * software. The user has to press the button himself. */
 
@@ -141,9 +144,6 @@ void machine_power_off(void)
               "Please power this system off now.");
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * Free current thread data structures etc..
  */
arch/powerpc/kernel/setup-common.c +3 -3
index 1362cd6..5b7a851 100644
@@ -141,6 +141,9 @@ void machine_power_off(void)
        machine_shutdown();
        if (ppc_md.power_off)
                ppc_md.power_off();
+
+       do_kernel_power_off();
+
 #ifdef CONFIG_SMP
        smp_send_stop();
 #endif
@@ -151,9 +154,6 @@ void machine_power_off(void)
 /* Used by the G5 thermal driver */
 EXPORT_SYMBOL_GPL(machine_power_off);
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
-
 void machine_halt(void)
 {
        machine_shutdown();
arch/s390/kernel/setup.c +2 -6
index e80d9ff..267e025 100644
@@ -263,13 +263,9 @@ void machine_power_off(void)
                 */
                console_unblank();
        _machine_power_off();
-}
 
-/*
- * Dummy power off function.
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
+       do_kernel_power_off();
+}
 
 static int __init early_parse_mem(char *p)
 {
arch/score/kernel/process.c +4 -4
index a1519ad3..b76ea67 100644
@@ -29,9 +29,6 @@
 #include <linux/pm.h>
 #include <linux/rcupdate.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /* If or when software machine-restart is implemented, add code here. */
 void machine_restart(char *command) {}
 
@@ -39,7 +36,10 @@ void machine_restart(char *command) {}
 void machine_halt(void) {}
 
 /* If or when software machine-power-off is implemented, add code here. */
-void machine_power_off(void) {}
+void machine_power_off(void)
+{
+       do_kernel_power_off();
+}
 
 void ret_from_fork(void);
 void ret_from_kernel_thread(void);
arch/sh/kernel/reboot.c +1 -5
index 04afe5b..065de12 100644
@@ -11,9 +11,6 @@
 #include <asm/tlbflush.h>
 #include <asm/traps.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_SUPERH32
 static void watchdog_trigger_immediate(void)
 {
@@ -51,8 +48,7 @@ static void native_machine_shutdown(void)
 
 static void native_machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 static void native_machine_halt(void)
arch/sparc/kernel/process_32.c +2 -8
index 50e7b62..cb8148a 100644
@@ -48,14 +48,6 @@
  */
 void (*sparc_idle)(void);
 
-/*
- * Power-off handler instantiation for pm.h compliance
- * This is done via auxio, but could be used as a fallback
- * handler when auxio is not present-- unused for now...
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * sysctl - toggle power-off restriction for serial console
  * systems in machine_power_off()
@@ -112,6 +104,8 @@ void machine_power_off(void)
                sbus_writeb(power_register, auxio_power_register);
        }
 
+       do_kernel_power_off();
+
        machine_halt();
 }
 
arch/sparc/kernel/reboot.c +2 -6
index eba7d91..3c0bb03 100644
@@ -16,17 +16,13 @@
  */
 int scons_pwroff = 1;
 
-/* This isn't actually used, it exists merely to satisfy the
- * reference in kernel/sys.c
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
        if (strcmp(of_console_device->type, "serial") || scons_pwroff)
                prom_halt_power_off();
 
+       do_kernel_power_off();
+
        prom_halt();
 }
 
arch/tile/kernel/reboot.c +3 -4
index 6c5d2c0..8ff4a7f 100644
@@ -36,6 +36,9 @@ void machine_power_off(void)
 {
        arch_local_irq_disable_all();
        smp_send_stop();
+
+       do_kernel_power_off();
+
        hv_power_off();
 }
 
@@ -45,7 +48,3 @@ void machine_restart(char *cmd)
        smp_send_stop();
        hv_restart((HV_VirtAddr) "vmlinux", (HV_VirtAddr) cmd);
 }
-
-/* No interesting distinction to be made here. */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/um/kernel/reboot.c +0 -2
index ced8903..a82ef28 100644
@@ -11,8 +11,6 @@
 #include <os.h>
 #include <skas.h>
 
-void (*pm_power_off)(void);
-
 static void kill_off_processes(void)
 {
        if (proc_mm)
arch/unicore32/kernel/process.c +1 -8
index b008e99..9490dd5 100644
@@ -56,16 +56,9 @@ void machine_halt(void)
        gpio_set_value(GPO_SOFT_OFF, 0);
 }
 
-/*
- * Function pointers to optional machine specific functions
- */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        machine_halt();
 }
 
arch/x86/kernel/reboot.c +3 -8
index 17962e6..5c09e28 100644
@@ -30,12 +30,6 @@
 #include <asm/x86_init.h>
 #include <asm/efi.h>
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static const struct desc_ptr no_idt = {};
 
 /*
@@ -647,11 +641,12 @@ static void native_machine_halt(void)
 
 static void native_machine_power_off(void)
 {
-       if (pm_power_off) {
+       if (have_kernel_power_off()) {
                if (!reboot_force)
                        machine_shutdown();
-               pm_power_off();
+               do_kernel_power_off();
        }
+
        /* A fallback in case there is no PM info available */
        tboot_shutdown(TB_SHUTDOWN_HALT);
 }
arch/x86/xen/enlighten.c +1 -2
index 1a3f044..c2c1d74 100644
@@ -1320,8 +1320,7 @@ static void xen_machine_halt(void)
 
 static void xen_machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        xen_reboot(SHUTDOWN_poweroff);
 }
 
arch/xtensa/kernel/process.c +0 -4
index 1c85323..c487296 100644
@@ -49,10 +49,6 @@ extern void ret_from_kernel_thread(void);
 
 struct task_struct *current_set[NR_CPUS] = {&init_task, };
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
-
 #if XTENSA_HAVE_COPROCESSORS
 
 void coprocessor_release_all(struct thread_info *ti)
drivers/parisc/power.c +1 -2
index ef31b77..f10cf92 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();
                }
        }
 }
kernel/power/poweroff_handler.c +8 -0
index aeb4736..37f0b88 100644
@@ -22,6 +22,12 @@
 #include <linux/types.h>
 
 /*
+ * If set, calling this function will power off the system immediately.
+ */
+void (*pm_power_off)(void);
+EXPORT_SYMBOL(pm_power_off);
+
+/*
  *     Notifier list for kernel code which wants to be called
  *     to power off the system.
  */
@@ -236,6 +242,8 @@ EXPORT_SYMBOL(devm_register_power_off_handler);
 void do_kernel_power_off(void)
 {
        spin_lock(&power_off_handler_lock);
+       if (pm_power_off)
+               pm_power_off();
        raw_notifier_call_chain(&power_off_handler_list, 0, NULL);
        spin_unlock(&power_off_handler_lock);
 }
kernel/reboot.c +2 -3
index 5925f5a..0930851 100644
@@ -306,9 +306,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
                return ret;
 
        /* Instead of trying to make the power_off code look like
-        * halt when pm_power_off is not set do it the easy way.
+        * halt when no poweroff handler exists do it the easy way.
         */
-       if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
+       if (cmd == LINUX_REBOOT_CMD_POWER_OFF && !have_kernel_power_off())
                cmd = LINUX_REBOOT_CMD_HALT;
 
        mutex_lock(&reboot_mutex);
--

1.9.1

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

Acked-by on v2 8/47
#41 lore raw

Re: [PATCH v2 08/47] kernel: Move pm_power_off to common code

In reply to Guenter Roeck

2014-10-21 12:12 GMT+08:00 Guenter Roeck <[email protected]>:

Quoted 886 lines

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

---
v2:
- do_kernel_poweroff -> do_kernel_power_off
- have_kernel_poweroff -> have_kernel_power_off

 arch/alpha/kernel/process.c        |  9 +++------
 arch/arc/kernel/reset.c            |  5 +----
 arch/arm/kernel/process.c          |  5 +----
 arch/arm64/kernel/process.c        |  5 +----
 arch/avr32/kernel/process.c        |  6 +-----
 arch/blackfin/kernel/process.c     |  3 ---
 arch/blackfin/kernel/reboot.c      |  2 ++
 arch/c6x/kernel/process.c          |  9 +--------
 arch/cris/kernel/process.c         |  4 +---
 arch/frv/kernel/process.c          |  5 ++---
 arch/hexagon/kernel/reset.c        |  5 ++---
 arch/ia64/kernel/process.c         |  5 +----
 arch/m32r/kernel/process.c         |  8 ++++----
 arch/m68k/kernel/process.c         |  6 +-----
 arch/metag/kernel/process.c        |  6 +-----
 arch/microblaze/kernel/process.c   |  3 ---
 arch/microblaze/kernel/reset.c     |  1 +
 arch/mips/kernel/reset.c           |  6 +-----
 arch/mn10300/kernel/process.c      |  8 ++------
 arch/openrisc/kernel/process.c     |  8 +++++---
 arch/parisc/kernel/process.c       |  8 ++++----
 arch/powerpc/kernel/setup-common.c |  6 +++---
 arch/s390/kernel/setup.c           |  8 ++------
 arch/score/kernel/process.c        |  8 ++++----
 arch/sh/kernel/reboot.c            |  6 +-----
 arch/sparc/kernel/process_32.c     | 10 ++--------
 arch/sparc/kernel/reboot.c         |  8 ++------
 arch/tile/kernel/reboot.c          |  7 +++----
 arch/um/kernel/reboot.c            |  2 --
 arch/unicore32/kernel/process.c    |  9 +--------
 arch/x86/kernel/reboot.c           | 11 +++--------
 arch/x86/xen/enlighten.c           |  3 +--
 arch/xtensa/kernel/process.c       |  4 ----
 drivers/parisc/power.c             |  3 +--
 kernel/power/poweroff_handler.c    |  8 ++++++++
 kernel/reboot.c                    |  4 ++--
 36 files changed, 68 insertions(+), 146 deletions(-)
arch/alpha/kernel/process.c +3 -6
index 1941a07..81c43f8 100644
@@ -24,6 +24,7 @@
 #include <linux/vt.h>
 #include <linux/mman.h>
 #include <linux/elfcore.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/tty.h>
 #include <linux/console.h>
@@ -40,12 +41,6 @@
 #include "proto.h"
 #include "pci_impl.h"
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_ALPHA_WTINT
 /*
  * Sleep the CPU.
@@ -184,6 +179,8 @@ machine_halt(void)
 void
 machine_power_off(void)
 {
+       do_kernel_power_off();
+
        common_shutdown(LINUX_REBOOT_CMD_POWER_OFF, NULL);
 }
 
arch/arc/kernel/reset.c +1 -4
index 2768fa1..0758d9d 100644
@@ -26,9 +26,6 @@ void machine_restart(char *__unused)
 
 void machine_power_off(void)
 {
-       /* FIXME ::  power off ??? */
+       do_kernel_power_off();
        machine_halt();
 }
-
-void (*pm_power_off) (void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/arm/kernel/process.c +1 -4
index fe972a2..aa3f656 100644
@@ -117,8 +117,6 @@ void soft_restart(unsigned long addr)
 /*
  * 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);
 
@@ -205,8 +203,7 @@ void machine_power_off(void)
        local_irq_disable();
        smp_send_stop();
 
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 /*
arch/arm64/kernel/process.c +1 -4
index c3065db..46a483a 100644
@@ -68,8 +68,6 @@ void soft_restart(unsigned long addr)
 /*
  * Function pointers to optional machine specific functions
  */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL_GPL(pm_power_off);
 
 void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
 
@@ -129,8 +127,7 @@ void machine_power_off(void)
 {
        local_irq_disable();
        smp_send_stop();
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 /*
arch/avr32/kernel/process.c +1 -5
index 42a53e74..529c1f6 100644
@@ -23,9 +23,6 @@
 
 #include <mach/pm.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * This file handles the architecture-dependent parts of process handling..
  */
@@ -48,8 +45,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 void machine_restart(char *cmd)
arch/blackfin/kernel/process.c +0 -3
index 4aa5545..812dd83 100644
@@ -39,9 +39,6 @@ int nr_l1stack_tasks;
 void *l1_stack_base;
 unsigned long l1_stack_len;
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * The idle loop on BFIN
  */
arch/blackfin/kernel/reboot.c +2 -0
index c4f50a3..387d610 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/interrupt.h>
+#include <linux/pm.h>
 #include <asm/bfin-global.h>
 #include <asm/reboot.h>
 #include <asm/bfrom.h>
@@ -106,6 +107,7 @@ void machine_halt(void)
 __attribute__((weak))
 void native_machine_power_off(void)
 {
+       do_kernel_power_off();
        idle_with_irq_disabled();
 }
 
arch/c6x/kernel/process.c +1 -8
index 57d2ea8..edf7e5a 100644
@@ -27,12 +27,6 @@ void (*c6x_halt)(void);
 extern asmlinkage void ret_from_fork(void);
 extern asmlinkage void ret_from_kernel_thread(void);
 
-/*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
        unsigned long tmp;
@@ -73,8 +67,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        halt_loop();
 }
 
arch/cris/kernel/process.c +1 -3
index b78498e..9ebd76b 100644
@@ -31,9 +31,6 @@
 
 extern void default_idle(void);
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
        default_idle();
@@ -60,6 +57,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
+       do_kernel_power_off();
 }
 
 /*
arch/frv/kernel/process.c +2 -3
index 5d40aeb77..502dabb 100644
@@ -42,9 +42,6 @@ asmlinkage void ret_from_kernel_thread(void);
 
 #include <asm/pgalloc.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static void core_sleep_idle(void)
 {
 #ifdef LED_DEBUG_SLEEP
@@ -107,6 +104,8 @@ void machine_power_off(void)
        gdbstub_exit(0);
 #endif
 
+       do_kernel_power_off();
+
        for (;;);
 }
 
arch/hexagon/kernel/reset.c +2 -3
index 76483c1..6f607b6 100644
@@ -16,11 +16,13 @@
  * 02110-1301, USA.
  */
 
+#include <linux/pm.h>
 #include <linux/smp.h>
 #include <asm/hexagon_vm.h>
 
 void machine_power_off(void)
 {
+       do_kernel_power_off();
        smp_send_stop();
        __vmstop();
 }
@@ -32,6 +34,3 @@ void machine_halt(void)
 void machine_restart(char *cmd)
 {
 }
-
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/ia64/kernel/process.c +1 -4
index b515149..88121a2 100644
@@ -57,8 +57,6 @@ void (*ia64_mark_idle)(int);
 
 unsigned long boot_option_idle_override = IDLE_NO_OVERRIDE;
 EXPORT_SYMBOL(boot_option_idle_override);
-void (*pm_power_off) (void);
-EXPORT_SYMBOL(pm_power_off);
 
 void
 ia64_do_show_stack (struct unw_frame_info *info, void *arg)
@@ -675,8 +673,7 @@ machine_halt (void)
 void
 machine_power_off (void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        machine_halt();
 }
 
arch/m32r/kernel/process.c +4 -4
index e69221d..65a037e 100644
@@ -23,6 +23,7 @@
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/unistd.h>
 #include <linux/hardirq.h>
@@ -44,9 +45,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
        return tsk->thread.lr;
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_restart(char *__unused)
 {
 #if defined(CONFIG_PLAT_MAPPI3)
@@ -67,7 +65,9 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       /* M32R_FIXME */
+       do_kernel_power_off();
+       for (;;)
+               ;
 }
 
 void show_regs(struct pt_regs * regs)
arch/m68k/kernel/process.c +1 -5
index afe3d6e..bbc0a63 100644
@@ -78,14 +78,10 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        for (;;);
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void show_regs(struct pt_regs * regs)
 {
        printk("\n");
arch/metag/kernel/process.c +1 -5
index 483dff9..8d95773 100644
@@ -67,9 +67,6 @@ void arch_cpu_idle_dead(void)
 }
 #endif
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void (*soc_restart)(char *cmd);
 void (*soc_halt)(void);
 
@@ -90,8 +87,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        smp_send_stop();
        hard_processor_halt(HALT_OK);
 }
arch/microblaze/kernel/process.c +0 -3
index b2dd371..0ebca36 100644
@@ -44,9 +44,6 @@ void show_regs(struct pt_regs *regs)
                                regs->msr, regs->ear, regs->esr, regs->fsr);
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void flush_thread(void)
 {
 }
arch/microblaze/kernel/reset.c +1 -0
index fbe58c6..2c6b32c 100644
@@ -103,6 +103,7 @@ void machine_halt(void)
 void machine_power_off(void)
 {
        pr_notice("Machine power off...\n");
+       do_kernel_power_off();
        while (1)
                ;
 }
arch/mips/kernel/reset.c +1 -5
index 07fc524..09e74d2 100644
@@ -21,9 +21,6 @@
  */
 void (*_machine_restart)(char *command);
 void (*_machine_halt)(void);
-void (*pm_power_off)(void);
-
-EXPORT_SYMBOL(pm_power_off);
 
 void machine_restart(char *command)
 {
@@ -39,6 +36,5 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
arch/mn10300/kernel/process.c +2 -6
index 3707da5..c78b2eb 100644
@@ -20,6 +20,7 @@
 #include <linux/user.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/percpu.h>
 #include <linux/err.h>
@@ -45,12 +46,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
 }
 
 /*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
-/*
  * On SMP it's slightly faster (but much more power-consuming!)
  * to poll the ->work.need_resched flag instead of waiting for the
  * cross-CPU IPI to arrive. Use this option with caution.
@@ -93,6 +88,7 @@ void machine_power_off(void)
 #ifdef CONFIG_KERNEL_DEBUGGER
        gdbstub_exit(0);
 #endif
+       do_kernel_power_off();
 }
 
 void show_regs(struct pt_regs *regs)
arch/openrisc/kernel/process.c +5 -3
index 386af25..494afd2 100644
@@ -25,6 +25,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mm.h>
+#include <linux/pm.h>
 #include <linux/stddef.h>
 #include <linux/unistd.h>
 #include <linux/ptrace.h>
@@ -51,7 +52,7 @@
  */
 struct thread_info *current_thread_info_set[NR_CPUS] = { &init_thread_info, };
 
-void machine_restart(void)
+void machine_restart(char *cmd)
 {
        printk(KERN_INFO "*** MACHINE RESTART ***\n");
        __asm__("l.nop 1");
@@ -72,11 +73,12 @@ void machine_halt(void)
 void machine_power_off(void)
 {
        printk(KERN_INFO "*** MACHINE POWER OFF ***\n");
+
+       do_kernel_power_off();
+
        __asm__("l.nop 1");
 }
 
-void (*pm_power_off) (void) = machine_power_off;
-
 /*
  * When a process does an "exec", machine state like FPU and debug
  * registers need to be reset.  This is a hook function for that.
arch/parisc/kernel/process.c +4 -4
index 0bbbf0d..3f5d14a 100644
@@ -41,6 +41,7 @@
 #include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/personality.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/sched.h>
 #include <linux/slab.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_power_off();
+
        /* It seems we have no way to power the system off via
         * software. The user has to press the button himself. */
 
@@ -141,9 +144,6 @@ void machine_power_off(void)
               "Please power this system off now.");
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * Free current thread data structures etc..
  */
arch/powerpc/kernel/setup-common.c +3 -3
index 1362cd6..5b7a851 100644
@@ -141,6 +141,9 @@ void machine_power_off(void)
        machine_shutdown();
        if (ppc_md.power_off)
                ppc_md.power_off();
+
+       do_kernel_power_off();
+
 #ifdef CONFIG_SMP
        smp_send_stop();
 #endif
@@ -151,9 +154,6 @@ void machine_power_off(void)
 /* Used by the G5 thermal driver */
 EXPORT_SYMBOL_GPL(machine_power_off);
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
-
 void machine_halt(void)
 {
        machine_shutdown();
arch/s390/kernel/setup.c +2 -6
index e80d9ff..267e025 100644
@@ -263,13 +263,9 @@ void machine_power_off(void)
                 */
                console_unblank();
        _machine_power_off();
-}
 
-/*
- * Dummy power off function.
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
+       do_kernel_power_off();
+}
 
 static int __init early_parse_mem(char *p)
 {
arch/score/kernel/process.c +4 -4
index a1519ad3..b76ea67 100644
@@ -29,9 +29,6 @@
 #include <linux/pm.h>
 #include <linux/rcupdate.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /* If or when software machine-restart is implemented, add code here. */
 void machine_restart(char *command) {}
 
@@ -39,7 +36,10 @@ void machine_restart(char *command) {}
 void machine_halt(void) {}
 
 /* If or when software machine-power-off is implemented, add code here. */
-void machine_power_off(void) {}
+void machine_power_off(void)
+{
+       do_kernel_power_off();
+}
 
 void ret_from_fork(void);
 void ret_from_kernel_thread(void);
arch/sh/kernel/reboot.c +1 -5
index 04afe5b..065de12 100644
@@ -11,9 +11,6 @@
 #include <asm/tlbflush.h>
 #include <asm/traps.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_SUPERH32
 static void watchdog_trigger_immediate(void)
 {
@@ -51,8 +48,7 @@ static void native_machine_shutdown(void)
 
 static void native_machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
 }
 
 static void native_machine_halt(void)
arch/sparc/kernel/process_32.c +2 -8
index 50e7b62..cb8148a 100644
@@ -48,14 +48,6 @@
  */
 void (*sparc_idle)(void);
 
-/*
- * Power-off handler instantiation for pm.h compliance
- * This is done via auxio, but could be used as a fallback
- * handler when auxio is not present-- unused for now...
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * sysctl - toggle power-off restriction for serial console
  * systems in machine_power_off()
@@ -112,6 +104,8 @@ void machine_power_off(void)
                sbus_writeb(power_register, auxio_power_register);
        }
 
+       do_kernel_power_off();
+
        machine_halt();
 }
 
arch/sparc/kernel/reboot.c +2 -6
index eba7d91..3c0bb03 100644
@@ -16,17 +16,13 @@
  */
 int scons_pwroff = 1;
 
-/* This isn't actually used, it exists merely to satisfy the
- * reference in kernel/sys.c
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
        if (strcmp(of_console_device->type, "serial") || scons_pwroff)
                prom_halt_power_off();
 
+       do_kernel_power_off();
+
        prom_halt();
 }
 
arch/tile/kernel/reboot.c +3 -4
index 6c5d2c0..8ff4a7f 100644
@@ -36,6 +36,9 @@ void machine_power_off(void)
 {
        arch_local_irq_disable_all();
        smp_send_stop();
+
+       do_kernel_power_off();
+
        hv_power_off();
 }
 
@@ -45,7 +48,3 @@ void machine_restart(char *cmd)
        smp_send_stop();
        hv_restart((HV_VirtAddr) "vmlinux", (HV_VirtAddr) cmd);
 }
-
-/* No interesting distinction to be made here. */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/um/kernel/reboot.c +0 -2
index ced8903..a82ef28 100644
@@ -11,8 +11,6 @@
 #include <os.h>
 #include <skas.h>
 
-void (*pm_power_off)(void);
-
 static void kill_off_processes(void)
 {
        if (proc_mm)
arch/unicore32/kernel/process.c +1 -8
index b008e99..9490dd5 100644
@@ -56,16 +56,9 @@ void machine_halt(void)
        gpio_set_value(GPO_SOFT_OFF, 0);
 }
 
-/*
- * Function pointers to optional machine specific functions
- */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        machine_halt();
 }
 
arch/x86/kernel/reboot.c +3 -8
index 17962e6..5c09e28 100644
@@ -30,12 +30,6 @@
 #include <asm/x86_init.h>
 #include <asm/efi.h>
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static const struct desc_ptr no_idt = {};
 
 /*
@@ -647,11 +641,12 @@ static void native_machine_halt(void)
 
 static void native_machine_power_off(void)
 {
-       if (pm_power_off) {
+       if (have_kernel_power_off()) {
                if (!reboot_force)
                        machine_shutdown();
-               pm_power_off();
+               do_kernel_power_off();
        }
+
        /* A fallback in case there is no PM info available */
        tboot_shutdown(TB_SHUTDOWN_HALT);
 }
arch/x86/xen/enlighten.c +1 -2
index 1a3f044..c2c1d74 100644
@@ -1320,8 +1320,7 @@ static void xen_machine_halt(void)
 
 static void xen_machine_power_off(void)
 {
-       if (pm_power_off)
-               pm_power_off();
+       do_kernel_power_off();
        xen_reboot(SHUTDOWN_poweroff);
 }
 
arch/xtensa/kernel/process.c +0 -4
index 1c85323..c487296 100644
@@ -49,10 +49,6 @@ extern void ret_from_kernel_thread(void);
 
 struct task_struct *current_set[NR_CPUS] = {&init_task, };
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
-
 #if XTENSA_HAVE_COPROCESSORS
 
 void coprocessor_release_all(struct thread_info *ti)
drivers/parisc/power.c +1 -2
index ef31b77..f10cf92 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();
                }
        }
 }
kernel/power/poweroff_handler.c +8 -0
index aeb4736..37f0b88 100644
@@ -22,6 +22,12 @@
 #include <linux/types.h>
 
 /*
+ * If set, calling this function will power off the system immediately.
+ */
+void (*pm_power_off)(void);
+EXPORT_SYMBOL(pm_power_off);
+
+/*
  *     Notifier list for kernel code which wants to be called
  *     to power off the system.
  */
@@ -236,6 +242,8 @@ EXPORT_SYMBOL(devm_register_power_off_handler);
 void do_kernel_power_off(void)
 {
        spin_lock(&power_off_handler_lock);
+       if (pm_power_off)
+               pm_power_off();
        raw_notifier_call_chain(&power_off_handler_list, 0, NULL);
        spin_unlock(&power_off_handler_lock);
 }
kernel/reboot.c +2 -3
index 5925f5a..0930851 100644
@@ -306,9 +306,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
                return ret;
 
        /* Instead of trying to make the power_off code look like
-        * halt when pm_power_off is not set do it the easy way.
+        * halt when no poweroff handler exists do it the easy way.
         */
-       if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
+       if (cmd == LINUX_REBOOT_CMD_POWER_OFF && !have_kernel_power_off())
                cmd = LINUX_REBOOT_CMD_HALT;
 
        mutex_lock(&reboot_mutex);
--

1.9.1

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

#42 lore raw

PATCH v2 8/47 kernel: Move pm_power_off to common code

In reply to Guenter Roeck

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

---
v2:
- do_kernel_poweroff -> do_kernel_power_off
- have_kernel_poweroff -> have_kernel_power_off

 arch/alpha/kernel/process.c        |  9 +++------
 arch/arc/kernel/reset.c            |  5 +----
 arch/arm/kernel/process.c          |  5 +----
 arch/arm64/kernel/process.c        |  5 +----
 arch/avr32/kernel/process.c        |  6 +-----
 arch/blackfin/kernel/process.c     |  3 ---
 arch/blackfin/kernel/reboot.c      |  2 ++
 arch/c6x/kernel/process.c          |  9 +--------
 arch/cris/kernel/process.c         |  4 +---
 arch/frv/kernel/process.c          |  5 ++---
 arch/hexagon/kernel/reset.c        |  5 ++---
 arch/ia64/kernel/process.c         |  5 +----
 arch/m32r/kernel/process.c         |  8 ++++----
 arch/m68k/kernel/process.c         |  6 +-----
 arch/metag/kernel/process.c        |  6 +-----
 arch/microblaze/kernel/process.c   |  3 ---
 arch/microblaze/kernel/reset.c     |  1 +
 arch/mips/kernel/reset.c           |  6 +-----
 arch/mn10300/kernel/process.c      |  8 ++------
 arch/openrisc/kernel/process.c     |  8 +++++---
 arch/parisc/kernel/process.c       |  8 ++++----
 arch/powerpc/kernel/setup-common.c |  6 +++---
 arch/s390/kernel/setup.c           |  8 ++------
 arch/score/kernel/process.c        |  8 ++++----
 arch/sh/kernel/reboot.c            |  6 +-----
 arch/sparc/kernel/process_32.c     | 10 ++--------
 arch/sparc/kernel/reboot.c         |  8 ++------
 arch/tile/kernel/reboot.c          |  7 +++----
 arch/um/kernel/reboot.c            |  2 --
 arch/unicore32/kernel/process.c    |  9 +--------
 arch/x86/kernel/reboot.c           | 11 +++--------
 arch/x86/xen/enlighten.c           |  3 +--
 arch/xtensa/kernel/process.c       |  4 ----
 drivers/parisc/power.c             |  3 +--
 kernel/power/poweroff_handler.c    |  8 ++++++++
 kernel/reboot.c                    |  4 ++--
 36 files changed, 68 insertions(+), 146 deletions(-)
arch/alpha/kernel/process.c +3 -6
index 1941a07..81c43f8 100644
@@ -24,6 +24,7 @@
 #include <linux/vt.h>
 #include <linux/mman.h>
 #include <linux/elfcore.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/tty.h>
 #include <linux/console.h>
@@ -40,12 +41,6 @@
 #include "proto.h"
 #include "pci_impl.h"
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_ALPHA_WTINT
 /*
  * Sleep the CPU.
@@ -184,6 +179,8 @@ machine_halt(void)
 void
 machine_power_off(void)
 {
+	do_kernel_power_off();
+
 	common_shutdown(LINUX_REBOOT_CMD_POWER_OFF, NULL);
 }
 
arch/arc/kernel/reset.c +1 -4
index 2768fa1..0758d9d 100644
@@ -26,9 +26,6 @@ void machine_restart(char *__unused)
 
 void machine_power_off(void)
 {
-	/* FIXME ::  power off ??? */
+	do_kernel_power_off();
 	machine_halt();
 }
-
-void (*pm_power_off) (void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/arm/kernel/process.c +1 -4
index fe972a2..aa3f656 100644
@@ -117,8 +117,6 @@ void soft_restart(unsigned long addr)
 /*
  * 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);
 
@@ -205,8 +203,7 @@ void machine_power_off(void)
 	local_irq_disable();
 	smp_send_stop();
 
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 /*
arch/arm64/kernel/process.c +1 -4
index c3065db..46a483a 100644
@@ -68,8 +68,6 @@ void soft_restart(unsigned long addr)
 /*
  * Function pointers to optional machine specific functions
  */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL_GPL(pm_power_off);
 
 void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
 
@@ -129,8 +127,7 @@ void machine_power_off(void)
 {
 	local_irq_disable();
 	smp_send_stop();
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 /*
arch/avr32/kernel/process.c +1 -5
index 42a53e74..529c1f6 100644
@@ -23,9 +23,6 @@
 
 #include <mach/pm.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * This file handles the architecture-dependent parts of process handling..
  */
@@ -48,8 +45,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 void machine_restart(char *cmd)
arch/blackfin/kernel/process.c +0 -3
index 4aa5545..812dd83 100644
@@ -39,9 +39,6 @@ int nr_l1stack_tasks;
 void *l1_stack_base;
 unsigned long l1_stack_len;
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * The idle loop on BFIN
  */
arch/blackfin/kernel/reboot.c +2 -0
index c4f50a3..387d610 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/interrupt.h>
+#include <linux/pm.h>
 #include <asm/bfin-global.h>
 #include <asm/reboot.h>
 #include <asm/bfrom.h>
@@ -106,6 +107,7 @@ void machine_halt(void)
 __attribute__((weak))
 void native_machine_power_off(void)
 {
+	do_kernel_power_off();
 	idle_with_irq_disabled();
 }
 
arch/c6x/kernel/process.c +1 -8
index 57d2ea8..edf7e5a 100644
@@ -27,12 +27,6 @@ void	(*c6x_halt)(void);
 extern asmlinkage void ret_from_fork(void);
 extern asmlinkage void ret_from_kernel_thread(void);
 
-/*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
 	unsigned long tmp;
@@ -73,8 +67,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	halt_loop();
 }
 
arch/cris/kernel/process.c +1 -3
index b78498e..9ebd76b 100644
@@ -31,9 +31,6 @@
 
 extern void default_idle(void);
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
 	default_idle();
@@ -60,6 +57,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
+	do_kernel_power_off();
 }
 
 /*
arch/frv/kernel/process.c +2 -3
index 5d40aeb77..502dabb 100644
@@ -42,9 +42,6 @@ asmlinkage void ret_from_kernel_thread(void);
 
 #include <asm/pgalloc.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static void core_sleep_idle(void)
 {
 #ifdef LED_DEBUG_SLEEP
@@ -107,6 +104,8 @@ void machine_power_off(void)
 	gdbstub_exit(0);
 #endif
 
+	do_kernel_power_off();
+
 	for (;;);
 }
 
arch/hexagon/kernel/reset.c +2 -3
index 76483c1..6f607b6 100644
@@ -16,11 +16,13 @@
  * 02110-1301, USA.
  */
 
+#include <linux/pm.h>
 #include <linux/smp.h>
 #include <asm/hexagon_vm.h>
 
 void machine_power_off(void)
 {
+	do_kernel_power_off();
 	smp_send_stop();
 	__vmstop();
 }
@@ -32,6 +34,3 @@ void machine_halt(void)
 void machine_restart(char *cmd)
 {
 }
-
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/ia64/kernel/process.c +1 -4
index b515149..88121a2 100644
@@ -57,8 +57,6 @@ void (*ia64_mark_idle)(int);
 
 unsigned long boot_option_idle_override = IDLE_NO_OVERRIDE;
 EXPORT_SYMBOL(boot_option_idle_override);
-void (*pm_power_off) (void);
-EXPORT_SYMBOL(pm_power_off);
 
 void
 ia64_do_show_stack (struct unw_frame_info *info, void *arg)
@@ -675,8 +673,7 @@ machine_halt (void)
 void
 machine_power_off (void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	machine_halt();
 }
 
arch/m32r/kernel/process.c +4 -4
index e69221d..65a037e 100644
@@ -23,6 +23,7 @@
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/unistd.h>
 #include <linux/hardirq.h>
@@ -44,9 +45,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
 	return tsk->thread.lr;
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_restart(char *__unused)
 {
 #if defined(CONFIG_PLAT_MAPPI3)
@@ -67,7 +65,9 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	/* M32R_FIXME */
+	do_kernel_power_off();
+	for (;;)
+		;
 }
 
 void show_regs(struct pt_regs * regs)
arch/m68k/kernel/process.c +1 -5
index afe3d6e..bbc0a63 100644
@@ -78,14 +78,10 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	for (;;);
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void show_regs(struct pt_regs * regs)
 {
 	printk("\n");
arch/metag/kernel/process.c +1 -5
index 483dff9..8d95773 100644
@@ -67,9 +67,6 @@ void arch_cpu_idle_dead(void)
 }
 #endif
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void (*soc_restart)(char *cmd);
 void (*soc_halt)(void);
 
@@ -90,8 +87,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	smp_send_stop();
 	hard_processor_halt(HALT_OK);
 }
arch/microblaze/kernel/process.c +0 -3
index b2dd371..0ebca36 100644
@@ -44,9 +44,6 @@ void show_regs(struct pt_regs *regs)
 				regs->msr, regs->ear, regs->esr, regs->fsr);
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void flush_thread(void)
 {
 }
arch/microblaze/kernel/reset.c +1 -0
index fbe58c6..2c6b32c 100644
@@ -103,6 +103,7 @@ void machine_halt(void)
 void machine_power_off(void)
 {
 	pr_notice("Machine power off...\n");
+	do_kernel_power_off();
 	while (1)
 		;
 }
arch/mips/kernel/reset.c +1 -5
index 07fc524..09e74d2 100644
@@ -21,9 +21,6 @@
  */
 void (*_machine_restart)(char *command);
 void (*_machine_halt)(void);
-void (*pm_power_off)(void);
-
-EXPORT_SYMBOL(pm_power_off);
 
 void machine_restart(char *command)
 {
@@ -39,6 +36,5 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
arch/mn10300/kernel/process.c +2 -6
index 3707da5..c78b2eb 100644
@@ -20,6 +20,7 @@
 #include <linux/user.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/percpu.h>
 #include <linux/err.h>
@@ -45,12 +46,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
 }
 
 /*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
-/*
  * On SMP it's slightly faster (but much more power-consuming!)
  * to poll the ->work.need_resched flag instead of waiting for the
  * cross-CPU IPI to arrive. Use this option with caution.
@@ -93,6 +88,7 @@ void machine_power_off(void)
 #ifdef CONFIG_KERNEL_DEBUGGER
 	gdbstub_exit(0);
 #endif
+	do_kernel_power_off();
 }
 
 void show_regs(struct pt_regs *regs)
arch/openrisc/kernel/process.c +5 -3
index 386af25..494afd2 100644
@@ -25,6 +25,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mm.h>
+#include <linux/pm.h>
 #include <linux/stddef.h>
 #include <linux/unistd.h>
 #include <linux/ptrace.h>
@@ -51,7 +52,7 @@
  */
 struct thread_info *current_thread_info_set[NR_CPUS] = { &init_thread_info, };
 
-void machine_restart(void)
+void machine_restart(char *cmd)
 {
 	printk(KERN_INFO "*** MACHINE RESTART ***\n");
 	__asm__("l.nop 1");
@@ -72,11 +73,12 @@ void machine_halt(void)
 void machine_power_off(void)
 {
 	printk(KERN_INFO "*** MACHINE POWER OFF ***\n");
+
+	do_kernel_power_off();
+
 	__asm__("l.nop 1");
 }
 
-void (*pm_power_off) (void) = machine_power_off;
-
 /*
  * When a process does an "exec", machine state like FPU and debug
  * registers need to be reset.  This is a hook function for that.
arch/parisc/kernel/process.c +4 -4
index 0bbbf0d..3f5d14a 100644
@@ -41,6 +41,7 @@
 #include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/personality.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/sched.h>
 #include <linux/slab.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_power_off();
+
 	/* It seems we have no way to power the system off via
 	 * software. The user has to press the button himself. */
 
@@ -141,9 +144,6 @@ void machine_power_off(void)
 	       "Please power this system off now.");
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * Free current thread data structures etc..
  */
arch/powerpc/kernel/setup-common.c +3 -3
index 1362cd6..5b7a851 100644
@@ -141,6 +141,9 @@ void machine_power_off(void)
 	machine_shutdown();
 	if (ppc_md.power_off)
 		ppc_md.power_off();
+
+	do_kernel_power_off();
+
 #ifdef CONFIG_SMP
 	smp_send_stop();
 #endif
@@ -151,9 +154,6 @@ void machine_power_off(void)
 /* Used by the G5 thermal driver */
 EXPORT_SYMBOL_GPL(machine_power_off);
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
-
 void machine_halt(void)
 {
 	machine_shutdown();
arch/s390/kernel/setup.c +2 -6
index e80d9ff..267e025 100644
@@ -263,13 +263,9 @@ void machine_power_off(void)
 		 */
 		console_unblank();
 	_machine_power_off();
-}
 
-/*
- * Dummy power off function.
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
+	do_kernel_power_off();
+}
 
 static int __init early_parse_mem(char *p)
 {
arch/score/kernel/process.c +4 -4
index a1519ad3..b76ea67 100644
@@ -29,9 +29,6 @@
 #include <linux/pm.h>
 #include <linux/rcupdate.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /* If or when software machine-restart is implemented, add code here. */
 void machine_restart(char *command) {}
 
@@ -39,7 +36,10 @@ void machine_restart(char *command) {}
 void machine_halt(void) {}
 
 /* If or when software machine-power-off is implemented, add code here. */
-void machine_power_off(void) {}
+void machine_power_off(void)
+{
+	do_kernel_power_off();
+}
 
 void ret_from_fork(void);
 void ret_from_kernel_thread(void);
arch/sh/kernel/reboot.c +1 -5
index 04afe5b..065de12 100644
@@ -11,9 +11,6 @@
 #include <asm/tlbflush.h>
 #include <asm/traps.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_SUPERH32
 static void watchdog_trigger_immediate(void)
 {
@@ -51,8 +48,7 @@ static void native_machine_shutdown(void)
 
 static void native_machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 static void native_machine_halt(void)
arch/sparc/kernel/process_32.c +2 -8
index 50e7b62..cb8148a 100644
@@ -48,14 +48,6 @@
  */
 void (*sparc_idle)(void);
 
-/* 
- * Power-off handler instantiation for pm.h compliance
- * This is done via auxio, but could be used as a fallback
- * handler when auxio is not present-- unused for now...
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * sysctl - toggle power-off restriction for serial console 
  * systems in machine_power_off()
@@ -112,6 +104,8 @@ void machine_power_off(void)
 		sbus_writeb(power_register, auxio_power_register);
 	}
 
+	do_kernel_power_off();
+
 	machine_halt();
 }
 
arch/sparc/kernel/reboot.c +2 -6
index eba7d91..3c0bb03 100644
@@ -16,17 +16,13 @@
  */
 int scons_pwroff = 1;
 
-/* This isn't actually used, it exists merely to satisfy the
- * reference in kernel/sys.c
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
 	if (strcmp(of_console_device->type, "serial") || scons_pwroff)
 		prom_halt_power_off();
 
+	do_kernel_power_off();
+
 	prom_halt();
 }
 
arch/tile/kernel/reboot.c +3 -4
index 6c5d2c0..8ff4a7f 100644
@@ -36,6 +36,9 @@ void machine_power_off(void)
 {
 	arch_local_irq_disable_all();
 	smp_send_stop();
+
+	do_kernel_power_off();
+
 	hv_power_off();
 }
 
@@ -45,7 +48,3 @@ void machine_restart(char *cmd)
 	smp_send_stop();
 	hv_restart((HV_VirtAddr) "vmlinux", (HV_VirtAddr) cmd);
 }
-
-/* No interesting distinction to be made here. */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/um/kernel/reboot.c +0 -2
index ced8903..a82ef28 100644
@@ -11,8 +11,6 @@
 #include <os.h>
 #include <skas.h>
 
-void (*pm_power_off)(void);
-
 static void kill_off_processes(void)
 {
 	if (proc_mm)
arch/unicore32/kernel/process.c +1 -8
index b008e99..9490dd5 100644
@@ -56,16 +56,9 @@ void machine_halt(void)
 	gpio_set_value(GPO_SOFT_OFF, 0);
 }
 
-/*
- * Function pointers to optional machine specific functions
- */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	machine_halt();
 }
 
arch/x86/kernel/reboot.c +3 -8
index 17962e6..5c09e28 100644
@@ -30,12 +30,6 @@
 #include <asm/x86_init.h>
 #include <asm/efi.h>
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static const struct desc_ptr no_idt = {};
 
 /*
@@ -647,11 +641,12 @@ static void native_machine_halt(void)
 
 static void native_machine_power_off(void)
 {
-	if (pm_power_off) {
+	if (have_kernel_power_off()) {
 		if (!reboot_force)
 			machine_shutdown();
-		pm_power_off();
+		do_kernel_power_off();
 	}
+
 	/* A fallback in case there is no PM info available */
 	tboot_shutdown(TB_SHUTDOWN_HALT);
 }
arch/x86/xen/enlighten.c +1 -2
index 1a3f044..c2c1d74 100644
@@ -1320,8 +1320,7 @@ static void xen_machine_halt(void)
 
 static void xen_machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	xen_reboot(SHUTDOWN_poweroff);
 }
 
arch/xtensa/kernel/process.c +0 -4
index 1c85323..c487296 100644
@@ -49,10 +49,6 @@ extern void ret_from_kernel_thread(void);
 
 struct task_struct *current_set[NR_CPUS] = {&init_task, };
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
-
 #if XTENSA_HAVE_COPROCESSORS
 
 void coprocessor_release_all(struct thread_info *ti)
drivers/parisc/power.c +1 -2
index ef31b77..f10cf92 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();
 		}
 	}
 }
kernel/power/poweroff_handler.c +8 -0
index aeb4736..37f0b88 100644
@@ -22,6 +22,12 @@
 #include <linux/types.h>
 
 /*
+ * If set, calling this function will power off the system immediately.
+ */
+void (*pm_power_off)(void);
+EXPORT_SYMBOL(pm_power_off);
+
+/*
  *	Notifier list for kernel code which wants to be called
  *	to power off the system.
  */
@@ -236,6 +242,8 @@ EXPORT_SYMBOL(devm_register_power_off_handler);
 void do_kernel_power_off(void)
 {
 	spin_lock(&power_off_handler_lock);
+	if (pm_power_off)
+		pm_power_off();
 	raw_notifier_call_chain(&power_off_handler_list, 0, NULL);
 	spin_unlock(&power_off_handler_lock);
 }
kernel/reboot.c +2 -2
index 5925f5a..0930851 100644
@@ -306,9 +306,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 		return ret;
 
 	/* Instead of trying to make the power_off code look like
-	 * halt when pm_power_off is not set do it the easy way.
+	 * halt when no poweroff handler exists do it the easy way.
 	 */
-	if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
+	if (cmd == LINUX_REBOOT_CMD_POWER_OFF && !have_kernel_power_off())
 		cmd = LINUX_REBOOT_CMD_HALT;
 
 	mutex_lock(&reboot_mutex);
Signature · 1 line
1.9.1
#43 lore raw

PATCH v2 8/47 kernel: Move pm_power_off to common code

In reply to Guenter Roeck

pm_power_off is defined for all architectures. Move it to common code.

Have all architectures call do_kernel_power_off instead of pm_power_off. Some architectures point pm_power_off to machine_power_off. For those, call do_kernel_power_off from machine_power_off instead.

---
v2:
- do_kernel_poweroff -> do_kernel_power_off
- have_kernel_poweroff -> have_kernel_power_off

 arch/alpha/kernel/process.c        |  9 +++------
 arch/arc/kernel/reset.c            |  5 +----
 arch/arm/kernel/process.c          |  5 +----
 arch/arm64/kernel/process.c        |  5 +----
 arch/avr32/kernel/process.c        |  6 +-----
 arch/blackfin/kernel/process.c     |  3 ---
 arch/blackfin/kernel/reboot.c      |  2 ++
 arch/c6x/kernel/process.c          |  9 +--------
 arch/cris/kernel/process.c         |  4 +---
 arch/frv/kernel/process.c          |  5 ++---
 arch/hexagon/kernel/reset.c        |  5 ++---
 arch/ia64/kernel/process.c         |  5 +----
 arch/m32r/kernel/process.c         |  8 ++++----
 arch/m68k/kernel/process.c         |  6 +-----
 arch/metag/kernel/process.c        |  6 +-----
 arch/microblaze/kernel/process.c   |  3 ---
 arch/microblaze/kernel/reset.c     |  1 +
 arch/mips/kernel/reset.c           |  6 +-----
 arch/mn10300/kernel/process.c      |  8 ++------
 arch/openrisc/kernel/process.c     |  8 +++++---
 arch/parisc/kernel/process.c       |  8 ++++----
 arch/powerpc/kernel/setup-common.c |  6 +++---
 arch/s390/kernel/setup.c           |  8 ++------
 arch/score/kernel/process.c        |  8 ++++----
 arch/sh/kernel/reboot.c            |  6 +-----
 arch/sparc/kernel/process_32.c     | 10 ++--------
 arch/sparc/kernel/reboot.c         |  8 ++------
 arch/tile/kernel/reboot.c          |  7 +++----
 arch/um/kernel/reboot.c            |  2 --
 arch/unicore32/kernel/process.c    |  9 +--------
 arch/x86/kernel/reboot.c           | 11 +++--------
 arch/x86/xen/enlighten.c           |  3 +--
 arch/xtensa/kernel/process.c       |  4 ----
 drivers/parisc/power.c             |  3 +--
 kernel/power/poweroff_handler.c    |  8 ++++++++
 kernel/reboot.c                    |  4 ++--
 36 files changed, 68 insertions(+), 146 deletions(-)
arch/alpha/kernel/process.c +3 -6
index 1941a07..81c43f8 100644
@@ -24,6 +24,7 @@
 #include <linux/vt.h>
 #include <linux/mman.h>
 #include <linux/elfcore.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/tty.h>
 #include <linux/console.h>
@@ -40,12 +41,6 @@
 #include "proto.h"
 #include "pci_impl.h"
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_ALPHA_WTINT
 /*
  * Sleep the CPU.
@@ -184,6 +179,8 @@ machine_halt(void)
 void
 machine_power_off(void)
 {
+	do_kernel_power_off();
+
 	common_shutdown(LINUX_REBOOT_CMD_POWER_OFF, NULL);
 }
 
arch/arc/kernel/reset.c +1 -4
index 2768fa1..0758d9d 100644
@@ -26,9 +26,6 @@ void machine_restart(char *__unused)
 
 void machine_power_off(void)
 {
-	/* FIXME ::  power off ??? */
+	do_kernel_power_off();
 	machine_halt();
 }
-
-void (*pm_power_off) (void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/arm/kernel/process.c +1 -4
index fe972a2..aa3f656 100644
@@ -117,8 +117,6 @@ void soft_restart(unsigned long addr)
 /*
  * 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);
 
@@ -205,8 +203,7 @@ void machine_power_off(void)
 	local_irq_disable();
 	smp_send_stop();
 
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 /*
arch/arm64/kernel/process.c +1 -4
index c3065db..46a483a 100644
@@ -68,8 +68,6 @@ void soft_restart(unsigned long addr)
 /*
  * Function pointers to optional machine specific functions
  */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL_GPL(pm_power_off);
 
 void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
 
@@ -129,8 +127,7 @@ void machine_power_off(void)
 {
 	local_irq_disable();
 	smp_send_stop();
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 /*
arch/avr32/kernel/process.c +1 -5
index 42a53e74..529c1f6 100644
@@ -23,9 +23,6 @@
 
 #include <mach/pm.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * This file handles the architecture-dependent parts of process handling..
  */
@@ -48,8 +45,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 void machine_restart(char *cmd)
arch/blackfin/kernel/process.c +0 -3
index 4aa5545..812dd83 100644
@@ -39,9 +39,6 @@ int nr_l1stack_tasks;
 void *l1_stack_base;
 unsigned long l1_stack_len;
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * The idle loop on BFIN
  */
arch/blackfin/kernel/reboot.c +2 -0
index c4f50a3..387d610 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/interrupt.h>
+#include <linux/pm.h>
 #include <asm/bfin-global.h>
 #include <asm/reboot.h>
 #include <asm/bfrom.h>
@@ -106,6 +107,7 @@ void machine_halt(void)
 __attribute__((weak))
 void native_machine_power_off(void)
 {
+	do_kernel_power_off();
 	idle_with_irq_disabled();
 }
 
arch/c6x/kernel/process.c +1 -8
index 57d2ea8..edf7e5a 100644
@@ -27,12 +27,6 @@ void	(*c6x_halt)(void);
 extern asmlinkage void ret_from_fork(void);
 extern asmlinkage void ret_from_kernel_thread(void);
 
-/*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
 	unsigned long tmp;
@@ -73,8 +67,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	halt_loop();
 }
 
arch/cris/kernel/process.c +1 -3
index b78498e..9ebd76b 100644
@@ -31,9 +31,6 @@
 
 extern void default_idle(void);
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void arch_cpu_idle(void)
 {
 	default_idle();
@@ -60,6 +57,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
+	do_kernel_power_off();
 }
 
 /*
arch/frv/kernel/process.c +2 -3
index 5d40aeb77..502dabb 100644
@@ -42,9 +42,6 @@ asmlinkage void ret_from_kernel_thread(void);
 
 #include <asm/pgalloc.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static void core_sleep_idle(void)
 {
 #ifdef LED_DEBUG_SLEEP
@@ -107,6 +104,8 @@ void machine_power_off(void)
 	gdbstub_exit(0);
 #endif
 
+	do_kernel_power_off();
+
 	for (;;);
 }
 
arch/hexagon/kernel/reset.c +2 -3
index 76483c1..6f607b6 100644
@@ -16,11 +16,13 @@
  * 02110-1301, USA.
  */
 
+#include <linux/pm.h>
 #include <linux/smp.h>
 #include <asm/hexagon_vm.h>
 
 void machine_power_off(void)
 {
+	do_kernel_power_off();
 	smp_send_stop();
 	__vmstop();
 }
@@ -32,6 +34,3 @@ void machine_halt(void)
 void machine_restart(char *cmd)
 {
 }
-
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/ia64/kernel/process.c +1 -4
index b515149..88121a2 100644
@@ -57,8 +57,6 @@ void (*ia64_mark_idle)(int);
 
 unsigned long boot_option_idle_override = IDLE_NO_OVERRIDE;
 EXPORT_SYMBOL(boot_option_idle_override);
-void (*pm_power_off) (void);
-EXPORT_SYMBOL(pm_power_off);
 
 void
 ia64_do_show_stack (struct unw_frame_info *info, void *arg)
@@ -675,8 +673,7 @@ machine_halt (void)
 void
 machine_power_off (void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	machine_halt();
 }
 
arch/m32r/kernel/process.c +4 -4
index e69221d..65a037e 100644
@@ -23,6 +23,7 @@
 #include <linux/fs.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/unistd.h>
 #include <linux/hardirq.h>
@@ -44,9 +45,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
 	return tsk->thread.lr;
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_restart(char *__unused)
 {
 #if defined(CONFIG_PLAT_MAPPI3)
@@ -67,7 +65,9 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	/* M32R_FIXME */
+	do_kernel_power_off();
+	for (;;)
+		;
 }
 
 void show_regs(struct pt_regs * regs)
arch/m68k/kernel/process.c +1 -5
index afe3d6e..bbc0a63 100644
@@ -78,14 +78,10 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	for (;;);
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void show_regs(struct pt_regs * regs)
 {
 	printk("\n");
arch/metag/kernel/process.c +1 -5
index 483dff9..8d95773 100644
@@ -67,9 +67,6 @@ void arch_cpu_idle_dead(void)
 }
 #endif
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 void (*soc_restart)(char *cmd);
 void (*soc_halt)(void);
 
@@ -90,8 +87,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	smp_send_stop();
 	hard_processor_halt(HALT_OK);
 }
arch/microblaze/kernel/process.c +0 -3
index b2dd371..0ebca36 100644
@@ -44,9 +44,6 @@ void show_regs(struct pt_regs *regs)
 				regs->msr, regs->ear, regs->esr, regs->fsr);
 }
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void flush_thread(void)
 {
 }
arch/microblaze/kernel/reset.c +1 -0
index fbe58c6..2c6b32c 100644
@@ -103,6 +103,7 @@ void machine_halt(void)
 void machine_power_off(void)
 {
 	pr_notice("Machine power off...\n");
+	do_kernel_power_off();
 	while (1)
 		;
 }
arch/mips/kernel/reset.c +1 -5
index 07fc524..09e74d2 100644
@@ -21,9 +21,6 @@
  */
 void (*_machine_restart)(char *command);
 void (*_machine_halt)(void);
-void (*pm_power_off)(void);
-
-EXPORT_SYMBOL(pm_power_off);
 
 void machine_restart(char *command)
 {
@@ -39,6 +36,5 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
arch/mn10300/kernel/process.c +2 -6
index 3707da5..c78b2eb 100644
@@ -20,6 +20,7 @@
 #include <linux/user.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/percpu.h>
 #include <linux/err.h>
@@ -45,12 +46,6 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
 }
 
 /*
- * power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
-/*
  * On SMP it's slightly faster (but much more power-consuming!)
  * to poll the ->work.need_resched flag instead of waiting for the
  * cross-CPU IPI to arrive. Use this option with caution.
@@ -93,6 +88,7 @@ void machine_power_off(void)
 #ifdef CONFIG_KERNEL_DEBUGGER
 	gdbstub_exit(0);
 #endif
+	do_kernel_power_off();
 }
 
 void show_regs(struct pt_regs *regs)
arch/openrisc/kernel/process.c +5 -3
index 386af25..494afd2 100644
@@ -25,6 +25,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mm.h>
+#include <linux/pm.h>
 #include <linux/stddef.h>
 #include <linux/unistd.h>
 #include <linux/ptrace.h>
@@ -51,7 +52,7 @@
  */
 struct thread_info *current_thread_info_set[NR_CPUS] = { &init_thread_info, };
 
-void machine_restart(void)
+void machine_restart(char *cmd)
 {
 	printk(KERN_INFO "*** MACHINE RESTART ***\n");
 	__asm__("l.nop 1");
@@ -72,11 +73,12 @@ void machine_halt(void)
 void machine_power_off(void)
 {
 	printk(KERN_INFO "*** MACHINE POWER OFF ***\n");
+
+	do_kernel_power_off();
+
 	__asm__("l.nop 1");
 }
 
-void (*pm_power_off) (void) = machine_power_off;
-
 /*
  * When a process does an "exec", machine state like FPU and debug
  * registers need to be reset.  This is a hook function for that.
arch/parisc/kernel/process.c +4 -4
index 0bbbf0d..3f5d14a 100644
@@ -41,6 +41,7 @@
 #include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/personality.h>
+#include <linux/pm.h>
 #include <linux/ptrace.h>
 #include <linux/sched.h>
 #include <linux/slab.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_power_off();
+
 	/* It seems we have no way to power the system off via
 	 * software. The user has to press the button himself. */
 
@@ -141,9 +144,6 @@ void machine_power_off(void)
 	       "Please power this system off now.");
 }
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * Free current thread data structures etc..
  */
arch/powerpc/kernel/setup-common.c +3 -3
index 1362cd6..5b7a851 100644
@@ -141,6 +141,9 @@ void machine_power_off(void)
 	machine_shutdown();
 	if (ppc_md.power_off)
 		ppc_md.power_off();
+
+	do_kernel_power_off();
+
 #ifdef CONFIG_SMP
 	smp_send_stop();
 #endif
@@ -151,9 +154,6 @@ void machine_power_off(void)
 /* Used by the G5 thermal driver */
 EXPORT_SYMBOL_GPL(machine_power_off);
 
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
-
 void machine_halt(void)
 {
 	machine_shutdown();
arch/s390/kernel/setup.c +2 -6
index e80d9ff..267e025 100644
@@ -263,13 +263,9 @@ void machine_power_off(void)
 		 */
 		console_unblank();
 	_machine_power_off();
-}
 
-/*
- * Dummy power off function.
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL_GPL(pm_power_off);
+	do_kernel_power_off();
+}
 
 static int __init early_parse_mem(char *p)
 {
arch/score/kernel/process.c +4 -4
index a1519ad3..b76ea67 100644
@@ -29,9 +29,6 @@
 #include <linux/pm.h>
 #include <linux/rcupdate.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 /* If or when software machine-restart is implemented, add code here. */
 void machine_restart(char *command) {}
 
@@ -39,7 +36,10 @@ void machine_restart(char *command) {}
 void machine_halt(void) {}
 
 /* If or when software machine-power-off is implemented, add code here. */
-void machine_power_off(void) {}
+void machine_power_off(void)
+{
+	do_kernel_power_off();
+}
 
 void ret_from_fork(void);
 void ret_from_kernel_thread(void);
arch/sh/kernel/reboot.c +1 -5
index 04afe5b..065de12 100644
@@ -11,9 +11,6 @@
 #include <asm/tlbflush.h>
 #include <asm/traps.h>
 
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 #ifdef CONFIG_SUPERH32
 static void watchdog_trigger_immediate(void)
 {
@@ -51,8 +48,7 @@ static void native_machine_shutdown(void)
 
 static void native_machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 static void native_machine_halt(void)
arch/sparc/kernel/process_32.c +2 -8
index 50e7b62..cb8148a 100644
@@ -48,14 +48,6 @@
  */
 void (*sparc_idle)(void);
 
-/* 
- * Power-off handler instantiation for pm.h compliance
- * This is done via auxio, but could be used as a fallback
- * handler when auxio is not present-- unused for now...
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 /*
  * sysctl - toggle power-off restriction for serial console 
  * systems in machine_power_off()
@@ -112,6 +104,8 @@ void machine_power_off(void)
 		sbus_writeb(power_register, auxio_power_register);
 	}
 
+	do_kernel_power_off();
+
 	machine_halt();
 }
 
arch/sparc/kernel/reboot.c +2 -6
index eba7d91..3c0bb03 100644
@@ -16,17 +16,13 @@
  */
 int scons_pwroff = 1;
 
-/* This isn't actually used, it exists merely to satisfy the
- * reference in kernel/sys.c
- */
-void (*pm_power_off)(void) = machine_power_off;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
 	if (strcmp(of_console_device->type, "serial") || scons_pwroff)
 		prom_halt_power_off();
 
+	do_kernel_power_off();
+
 	prom_halt();
 }
 
arch/tile/kernel/reboot.c +3 -4
index 6c5d2c0..8ff4a7f 100644
@@ -36,6 +36,9 @@ void machine_power_off(void)
 {
 	arch_local_irq_disable_all();
 	smp_send_stop();
+
+	do_kernel_power_off();
+
 	hv_power_off();
 }
 
@@ -45,7 +48,3 @@ void machine_restart(char *cmd)
 	smp_send_stop();
 	hv_restart((HV_VirtAddr) "vmlinux", (HV_VirtAddr) cmd);
 }
-
-/* No interesting distinction to be made here. */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
arch/um/kernel/reboot.c +0 -2
index ced8903..a82ef28 100644
@@ -11,8 +11,6 @@
 #include <os.h>
 #include <skas.h>
 
-void (*pm_power_off)(void);
-
 static void kill_off_processes(void)
 {
 	if (proc_mm)
arch/unicore32/kernel/process.c +1 -8
index b008e99..9490dd5 100644
@@ -56,16 +56,9 @@ void machine_halt(void)
 	gpio_set_value(GPO_SOFT_OFF, 0);
 }
 
-/*
- * Function pointers to optional machine specific functions
- */
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	machine_halt();
 }
 
arch/x86/kernel/reboot.c +3 -8
index 17962e6..5c09e28 100644
@@ -30,12 +30,6 @@
 #include <asm/x86_init.h>
 #include <asm/efi.h>
 
-/*
- * Power off function, if any
- */
-void (*pm_power_off)(void);
-EXPORT_SYMBOL(pm_power_off);
-
 static const struct desc_ptr no_idt = {};
 
 /*
@@ -647,11 +641,12 @@ static void native_machine_halt(void)
 
 static void native_machine_power_off(void)
 {
-	if (pm_power_off) {
+	if (have_kernel_power_off()) {
 		if (!reboot_force)
 			machine_shutdown();
-		pm_power_off();
+		do_kernel_power_off();
 	}
+
 	/* A fallback in case there is no PM info available */
 	tboot_shutdown(TB_SHUTDOWN_HALT);
 }
arch/x86/xen/enlighten.c +1 -2
index 1a3f044..c2c1d74 100644
@@ -1320,8 +1320,7 @@ static void xen_machine_halt(void)
 
 static void xen_machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	xen_reboot(SHUTDOWN_poweroff);
 }
 
arch/xtensa/kernel/process.c +0 -4
index 1c85323..c487296 100644
@@ -49,10 +49,6 @@ extern void ret_from_kernel_thread(void);
 
 struct task_struct *current_set[NR_CPUS] = {&init_task, };
 
-void (*pm_power_off)(void) = NULL;
-EXPORT_SYMBOL(pm_power_off);
-
-
 #if XTENSA_HAVE_COPROCESSORS
 
 void coprocessor_release_all(struct thread_info *ti)
drivers/parisc/power.c +1 -2
index ef31b77..f10cf92 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();
 		}
 	}
 }
kernel/power/poweroff_handler.c +8 -0
index aeb4736..37f0b88 100644
@@ -22,6 +22,12 @@
 #include <linux/types.h>
 
 /*
+ * If set, calling this function will power off the system immediately.
+ */
+void (*pm_power_off)(void);
+EXPORT_SYMBOL(pm_power_off);
+
+/*
  *	Notifier list for kernel code which wants to be called
  *	to power off the system.
  */
@@ -236,6 +242,8 @@ EXPORT_SYMBOL(devm_register_power_off_handler);
 void do_kernel_power_off(void)
 {
 	spin_lock(&power_off_handler_lock);
+	if (pm_power_off)
+		pm_power_off();
 	raw_notifier_call_chain(&power_off_handler_list, 0, NULL);
 	spin_unlock(&power_off_handler_lock);
 }
kernel/reboot.c +2 -2
index 5925f5a..0930851 100644
@@ -306,9 +306,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 		return ret;
 
 	/* Instead of trying to make the power_off code look like
-	 * halt when pm_power_off is not set do it the easy way.
+	 * halt when no poweroff handler exists do it the easy way.
 	 */
-	if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
+	if (cmd == LINUX_REBOOT_CMD_POWER_OFF && !have_kernel_power_off())
 		cmd = LINUX_REBOOT_CMD_HALT;
 
 	mutex_lock(&reboot_mutex);
Signature · 1 line
1.9.1
#44 lore raw

PATCH v2 9/47 mfd: palmas: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>

---
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Use dev_warn instead of dev_err

 drivers/mfd/palmas.c       | 31 +++++++++++++++++--------------
 include/linux/mfd/palmas.h |  3 +++
 2 files changed, 20 insertions(+), 14 deletions(-)
drivers/mfd/palmas.c +17 -14
index 28cb048..2fda979 100644
@@ -19,6 +19,7 @@
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
+#include <linux/pm.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,16 @@ 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) {
+			int ret2;
+
+			palmas->poweroff_nb.notifier_call = palmas_power_off;
+			palmas->poweroff_nb.priority = POWEROFF_PRIORITY_LOW;
+			ret2 = devm_register_power_off_handler(palmas->dev,
+							&palmas->poweroff_nb);
+			if (ret2)
+				dev_warn(palmas->dev,
+					 "Failed to register poweroff handler");
 		}
 	}
 
@@ -698,11 +706,6 @@ 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;
-	}
-
 	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
#45 lore raw

PATCH v2 10/47 mfd: axp20x: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with a low priority value of 64 to reflect that the original code only sets pm_power_off if it was not already set.

Cc Lee Jones <[email protected]>
Cc Samuel Ortiz <[email protected]>

---
v2:
- Use define to specify powroff handler priority
- Use devm_register_power_off_handler
- Use dev_warn instead of dev_err

 drivers/mfd/axp20x.c       | 30 ++++++++++++++++--------------
 include/linux/mfd/axp20x.h |  1 +
 2 files changed, 17 insertions(+), 14 deletions(-)
drivers/mfd/axp20x.c +16 -14
index 6231adb..9e6406c 100644
@@ -17,7 +17,8 @@
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/pm_runtime.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 #include <linux/regulator/consumer.h>
@@ -150,11 +151,16 @@ static struct mfd_cell axp20x_cells[] = {
 	},
 };
 
-static struct axp20x_dev *axp20x_pm_power_off;
-static void axp20x_power_off(void)
+static int axp20x_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
+
 {
-	regmap_write(axp20x_pm_power_off->regmap, AXP20X_OFF_CTRL,
-		     AXP20X_OFF);
+	struct axp20x_dev *axp20x = container_of(this, struct axp20x_dev,
+						 poweroff_nb);
+
+	regmap_write(axp20x->regmap, AXP20X_OFF_CTRL, AXP20X_OFF);
+
+	return NOTIFY_DONE;
 }
 
 static int axp20x_i2c_probe(struct i2c_client *i2c,
@@ -204,10 +210,11 @@ static int axp20x_i2c_probe(struct i2c_client *i2c,
 		return ret;
 	}
 
-	if (!pm_power_off) {
-		axp20x_pm_power_off = axp20x;
-		pm_power_off = axp20x_power_off;
-	}
+	axp20x->poweroff_nb.notifier_call = axp20x_power_off;
+	axp20x->poweroff_nb.priority = POWEROFF_PRIORITY_LOW;
+	ret = devm_register_power_off_handler(&i2c->dev, &axp20x->poweroff_nb);
+	if (ret)
+		dev_warn(&i2c->dev, "failed to register poweroff handler\n");
 
 	dev_info(&i2c->dev, "AXP20X driver loaded\n");
 
@@ -218,11 +225,6 @@ static int axp20x_i2c_remove(struct i2c_client *i2c)
 {
 	struct axp20x_dev *axp20x = i2c_get_clientdata(i2c);
 
-	if (axp20x == axp20x_pm_power_off) {
-		axp20x_pm_power_off = NULL;
-		pm_power_off = NULL;
-	}
-
 	mfd_remove_devices(axp20x->dev);
 	regmap_del_irq_chip(axp20x->i2c_client->irq, axp20x->regmap_irqc);
 
include/linux/mfd/axp20x.h +1 -0
index d0e31a2..8f23b39 100644
@@ -175,6 +175,7 @@ struct axp20x_dev {
 	struct regmap			*regmap;
 	struct regmap_irq_chip_data	*regmap_irqc;
 	long				variant;
+	struct notifier_block		poweroff_nb;
 };
 
 #endif /* __LINUX_MFD_AXP20X_H */
Signature · 1 line
1.9.1
#46 lore raw

PATCH v2 11/47 mfd: retu: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Cc Lee Jones <[email protected]>
Cc Samuel Ortiz <[email protected]>

---
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Use dev_warn instead of dev_err

 drivers/mfd/retu-mfd.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
drivers/mfd/retu-mfd.c +19 -14
index 663f8a3..3c720cb 100644
@@ -22,6 +22,8 @@
 #include <linux/slab.h>
 #include <linux/mutex.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/mfd/core.h>
 #include <linux/mfd/retu.h>
@@ -43,6 +45,7 @@ struct retu_dev {
 	struct device			*dev;
 	struct mutex			mutex;
 	struct regmap_irq_chip_data	*irq_data;
+	struct notifier_block		poweroff_nb;
 };
 
 static struct resource retu_pwrbutton_res[] = {
@@ -81,9 +84,6 @@ static struct regmap_irq_chip retu_irq_chip = {
 	.ack_base	= RETU_REG_IDR,
 };
 
-/* Retu device registered for the power off. */
-static struct retu_dev *retu_pm_power_off;
-
 static struct resource tahvo_usb_res[] = {
 	{
 		.name	= "tahvo-usb",
@@ -165,12 +165,14 @@ int retu_write(struct retu_dev *rdev, u8 reg, u16 data)
 }
 EXPORT_SYMBOL_GPL(retu_write);
 
-static void retu_power_off(void)
+static int retu_power_off(struct notifier_block *this, unsigned long unused1,
+			  void *unused2)
 {
-	struct retu_dev *rdev = retu_pm_power_off;
+	struct retu_dev *rdev = container_of(this, struct retu_dev,
+					     poweroff_nb);
 	int reg;
 
-	mutex_lock(&retu_pm_power_off->mutex);
+	mutex_lock(&rdev->mutex);
 
 	/* Ignore power button state */
 	regmap_read(rdev->regmap, RETU_REG_CC1, &reg);
@@ -183,7 +185,9 @@ static void retu_power_off(void)
 	for (;;)
 		cpu_relax();
 
-	mutex_unlock(&retu_pm_power_off->mutex);
+	mutex_unlock(&rdev->mutex);
+
+	return NOTIFY_DONE;
 }
 
 static int retu_regmap_read(void *context, const void *reg, size_t reg_size,
@@ -279,9 +283,14 @@ static int retu_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 		return ret;
 	}
 
-	if (i2c->addr == 1 && !pm_power_off) {
-		retu_pm_power_off = rdev;
-		pm_power_off	  = retu_power_off;
+	if (i2c->addr == 1) {
+		rdev->poweroff_nb.notifier_call = retu_power_off;
+		rdev->poweroff_nb.priority = POWEROFF_PRIORITY_LOW;
+		ret = devm_register_power_off_handler(rdev->dev,
+						      &rdev->poweroff_nb);
+		if (ret)
+			dev_warn(rdev->dev,
+				 "Failed to register poweroff handler\n");
 	}
 
 	return 0;
@@ -291,10 +300,6 @@ static int retu_remove(struct i2c_client *i2c)
 {
 	struct retu_dev *rdev = i2c_get_clientdata(i2c);
 
-	if (retu_pm_power_off == rdev) {
-		pm_power_off	  = NULL;
-		retu_pm_power_off = NULL;
-	}
 	mfd_remove_devices(rdev->dev);
 	regmap_del_irq_chip(i2c->irq, rdev->irq_data);
 
Signature · 1 line
1.9.1
#47 lore raw

PATCH v2 12/47 mfd: ab8500-sysctrl: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

sysctrl_dev is set prior to poweroff handler registration, and the poweroff handler is unregistered prior to clearing sysrctrl_dev. It is therefore not necessary to check if sysctrl_dev is NULL in the poweroff handler, and the check was removed. Setting sysctrl_dev to NULL in the remove function was also removed as unnecessary. With those changes, devm_register_power_off_handler can be used to register the poeroff handler. The now empty remove function was retained since the ab8500_restart function, which is currently unused, would likely need some cleanup if it was ever used.

Cc Linus Walleij <[email protected]>
Cc Lee Jones <[email protected]>
Cc Samuel Ortiz <[email protected]>

---
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Use dev_warn instead of dev_err
- Since we use devm_register_power_off_handler,
we need to check if sysctrl_dev in the poweroff handler to avoid a race condition on unload, so this check is no longer removed

 drivers/mfd/ab8500-sysctrl.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/mfd/ab8500-sysctrl.c +15 -7
index 8e0dae5..dc634d5 100644
@@ -6,6 +6,7 @@
 
 #include <linux/err.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/reboot.h>
@@ -23,7 +24,8 @@
 
 static struct device *sysctrl_dev;
 
-static void ab8500_power_off(void)
+static int ab8500_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
 	sigset_t old;
 	sigset_t all;
@@ -36,7 +38,7 @@ static void ab8500_power_off(void)
 
 	if (sysctrl_dev == NULL) {
 		pr_err("%s: sysctrl not initialized\n", __func__);
-		return;
+		return NOTIFY_DONE;
 	}
 
 	/*
@@ -83,8 +85,15 @@ shutdown:
 					 AB8500_STW4500CTRL1_SWRESET4500N);
 		(void)sigprocmask(SIG_SETMASK, &old, NULL);
 	}
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block ab8500_poweroff_nb = {
+	.notifier_call = ab8500_power_off,
+	.priority = POWEROFF_PRIORITY_LOW,
+};
+
 /*
  * Use the AB WD to reset the platform. It will perform a hard
  * reset instead of a soft reset. Write the reset reason to
@@ -185,6 +194,7 @@ static int ab8500_sysctrl_probe(struct platform_device *pdev)
 	struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
 	struct ab8500_platform_data *plat;
 	struct ab8500_sysctrl_platform_data *pdata;
+	int err;
 
 	plat = dev_get_platdata(pdev->dev.parent);
 
@@ -193,8 +203,9 @@ static int ab8500_sysctrl_probe(struct platform_device *pdev)
 
 	sysctrl_dev = &pdev->dev;
 
-	if (!pm_power_off)
-		pm_power_off = ab8500_power_off;
+	err = devm_register_power_off_handler(sysctrl_dev, &ab8500_poweroff_nb);
+	if (err)
+		dev_warn(&pdev->dev, "Failed to register poweroff handler\n");
 
 	pdata = plat->sysctrl;
 	if (pdata) {
@@ -228,9 +239,6 @@ static int ab8500_sysctrl_remove(struct platform_device *pdev)
 {
 	sysctrl_dev = NULL;
 
-	if (pm_power_off == ab8500_power_off)
-		pm_power_off = NULL;
-
 	return 0;
 }
 
Signature · 1 line
1.9.1
Acked-by on v2 12/47
#48 lore raw

Re: [PATCH v2 12/47] mfd: ab8500-sysctrl: Register with kernel poweroff handler

Quoted 17 lines · Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

sysctrl_dev is set prior to poweroff handler registration, and the poweroff handler is unregistered prior to clearing sysrctrl_dev. It is therefore not necessary to check if sysctrl_dev is NULL in the poweroff handler, and the check was removed. Setting sysctrl_dev to NULL in the remove function was also removed as unnecessary. With those changes, devm_register_power_off_handler can be used to register the poeroff handler. The now empty remove function was retained since the ab8500_restart function, which is currently unused, would likely need some cleanup if it was ever used.

Cc Linus Walleij <[email protected]>
Cc Lee Jones <[email protected]>
Cc Samuel Ortiz <[email protected]>
Quoted 8 lines

---
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Use dev_warn instead of dev_err
- Since we use devm_register_power_off_handler,
we need to check if sysctrl_dev in the poweroff handler to avoid a race condition on unload, so this check is no longer removed

I can't compile this, I guess because of a dependency on some other patch?

CC drivers/mfd/ab8500-sysctrl.o
../drivers/mfd/ab8500-sysctrl.c:94:14: error: ?POWEROFF_PRIORITY_LOW? undeclared here (not in a function)
.priority = POWEROFF_PRIORITY_LOW,

              ^

../drivers/mfd/ab8500-sysctrl.c: In function ?ab8500_sysctrl_probe?:
../drivers/mfd/ab8500-sysctrl.c:206:2: error: implicit declaration of function ?devm_register_power_off_handler? [-Werror=implicit-function-declaration]
err = devm_register_power_off_handler(sysctrl_dev, &ab8500_poweroff_nb);

I wanted to provide a Tested-by but I guess I can only give this:

Yours,
Linus Walleij

#49 lore raw

Re: [PATCH v2 12/47] mfd: ab8500-sysctrl: Register with kernel poweroff handler

Quoted 28 lines · Linus Walleij
Quoted 17 lines · Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

sysctrl_dev is set prior to poweroff handler registration, and the poweroff handler is unregistered prior to clearing sysrctrl_dev. It is therefore not necessary to check if sysctrl_dev is NULL in the poweroff handler, and the check was removed. Setting sysctrl_dev to NULL in the remove function was also removed as unnecessary. With those changes, devm_register_power_off_handler can be used to register the poeroff handler. The now empty remove function was retained since the ab8500_restart function, which is currently unused, would likely need some cleanup if it was ever used.

Cc Linus Walleij <[email protected]>
Cc Lee Jones <[email protected]>
Cc Samuel Ortiz <[email protected]>
Quoted 8 lines

---
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Use dev_warn instead of dev_err
- Since we use devm_register_power_off_handler,
we need to check if sysctrl_dev in the poweroff handler to avoid a race condition on unload, so this check is no longer removed

Quoted 3 lines

I can't compile this, I guess because of a dependency on some other patch?

Hi Linus,

can you try v3 ? It has a number of improvements, and POWEROFF_PRIORITY_LOW was replaced with POWER_OFF_PRIORITY_LOW. You will need patch 01/47 of the series as well to get the definition.

Quoted 5 lines

CC drivers/mfd/ab8500-sysctrl.o
../drivers/mfd/ab8500-sysctrl.c:94:14: error: ?POWEROFF_PRIORITY_LOW? undeclared here (not in a function)
.priority = POWEROFF_PRIORITY_LOW,

              ^
Quoted 9 lines

../drivers/mfd/ab8500-sysctrl.c: In function ?ab8500_sysctrl_probe?:
../drivers/mfd/ab8500-sysctrl.c:206:2: error: implicit declaration of function ?devm_register_power_off_handler? [-Werror=implicit-function-declaration]
err = devm_register_power_off_handler(sysctrl_dev, &ab8500_poweroff_nb);

I wanted to provide a Tested-by but I guess I can only give this:

Thanks!
Guenter

#50 lore raw

PATCH v2 13/47 mfd: max8907: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Note that this patch fixes a problem on driver unload as side effect:
The old code did not restore or clean up pm_power_off on remove, meaning the pointer was left in an undefined state.

Cc Lee Jones <[email protected]>
Cc Samuel Ortiz <[email protected]>

---
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err

 drivers/mfd/max8907.c       | 24 ++++++++++++++++++------
 include/linux/mfd/max8907.h |  2 ++
 2 files changed, 20 insertions(+), 6 deletions(-)
drivers/mfd/max8907.c +18 -6
index 232749c..daacdbc 100644
@@ -19,6 +19,7 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 
@@ -177,11 +178,16 @@ static const struct regmap_irq_chip max8907_rtc_irq_chip = {
 	.num_irqs = ARRAY_SIZE(max8907_rtc_irqs),
 };
 
-static struct max8907 *max8907_pm_off;
-static void max8907_power_off(void)
+static int max8907_power_off(struct notifier_block *this, unsigned long unused1,
+			     void *unused2)
 {
-	regmap_update_bits(max8907_pm_off->regmap_gen, MAX8907_REG_RESET_CNFG,
+	struct max8907 *max8907 = container_of(this, struct max8907,
+					       poweroff_nb);
+
+	regmap_update_bits(max8907->regmap_gen, MAX8907_REG_RESET_CNFG,
 			MAX8907_MASK_POWER_OFF, MAX8907_MASK_POWER_OFF);
+
+	return NOTIFY_DONE;
 }
 
 static int max8907_i2c_probe(struct i2c_client *i2c,
@@ -267,9 +273,13 @@ static int max8907_i2c_probe(struct i2c_client *i2c,
 		goto err_add_devices;
 	}
 
-	if (pm_off && !pm_power_off) {
-		max8907_pm_off = max8907;
-		pm_power_off = max8907_power_off;
+	if (pm_off) {
+		max8907->poweroff_nb.notifier_call = max8907_power_off;
+		max8907->poweroff_nb.priority = POWEROFF_PRIORITY_LOW;
+		ret = register_power_off_handler(&max8907->poweroff_nb);
+		if (ret)
+			dev_warn(&i2c->dev,
+				 "Failed to register poweroff handler");
 	}
 
 	return 0;
@@ -293,6 +303,8 @@ static int max8907_i2c_remove(struct i2c_client *i2c)
 {
 	struct max8907 *max8907 = i2c_get_clientdata(i2c);
 
+	unregister_power_off_handler(&max8907->poweroff_nb);
+
 	mfd_remove_devices(max8907->dev);
 
 	regmap_del_irq_chip(max8907->i2c_gen->irq, max8907->irqc_rtc);
include/linux/mfd/max8907.h +2 -0
index b06f7a6..016428e 100644
@@ -13,6 +13,7 @@
 #define __LINUX_MFD_MAX8907_H
 
 #include <linux/mutex.h>
+#include <linux/notifier.h>
 #include <linux/pm.h>
 
 #define MAX8907_GEN_I2C_ADDR		(0x78 >> 1)
@@ -247,6 +248,7 @@ struct max8907 {
 	struct regmap_irq_chip_data	*irqc_chg;
 	struct regmap_irq_chip_data	*irqc_on_off;
 	struct regmap_irq_chip_data	*irqc_rtc;
+	struct notifier_block		poweroff_nb;
 };
 
 #endif
Signature · 1 line
1.9.1
#51 lore raw

PATCH v2 14/47 mfd: tps80031: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>

---
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err

 drivers/mfd/tps80031.c       | 30 ++++++++++++++++++------------
 include/linux/mfd/tps80031.h |  2 ++
 2 files changed, 20 insertions(+), 12 deletions(-)
drivers/mfd/tps80031.c +18 -12
index ed6c5b0..926c62a 100644
@@ -147,7 +147,6 @@ static const struct tps80031_pupd_data tps80031_pupds[] = {
 	[TPS80031_CTLI2C_SCL]		= PUPD_DATA(4, 0,	BIT(2)),
 	[TPS80031_CTLI2C_SDA]		= PUPD_DATA(4, 0,	BIT(3)),
 };
-static struct tps80031 *tps80031_power_off_dev;
 
 int tps80031_ext_power_req_config(struct device *dev,
 		unsigned long ext_ctrl_flag, int preq_bit,
@@ -209,11 +208,17 @@ int tps80031_ext_power_req_config(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(tps80031_ext_power_req_config);
 
-static void tps80031_power_off(void)
+static int tps80031_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
-	dev_info(tps80031_power_off_dev->dev, "switching off PMU\n");
-	tps80031_write(tps80031_power_off_dev->dev, TPS80031_SLAVE_ID1,
-				TPS80031_PHOENIX_DEV_ON, TPS80031_DEVOFF);
+	struct tps80031 *tps80031 = container_of(this, struct tps80031,
+						 poweroff_nb);
+
+	dev_info(tps80031->dev, "switching off PMU\n");
+	tps80031_write(tps80031->dev, TPS80031_SLAVE_ID1,
+		       TPS80031_PHOENIX_DEV_ON, TPS80031_DEVOFF);
+
+	return NOTIFY_DONE;
 }
 
 static void tps80031_pupd_init(struct tps80031 *tps80031,
@@ -501,9 +506,13 @@ static int tps80031_probe(struct i2c_client *client,
 		goto fail_mfd_add;
 	}
 
-	if (pdata->use_power_off && !pm_power_off) {
-		tps80031_power_off_dev = tps80031;
-		pm_power_off = tps80031_power_off;
+	if (pdata->use_power_off) {
+		tps80031->poweroff_nb.notifier_call = tps80031_power_off;
+		tps80031->poweroff_nb.priority = POWEROFF_PRIORITY_LOW;
+		ret = register_power_off_handler(&tps80031->poweroff_nb);
+		if (ret)
+			dev_warn(&client->dev,
+				 "Failed to register poweroff handler\n");
 	}
 	return 0;
 
@@ -523,10 +532,7 @@ static int tps80031_remove(struct i2c_client *client)
 	struct tps80031 *tps80031 = i2c_get_clientdata(client);
 	int i;
 
-	if (tps80031_power_off_dev == tps80031) {
-		tps80031_power_off_dev = NULL;
-		pm_power_off = NULL;
-	}
+	unregister_power_off_handler(&tps80031->poweroff_nb);
 
 	mfd_remove_devices(tps80031->dev);
 
include/linux/mfd/tps80031.h +2 -0
index 2c75c9c..49bc006 100644
@@ -24,6 +24,7 @@
 #define __LINUX_MFD_TPS80031_H
 
 #include <linux/device.h>
+#include <linux/notifier.h>
 #include <linux/regmap.h>
 
 /* Pull-ups/Pull-downs */
@@ -513,6 +514,7 @@ struct tps80031 {
 	struct i2c_client	*clients[TPS80031_NUM_SLAVES];
 	struct regmap		*regmap[TPS80031_NUM_SLAVES];
 	struct regmap_irq_chip_data *irq_data;
+	struct notifier_block	poweroff_nb;
 };
 
 struct tps80031_pupd_init_data {
Signature · 1 line
1.9.1
#52 lore raw

PATCH v2 15/47 mfd: dm355evm_msp: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>

---
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err

 drivers/mfd/dm355evm_msp.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/mfd/dm355evm_msp.c +15 -3
index 4c826f7..3ec49a7 100644
@@ -14,6 +14,8 @@
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/err.h>
 #include <linux/gpio.h>
 #include <linux/leds.h>
@@ -352,14 +354,22 @@ static void dm355evm_command(unsigned command)
 				command, status);
 }
 
-static void dm355evm_power_off(void)
+static int dm355evm_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
 	dm355evm_command(MSP_COMMAND_POWEROFF);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block dm355evm_msp_poweroff_nb = {
+	.notifier_call = dm355evm_power_off,
+	.priority = POWEROFF_PRIORITY_LOW,
+};
+
 static int dm355evm_msp_remove(struct i2c_client *client)
 {
-	pm_power_off = NULL;
+	unregister_power_off_handler(&dm355evm_msp_poweroff_nb);
 	msp430 = NULL;
 	return 0;
 }
@@ -398,7 +408,9 @@ dm355evm_msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		goto fail;
 
 	/* PM hookup */
-	pm_power_off = dm355evm_power_off;
+	status = register_power_off_handler(&dm355evm_msp_poweroff_nb);
+	if (status)
+		dev_warn(&client->dev, "Failed to register poweroff handler\n");
 
 	return 0;
 
Signature · 1 line
1.9.1
#53 lore raw

PATCH v2 16/47 mfd: tps6586x: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>

---
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err

 drivers/mfd/tps6586x.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
drivers/mfd/tps6586x.c +23 -8
index 8e1dbc4..01c2714 100644
@@ -21,10 +21,12 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/notifier.h>
 #include <linux/slab.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
 #include <linux/platform_device.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/of.h>
 
@@ -133,6 +135,8 @@ struct tps6586x {
 	u32			irq_en;
 	u8			mask_reg[5];
 	struct irq_domain	*irq_domain;
+
+	struct notifier_block	poweroff_nb;
 };
 
 static inline struct tps6586x *dev_to_tps6586x(struct device *dev)
@@ -472,13 +476,18 @@ static const struct regmap_config tps6586x_regmap_config = {
 	.cache_type = REGCACHE_RBTREE,
 };
 
-static struct device *tps6586x_dev;
-static void tps6586x_power_off(void)
+static int tps6586x_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
-	if (tps6586x_clr_bits(tps6586x_dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
-		return;
+	struct tps6586x *tps6586x = container_of(this, struct tps6586x,
+						 poweroff_nb);
+
+	if (tps6586x_clr_bits(tps6586x->dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
+		return NOTIFY_DONE;
 
-	tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
+	tps6586x_set_bits(tps6586x->dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
+
+	return NOTIFY_DONE;
 }
 
 static void tps6586x_print_version(struct i2c_client *client, int version)
@@ -575,9 +584,13 @@ static int tps6586x_i2c_probe(struct i2c_client *client,
 		goto err_add_devs;
 	}
 
-	if (pdata->pm_off && !pm_power_off) {
-		tps6586x_dev = &client->dev;
-		pm_power_off = tps6586x_power_off;
+	if (pdata->pm_off) {
+		tps6586x->poweroff_nb.notifier_call = tps6586x_power_off;
+		tps6586x->poweroff_nb.priority = POWEROFF_PRIORITY_LOW;
+		ret = register_power_off_handler(&tps6586x->poweroff_nb);
+		if (ret)
+			dev_warn(&client->dev,
+				 "failed to register poweroff handler\n");
 	}
 
 	return 0;
@@ -594,6 +607,8 @@ static int tps6586x_i2c_remove(struct i2c_client *client)
 {
 	struct tps6586x *tps6586x = i2c_get_clientdata(client);
 
+	unregister_power_off_handler(&tps6586x->poweroff_nb);
+
 	tps6586x_remove_subdevs(tps6586x);
 	mfd_remove_devices(tps6586x->dev);
 	if (client->irq)
Signature · 1 line
1.9.1
#54 lore raw

PATCH v2 17/47 mfd: tps65910: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>

---
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err

 drivers/mfd/tps65910.c       | 27 ++++++++++++++++++---------
 include/linux/mfd/tps65910.h |  3 +++
 2 files changed, 21 insertions(+), 9 deletions(-)
drivers/mfd/tps65910.c +18 -9
index 7612d89..88ea108 100644
@@ -23,6 +23,8 @@
 #include <linux/irq.h>
 #include <linux/irqdomain.h>
 #include <linux/mfd/core.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/mfd/tps65910.h>
 #include <linux/of.h>
@@ -437,19 +439,20 @@ struct tps65910_board *tps65910_parse_dt(struct i2c_client *client,
 }
 #endif
 
-static struct i2c_client *tps65910_i2c_client;
-static void tps65910_power_off(void)
+static int tps65910_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
-	struct tps65910 *tps65910;
-
-	tps65910 = dev_get_drvdata(&tps65910_i2c_client->dev);
+	struct tps65910 *tps65910 = container_of(this, struct tps65910,
+						 poweroff_nb);
 
 	if (tps65910_reg_set_bits(tps65910, TPS65910_DEVCTRL,
 			DEVCTRL_PWR_OFF_MASK) < 0)
-		return;
+		return NOTIFY_DONE;
 
 	tps65910_reg_clear_bits(tps65910, TPS65910_DEVCTRL,
 			DEVCTRL_DEV_ON_MASK);
+
+	return NOTIFY_DONE;
 }
 
 static int tps65910_i2c_probe(struct i2c_client *i2c,
@@ -505,9 +508,13 @@ static int tps65910_i2c_probe(struct i2c_client *i2c,
 	tps65910_ck32k_init(tps65910, pmic_plat_data);
 	tps65910_sleepinit(tps65910, pmic_plat_data);
 
-	if (pmic_plat_data->pm_off && !pm_power_off) {
-		tps65910_i2c_client = i2c;
-		pm_power_off = tps65910_power_off;
+	if (pmic_plat_data->pm_off) {
+		tps65910->poweroff_nb.notifier_call = tps65910_power_off;
+		tps65910->poweroff_nb.priority = POWEROFF_PRIORITY_LOW;
+		ret = register_power_off_handler(&tps65910->poweroff_nb);
+		if (ret)
+			dev_warn(&i2c->dev,
+				 "failed to register poweroff handler\n");
 	}
 
 	ret = mfd_add_devices(tps65910->dev, -1,
@@ -527,6 +534,8 @@ static int tps65910_i2c_remove(struct i2c_client *i2c)
 {
 	struct tps65910 *tps65910 = i2c_get_clientdata(i2c);
 
+	unregister_power_off_handler(&tps65910->poweroff_nb);
+
 	tps65910_irq_exit(tps65910);
 	mfd_remove_devices(tps65910->dev);
 
include/linux/mfd/tps65910.h +3 -0
index 6483a6f..65cae2c 100644
@@ -905,6 +905,9 @@ struct tps65910 {
 	/* IRQ Handling */
 	int chip_irq;
 	struct regmap_irq_chip_data *irq_data;
+
+	/* Poweroff handling */
+	struct notifier_block poweroff_nb;
 };
 
 struct tps65910_platform_data {
Signature · 1 line
1.9.1
#55 lore raw

PATCH v2 18/47 mfd: twl4030-power: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Make twl4030_power_off static as it is only called from the twl4030-power driver. Drop remove function as it is no longer needed.

Cc Samuel Ortiz <[email protected]>
Cc Lee Jones <[email protected]>

---
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err
- Use devm_register_power_off_handler
- Drop remove function as it is no longer needed.

 drivers/mfd/twl4030-power.c | 29 +++++++++++++++++++----------
 include/linux/i2c/twl.h     |  1 -
 2 files changed, 19 insertions(+), 11 deletions(-)
drivers/mfd/twl4030-power.c +19 -10
index cf92a6d..85e4aa4 100644
@@ -25,9 +25,10 @@
  */
 
 #include <linux/module.h>
-#include <linux/pm.h>
+#include <linux/notifier.h>
 #include <linux/i2c/twl.h>
 #include <linux/platform_device.h>
+#include <linux/pm.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
 
@@ -611,7 +612,8 @@ twl4030_power_configure_resources(const struct twl4030_power_data *pdata)
  * After a successful execution, TWL shuts down the power to the SoC
  * and all peripherals connected to it.
  */
-void twl4030_power_off(void)
+static int twl4030_power_off(struct notifier_block *this, unsigned long unused1,
+			     void *unused2)
 {
 	int err;
 
@@ -619,8 +621,15 @@ void twl4030_power_off(void)
 			       TWL4030_PM_MASTER_P1_SW_EVENTS);
 	if (err)
 		pr_err("TWL4030 Unable to power off\n");
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block twl4030_poweroff_nb = {
+	.notifier_call = twl4030_power_off,
+	.priority = POWEROFF_PRIORITY_LOW,
+};
+
 static bool twl4030_power_use_poweroff(const struct twl4030_power_data *pdata,
 					struct device_node *node)
 {
@@ -839,7 +848,9 @@ static int twl4030_power_probe(struct platform_device *pdev)
 	}
 
 	/* Board has to be wired properly to use this feature */
-	if (twl4030_power_use_poweroff(pdata, node) && !pm_power_off) {
+	if (twl4030_power_use_poweroff(pdata, node)) {
+		int ret;
+
 		/* Default for SEQ_OFFSYNC is set, lets ensure this */
 		err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val,
 				      TWL4030_PM_MASTER_CFG_P123_TRANSITION);
@@ -856,7 +867,11 @@ static int twl4030_power_probe(struct platform_device *pdev)
 			}
 		}
 
-		pm_power_off = twl4030_power_off;
+		ret = devm_register_power_off_handler(&pdev->dev,
+						      &twl4030_poweroff_nb);
+		if (ret)
+			dev_warn(&pdev->dev,
+				 "Failed to register poweroff handler\n");
 	}
 
 relock:
@@ -870,11 +885,6 @@ relock:
 	return err;
 }
 
-static int twl4030_power_remove(struct platform_device *pdev)
-{
-	return 0;
-}
-
 static struct platform_driver twl4030_power_driver = {
 	.driver = {
 		.name	= "twl4030_power",
@@ -882,7 +892,6 @@ static struct platform_driver twl4030_power_driver = {
 		.of_match_table = of_match_ptr(twl4030_power_of_match),
 	},
 	.probe		= twl4030_power_probe,
-	.remove		= twl4030_power_remove,
 };
 
 module_platform_driver(twl4030_power_driver);
include/linux/i2c/twl.h +0 -1
index 8cfb50f..f8544f1 100644
@@ -680,7 +680,6 @@ struct twl4030_power_data {
 };
 
 extern int twl4030_remove_script(u8 flags);
-extern void twl4030_power_off(void);
 
 struct twl4030_codec_data {
 	unsigned int digimic_delay; /* in ms */
Signature · 1 line
1.9.1
#56 lore raw

PATCH v2 19/47 mfd: rk808: Register poweroff handler with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Cc Chris Zhong <[email protected]>
Cc Zhang Qing <[email protected]>

---
v2:
- New patch

 drivers/mfd/rk808.c       | 30 ++++++++++++++++--------------
 include/linux/mfd/rk808.h |  2 ++
 2 files changed, 18 insertions(+), 14 deletions(-)
drivers/mfd/rk808.c +16 -14
index bd02150..7f07279 100644
@@ -21,6 +21,8 @@
 #include <linux/mfd/rk808.h>
 #include <linux/mfd/core.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 
 struct rk808_reg_data {
@@ -147,23 +149,19 @@ static struct regmap_irq_chip rk808_irq_chip = {
 	.init_ack_masked = true,
 };
 
-static struct i2c_client *rk808_i2c_client;
-static void rk808_device_shutdown(void)
+static int rk808_device_shutdown(struct notifier_block *this,
+				 unsigned long unused1, void *unused2)
 {
+	struct rk808 *rk808 = container_of(this, struct rk808, poweroff_nb);
 	int ret;
-	struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
-
-	if (!rk808) {
-		dev_warn(&rk808_i2c_client->dev,
-			 "have no rk808, so do nothing here\n");
-		return;
-	}
 
 	ret = regmap_update_bits(rk808->regmap,
 				 RK808_DEVCTRL_REG,
 				 DEV_OFF_RST, DEV_OFF_RST);
 	if (ret)
-		dev_err(&rk808_i2c_client->dev, "power off error!\n");
+		dev_err(&rk808->i2c->dev, "power off error!\n");
+
+	return NOTIFY_DONE;
 }
 
 static int rk808_probe(struct i2c_client *client,
@@ -222,9 +220,14 @@ static int rk808_probe(struct i2c_client *client,
 
 	pm_off = of_property_read_bool(np,
 				"rockchip,system-power-controller");
-	if (pm_off && !pm_power_off) {
-		rk808_i2c_client = client;
-		pm_power_off = rk808_device_shutdown;
+	if (pm_off) {
+		rk808->poweroff_nb.notifier_call = rk808_device_shutdown;
+		rk808->poweroff_nb.priority = POWEROFF_PRIORITY_LOW;
+		ret = devm_register_power_off_handler(&client->dev,
+						      &rk808->poweroff_nb);
+		if (ret)
+			dev_warn(&client->dev,
+				 "Failed to register poweroff handler\n");
 	}
 
 	return 0;
@@ -240,7 +243,6 @@ static int rk808_remove(struct i2c_client *client)
 
 	regmap_del_irq_chip(client->irq, rk808->irq_data);
 	mfd_remove_devices(&client->dev);
-	pm_power_off = NULL;
 
 	return 0;
 }
include/linux/mfd/rk808.h +2 -0
index fb09312..abc80cc 100644
@@ -19,6 +19,7 @@
 #ifndef __LINUX_REGULATOR_rk808_H
 #define __LINUX_REGULATOR_rk808_H
 
+#include <linux/notifier.h>
 #include <linux/regulator/machine.h>
 #include <linux/regmap.h>
 
@@ -192,5 +193,6 @@ struct rk808 {
 	struct i2c_client *i2c;
 	struct regmap_irq_chip_data *irq_data;
 	struct regmap *regmap;
+	struct notifier_block poweroff_nb;
 };
 #endif /* __LINUX_REGULATOR_rk808_H */
Signature · 1 line
1.9.1
#57 lore raw

PATCH v2 20/47 mfd: rn5t618: Register poweroff handler with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Cc Beniamino Galvani <[email protected]>

---
v2: New patch

 drivers/mfd/rn5t618.c       | 32 ++++++++++++++++----------------
 include/linux/mfd/rn5t618.h |  2 ++
 2 files changed, 18 insertions(+), 16 deletions(-)
drivers/mfd/rn5t618.c +16 -16
index 6668571..045cd43 100644
@@ -15,6 +15,8 @@
 #include <linux/mfd/core.h>
 #include <linux/mfd/rn5t618.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/regmap.h>
 
 static const struct mfd_cell rn5t618_cells[] = {
@@ -47,16 +49,20 @@ static const struct regmap_config rn5t618_regmap_config = {
 	.cache_type	= REGCACHE_RBTREE,
 };
 
-static struct rn5t618 *rn5t618_pm_power_off;
-
-static void rn5t618_power_off(void)
+static int rn5t618_power_off(struct notifier_block *this,
+			     unsigned long unused1, void *unused2)
 {
+	struct rn5t618 *rn5t618 = container_of(this, struct rn5t618,
+					       poweroff_nb);
+
 	/* disable automatic repower-on */
-	regmap_update_bits(rn5t618_pm_power_off->regmap, RN5T618_REPCNT,
+	regmap_update_bits(rn5t618->regmap, RN5T618_REPCNT,
 			   RN5T618_REPCNT_REPWRON, 0);
 	/* start power-off sequence */
-	regmap_update_bits(rn5t618_pm_power_off->regmap, RN5T618_SLPCNT,
+	regmap_update_bits(rn5t618->regmap, RN5T618_SLPCNT,
 			   RN5T618_SLPCNT_SWPWROFF, RN5T618_SLPCNT_SWPWROFF);
+
+	return NOTIFY_DONE;
 }
 
 static int rn5t618_i2c_probe(struct i2c_client *i2c,
@@ -85,23 +91,17 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c,
 		return ret;
 	}
 
-	if (!pm_power_off) {
-		rn5t618_pm_power_off = priv;
-		pm_power_off = rn5t618_power_off;
-	}
+	priv->poweroff_nb.notifier_call = rn5t618_power_off;
+	priv->poweroff_nb.priority = POWEROFF_PRIORITY_LOW;
+	ret = devm_register_power_off_handler(&i2c->dev, &priv->poweroff_nb);
+	if (ret)
+		dev_warn(&i2c->dev, "Failed to register poweroff handler\n");
 
 	return 0;
 }
 
 static int rn5t618_i2c_remove(struct i2c_client *i2c)
 {
-	struct rn5t618 *priv = i2c_get_clientdata(i2c);
-
-	if (priv == rn5t618_pm_power_off) {
-		rn5t618_pm_power_off = NULL;
-		pm_power_off = NULL;
-	}
-
 	mfd_remove_devices(&i2c->dev);
 	return 0;
 }
include/linux/mfd/rn5t618.h +2 -0
index c72d534..3b0f0e6 100644
@@ -14,6 +14,7 @@
 #ifndef __LINUX_MFD_RN5T618_H
 #define __LINUX_MFD_RN5T618_H
 
+#include <linux/notifier.h>
 #include <linux/regmap.h>
 
 #define RN5T618_LSIVER			0x00
@@ -223,6 +224,7 @@ enum {
 
 struct rn5t618 {
 	struct regmap *regmap;
+	struct notifier_block poweroff_nb;
 };
 
 #endif /* __LINUX_MFD_RN5T618_H */
Signature · 1 line
1.9.1
#58 lore raw

PATCH v2 21/47 ipmi: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with high priority to reflect that the original code overwrites pm_power_off unconditionally.

Register poweroff handler after the ipmi system is ready, and unregister it prior to cleanup. This avoids having to check for the ready variable in the poweroff callback.

---
v2:
- Use define to specify poweroff handler priority
- Use pr_warn instead of pr_err
- Call unregister_power_off_handler on exit only if not already unregistered

 drivers/char/ipmi/ipmi_poweroff.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)
drivers/char/ipmi/ipmi_poweroff.c +18 -11
index 9f2e3be..41067da 100644
@@ -36,6 +36,7 @@
 #include <linux/proc_fs.h>
 #include <linux/string.h>
 #include <linux/completion.h>
+#include <linux/notifier.h>
 #include <linux/pm.h>
 #include <linux/kdev_t.h>
 #include <linux/ipmi.h>
@@ -63,9 +64,6 @@ static ipmi_user_t ipmi_user;
 static int ipmi_ifnum;
 static void (*specific_poweroff_func)(ipmi_user_t user);
 
-/* Holds the old poweroff function so we can restore it on removal. */
-static void (*old_poweroff_func)(void);
-
 static int set_param_ifnum(const char *val, struct kernel_param *kp)
 {
 	int rv = param_set_int(val, kp);
@@ -544,15 +542,20 @@ static struct poweroff_function poweroff_functions[] = {
 
 
 /* Called on a powerdown request. */
-static void ipmi_poweroff_function(void)
+static int ipmi_poweroff_function(struct notifier_block *this,
+				  unsigned long unused1, void *unused2)
 {
-	if (!ready)
-		return;
-
 	/* Use run-to-completion mode, since interrupts may be off. */
 	specific_poweroff_func(ipmi_user);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block ipmi_poweroff_nb = {
+	.notifier_call = ipmi_poweroff_function,
+	.priority = POWEROFF_PRIORITY_HIGH,
+};
+
 /* Wait for an IPMI interface to be installed, the first one installed
    will be grabbed by this code and used to perform the powerdown. */
 static void ipmi_po_new_smi(int if_num, struct device *device)
@@ -631,9 +634,12 @@ static void ipmi_po_new_smi(int if_num, struct device *device)
 	printk(KERN_INFO PFX "Found a %s style poweroff function\n",
 	       poweroff_functions[i].platform_type);
 	specific_poweroff_func = poweroff_functions[i].poweroff_func;
-	old_poweroff_func = pm_power_off;
-	pm_power_off = ipmi_poweroff_function;
+
 	ready = 1;
+
+	rv = register_power_off_handler(&ipmi_poweroff_nb);
+	if (rv)
+		pr_warn(PFX "failed to register poweroff handler\n");
 }
 
 static void ipmi_po_smi_gone(int if_num)
@@ -644,9 +650,10 @@ static void ipmi_po_smi_gone(int if_num)
 	if (ipmi_ifnum != if_num)
 		return;
 
+	unregister_power_off_handler(&ipmi_poweroff_nb);
+
 	ready = 0;
 	ipmi_destroy_user(ipmi_user);
-	pm_power_off = old_poweroff_func;
 }
 
 static struct ipmi_smi_watcher smi_watcher = {
@@ -733,11 +740,11 @@ static void __exit ipmi_poweroff_cleanup(void)
 	ipmi_smi_watcher_unregister(&smi_watcher);
 
 	if (ready) {
+		unregister_power_off_handler(&ipmi_poweroff_nb);
 		rv = ipmi_destroy_user(ipmi_user);
 		if (rv)
 			printk(KERN_ERR PFX "could not cleanup the IPMI"
 			       " user: 0x%x\n", rv);
-		pm_power_off = old_poweroff_func;
 	}
 }
 module_exit(ipmi_poweroff_cleanup);
Signature · 1 line
1.9.1
#59 lore raw

PATCH v2 22/47 power/reset: restart-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting 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.

Drop remove function since it is no longer needed.

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

---
v2:
- Use define to sepcify poweroff handler priority
- Use devm_register_power_off_handler
- Drop remove function since it is no longer needed

 drivers/power/reset/restart-poweroff.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)
drivers/power/reset/restart-poweroff.c +13 -20
index edd707e..e8f8e59 100644
@@ -12,37 +12,31 @@
  */
 #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/pm.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);
-}
-
-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 NOTIFY_DONE;
 }
 
-static int restart_poweroff_remove(struct platform_device *pdev)
-{
-	if (pm_power_off == &restart_poweroff_do_poweroff)
-		pm_power_off = NULL;
+static struct notifier_block restart_power_off_handler = {
+	.notifier_call = restart_poweroff_do_poweroff,
+	.priority = POWEROFF_PRIORITY_FALLBACK,
+};
 
-	return 0;
+static int restart_poweroff_probe(struct platform_device *pdev)
+{
+	return devm_register_power_off_handler(&pdev->dev,
+					      &restart_power_off_handler);
 }
 
 static const struct of_device_id of_restart_poweroff_match[] = {
@@ -52,7 +46,6 @@ static const struct of_device_id of_restart_poweroff_match[] = {
 
 static struct platform_driver restart_poweroff_driver = {
 	.probe = restart_poweroff_probe,
-	.remove = restart_poweroff_remove,
 	.driver = {
 		.name = "poweroff-restart",
 		.owner = THIS_MODULE,
Signature · 1 line
1.9.1
maintainer Acked-by on v2 22/47
#60 lore raw

Re: [PATCH v2 22/47] power/reset: restart-poweroff: Register with kernel poweroff handler

Hi,

Quoted 11 lines · Guenter Roeck

Register with kernel poweroff handler instead of setting 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.

Drop remove function since it is no longer needed.

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

-- Sebastian

#61 lore raw

Re: [PATCH v2 22/47] power/reset: restart-poweroff: Register with kernel poweroff handler

Quoted 9 lines · Sebastian Reichel

Hi,

Quoted 6 lines · Guenter Roeck

Register with kernel poweroff handler instead of setting 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.

Drop remove function since it is no longer needed.

Quoted 8 lines
Quoted 5 lines
Cc Sebastian Reichel <[email protected]>
Cc Dmitry Eremin-Solenikov <[email protected]>
Cc David Woodhouse <[email protected]>

Thanks for all the Acks!

Guenter

#62 lore raw

PATCH v2 23/47 power/reset: gpio-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Other changes:

Drop note that there can not be an additional instance of this driver. The original reason no longer applies, it should be obvious that there can only be one instance of the driver if static variables are used to reflect its state, and support for multiple instances can now be added easily if needed by avoiding static variables.

Do not create an error message if another poweroff handler has already been registered. This is perfectly normal and acceptable.

Drop remove function since it is no longer needed.

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

---
v2;
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Drop remove function as it is no longer needed

 drivers/power/reset/gpio-poweroff.c | 40 ++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 23 deletions(-)
drivers/power/reset/gpio-poweroff.c +17 -23
index ce849bc..5d35f13 100644
@@ -14,18 +14,18 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/platform_device.h>
 #include <linux/gpio/consumer.h>
 #include <linux/of_platform.h>
 #include <linux/module.h>
 
-/*
- * Hold configuration here, cannot be more than one instance of the driver
- * since pm_power_off itself is global.
- */
 static struct gpio_desc *reset_gpio;
 
-static void gpio_poweroff_do_poweroff(void)
+static int gpio_poweroff_do_poweroff(struct notifier_block *this,
+				     unsigned long unused1, void *unused2)
+
 {
 	BUG_ON(!reset_gpio);
 
@@ -43,19 +43,19 @@ static void gpio_poweroff_do_poweroff(void)
 	mdelay(3000);
 
 	WARN_ON(1);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block gpio_poweroff_nb = {
+	.notifier_call = gpio_poweroff_do_poweroff,
+	.priority = POWEROFF_PRIORITY_LOW,
+};
+
 static int gpio_poweroff_probe(struct platform_device *pdev)
 {
 	bool input = false;
-
-	/* If a pm_power_off function has already been added, leave it alone */
-	if (pm_power_off != NULL) {
-		dev_err(&pdev->dev,
-			"%s: pm_power_off function already registered",
-		       __func__);
-		return -EBUSY;
-	}
+	int err;
 
 	reset_gpio = devm_gpiod_get(&pdev->dev, NULL);
 	if (IS_ERR(reset_gpio))
@@ -77,16 +77,11 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
 		}
 	}
 
-	pm_power_off = &gpio_poweroff_do_poweroff;
-	return 0;
-}
-
-static int gpio_poweroff_remove(struct platform_device *pdev)
-{
-	if (pm_power_off == &gpio_poweroff_do_poweroff)
-		pm_power_off = NULL;
+	err = devm_register_power_off_handler(&pdev->dev, &gpio_poweroff_nb);
+	if (err)
+		dev_err(&pdev->dev, "Failed to register poweroff handler\n");
 
-	return 0;
+	return err;
 }
 
 static const struct of_device_id of_gpio_poweroff_match[] = {
@@ -96,7 +91,6 @@ static const struct of_device_id of_gpio_poweroff_match[] = {
 
 static struct platform_driver gpio_poweroff_driver = {
 	.probe = gpio_poweroff_probe,
-	.remove = gpio_poweroff_remove,
 	.driver = {
 		.name = "poweroff-gpio",
 		.owner = THIS_MODULE,
Signature · 1 line
1.9.1
maintainer Acked-by on v2 23/47
#63 lore raw

Re: [PATCH v2 23/47] power/reset: gpio-poweroff: Register with kernel poweroff handler

Hi,

Quoted 15 lines · Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Other changes:

Drop note that there can not be an additional instance of this driver. The original reason no longer applies, it should be obvious that there can only be one instance of the driver if static variables are used to reflect its state, and support for multiple instances can now be added easily if needed by avoiding static variables.

Do not create an error message if another poweroff handler has already been registered. This is perfectly normal and acceptable.

Quoted 7 lines

Drop remove function since it is no longer needed.

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

-- Sebastian

#64 lore raw

PATCH v2 24/47 power/reset: as3722-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Drop remove function since it is no longer needed.

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

---
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Drop remove function since it is no longer needed

 drivers/power/reset/as3722-poweroff.c | 39 ++++++++++++++---------------------
 1 file changed, 15 insertions(+), 24 deletions(-)
drivers/power/reset/as3722-poweroff.c +15 -24
index 6849711..9f878e7 100644
@@ -17,32 +17,33 @@
 
 #include <linux/mfd/as3722.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
+#include <linux/pm.h>
 #include <linux/slab.h>
 
 struct as3722_poweroff {
 	struct device *dev;
 	struct as3722 *as3722;
+	struct notifier_block poweroff_nb;
 };
 
-static struct as3722_poweroff *as3722_pm_poweroff;
-
-static void as3722_pm_power_off(void)
+static int as3722_power_off(struct notifier_block *this, unsigned long unused1,
+			    void *unused2)
 {
+	struct as3722_poweroff *as3722_poweroff =
+		container_of(this, struct as3722_poweroff, poweroff_nb);
 	int ret;
 
-	if (!as3722_pm_poweroff) {
-		pr_err("AS3722 poweroff is not initialised\n");
-		return;
-	}
-
-	ret = as3722_update_bits(as3722_pm_poweroff->as3722,
+	ret = as3722_update_bits(as3722_poweroff->as3722,
 		AS3722_RESET_CONTROL_REG, AS3722_POWER_OFF, AS3722_POWER_OFF);
 	if (ret < 0)
-		dev_err(as3722_pm_poweroff->dev,
+		dev_err(as3722_poweroff->dev,
 			"RESET_CONTROL_REG update failed, %d\n", ret);
+
+	return NOTIFY_DONE;
 }
 
 static int as3722_poweroff_probe(struct platform_device *pdev)
@@ -63,20 +64,11 @@ static int as3722_poweroff_probe(struct platform_device *pdev)
 
 	as3722_poweroff->as3722 = dev_get_drvdata(pdev->dev.parent);
 	as3722_poweroff->dev = &pdev->dev;
-	as3722_pm_poweroff = as3722_poweroff;
-	if (!pm_power_off)
-		pm_power_off = as3722_pm_power_off;
-
-	return 0;
-}
-
-static int as3722_poweroff_remove(struct platform_device *pdev)
-{
-	if (pm_power_off == as3722_pm_power_off)
-		pm_power_off = NULL;
-	as3722_pm_poweroff = NULL;
+	as3722_poweroff->poweroff_nb.notifier_call = as3722_power_off;
+	as3722_poweroff->poweroff_nb.priority = POWEROFF_PRIORITY_LOW;
 
-	return 0;
+	return devm_register_power_off_handler(&pdev->dev,
+					      &as3722_poweroff->poweroff_nb);
 }
 
 static struct platform_driver as3722_poweroff_driver = {
@@ -85,7 +77,6 @@ static struct platform_driver as3722_poweroff_driver = {
 		.owner = THIS_MODULE,
 	},
 	.probe = as3722_poweroff_probe,
-	.remove = as3722_poweroff_remove,
 };
 
 module_platform_driver(as3722_poweroff_driver);
Signature · 1 line
1.9.1
maintainer Acked-by on v2 24/47
#65 lore raw

Re: [PATCH v2 24/47] power/reset: as3722-poweroff: Register with kernel poweroff handler

Hi,

Quoted 10 lines · Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code only sets pm_power_off if it was not already set.

Drop remove function since it is no longer needed.

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

-- Sebastian

#66 lore raw

PATCH v2 25/47 power/reset: qnap-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with default priority to reflect that the original code generates an error if another poweroff handler has already been registered when the driver is loaded.

Drop remove function since it is no longer needed.

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

---
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler
- Drop remove function since it is no longer needed

 drivers/power/reset/qnap-poweroff.c | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)
drivers/power/reset/qnap-poweroff.c +12 -20
index a75db7f..da3d58a 100644
@@ -16,7 +16,9 @@
 
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #include <linux/platform_device.h>
+#include <linux/pm.h>
 #include <linux/serial_reg.h>
 #include <linux/kallsyms.h>
 #include <linux/of.h>
@@ -55,7 +57,8 @@ static void __iomem *base;
 static unsigned long tclk;
 static const struct power_off_cfg *cfg;
 
-static void qnap_power_off(void)
+static int qnap_power_off(struct notifier_block *this, unsigned long unused1,
+			  void *unused2)
 {
 	const unsigned divisor = ((tclk + (8 * cfg->baud)) / (16 * cfg->baud));
 
@@ -72,14 +75,20 @@ static void qnap_power_off(void)
 
 	/* send the power-off command to PIC */
 	writel(cfg->cmd, UART1_REG(TX));
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block qnap_poweroff_nb = {
+	.notifier_call = qnap_power_off,
+	.priority = POWEROFF_PRIORITY_DEFAULT,
+};
+
 static int qnap_power_off_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
 	struct resource *res;
 	struct clk *clk;
-	char symname[KSYM_NAME_LEN];
 
 	const struct of_device_id *match =
 		of_match_node(qnap_power_off_of_match_table, np);
@@ -106,28 +115,11 @@ static int qnap_power_off_probe(struct platform_device *pdev)
 
 	tclk = clk_get_rate(clk);
 
-	/* Check that nothing else has already setup a handler */
-	if (pm_power_off) {
-		lookup_symbol_name((ulong)pm_power_off, symname);
-		dev_err(&pdev->dev,
-			"pm_power_off already claimed %p %s",
-			pm_power_off, symname);
-		return -EBUSY;
-	}
-	pm_power_off = qnap_power_off;
-
-	return 0;
-}
-
-static int qnap_power_off_remove(struct platform_device *pdev)
-{
-	pm_power_off = NULL;
-	return 0;
+	return devm_register_power_off_handler(&pdev->dev, &qnap_poweroff_nb);
 }
 
 static struct platform_driver qnap_power_off_driver = {
 	.probe	= qnap_power_off_probe,
-	.remove	= qnap_power_off_remove,
 	.driver	= {
 		.owner	= THIS_MODULE,
 		.name	= "qnap_power_off",
Signature · 1 line
1.9.1
maintainer Acked-by on v2 25/47
#67 lore raw

Re: [PATCH v2 25/47] power/reset: qnap-poweroff: Register with kernel poweroff handler

Hi,

Quoted 5 lines · Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with default priority to reflect that the original code generates an error if another poweroff handler has already been registered when the driver is loaded.

Quoted 7 lines

Drop remove function since it is no longer needed.

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

-- Sebastian

#68 lore raw

PATCH v2 26/47 power/reset: msm-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Select fallback priority since the code does not really poweroff the system but resets it instead.

---
v2:
- Use define to specify poweroff handler priority
- Fix headline and description
- Merge with restart handler code now used in same driver
- Use dev_warn instead of dev_err

 drivers/power/reset/msm-poweroff.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/power/reset/msm-poweroff.c +8 -5
index 4702efd..d44f332 100644
@@ -19,10 +19,12 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #include <linux/reboot.h>
 #include <linux/pm.h>
 
 static void __iomem *msm_ps_hold;
+
 static int do_msm_restart(struct notifier_block *nb, unsigned long action,
 			   void *data)
 {
@@ -37,11 +39,11 @@ static struct notifier_block restart_nb = {
 	.priority = 128,
 };
 
-static void do_msm_poweroff(void)
-{
+static struct notifier_block msm_poweroff_nb = {
 	/* TODO: Add poweroff capability */
-	do_msm_restart(&restart_nb, 0, NULL);
-}
+	.notifier_call = do_msm_restart,
+	.priority = POWEROFF_PRIORITY_FALLBACK,
+};
 
 static int msm_restart_probe(struct platform_device *pdev)
 {
@@ -55,7 +57,8 @@ static int msm_restart_probe(struct platform_device *pdev)
 
 	register_restart_handler(&restart_nb);
 
-	pm_power_off = do_msm_poweroff;
+	if (register_power_off_handler(&msm_poweroff_nb))
+		dev_warn(&pdev->dev, "Failed to register poweroff handler\n");
 
 	return 0;
 }
Signature · 1 line
1.9.1
#70 lore raw

PATCH v2 27/47 power/reset: vexpress-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Select default priority to reflect that the original code sets pm_power_off unconditionally.

---
v2: Use define to specify poweroff handler priority

 drivers/power/reset/vexpress-poweroff.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/power/reset/vexpress-poweroff.c +17 -2
index 4dc102e2..1ea2f2e 100644
@@ -12,6 +12,7 @@
  */
 
 #include <linux/delay.h>
+#include <linux/notifier.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
@@ -36,11 +37,19 @@ static void vexpress_reset_do(struct device *dev, const char *what)
 
 static struct device *vexpress_power_off_device;
 
-static void vexpress_power_off(void)
+static int vexpress_power_off(struct notifier_block *this,
+			      unsigned long unused1, void *unused2)
 {
 	vexpress_reset_do(vexpress_power_off_device, "power off");
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block vexpress_poweroff_nb = {
+	.notifier_call = vexpress_power_off,
+	.priority = POWEROFF_PRIORITY_DEFAULT,
+};
+
 static struct device *vexpress_restart_device;
 
 static void vexpress_restart(enum reboot_mode reboot_mode, const char *cmd)
@@ -92,6 +101,7 @@ static int vexpress_reset_probe(struct platform_device *pdev)
 	const struct of_device_id *match =
 			of_match_device(vexpress_reset_of_match, &pdev->dev);
 	struct regmap *regmap;
+	int ret;
 
 	if (match)
 		func = (enum vexpress_reset_func)match->data;
@@ -106,7 +116,12 @@ static int vexpress_reset_probe(struct platform_device *pdev)
 	switch (func) {
 	case FUNC_SHUTDOWN:
 		vexpress_power_off_device = &pdev->dev;
-		pm_power_off = vexpress_power_off;
+		ret = register_power_off_handler(&vexpress_poweroff_nb);
+		if (ret) {
+			dev_err(&pdev->dev,
+				"Failed to register poweroff handler\n");
+			return ret;
+		}
 		break;
 	case FUNC_RESET:
 		if (!vexpress_restart_device)
Signature · 1 line
1.9.1
#72 lore raw

PATCH v2 28/47 power/reset: at91-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Select default priority to reflect that the original code sets pm_power_off unconditionally.

---
v2: Added patch

 drivers/power/reset/at91-poweroff.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/power/reset/at91-poweroff.c +12 -4
index c610003..ac49a83 100644
@@ -12,8 +12,10 @@
 
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/pm.h>
 #include <linux/printk.h>
 
 #define AT91_SHDW_CR	0x00		/* Shut Down Control Register */
@@ -66,11 +68,19 @@ static void __init at91_wakeup_status(void)
 	pr_info("AT91: Wake-Up source: %s\n", reason);
 }
 
-static void at91_poweroff(void)
+static int at91_poweroff(struct notifier_block *this, unsigned long unused1,
+			 void *unused2)
 {
 	writel(AT91_SHDW_KEY | AT91_SHDW_SHDW, at91_shdwc_base + AT91_SHDW_CR);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block at91_poweroff_nb = {
+	.notifier_call = at91_poweroff,
+	.priority = POWEROFF_PRIORITY_DEFAULT,
+};
+
 const enum wakeup_type at91_poweroff_get_wakeup_mode(struct device_node *np)
 {
 	const char *pm;
@@ -134,9 +144,7 @@ static int at91_poweroff_probe(struct platform_device *pdev)
 	if (pdev->dev.of_node)
 		at91_poweroff_dt_set_wakeup_mode(pdev);
 
-	pm_power_off = at91_poweroff;
-
-	return 0;
+	return devm_register_power_off_handler(&pdev->dev, &at91_poweroff_nb);
 }
 
 static struct of_device_id at91_poweroff_of_match[] = {
Signature · 1 line
1.9.1
#74 lore raw

PATCH v2 29/47 power/reset: ltc2952-poweroff: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code sets pm_power_off only if it was not already set.

---
v2: Added patch

 drivers/power/reset/ltc2952-poweroff.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
drivers/power/reset/ltc2952-poweroff.c +18 -9
index 116a1ce..da9abd2 100644
@@ -80,6 +80,8 @@ struct ltc2952_poweroff_data {
 	 * 2: kill
 	 */
 	struct gpio_desc *gpio[3];
+
+	struct notifier_block poweroff_nb;
 };
 
 static int ltc2952_poweroff_panic;
@@ -180,9 +182,13 @@ irq_ok:
 	return IRQ_HANDLED;
 }
 
-static void ltc2952_poweroff_kill(void)
+static int ltc2952_poweroff_kill(struct notifier_block *this,
+				 unsigned long unused1, void *unused2)
+
 {
 	gpiod_set_value(ltc2952_data->gpio[POWERPATH_IO_KILL], 1);
+
+	return NOTIFY_DONE;
 }
 
 static int ltc2952_poweroff_suspend(struct platform_device *pdev,
@@ -285,12 +291,7 @@ err_io:
 
 static int ltc2952_poweroff_probe(struct platform_device *pdev)
 {
-	int ret;
-
-	if (pm_power_off) {
-		dev_err(&pdev->dev, "pm_power_off already registered");
-		return -EBUSY;
-	}
+	int i, ret;
 
 	ltc2952_data = kzalloc(sizeof(*ltc2952_data), GFP_KERNEL);
 	if (!ltc2952_data)
@@ -302,12 +303,20 @@ static int ltc2952_poweroff_probe(struct platform_device *pdev)
 	if (ret)
 		goto err;
 
-	pm_power_off = &ltc2952_poweroff_kill;
+	ltc2952_data->poweroff_nb.notifier_call = ltc2952_poweroff_kill;
+	ltc2952_data->poweroff_nb.priority = POWEROFF_PRIORITY_LOW;
+	ret = register_power_off_handler(&ltc2952_data->poweroff_nb);
+	if (ret)
+		goto err_power;
 
 	dev_info(&pdev->dev, "probe successful\n");
 
 	return 0;
 
+err_power:
+	free_irq(ltc2952_data->virq, ltc2952_data);
+	for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++)
+		gpiod_put(ltc2952_data->gpio[i]);
 err:
 	kfree(ltc2952_data);
 	return ret;
@@ -317,7 +326,7 @@ static int ltc2952_poweroff_remove(struct platform_device *pdev)
 {
 	unsigned int i;
 
-	pm_power_off = NULL;
+	unregister_power_off_handler(&ltc2952_data->poweroff_nb);
 
 	if (ltc2952_data) {
 		free_irq(ltc2952_data->virq, ltc2952_data);
Signature · 1 line
1.9.1
maintainer Acked-by on v2 29/47
#75 lore raw

Re: [PATCH v2 29/47] power/reset: ltc2952-poweroff: Register with kernel poweroff handler

Hi,

Quoted 5 lines · Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the original code sets pm_power_off only if it was not already set.

-- Sebastian

#76 lore raw

PATCH v2 30/47 x86: iris: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with high priority to reflect that the original code overwrites existing poweroff handlers.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>

---
v2:
- Use define to specify poweroff handler priority
- Use devm_register_power_off_handler

 arch/x86/platform/iris/iris.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
arch/x86/platform/iris/iris.c +18 -6
index 4d171e8..dd36815 100644
@@ -23,6 +23,7 @@
 
 #include <linux/moduleparam.h>
 #include <linux/module.h>
+#include <linux/notifier.h>
 #include <linux/platform_device.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -47,15 +48,21 @@ static bool force;
 module_param(force, bool, 0);
 MODULE_PARM_DESC(force, "Set to one to force poweroff handler installation.");
 
-static void (*old_pm_power_off)(void);
-
-static void iris_power_off(void)
+static int iris_power_off(struct notifier_block *this, unsigned long unused1,
+			  void *unused2)
 {
 	outb(IRIS_GIO_PULSE, IRIS_GIO_OUTPUT);
 	msleep(850);
 	outb(IRIS_GIO_REST, IRIS_GIO_OUTPUT);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block iris_poweroff_nb = {
+	.notifier_call = iris_power_off,
+	.priority = POWEROFF_PRIORITY_HIGH,
+};
+
 /*
  * Before installing the power_off handler, try to make sure the OS is
  * running on an Iris.  Since Iris does not support DMI, this is done
@@ -65,20 +72,25 @@ static void iris_power_off(void)
 static int iris_probe(struct platform_device *pdev)
 {
 	unsigned char status = inb(IRIS_GIO_INPUT);
+	int ret;
+
 	if (status == IRIS_GIO_NODEV) {
 		printk(KERN_ERR "This machine does not seem to be an Iris. "
 			"Power off handler not installed.\n");
 		return -ENODEV;
 	}
-	old_pm_power_off = pm_power_off;
-	pm_power_off = &iris_power_off;
+
+	ret = devm_register_power_off_handler(&pdev->dev, &iris_poweroff_nb);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to register poweroff handler\n");
+		return ret;
+	}
 	printk(KERN_INFO "Iris power_off handler installed.\n");
 	return 0;
 }
 
 static int iris_remove(struct platform_device *pdev)
 {
-	pm_power_off = old_pm_power_off;
 	printk(KERN_INFO "Iris power_off handler uninstalled.\n");
 	return 0;
 }
Signature · 1 line
1.9.1
#77 lore raw

PATCH v2 31/47 x86: apm: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with high priority to reflect that the original code overwrites existing poweroff handlers.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Jiri Kosina <[email protected]>

---
v2:
- Use define to specify poweroff handler priority

 arch/x86/kernel/apm_32.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
arch/x86/kernel/apm_32.c +15 -5
index 5848744..b03a65e 100644
@@ -219,6 +219,7 @@
 #include <linux/init.h>
 #include <linux/time.h>
 #include <linux/sched.h>
+#include <linux/notifier.h>
 #include <linux/pm.h>
 #include <linux/capability.h>
 #include <linux/device.h>
@@ -981,7 +982,8 @@ recalc:
  *	on their first cpu.
  */
 
-static void apm_power_off(void)
+static int apm_power_off(struct notifier_block *this, unsigned long unused1,
+			 void *unused2)
 {
 	/* Some bioses don't like being called from CPU != 0 */
 	if (apm_info.realmode_power_off) {
@@ -990,8 +992,14 @@ static void apm_power_off(void)
 	} else {
 		(void)set_system_power_state(APM_STATE_OFF);
 	}
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block apm_poweroff_nb = {
+	.notifier_call = apm_power_off,
+	.priority = POWEROFF_PRIORITY_HIGH,
+};
+
 #ifdef CONFIG_APM_DO_ENABLE
 
 /**
@@ -1847,8 +1855,11 @@ static int apm(void *unused)
 	}
 
 	/* Install our power off handler.. */
-	if (power_off)
-		pm_power_off = apm_power_off;
+	if (power_off) {
+		error = register_power_off_handler(&apm_poweroff_nb);
+		if (error)
+			pr_err("apm: Failed to register poweroff handler\n");
+	}
 
 	if (num_online_cpus() == 1 || smp) {
 #if defined(CONFIG_APM_DISPLAY_BLANK) && defined(CONFIG_VT)
@@ -2408,9 +2419,8 @@ static void __exit apm_exit(void)
 			apm_error("disengage power management", error);
 	}
 	misc_deregister(&apm_device);
+	unregister_power_off_handler(&apm_poweroff_nb);
 	remove_proc_entry("apm", NULL);
-	if (power_off)
-		pm_power_off = NULL;
 	if (kapmd_task) {
 		kthread_stop(kapmd_task);
 		kapmd_task = NULL;
Signature · 1 line
1.9.1
Reviewed-by on v2 31/47
#78 lore raw

Re: [PATCH v2 31/47] x86: apm: Register with kernel poweroff handler

Quoted 9 lines · Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with high priority to reflect that the original code overwrites existing poweroff handlers.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Jiri Kosina <[email protected]>

For this one:

Signature · 2 lines
Jiri Kosina
SUSE Labs
#79 lore raw

PATCH v2 32/47 x86: olpc: Register xo1 poweroff handler with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with high priority to reflect that the driver explicitly wants to override default poweroff handlers.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc H. Peter Anvin <[email protected]>

---
v2: Use define to specify poweroff handler priority

 arch/x86/platform/olpc/olpc-xo1-pm.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
arch/x86/platform/olpc/olpc-xo1-pm.c +17 -3
index a9acde7..a8e427f 100644
@@ -15,6 +15,7 @@
 #include <linux/cs5535.h>
 #include <linux/platform_device.h>
 #include <linux/export.h>
+#include <linux/notifier.h>
 #include <linux/pm.h>
 #include <linux/mfd/core.h>
 #include <linux/suspend.h>
@@ -92,7 +93,8 @@ asmlinkage __visible int xo1_do_sleep(u8 sleep_state)
 	return 0;
 }
 
-static void xo1_power_off(void)
+static int xo1_power_off(struct notifier_block *this, unsigned long unused1,
+			 void *unused2)
 {
 	printk(KERN_INFO "OLPC XO-1 power off sequence...\n");
 
@@ -108,8 +110,15 @@ static void xo1_power_off(void)
 
 	/* Write SLP_EN bit to start the machinery */
 	outl(0x00002000, acpi_base + CS5536_PM1_CNT);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block xo1_poweroff_nb = {
+	.notifier_call = xo1_power_off,
+	.priority = POWEROFF_PRIORITY_HIGH,
+};
+
 static int xo1_power_state_valid(suspend_state_t pm_state)
 {
 	/* suspend-to-RAM only */
@@ -146,8 +155,12 @@ static int xo1_pm_probe(struct platform_device *pdev)
 
 	/* If we have both addresses, we can override the poweroff hook */
 	if (pms_base && acpi_base) {
+		err = register_power_off_handler(&xo1_poweroff_nb);
+		if (err) {
+			dev_err(&pdev->dev, "Failed to register poweroff handler\n");
+			return err;
+		}
 		suspend_set_ops(&xo1_suspend_ops);
-		pm_power_off = xo1_power_off;
 		printk(KERN_INFO "OLPC XO-1 support registered\n");
 	}
 
@@ -158,12 +171,13 @@ static int xo1_pm_remove(struct platform_device *pdev)
 {
 	mfd_cell_disable(pdev);
 
+	unregister_power_off_handler(&xo1_poweroff_nb);
+
 	if (strcmp(pdev->name, "cs5535-pms") == 0)
 		pms_base = 0;
 	else if (strcmp(pdev->name, "olpc-xo1-pm-acpi") == 0)
 		acpi_base = 0;
 
-	pm_power_off = NULL;
 	return 0;
 }
 
Signature · 1 line
1.9.1
#80 lore raw

PATCH v2 33/47 staging: nvec: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with default priority since we don't know any better.

Cc Julian Andres Klode <[email protected]>
Cc Marc Dietrich <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---
v2:
- Use define to specify poweroff handler priority
- Use dev_warn instead of dev_err

 drivers/staging/nvec/nvec.c | 24 +++++++++++++++---------
 drivers/staging/nvec/nvec.h |  2 ++
 2 files changed, 17 insertions(+), 9 deletions(-)
drivers/staging/nvec/nvec.c +15 -9
index a93208a..78b68a3 100644
@@ -33,6 +33,7 @@
 #include <linux/mfd/core.h>
 #include <linux/mutex.h>
 #include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/workqueue.h>
@@ -80,8 +81,6 @@ enum nvec_sleep_subcmds {
 #define LID_SWITCH BIT(1)
 #define PWR_BUTTON BIT(15)
 
-static struct nvec_chip *nvec_power_handle;
-
 static const struct mfd_cell nvec_devices[] = {
 	{
 		.name = "nvec-kbd",
@@ -759,12 +758,17 @@ static void nvec_disable_i2c_slave(struct nvec_chip *nvec)
 }
 #endif
 
-static void nvec_power_off(void)
+static int nvec_power_off(struct notifier_block *this, unsigned long unused1,
+			  void *unused2)
 {
+	struct nvec_chip *nvec = container_of(this, struct nvec_chip,
+					      poweroff_nb);
 	char ap_pwr_down[] = { NVEC_SLEEP, AP_PWR_DOWN };
 
-	nvec_toggle_global_events(nvec_power_handle, false);
-	nvec_write_async(nvec_power_handle, ap_pwr_down, 2);
+	nvec_toggle_global_events(nvec, false);
+	nvec_write_async(nvec, ap_pwr_down, 2);
+
+	return NOTIFY_DONE;
 }
 
 /*
@@ -878,8 +882,11 @@ static int tegra_nvec_probe(struct platform_device *pdev)
 	nvec->nvec_status_notifier.notifier_call = nvec_status_notifier;
 	nvec_register_notifier(nvec, &nvec->nvec_status_notifier, 0);
 
-	nvec_power_handle = nvec;
-	pm_power_off = nvec_power_off;
+	nvec->poweroff_nb.notifier_call = nvec_power_off;
+	nvec->poweroff_nb.priority = POWEROFF_PRIORITY_DEFAULT;
+	ret = register_power_off_handler(&nvec->poweroff_nb);
+	if (ret)
+		dev_warn(nvec->dev, "Failed to register poweroff handler\n");
 
 	/* Get Firmware Version */
 	msg = nvec_write_sync(nvec, get_firmware_version, 2);
@@ -914,13 +921,12 @@ static int tegra_nvec_remove(struct platform_device *pdev)
 {
 	struct nvec_chip *nvec = platform_get_drvdata(pdev);
 
+	unregister_power_off_handler(&nvec->poweroff_nb);
 	nvec_toggle_global_events(nvec, false);
 	mfd_remove_devices(nvec->dev);
 	nvec_unregister_notifier(nvec, &nvec->nvec_status_notifier);
 	cancel_work_sync(&nvec->rx_work);
 	cancel_work_sync(&nvec->tx_work);
-	/* FIXME: needs check wether nvec is responsible for power off */
-	pm_power_off = NULL;
 
 	return 0;
 }
drivers/staging/nvec/nvec.h +2 -0
index e271375..e5ee2af 100644
@@ -163,6 +163,8 @@ struct nvec_chip {
 	struct nvec_msg *last_sync_msg;
 
 	int state;
+
+	struct notifier_block poweroff_nb;
 };
 
 extern int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
Signature · 1 line
1.9.1
#81 lore raw

PATCH v2 34/47 acpi: Register poweroff handler with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with high priority to reflect that the driver explicitly overrides existing poweroff handlers.

Cc Rafael J. Wysocki <[email protected]>
Cc Len Brown <[email protected]>

---
v2:
- Use define to specify poweroff handler priority
- Use pr_warn instead of pr_err

 drivers/acpi/sleep.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/acpi/sleep.c +13 -2
index 05a31b5..1eba563 100644
@@ -16,6 +16,8 @@
 #include <linux/device.h>
 #include <linux/interrupt.h>
 #include <linux/suspend.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/acpi.h>
 #include <linux/module.h>
@@ -827,14 +829,22 @@ static void acpi_power_off_prepare(void)
 	acpi_disable_all_gpes();
 }
 
-static void acpi_power_off(void)
+static int acpi_power_off(struct notifier_block *this,
+			  unsigned long unused1, void *unused2)
 {
 	/* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
 	printk(KERN_DEBUG "%s called\n", __func__);
 	local_irq_disable();
 	acpi_enter_sleep_state(ACPI_STATE_S5);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block acpi_poweroff_nb = {
+	.notifier_call = acpi_power_off,
+	.priority = POWEROFF_PRIORITY_HIGH,
+};
+
 int __init acpi_sleep_init(void)
 {
 	char supported[ACPI_S_STATE_COUNT * 3 + 1];
@@ -851,7 +861,8 @@ int __init acpi_sleep_init(void)
 	if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
 		sleep_states[ACPI_STATE_S5] = 1;
 		pm_power_off_prepare = acpi_power_off_prepare;
-		pm_power_off = acpi_power_off;
+		if (register_power_off_handler(&acpi_poweroff_nb))
+			pr_warn("acpi: Failed to register poweroff handler\n");
 	}
 
 	supported[0] = 0;
Signature · 1 line
1.9.1
#82 lore raw

Re: [PATCH v2 34/47] acpi: Register poweroff handler with kernel poweroff handler

Quoted 53 lines · Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with high priority to reflect that the driver explicitly overrides existing poweroff handlers.

Cc Rafael J. Wysocki <[email protected]>
Cc Len Brown <[email protected]>

---
v2:
- Use define to specify poweroff handler priority
- Use pr_warn instead of pr_err

 drivers/acpi/sleep.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/acpi/sleep.c +11 -1
index 05a31b5..1eba563 100644
@@ -16,6 +16,8 @@
 #include <linux/device.h>
 #include <linux/interrupt.h>
 #include <linux/suspend.h>
+#include <linux/notifier.h>
+#include <linux/pm.h>
 #include <linux/reboot.h>
 #include <linux/acpi.h>
 #include <linux/module.h>
@@ -827,14 +829,22 @@ static void acpi_power_off_prepare(void)
 	acpi_disable_all_gpes();
 }
 
-static void acpi_power_off(void)
+static int acpi_power_off(struct notifier_block *this,
+			  unsigned long unused1, void *unused2)
 {
 	/* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
 	printk(KERN_DEBUG "%s called\n", __func__);
 	local_irq_disable();
 	acpi_enter_sleep_state(ACPI_STATE_S5);
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block acpi_poweroff_nb = {
+	.notifier_call = acpi_power_off,
+	.priority = POWEROFF_PRIORITY_HIGH,
+};
+
 int __init acpi_sleep_init(void)
 {
 	char supported[ACPI_S_STATE_COUNT * 3 + 1];

drivers/acpi/sleep.c int __init acpi_sleep_init(void) · line 865

Quoted 6 lines
drivers/acpi/sleep.c +2 -1
@@ -851,7 +861,8 @@ int __init acpi_sleep_init(void)
 	if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
 		sleep_states[ACPI_STATE_S5] = 1;
 		pm_power_off_prepare = acpi_power_off_prepare;
-		pm_power_off = acpi_power_off;
+		if (register_power_off_handler(&acpi_poweroff_nb))
+			pr_warn("acpi: Failed to register poweroff handler\n");

Please always spell "ACPI" in capitals in kernel messages.

Quoted 4 lines
drivers/acpi/sleep.c +0 -0
 	}
 
 	supported[0] = 0;
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#83 lore raw

PATCH v2 35/47 arm: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Always use register_power_off_handler_simple as there is no indication that more than one poweroff handler is registered.

If the poweroff handler only resets the system or puts the CPU in sleep mode, select the fallback priority to indicate that the poweroff handler is one of last resort. If the poweroff handler powers off the system, select the default priority.

---
- Use defines to specify poweroff handler priorities
- Drop changes in arch/arm/mach-at91/setup.c (file removed upstream)

 arch/arm/kernel/psci.c                         | 3 ++-
 arch/arm/mach-at91/board-gsia18s.c             | 3 ++-
 arch/arm/mach-bcm/board_bcm2835.c              | 3 ++-
 arch/arm/mach-cns3xxx/cns3420vb.c              | 3 ++-
 arch/arm/mach-cns3xxx/core.c                   | 3 ++-
 arch/arm/mach-highbank/highbank.c              | 3 ++-
 arch/arm/mach-imx/mach-mx31moboard.c           | 3 ++-
 arch/arm/mach-iop32x/em7210.c                  | 3 ++-
 arch/arm/mach-iop32x/glantank.c                | 3 ++-
 arch/arm/mach-iop32x/iq31244.c                 | 3 ++-
 arch/arm/mach-iop32x/n2100.c                   | 3 ++-
 arch/arm/mach-ixp4xx/dsmg600-setup.c           | 3 ++-
 arch/arm/mach-ixp4xx/nas100d-setup.c           | 3 ++-
 arch/arm/mach-ixp4xx/nslu2-setup.c             | 3 ++-
 arch/arm/mach-omap2/board-omap3touchbook.c     | 3 ++-
 arch/arm/mach-orion5x/board-mss2.c             | 3 ++-
 arch/arm/mach-orion5x/dns323-setup.c           | 9 ++++++---
 arch/arm/mach-orion5x/kurobox_pro-setup.c      | 3 ++-
 arch/arm/mach-orion5x/ls-chl-setup.c           | 3 ++-
 arch/arm/mach-orion5x/ls_hgl-setup.c           | 3 ++-
 arch/arm/mach-orion5x/lsmini-setup.c           | 3 ++-
 arch/arm/mach-orion5x/mv2120-setup.c           | 3 ++-
 arch/arm/mach-orion5x/net2big-setup.c          | 3 ++-
 arch/arm/mach-orion5x/terastation_pro2-setup.c | 3 ++-
 arch/arm/mach-orion5x/ts209-setup.c            | 3 ++-
 arch/arm/mach-orion5x/ts409-setup.c            | 3 ++-
 arch/arm/mach-pxa/corgi.c                      | 3 ++-
 arch/arm/mach-pxa/mioa701.c                    | 3 ++-
 arch/arm/mach-pxa/poodle.c                     | 3 ++-
 arch/arm/mach-pxa/spitz.c                      | 3 ++-
 arch/arm/mach-pxa/tosa.c                       | 3 ++-
 arch/arm/mach-pxa/viper.c                      | 3 ++-
 arch/arm/mach-pxa/z2.c                         | 7 ++++---
 arch/arm/mach-pxa/zeus.c                       | 7 ++++---
 arch/arm/mach-s3c24xx/mach-gta02.c             | 3 ++-
 arch/arm/mach-s3c24xx/mach-jive.c              | 3 ++-
 arch/arm/mach-s3c24xx/mach-vr1000.c            | 3 ++-
 arch/arm/mach-s3c64xx/mach-smartq.c            | 3 ++-
 arch/arm/mach-sa1100/generic.c                 | 3 ++-
 arch/arm/mach-sa1100/simpad.c                  | 3 ++-
 arch/arm/mach-u300/regulator.c                 | 3 ++-
 arch/arm/mach-vt8500/vt8500.c                  | 3 ++-
 arch/arm/xen/enlighten.c                       | 3 ++-
 43 files changed, 94 insertions(+), 49 deletions(-)
arch/arm/kernel/psci.c +2 -1
index f73891b..4917c99 100644
@@ -264,7 +264,8 @@ static int psci_0_2_init(struct device_node *np)
 
 	arm_pm_restart = psci_sys_reset;
 
-	pm_power_off = psci_sys_poweroff;
+	register_power_off_handler_simple(psci_sys_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 out_put_node:
 	of_node_put(np);
arch/arm/mach-at91/board-gsia18s.c +2 -1
index bf5cc55..cb5d1c3 100644
@@ -521,7 +521,8 @@ static void gsia18s_power_off(void)
 
 static int __init gsia18s_power_off_init(void)
 {
-	pm_power_off = gsia18s_power_off;
+	register_power_off_handler_simple(gsia18s_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 	return 0;
 }
 
arch/arm/mach-bcm/board_bcm2835.c +2 -1
index 70f2f39..307ebc1 100644
@@ -111,7 +111,8 @@ static void __init bcm2835_init(void)
 
 	bcm2835_setup_restart();
 	if (wdt_regs)
-		pm_power_off = bcm2835_power_off;
+		register_power_off_handler_simple(bcm2835_power_off,
+						  POWEROFF_PRIORITY_FALLBACK);
 
 	bcm2835_init_clocks();
 
arch/arm/mach-cns3xxx/cns3420vb.c +2 -1
index 6428bcc7..3f48979 100644
@@ -224,7 +224,8 @@ static void __init cns3420_init(void)
 	cns3xxx_ahci_init();
 	cns3xxx_sdhci_init();
 
-	pm_power_off = cns3xxx_power_off;
+	register_power_off_handler_simple(cns3xxx_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 static struct map_desc cns3420_io_desc[] __initdata = {
arch/arm/mach-cns3xxx/core.c +2 -1
index 4e9837d..fc0b9e0 100644
@@ -386,7 +386,8 @@ static void __init cns3xxx_init(void)
 		cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(SDIO));
 	}
 
-	pm_power_off = cns3xxx_power_off;
+	register_power_off_handler_simple(cns3xxx_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	of_platform_populate(NULL, of_default_bus_match_table,
                         cns3xxx_auxdata, NULL);
arch/arm/mach-highbank/highbank.c +2 -1
index 8c35ae4..87958f9a 100644
@@ -155,7 +155,8 @@ static void __init highbank_init(void)
 	sregs_base = of_iomap(np, 0);
 	WARN_ON(!sregs_base);
 
-	pm_power_off = highbank_power_off;
+	register_power_off_handler_simple(highbank_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 	highbank_pm_init();
 
 	bus_register_notifier(&platform_bus_type, &highbank_platform_nb);
arch/arm/mach-imx/mach-mx31moboard.c +2 -1
index bb6f8a5..736937b 100644
@@ -559,7 +559,8 @@ static void __init mx31moboard_init(void)
 
 	imx_add_platform_device("imx_mc13783", 0, NULL, 0, NULL, 0);
 
-	pm_power_off = mx31moboard_poweroff;
+	register_power_off_handler_simple(mx31moboard_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	switch (mx31moboard_baseboard) {
 	case MX31NOBOARD:
arch/arm/mach-iop32x/em7210.c +2 -1
index 77e1ff0..8f93266 100644
@@ -201,7 +201,8 @@ static int __init em7210_request_gpios(void)
 		return 0;
 	}
 
-	pm_power_off = em7210_power_off;
+	register_power_off_handler_simple(em7210_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	return 0;
 }
arch/arm/mach-iop32x/glantank.c +2 -1
index 547b234..8d12aa1 100644
@@ -199,7 +199,8 @@ static void __init glantank_init_machine(void)
 	i2c_register_board_info(0, glantank_i2c_devices,
 		ARRAY_SIZE(glantank_i2c_devices));
 
-	pm_power_off = glantank_power_off;
+	register_power_off_handler_simple(glantank_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 MACHINE_START(GLANTANK, "GLAN Tank")
arch/arm/mach-iop32x/iq31244.c +2 -1
index 0e1392b..7c09bbe 100644
@@ -293,7 +293,8 @@ static void __init iq31244_init_machine(void)
 	platform_device_register(&iop3xx_dma_1_channel);
 
 	if (is_ep80219())
-		pm_power_off = ep80219_power_off;
+		register_power_off_handler_simple(ep80219_power_off,
+						  POWEROFF_PRIORITY_DEFAULT);
 
 	if (!is_80219())
 		platform_device_register(&iop3xx_aau_channel);
arch/arm/mach-iop32x/n2100.c +2 -1
index c1cd80e..ee949c5 100644
@@ -356,7 +356,8 @@ static void __init n2100_init_machine(void)
 	i2c_register_board_info(0, n2100_i2c_devices,
 		ARRAY_SIZE(n2100_i2c_devices));
 
-	pm_power_off = n2100_power_off;
+	register_power_off_handler_simple(n2100_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 MACHINE_START(N2100, "Thecus N2100")
arch/arm/mach-ixp4xx/dsmg600-setup.c +2 -1
index 43ee06d..ae3dafa 100644
@@ -281,7 +281,8 @@ static void __init dsmg600_init(void)
 
 	platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
 
-	pm_power_off = dsmg600_power_off;
+	register_power_off_handler_simple(dsmg600_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
arch/arm/mach-ixp4xx/nas100d-setup.c +2 -1
index 4e0f762..a8062db 100644
@@ -292,7 +292,8 @@ static void __init nas100d_init(void)
 
 	platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));
 
-	pm_power_off = nas100d_power_off;
+	register_power_off_handler_simple(nas100d_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
 		IRQF_TRIGGER_LOW, "NAS100D reset button", NULL) < 0) {
arch/arm/mach-ixp4xx/nslu2-setup.c +2 -1
index 88c025f..a95f727 100644
@@ -262,7 +262,8 @@ static void __init nslu2_init(void)
 
 	platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));
 
-	pm_power_off = nslu2_power_off;
+	register_power_off_handler_simple(nslu2_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler,
 		IRQF_TRIGGER_LOW, "NSLU2 reset button", NULL) < 0) {
arch/arm/mach-omap2/board-omap3touchbook.c +2 -1
index a01993e..22347b8 100644
@@ -344,7 +344,8 @@ static void __init omap3_touchbook_init(void)
 {
 	omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
 
-	pm_power_off = omap3_touchbook_poweroff;
+	register_power_off_handler_simple(omap3_touchbook_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	if (system_rev >= 0x20 && system_rev <= 0x34301000) {
 		omap_mux_init_gpio(23, OMAP_PIN_INPUT);
arch/arm/mach-orion5x/board-mss2.c +2 -1
index 66f9c3b..7b46868 100644
@@ -86,5 +86,6 @@ static void mss2_power_off(void)
 void __init mss2_init(void)
 {
 	/* register mss2 specific power-off method */
-	pm_power_off = mss2_power_off;
+	register_power_off_handler_simple(mss2_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 }
arch/arm/mach-orion5x/dns323-setup.c +6 -3
index 09d2a26..979c696 100644
@@ -669,7 +669,8 @@ static void __init dns323_init(void)
 		if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
 		    gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
 			pr_err("DNS-323: failed to setup power-off GPIO\n");
-		pm_power_off = dns323a_power_off;
+		register_power_off_handler_simple(dns323a_power_off,
+						  POWEROFF_PRIORITY_DEFAULT);
 		break;
 	case DNS323_REV_B1:
 		/* 5182 built-in SATA init */
@@ -686,7 +687,8 @@ static void __init dns323_init(void)
 		if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
 		    gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
 			pr_err("DNS-323: failed to setup power-off GPIO\n");
-		pm_power_off = dns323b_power_off;
+		register_power_off_handler_simple(dns323b_power_off,
+						  POWEROFF_PRIORITY_DEFAULT);
 		break;
 	case DNS323_REV_C1:
 		/* 5182 built-in SATA init */
@@ -696,7 +698,8 @@ static void __init dns323_init(void)
 		if (gpio_request(DNS323C_GPIO_POWER_OFF, "POWEROFF") != 0 ||
 		    gpio_direction_output(DNS323C_GPIO_POWER_OFF, 0) != 0)
 			pr_err("DNS-323: failed to setup power-off GPIO\n");
-		pm_power_off = dns323c_power_off;
+		register_power_off_handler_simple(dns323c_power_off,
+						  POWEROFF_PRIORITY_DEFAULT);
 
 		/* Now, -this- should theorically be done by the sata_mv driver
 		 * once I figure out what's going on there. Maybe the behaviour
arch/arm/mach-orion5x/kurobox_pro-setup.c +2 -1
index fe6a48a..1004d2ad 100644
@@ -376,7 +376,8 @@ static void __init kurobox_pro_init(void)
 	i2c_register_board_info(0, &kurobox_pro_i2c_rtc, 1);
 
 	/* register Kurobox Pro specific power-off method */
-	pm_power_off = kurobox_pro_power_off;
+	register_power_off_handler_simple(kurobox_pro_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 #ifdef CONFIG_MACH_KUROBOX_PRO
arch/arm/mach-orion5x/ls-chl-setup.c +2 -1
index 028ea03..b1e161a 100644
@@ -312,7 +312,8 @@ static void __init lschl_init(void)
 	gpio_set_value(LSCHL_GPIO_USB_POWER, 1);
 
 	/* register power-off method */
-	pm_power_off = lschl_power_off;
+	register_power_off_handler_simple(lschl_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	pr_info("%s: finished\n", __func__);
 }
arch/arm/mach-orion5x/ls_hgl-setup.c +2 -1
index 32b7129..c77e5a0 100644
@@ -259,7 +259,8 @@ static void __init ls_hgl_init(void)
 	gpio_set_value(LS_HGL_GPIO_USB_POWER, 1);
 
 	/* register power-off method */
-	pm_power_off = ls_hgl_power_off;
+	register_power_off_handler_simple(ls_hgl_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	pr_info("%s: finished\n", __func__);
 }
arch/arm/mach-orion5x/lsmini-setup.c +2 -1
index a6493e7..9235353 100644
@@ -260,7 +260,8 @@ static void __init lsmini_init(void)
 	gpio_set_value(LSMINI_GPIO_USB_POWER, 1);
 
 	/* register power-off method */
-	pm_power_off = lsmini_power_off;
+	register_power_off_handler_simple(lsmini_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	pr_info("%s: finished\n", __func__);
 }
arch/arm/mach-orion5x/mv2120-setup.c +2 -1
index e032f01..897f1f6 100644
@@ -225,7 +225,8 @@ static void __init mv2120_init(void)
 	if (gpio_request(MV2120_GPIO_POWER_OFF, "POWEROFF") != 0 ||
 	    gpio_direction_output(MV2120_GPIO_POWER_OFF, 1) != 0)
 		pr_err("mv2120: failed to setup power-off GPIO\n");
-	pm_power_off = mv2120_power_off;
+	register_power_off_handler_simple(mv2120_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 /* Warning: HP uses a wrong mach-type (=526) in their bootloader */
arch/arm/mach-orion5x/net2big-setup.c +2 -1
index ba73dc7..f783ad7 100644
@@ -413,7 +413,8 @@ static void __init net2big_init(void)
 
 	if (gpio_request(NET2BIG_GPIO_POWER_OFF, "power-off") == 0 &&
 	    gpio_direction_output(NET2BIG_GPIO_POWER_OFF, 0) == 0)
-		pm_power_off = net2big_power_off;
+		register_power_off_handler_simple(net2big_power_off,
+						  POWEROFF_PRIORITY_DEFAULT);
 	else
 		pr_err("net2big: failed to configure power-off GPIO\n");
 
arch/arm/mach-orion5x/terastation_pro2-setup.c +2 -1
index 1208674..4c16209 100644
@@ -353,7 +353,8 @@ static void __init tsp2_init(void)
 	i2c_register_board_info(0, &tsp2_i2c_rtc, 1);
 
 	/* register Terastation Pro II specific power-off method */
-	pm_power_off = tsp2_power_off;
+	register_power_off_handler_simple(tsp2_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 MACHINE_START(TERASTATION_PRO2, "Buffalo Terastation Pro II/Live")
arch/arm/mach-orion5x/ts209-setup.c +2 -1
index c725b7c..7b46830 100644
@@ -318,7 +318,8 @@ static void __init qnap_ts209_init(void)
 	i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);
 
 	/* register tsx09 specific power-off method */
-	pm_power_off = qnap_tsx09_power_off;
+	register_power_off_handler_simple(qnap_tsx09_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 MACHINE_START(TS209, "QNAP TS-109/TS-209")
arch/arm/mach-orion5x/ts409-setup.c +2 -1
index cf2ab53..d36949a 100644
@@ -307,7 +307,8 @@ static void __init qnap_ts409_init(void)
 	platform_device_register(&ts409_leds);
 
 	/* register tsx09 specific power-off method */
-	pm_power_off = qnap_tsx09_power_off;
+	register_power_off_handler_simple(qnap_tsx09_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 MACHINE_START(TS409, "QNAP TS-409")
arch/arm/mach-pxa/corgi.c +2 -1
index 06022b2..82ef5ad 100644
@@ -718,7 +718,8 @@ static void corgi_restart(enum reboot_mode mode, const char *cmd)
 
 static void __init corgi_init(void)
 {
-	pm_power_off = corgi_poweroff;
+	register_power_off_handler_simple(corgi_poweroff,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	/* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
 	PCFR |= PCFR_OPDE;
arch/arm/mach-pxa/mioa701.c +2 -1
index 29997bd..7a29258 100644
@@ -750,7 +750,8 @@ static void __init mioa701_machine_init(void)
 	pxa_set_keypad_info(&mioa701_keypad_info);
 	pxa_set_udc_info(&mioa701_udc_info);
 	pxa_set_ac97_info(&mioa701_ac97_info);
-	pm_power_off = mioa701_poweroff;
+	register_power_off_handler_simple(mioa701_poweroff,
+					  POWEROFF_PRIORITY_FALLBACK);
 	platform_add_devices(devices, ARRAY_SIZE(devices));
 	gsm_init();
 
arch/arm/mach-pxa/poodle.c +2 -1
index 1319916..867b255 100644
@@ -432,7 +432,8 @@ static void __init poodle_init(void)
 {
 	int ret = 0;
 
-	pm_power_off = poodle_poweroff;
+	register_power_off_handler_simple(poodle_poweroff,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	PCFR |= PCFR_OPDE;
 
arch/arm/mach-pxa/spitz.c +2 -1
index 840c3a4..269b74b 100644
@@ -944,7 +944,8 @@ static void spitz_restart(enum reboot_mode mode, const char *cmd)
 static void __init spitz_init(void)
 {
 	init_gpio_reset(SPITZ_GPIO_ON_RESET, 1, 0);
-	pm_power_off = spitz_poweroff;
+	register_power_off_handler_simple(spitz_poweroff,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	PMCR = 0x00;
 
arch/arm/mach-pxa/tosa.c +2 -1
index c158a6e..8f7fd80 100644
@@ -940,7 +940,8 @@ static void __init tosa_init(void)
 
 	init_gpio_reset(TOSA_GPIO_ON_RESET, 0, 0);
 
-	pm_power_off = tosa_poweroff;
+	register_power_off_handler_simple(tosa_poweroff,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	PCFR |= PCFR_OPDE;
 
arch/arm/mach-pxa/viper.c +2 -1
index de3b080..8f8427c 100644
@@ -919,7 +919,8 @@ static void __init viper_init(void)
 {
 	u8 version;
 
-	pm_power_off = viper_power_off;
+	register_power_off_handler_simple(viper_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	pxa2xx_mfp_config(ARRAY_AND_SIZE(viper_pin_config));
 
arch/arm/mach-pxa/z2.c +4 -3
index e1a121b..cefd1bf 100644
@@ -693,8 +693,6 @@ static void z2_power_off(void)
 	pxa27x_set_pwrmode(PWRMODE_DEEPSLEEP);
 	pxa27x_cpu_pm_enter(PM_SUSPEND_MEM);
 }
-#else
-#define z2_power_off   NULL
 #endif
 
 /******************************************************************************
@@ -719,7 +717,10 @@ static void __init z2_init(void)
 	z2_keys_init();
 	z2_pmic_init();
 
-	pm_power_off = z2_power_off;
+#ifdef CONFIG_PM
+	register_power_off_handler_simple(z2_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
+#endif
 }
 
 MACHINE_START(ZIPIT2, "Zipit Z2")
arch/arm/mach-pxa/zeus.c +4 -3
index 205f9bf..651d7b9 100644
@@ -690,8 +690,6 @@ static void zeus_power_off(void)
 	local_irq_disable();
 	cpu_suspend(PWRMODE_DEEPSLEEP, pxa27x_finish_suspend);
 }
-#else
-#define zeus_power_off   NULL
 #endif
 
 #ifdef CONFIG_APM_EMULATION
@@ -847,7 +845,10 @@ static void __init zeus_init(void)
 	__raw_writel(msc0, MSC0);
 	__raw_writel(msc1, MSC1);
 
-	pm_power_off = zeus_power_off;
+#ifdef CONFIG_PM
+	register_power_off_handler_simple(zeus_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
+#endif
 	zeus_setup_apm();
 
 	pxa2xx_mfp_config(ARRAY_AND_SIZE(zeus_pin_config));
arch/arm/mach-s3c24xx/mach-gta02.c +2 -1
index 6d1e0b9..d3659ee 100644
@@ -579,7 +579,8 @@ static void __init gta02_machine_init(void)
 	i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
 
 	platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
-	pm_power_off = gta02_poweroff;
+	register_power_off_handler_simple(gta02_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	regulator_has_full_constraints();
 }
arch/arm/mach-s3c24xx/mach-jive.c +2 -1
index 7d99fe8..1890fc2 100644
@@ -657,7 +657,8 @@ static void __init jive_machine_init(void)
 	s3c_i2c0_set_platdata(&jive_i2c_cfg);
 	i2c_register_board_info(0, jive_i2c_devs, ARRAY_SIZE(jive_i2c_devs));
 
-	pm_power_off = jive_power_off;
+	register_power_off_handler_simple(jive_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	platform_add_devices(jive_devices, ARRAY_SIZE(jive_devices));
 }
arch/arm/mach-s3c24xx/mach-vr1000.c +2 -1
index 89f32bd..8b19864 100644
@@ -306,7 +306,8 @@ static void vr1000_power_off(void)
 
 static void __init vr1000_map_io(void)
 {
-	pm_power_off = vr1000_power_off;
+	register_power_off_handler_simple(vr1000_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	s3c24xx_init_io(vr1000_iodesc, ARRAY_SIZE(vr1000_iodesc));
 	s3c24xx_init_uarts(vr1000_uartcfgs, ARRAY_SIZE(vr1000_uartcfgs));
arch/arm/mach-s3c64xx/mach-smartq.c +2 -1
index b3d1353..7e62e62 100644
@@ -291,7 +291,8 @@ static int __init smartq_power_off_init(void)
 	/* leave power on */
 	gpio_direction_output(S3C64XX_GPK(15), 0);
 
-	pm_power_off = smartq_power_off;
+	register_power_off_handler_simple(smartq_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	return ret;
 }
arch/arm/mach-sa1100/generic.c +2 -1
index d4ea142..23a33d1 100644
@@ -311,7 +311,8 @@ static struct platform_device *sa11x0_devices[] __initdata = {
 
 static int __init sa1100_init(void)
 {
-	pm_power_off = sa1100_power_off;
+	register_power_off_handler_simple(sa1100_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 	return platform_add_devices(sa11x0_devices, ARRAY_SIZE(sa11x0_devices));
 }
 
arch/arm/mach-sa1100/simpad.c +2 -1
index 41e476e..4db57cf 100644
@@ -373,7 +373,8 @@ static int __init simpad_init(void)
 	if (ret)
 		printk(KERN_WARNING "simpad: Unable to register cs3 GPIO device");
 
-	pm_power_off = simpad_power_off;
+	register_power_off_handler_simple(simpad_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	sa11x0_ppc_configure_mcp();
 	sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources,
arch/arm/mach-u300/regulator.c +2 -1
index 0493a84..f8c0fe2 100644
@@ -98,7 +98,8 @@ static int __init __u300_init_boardpower(struct platform_device *pdev)
 			   U300_SYSCON_PMCR_DCON_ENABLE, 0);
 
 	/* Register globally exported PM poweroff hook */
-	pm_power_off = u300_pm_poweroff;
+	register_power_off_handler_simple(u300_pm_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	return 0;
 }
arch/arm/mach-vt8500/vt8500.c +2 -1
index 3bc0dc9..f5b9936 100644
@@ -155,7 +155,8 @@ static void __init vt8500_init(void)
 			pr_err("%s:ioremap(power_off) failed\n", __func__);
 	}
 	if (pmc_base)
-		pm_power_off = &vt8500_power_off;
+		register_power_off_handler_simple(vt8500_power_off,
+						  POWEROFF_PRIORITY_FALLBACK);
 	else
 		pr_err("%s: PMC Hibernation register could not be remapped, not enabling power off!\n", __func__);
 
arch/arm/xen/enlighten.c +2 -1
index 0e15f01..46bd95b 100644
@@ -336,7 +336,8 @@ static int __init xen_pm_init(void)
 	if (!xen_domain())
 		return -ENODEV;
 
-	pm_power_off = xen_power_off;
+	register_power_off_handler_simple(xen_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 	arm_pm_restart = xen_restart;
 
 	return 0;
Signature · 1 line
1.9.1
#84 lore raw

PATCH v2 35/47 arm: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Always use register_power_off_handler_simple as there is no indication that more than one poweroff handler is registered.

If the poweroff handler only resets the system or puts the CPU in sleep mode, select the fallback priority to indicate that the poweroff handler is one of last resort. If the poweroff handler powers off the system, select the default priority.

---
- Use defines to specify poweroff handler priorities
- Drop changes in arch/arm/mach-at91/setup.c (file removed upstream)

 arch/arm/kernel/psci.c                         | 3 ++-
 arch/arm/mach-at91/board-gsia18s.c             | 3 ++-
 arch/arm/mach-bcm/board_bcm2835.c              | 3 ++-
 arch/arm/mach-cns3xxx/cns3420vb.c              | 3 ++-
 arch/arm/mach-cns3xxx/core.c                   | 3 ++-
 arch/arm/mach-highbank/highbank.c              | 3 ++-
 arch/arm/mach-imx/mach-mx31moboard.c           | 3 ++-
 arch/arm/mach-iop32x/em7210.c                  | 3 ++-
 arch/arm/mach-iop32x/glantank.c                | 3 ++-
 arch/arm/mach-iop32x/iq31244.c                 | 3 ++-
 arch/arm/mach-iop32x/n2100.c                   | 3 ++-
 arch/arm/mach-ixp4xx/dsmg600-setup.c           | 3 ++-
 arch/arm/mach-ixp4xx/nas100d-setup.c           | 3 ++-
 arch/arm/mach-ixp4xx/nslu2-setup.c             | 3 ++-
 arch/arm/mach-omap2/board-omap3touchbook.c     | 3 ++-
 arch/arm/mach-orion5x/board-mss2.c             | 3 ++-
 arch/arm/mach-orion5x/dns323-setup.c           | 9 ++++++---
 arch/arm/mach-orion5x/kurobox_pro-setup.c      | 3 ++-
 arch/arm/mach-orion5x/ls-chl-setup.c           | 3 ++-
 arch/arm/mach-orion5x/ls_hgl-setup.c           | 3 ++-
 arch/arm/mach-orion5x/lsmini-setup.c           | 3 ++-
 arch/arm/mach-orion5x/mv2120-setup.c           | 3 ++-
 arch/arm/mach-orion5x/net2big-setup.c          | 3 ++-
 arch/arm/mach-orion5x/terastation_pro2-setup.c | 3 ++-
 arch/arm/mach-orion5x/ts209-setup.c            | 3 ++-
 arch/arm/mach-orion5x/ts409-setup.c            | 3 ++-
 arch/arm/mach-pxa/corgi.c                      | 3 ++-
 arch/arm/mach-pxa/mioa701.c                    | 3 ++-
 arch/arm/mach-pxa/poodle.c                     | 3 ++-
 arch/arm/mach-pxa/spitz.c                      | 3 ++-
 arch/arm/mach-pxa/tosa.c                       | 3 ++-
 arch/arm/mach-pxa/viper.c                      | 3 ++-
 arch/arm/mach-pxa/z2.c                         | 7 ++++---
 arch/arm/mach-pxa/zeus.c                       | 7 ++++---
 arch/arm/mach-s3c24xx/mach-gta02.c             | 3 ++-
 arch/arm/mach-s3c24xx/mach-jive.c              | 3 ++-
 arch/arm/mach-s3c24xx/mach-vr1000.c            | 3 ++-
 arch/arm/mach-s3c64xx/mach-smartq.c            | 3 ++-
 arch/arm/mach-sa1100/generic.c                 | 3 ++-
 arch/arm/mach-sa1100/simpad.c                  | 3 ++-
 arch/arm/mach-u300/regulator.c                 | 3 ++-
 arch/arm/mach-vt8500/vt8500.c                  | 3 ++-
 arch/arm/xen/enlighten.c                       | 3 ++-
 43 files changed, 94 insertions(+), 49 deletions(-)
arch/arm/kernel/psci.c +2 -1
index f73891b..4917c99 100644
@@ -264,7 +264,8 @@ static int psci_0_2_init(struct device_node *np)
 
 	arm_pm_restart = psci_sys_reset;
 
-	pm_power_off = psci_sys_poweroff;
+	register_power_off_handler_simple(psci_sys_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 out_put_node:
 	of_node_put(np);
arch/arm/mach-at91/board-gsia18s.c +2 -1
index bf5cc55..cb5d1c3 100644
@@ -521,7 +521,8 @@ static void gsia18s_power_off(void)
 
 static int __init gsia18s_power_off_init(void)
 {
-	pm_power_off = gsia18s_power_off;
+	register_power_off_handler_simple(gsia18s_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 	return 0;
 }
 
arch/arm/mach-bcm/board_bcm2835.c +2 -1
index 70f2f39..307ebc1 100644
@@ -111,7 +111,8 @@ static void __init bcm2835_init(void)
 
 	bcm2835_setup_restart();
 	if (wdt_regs)
-		pm_power_off = bcm2835_power_off;
+		register_power_off_handler_simple(bcm2835_power_off,
+						  POWEROFF_PRIORITY_FALLBACK);
 
 	bcm2835_init_clocks();
 
arch/arm/mach-cns3xxx/cns3420vb.c +2 -1
index 6428bcc7..3f48979 100644
@@ -224,7 +224,8 @@ static void __init cns3420_init(void)
 	cns3xxx_ahci_init();
 	cns3xxx_sdhci_init();
 
-	pm_power_off = cns3xxx_power_off;
+	register_power_off_handler_simple(cns3xxx_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 static struct map_desc cns3420_io_desc[] __initdata = {
arch/arm/mach-cns3xxx/core.c +2 -1
index 4e9837d..fc0b9e0 100644
@@ -386,7 +386,8 @@ static void __init cns3xxx_init(void)
 		cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(SDIO));
 	}
 
-	pm_power_off = cns3xxx_power_off;
+	register_power_off_handler_simple(cns3xxx_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	of_platform_populate(NULL, of_default_bus_match_table,
                         cns3xxx_auxdata, NULL);
arch/arm/mach-highbank/highbank.c +2 -1
index 8c35ae4..87958f9a 100644
@@ -155,7 +155,8 @@ static void __init highbank_init(void)
 	sregs_base = of_iomap(np, 0);
 	WARN_ON(!sregs_base);
 
-	pm_power_off = highbank_power_off;
+	register_power_off_handler_simple(highbank_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 	highbank_pm_init();
 
 	bus_register_notifier(&platform_bus_type, &highbank_platform_nb);
arch/arm/mach-imx/mach-mx31moboard.c +2 -1
index bb6f8a5..736937b 100644
@@ -559,7 +559,8 @@ static void __init mx31moboard_init(void)
 
 	imx_add_platform_device("imx_mc13783", 0, NULL, 0, NULL, 0);
 
-	pm_power_off = mx31moboard_poweroff;
+	register_power_off_handler_simple(mx31moboard_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	switch (mx31moboard_baseboard) {
 	case MX31NOBOARD:
arch/arm/mach-iop32x/em7210.c +2 -1
index 77e1ff0..8f93266 100644
@@ -201,7 +201,8 @@ static int __init em7210_request_gpios(void)
 		return 0;
 	}
 
-	pm_power_off = em7210_power_off;
+	register_power_off_handler_simple(em7210_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	return 0;
 }
arch/arm/mach-iop32x/glantank.c +2 -1
index 547b234..8d12aa1 100644
@@ -199,7 +199,8 @@ static void __init glantank_init_machine(void)
 	i2c_register_board_info(0, glantank_i2c_devices,
 		ARRAY_SIZE(glantank_i2c_devices));
 
-	pm_power_off = glantank_power_off;
+	register_power_off_handler_simple(glantank_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 MACHINE_START(GLANTANK, "GLAN Tank")
arch/arm/mach-iop32x/iq31244.c +2 -1
index 0e1392b..7c09bbe 100644
@@ -293,7 +293,8 @@ static void __init iq31244_init_machine(void)
 	platform_device_register(&iop3xx_dma_1_channel);
 
 	if (is_ep80219())
-		pm_power_off = ep80219_power_off;
+		register_power_off_handler_simple(ep80219_power_off,
+						  POWEROFF_PRIORITY_DEFAULT);
 
 	if (!is_80219())
 		platform_device_register(&iop3xx_aau_channel);
arch/arm/mach-iop32x/n2100.c +2 -1
index c1cd80e..ee949c5 100644
@@ -356,7 +356,8 @@ static void __init n2100_init_machine(void)
 	i2c_register_board_info(0, n2100_i2c_devices,
 		ARRAY_SIZE(n2100_i2c_devices));
 
-	pm_power_off = n2100_power_off;
+	register_power_off_handler_simple(n2100_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 MACHINE_START(N2100, "Thecus N2100")
arch/arm/mach-ixp4xx/dsmg600-setup.c +2 -1
index 43ee06d..ae3dafa 100644
@@ -281,7 +281,8 @@ static void __init dsmg600_init(void)
 
 	platform_add_devices(dsmg600_devices, ARRAY_SIZE(dsmg600_devices));
 
-	pm_power_off = dsmg600_power_off;
+	register_power_off_handler_simple(dsmg600_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 MACHINE_START(DSMG600, "D-Link DSM-G600 RevA")
arch/arm/mach-ixp4xx/nas100d-setup.c +2 -1
index 4e0f762..a8062db 100644
@@ -292,7 +292,8 @@ static void __init nas100d_init(void)
 
 	platform_add_devices(nas100d_devices, ARRAY_SIZE(nas100d_devices));
 
-	pm_power_off = nas100d_power_off;
+	register_power_off_handler_simple(nas100d_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	if (request_irq(gpio_to_irq(NAS100D_RB_GPIO), &nas100d_reset_handler,
 		IRQF_TRIGGER_LOW, "NAS100D reset button", NULL) < 0) {
arch/arm/mach-ixp4xx/nslu2-setup.c +2 -1
index 88c025f..a95f727 100644
@@ -262,7 +262,8 @@ static void __init nslu2_init(void)
 
 	platform_add_devices(nslu2_devices, ARRAY_SIZE(nslu2_devices));
 
-	pm_power_off = nslu2_power_off;
+	register_power_off_handler_simple(nslu2_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	if (request_irq(gpio_to_irq(NSLU2_RB_GPIO), &nslu2_reset_handler,
 		IRQF_TRIGGER_LOW, "NSLU2 reset button", NULL) < 0) {
arch/arm/mach-omap2/board-omap3touchbook.c +2 -1
index a01993e..22347b8 100644
@@ -344,7 +344,8 @@ static void __init omap3_touchbook_init(void)
 {
 	omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
 
-	pm_power_off = omap3_touchbook_poweroff;
+	register_power_off_handler_simple(omap3_touchbook_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	if (system_rev >= 0x20 && system_rev <= 0x34301000) {
 		omap_mux_init_gpio(23, OMAP_PIN_INPUT);
arch/arm/mach-orion5x/board-mss2.c +2 -1
index 66f9c3b..7b46868 100644
@@ -86,5 +86,6 @@ static void mss2_power_off(void)
 void __init mss2_init(void)
 {
 	/* register mss2 specific power-off method */
-	pm_power_off = mss2_power_off;
+	register_power_off_handler_simple(mss2_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 }
arch/arm/mach-orion5x/dns323-setup.c +6 -3
index 09d2a26..979c696 100644
@@ -669,7 +669,8 @@ static void __init dns323_init(void)
 		if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
 		    gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
 			pr_err("DNS-323: failed to setup power-off GPIO\n");
-		pm_power_off = dns323a_power_off;
+		register_power_off_handler_simple(dns323a_power_off,
+						  POWEROFF_PRIORITY_DEFAULT);
 		break;
 	case DNS323_REV_B1:
 		/* 5182 built-in SATA init */
@@ -686,7 +687,8 @@ static void __init dns323_init(void)
 		if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
 		    gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
 			pr_err("DNS-323: failed to setup power-off GPIO\n");
-		pm_power_off = dns323b_power_off;
+		register_power_off_handler_simple(dns323b_power_off,
+						  POWEROFF_PRIORITY_DEFAULT);
 		break;
 	case DNS323_REV_C1:
 		/* 5182 built-in SATA init */
@@ -696,7 +698,8 @@ static void __init dns323_init(void)
 		if (gpio_request(DNS323C_GPIO_POWER_OFF, "POWEROFF") != 0 ||
 		    gpio_direction_output(DNS323C_GPIO_POWER_OFF, 0) != 0)
 			pr_err("DNS-323: failed to setup power-off GPIO\n");
-		pm_power_off = dns323c_power_off;
+		register_power_off_handler_simple(dns323c_power_off,
+						  POWEROFF_PRIORITY_DEFAULT);
 
 		/* Now, -this- should theorically be done by the sata_mv driver
 		 * once I figure out what's going on there. Maybe the behaviour
arch/arm/mach-orion5x/kurobox_pro-setup.c +2 -1
index fe6a48a..1004d2ad 100644
@@ -376,7 +376,8 @@ static void __init kurobox_pro_init(void)
 	i2c_register_board_info(0, &kurobox_pro_i2c_rtc, 1);
 
 	/* register Kurobox Pro specific power-off method */
-	pm_power_off = kurobox_pro_power_off;
+	register_power_off_handler_simple(kurobox_pro_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 #ifdef CONFIG_MACH_KUROBOX_PRO
arch/arm/mach-orion5x/ls-chl-setup.c +2 -1
index 028ea03..b1e161a 100644
@@ -312,7 +312,8 @@ static void __init lschl_init(void)
 	gpio_set_value(LSCHL_GPIO_USB_POWER, 1);
 
 	/* register power-off method */
-	pm_power_off = lschl_power_off;
+	register_power_off_handler_simple(lschl_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	pr_info("%s: finished\n", __func__);
 }
arch/arm/mach-orion5x/ls_hgl-setup.c +2 -1
index 32b7129..c77e5a0 100644
@@ -259,7 +259,8 @@ static void __init ls_hgl_init(void)
 	gpio_set_value(LS_HGL_GPIO_USB_POWER, 1);
 
 	/* register power-off method */
-	pm_power_off = ls_hgl_power_off;
+	register_power_off_handler_simple(ls_hgl_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	pr_info("%s: finished\n", __func__);
 }
arch/arm/mach-orion5x/lsmini-setup.c +2 -1
index a6493e7..9235353 100644
@@ -260,7 +260,8 @@ static void __init lsmini_init(void)
 	gpio_set_value(LSMINI_GPIO_USB_POWER, 1);
 
 	/* register power-off method */
-	pm_power_off = lsmini_power_off;
+	register_power_off_handler_simple(lsmini_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	pr_info("%s: finished\n", __func__);
 }
arch/arm/mach-orion5x/mv2120-setup.c +2 -1
index e032f01..897f1f6 100644
@@ -225,7 +225,8 @@ static void __init mv2120_init(void)
 	if (gpio_request(MV2120_GPIO_POWER_OFF, "POWEROFF") != 0 ||
 	    gpio_direction_output(MV2120_GPIO_POWER_OFF, 1) != 0)
 		pr_err("mv2120: failed to setup power-off GPIO\n");
-	pm_power_off = mv2120_power_off;
+	register_power_off_handler_simple(mv2120_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 /* Warning: HP uses a wrong mach-type (=526) in their bootloader */
arch/arm/mach-orion5x/net2big-setup.c +2 -1
index ba73dc7..f783ad7 100644
@@ -413,7 +413,8 @@ static void __init net2big_init(void)
 
 	if (gpio_request(NET2BIG_GPIO_POWER_OFF, "power-off") == 0 &&
 	    gpio_direction_output(NET2BIG_GPIO_POWER_OFF, 0) == 0)
-		pm_power_off = net2big_power_off;
+		register_power_off_handler_simple(net2big_power_off,
+						  POWEROFF_PRIORITY_DEFAULT);
 	else
 		pr_err("net2big: failed to configure power-off GPIO\n");
 
arch/arm/mach-orion5x/terastation_pro2-setup.c +2 -1
index 1208674..4c16209 100644
@@ -353,7 +353,8 @@ static void __init tsp2_init(void)
 	i2c_register_board_info(0, &tsp2_i2c_rtc, 1);
 
 	/* register Terastation Pro II specific power-off method */
-	pm_power_off = tsp2_power_off;
+	register_power_off_handler_simple(tsp2_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 MACHINE_START(TERASTATION_PRO2, "Buffalo Terastation Pro II/Live")
arch/arm/mach-orion5x/ts209-setup.c +2 -1
index c725b7c..7b46830 100644
@@ -318,7 +318,8 @@ static void __init qnap_ts209_init(void)
 	i2c_register_board_info(0, &qnap_ts209_i2c_rtc, 1);
 
 	/* register tsx09 specific power-off method */
-	pm_power_off = qnap_tsx09_power_off;
+	register_power_off_handler_simple(qnap_tsx09_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 MACHINE_START(TS209, "QNAP TS-109/TS-209")
arch/arm/mach-orion5x/ts409-setup.c +2 -1
index cf2ab53..d36949a 100644
@@ -307,7 +307,8 @@ static void __init qnap_ts409_init(void)
 	platform_device_register(&ts409_leds);
 
 	/* register tsx09 specific power-off method */
-	pm_power_off = qnap_tsx09_power_off;
+	register_power_off_handler_simple(qnap_tsx09_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
 
 MACHINE_START(TS409, "QNAP TS-409")
arch/arm/mach-pxa/corgi.c +2 -1
index 06022b2..82ef5ad 100644
@@ -718,7 +718,8 @@ static void corgi_restart(enum reboot_mode mode, const char *cmd)
 
 static void __init corgi_init(void)
 {
-	pm_power_off = corgi_poweroff;
+	register_power_off_handler_simple(corgi_poweroff,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	/* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
 	PCFR |= PCFR_OPDE;
arch/arm/mach-pxa/mioa701.c +2 -1
index 29997bd..7a29258 100644
@@ -750,7 +750,8 @@ static void __init mioa701_machine_init(void)
 	pxa_set_keypad_info(&mioa701_keypad_info);
 	pxa_set_udc_info(&mioa701_udc_info);
 	pxa_set_ac97_info(&mioa701_ac97_info);
-	pm_power_off = mioa701_poweroff;
+	register_power_off_handler_simple(mioa701_poweroff,
+					  POWEROFF_PRIORITY_FALLBACK);
 	platform_add_devices(devices, ARRAY_SIZE(devices));
 	gsm_init();
 
arch/arm/mach-pxa/poodle.c +2 -1
index 1319916..867b255 100644
@@ -432,7 +432,8 @@ static void __init poodle_init(void)
 {
 	int ret = 0;
 
-	pm_power_off = poodle_poweroff;
+	register_power_off_handler_simple(poodle_poweroff,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	PCFR |= PCFR_OPDE;
 
arch/arm/mach-pxa/spitz.c +2 -1
index 840c3a4..269b74b 100644
@@ -944,7 +944,8 @@ static void spitz_restart(enum reboot_mode mode, const char *cmd)
 static void __init spitz_init(void)
 {
 	init_gpio_reset(SPITZ_GPIO_ON_RESET, 1, 0);
-	pm_power_off = spitz_poweroff;
+	register_power_off_handler_simple(spitz_poweroff,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	PMCR = 0x00;
 
arch/arm/mach-pxa/tosa.c +2 -1
index c158a6e..8f7fd80 100644
@@ -940,7 +940,8 @@ static void __init tosa_init(void)
 
 	init_gpio_reset(TOSA_GPIO_ON_RESET, 0, 0);
 
-	pm_power_off = tosa_poweroff;
+	register_power_off_handler_simple(tosa_poweroff,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	PCFR |= PCFR_OPDE;
 
arch/arm/mach-pxa/viper.c +2 -1
index de3b080..8f8427c 100644
@@ -919,7 +919,8 @@ static void __init viper_init(void)
 {
 	u8 version;
 
-	pm_power_off = viper_power_off;
+	register_power_off_handler_simple(viper_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	pxa2xx_mfp_config(ARRAY_AND_SIZE(viper_pin_config));
 
arch/arm/mach-pxa/z2.c +4 -3
index e1a121b..cefd1bf 100644
@@ -693,8 +693,6 @@ static void z2_power_off(void)
 	pxa27x_set_pwrmode(PWRMODE_DEEPSLEEP);
 	pxa27x_cpu_pm_enter(PM_SUSPEND_MEM);
 }
-#else
-#define z2_power_off   NULL
 #endif
 
 /******************************************************************************
@@ -719,7 +717,10 @@ static void __init z2_init(void)
 	z2_keys_init();
 	z2_pmic_init();
 
-	pm_power_off = z2_power_off;
+#ifdef CONFIG_PM
+	register_power_off_handler_simple(z2_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
+#endif
 }
 
 MACHINE_START(ZIPIT2, "Zipit Z2")
arch/arm/mach-pxa/zeus.c +4 -3
index 205f9bf..651d7b9 100644
@@ -690,8 +690,6 @@ static void zeus_power_off(void)
 	local_irq_disable();
 	cpu_suspend(PWRMODE_DEEPSLEEP, pxa27x_finish_suspend);
 }
-#else
-#define zeus_power_off   NULL
 #endif
 
 #ifdef CONFIG_APM_EMULATION
@@ -847,7 +845,10 @@ static void __init zeus_init(void)
 	__raw_writel(msc0, MSC0);
 	__raw_writel(msc1, MSC1);
 
-	pm_power_off = zeus_power_off;
+#ifdef CONFIG_PM
+	register_power_off_handler_simple(zeus_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
+#endif
 	zeus_setup_apm();
 
 	pxa2xx_mfp_config(ARRAY_AND_SIZE(zeus_pin_config));
arch/arm/mach-s3c24xx/mach-gta02.c +2 -1
index 6d1e0b9..d3659ee 100644
@@ -579,7 +579,8 @@ static void __init gta02_machine_init(void)
 	i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
 
 	platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
-	pm_power_off = gta02_poweroff;
+	register_power_off_handler_simple(gta02_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	regulator_has_full_constraints();
 }
arch/arm/mach-s3c24xx/mach-jive.c +2 -1
index 7d99fe8..1890fc2 100644
@@ -657,7 +657,8 @@ static void __init jive_machine_init(void)
 	s3c_i2c0_set_platdata(&jive_i2c_cfg);
 	i2c_register_board_info(0, jive_i2c_devs, ARRAY_SIZE(jive_i2c_devs));
 
-	pm_power_off = jive_power_off;
+	register_power_off_handler_simple(jive_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	platform_add_devices(jive_devices, ARRAY_SIZE(jive_devices));
 }
arch/arm/mach-s3c24xx/mach-vr1000.c +2 -1
index 89f32bd..8b19864 100644
@@ -306,7 +306,8 @@ static void vr1000_power_off(void)
 
 static void __init vr1000_map_io(void)
 {
-	pm_power_off = vr1000_power_off;
+	register_power_off_handler_simple(vr1000_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	s3c24xx_init_io(vr1000_iodesc, ARRAY_SIZE(vr1000_iodesc));
 	s3c24xx_init_uarts(vr1000_uartcfgs, ARRAY_SIZE(vr1000_uartcfgs));
arch/arm/mach-s3c64xx/mach-smartq.c +2 -1
index b3d1353..7e62e62 100644
@@ -291,7 +291,8 @@ static int __init smartq_power_off_init(void)
 	/* leave power on */
 	gpio_direction_output(S3C64XX_GPK(15), 0);
 
-	pm_power_off = smartq_power_off;
+	register_power_off_handler_simple(smartq_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	return ret;
 }
arch/arm/mach-sa1100/generic.c +2 -1
index d4ea142..23a33d1 100644
@@ -311,7 +311,8 @@ static struct platform_device *sa11x0_devices[] __initdata = {
 
 static int __init sa1100_init(void)
 {
-	pm_power_off = sa1100_power_off;
+	register_power_off_handler_simple(sa1100_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 	return platform_add_devices(sa11x0_devices, ARRAY_SIZE(sa11x0_devices));
 }
 
arch/arm/mach-sa1100/simpad.c +2 -1
index 41e476e..4db57cf 100644
@@ -373,7 +373,8 @@ static int __init simpad_init(void)
 	if (ret)
 		printk(KERN_WARNING "simpad: Unable to register cs3 GPIO device");
 
-	pm_power_off = simpad_power_off;
+	register_power_off_handler_simple(simpad_power_off,
+					  POWEROFF_PRIORITY_FALLBACK);
 
 	sa11x0_ppc_configure_mcp();
 	sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources,
arch/arm/mach-u300/regulator.c +2 -1
index 0493a84..f8c0fe2 100644
@@ -98,7 +98,8 @@ static int __init __u300_init_boardpower(struct platform_device *pdev)
 			   U300_SYSCON_PMCR_DCON_ENABLE, 0);
 
 	/* Register globally exported PM poweroff hook */
-	pm_power_off = u300_pm_poweroff;
+	register_power_off_handler_simple(u300_pm_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	return 0;
 }
arch/arm/mach-vt8500/vt8500.c +2 -1
index 3bc0dc9..f5b9936 100644
@@ -155,7 +155,8 @@ static void __init vt8500_init(void)
 			pr_err("%s:ioremap(power_off) failed\n", __func__);
 	}
 	if (pmc_base)
-		pm_power_off = &vt8500_power_off;
+		register_power_off_handler_simple(vt8500_power_off,
+						  POWEROFF_PRIORITY_FALLBACK);
 	else
 		pr_err("%s: PMC Hibernation register could not be remapped, not enabling power off!\n", __func__);
 
arch/arm/xen/enlighten.c +2 -1
index 0e15f01..46bd95b 100644
@@ -336,7 +336,8 @@ static int __init xen_pm_init(void)
 	if (!xen_domain())
 		return -ENODEV;
 
-	pm_power_off = xen_power_off;
+	register_power_off_handler_simple(xen_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 	arm_pm_restart = xen_restart;
 
 	return 0;
Signature · 1 line
1.9.1
#85 lore raw

PATCH v2 36/47 arm64: psci: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>

---
- Use define to specify poweroff handler priority

 arch/arm64/kernel/psci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/psci.c +2 -1
index 866c1c8..150ac1c 100644
@@ -359,7 +359,8 @@ static int __init psci_0_2_init(struct device_node *np)
 
 	arm_pm_restart = psci_sys_reset;
 
-	pm_power_off = psci_sys_poweroff;
+	register_power_off_handler_simple(psci_sys_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 out_put_node:
 	of_node_put(np);
Signature · 1 line
1.9.1
reviewer Tested-by on v2 36/47
#88 lore raw

Re: [PATCH v2 36/47] arm64: psci: Register with kernel poweroff handler

In reply to Guenter Roeck
Quoted 6 lines · Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>

My Juno board powers down correctly with this applied, so:

Thanks,
Mark.

Quoted 29 lines

---
- Use define to specify poweroff handler priority

 arch/arm64/kernel/psci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kernel/psci.c +2 -1
index 866c1c8..150ac1c 100644
@@ -359,7 +359,8 @@ static int __init psci_0_2_init(struct device_node *np)
 
 	arm_pm_restart = psci_sys_reset;
 
-	pm_power_off = psci_sys_poweroff;
+	register_power_off_handler_simple(psci_sys_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 out_put_node:
 	of_node_put(np);
Signature · 7 lines
1.9.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#89 lore raw

Re: [PATCH v2 36/47] arm64: psci: Register with kernel poweroff handler

Quoted 4 lines · Mark Rutland
Quoted 3 lines · Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly.

Quoted 8 lines
Quoted 3 lines
Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>

My Juno board powers down correctly with this applied, so:

Thanks a lot!

Guenter

#90 lore raw

PATCH v2 37/47 avr32: atngw100: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly.

Cc Haavard Skinnemoen <[email protected]>
Cc Hans-Christian Egtvedt <[email protected]>

---
- Use define to specify poweroff handler priority

 arch/avr32/boards/atngw100/mrmt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/avr32/boards/atngw100/mrmt.c +2 -1
index 91146b4..833212e 100644
@@ -274,7 +274,8 @@ static int __init mrmt1_init(void)
 {
 	gpio_set_value( PIN_PWR_ON, 1 );	/* Ensure PWR_ON is enabled */
 
-	pm_power_off = mrmt_power_off;
+	register_power_off_handler_simple(mrmt_power_off,
+					  POWEROFF_PRIORITY_DEFAULT);
 
 	/* Setup USARTS (other than console) */
 	at32_map_usart(2, 1, 0);	/* USART 2: /dev/ttyS1, RMT1:DB9M */
Signature · 1 line
1.9.1
#91 lore raw

PATCH v2 38/47 ia64: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly. Register with low priority to reflect that the call is expected to be replaced at some point in the future.

---
- Use define to specify poweroff handler priority

 arch/ia64/sn/kernel/setup.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/ia64/sn/kernel/setup.c +3 -2
index 5f6b6b4..1888aeb 100644
@@ -488,12 +488,13 @@ void __init sn_setup(char **cmdline_p)
 	sn_timer_init();
 
 	/*
-	 * set pm_power_off to a SAL call to allow
+	 * set poweroff handler to a SAL call to allow
 	 * sn machines to power off. The SAL call can be replaced
 	 * by an ACPI interface call when ACPI is fully implemented
 	 * for sn.
 	 */
-	pm_power_off = ia64_sn_power_down;
+	register_power_off_handler_simple(ia64_sn_power_down,
+					  POWEROFF_PRIORITY_LOW);
 	current->thread.flags |= IA64_THREAD_MIGRATION;
 }
 
Signature · 1 line
1.9.1
#92 lore raw

PATCH v2 39/47 m68k: Register with kernel poweroff handler

In reply to Guenter Roeck

Register with kernel poweroff handler instead of setting pm_power_off directly.

---
- Use defines to specify poweroff handler priorities

 arch/m68k/emu/natfeat.c | 3 ++-
 arch/m68k/mac/config.c  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
arch/m68k/emu/natfeat.c +2 -1
index 91e2ae7..b105681 100644
@@ -91,5 +91,6 @@ void __init nf_init(void)
 	pr_info("NatFeats found (%s, %lu.%lu)\n", buf, version >> 16,
 		version & 0xffff);
 
-	pm_power_off = nf_poweroff;
+	register_power_off_handler_simple(nf_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 }
arch/m68k/mac/config.c +2 -1
index 677913ff..07e853e 100644
@@ -160,7 +160,8 @@ void __init config_mac(void)
 	mach_set_clock_mmss = mac_set_clock_mmss;
 	mach_reset = mac_reset;
 	mach_halt = mac_poweroff;
-	pm_power_off = mac_poweroff;
+	register_power_off_handler_simple(mac_poweroff,
+					  POWEROFF_PRIORITY_DEFAULT);
 	mach_max_dma_address = 0xffffffff;
 #if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
 	mach_beep = mac_mksound;
Signature · 1 line
1.9.1