Skip to content

Commit

Permalink
kernel/reboot: Wrap legacy power-off callbacks into sys-off handlers
Browse files Browse the repository at this point in the history
Wrap legacy power-off callbacks into sys-off handlers in order to
support co-existence of both legacy and new callbacks while we're
in process of upgrading legacy callbacks to the new API.

Signed-off-by: Dmitry Osipenko <[email protected]>
Signed-off-by: Rafael J. Wysocki <[email protected]>
  • Loading branch information
digetx authored and rafaeljw committed May 19, 2022
1 parent 232edc2 commit 7b9a3de
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions kernel/reboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,47 @@ int devm_register_sys_off_handler(struct device *dev,
}
EXPORT_SYMBOL_GPL(devm_register_sys_off_handler);

static int legacy_pm_power_off_prepare(struct sys_off_data *data)
{
if (pm_power_off_prepare)
pm_power_off_prepare();

return NOTIFY_DONE;
}

static int legacy_pm_power_off(struct sys_off_data *data)
{
if (pm_power_off)
pm_power_off();

return NOTIFY_DONE;
}

/*
* Register sys-off handlers for legacy PM callbacks. This allows legacy
* PM callbacks co-exist with the new sys-off API.
*
* TODO: Remove legacy handlers once all legacy PM users will be switched
* to the sys-off based APIs.
*/
static int __init legacy_pm_init(void)
{
register_sys_off_handler(SYS_OFF_MODE_POWER_OFF_PREPARE,
SYS_OFF_PRIO_DEFAULT,
legacy_pm_power_off_prepare, NULL);

register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_DEFAULT,
legacy_pm_power_off, NULL);

return 0;
}
core_initcall(legacy_pm_init);

static void do_kernel_power_off_prepare(void)
{
blocking_notifier_call_chain(&power_off_prep_handler_list, 0, NULL);
}

/**
* kernel_power_off - power_off the system
*
Expand All @@ -471,8 +512,7 @@ EXPORT_SYMBOL_GPL(devm_register_sys_off_handler);
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");
Expand Down

0 comments on commit 7b9a3de

Please sign in to comment.