Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / firmware / efi / reboot.c
blobceae84c19d226d911fbed1e891fdb87183a1bd4a
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2014 Intel Corporation; author Matt Fleming
4 * Copyright (c) 2014 Red Hat, Inc., Mark Salter <msalter@redhat.com>
5 */
6 #include <linux/efi.h>
7 #include <linux/reboot.h>
9 static struct sys_off_handler *efi_sys_off_handler;
11 int efi_reboot_quirk_mode = -1;
13 void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
15 const char *str[] = { "cold", "warm", "shutdown", "platform" };
16 int efi_mode, cap_reset_mode;
18 if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM))
19 return;
21 switch (reboot_mode) {
22 case REBOOT_WARM:
23 case REBOOT_SOFT:
24 efi_mode = EFI_RESET_WARM;
25 break;
26 default:
27 efi_mode = EFI_RESET_COLD;
28 break;
32 * If a quirk forced an EFI reset mode, always use that.
34 if (efi_reboot_quirk_mode != -1)
35 efi_mode = efi_reboot_quirk_mode;
37 if (efi_capsule_pending(&cap_reset_mode)) {
38 if (efi_mode != cap_reset_mode)
39 printk(KERN_CRIT "efi: %s reset requested but pending "
40 "capsule update requires %s reset... Performing "
41 "%s reset.\n", str[efi_mode], str[cap_reset_mode],
42 str[cap_reset_mode]);
43 efi_mode = cap_reset_mode;
46 efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL);
49 bool __weak efi_poweroff_required(void)
51 return false;
54 static int efi_power_off(struct sys_off_data *data)
56 efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
58 return NOTIFY_DONE;
61 static int __init efi_shutdown_init(void)
63 if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM))
64 return -ENODEV;
66 if (efi_poweroff_required()) {
67 /* SYS_OFF_PRIO_FIRMWARE + 1 so that it runs before acpi_power_off */
68 efi_sys_off_handler =
69 register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
70 SYS_OFF_PRIO_FIRMWARE + 1,
71 efi_power_off, NULL);
72 if (IS_ERR(efi_sys_off_handler))
73 return PTR_ERR(efi_sys_off_handler);
76 return 0;
78 late_initcall(efi_shutdown_init);