blob: 62ead9b9d871a606af7c0b575f382377f7f82aaa [file] [log] [blame]
Matt Fleming8562c992014-06-13 12:22:22 +01001/*
2 * Copyright (C) 2014 Intel Corporation; author Matt Fleming
3 * Copyright (c) 2014 Red Hat, Inc., Mark Salter <msalter@redhat.com>
4 */
5#include <linux/efi.h>
6#include <linux/reboot.h>
7
Matt Fleming44be28e2014-06-13 12:39:55 +01008int efi_reboot_quirk_mode = -1;
9
Matt Fleming8562c992014-06-13 12:22:22 +010010void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
11{
Matt Flemingf0133f32016-04-25 21:06:59 +010012 const char *str[] = { "cold", "warm", "shutdown", "platform" };
13 int efi_mode, cap_reset_mode;
Matt Fleming8562c992014-06-13 12:22:22 +010014
15 if (!efi_enabled(EFI_RUNTIME_SERVICES))
16 return;
17
18 switch (reboot_mode) {
19 case REBOOT_WARM:
20 case REBOOT_SOFT:
21 efi_mode = EFI_RESET_WARM;
22 break;
23 default:
24 efi_mode = EFI_RESET_COLD;
25 break;
26 }
27
Matt Fleming44be28e2014-06-13 12:39:55 +010028 /*
29 * If a quirk forced an EFI reset mode, always use that.
30 */
31 if (efi_reboot_quirk_mode != -1)
32 efi_mode = efi_reboot_quirk_mode;
33
Matt Flemingf0133f32016-04-25 21:06:59 +010034 if (efi_capsule_pending(&cap_reset_mode)) {
35 if (efi_mode != cap_reset_mode)
36 printk(KERN_CRIT "efi: %s reset requested but pending "
37 "capsule update requires %s reset... Performing "
38 "%s reset.\n", str[efi_mode], str[cap_reset_mode],
39 str[cap_reset_mode]);
40 efi_mode = cap_reset_mode;
41 }
42
Matt Fleming8562c992014-06-13 12:22:22 +010043 efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL);
44}
Matt Fleming0c5ed612014-06-13 12:35:21 +010045
46bool __weak efi_poweroff_required(void)
47{
48 return false;
49}
50
51static void efi_power_off(void)
52{
53 efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
54}
55
56static int __init efi_shutdown_init(void)
57{
58 if (!efi_enabled(EFI_RUNTIME_SERVICES))
59 return -ENODEV;
60
61 if (efi_poweroff_required())
62 pm_power_off = efi_power_off;
63
64 return 0;
65}
66late_initcall(efi_shutdown_init);