reboot.c 2.9 KB

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