efi/reboot: Allow powering off machines using EFI
[cascardo/linux.git] / drivers / firmware / efi / reboot.c
1 /*
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
8 void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
9 {
10         int efi_mode;
11
12         if (!efi_enabled(EFI_RUNTIME_SERVICES))
13                 return;
14
15         switch (reboot_mode) {
16         case REBOOT_WARM:
17         case REBOOT_SOFT:
18                 efi_mode = EFI_RESET_WARM;
19                 break;
20         default:
21                 efi_mode = EFI_RESET_COLD;
22                 break;
23         }
24
25         efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL);
26 }
27
28 bool __weak efi_poweroff_required(void)
29 {
30         return false;
31 }
32
33 static void efi_power_off(void)
34 {
35         efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
36 }
37
38 static int __init efi_shutdown_init(void)
39 {
40         if (!efi_enabled(EFI_RUNTIME_SERVICES))
41                 return -ENODEV;
42
43         if (efi_poweroff_required())
44                 pm_power_off = efi_power_off;
45
46         return 0;
47 }
48 late_initcall(efi_shutdown_init);