mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
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>
This commit is contained in:
committed by
Rafael J. Wysocki
parent
c82f898d87
commit
232edc2f72
@@ -7,6 +7,7 @@
|
||||
#include <uapi/linux/reboot.h>
|
||||
|
||||
struct device;
|
||||
struct sys_off_handler;
|
||||
|
||||
#define SYS_DOWN 0x0001 /* Notify of system down */
|
||||
#define SYS_RESTART SYS_DOWN
|
||||
@@ -62,6 +63,82 @@ extern void machine_shutdown(void);
|
||||
struct pt_regs;
|
||||
extern void machine_crash_shutdown(struct pt_regs *);
|
||||
|
||||
/*
|
||||
* sys-off handler API.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Standard sys-off priority levels. Users are expected to set priorities
|
||||
* relative to the standard levels.
|
||||
*
|
||||
* SYS_OFF_PRIO_PLATFORM: Use this for platform-level handlers.
|
||||
*
|
||||
* SYS_OFF_PRIO_LOW: Use this for handler of last resort.
|
||||
*
|
||||
* SYS_OFF_PRIO_DEFAULT: Use this for normal handlers.
|
||||
*
|
||||
* SYS_OFF_PRIO_HIGH: Use this for higher priority handlers.
|
||||
*
|
||||
* SYS_OFF_PRIO_FIRMWARE: Use this if handler uses firmware call.
|
||||
*/
|
||||
#define SYS_OFF_PRIO_PLATFORM -256
|
||||
#define SYS_OFF_PRIO_LOW -128
|
||||
#define SYS_OFF_PRIO_DEFAULT 0
|
||||
#define SYS_OFF_PRIO_HIGH 192
|
||||
#define SYS_OFF_PRIO_FIRMWARE 224
|
||||
|
||||
enum sys_off_mode {
|
||||
/**
|
||||
* @SYS_OFF_MODE_POWER_OFF_PREPARE:
|
||||
*
|
||||
* Handlers prepare system to be powered off. Handlers are
|
||||
* allowed to sleep.
|
||||
*/
|
||||
SYS_OFF_MODE_POWER_OFF_PREPARE,
|
||||
|
||||
/**
|
||||
* @SYS_OFF_MODE_POWER_OFF:
|
||||
*
|
||||
* Handlers power-off system. Handlers are disallowed to sleep.
|
||||
*/
|
||||
SYS_OFF_MODE_POWER_OFF,
|
||||
|
||||
/**
|
||||
* @SYS_OFF_MODE_RESTART:
|
||||
*
|
||||
* Handlers restart system. Handlers are disallowed to sleep.
|
||||
*/
|
||||
SYS_OFF_MODE_RESTART,
|
||||
};
|
||||
|
||||
/**
|
||||
* struct sys_off_data - sys-off callback argument
|
||||
*
|
||||
* @mode: Mode ID. Currently used only by the sys-off restart mode,
|
||||
* see enum reboot_mode for the available modes.
|
||||
* @cb_data: User's callback data.
|
||||
* @cmd: Command string. Currently used only by the sys-off restart mode,
|
||||
* NULL otherwise.
|
||||
*/
|
||||
struct sys_off_data {
|
||||
int mode;
|
||||
void *cb_data;
|
||||
const char *cmd;
|
||||
};
|
||||
|
||||
struct sys_off_handler *
|
||||
register_sys_off_handler(enum sys_off_mode mode,
|
||||
int priority,
|
||||
int (*callback)(struct sys_off_data *data),
|
||||
void *cb_data);
|
||||
void unregister_sys_off_handler(struct sys_off_handler *handler);
|
||||
|
||||
int devm_register_sys_off_handler(struct device *dev,
|
||||
enum sys_off_mode mode,
|
||||
int priority,
|
||||
int (*callback)(struct sys_off_data *data),
|
||||
void *cb_data);
|
||||
|
||||
/*
|
||||
* Architecture independent implemenations of sys_reboot commands.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user