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