]>
Commit | Line | Data |
---|---|---|
c767a54b JP |
1 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
2 | ||
1da177e4 | 3 | #include <linux/module.h> |
cd6ed525 | 4 | #include <linux/reboot.h> |
4d022e35 MB |
5 | #include <linux/init.h> |
6 | #include <linux/pm.h> | |
7 | #include <linux/efi.h> | |
6c6c51e4 | 8 | #include <linux/dmi.h> |
d43c36dc | 9 | #include <linux/sched.h> |
69575d38 | 10 | #include <linux/tboot.h> |
ca444564 | 11 | #include <linux/delay.h> |
4d022e35 MB |
12 | #include <acpi/reboot.h> |
13 | #include <asm/io.h> | |
1da177e4 | 14 | #include <asm/apic.h> |
4d37e7e3 | 15 | #include <asm/desc.h> |
4d022e35 | 16 | #include <asm/hpet.h> |
68db065c | 17 | #include <asm/pgtable.h> |
4412620f | 18 | #include <asm/proto.h> |
973efae2 | 19 | #include <asm/reboot_fixups.h> |
07f3331c | 20 | #include <asm/reboot.h> |
82487711 | 21 | #include <asm/pci_x86.h> |
d176720d | 22 | #include <asm/virtext.h> |
96b89dc6 | 23 | #include <asm/cpu.h> |
c410b830 | 24 | #include <asm/nmi.h> |
65051397 | 25 | #include <asm/smp.h> |
1da177e4 | 26 | |
65051397 PA |
27 | #include <linux/ctype.h> |
28 | #include <linux/mc146818rtc.h> | |
29 | #include <asm/realmode.h> | |
30 | #include <asm/x86_init.h> | |
44be28e9 | 31 | #include <asm/efi.h> |
4d022e35 | 32 | |
1da177e4 LT |
33 | /* |
34 | * Power off function, if any | |
35 | */ | |
36 | void (*pm_power_off)(void); | |
129f6946 | 37 | EXPORT_SYMBOL(pm_power_off); |
1da177e4 | 38 | |
ebdd561a | 39 | static const struct desc_ptr no_idt = {}; |
4d022e35 | 40 | |
144d102b ML |
41 | /* |
42 | * This is set if we need to go through the 'emergency' path. | |
d176720d EH |
43 | * When machine_emergency_restart() is called, we may be on |
44 | * an inconsistent state and won't be able to do a clean cleanup | |
45 | */ | |
46 | static int reboot_emergency; | |
47 | ||
14d7ca5c PA |
48 | /* This is set by the PCI code if either type 1 or type 2 PCI is detected */ |
49 | bool port_cf9_safe = false; | |
50 | ||
1da177e4 LT |
51 | /* |
52 | * Reboot options and system auto-detection code provided by | |
53 | * Dell Inc. so their systems "just work". :-) | |
54 | */ | |
55 | ||
56 | /* | |
1ef03890 | 57 | * Some machines require the "reboot=b" or "reboot=k" commandline options, |
4d022e35 | 58 | * this quirk makes that automatic. |
1da177e4 | 59 | */ |
1855256c | 60 | static int __init set_bios_reboot(const struct dmi_system_id *d) |
1da177e4 | 61 | { |
4d022e35 MB |
62 | if (reboot_type != BOOT_BIOS) { |
63 | reboot_type = BOOT_BIOS; | |
c767a54b | 64 | pr_info("%s series board detected. Selecting %s-method for reboots.\n", |
6d9153bb | 65 | d->ident, "BIOS"); |
1da177e4 LT |
66 | } |
67 | return 0; | |
68 | } | |
69 | ||
65051397 | 70 | void __noreturn machine_real_restart(unsigned int type) |
57b16594 | 71 | { |
57b16594 ML |
72 | local_irq_disable(); |
73 | ||
144d102b ML |
74 | /* |
75 | * Write zero to CMOS register number 0x0f, which the BIOS POST | |
76 | * routine will recognize as telling it to do a proper reboot. (Well | |
77 | * that's what this book in front of me says -- it may only apply to | |
78 | * the Phoenix BIOS though, it's not clear). At the same time, | |
79 | * disable NMIs by setting the top bit in the CMOS address register, | |
80 | * as we're about to do peculiar things to the CPU. I'm not sure if | |
81 | * `outb_p' is needed instead of just `outb'. Use it to be on the | |
82 | * safe side. (Yes, CMOS_WRITE does outb_p's. - Paul G.) | |
57b16594 ML |
83 | */ |
84 | spin_lock(&rtc_lock); | |
85 | CMOS_WRITE(0x00, 0x8f); | |
86 | spin_unlock(&rtc_lock); | |
87 | ||
88 | /* | |
89 | * Switch back to the initial page table. | |
90 | */ | |
65051397 | 91 | #ifdef CONFIG_X86_32 |
57b16594 | 92 | load_cr3(initial_page_table); |
65051397 PA |
93 | #else |
94 | write_cr3(real_mode_header->trampoline_pgd); | |
95 | #endif | |
57b16594 | 96 | |
57b16594 | 97 | /* Jump to the identity-mapped low memory code */ |
65051397 PA |
98 | #ifdef CONFIG_X86_32 |
99 | asm volatile("jmpl *%0" : : | |
100 | "rm" (real_mode_header->machine_real_restart_asm), | |
101 | "a" (type)); | |
102 | #else | |
103 | asm volatile("ljmpl *%0" : : | |
104 | "m" (real_mode_header->machine_real_restart_asm), | |
105 | "D" (type)); | |
106 | #endif | |
107 | unreachable(); | |
57b16594 ML |
108 | } |
109 | #ifdef CONFIG_APM_MODULE | |
110 | EXPORT_SYMBOL(machine_real_restart); | |
111 | #endif | |
112 | ||
57b16594 ML |
113 | /* |
114 | * Some Apple MacBook and MacBookPro's needs reboot=p to be able to reboot | |
115 | */ | |
116 | static int __init set_pci_reboot(const struct dmi_system_id *d) | |
117 | { | |
5be44a6f IM |
118 | if (reboot_type != BOOT_CF9_FORCE) { |
119 | reboot_type = BOOT_CF9_FORCE; | |
c767a54b | 120 | pr_info("%s series board detected. Selecting %s-method for reboots.\n", |
6d9153bb | 121 | d->ident, "PCI"); |
57b16594 ML |
122 | } |
123 | return 0; | |
124 | } | |
125 | ||
1ef03890 PC |
126 | static int __init set_kbd_reboot(const struct dmi_system_id *d) |
127 | { | |
128 | if (reboot_type != BOOT_KBD) { | |
129 | reboot_type = BOOT_KBD; | |
c767a54b | 130 | pr_info("%s series board detected. Selecting %s-method for reboot.\n", |
6d9153bb | 131 | d->ident, "KBD"); |
1ef03890 PC |
132 | } |
133 | return 0; | |
134 | } | |
135 | ||
144d102b | 136 | /* |
65051397 | 137 | * This is a single dmi_table handling all reboot quirks. |
57b16594 | 138 | */ |
1da177e4 | 139 | static struct dmi_system_id __initdata reboot_dmi_table[] = { |
e56e57f6 DJ |
140 | |
141 | /* Acer */ | |
142 | { /* Handle reboot issue on Acer Aspire one */ | |
143 | .callback = set_kbd_reboot, | |
144 | .ident = "Acer Aspire One A110", | |
b9e82af8 | 145 | .matches = { |
e56e57f6 DJ |
146 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
147 | DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"), | |
b9e82af8 TG |
148 | }, |
149 | }, | |
e56e57f6 DJ |
150 | |
151 | /* Apple */ | |
152 | { /* Handle problems with rebooting on Apple MacBook5 */ | |
153 | .callback = set_pci_reboot, | |
154 | .ident = "Apple MacBook5", | |
1da177e4 | 155 | .matches = { |
e56e57f6 DJ |
156 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), |
157 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5"), | |
1da177e4 LT |
158 | }, |
159 | }, | |
e56e57f6 DJ |
160 | { /* Handle problems with rebooting on Apple MacBookPro5 */ |
161 | .callback = set_pci_reboot, | |
162 | .ident = "Apple MacBookPro5", | |
1da177e4 | 163 | .matches = { |
e56e57f6 DJ |
164 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), |
165 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5"), | |
1da177e4 LT |
166 | }, |
167 | }, | |
e56e57f6 DJ |
168 | { /* Handle problems with rebooting on Apple Macmini3,1 */ |
169 | .callback = set_pci_reboot, | |
170 | .ident = "Apple Macmini3,1", | |
df2edcf3 | 171 | .matches = { |
e56e57f6 DJ |
172 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), |
173 | DMI_MATCH(DMI_PRODUCT_NAME, "Macmini3,1"), | |
df2edcf3 JJ |
174 | }, |
175 | }, | |
e56e57f6 DJ |
176 | { /* Handle problems with rebooting on the iMac9,1. */ |
177 | .callback = set_pci_reboot, | |
178 | .ident = "Apple iMac9,1", | |
fc115bf1 | 179 | .matches = { |
e56e57f6 DJ |
180 | DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), |
181 | DMI_MATCH(DMI_PRODUCT_NAME, "iMac9,1"), | |
fc115bf1 CK |
182 | }, |
183 | }, | |
e56e57f6 DJ |
184 | |
185 | /* ASUS */ | |
186 | { /* Handle problems with rebooting on ASUS P4S800 */ | |
fc1c8925 | 187 | .callback = set_bios_reboot, |
e56e57f6 | 188 | .ident = "ASUS P4S800", |
fc1c8925 | 189 | .matches = { |
e56e57f6 DJ |
190 | DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), |
191 | DMI_MATCH(DMI_BOARD_NAME, "P4S800"), | |
fc1c8925 HAA |
192 | }, |
193 | }, | |
e56e57f6 | 194 | |
aadca6fa CG |
195 | /* Certec */ |
196 | { /* Handle problems with rebooting on Certec BPC600 */ | |
197 | .callback = set_pci_reboot, | |
198 | .ident = "Certec BPC600", | |
199 | .matches = { | |
200 | DMI_MATCH(DMI_SYS_VENDOR, "Certec"), | |
201 | DMI_MATCH(DMI_PRODUCT_NAME, "BPC600"), | |
202 | }, | |
203 | }, | |
204 | ||
e56e57f6 DJ |
205 | /* Dell */ |
206 | { /* Handle problems with rebooting on Dell DXP061 */ | |
093bac15 | 207 | .callback = set_bios_reboot, |
e56e57f6 | 208 | .ident = "Dell DXP061", |
093bac15 SC |
209 | .matches = { |
210 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
e56e57f6 | 211 | DMI_MATCH(DMI_PRODUCT_NAME, "Dell DXP061"), |
093bac15 SC |
212 | }, |
213 | }, | |
e56e57f6 | 214 | { /* Handle problems with rebooting on Dell E520's */ |
4a4aca64 | 215 | .callback = set_bios_reboot, |
e56e57f6 | 216 | .ident = "Dell E520", |
4a4aca64 JD |
217 | .matches = { |
218 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
e56e57f6 | 219 | DMI_MATCH(DMI_PRODUCT_NAME, "Dell DM061"), |
4a4aca64 JD |
220 | }, |
221 | }, | |
986189f9 LT |
222 | { /* Handle problems with rebooting on the Latitude E5410. */ |
223 | .callback = set_pci_reboot, | |
224 | .ident = "Dell Latitude E5410", | |
35ea63d7 LO |
225 | .matches = { |
226 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
986189f9 | 227 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5410"), |
35ea63d7 LO |
228 | }, |
229 | }, | |
e56e57f6 DJ |
230 | { /* Handle problems with rebooting on the Latitude E5420. */ |
231 | .callback = set_pci_reboot, | |
232 | .ident = "Dell Latitude E5420", | |
1da177e4 | 233 | .matches = { |
35ea63d7 | 234 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
e56e57f6 | 235 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5420"), |
1da177e4 LT |
236 | }, |
237 | }, | |
e56e57f6 DJ |
238 | { /* Handle problems with rebooting on the Latitude E6320. */ |
239 | .callback = set_pci_reboot, | |
240 | .ident = "Dell Latitude E6320", | |
fab3b58d IM |
241 | .matches = { |
242 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
e56e57f6 | 243 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6320"), |
fab3b58d IM |
244 | }, |
245 | }, | |
e56e57f6 DJ |
246 | { /* Handle problems with rebooting on the Latitude E6420. */ |
247 | .callback = set_pci_reboot, | |
248 | .ident = "Dell Latitude E6420", | |
890ffedc TB |
249 | .matches = { |
250 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
e56e57f6 | 251 | DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6420"), |
890ffedc TB |
252 | }, |
253 | }, | |
e56e57f6 | 254 | { /* Handle problems with rebooting on Dell Optiplex 330 with 0KP561 */ |
d91b14c4 | 255 | .callback = set_bios_reboot, |
e56e57f6 | 256 | .ident = "Dell OptiPlex 330", |
d91b14c4 | 257 | .matches = { |
890ffedc | 258 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
e56e57f6 DJ |
259 | DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 330"), |
260 | DMI_MATCH(DMI_BOARD_NAME, "0KP561"), | |
d91b14c4 TV |
261 | }, |
262 | }, | |
e56e57f6 | 263 | { /* Handle problems with rebooting on Dell Optiplex 360 with 0T656F */ |
dd4124a8 | 264 | .callback = set_bios_reboot, |
e56e57f6 | 265 | .ident = "Dell OptiPlex 360", |
dd4124a8 LO |
266 | .matches = { |
267 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
e56e57f6 DJ |
268 | DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 360"), |
269 | DMI_MATCH(DMI_BOARD_NAME, "0T656F"), | |
dd4124a8 LO |
270 | }, |
271 | }, | |
e56e57f6 | 272 | { /* Handle problems with rebooting on Dell Optiplex 745's SFF */ |
c5da9a2b | 273 | .callback = set_bios_reboot, |
e56e57f6 | 274 | .ident = "Dell OptiPlex 745", |
c5da9a2b AC |
275 | .matches = { |
276 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
e56e57f6 | 277 | DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"), |
c5da9a2b AC |
278 | }, |
279 | }, | |
e56e57f6 | 280 | { /* Handle problems with rebooting on Dell Optiplex 745's DFF */ |
88dff493 | 281 | .callback = set_bios_reboot, |
e56e57f6 | 282 | .ident = "Dell OptiPlex 745", |
88dff493 | 283 | .matches = { |
c5da9a2b | 284 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
e56e57f6 DJ |
285 | DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"), |
286 | DMI_MATCH(DMI_BOARD_NAME, "0MM599"), | |
88dff493 ZR |
287 | }, |
288 | }, | |
e56e57f6 | 289 | { /* Handle problems with rebooting on Dell Optiplex 745 with 0KW626 */ |
4832ddda | 290 | .callback = set_bios_reboot, |
e56e57f6 | 291 | .ident = "Dell OptiPlex 745", |
b49c78d4 | 292 | .matches = { |
e56e57f6 DJ |
293 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
294 | DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"), | |
295 | DMI_MATCH(DMI_BOARD_NAME, "0KW626"), | |
b49c78d4 PC |
296 | }, |
297 | }, | |
e56e57f6 | 298 | { /* Handle problems with rebooting on Dell OptiPlex 760 with 0G919G */ |
4832ddda | 299 | .callback = set_bios_reboot, |
e56e57f6 | 300 | .ident = "Dell OptiPlex 760", |
6c6c51e4 | 301 | .matches = { |
e56e57f6 DJ |
302 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
303 | DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 760"), | |
304 | DMI_MATCH(DMI_BOARD_NAME, "0G919G"), | |
6c6c51e4 PM |
305 | }, |
306 | }, | |
e56e57f6 | 307 | { /* Handle problems with rebooting on the OptiPlex 990. */ |
498cdbfb | 308 | .callback = set_pci_reboot, |
e56e57f6 | 309 | .ident = "Dell OptiPlex 990", |
498cdbfb | 310 | .matches = { |
e56e57f6 DJ |
311 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
312 | DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 990"), | |
498cdbfb OÇ |
313 | }, |
314 | }, | |
e56e57f6 DJ |
315 | { /* Handle problems with rebooting on Dell 300's */ |
316 | .callback = set_bios_reboot, | |
317 | .ident = "Dell PowerEdge 300", | |
05154752 | 318 | .matches = { |
e56e57f6 DJ |
319 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), |
320 | DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 300/"), | |
05154752 GH |
321 | }, |
322 | }, | |
e56e57f6 DJ |
323 | { /* Handle problems with rebooting on Dell 1300's */ |
324 | .callback = set_bios_reboot, | |
325 | .ident = "Dell PowerEdge 1300", | |
0a832320 | 326 | .matches = { |
e56e57f6 DJ |
327 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), |
328 | DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1300/"), | |
0a832320 JM |
329 | }, |
330 | }, | |
e56e57f6 DJ |
331 | { /* Handle problems with rebooting on Dell 2400's */ |
332 | .callback = set_bios_reboot, | |
333 | .ident = "Dell PowerEdge 2400", | |
3628c3f5 | 334 | .matches = { |
e56e57f6 DJ |
335 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), |
336 | DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2400"), | |
3628c3f5 MR |
337 | }, |
338 | }, | |
e56e57f6 | 339 | { /* Handle problems with rebooting on the Dell PowerEdge C6100. */ |
8412da75 | 340 | .callback = set_pci_reboot, |
e56e57f6 | 341 | .ident = "Dell PowerEdge C6100", |
8412da75 | 342 | .matches = { |
e56e57f6 DJ |
343 | DMI_MATCH(DMI_SYS_VENDOR, "Dell"), |
344 | DMI_MATCH(DMI_PRODUCT_NAME, "C6100"), | |
8412da75 VS |
345 | }, |
346 | }, | |
e56e57f6 | 347 | { /* Handle problems with rebooting on the Precision M6600. */ |
b7798d28 | 348 | .callback = set_pci_reboot, |
e56e57f6 | 349 | .ident = "Dell Precision M6600", |
b7798d28 DB |
350 | .matches = { |
351 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
e56e57f6 | 352 | DMI_MATCH(DMI_PRODUCT_NAME, "Precision M6600"), |
b7798d28 DB |
353 | }, |
354 | }, | |
e56e57f6 DJ |
355 | { /* Handle problems with rebooting on Dell T5400's */ |
356 | .callback = set_bios_reboot, | |
357 | .ident = "Dell Precision T5400", | |
a536877e PA |
358 | .matches = { |
359 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
e56e57f6 | 360 | DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T5400"), |
a536877e PA |
361 | }, |
362 | }, | |
e56e57f6 DJ |
363 | { /* Handle problems with rebooting on Dell T7400's */ |
364 | .callback = set_bios_reboot, | |
365 | .ident = "Dell Precision T7400", | |
6be30bb7 RW |
366 | .matches = { |
367 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
e56e57f6 | 368 | DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T7400"), |
6be30bb7 RW |
369 | }, |
370 | }, | |
e56e57f6 DJ |
371 | { /* Handle problems with rebooting on Dell XPS710 */ |
372 | .callback = set_bios_reboot, | |
373 | .ident = "Dell XPS710", | |
76eb9a30 ZR |
374 | .matches = { |
375 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | |
e56e57f6 | 376 | DMI_MATCH(DMI_PRODUCT_NAME, "Dell XPS710"), |
76eb9a30 ZR |
377 | }, |
378 | }, | |
e56e57f6 DJ |
379 | |
380 | /* Hewlett-Packard */ | |
381 | { /* Handle problems with rebooting on HP laptops */ | |
382 | .callback = set_bios_reboot, | |
383 | .ident = "HP Compaq Laptop", | |
4f0acd31 | 384 | .matches = { |
e56e57f6 DJ |
385 | DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), |
386 | DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq"), | |
4f0acd31 MS |
387 | }, |
388 | }, | |
e56e57f6 DJ |
389 | |
390 | /* Sony */ | |
391 | { /* Handle problems with rebooting on Sony VGN-Z540N */ | |
392 | .callback = set_bios_reboot, | |
393 | .ident = "Sony VGN-Z540N", | |
4f0acd31 | 394 | .matches = { |
e56e57f6 DJ |
395 | DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), |
396 | DMI_MATCH(DMI_PRODUCT_NAME, "VGN-Z540N"), | |
4f0acd31 MS |
397 | }, |
398 | }, | |
e56e57f6 | 399 | |
6c6c51e4 PM |
400 | { } |
401 | }; | |
402 | ||
57b16594 | 403 | static int __init reboot_init(void) |
6c6c51e4 | 404 | { |
44be28e9 MF |
405 | int rv; |
406 | ||
144d102b ML |
407 | /* |
408 | * Only do the DMI check if reboot_type hasn't been overridden | |
5955633e ML |
409 | * on the command line |
410 | */ | |
44be28e9 MF |
411 | if (!reboot_default) |
412 | return 0; | |
413 | ||
414 | /* | |
415 | * The DMI quirks table takes precedence. If no quirks entry | |
416 | * matches and the ACPI Hardware Reduced bit is set, force EFI | |
417 | * reboot. | |
418 | */ | |
419 | rv = dmi_check_system(reboot_dmi_table); | |
420 | ||
421 | if (!rv && efi_reboot_required()) | |
422 | reboot_type = BOOT_EFI; | |
423 | ||
6c6c51e4 PM |
424 | return 0; |
425 | } | |
57b16594 | 426 | core_initcall(reboot_init); |
6c6c51e4 | 427 | |
4d022e35 MB |
428 | static inline void kb_wait(void) |
429 | { | |
430 | int i; | |
431 | ||
c84d6af8 AC |
432 | for (i = 0; i < 0x10000; i++) { |
433 | if ((inb(0x64) & 0x02) == 0) | |
4d022e35 | 434 | break; |
c84d6af8 AC |
435 | udelay(2); |
436 | } | |
4d022e35 MB |
437 | } |
438 | ||
9c48f1c6 | 439 | static void vmxoff_nmi(int cpu, struct pt_regs *regs) |
d176720d EH |
440 | { |
441 | cpu_emergency_vmxoff(); | |
442 | } | |
443 | ||
144d102b | 444 | /* Use NMIs as IPIs to tell all CPUs to disable virtualization */ |
d176720d EH |
445 | static void emergency_vmx_disable_all(void) |
446 | { | |
447 | /* Just make sure we won't change CPUs while doing this */ | |
448 | local_irq_disable(); | |
449 | ||
144d102b ML |
450 | /* |
451 | * We need to disable VMX on all CPUs before rebooting, otherwise | |
d176720d EH |
452 | * we risk hanging up the machine, because the CPU ignore INIT |
453 | * signals when VMX is enabled. | |
454 | * | |
455 | * We can't take any locks and we may be on an inconsistent | |
456 | * state, so we use NMIs as IPIs to tell the other CPUs to disable | |
457 | * VMX and halt. | |
458 | * | |
459 | * For safety, we will avoid running the nmi_shootdown_cpus() | |
460 | * stuff unnecessarily, but we don't have a way to check | |
461 | * if other CPUs have VMX enabled. So we will call it only if the | |
462 | * CPU we are running on has VMX enabled. | |
463 | * | |
464 | * We will miss cases where VMX is not enabled on all CPUs. This | |
465 | * shouldn't do much harm because KVM always enable VMX on all | |
466 | * CPUs anyway. But we can miss it on the small window where KVM | |
467 | * is still enabling VMX. | |
468 | */ | |
469 | if (cpu_has_vmx() && cpu_vmx_enabled()) { | |
144d102b | 470 | /* Disable VMX on this CPU. */ |
d176720d EH |
471 | cpu_vmxoff(); |
472 | ||
473 | /* Halt and disable VMX on the other CPUs */ | |
474 | nmi_shootdown_cpus(vmxoff_nmi); | |
475 | ||
476 | } | |
477 | } | |
478 | ||
479 | ||
7432d149 IM |
480 | void __attribute__((weak)) mach_reboot_fixups(void) |
481 | { | |
482 | } | |
483 | ||
660e34ce | 484 | /* |
5be44a6f IM |
485 | * To the best of our knowledge Windows compatible x86 hardware expects |
486 | * the following on reboot: | |
660e34ce MG |
487 | * |
488 | * 1) If the FADT has the ACPI reboot register flag set, try it | |
489 | * 2) If still alive, write to the keyboard controller | |
490 | * 3) If still alive, write to the ACPI reboot register again | |
491 | * 4) If still alive, write to the keyboard controller again | |
a4f1987e | 492 | * 5) If still alive, call the EFI runtime service to reboot |
5be44a6f | 493 | * 6) If no EFI runtime service, call the BIOS to do a reboot |
660e34ce | 494 | * |
5be44a6f IM |
495 | * We default to following the same pattern. We also have |
496 | * two other reboot methods: 'triple fault' and 'PCI', which | |
497 | * can be triggered via the reboot= kernel boot option or | |
498 | * via quirks. | |
499 | * | |
500 | * This means that this function can never return, it can misbehave | |
501 | * by not rebooting properly and hanging. | |
660e34ce | 502 | */ |
416e2d63 | 503 | static void native_machine_emergency_restart(void) |
1da177e4 | 504 | { |
4d022e35 | 505 | int i; |
660e34ce MG |
506 | int attempt = 0; |
507 | int orig_reboot_type = reboot_type; | |
edf2b139 | 508 | unsigned short mode; |
4d022e35 | 509 | |
d176720d EH |
510 | if (reboot_emergency) |
511 | emergency_vmx_disable_all(); | |
512 | ||
840c2baf JC |
513 | tboot_shutdown(TB_SHUTDOWN_REBOOT); |
514 | ||
4d022e35 | 515 | /* Tell the BIOS if we want cold or warm reboot */ |
edf2b139 RH |
516 | mode = reboot_mode == REBOOT_WARM ? 0x1234 : 0; |
517 | *((unsigned short *)__va(0x472)) = mode; | |
4d022e35 MB |
518 | |
519 | for (;;) { | |
520 | /* Could also try the reset bit in the Hammer NB */ | |
521 | switch (reboot_type) { | |
5be44a6f IM |
522 | case BOOT_ACPI: |
523 | acpi_reboot(); | |
524 | reboot_type = BOOT_KBD; | |
525 | break; | |
526 | ||
4d022e35 | 527 | case BOOT_KBD: |
144d102b | 528 | mach_reboot_fixups(); /* For board specific fixups */ |
7432d149 | 529 | |
4d022e35 MB |
530 | for (i = 0; i < 10; i++) { |
531 | kb_wait(); | |
532 | udelay(50); | |
144d102b | 533 | outb(0xfe, 0x64); /* Pulse reset low */ |
4d022e35 MB |
534 | udelay(50); |
535 | } | |
660e34ce MG |
536 | if (attempt == 0 && orig_reboot_type == BOOT_ACPI) { |
537 | attempt = 1; | |
538 | reboot_type = BOOT_ACPI; | |
539 | } else { | |
a4f1987e | 540 | reboot_type = BOOT_EFI; |
660e34ce MG |
541 | } |
542 | break; | |
4d022e35 | 543 | |
4d022e35 | 544 | case BOOT_EFI: |
8562c99c | 545 | efi_reboot(reboot_mode, NULL); |
5be44a6f IM |
546 | reboot_type = BOOT_BIOS; |
547 | break; | |
548 | ||
549 | case BOOT_BIOS: | |
550 | machine_real_restart(MRR_BIOS); | |
551 | ||
552 | /* We're probably dead after this, but... */ | |
553 | reboot_type = BOOT_CF9_SAFE; | |
14d7ca5c | 554 | break; |
4d022e35 | 555 | |
5be44a6f | 556 | case BOOT_CF9_FORCE: |
14d7ca5c | 557 | port_cf9_safe = true; |
144d102b | 558 | /* Fall through */ |
4d022e35 | 559 | |
5be44a6f | 560 | case BOOT_CF9_SAFE: |
14d7ca5c | 561 | if (port_cf9_safe) { |
5be44a6f | 562 | u8 reboot_code = reboot_mode == REBOOT_WARM ? 0x06 : 0x0E; |
16c21ae5 | 563 | u8 cf9 = inb(0xcf9) & ~reboot_code; |
14d7ca5c PA |
564 | outb(cf9|2, 0xcf9); /* Request hard reset */ |
565 | udelay(50); | |
16c21ae5 LF |
566 | /* Actually do the reset */ |
567 | outb(cf9|reboot_code, 0xcf9); | |
14d7ca5c PA |
568 | udelay(50); |
569 | } | |
5be44a6f IM |
570 | reboot_type = BOOT_TRIPLE; |
571 | break; | |
572 | ||
573 | case BOOT_TRIPLE: | |
574 | load_idt(&no_idt); | |
575 | __asm__ __volatile__("int3"); | |
576 | ||
577 | /* We're probably dead after this, but... */ | |
578 | reboot_type = BOOT_KBD; | |
4d022e35 MB |
579 | break; |
580 | } | |
581 | } | |
582 | } | |
583 | ||
3c62c625 | 584 | void native_machine_shutdown(void) |
4d022e35 MB |
585 | { |
586 | /* Stop the cpus and apics */ | |
522e6646 | 587 | #ifdef CONFIG_X86_IO_APIC |
2885432a FY |
588 | /* |
589 | * Disabling IO APIC before local APIC is a workaround for | |
590 | * erratum AVR31 in "Intel Atom Processor C2000 Product Family | |
591 | * Specification Update". In this situation, interrupts that target | |
592 | * a Logical Processor whose Local APIC is either in the process of | |
593 | * being hardware disabled or software disabled are neither delivered | |
594 | * nor discarded. When this erratum occurs, the processor may hang. | |
595 | * | |
596 | * Even without the erratum, it still makes sense to quiet IO APIC | |
597 | * before disabling Local APIC. | |
598 | */ | |
522e6646 FY |
599 | disable_IO_APIC(); |
600 | #endif | |
601 | ||
1da177e4 | 602 | #ifdef CONFIG_SMP |
144d102b | 603 | /* |
1b3a5d02 RH |
604 | * Stop all of the others. Also disable the local irq to |
605 | * not receive the per-cpu timer interrupt which may trigger | |
606 | * scheduler's load balance. | |
1da177e4 | 607 | */ |
55c844a4 | 608 | local_irq_disable(); |
76fac077 | 609 | stop_other_cpus(); |
4d022e35 | 610 | #endif |
1da177e4 LT |
611 | |
612 | lapic_shutdown(); | |
613 | ||
c86c7fbc OH |
614 | #ifdef CONFIG_HPET_TIMER |
615 | hpet_disable(); | |
616 | #endif | |
dd2a1305 | 617 | |
4d022e35 | 618 | #ifdef CONFIG_X86_64 |
338bac52 | 619 | x86_platform.iommu_shutdown(); |
4d022e35 | 620 | #endif |
973efae2 JF |
621 | } |
622 | ||
d176720d EH |
623 | static void __machine_emergency_restart(int emergency) |
624 | { | |
625 | reboot_emergency = emergency; | |
626 | machine_ops.emergency_restart(); | |
627 | } | |
628 | ||
416e2d63 | 629 | static void native_machine_restart(char *__unused) |
dd2a1305 | 630 | { |
c767a54b | 631 | pr_notice("machine restart\n"); |
1da177e4 | 632 | |
4d022e35 MB |
633 | if (!reboot_force) |
634 | machine_shutdown(); | |
d176720d | 635 | __machine_emergency_restart(0); |
4a1421f8 EB |
636 | } |
637 | ||
416e2d63 | 638 | static void native_machine_halt(void) |
1da177e4 | 639 | { |
144d102b | 640 | /* Stop other cpus and apics */ |
d3ec5cae IV |
641 | machine_shutdown(); |
642 | ||
840c2baf JC |
643 | tboot_shutdown(TB_SHUTDOWN_HALT); |
644 | ||
d3ec5cae | 645 | stop_this_cpu(NULL); |
1da177e4 LT |
646 | } |
647 | ||
416e2d63 | 648 | static void native_machine_power_off(void) |
1da177e4 | 649 | { |
6e3fbee5 | 650 | if (pm_power_off) { |
4d022e35 MB |
651 | if (!reboot_force) |
652 | machine_shutdown(); | |
1da177e4 | 653 | pm_power_off(); |
6e3fbee5 | 654 | } |
144d102b | 655 | /* A fallback in case there is no PM info available */ |
840c2baf | 656 | tboot_shutdown(TB_SHUTDOWN_HALT); |
1da177e4 LT |
657 | } |
658 | ||
07f3331c | 659 | struct machine_ops machine_ops = { |
416e2d63 JB |
660 | .power_off = native_machine_power_off, |
661 | .shutdown = native_machine_shutdown, | |
662 | .emergency_restart = native_machine_emergency_restart, | |
663 | .restart = native_machine_restart, | |
ed23dc6f GC |
664 | .halt = native_machine_halt, |
665 | #ifdef CONFIG_KEXEC | |
666 | .crash_shutdown = native_machine_crash_shutdown, | |
667 | #endif | |
07f3331c | 668 | }; |
416e2d63 JB |
669 | |
670 | void machine_power_off(void) | |
671 | { | |
672 | machine_ops.power_off(); | |
673 | } | |
674 | ||
675 | void machine_shutdown(void) | |
676 | { | |
677 | machine_ops.shutdown(); | |
678 | } | |
679 | ||
680 | void machine_emergency_restart(void) | |
681 | { | |
d176720d | 682 | __machine_emergency_restart(1); |
416e2d63 JB |
683 | } |
684 | ||
685 | void machine_restart(char *cmd) | |
686 | { | |
687 | machine_ops.restart(cmd); | |
688 | } | |
689 | ||
690 | void machine_halt(void) | |
691 | { | |
692 | machine_ops.halt(); | |
693 | } | |
694 | ||
ed23dc6f GC |
695 | #ifdef CONFIG_KEXEC |
696 | void machine_crash_shutdown(struct pt_regs *regs) | |
697 | { | |
698 | machine_ops.crash_shutdown(regs); | |
699 | } | |
700 | #endif | |
2ddded21 EH |
701 | |
702 | ||
bb8dd270 | 703 | #if defined(CONFIG_SMP) |
2ddded21 EH |
704 | |
705 | /* This keeps a track of which one is crashing cpu. */ | |
706 | static int crashing_cpu; | |
707 | static nmi_shootdown_cb shootdown_callback; | |
708 | ||
709 | static atomic_t waiting_for_crash_ipi; | |
710 | ||
9c48f1c6 | 711 | static int crash_nmi_callback(unsigned int val, struct pt_regs *regs) |
2ddded21 EH |
712 | { |
713 | int cpu; | |
714 | ||
2ddded21 EH |
715 | cpu = raw_smp_processor_id(); |
716 | ||
144d102b ML |
717 | /* |
718 | * Don't do anything if this handler is invoked on crashing cpu. | |
2ddded21 EH |
719 | * Otherwise, system will completely hang. Crashing cpu can get |
720 | * an NMI if system was initially booted with nmi_watchdog parameter. | |
721 | */ | |
722 | if (cpu == crashing_cpu) | |
9c48f1c6 | 723 | return NMI_HANDLED; |
2ddded21 EH |
724 | local_irq_disable(); |
725 | ||
9c48f1c6 | 726 | shootdown_callback(cpu, regs); |
2ddded21 EH |
727 | |
728 | atomic_dec(&waiting_for_crash_ipi); | |
729 | /* Assume hlt works */ | |
730 | halt(); | |
731 | for (;;) | |
732 | cpu_relax(); | |
733 | ||
9c48f1c6 | 734 | return NMI_HANDLED; |
2ddded21 EH |
735 | } |
736 | ||
737 | static void smp_send_nmi_allbutself(void) | |
738 | { | |
dac5f412 | 739 | apic->send_IPI_allbutself(NMI_VECTOR); |
2ddded21 EH |
740 | } |
741 | ||
144d102b ML |
742 | /* |
743 | * Halt all other CPUs, calling the specified function on each of them | |
bb8dd270 EH |
744 | * |
745 | * This function can be used to halt all other CPUs on crash | |
746 | * or emergency reboot time. The function passed as parameter | |
747 | * will be called inside a NMI handler on all CPUs. | |
748 | */ | |
2ddded21 EH |
749 | void nmi_shootdown_cpus(nmi_shootdown_cb callback) |
750 | { | |
751 | unsigned long msecs; | |
c415b3dc | 752 | local_irq_disable(); |
2ddded21 | 753 | |
144d102b | 754 | /* Make a note of crashing cpu. Will be used in NMI callback. */ |
2ddded21 EH |
755 | crashing_cpu = safe_smp_processor_id(); |
756 | ||
757 | shootdown_callback = callback; | |
758 | ||
759 | atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1); | |
760 | /* Would it be better to replace the trap vector here? */ | |
9c48f1c6 DZ |
761 | if (register_nmi_handler(NMI_LOCAL, crash_nmi_callback, |
762 | NMI_FLAG_FIRST, "crash")) | |
144d102b ML |
763 | return; /* Return what? */ |
764 | /* | |
765 | * Ensure the new callback function is set before sending | |
2ddded21 EH |
766 | * out the NMI |
767 | */ | |
768 | wmb(); | |
769 | ||
770 | smp_send_nmi_allbutself(); | |
771 | ||
772 | msecs = 1000; /* Wait at most a second for the other cpus to stop */ | |
773 | while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) { | |
774 | mdelay(1); | |
775 | msecs--; | |
776 | } | |
777 | ||
778 | /* Leave the nmi callback set */ | |
779 | } | |
bb8dd270 EH |
780 | #else /* !CONFIG_SMP */ |
781 | void nmi_shootdown_cpus(nmi_shootdown_cb callback) | |
782 | { | |
783 | /* No other CPUs to shoot down */ | |
784 | } | |
2ddded21 | 785 | #endif |