Matt Fleming | 8562c99c | 2014-06-13 12:22:22 +0100 | [diff] [blame] | 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 | |
Matt Fleming | 44be28e | 2014-06-13 12:39:55 +0100 | [diff] [blame] | 8 | int efi_reboot_quirk_mode = -1; |
| 9 | |
Matt Fleming | 8562c99c | 2014-06-13 12:22:22 +0100 | [diff] [blame] | 10 | void 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 Fleming | 44be28e | 2014-06-13 12:39:55 +0100 | [diff] [blame] | 27 | /* |
| 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 Fleming | 8562c99c | 2014-06-13 12:22:22 +0100 | [diff] [blame] | 33 | efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL); |
| 34 | } |
Matt Fleming | 0c5ed61 | 2014-06-13 12:35:21 +0100 | [diff] [blame] | 35 | |
| 36 | bool __weak efi_poweroff_required(void) |
| 37 | { |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | static void efi_power_off(void) |
| 42 | { |
| 43 | efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL); |
| 44 | } |
| 45 | |
| 46 | static 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 | } |
| 56 | late_initcall(efi_shutdown_init); |