reset.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2001, 06 by Ralf Baechle ([email protected])
  7. * Copyright (C) 2001 MIPS Technologies, Inc.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/export.h>
  11. #include <linux/pm.h>
  12. #include <linux/types.h>
  13. #include <linux/reboot.h>
  14. #include <linux/delay.h>
  15. #include <asm/compiler.h>
  16. #include <asm/idle.h>
  17. #include <asm/mipsregs.h>
  18. #include <asm/reboot.h>
  19. /*
  20. * Urgs ... Too many MIPS machines to handle this in a generic way.
  21. * So handle all using function pointers to machine specific
  22. * functions.
  23. */
  24. void (*_machine_restart)(char *command);
  25. void (*_machine_halt)(void);
  26. void (*pm_power_off)(void);
  27. EXPORT_SYMBOL(pm_power_off);
  28. static void machine_hang(void)
  29. {
  30. /*
  31. * We're hanging the system so we don't want to be interrupted anymore.
  32. * Any interrupt handlers that ran would at best be useless & at worst
  33. * go awry because the system isn't in a functional state.
  34. */
  35. local_irq_disable();
  36. /*
  37. * Mask all interrupts, giving us a better chance of remaining in the
  38. * low power wait state.
  39. */
  40. clear_c0_status(ST0_IM);
  41. while (true) {
  42. if (cpu_has_mips_r) {
  43. /*
  44. * We know that the wait instruction is supported so
  45. * make use of it directly, leaving interrupts
  46. * disabled.
  47. */
  48. asm volatile(
  49. ".set push\n\t"
  50. ".set " MIPS_ISA_ARCH_LEVEL "\n\t"
  51. "wait\n\t"
  52. ".set pop");
  53. } else if (cpu_wait) {
  54. /*
  55. * Try the cpu_wait() callback. This isn't ideal since
  56. * it'll re-enable interrupts, but that ought to be
  57. * harmless given that they're all masked.
  58. */
  59. cpu_wait();
  60. local_irq_disable();
  61. } else {
  62. /*
  63. * We're going to burn some power running round the
  64. * loop, but we don't really have a choice. This isn't
  65. * a path we should expect to run for long during
  66. * typical use anyway.
  67. */
  68. }
  69. /*
  70. * In most modern MIPS CPUs interrupts will cause the wait
  71. * instruction to graduate even when disabled, and in some
  72. * cases even when masked. In order to prevent a timer
  73. * interrupt from continuously taking us out of the low power
  74. * wait state, we clear any pending timer interrupt here.
  75. */
  76. if (cpu_has_counter)
  77. write_c0_compare(0);
  78. }
  79. }
  80. void machine_restart(char *command)
  81. {
  82. if (_machine_restart)
  83. _machine_restart(command);
  84. #ifdef CONFIG_SMP
  85. preempt_disable();
  86. smp_send_stop();
  87. #endif
  88. do_kernel_restart(command);
  89. mdelay(1000);
  90. pr_emerg("Reboot failed -- System halted\n");
  91. machine_hang();
  92. }
  93. void machine_halt(void)
  94. {
  95. if (_machine_halt)
  96. _machine_halt();
  97. #ifdef CONFIG_SMP
  98. preempt_disable();
  99. smp_send_stop();
  100. #endif
  101. machine_hang();
  102. }
  103. void machine_power_off(void)
  104. {
  105. do_kernel_power_off();
  106. #ifdef CONFIG_SMP
  107. preempt_disable();
  108. smp_send_stop();
  109. #endif
  110. machine_hang();
  111. }