reset.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/acpi.h>
  7. #include <linux/efi.h>
  8. #include <linux/export.h>
  9. #include <linux/pm.h>
  10. #include <linux/types.h>
  11. #include <linux/reboot.h>
  12. #include <linux/delay.h>
  13. #include <linux/console.h>
  14. #include <acpi/reboot.h>
  15. #include <asm/idle.h>
  16. #include <asm/loongarch.h>
  17. void (*pm_power_off)(void);
  18. EXPORT_SYMBOL(pm_power_off);
  19. void machine_halt(void)
  20. {
  21. #ifdef CONFIG_SMP
  22. preempt_disable();
  23. smp_send_stop();
  24. #endif
  25. local_irq_disable();
  26. clear_csr_ecfg(ECFG0_IM);
  27. pr_notice("\n\n** You can safely turn off the power now **\n\n");
  28. console_flush_on_panic(CONSOLE_FLUSH_PENDING);
  29. while (true) {
  30. __arch_cpu_idle();
  31. }
  32. }
  33. void machine_power_off(void)
  34. {
  35. #ifdef CONFIG_SMP
  36. preempt_disable();
  37. smp_send_stop();
  38. #endif
  39. do_kernel_power_off();
  40. #ifdef CONFIG_EFI
  41. efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
  42. #endif
  43. while (true) {
  44. __arch_cpu_idle();
  45. }
  46. }
  47. void machine_restart(char *command)
  48. {
  49. #ifdef CONFIG_SMP
  50. preempt_disable();
  51. smp_send_stop();
  52. #endif
  53. do_kernel_restart(command);
  54. #ifdef CONFIG_EFI
  55. if (efi_capsule_pending(NULL))
  56. efi_reboot(REBOOT_WARM, NULL);
  57. else
  58. efi_reboot(REBOOT_COLD, NULL);
  59. #endif
  60. if (!acpi_disabled)
  61. acpi_reboot();
  62. while (true) {
  63. __arch_cpu_idle();
  64. }
  65. }