x86: add ACPI reboot option
[deliverable/linux.git] / arch / x86 / kernel / reboot_64.c
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 <acpi/reboot.h>
13 #include <asm/io.h>
14 #include <asm/delay.h>
15 #include <asm/desc.h>
16 #include <asm/hw_irq.h>
17 #include <asm/system.h>
18 #include <asm/pgtable.h>
19 #include <asm/tlbflush.h>
20 #include <asm/apic.h>
21 #include <asm/hpet.h>
22 #include <asm/gart.h>
23
24 /*
25 * Power off function, if any
26 */
27 void (*pm_power_off)(void);
28 EXPORT_SYMBOL(pm_power_off);
29
30 static long no_idt[3];
31 static enum {
32 BOOT_TRIPLE = 't',
33 BOOT_KBD = 'k',
34 BOOT_ACPI = 'a'
35 } reboot_type = BOOT_KBD;
36 static int reboot_mode = 0;
37 int reboot_force;
38
39 /* reboot=t[riple] | k[bd] [, [w]arm | [c]old]
40 warm Don't set the cold reboot flag
41 cold Set the cold reboot flag
42 triple Force a triple fault (init)
43 kbd Use the keyboard controller. cold reset (default)
44 acpi Use the RESET_REG in the FADT
45 force Avoid anything that could hang.
46 */
47 static int __init reboot_setup(char *str)
48 {
49 for (;;) {
50 switch (*str) {
51 case 'w':
52 reboot_mode = 0x1234;
53 break;
54
55 case 'c':
56 reboot_mode = 0;
57 break;
58
59 case 't':
60 case 'a':
61 case 'b':
62 case 'k':
63 reboot_type = *str;
64 break;
65 case 'f':
66 reboot_force = 1;
67 break;
68 }
69 if((str = strchr(str,',')) != NULL)
70 str++;
71 else
72 break;
73 }
74 return 1;
75 }
76
77 __setup("reboot=", reboot_setup);
78
79 static inline void kb_wait(void)
80 {
81 int i;
82
83 for (i=0; i<0x10000; i++)
84 if ((inb_p(0x64) & 0x02) == 0)
85 break;
86 }
87
88 void machine_shutdown(void)
89 {
90 unsigned long flags;
91
92 /* Stop the cpus and apics */
93 #ifdef CONFIG_SMP
94 int reboot_cpu_id;
95
96 /* The boot cpu is always logical cpu 0 */
97 reboot_cpu_id = 0;
98
99 /* Make certain the cpu I'm about to reboot on is online */
100 if (!cpu_isset(reboot_cpu_id, cpu_online_map)) {
101 reboot_cpu_id = smp_processor_id();
102 }
103
104 /* Make certain I only run on the appropriate processor */
105 set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id));
106
107 /* O.K Now that I'm on the appropriate processor,
108 * stop all of the others.
109 */
110 smp_send_stop();
111 #endif
112
113 local_irq_save(flags);
114
115 #ifndef CONFIG_SMP
116 disable_local_APIC();
117 #endif
118
119 disable_IO_APIC();
120
121 #ifdef CONFIG_HPET_TIMER
122 hpet_disable();
123 #endif
124 local_irq_restore(flags);
125
126 pci_iommu_shutdown();
127 }
128
129 void machine_emergency_restart(void)
130 {
131 int i;
132
133 /* Tell the BIOS if we want cold or warm reboot */
134 *((unsigned short *)__va(0x472)) = reboot_mode;
135
136 for (;;) {
137 /* Could also try the reset bit in the Hammer NB */
138 switch (reboot_type) {
139 case BOOT_KBD:
140 for (i=0; i<10; i++) {
141 kb_wait();
142 udelay(50);
143 outb(0xfe,0x64); /* pulse reset low */
144 udelay(50);
145 }
146
147 case BOOT_TRIPLE:
148 load_idt((const struct desc_ptr *)&no_idt);
149 __asm__ __volatile__("int3");
150
151 reboot_type = BOOT_KBD;
152 break;
153
154 case BOOT_ACPI:
155 acpi_reboot();
156 reboot_type = BOOT_KBD;
157 break;
158 }
159 }
160 }
161
162 void machine_restart(char * __unused)
163 {
164 printk("machine restart\n");
165
166 if (!reboot_force) {
167 machine_shutdown();
168 }
169 machine_emergency_restart();
170 }
171
172 void machine_halt(void)
173 {
174 }
175
176 void machine_power_off(void)
177 {
178 if (pm_power_off) {
179 if (!reboot_force) {
180 machine_shutdown();
181 }
182 pm_power_off();
183 }
184 }
185
This page took 0.040192 seconds and 5 git commands to generate.