reboot_64.c 3.3 KB

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