reset.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include <asm/loongson.h>
  18. void (*pm_power_off)(void);
  19. EXPORT_SYMBOL(pm_power_off);
  20. void machine_halt(void)
  21. {
  22. #ifdef CONFIG_SMP
  23. preempt_disable();
  24. smp_send_stop();
  25. #endif
  26. local_irq_disable();
  27. clear_csr_ecfg(ECFG0_IM);
  28. pr_notice("\n\n** You can safely turn off the power now **\n\n");
  29. console_flush_on_panic(CONSOLE_FLUSH_PENDING);
  30. while (true) {
  31. __asm__ __volatile__("idle 0" : : : "memory");
  32. }
  33. }
  34. void machine_power_off(void)
  35. {
  36. #ifdef CONFIG_SMP
  37. preempt_disable();
  38. smp_send_stop();
  39. #endif
  40. #ifdef CONFIG_PM
  41. if (!acpi_disabled)
  42. enable_pci_wakeup();
  43. #endif
  44. do_kernel_power_off();
  45. #ifdef CONFIG_EFI
  46. efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
  47. #endif
  48. while (true) {
  49. __asm__ __volatile__("idle 0" : : : "memory");
  50. }
  51. }
  52. void machine_restart(char *command)
  53. {
  54. #ifdef CONFIG_SMP
  55. preempt_disable();
  56. smp_send_stop();
  57. #endif
  58. do_kernel_restart(command);
  59. #ifdef CONFIG_EFI
  60. if (efi_capsule_pending(NULL))
  61. efi_reboot(REBOOT_WARM, NULL);
  62. else
  63. efi_reboot(REBOOT_COLD, NULL);
  64. #endif
  65. if (!acpi_disabled)
  66. acpi_reboot();
  67. while (true) {
  68. __asm__ __volatile__("idle 0" : : : "memory");
  69. }
  70. }