Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Eric W. Biederman | 6e3fbee | 2006-01-11 22:43:12 +0100 | [diff] [blame] | 9 | #include <linux/pm.h> |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 10 | #include <linux/kdebug.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 11 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/delay.h> |
Glauber de Oliveira Costa | 9d1c6e7 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 14 | #include <asm/desc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
OGAWA Hirofumi | c86c7fb | 2007-12-03 17:17:10 +0100 | [diff] [blame] | 20 | #include <asm/hpet.h> |
Joerg Roedel | 395624f | 2007-10-24 12:49:47 +0200 | [diff] [blame] | 21 | #include <asm/gart.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * Power off function, if any |
| 25 | */ |
| 26 | void (*pm_power_off)(void); |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 27 | EXPORT_SYMBOL(pm_power_off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | static long no_idt[3]; |
| 30 | static enum { |
| 31 | BOOT_TRIPLE = 't', |
| 32 | BOOT_KBD = 'k' |
| 33 | } reboot_type = BOOT_KBD; |
| 34 | static int reboot_mode = 0; |
| 35 | int reboot_force; |
| 36 | |
| 37 | /* reboot=t[riple] | k[bd] [, [w]arm | [c]old] |
| 38 | warm Don't set the cold reboot flag |
| 39 | cold Set the cold reboot flag |
| 40 | triple Force a triple fault (init) |
| 41 | kbd Use the keyboard controller. cold reset (default) |
| 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 | |
| 52 | case 'c': |
| 53 | reboot_mode = 0; |
| 54 | break; |
| 55 | |
| 56 | case 't': |
| 57 | case 'b': |
| 58 | case 'k': |
| 59 | reboot_type = *str; |
| 60 | break; |
| 61 | case 'f': |
| 62 | reboot_force = 1; |
| 63 | break; |
| 64 | } |
| 65 | if((str = strchr(str,',')) != NULL) |
| 66 | str++; |
| 67 | else |
| 68 | break; |
| 69 | } |
| 70 | return 1; |
| 71 | } |
| 72 | |
| 73 | __setup("reboot=", reboot_setup); |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | static inline void kb_wait(void) |
| 76 | { |
| 77 | int i; |
| 78 | |
| 79 | for (i=0; i<0x10000; i++) |
| 80 | if ((inb_p(0x64) & 0x02) == 0) |
| 81 | break; |
| 82 | } |
| 83 | |
Eric W. Biederman | d895595 | 2005-06-25 14:58:02 -0700 | [diff] [blame] | 84 | void machine_shutdown(void) |
| 85 | { |
Andi Kleen | 3506229 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 86 | unsigned long flags; |
Yinghai Lu | bc2cea6 | 2007-07-21 17:11:28 +0200 | [diff] [blame] | 87 | |
Eric W. Biederman | d895595 | 2005-06-25 14:58:02 -0700 | [diff] [blame] | 88 | /* Stop the cpus and apics */ |
| 89 | #ifdef CONFIG_SMP |
| 90 | int reboot_cpu_id; |
| 91 | |
| 92 | /* The boot cpu is always logical cpu 0 */ |
| 93 | reboot_cpu_id = 0; |
| 94 | |
| 95 | /* Make certain the cpu I'm about to reboot on is online */ |
| 96 | if (!cpu_isset(reboot_cpu_id, cpu_online_map)) { |
| 97 | reboot_cpu_id = smp_processor_id(); |
| 98 | } |
| 99 | |
| 100 | /* Make certain I only run on the appropriate processor */ |
| 101 | set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id)); |
| 102 | |
| 103 | /* O.K Now that I'm on the appropriate processor, |
| 104 | * stop all of the others. |
| 105 | */ |
| 106 | smp_send_stop(); |
| 107 | #endif |
| 108 | |
Andi Kleen | 3506229 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 109 | local_irq_save(flags); |
Eric W. Biederman | d895595 | 2005-06-25 14:58:02 -0700 | [diff] [blame] | 110 | |
| 111 | #ifndef CONFIG_SMP |
| 112 | disable_local_APIC(); |
| 113 | #endif |
| 114 | |
| 115 | disable_IO_APIC(); |
| 116 | |
OGAWA Hirofumi | c86c7fb | 2007-12-03 17:17:10 +0100 | [diff] [blame] | 117 | #ifdef CONFIG_HPET_TIMER |
| 118 | hpet_disable(); |
| 119 | #endif |
Andi Kleen | 3506229 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 120 | local_irq_restore(flags); |
Yinghai Lu | bc2cea6 | 2007-07-21 17:11:28 +0200 | [diff] [blame] | 121 | |
| 122 | pci_iommu_shutdown(); |
Eric W. Biederman | d895595 | 2005-06-25 14:58:02 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Eric W. Biederman | 62b3a04 | 2005-07-26 11:45:31 -0600 | [diff] [blame] | 125 | void machine_emergency_restart(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
| 127 | int i; |
| 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | /* Tell the BIOS if we want cold or warm reboot */ |
| 130 | *((unsigned short *)__va(0x472)) = reboot_mode; |
| 131 | |
| 132 | for (;;) { |
| 133 | /* Could also try the reset bit in the Hammer NB */ |
| 134 | switch (reboot_type) { |
| 135 | case BOOT_KBD: |
Andi Kleen | a6f5deb | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 136 | for (i=0; i<10; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | kb_wait(); |
| 138 | udelay(50); |
| 139 | outb(0xfe,0x64); /* pulse reset low */ |
| 140 | udelay(50); |
| 141 | } |
| 142 | |
| 143 | case BOOT_TRIPLE: |
Glauber de Oliveira Costa | 9d1c6e7 | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 144 | load_idt((const struct desc_ptr *)&no_idt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | __asm__ __volatile__("int3"); |
| 146 | |
| 147 | reboot_type = BOOT_KBD; |
| 148 | break; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
Eric W. Biederman | 62b3a04 | 2005-07-26 11:45:31 -0600 | [diff] [blame] | 153 | void machine_restart(char * __unused) |
| 154 | { |
| 155 | printk("machine restart\n"); |
| 156 | |
| 157 | if (!reboot_force) { |
| 158 | machine_shutdown(); |
| 159 | } |
| 160 | machine_emergency_restart(); |
| 161 | } |
| 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | void machine_halt(void) |
| 164 | { |
| 165 | } |
| 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | void machine_power_off(void) |
| 168 | { |
Eric W. Biederman | 6e3fbee | 2006-01-11 22:43:12 +0100 | [diff] [blame] | 169 | if (pm_power_off) { |
| 170 | if (!reboot_force) { |
| 171 | machine_shutdown(); |
| 172 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | pm_power_off(); |
Eric W. Biederman | 6e3fbee | 2006-01-11 22:43:12 +0100 | [diff] [blame] | 174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |