2 * Copyright (C) 2014 Intel Corporation; author Matt Fleming
3 * Copyright (c) 2014 Red Hat, Inc., Mark Salter <msalter@redhat.com>
6 #include <linux/reboot.h>
8 static void (*orig_pm_power_off)(void);
10 int efi_reboot_quirk_mode = -1;
12 void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
14 const char *str[] = { "cold", "warm", "shutdown", "platform" };
15 int efi_mode, cap_reset_mode;
17 if (!efi_enabled(EFI_RUNTIME_SERVICES))
20 switch (reboot_mode) {
23 efi_mode = EFI_RESET_WARM;
26 efi_mode = EFI_RESET_COLD;
31 * If a quirk forced an EFI reset mode, always use that.
33 if (efi_reboot_quirk_mode != -1)
34 efi_mode = efi_reboot_quirk_mode;
36 if (efi_capsule_pending(&cap_reset_mode)) {
37 if (efi_mode != cap_reset_mode)
38 printk(KERN_CRIT "efi: %s reset requested but pending "
39 "capsule update requires %s reset... Performing "
40 "%s reset.\n", str[efi_mode], str[cap_reset_mode],
42 efi_mode = cap_reset_mode;
45 efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL);
48 bool __weak efi_poweroff_required(void)
53 static void efi_power_off(void)
55 efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
57 * The above call should not return, if it does fall back to
58 * the original power off method (typically ACPI poweroff).
60 if (orig_pm_power_off)
64 static int __init efi_shutdown_init(void)
66 if (!efi_enabled(EFI_RUNTIME_SERVICES))
69 if (efi_poweroff_required()) {
70 orig_pm_power_off = pm_power_off;
71 pm_power_off = efi_power_off;
76 late_initcall(efi_shutdown_init);