reboot_64.c 3.0 KB

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