reboot.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. unsigned long flags;
  72. /* Stop the cpus and apics */
  73. #ifdef CONFIG_SMP
  74. int reboot_cpu_id;
  75. /* The boot cpu is always logical cpu 0 */
  76. reboot_cpu_id = 0;
  77. /* Make certain the cpu I'm about to reboot on is online */
  78. if (!cpu_isset(reboot_cpu_id, cpu_online_map)) {
  79. reboot_cpu_id = smp_processor_id();
  80. }
  81. /* Make certain I only run on the appropriate processor */
  82. set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id));
  83. /* O.K Now that I'm on the appropriate processor,
  84. * stop all of the others.
  85. */
  86. smp_send_stop();
  87. #endif
  88. local_irq_save(flags);
  89. #ifndef CONFIG_SMP
  90. disable_local_APIC();
  91. #endif
  92. disable_IO_APIC();
  93. local_irq_restore(flags);
  94. }
  95. void machine_emergency_restart(void)
  96. {
  97. int i;
  98. /* Tell the BIOS if we want cold or warm reboot */
  99. *((unsigned short *)__va(0x472)) = reboot_mode;
  100. for (;;) {
  101. /* Could also try the reset bit in the Hammer NB */
  102. switch (reboot_type) {
  103. case BOOT_KBD:
  104. for (i=0; i<10; i++) {
  105. kb_wait();
  106. udelay(50);
  107. outb(0xfe,0x64); /* pulse reset low */
  108. udelay(50);
  109. }
  110. case BOOT_TRIPLE:
  111. __asm__ __volatile__("lidt (%0)": :"r" (&no_idt));
  112. __asm__ __volatile__("int3");
  113. reboot_type = BOOT_KBD;
  114. break;
  115. }
  116. }
  117. }
  118. void machine_restart(char * __unused)
  119. {
  120. printk("machine restart\n");
  121. if (!reboot_force) {
  122. machine_shutdown();
  123. }
  124. machine_emergency_restart();
  125. }
  126. void machine_halt(void)
  127. {
  128. }
  129. void machine_power_off(void)
  130. {
  131. if (!reboot_force) {
  132. machine_shutdown();
  133. }
  134. if (pm_power_off)
  135. pm_power_off();
  136. }