linux-stable/drivers/firmware/efi/reboot.c
Hans de Goede d40908f262 efi: Fix efi_power_off() not being run before acpi_power_off() when necessary
Commit 98f30d0ecf ("ACPI: power: Switch to sys-off handler API")
switched the ACPI sleep code from directly setting the old global
pm_power_off handler to using the new register_sys_off_handler()
mechanism with a priority of SYS_OFF_PRIO_FIRMWARE.

This is a problem when the old global pm_power_off handler would later
be overwritten, such as done by the late_initcall(efi_shutdown_init):

	if (efi_poweroff_required())
		pm_power_off = efi_power_off;

The old global pm_power_off handler gets run with a priority of
SYS_OFF_PRIO_DEFAULT which is lower then SYS_OFF_PRIO_FIRMWARE, causing
acpi_power_off() to run first, changing the behavior from before
the ACPI sleep code switched to the new register_sys_off_handler().

Switch the registering of efi_power_off over to register_sys_off_handler()
with a priority of SYS_OFF_PRIO_FIRMWARE + 1 so that it will run before
acpi_power_off() as before.

Note since the new sys-off-handler code will try all handlers in
priority order, there is no more need for the EFI code to store and
call the original pm_power_off handler.

Fixes: 98f30d0ecf ("ACPI: power: Switch to sys-off handler API")
Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20220708131412.81078-3-hdegoede@redhat.com
2022-07-10 17:41:06 +02:00

78 lines
1.9 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2014 Intel Corporation; author Matt Fleming
* Copyright (c) 2014 Red Hat, Inc., Mark Salter <msalter@redhat.com>
*/
#include <linux/efi.h>
#include <linux/reboot.h>
static struct sys_off_handler *efi_sys_off_handler;
int efi_reboot_quirk_mode = -1;
void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
{
const char *str[] = { "cold", "warm", "shutdown", "platform" };
int efi_mode, cap_reset_mode;
if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM))
return;
switch (reboot_mode) {
case REBOOT_WARM:
case REBOOT_SOFT:
efi_mode = EFI_RESET_WARM;
break;
default:
efi_mode = EFI_RESET_COLD;
break;
}
/*
* If a quirk forced an EFI reset mode, always use that.
*/
if (efi_reboot_quirk_mode != -1)
efi_mode = efi_reboot_quirk_mode;
if (efi_capsule_pending(&cap_reset_mode)) {
if (efi_mode != cap_reset_mode)
printk(KERN_CRIT "efi: %s reset requested but pending "
"capsule update requires %s reset... Performing "
"%s reset.\n", str[efi_mode], str[cap_reset_mode],
str[cap_reset_mode]);
efi_mode = cap_reset_mode;
}
efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL);
}
bool __weak efi_poweroff_required(void)
{
return false;
}
static int efi_power_off(struct sys_off_data *data)
{
efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
return NOTIFY_DONE;
}
static int __init efi_shutdown_init(void)
{
if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM))
return -ENODEV;
if (efi_poweroff_required()) {
/* SYS_OFF_PRIO_FIRMWARE + 1 so that it runs before acpi_power_off */
efi_sys_off_handler =
register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
SYS_OFF_PRIO_FIRMWARE + 1,
efi_power_off, NULL);
if (IS_ERR(efi_sys_off_handler))
return PTR_ERR(efi_sys_off_handler);
}
return 0;
}
late_initcall(efi_shutdown_init);