reboot.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/pm.h>
  3. #include <linux/kexec.h>
  4. #include <linux/kernel.h>
  5. #include <linux/reboot.h>
  6. #include <linux/module.h>
  7. #ifdef CONFIG_SUPERH32
  8. #include <asm/watchdog.h>
  9. #endif
  10. #include <asm/addrspace.h>
  11. #include <asm/reboot.h>
  12. #include <asm/tlbflush.h>
  13. #include <asm/traps.h>
  14. void (*pm_power_off)(void);
  15. EXPORT_SYMBOL(pm_power_off);
  16. #ifdef CONFIG_SUPERH32
  17. static void watchdog_trigger_immediate(void)
  18. {
  19. sh_wdt_write_cnt(0xFF);
  20. sh_wdt_write_csr(0xC2);
  21. }
  22. #endif
  23. static void native_machine_restart(char * __unused)
  24. {
  25. local_irq_disable();
  26. /* Destroy all of the TLBs in preparation for reset by MMU */
  27. __flush_tlb_global();
  28. /* Address error with SR.BL=1 first. */
  29. trigger_address_error();
  30. #ifdef CONFIG_SUPERH32
  31. /* If that fails or is unsupported, go for the watchdog next. */
  32. watchdog_trigger_immediate();
  33. #endif
  34. /*
  35. * Give up and sleep.
  36. */
  37. while (1)
  38. cpu_sleep();
  39. }
  40. static void native_machine_shutdown(void)
  41. {
  42. smp_send_stop();
  43. }
  44. static void native_machine_power_off(void)
  45. {
  46. if (pm_power_off)
  47. pm_power_off();
  48. }
  49. static void native_machine_halt(void)
  50. {
  51. /* stop other cpus */
  52. machine_shutdown();
  53. /* stop this cpu */
  54. stop_this_cpu(NULL);
  55. }
  56. struct machine_ops machine_ops = {
  57. .power_off = native_machine_power_off,
  58. .shutdown = native_machine_shutdown,
  59. .restart = native_machine_restart,
  60. .halt = native_machine_halt,
  61. #ifdef CONFIG_KEXEC
  62. .crash_shutdown = native_machine_crash_shutdown,
  63. #endif
  64. };
  65. void machine_power_off(void)
  66. {
  67. machine_ops.power_off();
  68. }
  69. void machine_shutdown(void)
  70. {
  71. machine_ops.shutdown();
  72. }
  73. void machine_restart(char *cmd)
  74. {
  75. machine_ops.restart(cmd);
  76. }
  77. void machine_halt(void)
  78. {
  79. machine_ops.halt();
  80. }
  81. #ifdef CONFIG_KEXEC
  82. void machine_crash_shutdown(struct pt_regs *regs)
  83. {
  84. machine_ops.crash_shutdown(regs);
  85. }
  86. #endif