reboot.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. int efi_reboot_quirk_mode = -1;
  8. void efi_reboot(enum reboot_mode reboot_mode, const char *__unused)
  9. {
  10. int efi_mode;
  11. if (!efi_enabled(EFI_RUNTIME_SERVICES))
  12. return;
  13. switch (reboot_mode) {
  14. case REBOOT_WARM:
  15. case REBOOT_SOFT:
  16. efi_mode = EFI_RESET_WARM;
  17. break;
  18. default:
  19. efi_mode = EFI_RESET_COLD;
  20. break;
  21. }
  22. /*
  23. * If a quirk forced an EFI reset mode, always use that.
  24. */
  25. if (efi_reboot_quirk_mode != -1)
  26. efi_mode = efi_reboot_quirk_mode;
  27. efi.reset_system(efi_mode, EFI_SUCCESS, 0, NULL);
  28. }
  29. bool __weak efi_poweroff_required(void)
  30. {
  31. return false;
  32. }
  33. static void efi_power_off(void)
  34. {
  35. efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
  36. }
  37. static int __init efi_shutdown_init(void)
  38. {
  39. if (!efi_enabled(EFI_RUNTIME_SERVICES))
  40. return -ENODEV;
  41. if (efi_poweroff_required())
  42. pm_power_off = efi_power_off;
  43. return 0;
  44. }
  45. late_initcall(efi_shutdown_init);