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