Matt Fleming | 8562c99 | 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 | 8562c99 | 2014-06-13 12:22:22 +0100 | [diff] [blame] | 10 | void efi_reboot(enum reboot_mode reboot_mode, const char *__unused) |
| 11 | { |
Matt Fleming | f0133f3 | 2016-04-25 21:06:59 +0100 | [diff] [blame] | 12 | const char *str[] = { "cold", "warm", "shutdown", "platform" }; |
| 13 | int efi_mode, cap_reset_mode; |
Matt Fleming | 8562c99 | 2014-06-13 12:22:22 +0100 | [diff] [blame] | 14 | |
| 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 Fleming | 44be28e | 2014-06-13 12:39:55 +0100 | [diff] [blame] | 28 | /* |
| 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 Fleming | f0133f3 | 2016-04-25 21:06:59 +0100 | [diff] [blame] | 34 | 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 Fleming | 8562c99 | 2014-06-13 12:22:22 +0100 | [diff] [blame] | 43 | efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL); |
| 44 | } |
Matt Fleming | 0c5ed61 | 2014-06-13 12:35:21 +0100 | [diff] [blame] | 45 | |
| 46 | bool __weak efi_poweroff_required(void) |
| 47 | { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | static void efi_power_off(void) |
| 52 | { |
| 53 | efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL); |
| 54 | } |
| 55 | |
| 56 | static 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 | } |
| 66 | late_initcall(efi_shutdown_init); |