[PATCH] via-rhine: zero pad short packets on Rhine I ethernet cards
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86_64 / kernel / reboot.c
blob57117b8beb2bfd14e7fc51a618f56fff36176826
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 <asm/io.h>
11 #include <asm/kdebug.h>
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>
20 * Power off function, if any
22 void (*pm_power_off)(void);
24 static long no_idt[3];
25 static enum {
26 BOOT_TRIPLE = 't',
27 BOOT_KBD = 'k'
28 } reboot_type = BOOT_KBD;
29 static int reboot_mode = 0;
30 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)
41 for (;;) {
42 switch (*str) {
43 case 'w':
44 reboot_mode = 0x1234;
45 break;
47 case 'c':
48 reboot_mode = 0;
49 break;
51 case 't':
52 case 'b':
53 case 'k':
54 reboot_type = *str;
55 break;
56 case 'f':
57 reboot_force = 1;
58 break;
60 if((str = strchr(str,',')) != NULL)
61 str++;
62 else
63 break;
65 return 1;
68 __setup("reboot=", reboot_setup);
70 static inline void kb_wait(void)
72 int i;
74 for (i=0; i<0x10000; i++)
75 if ((inb_p(0x64) & 0x02) == 0)
76 break;
79 void machine_shutdown(void)
81 unsigned long flags;
82 /* Stop the cpus and apics */
83 #ifdef CONFIG_SMP
84 int reboot_cpu_id;
86 /* The boot cpu is always logical cpu 0 */
87 reboot_cpu_id = 0;
89 /* Make certain the cpu I'm about to reboot on is online */
90 if (!cpu_isset(reboot_cpu_id, cpu_online_map)) {
91 reboot_cpu_id = smp_processor_id();
94 /* Make certain I only run on the appropriate processor */
95 set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id));
97 /* O.K Now that I'm on the appropriate processor,
98 * stop all of the others.
100 smp_send_stop();
101 #endif
103 local_irq_save(flags);
105 #ifndef CONFIG_SMP
106 disable_local_APIC();
107 #endif
109 disable_IO_APIC();
111 local_irq_restore(flags);
114 void machine_emergency_restart(void)
116 int i;
118 /* Tell the BIOS if we want cold or warm reboot */
119 *((unsigned short *)__va(0x472)) = reboot_mode;
121 for (;;) {
122 /* Could also try the reset bit in the Hammer NB */
123 switch (reboot_type) {
124 case BOOT_KBD:
125 for (i=0; i<10; i++) {
126 kb_wait();
127 udelay(50);
128 outb(0xfe,0x64); /* pulse reset low */
129 udelay(50);
132 case BOOT_TRIPLE:
133 __asm__ __volatile__("lidt (%0)": :"r" (&no_idt));
134 __asm__ __volatile__("int3");
136 reboot_type = BOOT_KBD;
137 break;
142 void machine_restart(char * __unused)
144 printk("machine restart\n");
146 if (!reboot_force) {
147 machine_shutdown();
149 machine_emergency_restart();
152 void machine_halt(void)
156 void machine_power_off(void)
158 if (pm_power_off) {
159 if (!reboot_force) {
160 machine_shutdown();
162 pm_power_off();