reboot_64.c 3.1 KB

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