blob: 9c59d1c795d1f2d6787b9a3a248f384e4017e8f1 [file] [log] [blame]
Matt Fleming8562c99c2014-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 Fleming8562c99c2014-06-13 12:22:22 +010010void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
11{
12 int efi_mode;
13
14 if (!efi_enabled(EFI_RUNTIME_SERVICES))
15 return;
16
17 switch (reboot_mode) {
18 case REBOOT_WARM:
19 case REBOOT_SOFT:
20 efi_mode = EFI_RESET_WARM;
21 break;
22 default:
23 efi_mode = EFI_RESET_COLD;
24 break;
25 }
26
Matt Fleming44be28e2014-06-13 12:39:55 +010027 /*
28 * If a quirk forced an EFI reset mode, always use that.
29 */
30 if (efi_reboot_quirk_mode != -1)
31 efi_mode = efi_reboot_quirk_mode;
32
Matt Fleming8562c99c2014-06-13 12:22:22 +010033 efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL);
34}
Matt Fleming0c5ed612014-06-13 12:35:21 +010035
36bool __weak efi_poweroff_required(void)
37{
38 return false;
39}
40
41static void efi_power_off(void)
42{
43 efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
44}
45
46static int __init efi_shutdown_init(void)
47{
48 if (!efi_enabled(EFI_RUNTIME_SERVICES))
49 return -ENODEV;
50
51 if (efi_poweroff_required())
52 pm_power_off = efi_power_off;
53
54 return 0;
55}
56late_initcall(efi_shutdown_init);