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