linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/45] Introduce power-off+restart call chain API
@ 2021-10-27 21:16 Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 01/45] notifier: Remove extern annotation from function prototypes Dmitry Osipenko
                   ` (40 more replies)
  0 siblings, 41 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Problem
-------

SoC devices require power-off call chaining functionality from kernel.
We have a widely used restart chaining provided by restart notifier API,
but nothing for power-off.

Solution
--------

Introduce new API that provides both restart and power-off call chains.

Why combine restart with power-off? Because drivers often do both.
More practical to have API that provides both under the same roof.

The new API is designed with simplicity and extensibility in mind.
It's built upon the existing restart and reboot APIs. The simplicity
is in new helper functions that are convenient for drivers. The
extensibility is in the design that doesn't hardcode callback
arguments, making easy to add new parameters and remove old.

This is a third attempt to introduce the new API. First was made by
Guenter Roeck back in 2014, second was made by Thierry Reding in 2017.
In fact the work didn't stop and recently arm_pm_restart() was removed
from v5.14 kernel, which was a part of preparatory work started by
Guenter Roeck. I took into account experience and ideas from the
previous attempts, extended and polished them.

Adoption plan
-------------

This patchset introduces the new API. It also converts multiple drivers
and arch code to the new API to demonstrate how it all looks in practice.

The plan is:

1. Merge new API (patches 1-8). This API will co-exist with the old APIs.

2. Convert arch code to do_kernel_power_off() (patches 9-21).

3. Convert drivers and platform code to the new API.

4. Remove obsolete pm_power_off and pm_power_off_prepare variables.

5. Make restart-notifier API private to kernel/reboot.c once no users left.

Results
-------

1. Devices can be powered off properly.

2. Global variables are removed from drivers.

3. Global pm_power_off and pm_power_off_prepare callback variables are
removed once all users are converted to the new API. The latter callback
is removed by patch #25 of this series.

4. Ambiguous call chain ordering is prohibited. See patch #5 which adds
verification of restart handlers priorities, ensuring that they are unique.

Changelog:

v2: - Replaced standalone power-off call chain demo-API with the combined
      power-off+restart API because this is what drivers want. It's a more
      comprehensive solution.

    - Converted multiple drivers and arch code to the new API. Suggested by
      Andy Shevchenko. I skimmed through the rest of drivers, verifying that
      new API suits them. The rest of the drivers will be converted once we
      will settle on the new API, otherwise will be too many patches here.

    - v2 API doesn't expose notifier to users and require handlers to
      have unique priority. Suggested by Guenter Roeck.

    - v2 API has power-off chaining disabled by default and require
      drivers to explicitly opt-in to the chaining. This preserves old
      behaviour for existing drivers once they are converted to the new
      API.

Dmitry Osipenko (45):
  notifier: Remove extern annotation from function prototypes
  notifier: Add blocking_notifier_call_chain_empty()
  notifier: Add atomic/blocking_notifier_has_unique_priority()
  reboot: Correct typo in a comment
  reboot: Warn if restart handler has duplicated priority
  reboot: Warn if unregister_restart_handler() fails
  reboot: Remove extern annotation from function prototypes
  kernel: Add combined power-off+restart handler call chain API
  xen/x86: Use do_kernel_power_off()
  ARM: Use do_kernel_power_off()
  arm64: Use do_kernel_power_off()
  csky: Use do_kernel_power_off()
  ia64: Use do_kernel_power_off()
  mips: Use do_kernel_power_off()
  nds32: Use do_kernel_power_off()
  parisc: Use do_kernel_power_off()
  powerpc: Use do_kernel_power_off()
  riscv: Use do_kernel_power_off()
  sh: Use do_kernel_power_off()
  x86: Use do_kernel_power_off()
  m68k: Switch to new power-handler API
  memory: emif: Use kernel_can_power_off()
  ACPI: power: Switch to power-handler API
  regulator: pfuze100: Use devm_register_power_handler()
  reboot: Remove pm_power_off_prepare()
  soc/tegra: pmc: Utilize power-handler API to power off Nexus 7
    properly
  mfd: ntxec: Use devm_register_power_handler()
  mfd: rn5t618: Use devm_register_power_handler()
  mfd: acer-a500: Use devm_register_power_handler()
  mfd: ene-kb3930: Use devm_register_power_handler()
  mfd: axp20x: Use register_simple_power_off_handler()
  mfd: retu: Use devm_register_simple_power_off_handler()
  mfd: rk808: Use devm_register_simple_power_off_handler()
  mfd: palmas: Use devm_register_simple_power_off_handler()
  mfd: max8907: Use devm_register_simple_power_off_handler()
  mfd: tps6586x: Use devm_register_simple_power_off_handler()
  mfd: tps65910: Use devm_register_simple_power_off_handler()
  mfd: max77620: Use devm_register_simple_power_off_handler()
  mfd: dm355evm_msp: Use devm_register_trivial_power_off_handler()
  mfd: twl4030: Use devm_register_trivial_power_off_handler()
  mfd: ab8500: Use devm_register_trivial_power_off_handler()
  reset: ath79: Use devm_register_simple_restart_handler()
  reset: intel-gw: Use devm_register_simple_restart_handler()
  reset: lpc18xx: Use devm_register_prioritized_restart_handler()
  reset: npcm: Use devm_register_prioritized_restart_handler()

 arch/arm/kernel/reboot.c               |   4 +-
 arch/arm64/kernel/process.c            |   3 +-
 arch/csky/kernel/power.c               |   6 +-
 arch/ia64/kernel/process.c             |   4 +-
 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                 |   4 +-
 arch/mips/kernel/reset.c               |   3 +-
 arch/nds32/kernel/process.c            |   3 +-
 arch/parisc/kernel/process.c           |   4 +-
 arch/powerpc/kernel/setup-common.c     |   4 +-
 arch/powerpc/xmon/xmon.c               |   3 +-
 arch/riscv/kernel/reset.c              |  12 +-
 arch/sh/kernel/reboot.c                |   3 +-
 arch/x86/kernel/reboot.c               |   4 +-
 arch/x86/xen/enlighten_pv.c            |   4 +-
 drivers/acpi/sleep.c                   |  25 +-
 drivers/memory/emif.c                  |   2 +-
 drivers/mfd/ab8500-sysctrl.c           |  17 +-
 drivers/mfd/acer-ec-a500.c             |  52 +--
 drivers/mfd/axp20x.c                   |  22 +-
 drivers/mfd/dm355evm_msp.c             |  20 +-
 drivers/mfd/ene-kb3930.c               |  45 +-
 drivers/mfd/max77620.c                 |  21 +-
 drivers/mfd/max8907.c                  |  22 +-
 drivers/mfd/ntxec.c                    |  50 +-
 drivers/mfd/palmas.c                   |  24 +-
 drivers/mfd/retu-mfd.c                 |  31 +-
 drivers/mfd/rk808.c                    |  23 +-
 drivers/mfd/rn5t618.c                  |  56 +--
 drivers/mfd/tps6586x.c                 |  21 +-
 drivers/mfd/tps65910.c                 |  17 +-
 drivers/mfd/twl4030-power.c            |  10 +-
 drivers/regulator/pfuze100-regulator.c |  39 +-
 drivers/reset/reset-ath79.c            |  15 +-
 drivers/reset/reset-intel-gw.c         |  13 +-
 drivers/reset/reset-lpc18xx.c          |  14 +-
 drivers/reset/reset-npcm.c             |  14 +-
 drivers/soc/tegra/pmc.c                |  54 ++-
 include/linux/mfd/axp20x.h             |   1 +
 include/linux/notifier.h               |  37 +-
 include/linux/pm.h                     |   1 -
 include/linux/reboot.h                 | 216 ++++++++-
 kernel/notifier.c                      |  88 ++++
 kernel/power/hibernate.c               |   2 +-
 kernel/reboot.c                        | 615 ++++++++++++++++++++++++-
 49 files changed, 1209 insertions(+), 430 deletions(-)

-- 
2.33.1


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

* [PATCH v2 01/45] notifier: Remove extern annotation from function prototypes
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 02/45] notifier: Add blocking_notifier_call_chain_empty() Dmitry Osipenko
                   ` (39 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

There is no need to annotate function prototypes with 'extern', it makes
code less readable. Remove unnecessary annotations from <notifier.h>.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 include/linux/notifier.h | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/include/linux/notifier.h b/include/linux/notifier.h
index 87069b8459af..4b80a815b666 100644
--- a/include/linux/notifier.h
+++ b/include/linux/notifier.h
@@ -90,7 +90,7 @@ struct srcu_notifier_head {
 	} while (0)
 
 /* srcu_notifier_heads must be cleaned up dynamically */
-extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
+void srcu_init_notifier_head(struct srcu_notifier_head *nh);
 #define srcu_cleanup_notifier_head(name)	\
 		cleanup_srcu_struct(&(name)->srcu);
 
@@ -141,36 +141,36 @@ extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
 
 #ifdef __KERNEL__
 
-extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
+int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
 		struct notifier_block *nb);
-extern int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
+int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
 		struct notifier_block *nb);
-extern int raw_notifier_chain_register(struct raw_notifier_head *nh,
+int raw_notifier_chain_register(struct raw_notifier_head *nh,
 		struct notifier_block *nb);
-extern int srcu_notifier_chain_register(struct srcu_notifier_head *nh,
+int srcu_notifier_chain_register(struct srcu_notifier_head *nh,
 		struct notifier_block *nb);
 
-extern int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
+int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
 		struct notifier_block *nb);
-extern int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh,
+int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh,
 		struct notifier_block *nb);
-extern int raw_notifier_chain_unregister(struct raw_notifier_head *nh,
+int raw_notifier_chain_unregister(struct raw_notifier_head *nh,
 		struct notifier_block *nb);
-extern int srcu_notifier_chain_unregister(struct srcu_notifier_head *nh,
+int srcu_notifier_chain_unregister(struct srcu_notifier_head *nh,
 		struct notifier_block *nb);
 
-extern int atomic_notifier_call_chain(struct atomic_notifier_head *nh,
+int atomic_notifier_call_chain(struct atomic_notifier_head *nh,
 		unsigned long val, void *v);
-extern int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
+int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
 		unsigned long val, void *v);
-extern int raw_notifier_call_chain(struct raw_notifier_head *nh,
+int raw_notifier_call_chain(struct raw_notifier_head *nh,
 		unsigned long val, void *v);
-extern int srcu_notifier_call_chain(struct srcu_notifier_head *nh,
+int srcu_notifier_call_chain(struct srcu_notifier_head *nh,
 		unsigned long val, void *v);
 
-extern int blocking_notifier_call_chain_robust(struct blocking_notifier_head *nh,
+int blocking_notifier_call_chain_robust(struct blocking_notifier_head *nh,
 		unsigned long val_up, unsigned long val_down, void *v);
-extern int raw_notifier_call_chain_robust(struct raw_notifier_head *nh,
+int raw_notifier_call_chain_robust(struct raw_notifier_head *nh,
 		unsigned long val_up, unsigned long val_down, void *v);
 
 #define NOTIFY_DONE		0x0000		/* Don't care */
-- 
2.33.1


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

* [PATCH v2 02/45] notifier: Add blocking_notifier_call_chain_empty()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 01/45] notifier: Remove extern annotation from function prototypes Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 03/45] notifier: Add atomic/blocking_notifier_has_unique_priority() Dmitry Osipenko
                   ` (38 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Add blocking_notifier_call_chain_empty() that returns true if call chain
is empty.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 include/linux/notifier.h |  2 ++
 kernel/notifier.c        | 14 ++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/include/linux/notifier.h b/include/linux/notifier.h
index 4b80a815b666..054271e9cb20 100644
--- a/include/linux/notifier.h
+++ b/include/linux/notifier.h
@@ -173,6 +173,8 @@ int blocking_notifier_call_chain_robust(struct blocking_notifier_head *nh,
 int raw_notifier_call_chain_robust(struct raw_notifier_head *nh,
 		unsigned long val_up, unsigned long val_down, void *v);
 
+bool blocking_notifier_call_chain_empty(struct blocking_notifier_head *nh);
+
 #define NOTIFY_DONE		0x0000		/* Don't care */
 #define NOTIFY_OK		0x0001		/* Suits me */
 #define NOTIFY_STOP_MASK	0x8000		/* Don't call further */
diff --git a/kernel/notifier.c b/kernel/notifier.c
index b8251dc0bc0f..1f7ba8988b90 100644
--- a/kernel/notifier.c
+++ b/kernel/notifier.c
@@ -322,6 +322,20 @@ int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
 }
 EXPORT_SYMBOL_GPL(blocking_notifier_call_chain);
 
+/**
+ *	blocking_notifier_call_chain_empty - Check whether notifier chain is empty
+ *	@nh: Pointer to head of the blocking notifier chain
+ *
+ *	Checks whether notifier chain is empty.
+ *
+ *	Returns true is notifier chain is empty, false otherwise.
+ */
+bool blocking_notifier_call_chain_empty(struct blocking_notifier_head *nh)
+{
+	return !rcu_access_pointer(nh->head);
+}
+EXPORT_SYMBOL_GPL(blocking_notifier_call_chain_empty);
+
 /*
  *	Raw notifier chain routines.  There is no protection;
  *	the caller must provide it.  Use at your own risk!
-- 
2.33.1


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

* [PATCH v2 03/45] notifier: Add atomic/blocking_notifier_has_unique_priority()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 01/45] notifier: Remove extern annotation from function prototypes Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 02/45] notifier: Add blocking_notifier_call_chain_empty() Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-28 11:00   ` Andy Shevchenko
  2021-10-27 21:16 ` [PATCH v2 04/45] reboot: Correct typo in a comment Dmitry Osipenko
                   ` (37 subsequent siblings)
  40 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Add atomic/blocking_notifier_has_unique_priority() helpers which return
true if given handler has unique priority.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 include/linux/notifier.h |  5 +++
 kernel/notifier.c        | 74 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+)

diff --git a/include/linux/notifier.h b/include/linux/notifier.h
index 054271e9cb20..b782ce100022 100644
--- a/include/linux/notifier.h
+++ b/include/linux/notifier.h
@@ -175,6 +175,11 @@ int raw_notifier_call_chain_robust(struct raw_notifier_head *nh,
 
 bool blocking_notifier_call_chain_empty(struct blocking_notifier_head *nh);
 
+bool atomic_notifier_has_unique_priority(struct atomic_notifier_head *nh,
+		struct notifier_block *nb);
+bool blocking_notifier_has_unique_priority(struct blocking_notifier_head *nh,
+		struct notifier_block *nb);
+
 #define NOTIFY_DONE		0x0000		/* Don't care */
 #define NOTIFY_OK		0x0001		/* Suits me */
 #define NOTIFY_STOP_MASK	0x8000		/* Don't call further */
diff --git a/kernel/notifier.c b/kernel/notifier.c
index 1f7ba8988b90..cf0e1c4bd364 100644
--- a/kernel/notifier.c
+++ b/kernel/notifier.c
@@ -203,6 +203,40 @@ int atomic_notifier_call_chain(struct atomic_notifier_head *nh,
 EXPORT_SYMBOL_GPL(atomic_notifier_call_chain);
 NOKPROBE_SYMBOL(atomic_notifier_call_chain);
 
+/**
+ *	atomic_notifier_has_unique_priority - Checks whether notifier's priority is unique
+ *	@nh: Pointer to head of the atomic notifier chain
+ *	@n: Entry in notifier chain to check
+ *
+ *	Checks whether there is another notifier in the chain with the same priority.
+ *	Must be called in process context.
+ *
+ *	Returns true if priority is unique, false otherwise.
+ */
+bool atomic_notifier_has_unique_priority(struct atomic_notifier_head *nh,
+		struct notifier_block *n)
+{
+	struct notifier_block **nl = &nh->head;
+	unsigned long flags;
+	bool ret = true;
+
+	spin_lock_irqsave(&nh->lock, flags);
+
+	while ((*nl) != NULL && (*nl)->priority >= n->priority) {
+		if ((*nl)->priority == n->priority && (*nl) != n) {
+			ret = false;
+			break;
+		}
+
+		nl = &((*nl)->next);
+	}
+
+	spin_unlock_irqrestore(&nh->lock, flags);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(atomic_notifier_has_unique_priority);
+
 /*
  *	Blocking notifier chain routines.  All access to the chain is
  *	synchronized by an rwsem.
@@ -336,6 +370,46 @@ bool blocking_notifier_call_chain_empty(struct blocking_notifier_head *nh)
 }
 EXPORT_SYMBOL_GPL(blocking_notifier_call_chain_empty);
 
+/**
+ *	blocking_notifier_has_unique_priority - Checks whether notifier's priority is unique
+ *	@nh: Pointer to head of the blocking notifier chain
+ *	@n: Entry in notifier chain to check
+ *
+ *	Checks whether there is another notifier in the chain with the same priority.
+ *	Must be called in process context.
+ *
+ *	Returns true if priority is unique, false otherwise.
+ */
+bool blocking_notifier_has_unique_priority(struct blocking_notifier_head *nh,
+		struct notifier_block *n)
+{
+	struct notifier_block **nl = &nh->head;
+	bool ret = true;
+
+	/*
+	 * This code gets used during boot-up, when task switching is
+	 * not yet working and interrupts must remain disabled.  At
+	 * such times we must not call down_write().
+	 */
+	if (system_state != SYSTEM_BOOTING)
+		down_write(&nh->rwsem);
+
+	while ((*nl) != NULL && (*nl)->priority >= n->priority) {
+		if ((*nl)->priority == n->priority && (*nl) != n) {
+			ret = false;
+			break;
+		}
+
+		nl = &((*nl)->next);
+	}
+
+	if (system_state != SYSTEM_BOOTING)
+		up_write(&nh->rwsem);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(blocking_notifier_has_unique_priority);
+
 /*
  *	Raw notifier chain routines.  There is no protection;
  *	the caller must provide it.  Use at your own risk!
-- 
2.33.1


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

* [PATCH v2 04/45] reboot: Correct typo in a comment
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (2 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 03/45] notifier: Add atomic/blocking_notifier_has_unique_priority() Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 05/45] reboot: Warn if restart handler has duplicated priority Dmitry Osipenko
                   ` (36 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Correct s/implemenations/implementations/ in <reboot.h>.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 include/linux/reboot.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index af907a3d68d1..7c288013a3ca 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -63,7 +63,7 @@ struct pt_regs;
 extern void machine_crash_shutdown(struct pt_regs *);
 
 /*
- * Architecture independent implemenations of sys_reboot commands.
+ * Architecture independent implementations of sys_reboot commands.
  */
 
 extern void kernel_restart_prepare(char *cmd);
-- 
2.33.1


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

* [PATCH v2 05/45] reboot: Warn if restart handler has duplicated priority
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (3 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 04/45] reboot: Correct typo in a comment Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 06/45] reboot: Warn if unregister_restart_handler() fails Dmitry Osipenko
                   ` (35 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Add sanity check which ensures that there are no two restart handlers
registered with the same priority. Normally it's a direct sign of a
problem if two handlers use the same priority.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 kernel/reboot.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/kernel/reboot.c b/kernel/reboot.c
index efb40d095d1e..d39e599c3c99 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -182,7 +182,20 @@ static ATOMIC_NOTIFIER_HEAD(restart_handler_list);
  */
 int register_restart_handler(struct notifier_block *nb)
 {
-	return atomic_notifier_chain_register(&restart_handler_list, nb);
+	int ret;
+
+	ret = atomic_notifier_chain_register(&restart_handler_list, nb);
+	if (ret)
+		return ret;
+
+	/*
+	 * Handler must have unique priority. Otherwise invocation order is
+	 * determined by the registration order, which is presumed to be
+	 * unreliable.
+	 */
+	WARN_ON(!atomic_notifier_has_unique_priority(&restart_handler_list, nb));
+
+	return 0;
 }
 EXPORT_SYMBOL(register_restart_handler);
 
-- 
2.33.1


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

* [PATCH v2 06/45] reboot: Warn if unregister_restart_handler() fails
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (4 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 05/45] reboot: Warn if restart handler has duplicated priority Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 07/45] reboot: Remove extern annotation from function prototypes Dmitry Osipenko
                   ` (34 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Emit warning if unregister_restart_handler() fails since it never should
fail. This will ease further API development by catching mistakes early.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 kernel/reboot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/reboot.c b/kernel/reboot.c
index d39e599c3c99..291d44082f42 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -210,7 +210,7 @@ EXPORT_SYMBOL(register_restart_handler);
  */
 int unregister_restart_handler(struct notifier_block *nb)
 {
-	return atomic_notifier_chain_unregister(&restart_handler_list, nb);
+	return WARN_ON(atomic_notifier_chain_unregister(&restart_handler_list, nb));
 }
 EXPORT_SYMBOL(unregister_restart_handler);
 
-- 
2.33.1


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

* [PATCH v2 07/45] reboot: Remove extern annotation from function prototypes
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (5 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 06/45] reboot: Warn if unregister_restart_handler() fails Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 08/45] kernel: Add combined power-off+restart handler call chain API Dmitry Osipenko
                   ` (33 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

There is no need to annotate function prototypes with 'extern', it makes
code less readable. Remove unnecessary annotations from <reboot.h>.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 include/linux/reboot.h | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index 7c288013a3ca..b7fa25726323 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -40,36 +40,36 @@ extern int reboot_cpu;
 extern int reboot_force;
 
 
-extern int register_reboot_notifier(struct notifier_block *);
-extern int unregister_reboot_notifier(struct notifier_block *);
+int register_reboot_notifier(struct notifier_block *);
+int unregister_reboot_notifier(struct notifier_block *);
 
-extern int devm_register_reboot_notifier(struct device *, struct notifier_block *);
+int devm_register_reboot_notifier(struct device *, struct notifier_block *);
 
-extern int register_restart_handler(struct notifier_block *);
-extern int unregister_restart_handler(struct notifier_block *);
-extern void do_kernel_restart(char *cmd);
+int register_restart_handler(struct notifier_block *);
+int unregister_restart_handler(struct notifier_block *);
+void do_kernel_restart(char *cmd);
 
 /*
  * Architecture-specific implementations of sys_reboot commands.
  */
 
-extern void migrate_to_reboot_cpu(void);
-extern void machine_restart(char *cmd);
-extern void machine_halt(void);
-extern void machine_power_off(void);
+void migrate_to_reboot_cpu(void);
+void machine_restart(char *cmd);
+void machine_halt(void);
+void machine_power_off(void);
 
-extern void machine_shutdown(void);
+void machine_shutdown(void);
 struct pt_regs;
-extern void machine_crash_shutdown(struct pt_regs *);
+void machine_crash_shutdown(struct pt_regs *);
 
 /*
  * Architecture independent implementations of sys_reboot commands.
  */
 
-extern void kernel_restart_prepare(char *cmd);
-extern void kernel_restart(char *cmd);
-extern void kernel_halt(void);
-extern void kernel_power_off(void);
+void kernel_restart_prepare(char *cmd);
+void kernel_restart(char *cmd);
+void kernel_halt(void);
+void kernel_power_off(void);
 
 extern int C_A_D; /* for sysctl */
 void ctrl_alt_del(void);
@@ -77,15 +77,15 @@ void ctrl_alt_del(void);
 #define POWEROFF_CMD_PATH_LEN	256
 extern char poweroff_cmd[POWEROFF_CMD_PATH_LEN];
 
-extern void orderly_poweroff(bool force);
-extern void orderly_reboot(void);
+void orderly_poweroff(bool force);
+void orderly_reboot(void);
 void hw_protection_shutdown(const char *reason, int ms_until_forced);
 
 /*
  * Emergency restart, callable from an interrupt handler.
  */
 
-extern void emergency_restart(void);
+void emergency_restart(void);
 #include <asm/emergency-restart.h>
 
 #endif /* _LINUX_REBOOT_H */
-- 
2.33.1


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

* [PATCH v2 08/45] kernel: Add combined power-off+restart handler call chain API
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (6 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 07/45] reboot: Remove extern annotation from function prototypes Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-28  9:53   ` Rafael J. Wysocki
  2021-10-28  9:59   ` Rafael J. Wysocki
  2021-10-27 21:16 ` [PATCH v2 09/45] xen/x86: Use do_kernel_power_off() Dmitry Osipenko
                   ` (32 subsequent siblings)
  40 siblings, 2 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

SoC platforms often have multiple options of how to perform system's
power-off and restart operations. Meanwhile today's kernel is limited to
a single option. Add combined power-off+restart handler call chain API,
which is inspired by the restart API. The new API provides both power-off
and restart functionality.

The old pm_power_off method will be kept around till all users are
converted to the new API.

Current restart API will be replaced by the new unified API since
new API is its superset. The restart functionality of the power-handler
API is built upon the existing restart-notifier APIs.

In order to ease conversion to the new API, convenient helpers are added
for the common use-cases. They will reduce amount of boilerplate code and
remove global variables. These helpers preserve old behaviour for cases
where only one power-off handler is executed, this is what existing
drivers want, and thus, they could be easily converted to the new API.
Users of the new API should explicitly enable power-off chaining by
setting corresponding flag of the power_handler structure.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 include/linux/reboot.h   | 176 +++++++++++-
 kernel/power/hibernate.c |   2 +-
 kernel/reboot.c          | 601 ++++++++++++++++++++++++++++++++++++++-
 3 files changed, 768 insertions(+), 11 deletions(-)

diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index b7fa25726323..0ec835338c27 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -8,10 +8,16 @@
 
 struct device;
 
-#define SYS_DOWN	0x0001	/* Notify of system down */
-#define SYS_RESTART	SYS_DOWN
-#define SYS_HALT	0x0002	/* Notify of system halt */
-#define SYS_POWER_OFF	0x0003	/* Notify of system power off */
+enum reboot_prepare_mode {
+	SYS_DOWN = 1,		/* Notify of system down */
+	SYS_RESTART = SYS_DOWN,
+	SYS_HALT,		/* Notify of system halt */
+	SYS_POWER_OFF,		/* Notify of system power off */
+};
+
+#define RESTART_PRIO_RESERVED		0
+#define RESTART_PRIO_DEFAULT		128
+#define RESTART_PRIO_HIGH		192
 
 enum reboot_mode {
 	REBOOT_UNDEFINED = -1,
@@ -49,6 +55,167 @@ int register_restart_handler(struct notifier_block *);
 int unregister_restart_handler(struct notifier_block *);
 void do_kernel_restart(char *cmd);
 
+/*
+ * Unified poweroff + restart API.
+ */
+
+#define POWEROFF_PRIO_RESERVED		0
+#define POWEROFF_PRIO_PLATFORM		1
+#define POWEROFF_PRIO_DEFAULT		128
+#define POWEROFF_PRIO_HIGH		192
+#define POWEROFF_PRIO_FIRMWARE		224
+
+enum poweroff_mode {
+	POWEROFF_NORMAL = 0,
+	POWEROFF_PREPARE,
+};
+
+struct power_off_data {
+	void *cb_data;
+};
+
+struct power_off_prep_data {
+	void *cb_data;
+};
+
+struct restart_data {
+	void *cb_data;
+	const char *cmd;
+	enum reboot_mode mode;
+};
+
+struct reboot_prep_data {
+	void *cb_data;
+	const char *cmd;
+	enum reboot_prepare_mode mode;
+};
+
+struct power_handler_private_data {
+	struct notifier_block reboot_prep_nb;
+	struct notifier_block power_off_nb;
+	struct notifier_block restart_nb;
+	void (*trivial_power_off_cb)(void);
+	void (*simple_power_off_cb)(void *data);
+	void *simple_power_off_cb_data;
+	bool registered;
+};
+
+/**
+ * struct power_handler - Machine power-off + restart handler
+ *
+ * Describes power-off and restart handlers which are invoked by kernel
+ * to power off or restart this machine.  Supports prioritized chaining for
+ * both restart and power-off handlers.  Callback's priority must be unique.
+ * Intended to be used by device drivers that are responsible for restarting
+ * and powering off hardware which kernel is running on.
+ *
+ * Struct power_handler can be static.  Members of this structure must not be
+ * altered while handler is registered.
+ *
+ * Fill the structure members and pass it to register_power_handler().
+ */
+struct power_handler {
+	/**
+	 * @cb_data:
+	 *
+	 * User data included in callback's argument.
+	 */
+	void *cb_data;
+
+	/**
+	 * @power_off_cb:
+	 *
+	 * Callback that should turn off machine.  Inactive if NULL.
+	 */
+	void (*power_off_cb)(struct power_off_data *data);
+
+	/**
+	 * @power_off_prepare_cb:
+	 *
+	 * Power-off preparation callback.  All power-off preparation callbacks
+	 * are invoked before @restart_cb.  Inactive if NULL.
+	 */
+	void (*power_off_prepare_cb)(struct power_off_prep_data *data);
+
+	/**
+	 * @power_off_priority:
+	 *
+	 * Power-off callback priority, must be unique.  Zero value is
+	 * reassigned to default priority.  Inactive if @power_off_cb is NULL.
+	 */
+	int power_off_priority;
+
+	/**
+	 * @power_off_chaining_allowed:
+	 *
+	 * False if callbacks execution should stop when @power_off_cb fails
+	 * to power off machine.  True if further lower priority power-off
+	 * callback should be executed.
+	 */
+	bool power_off_chaining_allowed;
+
+	/**
+	 * @restart_cb:
+	 *
+	 * Callback that should reboot machine.  Inactive if NULL.
+	 */
+	void (*restart_cb)(struct restart_data *data);
+
+	/**
+	 * @restart_priority:
+	 *
+	 * Restart callback priority, must be unique.  Zero value is reassigned
+	 * to default priority.  Inactive if @restart_cb is NULL.
+	 */
+	int restart_priority;
+
+	/**
+	 * @reboot_prepare_cb:
+	 *
+	 * Reboot preparation callback.  All reboot preparation callbacks are
+	 * invoked before @restart_cb.  Inactive if NULL.
+	 */
+	void (*reboot_prepare_cb)(struct reboot_prep_data *data);
+
+	/**
+	 * @priv:
+	 *
+	 * Internal data.  Shouldn't be touched.
+	 */
+	const struct power_handler_private_data priv;
+};
+
+int register_power_handler(struct power_handler *handler);
+void unregister_power_handler(struct power_handler *handler);
+
+struct power_handler *
+register_simple_power_off_handler(void (*callback)(void *data), void *data);
+
+void unregister_simple_power_off_handler(struct power_handler *handler);
+
+int devm_register_power_handler(struct device *dev,
+				struct power_handler *handler);
+
+int devm_register_simple_power_off_handler(struct device *dev,
+					   void (*callback)(void *data),
+					   void *data);
+
+int devm_register_trivial_power_off_handler(struct device *dev,
+					    void (*callback)(void));
+
+int devm_register_simple_restart_handler(struct device *dev,
+					 void (*callback)(struct restart_data *data),
+					 void *data);
+
+int devm_register_prioritized_restart_handler(struct device *dev,
+					      int priority,
+					      void (*callback)(struct restart_data *data),
+					      void *data);
+
+int register_platform_power_off(void (*power_off)(void));
+
+void do_kernel_power_off(void);
+
 /*
  * Architecture-specific implementations of sys_reboot commands.
  */
@@ -70,6 +237,7 @@ void kernel_restart_prepare(char *cmd);
 void kernel_restart(char *cmd);
 void kernel_halt(void);
 void kernel_power_off(void);
+bool kernel_can_power_off(void);
 
 extern int C_A_D; /* for sysctl */
 void ctrl_alt_del(void);
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 559acef3fddb..13ad98352fde 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -664,7 +664,7 @@ static void power_down(void)
 		hibernation_platform_enter();
 		fallthrough;
 	case HIBERNATION_SHUTDOWN:
-		if (pm_power_off)
+		if (kernel_can_power_off())
 			kernel_power_off();
 		break;
 	}
diff --git a/kernel/reboot.c b/kernel/reboot.c
index 291d44082f42..779429726616 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -189,9 +189,8 @@ int register_restart_handler(struct notifier_block *nb)
 		return ret;
 
 	/*
-	 * Handler must have unique priority. Otherwise invocation order is
-	 * determined by the registration order, which is presumed to be
-	 * unreliable.
+	 * Handler must have unique priority. Otherwise call order is
+	 * determined by registration order, which is unreliable.
 	 */
 	WARN_ON(!atomic_notifier_has_unique_priority(&restart_handler_list, nb));
 
@@ -294,6 +293,587 @@ void kernel_halt(void)
 }
 EXPORT_SYMBOL_GPL(kernel_halt);
 
+/*
+ *	Notifier list for kernel code which wants to be called
+ *	to power off the system.
+ */
+static BLOCKING_NOTIFIER_HEAD(power_off_handler_list);
+
+static void dummy_pm_power_off(void)
+{
+	/* temporary stub until pm_power_off() is gone, see more below */
+}
+
+static struct notifier_block *pm_power_off_nb;
+
+/**
+ *	register_power_off_handler - Register function to be called to power off
+ *				     the system
+ *	@nb: Info about handler function to be called
+ *	@nb->priority:	Handler priority. Handlers should follow the
+ *			following guidelines for setting priorities.
+ *			0:	Power-off handler of last resort,
+ *				with limited power-off capabilities
+ *			128:	Default power-off handler; use if no other
+ *				power-off handler is expected to be available,
+ *				and/or if power-off functionality is
+ *				sufficient to power-off the entire system
+ *			255:	Highest priority power-off handler, will
+ *				preempt all other power-off handlers
+ *
+ *	Registers a function with code to be called to power off the
+ *	system.
+ *
+ *	Registered functions will be called as last step of the power-off
+ *	sequence.
+ *
+ *	Registered functions are expected to power off the system immediately.
+ *	If more than one function is registered, the power-off handler priority
+ *	selects which function will be called first.
+ *
+ *	Power-off handlers are expected to be registered from non-architecture
+ *	code, typically from drivers. A typical use case would be a system
+ *	where power-off functionality is provided through a PMIC. Multiple
+ *	power-off handlers may exist; for example, one power-off handler might
+ *	turn off the entire system, while another only turns off part of
+ *	system. In such cases, the power-off handler which only disables part
+ *	of the hardware is expected to register with low priority to ensure
+ *	that it only runs if no other means to power off the system is
+ *	available.
+ *
+ *	Currently always returns zero, as blocking_notifier_chain_register()
+ *	always returns zero.
+ */
+static int register_power_off_handler(struct notifier_block *nb)
+{
+	int ret;
+
+	ret = blocking_notifier_chain_register(&power_off_handler_list, nb);
+	if (ret)
+		return ret;
+
+	/*
+	 * Handler must have unique priority. Otherwise invocation order is
+	 * determined by the registration order, which is presumed to be
+	 * unreliable.
+	 */
+	WARN_ON(!blocking_notifier_has_unique_priority(&power_off_handler_list, nb));
+
+	/*
+	 * Some drivers check whether pm_power_off was already installed.
+	 * Install dummy callback using new API to preserve old behaviour
+	 * for those drivers during period of transition to the new API.
+	 */
+	if (!pm_power_off) {
+		pm_power_off = dummy_pm_power_off;
+		pm_power_off_nb = nb;
+	}
+
+	return 0;
+}
+
+static void unregister_power_off_handler(struct notifier_block *nb)
+{
+	if (nb == pm_power_off_nb) {
+		/*
+		 * Check whether somebody replaced pm_power_off behind
+		 * out back.
+		 */
+		if (!WARN_ON(pm_power_off != dummy_pm_power_off))
+			pm_power_off = NULL;
+
+		pm_power_off_nb = NULL;
+	}
+
+	WARN_ON(blocking_notifier_chain_unregister(&power_off_handler_list, nb));
+}
+
+static void devm_unregister_power_off_handler(void *data)
+{
+	struct notifier_block *nb = data;
+
+	unregister_power_off_handler(nb);
+}
+
+static int devm_register_power_off_handler(struct device *dev,
+					   struct notifier_block *nb)
+{
+	int err;
+
+	err = register_power_off_handler(nb);
+	if (err)
+		return err;
+
+	return devm_add_action_or_reset(dev, devm_unregister_power_off_handler,
+					nb);
+}
+
+static int power_handler_power_off(struct notifier_block *nb,
+				   unsigned long mode, void *unused)
+{
+	struct power_off_prep_data prep_data = {};
+	struct power_handler_private_data *priv;
+	struct power_off_data data = {};
+	struct power_handler *h;
+	int ret = NOTIFY_DONE;
+
+	priv = container_of(nb, struct power_handler_private_data, power_off_nb);
+	h = container_of(priv, struct power_handler, priv);
+	prep_data.cb_data = h->cb_data;
+	data.cb_data = h->cb_data;
+
+	switch (mode) {
+	case POWEROFF_NORMAL:
+		if (h->power_off_cb)
+			h->power_off_cb(&data);
+
+		if (priv->simple_power_off_cb)
+			priv->simple_power_off_cb(priv->simple_power_off_cb_data);
+
+		if (priv->trivial_power_off_cb)
+			priv->trivial_power_off_cb();
+
+		if (!h->power_off_chaining_allowed)
+			ret = NOTIFY_STOP;
+
+		break;
+
+	case POWEROFF_PREPARE:
+		if (h->power_off_prepare_cb)
+			h->power_off_prepare_cb(&prep_data);
+
+		break;
+
+	default:
+		unreachable();
+	}
+
+	return ret;
+}
+
+static int power_handler_restart(struct notifier_block *nb,
+				 unsigned long mode, void *cmd)
+{
+	struct power_handler_private_data *priv;
+	struct restart_data data = {};
+	struct power_handler *h;
+
+	priv = container_of(nb, struct power_handler_private_data, restart_nb);
+	h = container_of(priv, struct power_handler, priv);
+
+	data.cb_data = h->cb_data;
+	data.mode = mode;
+	data.cmd = cmd;
+
+	h->restart_cb(&data);
+
+	return NOTIFY_DONE;
+}
+
+static int power_handler_restart_prep(struct notifier_block *nb,
+				      unsigned long mode, void *cmd)
+{
+	struct power_handler_private_data *priv;
+	struct reboot_prep_data data = {};
+	struct power_handler *h;
+
+	priv = container_of(nb, struct power_handler_private_data, reboot_prep_nb);
+	h = container_of(priv, struct power_handler, priv);
+
+	data.cb_data = h->cb_data;
+	data.mode = mode;
+	data.cmd = cmd;
+
+	h->reboot_prepare_cb(&data);
+
+	return NOTIFY_DONE;
+}
+
+static struct power_handler_private_data *
+power_handler_private_data(struct power_handler *handler)
+{
+	return (struct power_handler_private_data *)&handler->priv;
+}
+
+/**
+ *	devm_register_power_handler - Register power handler
+ *	@dev: Device that registers handler
+ *	@handler: Power handler descriptor
+ *
+ *	Registers power handler that will be called as last step of the
+ *	power-off and restart sequences.
+ *
+ *	Returns zero on success, or error code on failure.
+ */
+int register_power_handler(struct power_handler *handler)
+{
+	struct power_handler_private_data *priv = power_handler_private_data(handler);
+	int err, priority;
+
+	/* sanity-check whether handler is registered twice */
+	if (WARN_ON(priv->registered))
+		return -EBUSY;
+
+	if (handler->power_off_cb || handler->power_off_prepare_cb) {
+		if (handler->power_off_priority == POWEROFF_PRIO_RESERVED)
+			priority = POWEROFF_PRIO_DEFAULT;
+		else
+			priority = handler->power_off_priority;
+
+		priv->power_off_nb.notifier_call = power_handler_power_off;
+		priv->power_off_nb.priority = priority;
+
+		err = register_power_off_handler(&priv->power_off_nb);
+		if (err)
+			goto reset_power_handler;
+	}
+
+	if (handler->restart_cb) {
+		if (handler->restart_priority == RESTART_PRIO_RESERVED)
+			priority = RESTART_PRIO_DEFAULT;
+		else
+			priority = handler->restart_priority;
+
+		priv->restart_nb.notifier_call = power_handler_restart;
+		priv->restart_nb.priority = priority;
+
+		err = register_restart_handler(&priv->restart_nb);
+		if (err)
+			goto unreg_power_off_handler;
+	}
+
+	if (handler->reboot_prepare_cb) {
+		priv->reboot_prep_nb.notifier_call = power_handler_restart_prep;
+		priv->reboot_prep_nb.priority = 0;
+
+		err = register_reboot_notifier(&priv->reboot_prep_nb);
+		if (err)
+			goto unreg_restart_handler;
+	}
+
+	priv->registered = true;
+
+	return 0;
+
+unreg_restart_handler:
+	if (handler->restart_cb)
+		unregister_restart_handler(&priv->restart_nb);
+
+unreg_power_off_handler:
+	if (handler->power_off_cb)
+		unregister_power_off_handler(&priv->power_off_nb);
+
+reset_power_handler:
+	memset(priv, 0, sizeof(*priv));
+
+	return err;
+}
+EXPORT_SYMBOL(register_power_handler);
+
+/**
+ *	unregister_power_handler - Unregister power handler
+ *	@handler: Power handler descriptor
+ *
+ *	Unregisters a previously registered power handler. Does nothing if
+ *	handler is NULL.
+ */
+void unregister_power_handler(struct power_handler *handler)
+{
+	struct power_handler_private_data *priv;
+
+	if (!handler)
+		return;
+
+	priv = power_handler_private_data(handler);
+
+	/* sanity-check whether handler is unregistered twice */
+	if (WARN_ON(!priv->registered))
+		return;
+
+	if (handler->reboot_prepare_cb)
+		unregister_reboot_notifier(&priv->reboot_prep_nb);
+
+	if (handler->restart_cb)
+		unregister_restart_handler(&priv->restart_nb);
+
+	if (handler->power_off_cb)
+		unregister_power_off_handler(&priv->power_off_nb);
+
+	memset(priv, 0, sizeof(*priv));
+}
+EXPORT_SYMBOL(unregister_power_handler);
+
+static void devm_unregister_power_handler(void *data)
+{
+	struct power_handler *handler = data;
+
+	unregister_power_handler(handler);
+}
+
+/**
+ *	devm_register_power_handler - Register power handler
+ *	@dev: Device that registers handler
+ *	@handler: Power handler descriptor
+ *
+ *	Resource-managed variant of register_power_handler();
+ *
+ *	Returns zero on success, or error code on failure.
+ */
+int devm_register_power_handler(struct device *dev,
+				struct power_handler *handler)
+{
+	int err;
+
+	err = register_power_handler(handler);
+	if (err)
+		return err;
+
+	return devm_add_action_or_reset(dev, devm_unregister_power_handler,
+					handler);
+}
+EXPORT_SYMBOL(devm_register_power_handler);
+
+/**
+ *	register_simple_power_off_handler - Register simple power-off callback
+ *	@dev: Device that registers callback
+ *	@callback: Callback function
+ *	@data: Callback's argument
+ *
+ *	Registers power-off callback with default priority, it will be called
+ *	as last step of the power-off sequence.
+ *
+ *	Returns power_handler pointer on success, or ERR_PTR on failure.
+ */
+struct power_handler *
+register_simple_power_off_handler(void (*callback)(void *data), void *data)
+{
+	struct power_handler_private_data *priv;
+	struct power_handler *handler;
+	int err;
+
+	handler = kzalloc(sizeof(*handler), GFP_KERNEL);
+	if (!handler)
+		return ERR_PTR(-ENOMEM);
+
+	priv = power_handler_private_data(handler);
+
+	priv->power_off_nb.notifier_call = power_handler_power_off;
+	priv->power_off_nb.priority = POWEROFF_PRIO_DEFAULT;
+	priv->simple_power_off_cb_data = data;
+	priv->simple_power_off_cb = callback;
+
+	err = register_power_off_handler(&priv->power_off_nb);
+	if (err) {
+		kfree(handler);
+		return ERR_PTR(err);
+	}
+
+	return handler;
+}
+EXPORT_SYMBOL(register_simple_power_off_handler);
+
+/**
+ *	unregister_power_handler - Unregister simple power-off handler
+ *	@handler: Power handler descriptor
+ *
+ *	Unregisters power handler that was registered by
+ *	register_simple_power_off_handler(). Does nothing if handler is
+ *	error or NULL.
+ */
+void unregister_simple_power_off_handler(struct power_handler *handler)
+{
+	struct power_handler_private_data *priv;
+
+	if (!IS_ERR_OR_NULL(handler)) {
+		priv = power_handler_private_data(handler);
+		unregister_power_off_handler(&priv->power_off_nb);
+		kfree(handler);
+	}
+}
+EXPORT_SYMBOL(unregister_simple_power_off_handler);
+
+/**
+ *	devm_register_simple_power_off_handler - Register simple power-off callback
+ *	@dev: Device that registers callback
+ *	@callback: Callback function
+ *	@data: Callback's argument
+ *
+ *	Registers resource-managed power-off callback with default priority,
+ *	it will be called as last step of the power-off sequence. Further
+ *	lower priority callbacks won't be executed if this @callback fails.
+ *
+ *	Returns zero on success, or error code on failure.
+ */
+int devm_register_simple_power_off_handler(struct device *dev,
+					   void (*callback)(void *data),
+					   void *data)
+{
+	struct power_handler_private_data *priv;
+	struct power_handler *handler;
+
+	handler = devm_kzalloc(dev, sizeof(*handler), GFP_KERNEL);
+	if (!handler)
+		return -ENOMEM;
+
+	priv = power_handler_private_data(handler);
+
+	priv->power_off_nb.notifier_call = power_handler_power_off;
+	priv->power_off_nb.priority = POWEROFF_PRIO_DEFAULT;
+	priv->simple_power_off_cb_data = data;
+	priv->simple_power_off_cb = callback;
+
+	return devm_register_power_off_handler(dev, &priv->power_off_nb);
+}
+EXPORT_SYMBOL(devm_register_simple_power_off_handler);
+
+/**
+ *	devm_register_trivial_power_off_handler - Register trivial power-off callback
+ *	@dev: Device that registers callback
+ *	@desc: Callback descriptor
+ *
+ *	Same as devm_register_simple_power_off_handler(), but callback
+ *	doesn't take argument. Further lower priority callbacks won't be
+ *	executed if this @callback fails.
+ *
+ *	Returns zero on success, or error code on failure.
+ */
+int devm_register_trivial_power_off_handler(struct device *dev,
+					    void (*callback)(void))
+{
+	struct power_handler_private_data *priv;
+	struct power_handler *handler;
+
+	handler = devm_kzalloc(dev, sizeof(*handler), GFP_KERNEL);
+	if (!handler)
+		return -ENOMEM;
+
+	priv = power_handler_private_data(handler);
+
+	priv->power_off_nb.notifier_call = power_handler_power_off;
+	priv->power_off_nb.priority = POWEROFF_PRIO_DEFAULT;
+	priv->trivial_power_off_cb = callback;
+
+	return devm_register_power_off_handler(dev, &priv->power_off_nb);
+}
+EXPORT_SYMBOL(devm_register_trivial_power_off_handler);
+
+/**
+ *	devm_register_simple_restart_handler - Register simple restart callback
+ *	@dev: Device that registers callback
+ *	@callback: Callback function
+ *	@data: Callback's argument
+ *
+ *	Registers resource-managed restart callback with default priority,
+ *	it will be called as last step of the restart sequence.
+ *
+ *	Returns zero on success, or error code on failure.
+ */
+int devm_register_simple_restart_handler(struct device *dev,
+					 void (*callback)(struct restart_data *data),
+					 void *data)
+{
+	return devm_register_prioritized_restart_handler(dev,
+							 RESTART_PRIO_DEFAULT,
+							 callback, data);
+}
+EXPORT_SYMBOL(devm_register_simple_restart_handler);
+
+/**
+ *	devm_register_prioritized_restart_handler - Register prioritized restart callback
+ *	@dev: Device that registers callback
+ *	@priority: Callback's priority
+ *	@callback: Callback function
+ *	@data: Callback's argument
+ *
+ *	Registers resource-managed restart callback with a given priority,
+ *	it will be called as last step of the restart sequence.
+ *
+ *	Returns zero on success, or error code on failure.
+ */
+int devm_register_prioritized_restart_handler(struct device *dev,
+					      int priority,
+					      void (*callback)(struct restart_data *data),
+					      void *data)
+{
+	struct power_handler *handler;
+
+	handler = devm_kzalloc(dev, sizeof(*handler), GFP_KERNEL);
+	if (!handler)
+		return -ENOMEM;
+
+	handler->restart_priority = priority;
+	handler->restart_cb = callback;
+	handler->cb_data = data;
+
+	return devm_register_power_handler(dev, handler);
+}
+EXPORT_SYMBOL(devm_register_prioritized_restart_handler);
+
+static struct power_handler platform_power_off_handler = {
+	.priv = {
+		.power_off_nb = {
+			.notifier_call = power_handler_power_off,
+			.priority = POWEROFF_PRIO_PLATFORM,
+		},
+	},
+};
+
+/**
+ *	register_platform_power_off - Register platform-level power-off callback
+ *	@power_off: Power-off callback
+ *
+ *	Registers power-off callback that will be called as last step
+ *	of the power-off sequence. This callback is expected to be invoked
+ *	for the last resort. Further lower priority callbacks won't be
+ *	executed if @power_off fails. Only one platform power-off callback
+ *	is allowed to be registered.
+ *
+ *	Returns zero on success, or error code on failure.
+ */
+int register_platform_power_off(void (*power_off)(void))
+{
+	struct power_handler_private_data *priv;
+
+	/* this function is allowed to be called only once */
+	if (WARN_ON(platform_power_off_handler.priv.trivial_power_off_cb))
+		return -EBUSY;
+
+	priv = power_handler_private_data(&platform_power_off_handler);
+	priv->trivial_power_off_cb = power_off;
+
+	return register_power_off_handler(&priv->power_off_nb);
+}
+
+/**
+ *	do_kernel_power_off - Execute kernel power-off handler call chain
+ *
+ *	Calls functions registered with register_power_off_handler.
+ *
+ *	Expected to be called as last step of the power-off sequence.
+ *
+ *	Powers off the system immediately if a power-off handler function has
+ *	been registered. Otherwise does nothing.
+ */
+void do_kernel_power_off(void)
+{
+	/* legacy pm_power_off() is unchained and it has highest priority */
+	if (pm_power_off && pm_power_off != dummy_pm_power_off)
+		return pm_power_off();
+
+	blocking_notifier_call_chain(&power_off_handler_list, POWEROFF_NORMAL,
+				     NULL);
+}
+
+static void do_kernel_power_off_prepare(void)
+{
+	/* legacy pm_power_off_prepare() is unchained and it has highest priority */
+	if (pm_power_off_prepare)
+		return pm_power_off_prepare();
+
+	blocking_notifier_call_chain(&power_off_handler_list, POWEROFF_PREPARE,
+				     NULL);
+}
+
 /**
  *	kernel_power_off - power_off the system
  *
@@ -302,8 +882,7 @@ EXPORT_SYMBOL_GPL(kernel_halt);
 void kernel_power_off(void)
 {
 	kernel_shutdown_prepare(SYSTEM_POWER_OFF);
-	if (pm_power_off_prepare)
-		pm_power_off_prepare();
+	do_kernel_power_off_prepare();
 	migrate_to_reboot_cpu();
 	syscore_shutdown();
 	pr_emerg("Power down\n");
@@ -312,6 +891,16 @@ void kernel_power_off(void)
 }
 EXPORT_SYMBOL_GPL(kernel_power_off);
 
+bool kernel_can_power_off(void)
+{
+	if (!pm_power_off &&
+	    blocking_notifier_call_chain_empty(&power_off_handler_list))
+		return false;
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(kernel_can_power_off);
+
 DEFINE_MUTEX(system_transition_mutex);
 
 /*
@@ -353,7 +942,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 	/* Instead of trying to make the power_off code look like
 	 * halt when pm_power_off is not set do it the easy way.
 	 */
-	if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
+	if (cmd == LINUX_REBOOT_CMD_POWER_OFF && !kernel_can_power_off())
 		cmd = LINUX_REBOOT_CMD_HALT;
 
 	mutex_lock(&system_transition_mutex);
-- 
2.33.1


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

* [PATCH v2 09/45] xen/x86: Use do_kernel_power_off()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (7 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 08/45] kernel: Add combined power-off+restart handler call chain API Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-28  7:35   ` Juergen Gross
  2021-10-27 21:16 ` [PATCH v2 10/45] ARM: " Dmitry Osipenko
                   ` (31 subsequent siblings)
  40 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Kernel now supports chained power-off handlers. Use do_kernel_power_off()
that invokes chained power-off handlers. It also invokes legacy
pm_power_off() for now, which will be removed once all drivers will
be converted to the new power-off API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 arch/x86/xen/enlighten_pv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
index 4f63117f09bb..4a0b9b7baf02 100644
--- a/arch/x86/xen/enlighten_pv.c
+++ b/arch/x86/xen/enlighten_pv.c
@@ -32,6 +32,7 @@
 #include <linux/gfp.h>
 #include <linux/edd.h>
 #include <linux/objtool.h>
+#include <linux/reboot.h>
 
 #include <xen/xen.h>
 #include <xen/events.h>
@@ -1087,8 +1088,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);
 }
 
-- 
2.33.1


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

* [PATCH v2 10/45] ARM: Use do_kernel_power_off()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (8 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 09/45] xen/x86: Use do_kernel_power_off() Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-28 12:04   ` Russell King (Oracle)
  2021-10-27 21:16 ` [PATCH v2 11/45] arm64: " Dmitry Osipenko
                   ` (30 subsequent siblings)
  40 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Kernel now supports chained power-off handlers. Use do_kernel_power_off()
that invokes chained power-off handlers. It also invokes legacy
pm_power_off() for now, which will be removed once all drivers will
be converted to the new power-off API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 arch/arm/kernel/reboot.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/arm/kernel/reboot.c b/arch/arm/kernel/reboot.c
index 3044fcb8d073..2cb943422554 100644
--- a/arch/arm/kernel/reboot.c
+++ b/arch/arm/kernel/reboot.c
@@ -116,9 +116,7 @@ void machine_power_off(void)
 {
 	local_irq_disable();
 	smp_send_stop();
-
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 /*
-- 
2.33.1


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

* [PATCH v2 11/45] arm64: Use do_kernel_power_off()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (9 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 10/45] ARM: " Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-11-01 13:28   ` Catalin Marinas
  2021-10-27 21:16 ` [PATCH v2 12/45] csky: " Dmitry Osipenko
                   ` (29 subsequent siblings)
  40 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Kernel now supports chained power-off handlers. Use do_kernel_power_off()
that invokes chained power-off handlers. It also invokes legacy
pm_power_off() for now, which will be removed once all drivers will
be converted to the new power-off API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 arch/arm64/kernel/process.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index aacf2f5559a8..f8db031afa7d 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -110,8 +110,7 @@ void machine_power_off(void)
 {
 	local_irq_disable();
 	smp_send_stop();
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 /*
-- 
2.33.1


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

* [PATCH v2 12/45] csky: Use do_kernel_power_off()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (10 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 11/45] arm64: " Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-11-01  1:57   ` Guo Ren
  2021-10-27 21:16 ` [PATCH v2 13/45] ia64: " Dmitry Osipenko
                   ` (28 subsequent siblings)
  40 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Kernel now supports chained power-off handlers. Use do_kernel_power_off()
that invokes chained power-off handlers. It also invokes legacy
pm_power_off() for now, which will be removed once all drivers will
be converted to the new power-off API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 arch/csky/kernel/power.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/csky/kernel/power.c b/arch/csky/kernel/power.c
index 923ee4e381b8..86ee202906f8 100644
--- a/arch/csky/kernel/power.c
+++ b/arch/csky/kernel/power.c
@@ -9,16 +9,14 @@ EXPORT_SYMBOL(pm_power_off);
 void machine_power_off(void)
 {
 	local_irq_disable();
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	asm volatile ("bkpt");
 }
 
 void machine_halt(void)
 {
 	local_irq_disable();
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	asm volatile ("bkpt");
 }
 
-- 
2.33.1


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

* [PATCH v2 13/45] ia64: Use do_kernel_power_off()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (11 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 12/45] csky: " Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 14/45] mips: " Dmitry Osipenko
                   ` (27 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Kernel now supports chained power-off handlers. Use do_kernel_power_off()
that invokes chained power-off handlers. It also invokes legacy
pm_power_off() for now, which will be removed once all drivers will
be converted to the new power-off API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 arch/ia64/kernel/process.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index 834df24a88f1..cee4d7db2143 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -19,6 +19,7 @@
 #include <linux/module.h>
 #include <linux/notifier.h>
 #include <linux/personality.h>
+#include <linux/reboot.h>
 #include <linux/sched.h>
 #include <linux/sched/debug.h>
 #include <linux/sched/hotplug.h>
@@ -599,8 +600,7 @@ machine_halt (void)
 void
 machine_power_off (void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 	machine_halt();
 }
 
-- 
2.33.1


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

* [PATCH v2 14/45] mips: Use do_kernel_power_off()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (12 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 13/45] ia64: " Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 15/45] nds32: " Dmitry Osipenko
                   ` (26 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Kernel now supports chained power-off handlers. Use do_kernel_power_off()
that invokes chained power-off handlers. It also invokes legacy
pm_power_off() for now, which will be removed once all drivers will
be converted to the new power-off API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 arch/mips/kernel/reset.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
index 6288780b779e..e7ce07b3e79b 100644
--- a/arch/mips/kernel/reset.c
+++ b/arch/mips/kernel/reset.c
@@ -114,8 +114,7 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 
 #ifdef CONFIG_SMP
 	preempt_disable();
-- 
2.33.1


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

* [PATCH v2 15/45] nds32: Use do_kernel_power_off()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (13 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 14/45] mips: " Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-28 12:20   ` Greentime Hu
  2021-10-27 21:16 ` [PATCH v2 16/45] parisc: " Dmitry Osipenko
                   ` (25 subsequent siblings)
  40 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Kernel now supports chained power-off handlers. Use do_kernel_power_off()
that invokes chained power-off handlers. It also invokes legacy
pm_power_off() for now, which will be removed once all drivers will
be converted to the new power-off API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 arch/nds32/kernel/process.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/nds32/kernel/process.c b/arch/nds32/kernel/process.c
index 49fab9e39cbf..0936dcd7db1b 100644
--- a/arch/nds32/kernel/process.c
+++ b/arch/nds32/kernel/process.c
@@ -54,8 +54,7 @@ EXPORT_SYMBOL(machine_halt);
 
 void machine_power_off(void)
 {
-	if (pm_power_off)
-		pm_power_off();
+	do_kernel_power_off();
 }
 
 EXPORT_SYMBOL(machine_power_off);
-- 
2.33.1


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

* [PATCH v2 16/45] parisc: Use do_kernel_power_off()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (14 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 15/45] nds32: " Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-28  6:38   ` Helge Deller
  2021-10-27 21:16 ` [PATCH v2 17/45] powerpc: " Dmitry Osipenko
                   ` (24 subsequent siblings)
  40 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Kernel now supports chained power-off handlers. Use do_kernel_power_off()
that invokes chained power-off handlers. It also invokes legacy
pm_power_off() for now, which will be removed once all drivers will
be converted to the new power-off API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 arch/parisc/kernel/process.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c
index ea3d83b6fb62..928201b1f58f 100644
--- a/arch/parisc/kernel/process.c
+++ b/arch/parisc/kernel/process.c
@@ -26,6 +26,7 @@
 #include <linux/module.h>
 #include <linux/personality.h>
 #include <linux/ptrace.h>
+#include <linux/reboot.h>
 #include <linux/sched.h>
 #include <linux/sched/debug.h>
 #include <linux/sched/task.h>
@@ -114,8 +115,7 @@ void machine_power_off(void)
 	pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
 
 	/* ipmi_poweroff may have been installed. */
-	if (pm_power_off)
-		pm_power_off();
+	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. */
-- 
2.33.1


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

* [PATCH v2 17/45] powerpc: Use do_kernel_power_off()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (15 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 16/45] parisc: " Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 18/45] riscv: " Dmitry Osipenko
                   ` (23 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Kernel now supports chained power-off handlers. Use do_kernel_power_off()
that invokes chained power-off handlers. It also invokes legacy
pm_power_off() for now, which will be removed once all drivers will
be converted to the new power-off API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 arch/powerpc/kernel/setup-common.c | 4 +---
 arch/powerpc/xmon/xmon.c           | 3 +--
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c
index 4f1322b65760..71c4ccd9bbb1 100644
--- a/arch/powerpc/kernel/setup-common.c
+++ b/arch/powerpc/kernel/setup-common.c
@@ -161,9 +161,7 @@ void machine_restart(char *cmd)
 void machine_power_off(void)
 {
 	machine_shutdown();
-	if (pm_power_off)
-		pm_power_off();
-
+	do_kernel_power_off();
 	smp_send_stop();
 	machine_hang();
 }
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index dd8241c009e5..9d835807d645 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -1243,8 +1243,7 @@ static void bootcmds(void)
 	} else if (cmd == 'h') {
 		ppc_md.halt();
 	} else if (cmd == 'p') {
-		if (pm_power_off)
-			pm_power_off();
+		do_kernel_power_off();
 	}
 }
 
-- 
2.33.1


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

* [PATCH v2 18/45] riscv: Use do_kernel_power_off()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (16 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 17/45] powerpc: " Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 23:09   ` Palmer Dabbelt
  2021-10-27 21:16 ` [PATCH v2 19/45] sh: " Dmitry Osipenko
                   ` (22 subsequent siblings)
  40 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Kernel now supports chained power-off handlers. Use do_kernel_power_off()
that invokes chained power-off handlers. It also invokes legacy
pm_power_off() for now, which will be removed once all drivers will
be converted to the new power-off API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 arch/riscv/kernel/reset.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/arch/riscv/kernel/reset.c b/arch/riscv/kernel/reset.c
index 9c842c41684a..912288572226 100644
--- a/arch/riscv/kernel/reset.c
+++ b/arch/riscv/kernel/reset.c
@@ -23,16 +23,12 @@ void machine_restart(char *cmd)
 
 void machine_halt(void)
 {
-	if (pm_power_off != NULL)
-		pm_power_off();
-	else
-		default_power_off();
+	do_kernel_power_off();
+	default_power_off();
 }
 
 void machine_power_off(void)
 {
-	if (pm_power_off != NULL)
-		pm_power_off();
-	else
-		default_power_off();
+	do_kernel_power_off();
+	default_power_off();
 }
-- 
2.33.1


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

* [PATCH v2 19/45] sh: Use do_kernel_power_off()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (17 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 18/45] riscv: " Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 20/45] x86: " Dmitry Osipenko
                   ` (21 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Kernel now supports chained power-off handlers. Use do_kernel_power_off()
that invokes chained power-off handlers. It also invokes legacy
pm_power_off() for now, which will be removed once all drivers will
be converted to the new power-off API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 arch/sh/kernel/reboot.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/sh/kernel/reboot.c b/arch/sh/kernel/reboot.c
index 5c33f036418b..e8eeedc9b182 100644
--- a/arch/sh/kernel/reboot.c
+++ b/arch/sh/kernel/reboot.c
@@ -46,8 +46,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)
-- 
2.33.1


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

* [PATCH v2 20/45] x86: Use do_kernel_power_off()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (18 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 19/45] sh: " Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 21/45] m68k: Switch to new power-handler API Dmitry Osipenko
                   ` (20 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Kernel now supports chained power-off handlers. Use do_kernel_power_off()
that invokes chained power-off handlers. It also invokes legacy
pm_power_off() for now, which will be removed once all drivers will
be converted to the new power-off API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 arch/x86/kernel/reboot.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index 0a40df66a40d..cd7d9416d81a 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -747,10 +747,10 @@ static void native_machine_halt(void)
 
 static void native_machine_power_off(void)
 {
-	if (pm_power_off) {
+	if (kernel_can_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);
-- 
2.33.1


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

* [PATCH v2 21/45] m68k: Switch to new power-handler API
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (19 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 20/45] x86: " Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 22/45] memory: emif: Use kernel_can_power_off() Dmitry Osipenko
                   ` (19 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Kernel now supports chained power-off handlers. Use
register_power_off_handler() that registers power-off handlers and
do_kernel_power_off() that invokes chained power-off handlers. Legacy
pm_power_off() will be removed once all drivers will be converted to
the new power-off API.

Normally arch code should adopt only the do_kernel_power_off() at first,
but m68k is a special case because it uses pm_power_off() "inside out",
i.e. pm_power_off() invokes machine_power_off() [in fact it does nothing],
while it's machine_power_off() that should invoke the pm_power_off(), and
thus, we can't convert platforms to the new API separately. There are only
two platforms changed here, so it's not a big deal.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 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          | 4 +++-
 6 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/arch/m68k/emu/natfeat.c b/arch/m68k/emu/natfeat.c
index 71b78ecee75c..b19dc00026d9 100644
--- a/arch/m68k/emu/natfeat.c
+++ b/arch/m68k/emu/natfeat.c
@@ -15,6 +15,7 @@
 #include <linux/string.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/reboot.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;
+	register_platform_power_off(nf_poweroff);
 }
diff --git a/arch/m68k/include/asm/machdep.h b/arch/m68k/include/asm/machdep.h
index 8fd80ef1b77e..8d8c3ee2069f 100644
--- a/arch/m68k/include/asm/machdep.h
+++ b/arch/m68k/include/asm/machdep.h
@@ -24,7 +24,6 @@ extern int (*mach_get_rtc_pll)(struct rtc_pll_info *);
 extern int (*mach_set_rtc_pll)(struct rtc_pll_info *);
 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 void (*mach_heartbeat) (int);
diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c
index a6030dbaa089..e160a7c57bd3 100644
--- a/arch/m68k/kernel/process.c
+++ b/arch/m68k/kernel/process.c
@@ -67,12 +67,11 @@ void machine_halt(void)
 
 void machine_power_off(void)
 {
-	if (mach_power_off)
-		mach_power_off();
+	do_kernel_power_off();
 	for (;;);
 }
 
-void (*pm_power_off)(void) = machine_power_off;
+void (*pm_power_off)(void);
 EXPORT_SYMBOL(pm_power_off);
 
 void show_regs(struct pt_regs * regs)
diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c
index 4b51bfd38e5f..50f4f120a4ff 100644
--- a/arch/m68k/kernel/setup_mm.c
+++ b/arch/m68k/kernel/setup_mm.c
@@ -98,7 +98,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 );
 #ifdef CONFIG_HEARTBEAT
 void (*mach_heartbeat) (int);
 EXPORT_SYMBOL(mach_heartbeat);
diff --git a/arch/m68k/kernel/setup_no.c b/arch/m68k/kernel/setup_no.c
index 5e4104f07a44..00bf82258233 100644
--- a/arch/m68k/kernel/setup_no.c
+++ b/arch/m68k/kernel/setup_no.c
@@ -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)
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index 5d16f9b47aa9..727320dedf08 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -12,6 +12,7 @@
 
 #include <linux/errno.h>
 #include <linux/module.h>
+#include <linux/reboot.h>
 #include <linux/types.h>
 #include <linux/mm.h>
 #include <linux/tty.h>
@@ -139,7 +140,6 @@ void __init config_mac(void)
 	mach_hwclk = mac_hwclk;
 	mach_reset = mac_reset;
 	mach_halt = mac_poweroff;
-	mach_power_off = mac_poweroff;
 #if IS_ENABLED(CONFIG_INPUT_M68K_BEEP)
 	mach_beep = mac_mksound;
 #endif
@@ -159,6 +159,8 @@ void __init config_mac(void)
 
 	if (macintosh_config->ident == MAC_MODEL_IICI)
 		mach_l2_flush = via_l2_flush;
+
+	register_platform_power_off(mac_poweroff);
 }
 
 
-- 
2.33.1


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

* [PATCH v2 22/45] memory: emif: Use kernel_can_power_off()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (20 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 21/45] m68k: Switch to new power-handler API Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 23/45] ACPI: power: Switch to power-handler API Dmitry Osipenko
                   ` (18 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Replace legacy pm_power_off with kernel_can_power_off() helper that
is aware about chained power-off handlers.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/memory/emif.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/memory/emif.c b/drivers/memory/emif.c
index 762d0c0f0716..cab10d5274a0 100644
--- a/drivers/memory/emif.c
+++ b/drivers/memory/emif.c
@@ -630,7 +630,7 @@ 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 (kernel_can_power_off()) {
 			kernel_power_off();
 		} else {
 			WARN(1, "FIXME: NO pm_power_off!!! trying restart\n");
-- 
2.33.1


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

* [PATCH v2 23/45] ACPI: power: Switch to power-handler API
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (21 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 22/45] memory: emif: Use kernel_can_power_off() Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 24/45] regulator: pfuze100: Use devm_register_power_handler() Dmitry Osipenko
                   ` (17 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Switch to power-handler API that replaces legacy pm_power_off callbacks.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/acpi/sleep.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 3023224515ab..41b3ea867f8f 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -47,19 +47,11 @@ static void acpi_sleep_tts_switch(u32 acpi_state)
 	}
 }
 
-static int tts_notify_reboot(struct notifier_block *this,
-			unsigned long code, void *x)
+static void tts_reboot_prepare(struct reboot_prep_data *data)
 {
 	acpi_sleep_tts_switch(ACPI_STATE_S5);
-	return NOTIFY_DONE;
 }
 
-static struct notifier_block tts_notifier = {
-	.notifier_call	= tts_notify_reboot,
-	.next		= NULL,
-	.priority	= 0,
-};
-
 static int acpi_sleep_prepare(u32 acpi_state)
 {
 #ifdef CONFIG_ACPI_SLEEP
@@ -1016,7 +1008,7 @@ static void acpi_sleep_hibernate_setup(void)
 static inline void acpi_sleep_hibernate_setup(void) {}
 #endif /* !CONFIG_HIBERNATION */
 
-static void acpi_power_off_prepare(void)
+static void acpi_power_off_prepare(struct power_off_prep_data *data)
 {
 	/* Prepare to power off the system */
 	acpi_sleep_prepare(ACPI_STATE_S5);
@@ -1024,7 +1016,7 @@ static void acpi_power_off_prepare(void)
 	acpi_os_wait_events_complete();
 }
 
-static void acpi_power_off(void)
+static void acpi_power_off(struct power_off_data *data)
 {
 	/* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
 	pr_debug("%s called\n", __func__);
@@ -1032,6 +1024,11 @@ static void acpi_power_off(void)
 	acpi_enter_sleep_state(ACPI_STATE_S5);
 }
 
+static struct power_handler acpi_power_handler = {
+	.power_off_priority = POWEROFF_PRIO_FIRMWARE,
+	.reboot_prepare_cb = tts_reboot_prepare,
+};
+
 int __init acpi_sleep_init(void)
 {
 	char supported[ACPI_S_STATE_COUNT * 3 + 1];
@@ -1048,8 +1045,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;
+		acpi_power_handler.power_off_cb = acpi_power_off;
+		acpi_power_handler.power_off_prepare_cb = acpi_power_off_prepare;
 	} else {
 		acpi_no_s5 = true;
 	}
@@ -1065,6 +1062,6 @@ int __init acpi_sleep_init(void)
 	 * Register the tts_notifier to reboot notifier list so that the _TTS
 	 * object can also be evaluated when the system enters S5.
 	 */
-	register_reboot_notifier(&tts_notifier);
+	register_power_handler(&acpi_power_handler);
 	return 0;
 }
-- 
2.33.1


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

* [PATCH v2 24/45] regulator: pfuze100: Use devm_register_power_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (22 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 23/45] ACPI: power: Switch to power-handler API Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-28 11:59   ` Mark Brown
  2021-10-27 21:16 ` [PATCH v2 25/45] reboot: Remove pm_power_off_prepare() Dmitry Osipenko
                   ` (16 subsequent siblings)
  40 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_power_handler() that replaces global pm_power_off_prepare
variable and allows to register multiple power-off handlers.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/regulator/pfuze100-regulator.c | 39 ++++++++++----------------
 1 file changed, 15 insertions(+), 24 deletions(-)

diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c
index d60d7d1b7fa2..73d5baf9d3ea 100644
--- a/drivers/regulator/pfuze100-regulator.c
+++ b/drivers/regulator/pfuze100-regulator.c
@@ -10,6 +10,7 @@
 #include <linux/of_device.h>
 #include <linux/regulator/of_regulator.h>
 #include <linux/platform_device.h>
+#include <linux/reboot.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
 #include <linux/regulator/pfuze100.h>
@@ -76,6 +77,7 @@ struct pfuze_chip {
 	struct pfuze_regulator regulator_descs[PFUZE100_MAX_REGULATOR];
 	struct regulator_dev *regulators[PFUZE100_MAX_REGULATOR];
 	struct pfuze_regulator *pfuze_regulators;
+	struct power_handler power_handler;
 };
 
 static const int pfuze100_swbst[] = {
@@ -569,10 +571,10 @@ static inline struct device_node *match_of_node(int index)
 	return pfuze_matches[index].of_node;
 }
 
-static struct pfuze_chip *syspm_pfuze_chip;
-
-static void pfuze_power_off_prepare(void)
+static void pfuze_power_off_prepare(struct power_off_prep_data *data)
 {
+	struct pfuze_chip *syspm_pfuze_chip = data->cb_data;
+
 	dev_info(syspm_pfuze_chip->dev, "Configure standby mode for power off");
 
 	/* Switch from default mode: APS/APS to APS/Off */
@@ -611,24 +613,24 @@ static void pfuze_power_off_prepare(void)
 
 static int pfuze_power_off_prepare_init(struct pfuze_chip *pfuze_chip)
 {
+	int err;
+
 	if (pfuze_chip->chip_id != PFUZE100) {
 		dev_warn(pfuze_chip->dev, "Requested pm_power_off_prepare handler for not supported chip\n");
 		return -ENODEV;
 	}
 
-	if (pm_power_off_prepare) {
-		dev_warn(pfuze_chip->dev, "pm_power_off_prepare is already registered.\n");
-		return -EBUSY;
-	}
+	pfuze_chip->power_handler.power_off_prepare_cb = pfuze_power_off_prepare;
+	pfuze_chip->power_handler.cb_data = pfuze_chip;
 
-	if (syspm_pfuze_chip) {
-		dev_warn(pfuze_chip->dev, "syspm_pfuze_chip is already set.\n");
-		return -EBUSY;
+	err = devm_register_power_handler(pfuze_chip->dev,
+					  &pfuze_chip->power_handler);
+	if (err) {
+		dev_err(pfuze_chip->dev,
+			"failed to register power handler: %d\n", err);
+		return err;
 	}
 
-	syspm_pfuze_chip = pfuze_chip;
-	pm_power_off_prepare = pfuze_power_off_prepare;
-
 	return 0;
 }
 
@@ -837,23 +839,12 @@ static int pfuze100_regulator_probe(struct i2c_client *client,
 	return 0;
 }
 
-static int pfuze100_regulator_remove(struct i2c_client *client)
-{
-	if (syspm_pfuze_chip) {
-		syspm_pfuze_chip = NULL;
-		pm_power_off_prepare = NULL;
-	}
-
-	return 0;
-}
-
 static struct i2c_driver pfuze_driver = {
 	.driver = {
 		.name = "pfuze100-regulator",
 		.of_match_table = pfuze_dt_ids,
 	},
 	.probe = pfuze100_regulator_probe,
-	.remove = pfuze100_regulator_remove,
 };
 module_i2c_driver(pfuze_driver);
 
-- 
2.33.1


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

* [PATCH v2 25/45] reboot: Remove pm_power_off_prepare()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (23 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 24/45] regulator: pfuze100: Use devm_register_power_handler() Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 26/45] soc/tegra: pmc: Utilize power-handler API to power off Nexus 7 properly Dmitry Osipenko
                   ` (15 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

All pm_power_off_prepare() users were converted to power-handler API.
Remove the obsolete callback.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 include/linux/pm.h |  1 -
 kernel/reboot.c    | 11 -----------
 2 files changed, 12 deletions(-)

diff --git a/include/linux/pm.h b/include/linux/pm.h
index 1d8209c09686..d9bf1426f81e 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -20,7 +20,6 @@
  * Callbacks for platform drivers to implement.
  */
 extern void (*pm_power_off)(void);
-extern void (*pm_power_off_prepare)(void);
 
 struct device; /* we have a circular dep with device.h */
 #ifdef CONFIG_VT_CONSOLE_SLEEP
diff --git a/kernel/reboot.c b/kernel/reboot.c
index 779429726616..9895bb56cee4 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -48,13 +48,6 @@ int reboot_cpu;
 enum reboot_type reboot_type = BOOT_ACPI;
 int reboot_force;
 
-/*
- * If set, this is used for preparing the system to power off.
- */
-
-void (*pm_power_off_prepare)(void);
-EXPORT_SYMBOL_GPL(pm_power_off_prepare);
-
 /**
  *	emergency_restart - reboot the system
  *
@@ -866,10 +859,6 @@ void do_kernel_power_off(void)
 
 static void do_kernel_power_off_prepare(void)
 {
-	/* legacy pm_power_off_prepare() is unchained and it has highest priority */
-	if (pm_power_off_prepare)
-		return pm_power_off_prepare();
-
 	blocking_notifier_call_chain(&power_off_handler_list, POWEROFF_PREPARE,
 				     NULL);
 }
-- 
2.33.1


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

* [PATCH v2 26/45] soc/tegra: pmc: Utilize power-handler API to power off Nexus 7 properly
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (24 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 25/45] reboot: Remove pm_power_off_prepare() Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:16 ` [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler() Dmitry Osipenko
                   ` (14 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Nexus 7 Android tablet can be turned off using a special bootloader
command which is conveyed to bootloader by putting magic value into
specific scratch register and then rebooting normally. This power-off
method should be invoked if USB cable is connected. Bootloader then will
display battery status and power off the device. This behaviour is
borrowed from downstream kernel and matches user expectations, otherwise
it looks like device got hung during power-off and it may wake up on
USB disconnect.

Switch PMC driver to power-handler API, which provides drivers with
combined power-off+restart call chains functionality, replacing the
restart-only call chain API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/soc/tegra/pmc.c | 54 +++++++++++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 18 deletions(-)

diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c
index 575d6d5b4294..a01330099e1a 100644
--- a/drivers/soc/tegra/pmc.c
+++ b/drivers/soc/tegra/pmc.c
@@ -39,6 +39,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm_domain.h>
 #include <linux/pm_opp.h>
+#include <linux/power_supply.h>
 #include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/reset.h>
@@ -107,6 +108,7 @@
 #define PMC_USB_DEBOUNCE_DEL		0xec
 #define PMC_USB_AO			0xf0
 
+#define PMC_SCRATCH37			0x130
 #define PMC_SCRATCH41			0x140
 
 #define PMC_WAKE2_MASK			0x160
@@ -1064,10 +1066,8 @@ int tegra_pmc_cpu_remove_clamping(unsigned int cpuid)
 	return tegra_powergate_remove_clamping(id);
 }
 
-static int tegra_pmc_restart_notify(struct notifier_block *this,
-				    unsigned long action, void *data)
+static void tegra_pmc_restart(const char *cmd)
 {
-	const char *cmd = data;
 	u32 value;
 
 	value = tegra_pmc_scratch_readl(pmc, pmc->soc->regs->scratch0);
@@ -1090,13 +1090,33 @@ static int tegra_pmc_restart_notify(struct notifier_block *this,
 	value = tegra_pmc_readl(pmc, PMC_CNTRL);
 	value |= PMC_CNTRL_MAIN_RST;
 	tegra_pmc_writel(pmc, value, PMC_CNTRL);
+}
 
-	return NOTIFY_DONE;
+static void tegra_pmc_restart_handler(struct restart_data *data)
+{
+	tegra_pmc_restart(data->cmd);
 }
 
-static struct notifier_block tegra_pmc_restart_handler = {
-	.notifier_call = tegra_pmc_restart_notify,
-	.priority = 128,
+static void tegra_pmc_power_off_handler(struct power_off_data *data)
+{
+	/*
+	 * Reboot Nexus 7 into special bootloader mode if USB cable is
+	 * connected in order to display battery status and power off.
+	 */
+	if (of_machine_is_compatible("asus,grouper") &&
+	    power_supply_is_system_supplied()) {
+		const u32 go_to_charger_mode = 0xa5a55a5a;
+
+		tegra_pmc_writel(pmc, go_to_charger_mode, PMC_SCRATCH37);
+		tegra_pmc_restart(NULL);
+	}
+}
+
+static struct power_handler tegra_pmc_power_handler = {
+	.restart_cb = tegra_pmc_restart_handler,
+	.power_off_cb = tegra_pmc_power_off_handler,
+	.power_off_priority = POWEROFF_PRIO_FIRMWARE,
+	.power_off_chaining_allowed = true,
 };
 
 static int powergate_show(struct seq_file *s, void *data)
@@ -2859,6 +2879,13 @@ static int tegra_pmc_probe(struct platform_device *pdev)
 		pmc->clk = NULL;
 	}
 
+	err = devm_register_power_handler(&pdev->dev, &tegra_pmc_power_handler);
+	if (err) {
+		dev_err(&pdev->dev, "unable to register power handler, %d\n",
+			err);
+		return err;
+	}
+
 	/*
 	 * PCLK clock rate can't be retrieved using CLK API because it
 	 * causes lockup if CPU enters LP2 idle state from some other
@@ -2890,20 +2917,13 @@ static int tegra_pmc_probe(struct platform_device *pdev)
 			goto cleanup_sysfs;
 	}
 
-	err = register_restart_handler(&tegra_pmc_restart_handler);
-	if (err) {
-		dev_err(&pdev->dev, "unable to register restart handler, %d\n",
-			err);
-		goto cleanup_debugfs;
-	}
-
 	err = tegra_pmc_pinctrl_init(pmc);
 	if (err)
-		goto cleanup_restart_handler;
+		goto cleanup_debugfs;
 
 	err = tegra_pmc_regmap_init(pmc);
 	if (err < 0)
-		goto cleanup_restart_handler;
+		goto cleanup_debugfs;
 
 	err = tegra_powergate_init(pmc, pdev->dev.of_node);
 	if (err < 0)
@@ -2926,8 +2946,6 @@ static int tegra_pmc_probe(struct platform_device *pdev)
 
 cleanup_powergates:
 	tegra_powergate_remove_all(pdev->dev.of_node);
-cleanup_restart_handler:
-	unregister_restart_handler(&tegra_pmc_restart_handler);
 cleanup_debugfs:
 	debugfs_remove(pmc->debugfs);
 cleanup_sysfs:
-- 
2.33.1


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

* [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (25 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 26/45] soc/tegra: pmc: Utilize power-handler API to power off Nexus 7 properly Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-11-06 20:54   ` Jonathan Neuschäfer
  2021-10-27 21:16 ` [PATCH v2 28/45] mfd: rn5t618: " Dmitry Osipenko
                   ` (13 subsequent siblings)
  40 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_power_handler() that replaces global pm_power_off
variable and allows to register multiple power-off handlers. It also
provides restart-handler support, i.e. all in one API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/ntxec.c | 50 ++++++++++-----------------------------------
 1 file changed, 11 insertions(+), 39 deletions(-)

diff --git a/drivers/mfd/ntxec.c b/drivers/mfd/ntxec.c
index b711e73eedcb..fd6410cbe153 100644
--- a/drivers/mfd/ntxec.c
+++ b/drivers/mfd/ntxec.c
@@ -32,12 +32,11 @@
 #define NTXEC_POWERKEEP_VALUE	0x0800
 #define NTXEC_RESET_VALUE	0xff00
 
-static struct i2c_client *poweroff_restart_client;
-
-static void ntxec_poweroff(void)
+static void ntxec_poweroff(struct power_off_data *data)
 {
 	int res;
 	u8 buf[3] = { NTXEC_REG_POWEROFF };
+	struct i2c_client *poweroff_restart_client = data->cb_data;
 	struct i2c_msg msgs[] = {
 		{
 			.addr = poweroff_restart_client->addr,
@@ -62,8 +61,7 @@ static void ntxec_poweroff(void)
 	msleep(5000);
 }
 
-static int ntxec_restart(struct notifier_block *nb,
-			 unsigned long action, void *data)
+static void ntxec_restart(struct restart_data *data)
 {
 	int res;
 	u8 buf[3] = { NTXEC_REG_RESET };
@@ -72,6 +70,7 @@ static int ntxec_restart(struct notifier_block *nb,
 	 * it causes an I2C error. (The reset handler in the downstream driver
 	 * does send the full two-byte value, but doesn't check the result).
 	 */
+	struct i2c_client *poweroff_restart_client = data->cb_data;
 	struct i2c_msg msgs[] = {
 		{
 			.addr = poweroff_restart_client->addr,
@@ -87,13 +86,11 @@ static int ntxec_restart(struct notifier_block *nb,
 	if (res < 0)
 		dev_warn(&poweroff_restart_client->dev,
 			 "Failed to restart (err = %d)\n", res);
-
-	return NOTIFY_DONE;
 }
 
-static struct notifier_block ntxec_restart_handler = {
-	.notifier_call = ntxec_restart,
-	.priority = 128,
+static struct power_handler ntxec_power_handler = {
+	.restart_cb = ntxec_restart,
+	.power_off_cb = ntxec_poweroff,
 };
 
 static int regmap_ignore_write(void *context,
@@ -208,25 +205,12 @@ static int ntxec_probe(struct i2c_client *client)
 		if (res < 0)
 			return res;
 
-		if (poweroff_restart_client)
-			/*
-			 * Another instance of the driver already took
-			 * poweroff/restart duties.
-			 */
-			dev_err(ec->dev, "poweroff_restart_client already assigned\n");
-		else
-			poweroff_restart_client = client;
-
-		if (pm_power_off)
-			/* Another driver already registered a poweroff handler. */
-			dev_err(ec->dev, "pm_power_off already assigned\n");
-		else
-			pm_power_off = ntxec_poweroff;
-
-		res = register_restart_handler(&ntxec_restart_handler);
+		ntxec_power_handler.cb_data = client;
+
+		res = devm_register_power_handler(ec->dev, &ntxec_power_handler);
 		if (res)
 			dev_err(ec->dev,
-				"Failed to register restart handler: %d\n", res);
+				"Failed to register power handler: %d\n", res);
 	}
 
 	i2c_set_clientdata(client, ec);
@@ -239,17 +223,6 @@ static int ntxec_probe(struct i2c_client *client)
 	return res;
 }
 
-static int ntxec_remove(struct i2c_client *client)
-{
-	if (client == poweroff_restart_client) {
-		poweroff_restart_client = NULL;
-		pm_power_off = NULL;
-		unregister_restart_handler(&ntxec_restart_handler);
-	}
-
-	return 0;
-}
-
 static const struct of_device_id of_ntxec_match_table[] = {
 	{ .compatible = "netronix,ntxec", },
 	{}
@@ -262,7 +235,6 @@ static struct i2c_driver ntxec_driver = {
 		.of_match_table = of_ntxec_match_table,
 	},
 	.probe_new = ntxec_probe,
-	.remove = ntxec_remove,
 };
 module_i2c_driver(ntxec_driver);
 
-- 
2.33.1


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

* [PATCH v2 28/45] mfd: rn5t618: Use devm_register_power_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (26 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler() Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-11-29 11:55   ` Lee Jones
  2021-10-27 21:16 ` [PATCH v2 29/45] mfd: acer-a500: " Dmitry Osipenko
                   ` (12 subsequent siblings)
  40 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_power_handler() that replaces global pm_power_off
variable and allows to register multiple power-off handlers. It also
provides restart-handler support, i.e. all in one API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/rn5t618.c | 56 ++++++++++++++++---------------------------
 1 file changed, 21 insertions(+), 35 deletions(-)

diff --git a/drivers/mfd/rn5t618.c b/drivers/mfd/rn5t618.c
index 384acb459427..12d7b2339bbe 100644
--- a/drivers/mfd/rn5t618.c
+++ b/drivers/mfd/rn5t618.c
@@ -84,9 +84,6 @@ static const struct regmap_irq_chip rc5t619_irq_chip = {
 	.mask_invert = true,
 };
 
-static struct i2c_client *rn5t618_pm_power_off;
-static struct notifier_block rn5t618_restart_handler;
-
 static int rn5t618_irq_init(struct rn5t618 *rn5t618)
 {
 	const struct regmap_irq_chip *irq_chip = NULL;
@@ -115,7 +112,9 @@ static int rn5t618_irq_init(struct rn5t618 *rn5t618)
 	return ret;
 }
 
-static void rn5t618_trigger_poweroff_sequence(bool repower)
+static void
+rn5t618_trigger_poweroff_sequence(struct i2c_client *rn5t618_pm_power_off,
+				  bool repower)
 {
 	int ret;
 
@@ -151,25 +150,31 @@ static void rn5t618_trigger_poweroff_sequence(bool repower)
 	dev_alert(&rn5t618_pm_power_off->dev, "Failed to shutdown (err = %d)\n", ret);
 }
 
-static void rn5t618_power_off(void)
+static void rn5t618_power_off(struct power_off_data *data)
 {
-	rn5t618_trigger_poweroff_sequence(false);
+	struct i2c_client *client = data->cb_data;
+
+	rn5t618_trigger_poweroff_sequence(client, false);
 }
 
-static int rn5t618_restart(struct notifier_block *this,
-			    unsigned long mode, void *cmd)
+static void rn5t618_restart(struct restart_data *data)
 {
-	rn5t618_trigger_poweroff_sequence(true);
+	struct i2c_client *client = data->cb_data;
+
+	rn5t618_trigger_poweroff_sequence(client, true);
 
 	/*
 	 * Re-power factor detection on PMIC side is not instant. 1ms
 	 * proved to be enough time until reset takes effect.
 	 */
 	mdelay(1);
-
-	return NOTIFY_DONE;
 }
 
+static struct power_handler rn5t618_power_handler = {
+	.restart_cb = rn5t618_restart,
+	.restart_priority = RESTART_PRIO_HIGH,
+};
+
 static const struct of_device_id rn5t618_of_match[] = {
 	{ .compatible = "ricoh,rn5t567", .data = (void *)RN5T567 },
 	{ .compatible = "ricoh,rn5t618", .data = (void *)RN5T618 },
@@ -221,38 +226,20 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c)
 		return ret;
 	}
 
-	rn5t618_pm_power_off = i2c;
-	if (of_device_is_system_power_controller(i2c->dev.of_node)) {
-		if (!pm_power_off)
-			pm_power_off = rn5t618_power_off;
-		else
-			dev_warn(&i2c->dev, "Poweroff callback already assigned\n");
-	}
+	if (of_device_is_system_power_controller(i2c->dev.of_node))
+		rn5t618_power_handler.power_off_cb = rn5t618_power_off;
 
-	rn5t618_restart_handler.notifier_call = rn5t618_restart;
-	rn5t618_restart_handler.priority = 192;
+	rn5t618_power_handler.cb_data = i2c;
 
-	ret = register_restart_handler(&rn5t618_restart_handler);
+	ret = devm_register_power_handler(&i2c->dev, &rn5t618_power_handler);
 	if (ret) {
-		dev_err(&i2c->dev, "cannot register restart handler, %d\n", ret);
+		dev_err(&i2c->dev, "failed to register power handler: %d\n", ret);
 		return ret;
 	}
 
 	return rn5t618_irq_init(priv);
 }
 
-static int rn5t618_i2c_remove(struct i2c_client *i2c)
-{
-	if (i2c == rn5t618_pm_power_off) {
-		rn5t618_pm_power_off = NULL;
-		pm_power_off = NULL;
-	}
-
-	unregister_restart_handler(&rn5t618_restart_handler);
-
-	return 0;
-}
-
 static int __maybe_unused rn5t618_i2c_suspend(struct device *dev)
 {
 	struct rn5t618 *priv = dev_get_drvdata(dev);
@@ -284,7 +271,6 @@ static struct i2c_driver rn5t618_i2c_driver = {
 		.pm = &rn5t618_i2c_dev_pm_ops,
 	},
 	.probe_new = rn5t618_i2c_probe,
-	.remove = rn5t618_i2c_remove,
 };
 
 module_i2c_driver(rn5t618_i2c_driver);
-- 
2.33.1


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

* [PATCH v2 29/45] mfd: acer-a500: Use devm_register_power_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (27 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 28/45] mfd: rn5t618: " Dmitry Osipenko
@ 2021-10-27 21:16 ` Dmitry Osipenko
  2021-10-27 21:17 ` [PATCH v2 30/45] mfd: ene-kb3930: " Dmitry Osipenko
                   ` (11 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:16 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_power_handler() that replaces global pm_power_off
variable and allows to register multiple power-off handlers. It also
provides restart-handler support, i.e. all in one API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/acer-ec-a500.c | 52 ++++++++++++++------------------------
 1 file changed, 19 insertions(+), 33 deletions(-)

diff --git a/drivers/mfd/acer-ec-a500.c b/drivers/mfd/acer-ec-a500.c
index 80c2fdd14fc4..fc864abc0049 100644
--- a/drivers/mfd/acer-ec-a500.c
+++ b/drivers/mfd/acer-ec-a500.c
@@ -31,8 +31,6 @@ enum {
 	REG_COLD_REBOOT = 0x55,
 };
 
-static struct i2c_client *a500_ec_client_pm_off;
-
 static int a500_ec_read(void *context, const void *reg_buf, size_t reg_size,
 			void *val_buf, size_t val_sizel)
 {
@@ -104,32 +102,35 @@ static const struct regmap_bus a500_ec_regmap_bus = {
 	.max_raw_read = 2,
 };
 
-static void a500_ec_poweroff(void)
+static void a500_ec_power_off_handler(struct power_off_data *data)
 {
-	i2c_smbus_write_word_data(a500_ec_client_pm_off,
-				  REG_SHUTDOWN, CMD_SHUTDOWN);
+	struct i2c_client *client = data->cb_data;
+
+	i2c_smbus_write_word_data(client, REG_SHUTDOWN, CMD_SHUTDOWN);
 
 	mdelay(A500_EC_POWER_CMD_TIMEOUT);
 }
 
-static int a500_ec_restart_notify(struct notifier_block *this,
-				  unsigned long reboot_mode, void *data)
+static void a500_ec_restart_handler(struct restart_data *data)
 {
-	if (reboot_mode == REBOOT_WARM)
-		i2c_smbus_write_word_data(a500_ec_client_pm_off,
+	struct i2c_client *client = data->cb_data;
+
+	if (data->mode == REBOOT_WARM)
+		i2c_smbus_write_word_data(client,
 					  REG_WARM_REBOOT, CMD_WARM_REBOOT);
 	else
-		i2c_smbus_write_word_data(a500_ec_client_pm_off,
+		i2c_smbus_write_word_data(client,
 					  REG_COLD_REBOOT, CMD_COLD_REBOOT);
 
 	mdelay(A500_EC_POWER_CMD_TIMEOUT);
-
-	return NOTIFY_DONE;
 }
 
-static struct notifier_block a500_ec_restart_handler = {
-	.notifier_call = a500_ec_restart_notify,
-	.priority = 200,
+static struct power_handler a500_ec_power_handler = {
+	.restart_cb = a500_ec_restart_handler,
+	.restart_priority = RESTART_PRIO_HIGH,
+
+	.power_off_cb = a500_ec_power_off_handler,
+	.power_off_priority = POWEROFF_PRIO_HIGH,
 };
 
 static const struct mfd_cell a500_ec_cells[] = {
@@ -156,26 +157,12 @@ static int a500_ec_probe(struct i2c_client *client)
 	}
 
 	if (of_device_is_system_power_controller(client->dev.of_node)) {
-		a500_ec_client_pm_off = client;
+		a500_ec_power_handler.cb_data = client;
 
-		err = register_restart_handler(&a500_ec_restart_handler);
+		err = devm_register_power_handler(&client->dev,
+						  &a500_ec_power_handler);
 		if (err)
 			return err;
-
-		if (!pm_power_off)
-			pm_power_off = a500_ec_poweroff;
-	}
-
-	return 0;
-}
-
-static int a500_ec_remove(struct i2c_client *client)
-{
-	if (of_device_is_system_power_controller(client->dev.of_node)) {
-		if (pm_power_off == a500_ec_poweroff)
-			pm_power_off = NULL;
-
-		unregister_restart_handler(&a500_ec_restart_handler);
 	}
 
 	return 0;
@@ -193,7 +180,6 @@ static struct i2c_driver a500_ec_driver = {
 		.of_match_table = a500_ec_match,
 	},
 	.probe_new = a500_ec_probe,
-	.remove = a500_ec_remove,
 };
 module_i2c_driver(a500_ec_driver);
 
-- 
2.33.1


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

* [PATCH v2 30/45] mfd: ene-kb3930: Use devm_register_power_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (28 preceding siblings ...)
  2021-10-27 21:16 ` [PATCH v2 29/45] mfd: acer-a500: " Dmitry Osipenko
@ 2021-10-27 21:17 ` Dmitry Osipenko
  2021-10-27 21:17 ` [PATCH v2 31/45] mfd: axp20x: Use register_simple_power_off_handler() Dmitry Osipenko
                   ` (10 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:17 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_power_handler() that replaces global pm_power_off
variable and allows to register multiple power-off handlers. It also
provides restart-handler support, i.e. all in one API.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/ene-kb3930.c | 45 ++++++++++++++--------------------------
 1 file changed, 15 insertions(+), 30 deletions(-)

diff --git a/drivers/mfd/ene-kb3930.c b/drivers/mfd/ene-kb3930.c
index 1b73318d1f1f..6a3c5f48e5e1 100644
--- a/drivers/mfd/ene-kb3930.c
+++ b/drivers/mfd/ene-kb3930.c
@@ -31,10 +31,9 @@ struct kb3930 {
 	struct i2c_client *client;
 	struct regmap *ram_regmap;
 	struct gpio_descs *off_gpios;
+	struct power_handler power_handler;
 };
 
-static struct kb3930 *kb3930_power_off;
-
 #define EC_GPIO_WAVE		0
 #define EC_GPIO_OFF_MODE	1
 
@@ -60,21 +59,19 @@ static void kb3930_off(struct kb3930 *ddata, int off_mode)
 	}
 }
 
-static int kb3930_restart(struct notifier_block *this,
-			  unsigned long mode, void *cmd)
+static void kb3930_restart(struct restart_data *data)
 {
-	kb3930_off(kb3930_power_off, EC_OFF_MODE_REBOOT);
-	return NOTIFY_DONE;
+	struct kb3930 *ddata = data->cb_data;
+
+	kb3930_off(ddata, EC_OFF_MODE_REBOOT);
 }
 
-static void kb3930_pm_power_off(void)
+static void kb3930_power_off(struct power_off_data *data)
 {
-	kb3930_off(kb3930_power_off, EC_OFF_MODE_POWER);
-}
+	struct kb3930 *ddata = data->cb_data;
 
-static struct notifier_block kb3930_restart_nb = {
-	.notifier_call = kb3930_restart,
-};
+	kb3930_off(ddata, EC_OFF_MODE_POWER);
+}
 
 static const struct mfd_cell ariel_ec_cells[] = {
 	{ .name = "dell-wyse-ariel-led", },
@@ -131,7 +128,6 @@ static int kb3930_probe(struct i2c_client *client)
 	if (!ddata)
 		return -ENOMEM;
 
-	kb3930_power_off = ddata;
 	ddata->client = client;
 	i2c_set_clientdata(client, ddata);
 
@@ -169,24 +165,14 @@ static int kb3930_probe(struct i2c_client *client)
 	}
 
 	if (ddata->off_gpios) {
-		register_restart_handler(&kb3930_restart_nb);
-		if (!pm_power_off)
-			pm_power_off = kb3930_pm_power_off;
-	}
+		ddata->power_handler.cb_data = ddata;
+		ddata->power_handler.restart_cb = kb3930_restart;
+		ddata->power_handler.power_off_cb = kb3930_power_off;
 
-	return 0;
-}
-
-static int kb3930_remove(struct i2c_client *client)
-{
-	struct kb3930 *ddata = i2c_get_clientdata(client);
-
-	if (ddata->off_gpios) {
-		if (pm_power_off == kb3930_pm_power_off)
-			pm_power_off = NULL;
-		unregister_restart_handler(&kb3930_restart_nb);
+		ret = devm_register_power_handler(dev, &ddata->power_handler);
+		if (ret)
+			return ret;
 	}
-	kb3930_power_off = NULL;
 
 	return 0;
 }
@@ -199,7 +185,6 @@ MODULE_DEVICE_TABLE(of, kb3930_dt_ids);
 
 static struct i2c_driver kb3930_driver = {
 	.probe_new = kb3930_probe,
-	.remove = kb3930_remove,
 	.driver = {
 		.name = "ene-kb3930",
 		.of_match_table = kb3930_dt_ids,
-- 
2.33.1


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

* [PATCH v2 31/45] mfd: axp20x: Use register_simple_power_off_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (29 preceding siblings ...)
  2021-10-27 21:17 ` [PATCH v2 30/45] mfd: ene-kb3930: " Dmitry Osipenko
@ 2021-10-27 21:17 ` Dmitry Osipenko
  2021-10-27 21:17 ` [PATCH v2 32/45] mfd: retu: Use devm_register_simple_power_off_handler() Dmitry Osipenko
                   ` (9 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:17 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use register_simple_power_off_handler() that replaces global pm_power_off
variable and allows to register multiple power-off handlers.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/axp20x.c       | 22 +++++++++++-----------
 include/linux/mfd/axp20x.h |  1 +
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
index 8161a5dc68e8..db31fdb169e4 100644
--- a/drivers/mfd/axp20x.c
+++ b/drivers/mfd/axp20x.c
@@ -24,6 +24,7 @@
 #include <linux/module.h>
 #include <linux/of_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
 
@@ -823,9 +824,10 @@ static const struct mfd_cell axp813_cells[] = {
 	},
 };
 
-static struct axp20x_dev *axp20x_pm_power_off;
-static void axp20x_power_off(void)
+static void axp20x_power_off(void *data)
 {
+	struct axp20x_dev *axp20x_pm_power_off = data;
+
 	if (axp20x_pm_power_off->variant == AXP288_ID)
 		return;
 
@@ -1000,10 +1002,12 @@ int axp20x_device_probe(struct axp20x_dev *axp20x)
 		return ret;
 	}
 
-	if (!pm_power_off) {
-		axp20x_pm_power_off = axp20x;
-		pm_power_off = axp20x_power_off;
-	}
+	axp20x->power_handler =
+		register_simple_power_off_handler(axp20x_power_off, axp20x);
+
+	if (IS_ERR(axp20x->power_handler))
+		dev_err(axp20x->dev, "failed to register power-off handler: %pe",
+			axp20x->power_handler);
 
 	dev_info(axp20x->dev, "AXP20X driver loaded\n");
 
@@ -1013,11 +1017,7 @@ EXPORT_SYMBOL(axp20x_device_probe);
 
 void axp20x_device_remove(struct axp20x_dev *axp20x)
 {
-	if (axp20x == axp20x_pm_power_off) {
-		axp20x_pm_power_off = NULL;
-		pm_power_off = NULL;
-	}
-
+	unregister_simple_power_off_handler(axp20x->power_handler);
 	mfd_remove_devices(axp20x->dev);
 	regmap_del_irq_chip(axp20x->irq, axp20x->regmap_irqc);
 }
diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h
index 9ab0e2fca7ea..49319a0ac369 100644
--- a/include/linux/mfd/axp20x.h
+++ b/include/linux/mfd/axp20x.h
@@ -643,6 +643,7 @@ struct axp20x_dev {
 	const struct mfd_cell           *cells;
 	const struct regmap_config	*regmap_cfg;
 	const struct regmap_irq_chip	*regmap_irq_chip;
+	struct power_handler		*power_handler;
 };
 
 /* generic helper function for reading 9-16 bit wide regs */
-- 
2.33.1


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

* [PATCH v2 32/45] mfd: retu: Use devm_register_simple_power_off_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (30 preceding siblings ...)
  2021-10-27 21:17 ` [PATCH v2 31/45] mfd: axp20x: Use register_simple_power_off_handler() Dmitry Osipenko
@ 2021-10-27 21:17 ` Dmitry Osipenko
  2021-10-27 21:17 ` [PATCH v2 33/45] mfd: rk808: " Dmitry Osipenko
                   ` (8 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:17 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_simple_power_off_handler() that replaces global
pm_power_off variable and allows to register multiple power-off handlers.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/retu-mfd.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/mfd/retu-mfd.c b/drivers/mfd/retu-mfd.c
index c748fd29a220..d18f05c1f095 100644
--- a/drivers/mfd/retu-mfd.c
+++ b/drivers/mfd/retu-mfd.c
@@ -22,6 +22,7 @@
 #include <linux/slab.h>
 #include <linux/mutex.h>
 #include <linux/module.h>
+#include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/mfd/core.h>
 #include <linux/mfd/retu.h>
@@ -81,9 +82,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 const struct resource tahvo_usb_res[] = {
 	{
 		.name	= "tahvo-usb",
@@ -165,12 +163,12 @@ int retu_write(struct retu_dev *rdev, u8 reg, u16 data)
 }
 EXPORT_SYMBOL_GPL(retu_write);
 
-static void retu_power_off(void)
+static void retu_power_off(void *data)
 {
-	struct retu_dev *rdev = retu_pm_power_off;
+	struct retu_dev *rdev = data;
 	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 +181,7 @@ static void retu_power_off(void)
 	for (;;)
 		cpu_relax();
 
-	mutex_unlock(&retu_pm_power_off->mutex);
+	mutex_unlock(&rdev->mutex);
 }
 
 static int retu_regmap_read(void *context, const void *reg, size_t reg_size,
@@ -261,6 +259,17 @@ static int retu_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 		 (ret & RETU_REG_ASICR_VILMA) ? rdat->companion_name : "",
 		 (ret >> 4) & 0x7, ret & 0xf);
 
+	if (i2c->addr == 1) {
+		ret = devm_register_simple_power_off_handler(&i2c->dev,
+							     retu_power_off,
+							     rdev);
+		if (ret) {
+			dev_err(rdev->dev,
+				"could not register power-off handler: %d\n", ret);
+			return ret;
+		}
+	}
+
 	/* Mask all interrupts. */
 	ret = retu_write(rdev, rdat->irq_chip->mask_base, 0xffff);
 	if (ret < 0)
@@ -279,10 +288,6 @@ 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;
-	}
 
 	return 0;
 }
@@ -291,10 +296,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);
 
-- 
2.33.1


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

* [PATCH v2 33/45] mfd: rk808: Use devm_register_simple_power_off_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (31 preceding siblings ...)
  2021-10-27 21:17 ` [PATCH v2 32/45] mfd: retu: Use devm_register_simple_power_off_handler() Dmitry Osipenko
@ 2021-10-27 21:17 ` Dmitry Osipenko
  2021-10-27 21:17 ` [PATCH v2 34/45] mfd: palmas: " Dmitry Osipenko
                   ` (7 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:17 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_simple_power_off_handler() that replaces global
pm_power_off variable and allows to register multiple power-off handlers.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/rk808.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/mfd/rk808.c b/drivers/mfd/rk808.c
index b181fe401330..3bf369469053 100644
--- a/drivers/mfd/rk808.c
+++ b/drivers/mfd/rk808.c
@@ -18,6 +18,7 @@
 #include <linux/mfd/core.h>
 #include <linux/module.h>
 #include <linux/of_device.h>
+#include <linux/reboot.h>
 #include <linux/regmap.h>
 
 struct rk808_reg_data {
@@ -526,12 +527,11 @@ static const struct regmap_irq_chip rk818_irq_chip = {
 	.init_ack_masked = true,
 };
 
-static struct i2c_client *rk808_i2c_client;
-
-static void rk808_pm_power_off(void)
+static void rk808_pm_power_off(void *data)
 {
 	int ret;
 	unsigned int reg, bit;
+	struct i2c_client *rk808_i2c_client = data;
 	struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
 
 	switch (rk808->variant) {
@@ -725,8 +725,14 @@ static int rk808_probe(struct i2c_client *client,
 	}
 
 	if (of_property_read_bool(np, "rockchip,system-power-controller")) {
-		rk808_i2c_client = client;
-		pm_power_off = rk808_pm_power_off;
+		ret = devm_register_simple_power_off_handler(&client->dev,
+							     rk808_pm_power_off,
+							     client);
+		if (ret) {
+			dev_err(&client->dev,
+				"failed to register power-off handler %d\n", ret);
+			goto err_irq;
+		}
 	}
 
 	return 0;
@@ -742,13 +748,6 @@ static int rk808_remove(struct i2c_client *client)
 
 	regmap_del_irq_chip(client->irq, rk808->irq_data);
 
-	/**
-	 * pm_power_off may points to a function from another module.
-	 * Check if the pointer is set by us and only then overwrite it.
-	 */
-	if (pm_power_off == rk808_pm_power_off)
-		pm_power_off = NULL;
-
 	return 0;
 }
 
-- 
2.33.1


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

* [PATCH v2 34/45] mfd: palmas: Use devm_register_simple_power_off_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (32 preceding siblings ...)
  2021-10-27 21:17 ` [PATCH v2 33/45] mfd: rk808: " Dmitry Osipenko
@ 2021-10-27 21:17 ` Dmitry Osipenko
  2021-10-27 21:17 ` [PATCH v2 35/45] mfd: max8907: " Dmitry Osipenko
                   ` (6 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:17 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_simple_power_off_handler() that replaces global
pm_power_off variable and allows to register multiple power-off handlers.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/palmas.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/mfd/palmas.c b/drivers/mfd/palmas.c
index f5b3fa973b13..c7d4d48d2fda 100644
--- a/drivers/mfd/palmas.c
+++ b/drivers/mfd/palmas.c
@@ -14,6 +14,7 @@
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
+#include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/err.h>
 #include <linux/mfd/core.h>
@@ -420,12 +421,12 @@ 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 void palmas_power_off(void *data)
 {
 	unsigned int addr;
 	int ret, slave;
 	u8 powerhold_mask;
+	struct palmas *palmas_dev = data;
 	struct device_node *np = palmas_dev->dev->of_node;
 
 	if (of_property_read_bool(np, "ti,palmas-override-powerhold")) {
@@ -680,12 +681,16 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
 	 */
 	if (node) {
 		ret = devm_of_platform_populate(&i2c->dev);
-		if (ret < 0) {
+		if (ret < 0)
+			goto err_irq;
+	}
+
+	if (pdata->pm_off) {
+		ret = devm_register_simple_power_off_handler(&i2c->dev,
+							     palmas_power_off,
+							     palmas);
+		if (ret)
 			goto err_irq;
-		} else if (pdata->pm_off && !pm_power_off) {
-			palmas_dev = palmas;
-			pm_power_off = palmas_power_off;
-		}
 	}
 
 	return ret;
@@ -712,11 +717,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;
 }
 
-- 
2.33.1


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

* [PATCH v2 35/45] mfd: max8907: Use devm_register_simple_power_off_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (33 preceding siblings ...)
  2021-10-27 21:17 ` [PATCH v2 34/45] mfd: palmas: " Dmitry Osipenko
@ 2021-10-27 21:17 ` Dmitry Osipenko
  2021-10-27 21:17 ` [PATCH v2 36/45] mfd: tps6586x: " Dmitry Osipenko
                   ` (5 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:17 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_simple_power_off_handler() that replaces global
pm_power_off variable and allows to register multiple power-off handlers.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/max8907.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/mfd/max8907.c b/drivers/mfd/max8907.c
index 41f566e6a096..58699510311b 100644
--- a/drivers/mfd/max8907.c
+++ b/drivers/mfd/max8907.c
@@ -16,6 +16,7 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 
@@ -174,9 +175,10 @@ 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 void max8907_power_off(void *data)
 {
+	struct max8907 *max8907_pm_off = data;
+
 	regmap_update_bits(max8907_pm_off->regmap_gen, MAX8907_REG_RESET_CNFG,
 			MAX8907_MASK_POWER_OFF, MAX8907_MASK_POWER_OFF);
 }
@@ -214,6 +216,17 @@ static int max8907_i2c_probe(struct i2c_client *i2c,
 		goto err_regmap_gen;
 	}
 
+	if (pm_off) {
+		ret = devm_register_simple_power_off_handler(&i2c->dev,
+							     max8907_power_off,
+							     max8907);
+		if (ret) {
+			dev_err(&i2c->dev,
+				"failed to register power-off handler: %d\n", ret);
+			return ret;
+		}
+	}
+
 	max8907->i2c_rtc = i2c_new_dummy_device(i2c->adapter, MAX8907_RTC_I2C_ADDR);
 	if (IS_ERR(max8907->i2c_rtc)) {
 		ret = PTR_ERR(max8907->i2c_rtc);
@@ -260,11 +273,6 @@ 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;
-	}
-
 	return 0;
 
 err_add_devices:
-- 
2.33.1


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

* [PATCH v2 36/45] mfd: tps6586x: Use devm_register_simple_power_off_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (34 preceding siblings ...)
  2021-10-27 21:17 ` [PATCH v2 35/45] mfd: max8907: " Dmitry Osipenko
@ 2021-10-27 21:17 ` Dmitry Osipenko
  2021-10-27 21:17 ` [PATCH v2 37/45] mfd: tps65910: " Dmitry Osipenko
                   ` (4 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:17 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_simple_power_off_handler() that replaces global
pm_power_off variable and allows to register multiple power-off handlers.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/tps6586x.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c
index c9303d3d6602..9033ed936d1e 100644
--- a/drivers/mfd/tps6586x.c
+++ b/drivers/mfd/tps6586x.c
@@ -22,6 +22,7 @@
 #include <linux/err.h>
 #include <linux/i2c.h>
 #include <linux/platform_device.h>
+#include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/of.h>
 
@@ -461,9 +462,10 @@ static const struct regmap_config tps6586x_regmap_config = {
 	.cache_type = REGCACHE_RBTREE,
 };
 
-static struct device *tps6586x_dev;
-static void tps6586x_power_off(void)
+static void tps6586x_power_off(void *data)
 {
+	struct device *tps6586x_dev = data;
+
 	if (tps6586x_clr_bits(tps6586x_dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
 		return;
 
@@ -540,6 +542,16 @@ static int tps6586x_i2c_probe(struct i2c_client *client,
 		return ret;
 	}
 
+	if (pdata->pm_off) {
+		ret = devm_register_simple_power_off_handler(&client->dev,
+							     tps6586x_power_off,
+							     &client->dev);
+		if (ret) {
+			dev_err(&client->dev,
+				"failed to register power-off handler: %d\n", ret);
+			return ret;
+		}
+	}
 
 	if (client->irq) {
 		ret = tps6586x_irq_init(tps6586x, client->irq,
@@ -564,11 +576,6 @@ 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;
-	}
-
 	return 0;
 
 err_add_devs:
-- 
2.33.1


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

* [PATCH v2 37/45] mfd: tps65910: Use devm_register_simple_power_off_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (35 preceding siblings ...)
  2021-10-27 21:17 ` [PATCH v2 36/45] mfd: tps6586x: " Dmitry Osipenko
@ 2021-10-27 21:17 ` Dmitry Osipenko
  2021-10-27 21:17 ` [PATCH v2 38/45] mfd: max77620: " Dmitry Osipenko
                   ` (3 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:17 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_simple_power_off_handler() that replaces global
pm_power_off variable and allows to register multiple power-off handlers.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/tps65910.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
index 6e105cca27d4..8fab30dc84e5 100644
--- a/drivers/mfd/tps65910.c
+++ b/drivers/mfd/tps65910.c
@@ -16,6 +16,7 @@
 #include <linux/irq.h>
 #include <linux/irqdomain.h>
 #include <linux/mfd/core.h>
+#include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/mfd/tps65910.h>
 #include <linux/of.h>
@@ -429,9 +430,9 @@ 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 void tps65910_power_off(void *data)
 {
+	struct i2c_client *tps65910_i2c_client = data;
 	struct tps65910 *tps65910;
 
 	tps65910 = dev_get_drvdata(&tps65910_i2c_client->dev);
@@ -503,9 +504,15 @@ 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) {
+		ret = devm_register_simple_power_off_handler(&i2c->dev,
+							     tps65910_power_off,
+							     i2c);
+		if (ret) {
+			dev_err(&i2c->dev,
+				"failed to register power-off handler: %d\n", ret);
+			return ret;
+		}
 	}
 
 	ret = devm_mfd_add_devices(tps65910->dev, -1,
-- 
2.33.1


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

* [PATCH v2 38/45] mfd: max77620: Use devm_register_simple_power_off_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (36 preceding siblings ...)
  2021-10-27 21:17 ` [PATCH v2 37/45] mfd: tps65910: " Dmitry Osipenko
@ 2021-10-27 21:17 ` Dmitry Osipenko
  2021-10-27 21:17 ` [PATCH v2 39/45] mfd: dm355evm_msp: Use devm_register_trivial_power_off_handler() Dmitry Osipenko
                   ` (2 subsequent siblings)
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:17 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_simple_power_off_handler() that replaces global
pm_power_off variable and allows to register multiple power-off handlers.

Nexus 7 Android tablet can be powered off using MAX77663 PMIC and using
a special bootloader command. At first the bootloader option should be
tried, it will have a higher priority than of PMIC that uses default
priority.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/max77620.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/mfd/max77620.c b/drivers/mfd/max77620.c
index fec2096474ad..29487ccc191a 100644
--- a/drivers/mfd/max77620.c
+++ b/drivers/mfd/max77620.c
@@ -31,11 +31,10 @@
 #include <linux/init.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 
-static struct max77620_chip *max77620_scratch;
-
 static const struct resource gpio_resources[] = {
 	DEFINE_RES_IRQ(MAX77620_IRQ_TOP_GPIO),
 };
@@ -483,13 +482,13 @@ static int max77620_read_es_version(struct max77620_chip *chip)
 	return ret;
 }
 
-static void max77620_pm_power_off(void)
+static void max77620_pm_power_off(void *data)
 {
-	struct max77620_chip *chip = max77620_scratch;
+	struct max77620_chip *chip = data;
 
 	regmap_update_bits(chip->rmap, MAX77620_REG_ONOFFCNFG1,
-			   MAX77620_ONOFFCNFG1_SFT_RST,
-			   MAX77620_ONOFFCNFG1_SFT_RST);
+				   MAX77620_ONOFFCNFG1_SFT_RST,
+				   MAX77620_ONOFFCNFG1_SFT_RST);
 }
 
 static int max77620_probe(struct i2c_client *client,
@@ -566,9 +565,13 @@ static int max77620_probe(struct i2c_client *client,
 	}
 
 	pm_off = of_device_is_system_power_controller(client->dev.of_node);
-	if (pm_off && !pm_power_off) {
-		max77620_scratch = chip;
-		pm_power_off = max77620_pm_power_off;
+	if (pm_off) {
+		ret = devm_register_simple_power_off_handler(chip->dev,
+							     max77620_pm_power_off,
+							     chip);
+		if (ret < 0)
+			dev_err(chip->dev,
+				"Failed to register power-off handler: %d\n", ret);
 	}
 
 	return 0;
-- 
2.33.1


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

* [PATCH v2 39/45] mfd: dm355evm_msp: Use devm_register_trivial_power_off_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (37 preceding siblings ...)
  2021-10-27 21:17 ` [PATCH v2 38/45] mfd: max77620: " Dmitry Osipenko
@ 2021-10-27 21:17 ` Dmitry Osipenko
  2021-10-27 21:17 ` [PATCH v2 40/45] mfd: twl4030: " Dmitry Osipenko
  2021-10-28 22:05 ` [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:17 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_trivial_power_off_handler() that replaces global
pm_power_off variable and allows to register multiple power-off handlers.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/dm355evm_msp.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/mfd/dm355evm_msp.c b/drivers/mfd/dm355evm_msp.c
index 54fb6cbd2aa0..5ee830f65589 100644
--- a/drivers/mfd/dm355evm_msp.c
+++ b/drivers/mfd/dm355evm_msp.c
@@ -8,6 +8,7 @@
 #include <linux/init.h>
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
+#include <linux/reboot.h>
 #include <linux/clk.h>
 #include <linux/module.h>
 #include <linux/err.h>
@@ -375,11 +376,10 @@ static void dm355evm_power_off(void)
 	dm355evm_command(MSP_COMMAND_POWEROFF);
 }
 
-static int dm355evm_msp_remove(struct i2c_client *client)
+static void dm355evm_msp_remove(void *data)
 {
-	pm_power_off = NULL;
+	/* FIXME remove children ... */
 	msp430 = NULL;
-	return 0;
 }
 
 static int
@@ -392,6 +392,11 @@ dm355evm_msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		return -EBUSY;
 	msp430 = client;
 
+	status = devm_add_action_or_reset(&client->dev, dm355evm_msp_remove,
+					  NULL);
+	if (status < 0)
+		goto fail;
+
 	/* display revision status; doubles as sanity check */
 	status = dm355evm_msp_read(DM355EVM_MSP_FIRMREV);
 	if (status < 0)
@@ -416,13 +421,15 @@ dm355evm_msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		goto fail;
 
 	/* PM hookup */
-	pm_power_off = dm355evm_power_off;
+	status = devm_register_trivial_power_off_handler(&client->dev,
+							 dm355evm_power_off);
+	if (status)
+		dev_err(&client->dev, "failed to register power-off handler: %d",
+			status);
 
 	return 0;
 
 fail:
-	/* FIXME remove children ... */
-	dm355evm_msp_remove(client);
 	return status;
 }
 
@@ -436,7 +443,6 @@ static struct i2c_driver dm355evm_msp_driver = {
 	.driver.name	= "dm355evm_msp",
 	.id_table	= dm355evm_msp_ids,
 	.probe		= dm355evm_msp_probe,
-	.remove		= dm355evm_msp_remove,
 };
 
 static int __init dm355evm_msp_init(void)
-- 
2.33.1


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

* [PATCH v2 40/45] mfd: twl4030: Use devm_register_trivial_power_off_handler()
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (38 preceding siblings ...)
  2021-10-27 21:17 ` [PATCH v2 39/45] mfd: dm355evm_msp: Use devm_register_trivial_power_off_handler() Dmitry Osipenko
@ 2021-10-27 21:17 ` Dmitry Osipenko
  2021-10-28 22:05 ` [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-27 21:17 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Use devm_register_trivial_power_off_handler() that replaces global
pm_power_off variable and allows to register multiple power-off handlers.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mfd/twl4030-power.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
index 6b36932263ba..72df4735d628 100644
--- a/drivers/mfd/twl4030-power.c
+++ b/drivers/mfd/twl4030-power.c
@@ -29,6 +29,7 @@
 #include <linux/platform_device.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <linux/reboot.h>
 
 #include <asm/mach-types.h>
 
@@ -923,7 +924,7 @@ 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)) {
 		/* 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);
@@ -939,7 +940,12 @@ static int twl4030_power_probe(struct platform_device *pdev)
 			}
 		}
 
-		pm_power_off = twl4030_power_off;
+		err = devm_register_trivial_power_off_handler(&pdev->dev,
+							      twl4030_power_off);
+		if (err) {
+			dev_err(&pdev->dev, "Failed to register power-off handler\n");
+			goto relock;
+		}
 	}
 
 relock:
-- 
2.33.1


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

* Re: [PATCH v2 18/45] riscv: Use do_kernel_power_off()
  2021-10-27 21:16 ` [PATCH v2 18/45] riscv: " Dmitry Osipenko
@ 2021-10-27 23:09   ` Palmer Dabbelt
  0 siblings, 0 replies; 71+ messages in thread
From: Palmer Dabbelt @ 2021-10-27 23:09 UTC (permalink / raw)
  To: digetx
  Cc: thierry.reding, jonathanh, lee.jones, rafael, broonie, akpm,
	linux, linux, daniel.lezcano, andriy.shevchenko, ulf.hansson,
	catalin.marinas, will, guoren, geert, gerg, funaho, tsbogend,
	nickhu, green.hu, deanbo422, James.Bottomley, deller, mpe, benh,
	paulus, Paul Walmsley, aou, ysato, dalias, tglx, mingo, bp,
	dave.hansen, x86, hpa, boris.ostrovsky, jgross, sstabellini,
	lenb, ssantosh, krzysztof.kozlowski, linus.walleij, wens,
	j.neuschaefer, tony, lgirdwood, p.zabel, vz, avifishman70,
	tmaimon77, tali.perry1, venture, yuenn, benjaminfair, pavel,
	linux-arm-kernel, linux-kernel, linux-csky, linux-ia64,
	linux-m68k, linux-mips, linux-parisc, linuxppc-dev, linux-riscv,
	linux-sh, xen-devel, linux-acpi, linux-omap, openbmc,
	linux-tegra, linux-pm

On Wed, 27 Oct 2021 14:16:48 PDT (-0700), digetx@gmail.com wrote:
> Kernel now supports chained power-off handlers. Use do_kernel_power_off()
> that invokes chained power-off handlers. It also invokes legacy
> pm_power_off() for now, which will be removed once all drivers will
> be converted to the new power-off API.
>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  arch/riscv/kernel/reset.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/arch/riscv/kernel/reset.c b/arch/riscv/kernel/reset.c
> index 9c842c41684a..912288572226 100644
> --- a/arch/riscv/kernel/reset.c
> +++ b/arch/riscv/kernel/reset.c
> @@ -23,16 +23,12 @@ void machine_restart(char *cmd)
>
>  void machine_halt(void)
>  {
> -	if (pm_power_off != NULL)
> -		pm_power_off();
> -	else
> -		default_power_off();
> +	do_kernel_power_off();
> +	default_power_off();
>  }
>
>  void machine_power_off(void)
>  {
> -	if (pm_power_off != NULL)
> -		pm_power_off();
> -	else
> -		default_power_off();
> +	do_kernel_power_off();
> +	default_power_off();
>  }

Acked-by: Palmer Dabbelt <palmer@dabbelt.com>

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

* Re: [PATCH v2 16/45] parisc: Use do_kernel_power_off()
  2021-10-27 21:16 ` [PATCH v2 16/45] parisc: " Dmitry Osipenko
@ 2021-10-28  6:38   ` Helge Deller
  0 siblings, 0 replies; 71+ messages in thread
From: Helge Deller @ 2021-10-28  6:38 UTC (permalink / raw)
  To: Dmitry Osipenko, Thierry Reding, Jonathan Hunter, Lee Jones,
	Rafael J . Wysocki, Mark Brown, Andrew Morton, Guenter Roeck,
	Russell King, Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

On 10/27/21 23:16, Dmitry Osipenko wrote:
> Kernel now supports chained power-off handlers. Use do_kernel_power_off()
> that invokes chained power-off handlers. It also invokes legacy
> pm_power_off() for now, which will be removed once all drivers will
> be converted to the new power-off API.
>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

Acked-by: Helge Deller <deller@gmx.de> # parisc



> ---
>  arch/parisc/kernel/process.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c
> index ea3d83b6fb62..928201b1f58f 100644
> --- a/arch/parisc/kernel/process.c
> +++ b/arch/parisc/kernel/process.c
> @@ -26,6 +26,7 @@
>  #include <linux/module.h>
>  #include <linux/personality.h>
>  #include <linux/ptrace.h>
> +#include <linux/reboot.h>
>  #include <linux/sched.h>
>  #include <linux/sched/debug.h>
>  #include <linux/sched/task.h>
> @@ -114,8 +115,7 @@ void machine_power_off(void)
>  	pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
>
>  	/* ipmi_poweroff may have been installed. */
> -	if (pm_power_off)
> -		pm_power_off();
> +	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. */
>


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

* Re: [PATCH v2 09/45] xen/x86: Use do_kernel_power_off()
  2021-10-27 21:16 ` [PATCH v2 09/45] xen/x86: Use do_kernel_power_off() Dmitry Osipenko
@ 2021-10-28  7:35   ` Juergen Gross
  0 siblings, 0 replies; 71+ messages in thread
From: Juergen Gross @ 2021-10-28  7:35 UTC (permalink / raw)
  To: Dmitry Osipenko, Thierry Reding, Jonathan Hunter, Lee Jones,
	Rafael J . Wysocki, Mark Brown, Andrew Morton, Guenter Roeck,
	Russell King, Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm


[-- Attachment #1.1.1: Type: text/plain, Size: 417 bytes --]

On 27.10.21 23:16, Dmitry Osipenko wrote:
> Kernel now supports chained power-off handlers. Use do_kernel_power_off()
> that invokes chained power-off handlers. It also invokes legacy
> pm_power_off() for now, which will be removed once all drivers will
> be converted to the new power-off API.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

Acked-by: Juergen Gross <jgross@suse.com>


Juergen


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

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

* Re: [PATCH v2 08/45] kernel: Add combined power-off+restart handler call chain API
  2021-10-27 21:16 ` [PATCH v2 08/45] kernel: Add combined power-off+restart handler call chain API Dmitry Osipenko
@ 2021-10-28  9:53   ` Rafael J. Wysocki
  2021-10-28 21:36     ` Dmitry Osipenko
  2021-10-28  9:59   ` Rafael J. Wysocki
  1 sibling, 1 reply; 71+ messages in thread
From: Rafael J. Wysocki @ 2021-10-28  9:53 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson, Catalin Marinas,
	Will Deacon, Guo Ren, Geert Uytterhoeven, Greg Ungerer,
	Joshua Thompson, Thomas Bogendoerfer, Nick Hu, Greentime Hu,
	Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, the arch/x86 maintainers, H. Peter Anvin,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, Len Brown,
	Santosh Shilimkar, Krzysztof Kozlowski, Linus Walleij,
	Chen-Yu Tsai, Jonathan Neuschäfer, Tony Lindgren,
	Liam Girdwood, Philipp Zabel, Vladimir Zapolskiy, Avi Fishman,
	Tomer Maimon, Tali Perry, Patrick Venture, Nancy Yuen,
	Benjamin Fair, Pavel Machek, Linux ARM,
	Linux Kernel Mailing List, linux-csky, linux-ia64, linux-m68k,
	linux-mips, linux-parisc, linuxppc-dev, linux-riscv,
	Linux-sh list, xen-devel, ACPI Devel Maling List,
	Linux OMAP Mailing List, openbmc, linux-tegra, Linux PM

On Wed, Oct 27, 2021 at 11:18 PM Dmitry Osipenko <digetx@gmail.com> wrote:
>
> SoC platforms often have multiple options of how to perform system's
> power-off and restart operations. Meanwhile today's kernel is limited to
> a single option. Add combined power-off+restart handler call chain API,
> which is inspired by the restart API. The new API provides both power-off
> and restart functionality.
>
> The old pm_power_off method will be kept around till all users are
> converted to the new API.
>
> Current restart API will be replaced by the new unified API since
> new API is its superset. The restart functionality of the power-handler
> API is built upon the existing restart-notifier APIs.
>
> In order to ease conversion to the new API, convenient helpers are added
> for the common use-cases. They will reduce amount of boilerplate code and
> remove global variables. These helpers preserve old behaviour for cases
> where only one power-off handler is executed, this is what existing
> drivers want, and thus, they could be easily converted to the new API.
> Users of the new API should explicitly enable power-off chaining by
> setting corresponding flag of the power_handler structure.
>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  include/linux/reboot.h   | 176 +++++++++++-
>  kernel/power/hibernate.c |   2 +-
>  kernel/reboot.c          | 601 ++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 768 insertions(+), 11 deletions(-)
>
> diff --git a/include/linux/reboot.h b/include/linux/reboot.h
> index b7fa25726323..0ec835338c27 100644
> --- a/include/linux/reboot.h
> +++ b/include/linux/reboot.h
> @@ -8,10 +8,16 @@
>
>  struct device;
>
> -#define SYS_DOWN       0x0001  /* Notify of system down */
> -#define SYS_RESTART    SYS_DOWN
> -#define SYS_HALT       0x0002  /* Notify of system halt */
> -#define SYS_POWER_OFF  0x0003  /* Notify of system power off */
> +enum reboot_prepare_mode {
> +       SYS_DOWN = 1,           /* Notify of system down */
> +       SYS_RESTART = SYS_DOWN,
> +       SYS_HALT,               /* Notify of system halt */
> +       SYS_POWER_OFF,          /* Notify of system power off */
> +};
> +
> +#define RESTART_PRIO_RESERVED          0
> +#define RESTART_PRIO_DEFAULT           128
> +#define RESTART_PRIO_HIGH              192
>
>  enum reboot_mode {
>         REBOOT_UNDEFINED = -1,
> @@ -49,6 +55,167 @@ int register_restart_handler(struct notifier_block *);
>  int unregister_restart_handler(struct notifier_block *);
>  void do_kernel_restart(char *cmd);
>
> +/*
> + * Unified poweroff + restart API.
> + */
> +
> +#define POWEROFF_PRIO_RESERVED         0
> +#define POWEROFF_PRIO_PLATFORM         1
> +#define POWEROFF_PRIO_DEFAULT          128
> +#define POWEROFF_PRIO_HIGH             192
> +#define POWEROFF_PRIO_FIRMWARE         224
> +
> +enum poweroff_mode {
> +       POWEROFF_NORMAL = 0,
> +       POWEROFF_PREPARE,
> +};
> +
> +struct power_off_data {
> +       void *cb_data;
> +};
> +
> +struct power_off_prep_data {
> +       void *cb_data;
> +};
> +
> +struct restart_data {
> +       void *cb_data;
> +       const char *cmd;
> +       enum reboot_mode mode;
> +};
> +
> +struct reboot_prep_data {
> +       void *cb_data;
> +       const char *cmd;
> +       enum reboot_prepare_mode mode;
> +};
> +
> +struct power_handler_private_data {
> +       struct notifier_block reboot_prep_nb;
> +       struct notifier_block power_off_nb;
> +       struct notifier_block restart_nb;
> +       void (*trivial_power_off_cb)(void);
> +       void (*simple_power_off_cb)(void *data);
> +       void *simple_power_off_cb_data;
> +       bool registered;
> +};
> +
> +/**
> + * struct power_handler - Machine power-off + restart handler
> + *
> + * Describes power-off and restart handlers which are invoked by kernel
> + * to power off or restart this machine.  Supports prioritized chaining for
> + * both restart and power-off handlers.  Callback's priority must be unique.
> + * Intended to be used by device drivers that are responsible for restarting
> + * and powering off hardware which kernel is running on.
> + *
> + * Struct power_handler can be static.  Members of this structure must not be
> + * altered while handler is registered.
> + *
> + * Fill the structure members and pass it to register_power_handler().
> + */
> +struct power_handler {

The name of this structure is too generic IMV.  There are many things
that it might apply to in principle.

What about calling power_off_handler or sys_off_handler as it need not
be about power at all?

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

* Re: [PATCH v2 08/45] kernel: Add combined power-off+restart handler call chain API
  2021-10-27 21:16 ` [PATCH v2 08/45] kernel: Add combined power-off+restart handler call chain API Dmitry Osipenko
  2021-10-28  9:53   ` Rafael J. Wysocki
@ 2021-10-28  9:59   ` Rafael J. Wysocki
  2021-10-28 21:58     ` Dmitry Osipenko
  2021-10-28 21:59     ` Dmitry Osipenko
  1 sibling, 2 replies; 71+ messages in thread
From: Rafael J. Wysocki @ 2021-10-28  9:59 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson, Catalin Marinas,
	Will Deacon, Guo Ren, Geert Uytterhoeven, Greg Ungerer,
	Joshua Thompson, Thomas Bogendoerfer, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	the arch/x86 maintainers, H. Peter Anvin, Boris Ostrovsky,
	Juergen Gross, Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, Linux ARM, Linux Kernel Mailing List, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, Linux-sh list, xen-devel, ACPI Devel Maling List,
	Linux OMAP Mailing List, openbmc, linux-tegra, Linux PM

On Wed, Oct 27, 2021 at 11:18 PM Dmitry Osipenko <digetx@gmail.com> wrote:
>
> SoC platforms often have multiple options of how to perform system's
> power-off and restart operations. Meanwhile today's kernel is limited to
> a single option. Add combined power-off+restart handler call chain API,
> which is inspired by the restart API. The new API provides both power-off
> and restart functionality.
>
> The old pm_power_off method will be kept around till all users are
> converted to the new API.
>
> Current restart API will be replaced by the new unified API since
> new API is its superset. The restart functionality of the power-handler
> API is built upon the existing restart-notifier APIs.
>
> In order to ease conversion to the new API, convenient helpers are added
> for the common use-cases. They will reduce amount of boilerplate code and
> remove global variables. These helpers preserve old behaviour for cases
> where only one power-off handler is executed, this is what existing
> drivers want, and thus, they could be easily converted to the new API.
> Users of the new API should explicitly enable power-off chaining by
> setting corresponding flag of the power_handler structure.
>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  include/linux/reboot.h   | 176 +++++++++++-
>  kernel/power/hibernate.c |   2 +-
>  kernel/reboot.c          | 601 ++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 768 insertions(+), 11 deletions(-)
>
> diff --git a/include/linux/reboot.h b/include/linux/reboot.h
> index b7fa25726323..0ec835338c27 100644
> --- a/include/linux/reboot.h
> +++ b/include/linux/reboot.h
> @@ -8,10 +8,16 @@
>
>  struct device;
>
> -#define SYS_DOWN       0x0001  /* Notify of system down */
> -#define SYS_RESTART    SYS_DOWN
> -#define SYS_HALT       0x0002  /* Notify of system halt */
> -#define SYS_POWER_OFF  0x0003  /* Notify of system power off */
> +enum reboot_prepare_mode {
> +       SYS_DOWN = 1,           /* Notify of system down */
> +       SYS_RESTART = SYS_DOWN,
> +       SYS_HALT,               /* Notify of system halt */
> +       SYS_POWER_OFF,          /* Notify of system power off */
> +};
> +
> +#define RESTART_PRIO_RESERVED          0
> +#define RESTART_PRIO_DEFAULT           128
> +#define RESTART_PRIO_HIGH              192
>
>  enum reboot_mode {
>         REBOOT_UNDEFINED = -1,
> @@ -49,6 +55,167 @@ int register_restart_handler(struct notifier_block *);
>  int unregister_restart_handler(struct notifier_block *);
>  void do_kernel_restart(char *cmd);
>
> +/*
> + * Unified poweroff + restart API.
> + */
> +
> +#define POWEROFF_PRIO_RESERVED         0
> +#define POWEROFF_PRIO_PLATFORM         1
> +#define POWEROFF_PRIO_DEFAULT          128
> +#define POWEROFF_PRIO_HIGH             192
> +#define POWEROFF_PRIO_FIRMWARE         224

Also I'm wondering why these particular numbers were chosen, here and above?

> +
> +enum poweroff_mode {
> +       POWEROFF_NORMAL = 0,
> +       POWEROFF_PREPARE,
> +};
> +
> +struct power_off_data {
> +       void *cb_data;
> +};
> +
> +struct power_off_prep_data {
> +       void *cb_data;
> +};
> +
> +struct restart_data {
> +       void *cb_data;
> +       const char *cmd;
> +       enum reboot_mode mode;
> +};
> +
> +struct reboot_prep_data {
> +       void *cb_data;
> +       const char *cmd;
> +       enum reboot_prepare_mode mode;
> +};
> +
> +struct power_handler_private_data {
> +       struct notifier_block reboot_prep_nb;
> +       struct notifier_block power_off_nb;
> +       struct notifier_block restart_nb;
> +       void (*trivial_power_off_cb)(void);
> +       void (*simple_power_off_cb)(void *data);
> +       void *simple_power_off_cb_data;
> +       bool registered;
> +};
> +
> +/**
> + * struct power_handler - Machine power-off + restart handler
> + *
> + * Describes power-off and restart handlers which are invoked by kernel
> + * to power off or restart this machine.  Supports prioritized chaining for
> + * both restart and power-off handlers.  Callback's priority must be unique.
> + * Intended to be used by device drivers that are responsible for restarting
> + * and powering off hardware which kernel is running on.
> + *
> + * Struct power_handler can be static.  Members of this structure must not be
> + * altered while handler is registered.
> + *
> + * Fill the structure members and pass it to register_power_handler().
> + */
> +struct power_handler {
> +       /**
> +        * @cb_data:
> +        *
> +        * User data included in callback's argument.
> +        */

And here I would document the structure fields in the main kerneldoc
comment above.

As is, it is a bit hard to grasp the whole definition.

> +       void *cb_data;
> +
> +       /**
> +        * @power_off_cb:
> +        *
> +        * Callback that should turn off machine.  Inactive if NULL.
> +        */
> +       void (*power_off_cb)(struct power_off_data *data);
> +
> +       /**
> +        * @power_off_prepare_cb:
> +        *
> +        * Power-off preparation callback.  All power-off preparation callbacks
> +        * are invoked before @restart_cb.  Inactive if NULL.
> +        */
> +       void (*power_off_prepare_cb)(struct power_off_prep_data *data);
> +
> +       /**
> +        * @power_off_priority:
> +        *
> +        * Power-off callback priority, must be unique.  Zero value is
> +        * reassigned to default priority.  Inactive if @power_off_cb is NULL.
> +        */
> +       int power_off_priority;
> +
> +       /**
> +        * @power_off_chaining_allowed:
> +        *
> +        * False if callbacks execution should stop when @power_off_cb fails
> +        * to power off machine.  True if further lower priority power-off
> +        * callback should be executed.
> +        */
> +       bool power_off_chaining_allowed;
> +
> +       /**
> +        * @restart_cb:
> +        *
> +        * Callback that should reboot machine.  Inactive if NULL.
> +        */
> +       void (*restart_cb)(struct restart_data *data);
> +
> +       /**
> +        * @restart_priority:
> +        *
> +        * Restart callback priority, must be unique.  Zero value is reassigned
> +        * to default priority.  Inactive if @restart_cb is NULL.
> +        */
> +       int restart_priority;
> +
> +       /**
> +        * @reboot_prepare_cb:
> +        *
> +        * Reboot preparation callback.  All reboot preparation callbacks are
> +        * invoked before @restart_cb.  Inactive if NULL.
> +        */
> +       void (*reboot_prepare_cb)(struct reboot_prep_data *data);
> +
> +       /**
> +        * @priv:
> +        *
> +        * Internal data.  Shouldn't be touched.
> +        */
> +       const struct power_handler_private_data priv;
> +};

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

* Re: [PATCH v2 03/45] notifier: Add atomic/blocking_notifier_has_unique_priority()
  2021-10-27 21:16 ` [PATCH v2 03/45] notifier: Add atomic/blocking_notifier_has_unique_priority() Dmitry Osipenko
@ 2021-10-28 11:00   ` Andy Shevchenko
  2021-10-28 21:32     ` Dmitry Osipenko
  2021-10-28 22:10     ` Dmitry Osipenko
  0 siblings, 2 replies; 71+ messages in thread
From: Andy Shevchenko @ 2021-10-28 11:00 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

On Thu, Oct 28, 2021 at 12:16:33AM +0300, Dmitry Osipenko wrote:
> Add atomic/blocking_notifier_has_unique_priority() helpers which return
> true if given handler has unique priority.

...

> +/**
> + *	atomic_notifier_has_unique_priority - Checks whether notifier's priority is unique
> + *	@nh: Pointer to head of the atomic notifier chain
> + *	@n: Entry in notifier chain to check
> + *
> + *	Checks whether there is another notifier in the chain with the same priority.
> + *	Must be called in process context.
> + *
> + *	Returns true if priority is unique, false otherwise.

Why this indentation?

> + */
> +bool atomic_notifier_has_unique_priority(struct atomic_notifier_head *nh,
> +		struct notifier_block *n)
> +{
> +	struct notifier_block **nl = &nh->head;
> +	unsigned long flags;
> +	bool ret = true;
> +
> +	spin_lock_irqsave(&nh->lock, flags);
> +
> +	while ((*nl) != NULL && (*nl)->priority >= n->priority) {

' != NULL' is redundant.

> +		if ((*nl)->priority == n->priority && (*nl) != n) {
> +			ret = false;
> +			break;
> +		}
> +
> +		nl = &((*nl)->next);
> +	}
> +
> +	spin_unlock_irqrestore(&nh->lock, flags);
> +
> +	return ret;
> +}

...

> +	/*
> +	 * This code gets used during boot-up, when task switching is
> +	 * not yet working and interrupts must remain disabled.  At

One space is enough.

> +	 * such times we must not call down_write().
> +	 */

> +	while ((*nl) != NULL && (*nl)->priority >= n->priority) {

' != NULL' is not needed.

> +		if ((*nl)->priority == n->priority && (*nl) != n) {
> +			ret = false;
> +			break;
> +		}
> +
> +		nl = &((*nl)->next);
> +	}

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2 24/45] regulator: pfuze100: Use devm_register_power_handler()
  2021-10-27 21:16 ` [PATCH v2 24/45] regulator: pfuze100: Use devm_register_power_handler() Dmitry Osipenko
@ 2021-10-28 11:59   ` Mark Brown
  0 siblings, 0 replies; 71+ messages in thread
From: Mark Brown @ 2021-10-28 11:59 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Andrew Morton, Guenter Roeck, Russell King, Daniel Lezcano,
	Andy Shevchenko, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

[-- Attachment #1: Type: text/plain, Size: 250 bytes --]

On Thu, Oct 28, 2021 at 12:16:54AM +0300, Dmitry Osipenko wrote:

> Use devm_register_power_handler() that replaces global pm_power_off_prepare
> variable and allows to register multiple power-off handlers.

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 10/45] ARM: Use do_kernel_power_off()
  2021-10-27 21:16 ` [PATCH v2 10/45] ARM: " Dmitry Osipenko
@ 2021-10-28 12:04   ` Russell King (Oracle)
  0 siblings, 0 replies; 71+ messages in thread
From: Russell King (Oracle) @ 2021-10-28 12:04 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Daniel Lezcano,
	Andy Shevchenko, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

On Thu, Oct 28, 2021 at 12:16:40AM +0300, Dmitry Osipenko wrote:
> Kernel now supports chained power-off handlers. Use do_kernel_power_off()
> that invokes chained power-off handlers. It also invokes legacy
> pm_power_off() for now, which will be removed once all drivers will
> be converted to the new power-off API.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

Thanks!

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

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

* Re: [PATCH v2 15/45] nds32: Use do_kernel_power_off()
  2021-10-27 21:16 ` [PATCH v2 15/45] nds32: " Dmitry Osipenko
@ 2021-10-28 12:20   ` Greentime Hu
  0 siblings, 0 replies; 71+ messages in thread
From: Greentime Hu @ 2021-10-28 12:20 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson, Catalin Marinas,
	Will Deacon, Guo Ren, Geert Uytterhoeven, Greg Ungerer,
	Joshua Thompson, Thomas Bogendoerfer, Nick Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, Linux Kernel Mailing List,
	linux-csky, linux-ia64, linux-m68k, linux-mips, linux-parisc,
	linuxppc-dev, linux-riscv, linux-sh, xen-devel, linux-acpi,
	linux-omap, openbmc, linux-tegra, linux-pm, Alan Kao,
	K.C. Kuen-Chern Lin(林坤成)

Dmitry Osipenko <digetx@gmail.com> 於 2021年10月28日 週四 上午5:18寫道:
>
> Kernel now supports chained power-off handlers. Use do_kernel_power_off()
> that invokes chained power-off handlers. It also invokes legacy
> pm_power_off() for now, which will be removed once all drivers will
> be converted to the new power-off API.
>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  arch/nds32/kernel/process.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/nds32/kernel/process.c b/arch/nds32/kernel/process.c
> index 49fab9e39cbf..0936dcd7db1b 100644
> --- a/arch/nds32/kernel/process.c
> +++ b/arch/nds32/kernel/process.c
> @@ -54,8 +54,7 @@ EXPORT_SYMBOL(machine_halt);
>
>  void machine_power_off(void)
>  {
> -       if (pm_power_off)
> -               pm_power_off();
> +       do_kernel_power_off();
>  }
>
>  EXPORT_SYMBOL(machine_power_off);
> --
> 2.33.1
>

Loop in Alan and KC

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

* Re: [PATCH v2 03/45] notifier: Add atomic/blocking_notifier_has_unique_priority()
  2021-10-28 11:00   ` Andy Shevchenko
@ 2021-10-28 21:32     ` Dmitry Osipenko
  2021-10-28 23:28       ` Dmitry Osipenko
  2021-10-28 22:10     ` Dmitry Osipenko
  1 sibling, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-28 21:32 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

28.10.2021 14:00, Andy Shevchenko пишет:
> On Thu, Oct 28, 2021 at 12:16:33AM +0300, Dmitry Osipenko wrote:
>> Add atomic/blocking_notifier_has_unique_priority() helpers which return
>> true if given handler has unique priority.
> 
> ...
> 
>> +/**
>> + *	atomic_notifier_has_unique_priority - Checks whether notifier's priority is unique
>> + *	@nh: Pointer to head of the atomic notifier chain
>> + *	@n: Entry in notifier chain to check
>> + *
>> + *	Checks whether there is another notifier in the chain with the same priority.
>> + *	Must be called in process context.
>> + *
>> + *	Returns true if priority is unique, false otherwise.
> 
> Why this indentation?

This is the same doc-comment style used by this file in general. I
haven't tried to invent anything new.


> ...
> 
>> +	/*
>> +	 * This code gets used during boot-up, when task switching is
>> +	 * not yet working and interrupts must remain disabled.  At
> 
> One space is enough.

This comment is replicated multiple times over this source file. You can
find it before each down_write(). I borrowed the text as-is, for
consistency.

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

* Re: [PATCH v2 08/45] kernel: Add combined power-off+restart handler call chain API
  2021-10-28  9:53   ` Rafael J. Wysocki
@ 2021-10-28 21:36     ` Dmitry Osipenko
  0 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-28 21:36 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Mark Brown,
	Andrew Morton, Guenter Roeck, Russell King, Daniel Lezcano,
	Andy Shevchenko, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	the arch/x86 maintainers, H. Peter Anvin, Boris Ostrovsky,
	Juergen Gross, Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, Linux ARM, Linux Kernel Mailing List, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, Linux-sh list, xen-devel, ACPI Devel Maling List,
	Linux OMAP Mailing List, openbmc, linux-tegra, Linux PM

28.10.2021 12:53, Rafael J. Wysocki пишет:
>> +/**
>> + * struct power_handler - Machine power-off + restart handler
>> + *
>> + * Describes power-off and restart handlers which are invoked by kernel
>> + * to power off or restart this machine.  Supports prioritized chaining for
>> + * both restart and power-off handlers.  Callback's priority must be unique.
>> + * Intended to be used by device drivers that are responsible for restarting
>> + * and powering off hardware which kernel is running on.
>> + *
>> + * Struct power_handler can be static.  Members of this structure must not be
>> + * altered while handler is registered.
>> + *
>> + * Fill the structure members and pass it to register_power_handler().
>> + */
>> +struct power_handler {
> The name of this structure is too generic IMV.  There are many things
> that it might apply to in principle.
> 
> What about calling power_off_handler or sys_off_handler as it need not
> be about power at all?

I didn't like much the 'power' either, but couldn't come up with a
better variant. Will change it in v3, thank you.

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

* Re: [PATCH v2 08/45] kernel: Add combined power-off+restart handler call chain API
  2021-10-28  9:59   ` Rafael J. Wysocki
@ 2021-10-28 21:58     ` Dmitry Osipenko
  2021-10-28 21:59     ` Dmitry Osipenko
  1 sibling, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-28 21:58 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Mark Brown,
	Andrew Morton, Guenter Roeck, Russell King, Daniel Lezcano,
	Andy Shevchenko, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	the arch/x86 maintainers, H. Peter Anvin, Boris Ostrovsky,
	Juergen Gross, Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, Linux ARM, Linux Kernel Mailing List, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, Linux-sh list, xen-devel, ACPI Devel Maling List,
	Linux OMAP Mailing List, openbmc, linux-tegra, Linux PM

28.10.2021 12:59, Rafael J. Wysocki пишет:
>> +#define RESTART_PRIO_RESERVED          0
>> +#define RESTART_PRIO_DEFAULT           128
>> +#define RESTART_PRIO_HIGH              192
>>
>>  enum reboot_mode {
>>         REBOOT_UNDEFINED = -1,
>> @@ -49,6 +55,167 @@ int register_restart_handler(struct notifier_block *);
>>  int unregister_restart_handler(struct notifier_block *);
>>  void do_kernel_restart(char *cmd);
>>
>> +/*
>> + * Unified poweroff + restart API.
>> + */
>> +
>> +#define POWEROFF_PRIO_RESERVED         0
>> +#define POWEROFF_PRIO_PLATFORM         1
>> +#define POWEROFF_PRIO_DEFAULT          128
>> +#define POWEROFF_PRIO_HIGH             192
>> +#define POWEROFF_PRIO_FIRMWARE         224
> Also I'm wondering why these particular numbers were chosen, here and above?

These values are chosen based on priorities that drivers already use. I looked thorough them all and ended with this scheme that fulfills the needs of the current API users.

I'll add these comments in v3:

/*
 * Standard restart priority levels. Intended to be set in the
 * sys_off_handler.restart_priority field.
 *
 * Use `RESTART_PRIO_XXX +- prio` style for additional levels.
 *
 * RESTART_PRIO_RESERVED:	Falls back to RESTART_PRIO_DEFAULT.
 *				Drivers may leave priority initialized
 *				to zero, to auto-set it to the default level.
 *
 * RESTART_PRIO_DEFAULT:	Use this for generic handler.
 *
 * RESTART_PRIO_HIGH:		Use this if you have multiple handlers and
 *				this handler has higher priority than the
 *				default handler.
 */

/*
 * Standard power-off priority levels. Intended to be set in the
 * sys_off_handler.power_off_priority field.
 *
 * Use `POWEROFF_PRIO_XXX +- prio` style for additional levels.
 *
 * POWEROFF_PRIO_RESERVED:	Falls back to POWEROFF_PRIO_DEFAULT.
 *				Drivers may leave priority initialized
 *				to zero, to auto-set it to the default level.
 *
 * POWEROFF_PRIO_PLATFORM:	Intended to be used by platform-level handler.
 *				Has lowest priority since device drivers are
 *				expected to take over platform handler which
 *				doesn't allow further callback chaining.
 *
 * POWEROFF_PRIO_DEFAULT:	Use this for generic handler.
 *
 * POWEROFF_PRIO_HIGH:		Use this if you have multiple handlers and
 *				this handler has higher priority than the
 *				default handler.
 *
 * POWEROFF_PRIO_FIRMWARE:	Use this if handler uses firmware call.
 *				Has highest priority since firmware is expected
 *				to know best how to power-off hardware properly.
 */

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

* Re: [PATCH v2 08/45] kernel: Add combined power-off+restart handler call chain API
  2021-10-28  9:59   ` Rafael J. Wysocki
  2021-10-28 21:58     ` Dmitry Osipenko
@ 2021-10-28 21:59     ` Dmitry Osipenko
  1 sibling, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-28 21:59 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Mark Brown,
	Andrew Morton, Guenter Roeck, Russell King, Daniel Lezcano,
	Andy Shevchenko, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	the arch/x86 maintainers, H. Peter Anvin, Boris Ostrovsky,
	Juergen Gross, Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, Linux ARM, Linux Kernel Mailing List, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, Linux-sh list, xen-devel, ACPI Devel Maling List,
	Linux OMAP Mailing List, openbmc, linux-tegra, Linux PM

28.10.2021 12:59, Rafael J. Wysocki пишет:
>> +/**
>> + * struct power_handler - Machine power-off + restart handler
>> + *
>> + * Describes power-off and restart handlers which are invoked by kernel
>> + * to power off or restart this machine.  Supports prioritized chaining for
>> + * both restart and power-off handlers.  Callback's priority must be unique.
>> + * Intended to be used by device drivers that are responsible for restarting
>> + * and powering off hardware which kernel is running on.
>> + *
>> + * Struct power_handler can be static.  Members of this structure must not be
>> + * altered while handler is registered.
>> + *
>> + * Fill the structure members and pass it to register_power_handler().
>> + */
>> +struct power_handler {
>> +       /**
>> +        * @cb_data:
>> +        *
>> +        * User data included in callback's argument.
>> +        */
> And here I would document the structure fields in the main kerneldoc
> comment above.
> 
> As is, it is a bit hard to grasp the whole definition.
> 

I'll move the comments in v3, thanks.

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

* Re: [PATCH v2 00/45] Introduce power-off+restart call chain API
  2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
                   ` (39 preceding siblings ...)
  2021-10-27 21:17 ` [PATCH v2 40/45] mfd: twl4030: " Dmitry Osipenko
@ 2021-10-28 22:05 ` Dmitry Osipenko
  40 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-28 22:05 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson
  Cc: Catalin Marinas, Will Deacon, Guo Ren, Geert Uytterhoeven,
	Greg Ungerer, Joshua Thompson, Thomas Bogendoerfer, Nick Hu,
	Greentime Hu, Vincent Chen, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Yoshinori Sato,
	Rich Felker, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

28.10.2021 00:16, Dmitry Osipenko пишет:
>   mfd: ab8500: Use devm_register_trivial_power_off_handler()
>   reset: ath79: Use devm_register_simple_restart_handler()
>   reset: intel-gw: Use devm_register_simple_restart_handler()
>   reset: lpc18xx: Use devm_register_prioritized_restart_handler()
>   reset: npcm: Use devm_register_prioritized_restart_handler()

These patches got lost because Gmail gave me ban after 40's email. I
think it doesn't worth to re-send them now since you should get an idea
about how API usage looks like without the lost patches.

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

* Re: [PATCH v2 03/45] notifier: Add atomic/blocking_notifier_has_unique_priority()
  2021-10-28 11:00   ` Andy Shevchenko
  2021-10-28 21:32     ` Dmitry Osipenko
@ 2021-10-28 22:10     ` Dmitry Osipenko
  1 sibling, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-28 22:10 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

28.10.2021 14:00, Andy Shevchenko пишет:
>> +	while ((*nl) != NULL && (*nl)->priority >= n->priority) {
> ' != NULL' is not needed.
> 

I'll change it in v3, thanks.

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

* Re: [PATCH v2 03/45] notifier: Add atomic/blocking_notifier_has_unique_priority()
  2021-10-28 21:32     ` Dmitry Osipenko
@ 2021-10-28 23:28       ` Dmitry Osipenko
  0 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-10-28 23:28 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

29.10.2021 00:32, Dmitry Osipenko пишет:
>>> +	/*
>>> +	 * This code gets used during boot-up, when task switching is
>>> +	 * not yet working and interrupts must remain disabled.  At
>> One space is enough.
> This comment is replicated multiple times over this source file. You can
> find it before each down_write(). I borrowed the text as-is, for
> consistency.

Actually, it should be down_read() here since there are no writes. I'll
correct it in v3.

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

* Re: [PATCH v2 12/45] csky: Use do_kernel_power_off()
  2021-10-27 21:16 ` [PATCH v2 12/45] csky: " Dmitry Osipenko
@ 2021-11-01  1:57   ` Guo Ren
  0 siblings, 0 replies; 71+ messages in thread
From: Guo Ren @ 2021-11-01  1:57 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson, Catalin Marinas,
	Will Deacon, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, Linux ARM, Linux Kernel Mailing List, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

Only for this patch, Acked-by: Guo Ren <guoren@kernel.org>

On Thu, Oct 28, 2021 at 5:18 AM Dmitry Osipenko <digetx@gmail.com> wrote:
>
> Kernel now supports chained power-off handlers. Use do_kernel_power_off()
> that invokes chained power-off handlers. It also invokes legacy
> pm_power_off() for now, which will be removed once all drivers will
> be converted to the new power-off API.
>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  arch/csky/kernel/power.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/arch/csky/kernel/power.c b/arch/csky/kernel/power.c
> index 923ee4e381b8..86ee202906f8 100644
> --- a/arch/csky/kernel/power.c
> +++ b/arch/csky/kernel/power.c
> @@ -9,16 +9,14 @@ EXPORT_SYMBOL(pm_power_off);
>  void machine_power_off(void)
>  {
>         local_irq_disable();
> -       if (pm_power_off)
> -               pm_power_off();
> +       do_kernel_power_off();
>         asm volatile ("bkpt");
>  }
>
>  void machine_halt(void)
>  {
>         local_irq_disable();
> -       if (pm_power_off)
> -               pm_power_off();
> +       do_kernel_power_off();
>         asm volatile ("bkpt");
>  }
>
> --
> 2.33.1
>


-- 
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/

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

* Re: [PATCH v2 11/45] arm64: Use do_kernel_power_off()
  2021-10-27 21:16 ` [PATCH v2 11/45] arm64: " Dmitry Osipenko
@ 2021-11-01 13:28   ` Catalin Marinas
  0 siblings, 0 replies; 71+ messages in thread
From: Catalin Marinas @ 2021-11-01 13:28 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

On Thu, Oct 28, 2021 at 12:16:41AM +0300, Dmitry Osipenko wrote:
> Kernel now supports chained power-off handlers. Use do_kernel_power_off()
> that invokes chained power-off handlers. It also invokes legacy
> pm_power_off() for now, which will be removed once all drivers will
> be converted to the new power-off API.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>

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

* Re: [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler()
  2021-10-27 21:16 ` [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler() Dmitry Osipenko
@ 2021-11-06 20:54   ` Jonathan Neuschäfer
  2021-11-07 16:53     ` Dmitry Osipenko
  0 siblings, 1 reply; 71+ messages in thread
From: Jonathan Neuschäfer @ 2021-11-06 20:54 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson, Catalin Marinas,
	Will Deacon, Guo Ren, Geert Uytterhoeven, Greg Ungerer,
	Joshua Thompson, Thomas Bogendoerfer, Nick Hu, Greentime Hu,
	Vincent Chen, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

[-- Attachment #1: Type: text/plain, Size: 4481 bytes --]

Hi,

On Thu, Oct 28, 2021 at 12:16:57AM +0300, Dmitry Osipenko wrote:
> Use devm_register_power_handler() that replaces global pm_power_off
> variable and allows to register multiple power-off handlers. It also
> provides restart-handler support, i.e. all in one API.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---

When I boot with (most of) this patchset applied, I get the warning at
kernel/reboot.c:187:

	/*
	 * Handler must have unique priority. Otherwise call order is
	 * determined by registration order, which is unreliable.
	 */
	WARN_ON(!atomic_notifier_has_unique_priority(&restart_handler_list, nb));

As the NTXEC driver doesn't specify a priority, I think this is an issue
to be fixed elsewhere.

Other than that, it works and looks good, as far as I can tell.


For this patch:

Reviewed-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
Tested-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>


Best regards,
Jonathan
---

Full Oops log:

[    3.523294] ------------[ cut here ]------------
[    3.528193] WARNING: CPU: 0 PID: 1 at kernel/reboot.c:187 register_restart_handler+0x4c/0x58
[    3.536975] Modules linked in:
[    3.540312] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.15.0-00021-gcb24c628b307 #622
[    3.548214] Hardware name: Freescale i.MX50 (Device Tree Support)
[    3.554357] [<c0111540>] (unwind_backtrace) from [<c010cdd0>] (show_stack+0x10/0x14)
[    3.562183] [<c010cdd0>] (show_stack) from [<c0bf240c>] (dump_stack_lvl+0x58/0x70)
[    3.569824] [<c0bf240c>] (dump_stack_lvl) from [<c0127604>] (__warn+0xd4/0x154)
[    3.577191] [<c0127604>] (__warn) from [<c0bec844>] (warn_slowpath_fmt+0x74/0xa8)
[    3.584727] [<c0bec844>] (warn_slowpath_fmt) from [<c01593c8>] (register_restart_handler+0x4c/0x58)
[    3.593823] [<c01593c8>] (register_restart_handler) from [<c08676c8>] (__watchdog_register_device+0x13c/0x27c)
[    3.603889] [<c08676c8>] (__watchdog_register_device) from [<c0867868>] (watchdog_register_device+0x60/0xb4)
[    3.613764] [<c0867868>] (watchdog_register_device) from [<c08678f8>] (devm_watchdog_register_device+0x3c/0x84)
[    3.623898] [<c08678f8>] (devm_watchdog_register_device) from [<c1146454>] (imx2_wdt_probe+0x254/0x2ac)
[    3.633346] [<c1146454>] (imx2_wdt_probe) from [<c06feb74>] (platform_probe+0x58/0xb8)
[    3.641314] [<c06feb74>] (platform_probe) from [<c06fb2f8>] (call_driver_probe+0x24/0x108)
[    3.649636] [<c06fb2f8>] (call_driver_probe) from [<c06fbe08>] (really_probe.part.0+0xa8/0x358)
[    3.658384] [<c06fbe08>] (really_probe.part.0) from [<c06fc1c4>] (__driver_probe_device+0x94/0x208)
[    3.667470] [<c06fc1c4>] (__driver_probe_device) from [<c06fc368>] (driver_probe_device+0x30/0xc8)
[    3.676468] [<c06fc368>] (driver_probe_device) from [<c06fcb0c>] (__driver_attach+0xe0/0x1c4)
[    3.685032] [<c06fcb0c>] (__driver_attach) from [<c06f9a20>] (bus_for_each_dev+0x74/0xc0)
[    3.693253] [<c06f9a20>] (bus_for_each_dev) from [<c06faeb8>] (bus_add_driver+0x100/0x208)
[    3.701563] [<c06faeb8>] (bus_add_driver) from [<c06fd8a0>] (driver_register+0x88/0x118)
[    3.709696] [<c06fd8a0>] (driver_register) from [<c06fe920>] (__platform_driver_probe+0x44/0xdc)
[    3.718522] [<c06fe920>] (__platform_driver_probe) from [<c01022ac>] (do_one_initcall+0x78/0x388)
[    3.727444] [<c01022ac>] (do_one_initcall) from [<c1101708>] (do_initcalls+0xcc/0x110)
[    3.735413] [<c1101708>] (do_initcalls) from [<c110198c>] (kernel_init_freeable+0x1ec/0x250)
[    3.743896] [<c110198c>] (kernel_init_freeable) from [<c0bfe724>] (kernel_init+0x10/0x128)
[    3.752224] [<c0bfe724>] (kernel_init) from [<c010011c>] (ret_from_fork+0x14/0x38)
[    3.759844] Exception stack(0xc40adfb0 to 0xc40adff8)
[    3.764933] dfa0:                                     00000000 00000000 00000000 00000000
[    3.773143] dfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    3.781351] dfe0: 00000000 00000000 00000000 00000000 00000013 00000000
[    3.788347] irq event stamp: 143613
[    3.792102] hardirqs last  enabled at (143623): [<c01a3ebc>] __up_console_sem+0x50/0x60
[    3.800397] hardirqs last disabled at (143632): [<c01a3ea8>] __up_console_sem+0x3c/0x60
[    3.808491] softirqs last  enabled at (143612): [<c0101518>] __do_softirq+0x2f8/0x5b0
[    3.816591] softirqs last disabled at (143603): [<c01307dc>] __irq_exit_rcu+0x160/0x1d8
[    3.825014] ---[ end trace 7f6709d2c89774b4 ]---

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler()
  2021-11-06 20:54   ` Jonathan Neuschäfer
@ 2021-11-07 16:53     ` Dmitry Osipenko
  2021-11-07 17:08       ` Guenter Roeck
  0 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-11-07 16:53 UTC (permalink / raw)
  To: Jonathan Neuschäfer
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Guenter Roeck, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson, Catalin Marinas,
	Will Deacon, Guo Ren, Geert Uytterhoeven, Greg Ungerer,
	Joshua Thompson, Thomas Bogendoerfer, Nick Hu, Greentime Hu,
	Vincent Chen, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai, Tony Lindgren,
	Liam Girdwood, Philipp Zabel, Vladimir Zapolskiy, Avi Fishman,
	Tomer Maimon, Tali Perry, Patrick Venture, Nancy Yuen,
	Benjamin Fair, Pavel Machek, linux-arm-kernel, linux-kernel,
	linux-csky, linux-ia64, linux-m68k, linux-mips, linux-parisc,
	linuxppc-dev, linux-riscv, linux-sh, xen-devel, linux-acpi,
	linux-omap, openbmc, linux-tegra, linux-pm

06.11.2021 23:54, Jonathan Neuschäfer пишет:
> Hi,
> 
> On Thu, Oct 28, 2021 at 12:16:57AM +0300, Dmitry Osipenko wrote:
>> Use devm_register_power_handler() that replaces global pm_power_off
>> variable and allows to register multiple power-off handlers. It also
>> provides restart-handler support, i.e. all in one API.
>>
>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>> ---
> 
> When I boot with (most of) this patchset applied, I get the warning at
> kernel/reboot.c:187:
> 
> 	/*
> 	 * Handler must have unique priority. Otherwise call order is
> 	 * determined by registration order, which is unreliable.
> 	 */
> 	WARN_ON(!atomic_notifier_has_unique_priority(&restart_handler_list, nb));
> 
> As the NTXEC driver doesn't specify a priority, I think this is an issue
> to be fixed elsewhere.
> 
> Other than that, it works and looks good, as far as I can tell.
> 
> 
> For this patch:
> 
> Reviewed-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
> Tested-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>

Thank you. You have conflicting restart handlers, apparently NTXEC
driver should have higher priority than the watchdog driver. It should
be a common problem for the watchdog drivers, I will lower watchdog's
default priority to fix it.

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

* Re: [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler()
  2021-11-07 16:53     ` Dmitry Osipenko
@ 2021-11-07 17:08       ` Guenter Roeck
  2021-11-07 17:16         ` Dmitry Osipenko
  0 siblings, 1 reply; 71+ messages in thread
From: Guenter Roeck @ 2021-11-07 17:08 UTC (permalink / raw)
  To: Dmitry Osipenko, Jonathan Neuschäfer
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Russell King, Daniel Lezcano,
	Andy Shevchenko, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	Helge Deller, Michael Ellerman, Benjamin Herrenschmidt,
	Paul Mackerras, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Yoshinori Sato, Rich Felker, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, Len Brown,
	Santosh Shilimkar, Krzysztof Kozlowski, Linus Walleij,
	Chen-Yu Tsai, Tony Lindgren, Liam Girdwood, Philipp Zabel,
	Vladimir Zapolskiy, Avi Fishman, Tomer Maimon, Tali Perry,
	Patrick Venture, Nancy Yuen, Benjamin Fair, Pavel Machek,
	linux-arm-kernel, linux-kernel, linux-csky, linux-ia64,
	linux-m68k, linux-mips, linux-parisc, linuxppc-dev, linux-riscv,
	linux-sh, xen-devel, linux-acpi, linux-omap, openbmc,
	linux-tegra, linux-pm

On 11/7/21 8:53 AM, Dmitry Osipenko wrote:
> 06.11.2021 23:54, Jonathan Neuschäfer пишет:
>> Hi,
>>
>> On Thu, Oct 28, 2021 at 12:16:57AM +0300, Dmitry Osipenko wrote:
>>> Use devm_register_power_handler() that replaces global pm_power_off
>>> variable and allows to register multiple power-off handlers. It also
>>> provides restart-handler support, i.e. all in one API.
>>>
>>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>>> ---
>>
>> When I boot with (most of) this patchset applied, I get the warning at
>> kernel/reboot.c:187:
>>
>> 	/*
>> 	 * Handler must have unique priority. Otherwise call order is
>> 	 * determined by registration order, which is unreliable.
>> 	 */
>> 	WARN_ON(!atomic_notifier_has_unique_priority(&restart_handler_list, nb));
>>
>> As the NTXEC driver doesn't specify a priority, I think this is an issue
>> to be fixed elsewhere.
>>
>> Other than that, it works and looks good, as far as I can tell.
>>
>>
>> For this patch:
>>
>> Reviewed-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
>> Tested-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
> 
> Thank you. You have conflicting restart handlers, apparently NTXEC
> driver should have higher priority than the watchdog driver. It should
> be a common problem for the watchdog drivers, I will lower watchdog's
> default priority to fix it.
> 

The watchdog subsystem already uses "0" as default priority, which was
intended as priority of last resort for restart handlers. I do not see
a reason to change that.

Guenter

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

* Re: [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler()
  2021-11-07 17:08       ` Guenter Roeck
@ 2021-11-07 17:16         ` Dmitry Osipenko
  2021-11-07 17:32           ` Guenter Roeck
  0 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-11-07 17:16 UTC (permalink / raw)
  To: Guenter Roeck, Jonathan Neuschäfer
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Russell King, Daniel Lezcano,
	Andy Shevchenko, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	Helge Deller, Michael Ellerman, Benjamin Herrenschmidt,
	Paul Mackerras, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Yoshinori Sato, Rich Felker, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, Len Brown,
	Santosh Shilimkar, Krzysztof Kozlowski, Linus Walleij,
	Chen-Yu Tsai, Tony Lindgren, Liam Girdwood, Philipp Zabel,
	Vladimir Zapolskiy, Avi Fishman, Tomer Maimon, Tali Perry,
	Patrick Venture, Nancy Yuen, Benjamin Fair, Pavel Machek,
	linux-arm-kernel, linux-kernel, linux-csky, linux-ia64,
	linux-m68k, linux-mips, linux-parisc, linuxppc-dev, linux-riscv,
	linux-sh, xen-devel, linux-acpi, linux-omap, openbmc,
	linux-tegra, linux-pm

07.11.2021 20:08, Guenter Roeck пишет:
> On 11/7/21 8:53 AM, Dmitry Osipenko wrote:
>> 06.11.2021 23:54, Jonathan Neuschäfer пишет:
>>> Hi,
>>>
>>> On Thu, Oct 28, 2021 at 12:16:57AM +0300, Dmitry Osipenko wrote:
>>>> Use devm_register_power_handler() that replaces global pm_power_off
>>>> variable and allows to register multiple power-off handlers. It also
>>>> provides restart-handler support, i.e. all in one API.
>>>>
>>>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>>>> ---
>>>
>>> When I boot with (most of) this patchset applied, I get the warning at
>>> kernel/reboot.c:187:
>>>
>>>     /*
>>>      * Handler must have unique priority. Otherwise call order is
>>>      * determined by registration order, which is unreliable.
>>>      */
>>>     WARN_ON(!atomic_notifier_has_unique_priority(&restart_handler_list,
>>> nb));
>>>
>>> As the NTXEC driver doesn't specify a priority, I think this is an issue
>>> to be fixed elsewhere.
>>>
>>> Other than that, it works and looks good, as far as I can tell.
>>>
>>>
>>> For this patch:
>>>
>>> Reviewed-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
>>> Tested-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
>>
>> Thank you. You have conflicting restart handlers, apparently NTXEC
>> driver should have higher priority than the watchdog driver. It should
>> be a common problem for the watchdog drivers, I will lower watchdog's
>> default priority to fix it.
>>
> 
> The watchdog subsystem already uses "0" as default priority, which was
> intended as priority of last resort for restart handlers. I do not see
> a reason to change that.

Right, I meant that watchdog drivers which use restart handler set the
level to the default 128 [1]. Although, maybe it's a problem only for
i.MX drivers in practice, I'll take a closer look at the other drivers.

[1]
https://elixir.bootlin.com/linux/latest/source/drivers/watchdog/imx2_wdt.c#L318

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

* Re: [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler()
  2021-11-07 17:16         ` Dmitry Osipenko
@ 2021-11-07 17:32           ` Guenter Roeck
  2021-11-07 17:42             ` Dmitry Osipenko
  0 siblings, 1 reply; 71+ messages in thread
From: Guenter Roeck @ 2021-11-07 17:32 UTC (permalink / raw)
  To: Dmitry Osipenko, Jonathan Neuschäfer
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Russell King, Daniel Lezcano,
	Andy Shevchenko, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	Helge Deller, Michael Ellerman, Benjamin Herrenschmidt,
	Paul Mackerras, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Yoshinori Sato, Rich Felker, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, Len Brown,
	Santosh Shilimkar, Krzysztof Kozlowski, Linus Walleij,
	Chen-Yu Tsai, Tony Lindgren, Liam Girdwood, Philipp Zabel,
	Vladimir Zapolskiy, Avi Fishman, Tomer Maimon, Tali Perry,
	Patrick Venture, Nancy Yuen, Benjamin Fair, Pavel Machek,
	linux-arm-kernel, linux-kernel, linux-csky, linux-ia64,
	linux-m68k, linux-mips, linux-parisc, linuxppc-dev, linux-riscv,
	linux-sh, xen-devel, linux-acpi, linux-omap, openbmc,
	linux-tegra, linux-pm

On 11/7/21 9:16 AM, Dmitry Osipenko wrote:
> 07.11.2021 20:08, Guenter Roeck пишет:
>> On 11/7/21 8:53 AM, Dmitry Osipenko wrote:
>>> 06.11.2021 23:54, Jonathan Neuschäfer пишет:
>>>> Hi,
>>>>
>>>> On Thu, Oct 28, 2021 at 12:16:57AM +0300, Dmitry Osipenko wrote:
>>>>> Use devm_register_power_handler() that replaces global pm_power_off
>>>>> variable and allows to register multiple power-off handlers. It also
>>>>> provides restart-handler support, i.e. all in one API.
>>>>>
>>>>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>>>>> ---
>>>>
>>>> When I boot with (most of) this patchset applied, I get the warning at
>>>> kernel/reboot.c:187:
>>>>
>>>>      /*
>>>>       * Handler must have unique priority. Otherwise call order is
>>>>       * determined by registration order, which is unreliable.
>>>>       */
>>>>      WARN_ON(!atomic_notifier_has_unique_priority(&restart_handler_list,
>>>> nb));
>>>>
>>>> As the NTXEC driver doesn't specify a priority, I think this is an issue
>>>> to be fixed elsewhere.
>>>>
>>>> Other than that, it works and looks good, as far as I can tell.
>>>>
>>>>
>>>> For this patch:
>>>>
>>>> Reviewed-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
>>>> Tested-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
>>>
>>> Thank you. You have conflicting restart handlers, apparently NTXEC
>>> driver should have higher priority than the watchdog driver. It should
>>> be a common problem for the watchdog drivers, I will lower watchdog's
>>> default priority to fix it.
>>>
>>
>> The watchdog subsystem already uses "0" as default priority, which was
>> intended as priority of last resort for restart handlers. I do not see
>> a reason to change that.
> 
> Right, I meant that watchdog drivers which use restart handler set the
> level to the default 128 [1]. Although, maybe it's a problem only for
> i.MX drivers in practice, I'll take a closer look at the other drivers.
> 

They don't have to do that. The default is priority 0. It is the decision
of the driver author to set the watchdog's restart priority. So it is wrong
to claim that this would be "a common problem for the watchdog drivers",
because it isn't. Presumably there was a reason for the driver author
to select the default priority of 128. If there is a platform which has
a better means to restart the system, it should select a priority of
129 or higher instead of affecting _all_ platforms using the imx watchdog
to reset the system.

Sure, you can negotiate that with the driver author, but the default should
really be to change the priority for less affected platforms.

Guenter

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

* Re: [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler()
  2021-11-07 17:32           ` Guenter Roeck
@ 2021-11-07 17:42             ` Dmitry Osipenko
  2021-11-08 11:22               ` Jonathan Neuschäfer
  0 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-11-07 17:42 UTC (permalink / raw)
  To: Guenter Roeck, Jonathan Neuschäfer
  Cc: Thierry Reding, Jonathan Hunter, Lee Jones, Rafael J . Wysocki,
	Mark Brown, Andrew Morton, Russell King, Daniel Lezcano,
	Andy Shevchenko, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	Helge Deller, Michael Ellerman, Benjamin Herrenschmidt,
	Paul Mackerras, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Yoshinori Sato, Rich Felker, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, Len Brown,
	Santosh Shilimkar, Krzysztof Kozlowski, Linus Walleij,
	Chen-Yu Tsai, Tony Lindgren, Liam Girdwood, Philipp Zabel,
	Vladimir Zapolskiy, Avi Fishman, Tomer Maimon, Tali Perry,
	Patrick Venture, Nancy Yuen, Benjamin Fair, Pavel Machek,
	linux-arm-kernel, linux-kernel, linux-csky, linux-ia64,
	linux-m68k, linux-mips, linux-parisc, linuxppc-dev, linux-riscv,
	linux-sh, xen-devel, linux-acpi, linux-omap, openbmc,
	linux-tegra, linux-pm

07.11.2021 20:32, Guenter Roeck пишет:
> On 11/7/21 9:16 AM, Dmitry Osipenko wrote:
>> 07.11.2021 20:08, Guenter Roeck пишет:
>>> On 11/7/21 8:53 AM, Dmitry Osipenko wrote:
>>>> 06.11.2021 23:54, Jonathan Neuschäfer пишет:
>>>>> Hi,
>>>>>
>>>>> On Thu, Oct 28, 2021 at 12:16:57AM +0300, Dmitry Osipenko wrote:
>>>>>> Use devm_register_power_handler() that replaces global pm_power_off
>>>>>> variable and allows to register multiple power-off handlers. It also
>>>>>> provides restart-handler support, i.e. all in one API.
>>>>>>
>>>>>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>>>>>> ---
>>>>>
>>>>> When I boot with (most of) this patchset applied, I get the warning at
>>>>> kernel/reboot.c:187:
>>>>>
>>>>>      /*
>>>>>       * Handler must have unique priority. Otherwise call order is
>>>>>       * determined by registration order, which is unreliable.
>>>>>       */
>>>>>      WARN_ON(!atomic_notifier_has_unique_priority(&restart_handler_list,
>>>>>
>>>>> nb));
>>>>>
>>>>> As the NTXEC driver doesn't specify a priority, I think this is an
>>>>> issue
>>>>> to be fixed elsewhere.
>>>>>
>>>>> Other than that, it works and looks good, as far as I can tell.
>>>>>
>>>>>
>>>>> For this patch:
>>>>>
>>>>> Reviewed-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
>>>>> Tested-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
>>>>
>>>> Thank you. You have conflicting restart handlers, apparently NTXEC
>>>> driver should have higher priority than the watchdog driver. It should
>>>> be a common problem for the watchdog drivers, I will lower watchdog's
>>>> default priority to fix it.
>>>>
>>>
>>> The watchdog subsystem already uses "0" as default priority, which was
>>> intended as priority of last resort for restart handlers. I do not see
>>> a reason to change that.
>>
>> Right, I meant that watchdog drivers which use restart handler set the
>> level to the default 128 [1]. Although, maybe it's a problem only for
>> i.MX drivers in practice, I'll take a closer look at the other drivers.
>>
> 
> They don't have to do that. The default is priority 0. It is the decision
> of the driver author to set the watchdog's restart priority. So it is wrong
> to claim that this would be "a common problem for the watchdog drivers",
> because it isn't. Presumably there was a reason for the driver author
> to select the default priority of 128. If there is a platform which has
> a better means to restart the system, it should select a priority of
> 129 or higher instead of affecting _all_ platforms using the imx watchdog
> to reset the system.
> 
> Sure, you can negotiate that with the driver author, but the default should
> really be to change the priority for less affected platforms.

Yes, looks like there is no common problem for watchdog drivers.
Initially I was recalling that watchdog core uses 128 by default and
typed the message without verifying it. I see now that it's incorrect,
my bad.

EC drivers tend to use higher priority in general. Jonathan, could you
please confirm that NTXEC driver is a more preferable restart method
than the watchdog?

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

* Re: [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler()
  2021-11-07 17:42             ` Dmitry Osipenko
@ 2021-11-08 11:22               ` Jonathan Neuschäfer
  2021-11-08 11:36                 ` Dmitry Osipenko
  0 siblings, 1 reply; 71+ messages in thread
From: Jonathan Neuschäfer @ 2021-11-08 11:22 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Guenter Roeck, Jonathan Neuschäfer, Thierry Reding,
	Jonathan Hunter, Lee Jones, Rafael J . Wysocki, Mark Brown,
	Andrew Morton, Russell King, Daniel Lezcano, Andy Shevchenko,
	Ulf Hansson, Catalin Marinas, Will Deacon, Guo Ren,
	Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	Helge Deller, Michael Ellerman, Benjamin Herrenschmidt,
	Paul Mackerras, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Yoshinori Sato, Rich Felker, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, Len Brown,
	Santosh Shilimkar, Krzysztof Kozlowski, Linus Walleij,
	Chen-Yu Tsai, Tony Lindgren, Liam Girdwood, Philipp Zabel,
	Vladimir Zapolskiy, Avi Fishman, Tomer Maimon, Tali Perry,
	Patrick Venture, Nancy Yuen, Benjamin Fair, Pavel Machek,
	linux-arm-kernel, linux-kernel, linux-csky, linux-ia64,
	linux-m68k, linux-mips, linux-parisc, linuxppc-dev, linux-riscv,
	linux-sh, xen-devel, linux-acpi, linux-omap, openbmc,
	linux-tegra, linux-pm

[-- Attachment #1: Type: text/plain, Size: 366 bytes --]

On Sun, Nov 07, 2021 at 08:42:33PM +0300, Dmitry Osipenko wrote:
[...]
> EC drivers tend to use higher priority in general. Jonathan, could you
> please confirm that NTXEC driver is a more preferable restart method
> than the watchdog?

Yes. The original firmware uses the NTXEC to restart, and it works well,
so I do think it's preferable.


Best regards,
Jonathan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler()
  2021-11-08 11:22               ` Jonathan Neuschäfer
@ 2021-11-08 11:36                 ` Dmitry Osipenko
  2021-11-10 10:43                   ` Jonathan Neuschäfer
  0 siblings, 1 reply; 71+ messages in thread
From: Dmitry Osipenko @ 2021-11-08 11:36 UTC (permalink / raw)
  To: Jonathan Neuschäfer
  Cc: Guenter Roeck, Thierry Reding, Jonathan Hunter, Lee Jones,
	Rafael J . Wysocki, Mark Brown, Andrew Morton, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson, Catalin Marinas,
	Will Deacon, Guo Ren, Geert Uytterhoeven, Greg Ungerer,
	Joshua Thompson, Thomas Bogendoerfer, Nick Hu, Greentime Hu,
	Vincent Chen, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai, Tony Lindgren,
	Liam Girdwood, Philipp Zabel, Vladimir Zapolskiy, Avi Fishman,
	Tomer Maimon, Tali Perry, Patrick Venture, Nancy Yuen,
	Benjamin Fair, Pavel Machek, linux-arm-kernel, linux-kernel,
	linux-csky, linux-ia64, linux-m68k, linux-mips, linux-parisc,
	linuxppc-dev, linux-riscv, linux-sh, xen-devel, linux-acpi,
	linux-omap, openbmc, linux-tegra, linux-pm

08.11.2021 14:22, Jonathan Neuschäfer пишет:
> On Sun, Nov 07, 2021 at 08:42:33PM +0300, Dmitry Osipenko wrote:
> [...]
>> EC drivers tend to use higher priority in general. Jonathan, could you
>> please confirm that NTXEC driver is a more preferable restart method
>> than the watchdog?
> 
> Yes. The original firmware uses the NTXEC to restart, and it works well,
> so I do think it's preferable.

Thank you, then I'll update the NTXEC patch like this:

https://github.com/grate-driver/linux/commit/22da3d91f1734d9a0ed036220ad4ea28465af988


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

* Re: [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler()
  2021-11-08 11:36                 ` Dmitry Osipenko
@ 2021-11-10 10:43                   ` Jonathan Neuschäfer
  2021-11-10 13:38                     ` Dmitry Osipenko
  0 siblings, 1 reply; 71+ messages in thread
From: Jonathan Neuschäfer @ 2021-11-10 10:43 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Jonathan Neuschäfer, Guenter Roeck, Thierry Reding,
	Jonathan Hunter, Lee Jones, Rafael J . Wysocki, Mark Brown,
	Andrew Morton, Russell King, Daniel Lezcano, Andy Shevchenko,
	Ulf Hansson, Catalin Marinas, Will Deacon, Guo Ren,
	Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	Helge Deller, Michael Ellerman, Benjamin Herrenschmidt,
	Paul Mackerras, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Yoshinori Sato, Rich Felker, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, Len Brown,
	Santosh Shilimkar, Krzysztof Kozlowski, Linus Walleij,
	Chen-Yu Tsai, Tony Lindgren, Liam Girdwood, Philipp Zabel,
	Vladimir Zapolskiy, Avi Fishman, Tomer Maimon, Tali Perry,
	Patrick Venture, Nancy Yuen, Benjamin Fair, Pavel Machek,
	linux-arm-kernel, linux-kernel, linux-csky, linux-ia64,
	linux-m68k, linux-mips, linux-parisc, linuxppc-dev, linux-riscv,
	linux-sh, xen-devel, linux-acpi, linux-omap, openbmc,
	linux-tegra, linux-pm

[-- Attachment #1: Type: text/plain, Size: 1381 bytes --]

On Mon, Nov 08, 2021 at 02:36:42PM +0300, Dmitry Osipenko wrote:
> 08.11.2021 14:22, Jonathan Neuschäfer пишет:
> > On Sun, Nov 07, 2021 at 08:42:33PM +0300, Dmitry Osipenko wrote:
> > [...]
> >> EC drivers tend to use higher priority in general. Jonathan, could you
> >> please confirm that NTXEC driver is a more preferable restart method
> >> than the watchdog?
> > 
> > Yes. The original firmware uses the NTXEC to restart, and it works well,
> > so I do think it's preferable.
> 
> Thank you, then I'll update the NTXEC patch like this:
> 
> https://github.com/grate-driver/linux/commit/22da3d91f1734d9a0ed036220ad4ea28465af988

I tested again, but sys_off_handler_reboot called a bogus pointer
(probably reboot_prepare_cb). I think it was left uninitialized in
ntxec_probe, which uses devm_kmalloc. I guess we could switch it to
devm_kzalloc:

diff --git a/drivers/mfd/ntxec.c b/drivers/mfd/ntxec.c
index 1f55dfce14308..30364beb4b1d0 100644
--- a/drivers/mfd/ntxec.c
+++ b/drivers/mfd/ntxec.c
@@ -144,7 +144,7 @@ static int ntxec_probe(struct i2c_client *client)
 	const struct mfd_cell *subdevs;
 	size_t n_subdevs;
 
-	ec = devm_kmalloc(&client->dev, sizeof(*ec), GFP_KERNEL);
+	ec = devm_kzalloc(&client->dev, sizeof(*ec), GFP_KERNEL);
 	if (!ec)
 		return -ENOMEM;
 


With that done, it works flawlessly.


Thanks,
Jonathan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler()
  2021-11-10 10:43                   ` Jonathan Neuschäfer
@ 2021-11-10 13:38                     ` Dmitry Osipenko
  0 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-11-10 13:38 UTC (permalink / raw)
  To: Jonathan Neuschäfer
  Cc: Guenter Roeck, Thierry Reding, Jonathan Hunter, Lee Jones,
	Rafael J . Wysocki, Mark Brown, Andrew Morton, Russell King,
	Daniel Lezcano, Andy Shevchenko, Ulf Hansson, Catalin Marinas,
	Will Deacon, Guo Ren, Geert Uytterhoeven, Greg Ungerer,
	Joshua Thompson, Thomas Bogendoerfer, Nick Hu, Greentime Hu,
	Vincent Chen, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai, Tony Lindgren,
	Liam Girdwood, Philipp Zabel, Vladimir Zapolskiy, Avi Fishman,
	Tomer Maimon, Tali Perry, Patrick Venture, Nancy Yuen,
	Benjamin Fair, Pavel Machek, linux-arm-kernel, linux-kernel,
	linux-csky, linux-ia64, linux-m68k, linux-mips, linux-parisc,
	linuxppc-dev, linux-riscv, linux-sh, xen-devel, linux-acpi,
	linux-omap, openbmc, linux-tegra, linux-pm

10.11.2021 13:43, Jonathan Neuschäfer пишет:
> On Mon, Nov 08, 2021 at 02:36:42PM +0300, Dmitry Osipenko wrote:
>> 08.11.2021 14:22, Jonathan Neuschäfer пишет:
>>> On Sun, Nov 07, 2021 at 08:42:33PM +0300, Dmitry Osipenko wrote:
>>> [...]
>>>> EC drivers tend to use higher priority in general. Jonathan, could you
>>>> please confirm that NTXEC driver is a more preferable restart method
>>>> than the watchdog?
>>>
>>> Yes. The original firmware uses the NTXEC to restart, and it works well,
>>> so I do think it's preferable.
>>
>> Thank you, then I'll update the NTXEC patch like this:
>>
>> https://github.com/grate-driver/linux/commit/22da3d91f1734d9a0ed036220ad4ea28465af988
> 
> I tested again, but sys_off_handler_reboot called a bogus pointer
> (probably reboot_prepare_cb). I think it was left uninitialized in
> ntxec_probe, which uses devm_kmalloc. I guess we could switch it to
> devm_kzalloc:
> 
> diff --git a/drivers/mfd/ntxec.c b/drivers/mfd/ntxec.c
> index 1f55dfce14308..30364beb4b1d0 100644
> --- a/drivers/mfd/ntxec.c
> +++ b/drivers/mfd/ntxec.c
> @@ -144,7 +144,7 @@ static int ntxec_probe(struct i2c_client *client)
>  	const struct mfd_cell *subdevs;
>  	size_t n_subdevs;
>  
> -	ec = devm_kmalloc(&client->dev, sizeof(*ec), GFP_KERNEL);
> +	ec = devm_kzalloc(&client->dev, sizeof(*ec), GFP_KERNEL);
>  	if (!ec)
>  		return -ENOMEM;
>  
> 
> 
> With that done, it works flawlessly.

Good catch, thank you! I'll correct this patch and add yours t-b.


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

* Re: [PATCH v2 28/45] mfd: rn5t618: Use devm_register_power_handler()
  2021-10-27 21:16 ` [PATCH v2 28/45] mfd: rn5t618: " Dmitry Osipenko
@ 2021-11-29 11:55   ` Lee Jones
  2021-11-29 12:04     ` Dmitry Osipenko
  0 siblings, 1 reply; 71+ messages in thread
From: Lee Jones @ 2021-11-29 11:55 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Rafael J . Wysocki, Mark Brown,
	Andrew Morton, Guenter Roeck, Russell King, Daniel Lezcano,
	Andy Shevchenko, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

On Thu, 28 Oct 2021, Dmitry Osipenko wrote:

> Use devm_register_power_handler() that replaces global pm_power_off
> variable and allows to register multiple power-off handlers. It also
> provides restart-handler support, i.e. all in one API.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  drivers/mfd/rn5t618.c | 56 ++++++++++++++++---------------------------
>  1 file changed, 21 insertions(+), 35 deletions(-)

For my own reference (apply this as-is to your sign-off block):

  Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>

-- 
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH v2 28/45] mfd: rn5t618: Use devm_register_power_handler()
  2021-11-29 11:55   ` Lee Jones
@ 2021-11-29 12:04     ` Dmitry Osipenko
  0 siblings, 0 replies; 71+ messages in thread
From: Dmitry Osipenko @ 2021-11-29 12:04 UTC (permalink / raw)
  To: Lee Jones
  Cc: Thierry Reding, Jonathan Hunter, Rafael J . Wysocki, Mark Brown,
	Andrew Morton, Guenter Roeck, Russell King, Daniel Lezcano,
	Andy Shevchenko, Ulf Hansson, Catalin Marinas, Will Deacon,
	Guo Ren, Geert Uytterhoeven, Greg Ungerer, Joshua Thompson,
	Thomas Bogendoerfer, Nick Hu, Greentime Hu, Vincent Chen,
	James E.J. Bottomley, Helge Deller, Michael Ellerman,
	Benjamin Herrenschmidt, Paul Mackerras, Paul Walmsley,
	Palmer Dabbelt, Albert Ou, Yoshinori Sato, Rich Felker,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Boris Ostrovsky, Juergen Gross,
	Stefano Stabellini, Len Brown, Santosh Shilimkar,
	Krzysztof Kozlowski, Linus Walleij, Chen-Yu Tsai,
	Jonathan Neuschäfer, Tony Lindgren, Liam Girdwood,
	Philipp Zabel, Vladimir Zapolskiy, Avi Fishman, Tomer Maimon,
	Tali Perry, Patrick Venture, Nancy Yuen, Benjamin Fair,
	Pavel Machek, linux-arm-kernel, linux-kernel, linux-csky,
	linux-ia64, linux-m68k, linux-mips, linux-parisc, linuxppc-dev,
	linux-riscv, linux-sh, xen-devel, linux-acpi, linux-omap,
	openbmc, linux-tegra, linux-pm

29.11.2021 14:55, Lee Jones пишет:
> On Thu, 28 Oct 2021, Dmitry Osipenko wrote:
> 
>> Use devm_register_power_handler() that replaces global pm_power_off
>> variable and allows to register multiple power-off handlers. It also
>> provides restart-handler support, i.e. all in one API.
>>
>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>> ---
>>  drivers/mfd/rn5t618.c | 56 ++++++++++++++++---------------------------
>>  1 file changed, 21 insertions(+), 35 deletions(-)
> 
> For my own reference (apply this as-is to your sign-off block):
> 
>   Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>
> 

Thanks you. This and other driver patches will be slightly changed
because the power-handler was renamed to sys-off handler starting with
the v3 of this series, but yours ack still will be valid here.

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

end of thread, other threads:[~2021-11-29 13:22 UTC | newest]

Thread overview: 71+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 21:16 [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 01/45] notifier: Remove extern annotation from function prototypes Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 02/45] notifier: Add blocking_notifier_call_chain_empty() Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 03/45] notifier: Add atomic/blocking_notifier_has_unique_priority() Dmitry Osipenko
2021-10-28 11:00   ` Andy Shevchenko
2021-10-28 21:32     ` Dmitry Osipenko
2021-10-28 23:28       ` Dmitry Osipenko
2021-10-28 22:10     ` Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 04/45] reboot: Correct typo in a comment Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 05/45] reboot: Warn if restart handler has duplicated priority Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 06/45] reboot: Warn if unregister_restart_handler() fails Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 07/45] reboot: Remove extern annotation from function prototypes Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 08/45] kernel: Add combined power-off+restart handler call chain API Dmitry Osipenko
2021-10-28  9:53   ` Rafael J. Wysocki
2021-10-28 21:36     ` Dmitry Osipenko
2021-10-28  9:59   ` Rafael J. Wysocki
2021-10-28 21:58     ` Dmitry Osipenko
2021-10-28 21:59     ` Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 09/45] xen/x86: Use do_kernel_power_off() Dmitry Osipenko
2021-10-28  7:35   ` Juergen Gross
2021-10-27 21:16 ` [PATCH v2 10/45] ARM: " Dmitry Osipenko
2021-10-28 12:04   ` Russell King (Oracle)
2021-10-27 21:16 ` [PATCH v2 11/45] arm64: " Dmitry Osipenko
2021-11-01 13:28   ` Catalin Marinas
2021-10-27 21:16 ` [PATCH v2 12/45] csky: " Dmitry Osipenko
2021-11-01  1:57   ` Guo Ren
2021-10-27 21:16 ` [PATCH v2 13/45] ia64: " Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 14/45] mips: " Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 15/45] nds32: " Dmitry Osipenko
2021-10-28 12:20   ` Greentime Hu
2021-10-27 21:16 ` [PATCH v2 16/45] parisc: " Dmitry Osipenko
2021-10-28  6:38   ` Helge Deller
2021-10-27 21:16 ` [PATCH v2 17/45] powerpc: " Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 18/45] riscv: " Dmitry Osipenko
2021-10-27 23:09   ` Palmer Dabbelt
2021-10-27 21:16 ` [PATCH v2 19/45] sh: " Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 20/45] x86: " Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 21/45] m68k: Switch to new power-handler API Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 22/45] memory: emif: Use kernel_can_power_off() Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 23/45] ACPI: power: Switch to power-handler API Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 24/45] regulator: pfuze100: Use devm_register_power_handler() Dmitry Osipenko
2021-10-28 11:59   ` Mark Brown
2021-10-27 21:16 ` [PATCH v2 25/45] reboot: Remove pm_power_off_prepare() Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 26/45] soc/tegra: pmc: Utilize power-handler API to power off Nexus 7 properly Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 27/45] mfd: ntxec: Use devm_register_power_handler() Dmitry Osipenko
2021-11-06 20:54   ` Jonathan Neuschäfer
2021-11-07 16:53     ` Dmitry Osipenko
2021-11-07 17:08       ` Guenter Roeck
2021-11-07 17:16         ` Dmitry Osipenko
2021-11-07 17:32           ` Guenter Roeck
2021-11-07 17:42             ` Dmitry Osipenko
2021-11-08 11:22               ` Jonathan Neuschäfer
2021-11-08 11:36                 ` Dmitry Osipenko
2021-11-10 10:43                   ` Jonathan Neuschäfer
2021-11-10 13:38                     ` Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 28/45] mfd: rn5t618: " Dmitry Osipenko
2021-11-29 11:55   ` Lee Jones
2021-11-29 12:04     ` Dmitry Osipenko
2021-10-27 21:16 ` [PATCH v2 29/45] mfd: acer-a500: " Dmitry Osipenko
2021-10-27 21:17 ` [PATCH v2 30/45] mfd: ene-kb3930: " Dmitry Osipenko
2021-10-27 21:17 ` [PATCH v2 31/45] mfd: axp20x: Use register_simple_power_off_handler() Dmitry Osipenko
2021-10-27 21:17 ` [PATCH v2 32/45] mfd: retu: Use devm_register_simple_power_off_handler() Dmitry Osipenko
2021-10-27 21:17 ` [PATCH v2 33/45] mfd: rk808: " Dmitry Osipenko
2021-10-27 21:17 ` [PATCH v2 34/45] mfd: palmas: " Dmitry Osipenko
2021-10-27 21:17 ` [PATCH v2 35/45] mfd: max8907: " Dmitry Osipenko
2021-10-27 21:17 ` [PATCH v2 36/45] mfd: tps6586x: " Dmitry Osipenko
2021-10-27 21:17 ` [PATCH v2 37/45] mfd: tps65910: " Dmitry Osipenko
2021-10-27 21:17 ` [PATCH v2 38/45] mfd: max77620: " Dmitry Osipenko
2021-10-27 21:17 ` [PATCH v2 39/45] mfd: dm355evm_msp: Use devm_register_trivial_power_off_handler() Dmitry Osipenko
2021-10-27 21:17 ` [PATCH v2 40/45] mfd: twl4030: " Dmitry Osipenko
2021-10-28 22:05 ` [PATCH v2 00/45] Introduce power-off+restart call chain API Dmitry Osipenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).