Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 2014 Intel Corporation; author Matt Fleming
0004  * Copyright (c) 2014 Red Hat, Inc., Mark Salter <msalter@redhat.com>
0005  */
0006 #include <linux/efi.h>
0007 #include <linux/reboot.h>
0008 
0009 static struct sys_off_handler *efi_sys_off_handler;
0010 
0011 int efi_reboot_quirk_mode = -1;
0012 
0013 void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
0014 {
0015     const char *str[] = { "cold", "warm", "shutdown", "platform" };
0016     int efi_mode, cap_reset_mode;
0017 
0018     if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM))
0019         return;
0020 
0021     switch (reboot_mode) {
0022     case REBOOT_WARM:
0023     case REBOOT_SOFT:
0024         efi_mode = EFI_RESET_WARM;
0025         break;
0026     default:
0027         efi_mode = EFI_RESET_COLD;
0028         break;
0029     }
0030 
0031     /*
0032      * If a quirk forced an EFI reset mode, always use that.
0033      */
0034     if (efi_reboot_quirk_mode != -1)
0035         efi_mode = efi_reboot_quirk_mode;
0036 
0037     if (efi_capsule_pending(&cap_reset_mode)) {
0038         if (efi_mode != cap_reset_mode)
0039             printk(KERN_CRIT "efi: %s reset requested but pending "
0040                    "capsule update requires %s reset... Performing "
0041                    "%s reset.\n", str[efi_mode], str[cap_reset_mode],
0042                    str[cap_reset_mode]);
0043         efi_mode = cap_reset_mode;
0044     }
0045 
0046     efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL);
0047 }
0048 
0049 bool __weak efi_poweroff_required(void)
0050 {
0051     return false;
0052 }
0053 
0054 static int efi_power_off(struct sys_off_data *data)
0055 {
0056     efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
0057 
0058     return NOTIFY_DONE;
0059 }
0060 
0061 static int __init efi_shutdown_init(void)
0062 {
0063     if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM))
0064         return -ENODEV;
0065 
0066     if (efi_poweroff_required()) {
0067         /* SYS_OFF_PRIO_FIRMWARE + 1 so that it runs before acpi_power_off */
0068         efi_sys_off_handler =
0069             register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
0070                          SYS_OFF_PRIO_FIRMWARE + 1,
0071                          efi_power_off, NULL);
0072         if (IS_ERR(efi_sys_off_handler))
0073             return PTR_ERR(efi_sys_off_handler);
0074     }
0075 
0076     return 0;
0077 }
0078 late_initcall(efi_shutdown_init);