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 <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_restart(char * __unused)
  95. {
  96. int i;
  97. printk("machine restart\n");
  98. machine_shutdown();
  99. if (!reboot_force) {
  100. local_irq_disable();
  101. #ifndef CONFIG_SMP
  102. disable_local_APIC();
  103. #endif
  104. disable_IO_APIC();
  105. local_irq_enable();
  106. }
  107. /* Tell the BIOS if we want cold or warm reboot */
  108. *((unsigned short *)__va(0x472)) = reboot_mode;
  109. for (;;) {
  110. /* Could also try the reset bit in the Hammer NB */
  111. switch (reboot_type) {
  112. case BOOT_KBD:
  113. for (i=0; i<100; i++) {
  114. kb_wait();
  115. udelay(50);
  116. outb(0xfe,0x64); /* pulse reset low */
  117. udelay(50);
  118. }
  119. case BOOT_TRIPLE:
  120. __asm__ __volatile__("lidt (%0)": :"r" (&no_idt));
  121. __asm__ __volatile__("int3");
  122. reboot_type = BOOT_KBD;
  123. break;
  124. }
  125. }
  126. }
  127. EXPORT_SYMBOL(machine_restart);
  128. void machine_halt(void)
  129. {
  130. }
  131. EXPORT_SYMBOL(machine_halt);
  132. void machine_power_off(void)
  133. {
  134. if (pm_power_off)
  135. pm_power_off();
  136. }
  137. EXPORT_SYMBOL(machine_power_off);