reboot.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (C) 1996-2000 Russell King - Converted to ARM.
  3. * Original Copyright (C) 1995 Linus Torvalds
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/console.h>
  10. #include <linux/cpu.h>
  11. #include <linux/delay.h>
  12. #include <linux/reboot.h>
  13. #include <asm/cacheflush.h>
  14. #include <asm/idmap.h>
  15. #include "reboot.h"
  16. typedef void (*phys_reset_t)(unsigned long);
  17. /*
  18. * Function pointers to optional machine specific functions
  19. */
  20. void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
  21. void (*pm_power_off)(void);
  22. EXPORT_SYMBOL(pm_power_off);
  23. /*
  24. * A temporary stack to use for CPU reset. This is static so that we
  25. * don't clobber it with the identity mapping. When running with this
  26. * stack, any references to the current task *will not work* so you
  27. * should really do as little as possible before jumping to your reset
  28. * code.
  29. */
  30. static u64 soft_restart_stack[16];
  31. static void __soft_restart(void *addr)
  32. {
  33. phys_reset_t phys_reset;
  34. /* Take out a flat memory mapping. */
  35. setup_mm_for_reboot();
  36. /* Clean and invalidate caches */
  37. flush_cache_all();
  38. /* Turn off caching */
  39. cpu_proc_fin();
  40. /* Push out any further dirty data, and ensure cache is empty */
  41. flush_cache_all();
  42. /* Switch to the identity mapping. */
  43. phys_reset = (phys_reset_t)virt_to_idmap(cpu_reset);
  44. phys_reset((unsigned long)addr);
  45. /* Should never get here. */
  46. BUG();
  47. }
  48. void _soft_restart(unsigned long addr, bool disable_l2)
  49. {
  50. u64 *stack = soft_restart_stack + ARRAY_SIZE(soft_restart_stack);
  51. /* Disable interrupts first */
  52. raw_local_irq_disable();
  53. local_fiq_disable();
  54. /* Disable the L2 if we're the last man standing. */
  55. if (disable_l2)
  56. outer_disable();
  57. /* Change to the new stack and continue with the reset. */
  58. call_with_stack(__soft_restart, (void *)addr, (void *)stack);
  59. /* Should never get here. */
  60. BUG();
  61. }
  62. void soft_restart(unsigned long addr)
  63. {
  64. _soft_restart(addr, num_online_cpus() == 1);
  65. }
  66. /*
  67. * Called by kexec, immediately prior to machine_kexec().
  68. *
  69. * This must completely disable all secondary CPUs; simply causing those CPUs
  70. * to execute e.g. a RAM-based pin loop is not sufficient. This allows the
  71. * kexec'd kernel to use any and all RAM as it sees fit, without having to
  72. * avoid any code or data used by any SW CPU pin loop. The CPU hotplug
  73. * functionality embodied in disable_nonboot_cpus() to achieve this.
  74. */
  75. void machine_shutdown(void)
  76. {
  77. disable_nonboot_cpus();
  78. }
  79. /*
  80. * Halting simply requires that the secondary CPUs stop performing any
  81. * activity (executing tasks, handling interrupts). smp_send_stop()
  82. * achieves this.
  83. */
  84. void machine_halt(void)
  85. {
  86. local_irq_disable();
  87. smp_send_stop();
  88. while (1);
  89. }
  90. /*
  91. * Power-off simply requires that the secondary CPUs stop performing any
  92. * activity (executing tasks, handling interrupts). smp_send_stop()
  93. * achieves this. When the system power is turned off, it will take all CPUs
  94. * with it.
  95. */
  96. void machine_power_off(void)
  97. {
  98. local_irq_disable();
  99. smp_send_stop();
  100. if (pm_power_off)
  101. pm_power_off();
  102. }
  103. #ifdef CONFIG_ARM_FLUSH_CONSOLE_ON_RESTART
  104. void arm_machine_flush_console(void)
  105. {
  106. printk("\n");
  107. pr_emerg("Restarting %s\n", linux_banner);
  108. if (console_trylock()) {
  109. console_unlock();
  110. return;
  111. }
  112. mdelay(50);
  113. local_irq_disable();
  114. if (!console_trylock())
  115. pr_emerg("arm_restart: Console was locked! Busting\n");
  116. else
  117. pr_emerg("arm_restart: Console was locked!\n");
  118. console_unlock();
  119. }
  120. #else
  121. void arm_machine_flush_console(void)
  122. {
  123. }
  124. #endif
  125. /*
  126. * Restart requires that the secondary CPUs stop performing any activity
  127. * while the primary CPU resets the system. Systems with a single CPU can
  128. * use soft_restart() as their machine descriptor's .restart hook, since that
  129. * will cause the only available CPU to reset. Systems with multiple CPUs must
  130. * provide a HW restart implementation, to ensure that all CPUs reset at once.
  131. * This is required so that any code running after reset on the primary CPU
  132. * doesn't have to co-ordinate with other CPUs to ensure they aren't still
  133. * executing pre-reset code, and using RAM that the primary CPU's code wishes
  134. * to use. Implementing such co-ordination would be essentially impossible.
  135. */
  136. void machine_restart(char *cmd)
  137. {
  138. local_irq_disable();
  139. smp_send_stop();
  140. /* Flush the console to make sure all the relevant messages make it
  141. * out to the console drivers */
  142. arm_machine_flush_console();
  143. if (arm_pm_restart)
  144. arm_pm_restart(reboot_mode, cmd);
  145. else
  146. do_kernel_restart(cmd);
  147. /* Give a grace period for failure to restart of 1s */
  148. mdelay(1000);
  149. /* Whoops - the platform was unable to reboot. Tell the user! */
  150. printk("Reboot failed -- System halted\n");
  151. while (1);
  152. }