reboot.c 3.0 KB

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