kernel/reboot: Introduce sys-off handler API
authorDmitry Osipenko <dmitry.osipenko@collabora.com>
Mon, 9 May 2022 23:32:11 +0000 (02:32 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 19 May 2022 17:30:30 +0000 (19:30 +0200)
commit232edc2f72f5beda3586360de6254d443820050a
treec3fb94f108b4b915d843099fdef906c8faad20cc
parentc82f898d873ce10d88f8d60b38c8dd19f1ed7c66
kernel/reboot: Introduce sys-off handler API

In order to support power-off chaining we need to get rid of the global
pm_* variables, replacing them with the new kernel API functions that
support chaining.

Introduce new generic sys-off handler API that brings the following
features:

1. Power-off and restart handlers are registered using same API function
   that supports chaining, hence all power-off and restart modes will
   support chaining using this unified function.

2. Prevents notifier priority collisions by disallowing registration of
   multiple handlers at the non-default priority level.

3. Supports passing opaque user argument to callback, which allows us to
   remove global variables from drivers.

This patch adds support of the following sys-off modes:

- SYS_OFF_MODE_POWER_OFF_PREPARE that replaces global pm_power_off_prepare
  variable and provides chaining support for power-off-prepare handlers.

- SYS_OFF_MODE_POWER_OFF that replaces global pm_power_off variable and
  provides chaining support for power-off handlers.

- SYS_OFF_MODE_RESTART that provides a better restart API, removing a need
  from drivers to have a global scratch variable by utilizing the opaque
  callback argument.

Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
include/linux/reboot.h
kernel/reboot.c