reboot.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* Various gunk just to reboot the machine. */
  2. #include <linux/module.h>
  3. #include <linux/reboot.h>
  4. #include <linux/init.h>
  5. #include <linux/smp.h>
  6. #include <linux/kernel.h>
  7. #include <linux/ctype.h>
  8. #include <linux/string.h>
  9. #include <asm/io.h>
  10. #include <asm/kdebug.h>
  11. #include <asm/delay.h>
  12. #include <asm/hw_irq.h>
  13. #include <asm/system.h>
  14. #include <asm/pgtable.h>
  15. #include <asm/tlbflush.h>
  16. #include <asm/apic.h>
  17. /*
  18. * Power off function, if any
  19. */
  20. void (*pm_power_off)(void);
  21. static long no_idt[3];
  22. static enum {
  23. BOOT_TRIPLE = 't',
  24. BOOT_KBD = 'k'
  25. } reboot_type = BOOT_KBD;
  26. static int reboot_mode = 0;
  27. int reboot_force;
  28. /* reboot=t[riple] | k[bd] [, [w]arm | [c]old]
  29. warm Don't set the cold reboot flag
  30. cold Set the cold reboot flag
  31. triple Force a triple fault (init)
  32. kbd Use the keyboard controller. cold reset (default)
  33. force Avoid anything that could hang.
  34. */
  35. static int __init reboot_setup(char *str)
  36. {
  37. for (;;) {
  38. switch (*str) {
  39. case 'w':
  40. reboot_mode = 0x1234;
  41. break;
  42. case 'c':
  43. reboot_mode = 0;
  44. break;
  45. case 't':
  46. case 'b':
  47. case 'k':
  48. reboot_type = *str;
  49. break;
  50. case 'f':
  51. reboot_force = 1;
  52. break;
  53. }
  54. if((str = strchr(str,',')) != NULL)
  55. str++;
  56. else
  57. break;
  58. }
  59. return 1;
  60. }
  61. __setup("reboot=", reboot_setup);
  62. static inline void kb_wait(void)
  63. {
  64. int i;
  65. for (i=0; i<0x10000; i++)
  66. if ((inb_p(0x64) & 0x02) == 0)
  67. break;
  68. }
  69. void machine_shutdown(void)
  70. {
  71. /* Stop the cpus and apics */
  72. #ifdef CONFIG_SMP
  73. int reboot_cpu_id;
  74. /* The boot cpu is always logical cpu 0 */
  75. reboot_cpu_id = 0;
  76. /* Make certain the cpu I'm about to reboot on is online */
  77. if (!cpu_isset(reboot_cpu_id, cpu_online_map)) {
  78. reboot_cpu_id = smp_processor_id();
  79. }
  80. /* Make certain I only run on the appropriate processor */
  81. set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id));
  82. /* O.K Now that I'm on the appropriate processor,
  83. * stop all of the others.
  84. */
  85. smp_send_stop();
  86. #endif
  87. local_irq_disable();
  88. #ifndef CONFIG_SMP
  89. disable_local_APIC();
  90. #endif
  91. disable_IO_APIC();
  92. local_irq_enable();
  93. }
  94. void machine_emergency_restart(void)
  95. {
  96. int i;
  97. /* Tell the BIOS if we want cold or warm reboot */
  98. *((unsigned short *)__va(0x472)) = reboot_mode;
  99. for (;;) {
  100. /* Could also try the reset bit in the Hammer NB */
  101. switch (reboot_type) {
  102. case BOOT_KBD:
  103. for (i=0; i<100; i++) {
  104. kb_wait();
  105. udelay(50);
  106. outb(0xfe,0x64); /* pulse reset low */
  107. udelay(50);
  108. }
  109. case BOOT_TRIPLE:
  110. __asm__ __volatile__("lidt (%0)": :"r" (&no_idt));
  111. __asm__ __volatile__("int3");
  112. reboot_type = BOOT_KBD;
  113. break;
  114. }
  115. }
  116. }
  117. void machine_restart(char * __unused)
  118. {
  119. printk("machine restart\n");
  120. if (!reboot_force) {
  121. machine_shutdown();
  122. }
  123. machine_emergency_restart();
  124. }
  125. void machine_halt(void)
  126. {
  127. }
  128. void machine_power_off(void)
  129. {
  130. if (!reboot_force) {
  131. machine_shutdown();
  132. }
  133. if (pm_power_off)
  134. pm_power_off();
  135. }