reboot_64.c 3.5 KB

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