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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/delay.h> |
| 13 | #include <asm/hw_irq.h> |
| 14 | #include <asm/system.h> |
| 15 | #include <asm/pgtable.h> |
| 16 | #include <asm/tlbflush.h> |
| 17 | #include <asm/apic.h> |
| 18 | |
| 19 | /* |
| 20 | * Power off function, if any |
| 21 | */ |
| 22 | void (*pm_power_off)(void); |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 23 | EXPORT_SYMBOL(pm_power_off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 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 | |
| 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 | |
| 48 | case 'c': |
| 49 | reboot_mode = 0; |
| 50 | break; |
| 51 | |
| 52 | case 't': |
| 53 | case 'b': |
| 54 | case 'k': |
| 55 | reboot_type = *str; |
| 56 | break; |
| 57 | case 'f': |
| 58 | reboot_force = 1; |
| 59 | break; |
| 60 | } |
| 61 | if((str = strchr(str,',')) != NULL) |
| 62 | str++; |
| 63 | else |
| 64 | break; |
| 65 | } |
| 66 | return 1; |
| 67 | } |
| 68 | |
| 69 | __setup("reboot=", reboot_setup); |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | static inline void kb_wait(void) |
| 72 | { |
| 73 | int i; |
| 74 | |
| 75 | for (i=0; i<0x10000; i++) |
| 76 | if ((inb_p(0x64) & 0x02) == 0) |
| 77 | break; |
| 78 | } |
| 79 | |
Eric W. Biederman | d895595 | 2005-06-25 14:58:02 -0700 | [diff] [blame] | 80 | void machine_shutdown(void) |
| 81 | { |
Andi Kleen | 3506229 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 82 | unsigned long flags; |
Eric W. Biederman | d895595 | 2005-06-25 14:58:02 -0700 | [diff] [blame] | 83 | /* Stop the cpus and apics */ |
| 84 | #ifdef CONFIG_SMP |
| 85 | int reboot_cpu_id; |
| 86 | |
| 87 | /* The boot cpu is always logical cpu 0 */ |
| 88 | reboot_cpu_id = 0; |
| 89 | |
| 90 | /* Make certain the cpu I'm about to reboot on is online */ |
| 91 | if (!cpu_isset(reboot_cpu_id, cpu_online_map)) { |
| 92 | reboot_cpu_id = smp_processor_id(); |
| 93 | } |
| 94 | |
| 95 | /* Make certain I only run on the appropriate processor */ |
| 96 | set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id)); |
| 97 | |
| 98 | /* O.K Now that I'm on the appropriate processor, |
| 99 | * stop all of the others. |
| 100 | */ |
| 101 | smp_send_stop(); |
| 102 | #endif |
| 103 | |
Andi Kleen | 3506229 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 104 | local_irq_save(flags); |
Eric W. Biederman | d895595 | 2005-06-25 14:58:02 -0700 | [diff] [blame] | 105 | |
| 106 | #ifndef CONFIG_SMP |
| 107 | disable_local_APIC(); |
| 108 | #endif |
| 109 | |
| 110 | disable_IO_APIC(); |
| 111 | |
Andi Kleen | 3506229 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 112 | local_irq_restore(flags); |
Eric W. Biederman | d895595 | 2005-06-25 14:58:02 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Eric W. Biederman | 62b3a04 | 2005-07-26 11:45:31 -0600 | [diff] [blame] | 115 | void machine_emergency_restart(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
| 117 | int i; |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /* Tell the BIOS if we want cold or warm reboot */ |
| 120 | *((unsigned short *)__va(0x472)) = reboot_mode; |
| 121 | |
| 122 | for (;;) { |
| 123 | /* Could also try the reset bit in the Hammer NB */ |
| 124 | switch (reboot_type) { |
| 125 | case BOOT_KBD: |
Andi Kleen | a6f5deb | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 126 | for (i=0; i<10; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | kb_wait(); |
| 128 | udelay(50); |
| 129 | outb(0xfe,0x64); /* pulse reset low */ |
| 130 | udelay(50); |
| 131 | } |
| 132 | |
| 133 | case BOOT_TRIPLE: |
| 134 | __asm__ __volatile__("lidt (%0)": :"r" (&no_idt)); |
| 135 | __asm__ __volatile__("int3"); |
| 136 | |
| 137 | reboot_type = BOOT_KBD; |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
Eric W. Biederman | 62b3a04 | 2005-07-26 11:45:31 -0600 | [diff] [blame] | 143 | void machine_restart(char * __unused) |
| 144 | { |
| 145 | printk("machine restart\n"); |
| 146 | |
| 147 | if (!reboot_force) { |
| 148 | machine_shutdown(); |
| 149 | } |
| 150 | machine_emergency_restart(); |
| 151 | } |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | void machine_halt(void) |
| 154 | { |
| 155 | } |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | void machine_power_off(void) |
| 158 | { |
Eric W. Biederman | 6e3fbee | 2006-01-11 22:43:12 +0100 | [diff] [blame] | 159 | if (pm_power_off) { |
| 160 | if (!reboot_force) { |
| 161 | machine_shutdown(); |
| 162 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | pm_power_off(); |
Eric W. Biederman | 6e3fbee | 2006-01-11 22:43:12 +0100 | [diff] [blame] | 164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |