reboot.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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/cpu.h>
  10. #include <linux/delay.h>
  11. #include <linux/reboot.h>
  12. #include <asm/cacheflush.h>
  13. #include <asm/idmap.h>
  14. #include <asm/virt.h>
  15. #include "reboot.h"
  16. typedef void (*phys_reset_t)(unsigned long, bool);
  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. bool hvc = false;
  35. /* Take out a flat memory mapping. */
  36. setup_mm_for_reboot();
  37. /* Clean and invalidate caches */
  38. flush_cache_all();
  39. /* Turn off caching */
  40. cpu_proc_fin();
  41. /* Push out any further dirty data, and ensure cache is empty */
  42. flush_cache_all();
  43. /* Switch to the identity mapping. */
  44. phys_reset = (phys_reset_t)virt_to_idmap(cpu_reset);
  45. #ifdef CONFIG_ARM_VIRT_EXT
  46. /* original stub should be restored by kvm */
  47. hvc = is_hyp_mode_available();
  48. #endif
  49. phys_reset((unsigned long)addr, hvc);
  50. /* Should never get here. */
  51. BUG();
  52. }
  53. void _soft_restart(unsigned long addr, bool disable_l2)
  54. {
  55. u64 *stack = soft_restart_stack + ARRAY_SIZE(soft_restart_stack);
  56. /* Disable interrupts first */
  57. raw_local_irq_disable();
  58. local_fiq_disable();
  59. /* Disable the L2 if we're the last man standing. */
  60. if (disable_l2)
  61. outer_disable();
  62. /* Change to the new stack and continue with the reset. */
  63. call_with_stack(__soft_restart, (void *)addr, (void *)stack);
  64. /* Should never get here. */
  65. BUG();
  66. }
  67. void soft_restart(unsigned long addr)
  68. {
  69. _soft_restart(addr, num_online_cpus() == 1);
  70. }
  71. /*
  72. * Called by kexec, immediately prior to machine_kexec().
  73. *
  74. * This must completely disable all secondary CPUs; simply causing those CPUs
  75. * to execute e.g. a RAM-based pin loop is not sufficient. This allows the
  76. * kexec'd kernel to use any and all RAM as it sees fit, without having to
  77. * avoid any code or data used by any SW CPU pin loop. The CPU hotplug
  78. * functionality embodied in disable_nonboot_cpus() to achieve this.
  79. */
  80. void machine_shutdown(void)
  81. {
  82. disable_nonboot_cpus();
  83. }
  84. /*
  85. * Halting simply requires that the secondary CPUs stop performing any
  86. * activity (executing tasks, handling interrupts). smp_send_stop()
  87. * achieves this.
  88. */
  89. void machine_halt(void)
  90. {
  91. local_irq_disable();
  92. smp_send_stop();
  93. while (1);
  94. }
  95. /*
  96. * Power-off simply requires that the secondary CPUs stop performing any
  97. * activity (executing tasks, handling interrupts). smp_send_stop()
  98. * achieves this. When the system power is turned off, it will take all CPUs
  99. * with it.
  100. */
  101. void machine_power_off(void)
  102. {
  103. local_irq_disable();
  104. smp_send_stop();
  105. if (pm_power_off)
  106. pm_power_off();
  107. }
  108. /*
  109. * Restart requires that the secondary CPUs stop performing any activity
  110. * while the primary CPU resets the system. Systems with a single CPU can
  111. * use soft_restart() as their machine descriptor's .restart hook, since that
  112. * will cause the only available CPU to reset. Systems with multiple CPUs must
  113. * provide a HW restart implementation, to ensure that all CPUs reset at once.
  114. * This is required so that any code running after reset on the primary CPU
  115. * doesn't have to co-ordinate with other CPUs to ensure they aren't still
  116. * executing pre-reset code, and using RAM that the primary CPU's code wishes
  117. * to use. Implementing such co-ordination would be essentially impossible.
  118. */
  119. void machine_restart(char *cmd)
  120. {
  121. local_irq_disable();
  122. smp_send_stop();
  123. if (arm_pm_restart)
  124. arm_pm_restart(reboot_mode, cmd);
  125. else
  126. do_kernel_restart(cmd);
  127. /* Give a grace period for failure to restart of 1s */
  128. mdelay(1000);
  129. /* Whoops - the platform was unable to reboot. Tell the user! */
  130. printk("Reboot failed -- System halted\n");
  131. while (1);
  132. }