xref: /linux/drivers/firmware/efi/reboot.c (revision f3a8b6645dc2e60d11f20c1c23afd964ff4e55ae)
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 int efi_reboot_quirk_mode = -1;
9 
10 void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
11 {
12 	const char *str[] = { "cold", "warm", "shutdown", "platform" };
13 	int efi_mode, cap_reset_mode;
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 
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 
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 
43 	efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL);
44 }
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);
67