reboot.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2014 Intel Corporation; author Matt Fleming
  4. * Copyright (c) 2014 Red Hat, Inc., Mark Salter <msalter@redhat.com>
  5. */
  6. #include <linux/efi.h>
  7. #include <linux/reboot.h>
  8. static void (*orig_pm_power_off)(void);
  9. int efi_reboot_quirk_mode = -1;
  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. if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM))
  15. return;
  16. switch (reboot_mode) {
  17. case REBOOT_WARM:
  18. case REBOOT_SOFT:
  19. efi_mode = EFI_RESET_WARM;
  20. break;
  21. default:
  22. efi_mode = EFI_RESET_COLD;
  23. break;
  24. }
  25. /*
  26. * If a quirk forced an EFI reset mode, always use that.
  27. */
  28. if (efi_reboot_quirk_mode != -1)
  29. efi_mode = efi_reboot_quirk_mode;
  30. if (efi_capsule_pending(&cap_reset_mode)) {
  31. if (efi_mode != cap_reset_mode)
  32. printk(KERN_CRIT "efi: %s reset requested but pending "
  33. "capsule update requires %s reset... Performing "
  34. "%s reset.\n", str[efi_mode], str[cap_reset_mode],
  35. str[cap_reset_mode]);
  36. efi_mode = cap_reset_mode;
  37. }
  38. efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL);
  39. }
  40. bool __weak efi_poweroff_required(void)
  41. {
  42. return false;
  43. }
  44. static void efi_power_off(void)
  45. {
  46. efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
  47. /*
  48. * The above call should not return, if it does fall back to
  49. * the original power off method (typically ACPI poweroff).
  50. */
  51. if (orig_pm_power_off)
  52. orig_pm_power_off();
  53. }
  54. static int __init efi_shutdown_init(void)
  55. {
  56. if (!efi_rt_services_supported(EFI_RT_SUPPORTED_RESET_SYSTEM))
  57. return -ENODEV;
  58. if (efi_poweroff_required()) {
  59. orig_pm_power_off = pm_power_off;
  60. pm_power_off = efi_power_off;
  61. }
  62. return 0;
  63. }
  64. late_initcall(efi_shutdown_init);