reboot.c 3.0 KB

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