reboot.c 4.1 KB

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