reboot.c 1.7 KB

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