reboot_64.c 3.0 KB

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