14d022e35SMiguel Boton #include <linux/module.h> 24d022e35SMiguel Boton #include <linux/reboot.h> 34d022e35SMiguel Boton #include <linux/init.h> 44d022e35SMiguel Boton #include <linux/pm.h> 54d022e35SMiguel Boton #include <linux/efi.h> 66c6c51e4SPaul Mackerras #include <linux/dmi.h> 7d43c36dcSAlexey Dobriyan #include <linux/sched.h> 869575d38SShane Wang #include <linux/tboot.h> 9ca444564SJean Delvare #include <linux/delay.h> 104d022e35SMiguel Boton #include <acpi/reboot.h> 114d022e35SMiguel Boton #include <asm/io.h> 124d022e35SMiguel Boton #include <asm/apic.h> 134d022e35SMiguel Boton #include <asm/desc.h> 144d022e35SMiguel Boton #include <asm/hpet.h> 1568db065cSJeremy Fitzhardinge #include <asm/pgtable.h> 164412620fSDmitri Vorobiev #include <asm/proto.h> 174d022e35SMiguel Boton #include <asm/reboot_fixups.h> 184d022e35SMiguel Boton #include <asm/reboot.h> 1982487711SJaswinder Singh Rajput #include <asm/pci_x86.h> 20d176720dSEduardo Habkost #include <asm/virtext.h> 2196b89dc6SJaswinder Singh Rajput #include <asm/cpu.h> 22c410b830SDon Zickus #include <asm/nmi.h> 234d022e35SMiguel Boton 244d022e35SMiguel Boton #ifdef CONFIG_X86_32 254d022e35SMiguel Boton # include <linux/ctype.h> 264d022e35SMiguel Boton # include <linux/mc146818rtc.h> 274d022e35SMiguel Boton #else 28338bac52SFUJITA Tomonori # include <asm/x86_init.h> 294d022e35SMiguel Boton #endif 304d022e35SMiguel Boton 314d022e35SMiguel Boton /* 324d022e35SMiguel Boton * Power off function, if any 334d022e35SMiguel Boton */ 344d022e35SMiguel Boton void (*pm_power_off)(void); 354d022e35SMiguel Boton EXPORT_SYMBOL(pm_power_off); 364d022e35SMiguel Boton 37ebdd561aSJan Beulich static const struct desc_ptr no_idt = {}; 384d022e35SMiguel Boton static int reboot_mode; 39660e34ceSMatthew Garrett enum reboot_type reboot_type = BOOT_ACPI; 404d022e35SMiguel Boton int reboot_force; 414d022e35SMiguel Boton 425955633eSMichael D Labriola /* This variable is used privately to keep track of whether or not 435955633eSMichael D Labriola * reboot_type is still set to its default value (i.e., reboot= hasn't 445955633eSMichael D Labriola * been set on the command line). This is needed so that we can 455955633eSMichael D Labriola * suppress DMI scanning for reboot quirks. Without it, it's 465955633eSMichael D Labriola * impossible to override a faulty reboot quirk without recompiling. 475955633eSMichael D Labriola */ 485955633eSMichael D Labriola static int reboot_default = 1; 495955633eSMichael D Labriola 504d022e35SMiguel Boton #if defined(CONFIG_X86_32) && defined(CONFIG_SMP) 514d022e35SMiguel Boton static int reboot_cpu = -1; 524d022e35SMiguel Boton #endif 534d022e35SMiguel Boton 54d176720dSEduardo Habkost /* This is set if we need to go through the 'emergency' path. 55d176720dSEduardo Habkost * When machine_emergency_restart() is called, we may be on 56d176720dSEduardo Habkost * an inconsistent state and won't be able to do a clean cleanup 57d176720dSEduardo Habkost */ 58d176720dSEduardo Habkost static int reboot_emergency; 59d176720dSEduardo Habkost 6014d7ca5cSH. Peter Anvin /* This is set by the PCI code if either type 1 or type 2 PCI is detected */ 6114d7ca5cSH. Peter Anvin bool port_cf9_safe = false; 6214d7ca5cSH. Peter Anvin 6314d7ca5cSH. Peter Anvin /* reboot=b[ios] | s[mp] | t[riple] | k[bd] | e[fi] [, [w]arm | [c]old] | p[ci] 644d022e35SMiguel Boton warm Don't set the cold reboot flag 654d022e35SMiguel Boton cold Set the cold reboot flag 664d022e35SMiguel Boton bios Reboot by jumping through the BIOS (only for X86_32) 674d022e35SMiguel Boton smp Reboot by executing reset on BSP or other CPU (only for X86_32) 684d022e35SMiguel Boton triple Force a triple fault (init) 694d022e35SMiguel Boton kbd Use the keyboard controller. cold reset (default) 704d022e35SMiguel Boton acpi Use the RESET_REG in the FADT 714d022e35SMiguel Boton efi Use efi reset_system runtime service 7214d7ca5cSH. Peter Anvin pci Use the so-called "PCI reset register", CF9 734d022e35SMiguel Boton force Avoid anything that could hang. 744d022e35SMiguel Boton */ 754d022e35SMiguel Boton static int __init reboot_setup(char *str) 764d022e35SMiguel Boton { 774d022e35SMiguel Boton for (;;) { 785955633eSMichael D Labriola /* Having anything passed on the command line via 795955633eSMichael D Labriola * reboot= will cause us to disable DMI checking 805955633eSMichael D Labriola * below. 815955633eSMichael D Labriola */ 825955633eSMichael D Labriola reboot_default = 0; 835955633eSMichael D Labriola 844d022e35SMiguel Boton switch (*str) { 854d022e35SMiguel Boton case 'w': 864d022e35SMiguel Boton reboot_mode = 0x1234; 874d022e35SMiguel Boton break; 884d022e35SMiguel Boton 894d022e35SMiguel Boton case 'c': 904d022e35SMiguel Boton reboot_mode = 0; 914d022e35SMiguel Boton break; 924d022e35SMiguel Boton 934d022e35SMiguel Boton #ifdef CONFIG_X86_32 944d022e35SMiguel Boton #ifdef CONFIG_SMP 954d022e35SMiguel Boton case 's': 964d022e35SMiguel Boton if (isdigit(*(str+1))) { 974d022e35SMiguel Boton reboot_cpu = (int) (*(str+1) - '0'); 984d022e35SMiguel Boton if (isdigit(*(str+2))) 994d022e35SMiguel Boton reboot_cpu = reboot_cpu*10 + (int)(*(str+2) - '0'); 1004d022e35SMiguel Boton } 1014d022e35SMiguel Boton /* we will leave sorting out the final value 1024d022e35SMiguel Boton when we are ready to reboot, since we might not 103f6e9456cSRobert Richter have detected BSP APIC ID or smp_num_cpu */ 1044d022e35SMiguel Boton break; 1054d022e35SMiguel Boton #endif /* CONFIG_SMP */ 1064d022e35SMiguel Boton 1074d022e35SMiguel Boton case 'b': 1084d022e35SMiguel Boton #endif 1094d022e35SMiguel Boton case 'a': 1104d022e35SMiguel Boton case 'k': 1114d022e35SMiguel Boton case 't': 1124d022e35SMiguel Boton case 'e': 11314d7ca5cSH. Peter Anvin case 'p': 1144d022e35SMiguel Boton reboot_type = *str; 1154d022e35SMiguel Boton break; 1164d022e35SMiguel Boton 1174d022e35SMiguel Boton case 'f': 1184d022e35SMiguel Boton reboot_force = 1; 1194d022e35SMiguel Boton break; 1204d022e35SMiguel Boton } 1214d022e35SMiguel Boton 1224d022e35SMiguel Boton str = strchr(str, ','); 1234d022e35SMiguel Boton if (str) 1244d022e35SMiguel Boton str++; 1254d022e35SMiguel Boton else 1264d022e35SMiguel Boton break; 1274d022e35SMiguel Boton } 1284d022e35SMiguel Boton return 1; 1294d022e35SMiguel Boton } 1304d022e35SMiguel Boton 1314d022e35SMiguel Boton __setup("reboot=", reboot_setup); 1324d022e35SMiguel Boton 1334d022e35SMiguel Boton 1344d022e35SMiguel Boton #ifdef CONFIG_X86_32 1354d022e35SMiguel Boton /* 1364d022e35SMiguel Boton * Reboot options and system auto-detection code provided by 1374d022e35SMiguel Boton * Dell Inc. so their systems "just work". :-) 1384d022e35SMiguel Boton */ 1394d022e35SMiguel Boton 1404d022e35SMiguel Boton /* 1411ef03890SPeter Chubb * Some machines require the "reboot=b" or "reboot=k" commandline options, 1424d022e35SMiguel Boton * this quirk makes that automatic. 1434d022e35SMiguel Boton */ 1444d022e35SMiguel Boton static int __init set_bios_reboot(const struct dmi_system_id *d) 1454d022e35SMiguel Boton { 1464d022e35SMiguel Boton if (reboot_type != BOOT_BIOS) { 1474d022e35SMiguel Boton reboot_type = BOOT_BIOS; 1484d022e35SMiguel Boton printk(KERN_INFO "%s series board detected. Selecting BIOS-method for reboots.\n", d->ident); 1494d022e35SMiguel Boton } 1504d022e35SMiguel Boton return 0; 1514d022e35SMiguel Boton } 1524d022e35SMiguel Boton 153*57b16594SMichael D Labriola extern const unsigned char machine_real_restart_asm[]; 154*57b16594SMichael D Labriola extern const u64 machine_real_restart_gdt[3]; 155*57b16594SMichael D Labriola 156*57b16594SMichael D Labriola void machine_real_restart(unsigned int type) 157*57b16594SMichael D Labriola { 158*57b16594SMichael D Labriola void *restart_va; 159*57b16594SMichael D Labriola unsigned long restart_pa; 160*57b16594SMichael D Labriola void (*restart_lowmem)(unsigned int); 161*57b16594SMichael D Labriola u64 *lowmem_gdt; 162*57b16594SMichael D Labriola 163*57b16594SMichael D Labriola local_irq_disable(); 164*57b16594SMichael D Labriola 165*57b16594SMichael D Labriola /* Write zero to CMOS register number 0x0f, which the BIOS POST 166*57b16594SMichael D Labriola routine will recognize as telling it to do a proper reboot. (Well 167*57b16594SMichael D Labriola that's what this book in front of me says -- it may only apply to 168*57b16594SMichael D Labriola the Phoenix BIOS though, it's not clear). At the same time, 169*57b16594SMichael D Labriola disable NMIs by setting the top bit in the CMOS address register, 170*57b16594SMichael D Labriola as we're about to do peculiar things to the CPU. I'm not sure if 171*57b16594SMichael D Labriola `outb_p' is needed instead of just `outb'. Use it to be on the 172*57b16594SMichael D Labriola safe side. (Yes, CMOS_WRITE does outb_p's. - Paul G.) 173*57b16594SMichael D Labriola */ 174*57b16594SMichael D Labriola spin_lock(&rtc_lock); 175*57b16594SMichael D Labriola CMOS_WRITE(0x00, 0x8f); 176*57b16594SMichael D Labriola spin_unlock(&rtc_lock); 177*57b16594SMichael D Labriola 178*57b16594SMichael D Labriola /* 179*57b16594SMichael D Labriola * Switch back to the initial page table. 180*57b16594SMichael D Labriola */ 181*57b16594SMichael D Labriola load_cr3(initial_page_table); 182*57b16594SMichael D Labriola 183*57b16594SMichael D Labriola /* Write 0x1234 to absolute memory location 0x472. The BIOS reads 184*57b16594SMichael D Labriola this on booting to tell it to "Bypass memory test (also warm 185*57b16594SMichael D Labriola boot)". This seems like a fairly standard thing that gets set by 186*57b16594SMichael D Labriola REBOOT.COM programs, and the previous reset routine did this 187*57b16594SMichael D Labriola too. */ 188*57b16594SMichael D Labriola *((unsigned short *)0x472) = reboot_mode; 189*57b16594SMichael D Labriola 190*57b16594SMichael D Labriola /* Patch the GDT in the low memory trampoline */ 191*57b16594SMichael D Labriola lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt); 192*57b16594SMichael D Labriola 193*57b16594SMichael D Labriola restart_va = TRAMPOLINE_SYM(machine_real_restart_asm); 194*57b16594SMichael D Labriola restart_pa = virt_to_phys(restart_va); 195*57b16594SMichael D Labriola restart_lowmem = (void (*)(unsigned int))restart_pa; 196*57b16594SMichael D Labriola 197*57b16594SMichael D Labriola /* GDT[0]: GDT self-pointer */ 198*57b16594SMichael D Labriola lowmem_gdt[0] = 199*57b16594SMichael D Labriola (u64)(sizeof(machine_real_restart_gdt) - 1) + 200*57b16594SMichael D Labriola ((u64)virt_to_phys(lowmem_gdt) << 16); 201*57b16594SMichael D Labriola /* GDT[1]: 64K real mode code segment */ 202*57b16594SMichael D Labriola lowmem_gdt[1] = 203*57b16594SMichael D Labriola GDT_ENTRY(0x009b, restart_pa, 0xffff); 204*57b16594SMichael D Labriola 205*57b16594SMichael D Labriola /* Jump to the identity-mapped low memory code */ 206*57b16594SMichael D Labriola restart_lowmem(type); 207*57b16594SMichael D Labriola } 208*57b16594SMichael D Labriola #ifdef CONFIG_APM_MODULE 209*57b16594SMichael D Labriola EXPORT_SYMBOL(machine_real_restart); 210*57b16594SMichael D Labriola #endif 211*57b16594SMichael D Labriola 212*57b16594SMichael D Labriola #endif /* CONFIG_X86_32 */ 213*57b16594SMichael D Labriola 214*57b16594SMichael D Labriola /* 215*57b16594SMichael D Labriola * Some Apple MacBook and MacBookPro's needs reboot=p to be able to reboot 216*57b16594SMichael D Labriola */ 217*57b16594SMichael D Labriola static int __init set_pci_reboot(const struct dmi_system_id *d) 218*57b16594SMichael D Labriola { 219*57b16594SMichael D Labriola if (reboot_type != BOOT_CF9) { 220*57b16594SMichael D Labriola reboot_type = BOOT_CF9; 221*57b16594SMichael D Labriola printk(KERN_INFO "%s series board detected. " 222*57b16594SMichael D Labriola "Selecting PCI-method for reboots.\n", d->ident); 223*57b16594SMichael D Labriola } 224*57b16594SMichael D Labriola return 0; 225*57b16594SMichael D Labriola } 226*57b16594SMichael D Labriola 2271ef03890SPeter Chubb static int __init set_kbd_reboot(const struct dmi_system_id *d) 2281ef03890SPeter Chubb { 2291ef03890SPeter Chubb if (reboot_type != BOOT_KBD) { 2301ef03890SPeter Chubb reboot_type = BOOT_KBD; 2311ef03890SPeter Chubb printk(KERN_INFO "%s series board detected. Selecting KBD-method for reboot.\n", d->ident); 2321ef03890SPeter Chubb } 2331ef03890SPeter Chubb return 0; 2341ef03890SPeter Chubb } 2351ef03890SPeter Chubb 236*57b16594SMichael D Labriola /* This is a single dmi_table handling all reboot quirks. Note that 237*57b16594SMichael D Labriola * REBOOT_BIOS is only available for 32bit 238*57b16594SMichael D Labriola */ 2394d022e35SMiguel Boton static struct dmi_system_id __initdata reboot_dmi_table[] = { 240*57b16594SMichael D Labriola #ifdef CONFIG_X86_32 2414d022e35SMiguel Boton { /* Handle problems with rebooting on Dell E520's */ 2424d022e35SMiguel Boton .callback = set_bios_reboot, 2434d022e35SMiguel Boton .ident = "Dell E520", 2444d022e35SMiguel Boton .matches = { 2454d022e35SMiguel Boton DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 2464d022e35SMiguel Boton DMI_MATCH(DMI_PRODUCT_NAME, "Dell DM061"), 2474d022e35SMiguel Boton }, 2484d022e35SMiguel Boton }, 2494d022e35SMiguel Boton { /* Handle problems with rebooting on Dell 1300's */ 2504d022e35SMiguel Boton .callback = set_bios_reboot, 2514d022e35SMiguel Boton .ident = "Dell PowerEdge 1300", 2524d022e35SMiguel Boton .matches = { 2534d022e35SMiguel Boton DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), 2544d022e35SMiguel Boton DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1300/"), 2554d022e35SMiguel Boton }, 2564d022e35SMiguel Boton }, 2574d022e35SMiguel Boton { /* Handle problems with rebooting on Dell 300's */ 2584d022e35SMiguel Boton .callback = set_bios_reboot, 2594d022e35SMiguel Boton .ident = "Dell PowerEdge 300", 2604d022e35SMiguel Boton .matches = { 2614d022e35SMiguel Boton DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), 2624d022e35SMiguel Boton DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 300/"), 2634d022e35SMiguel Boton }, 2644d022e35SMiguel Boton }, 2654d022e35SMiguel Boton { /* Handle problems with rebooting on Dell Optiplex 745's SFF*/ 2664d022e35SMiguel Boton .callback = set_bios_reboot, 2674d022e35SMiguel Boton .ident = "Dell OptiPlex 745", 2684d022e35SMiguel Boton .matches = { 2694d022e35SMiguel Boton DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 2704d022e35SMiguel Boton DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"), 2714d022e35SMiguel Boton }, 2724d022e35SMiguel Boton }, 273fc115bf1SColeman Kane { /* Handle problems with rebooting on Dell Optiplex 745's DFF*/ 274fc115bf1SColeman Kane .callback = set_bios_reboot, 275fc115bf1SColeman Kane .ident = "Dell OptiPlex 745", 276fc115bf1SColeman Kane .matches = { 277fc115bf1SColeman Kane DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 278fc115bf1SColeman Kane DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"), 279fc115bf1SColeman Kane DMI_MATCH(DMI_BOARD_NAME, "0MM599"), 280fc115bf1SColeman Kane }, 281fc115bf1SColeman Kane }, 282fc1c8925SHeinz-Ado Arnolds { /* Handle problems with rebooting on Dell Optiplex 745 with 0KW626 */ 283fc1c8925SHeinz-Ado Arnolds .callback = set_bios_reboot, 284fc1c8925SHeinz-Ado Arnolds .ident = "Dell OptiPlex 745", 285fc1c8925SHeinz-Ado Arnolds .matches = { 286fc1c8925SHeinz-Ado Arnolds DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 287fc1c8925SHeinz-Ado Arnolds DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"), 288fc1c8925SHeinz-Ado Arnolds DMI_MATCH(DMI_BOARD_NAME, "0KW626"), 289fc1c8925SHeinz-Ado Arnolds }, 290fc1c8925SHeinz-Ado Arnolds }, 291093bac15SSteve Conklin { /* Handle problems with rebooting on Dell Optiplex 330 with 0KP561 */ 292093bac15SSteve Conklin .callback = set_bios_reboot, 293093bac15SSteve Conklin .ident = "Dell OptiPlex 330", 294093bac15SSteve Conklin .matches = { 295093bac15SSteve Conklin DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 296093bac15SSteve Conklin DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 330"), 297093bac15SSteve Conklin DMI_MATCH(DMI_BOARD_NAME, "0KP561"), 298093bac15SSteve Conklin }, 299093bac15SSteve Conklin }, 3004a4aca64SJean Delvare { /* Handle problems with rebooting on Dell Optiplex 360 with 0T656F */ 3014a4aca64SJean Delvare .callback = set_bios_reboot, 3024a4aca64SJean Delvare .ident = "Dell OptiPlex 360", 3034a4aca64SJean Delvare .matches = { 3044a4aca64SJean Delvare DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 3054a4aca64SJean Delvare DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 360"), 3064a4aca64SJean Delvare DMI_MATCH(DMI_BOARD_NAME, "0T656F"), 3074a4aca64SJean Delvare }, 3084a4aca64SJean Delvare }, 30935ea63d7SLeann Ogasawara { /* Handle problems with rebooting on Dell OptiPlex 760 with 0G919G*/ 31035ea63d7SLeann Ogasawara .callback = set_bios_reboot, 31135ea63d7SLeann Ogasawara .ident = "Dell OptiPlex 760", 31235ea63d7SLeann Ogasawara .matches = { 31335ea63d7SLeann Ogasawara DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 31435ea63d7SLeann Ogasawara DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 760"), 31535ea63d7SLeann Ogasawara DMI_MATCH(DMI_BOARD_NAME, "0G919G"), 31635ea63d7SLeann Ogasawara }, 31735ea63d7SLeann Ogasawara }, 3184d022e35SMiguel Boton { /* Handle problems with rebooting on Dell 2400's */ 3194d022e35SMiguel Boton .callback = set_bios_reboot, 3204d022e35SMiguel Boton .ident = "Dell PowerEdge 2400", 3214d022e35SMiguel Boton .matches = { 3224d022e35SMiguel Boton DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), 3234d022e35SMiguel Boton DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2400"), 3244d022e35SMiguel Boton }, 3254d022e35SMiguel Boton }, 326fab3b58dSIngo Molnar { /* Handle problems with rebooting on Dell T5400's */ 327fab3b58dSIngo Molnar .callback = set_bios_reboot, 328fab3b58dSIngo Molnar .ident = "Dell Precision T5400", 329fab3b58dSIngo Molnar .matches = { 330fab3b58dSIngo Molnar DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 331fab3b58dSIngo Molnar DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T5400"), 332fab3b58dSIngo Molnar }, 333fab3b58dSIngo Molnar }, 334890ffedcSThomas Backlund { /* Handle problems with rebooting on Dell T7400's */ 335890ffedcSThomas Backlund .callback = set_bios_reboot, 336890ffedcSThomas Backlund .ident = "Dell Precision T7400", 337890ffedcSThomas Backlund .matches = { 338890ffedcSThomas Backlund DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 339890ffedcSThomas Backlund DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T7400"), 340890ffedcSThomas Backlund }, 341890ffedcSThomas Backlund }, 3424d022e35SMiguel Boton { /* Handle problems with rebooting on HP laptops */ 3434d022e35SMiguel Boton .callback = set_bios_reboot, 3444d022e35SMiguel Boton .ident = "HP Compaq Laptop", 3454d022e35SMiguel Boton .matches = { 3464d022e35SMiguel Boton DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), 3474d022e35SMiguel Boton DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq"), 3484d022e35SMiguel Boton }, 3494d022e35SMiguel Boton }, 350dd4124a8SLeann Ogasawara { /* Handle problems with rebooting on Dell XPS710 */ 351dd4124a8SLeann Ogasawara .callback = set_bios_reboot, 352dd4124a8SLeann Ogasawara .ident = "Dell XPS710", 353dd4124a8SLeann Ogasawara .matches = { 354dd4124a8SLeann Ogasawara DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 355dd4124a8SLeann Ogasawara DMI_MATCH(DMI_PRODUCT_NAME, "Dell XPS710"), 356dd4124a8SLeann Ogasawara }, 357dd4124a8SLeann Ogasawara }, 358c5da9a2bSAlan Cox { /* Handle problems with rebooting on Dell DXP061 */ 359c5da9a2bSAlan Cox .callback = set_bios_reboot, 360c5da9a2bSAlan Cox .ident = "Dell DXP061", 361c5da9a2bSAlan Cox .matches = { 362c5da9a2bSAlan Cox DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 363c5da9a2bSAlan Cox DMI_MATCH(DMI_PRODUCT_NAME, "Dell DXP061"), 364c5da9a2bSAlan Cox }, 365c5da9a2bSAlan Cox }, 36688dff493SZhang Rui { /* Handle problems with rebooting on Sony VGN-Z540N */ 36788dff493SZhang Rui .callback = set_bios_reboot, 36888dff493SZhang Rui .ident = "Sony VGN-Z540N", 36988dff493SZhang Rui .matches = { 37088dff493SZhang Rui DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), 37188dff493SZhang Rui DMI_MATCH(DMI_PRODUCT_NAME, "VGN-Z540N"), 37288dff493SZhang Rui }, 37388dff493SZhang Rui }, 37477f32dfdSDenis Turischev { /* Handle problems with rebooting on CompuLab SBC-FITPC2 */ 37577f32dfdSDenis Turischev .callback = set_bios_reboot, 37677f32dfdSDenis Turischev .ident = "CompuLab SBC-FITPC2", 37777f32dfdSDenis Turischev .matches = { 37877f32dfdSDenis Turischev DMI_MATCH(DMI_SYS_VENDOR, "CompuLab"), 37977f32dfdSDenis Turischev DMI_MATCH(DMI_PRODUCT_NAME, "SBC-FITPC2"), 38077f32dfdSDenis Turischev }, 38177f32dfdSDenis Turischev }, 3824832dddaSLeann Ogasawara { /* Handle problems with rebooting on ASUS P4S800 */ 3834832dddaSLeann Ogasawara .callback = set_bios_reboot, 3844832dddaSLeann Ogasawara .ident = "ASUS P4S800", 3854832dddaSLeann Ogasawara .matches = { 3864832dddaSLeann Ogasawara DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), 3874832dddaSLeann Ogasawara DMI_MATCH(DMI_BOARD_NAME, "P4S800"), 3884832dddaSLeann Ogasawara }, 3894832dddaSLeann Ogasawara }, 390*57b16594SMichael D Labriola #endif /* CONFIG_X86_32 */ 391*57b16594SMichael D Labriola 392b49c78d4SPeter Chubb { /* Handle reboot issue on Acer Aspire one */ 3931ef03890SPeter Chubb .callback = set_kbd_reboot, 394b49c78d4SPeter Chubb .ident = "Acer Aspire One A110", 395b49c78d4SPeter Chubb .matches = { 396b49c78d4SPeter Chubb DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 397b49c78d4SPeter Chubb DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"), 398b49c78d4SPeter Chubb }, 399b49c78d4SPeter Chubb }, 4003e03bbeaSShunichi Fuji { /* Handle problems with rebooting on Apple MacBook5 */ 4016c6c51e4SPaul Mackerras .callback = set_pci_reboot, 4023e03bbeaSShunichi Fuji .ident = "Apple MacBook5", 4036c6c51e4SPaul Mackerras .matches = { 4046c6c51e4SPaul Mackerras DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 4053e03bbeaSShunichi Fuji DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5"), 4066c6c51e4SPaul Mackerras }, 4076c6c51e4SPaul Mackerras }, 4083e03bbeaSShunichi Fuji { /* Handle problems with rebooting on Apple MacBookPro5 */ 409498cdbfbSOzan Çağlayan .callback = set_pci_reboot, 4103e03bbeaSShunichi Fuji .ident = "Apple MacBookPro5", 411498cdbfbSOzan Çağlayan .matches = { 412498cdbfbSOzan Çağlayan DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 4133e03bbeaSShunichi Fuji DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5"), 414498cdbfbSOzan Çağlayan }, 415498cdbfbSOzan Çağlayan }, 41605154752SGottfried Haider { /* Handle problems with rebooting on Apple Macmini3,1 */ 41705154752SGottfried Haider .callback = set_pci_reboot, 41805154752SGottfried Haider .ident = "Apple Macmini3,1", 41905154752SGottfried Haider .matches = { 42005154752SGottfried Haider DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 42105154752SGottfried Haider DMI_MATCH(DMI_PRODUCT_NAME, "Macmini3,1"), 42205154752SGottfried Haider }, 42305154752SGottfried Haider }, 4240a832320SJustin P. Mattock { /* Handle problems with rebooting on the iMac9,1. */ 4250a832320SJustin P. Mattock .callback = set_pci_reboot, 4260a832320SJustin P. Mattock .ident = "Apple iMac9,1", 4270a832320SJustin P. Mattock .matches = { 4280a832320SJustin P. Mattock DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 4290a832320SJustin P. Mattock DMI_MATCH(DMI_PRODUCT_NAME, "iMac9,1"), 4300a832320SJustin P. Mattock }, 4310a832320SJustin P. Mattock }, 4323628c3f5SMaxime Ripard { /* Handle problems with rebooting on the Latitude E6320. */ 4333628c3f5SMaxime Ripard .callback = set_pci_reboot, 4343628c3f5SMaxime Ripard .ident = "Dell Latitude E6320", 4353628c3f5SMaxime Ripard .matches = { 4363628c3f5SMaxime Ripard DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 4373628c3f5SMaxime Ripard DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6320"), 4383628c3f5SMaxime Ripard }, 4393628c3f5SMaxime Ripard }, 440b7798d28SDaniel J Blueman { /* Handle problems with rebooting on the Latitude E5420. */ 441b7798d28SDaniel J Blueman .callback = set_pci_reboot, 442b7798d28SDaniel J Blueman .ident = "Dell Latitude E5420", 443b7798d28SDaniel J Blueman .matches = { 444b7798d28SDaniel J Blueman DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 445b7798d28SDaniel J Blueman DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5420"), 446b7798d28SDaniel J Blueman }, 447b7798d28SDaniel J Blueman }, 448a536877eSH. Peter Anvin { /* Handle problems with rebooting on the Latitude E6420. */ 449a536877eSH. Peter Anvin .callback = set_pci_reboot, 450a536877eSH. Peter Anvin .ident = "Dell Latitude E6420", 451a536877eSH. Peter Anvin .matches = { 452a536877eSH. Peter Anvin DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 453a536877eSH. Peter Anvin DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6420"), 454a536877eSH. Peter Anvin }, 455a536877eSH. Peter Anvin }, 4566be30bb7SRafael J. Wysocki { /* Handle problems with rebooting on the OptiPlex 990. */ 4576be30bb7SRafael J. Wysocki .callback = set_pci_reboot, 4586be30bb7SRafael J. Wysocki .ident = "Dell OptiPlex 990", 4596be30bb7SRafael J. Wysocki .matches = { 4606be30bb7SRafael J. Wysocki DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 4616be30bb7SRafael J. Wysocki DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 990"), 4626be30bb7SRafael J. Wysocki }, 4636be30bb7SRafael J. Wysocki }, 4646c6c51e4SPaul Mackerras { } 4656c6c51e4SPaul Mackerras }; 4666c6c51e4SPaul Mackerras 467*57b16594SMichael D Labriola static int __init reboot_init(void) 4686c6c51e4SPaul Mackerras { 4695955633eSMichael D Labriola /* Only do the DMI check if reboot_type hasn't been overridden 4705955633eSMichael D Labriola * on the command line 4715955633eSMichael D Labriola */ 4725955633eSMichael D Labriola if (reboot_default) { 473*57b16594SMichael D Labriola dmi_check_system(reboot_dmi_table); 4745955633eSMichael D Labriola } 4756c6c51e4SPaul Mackerras return 0; 4766c6c51e4SPaul Mackerras } 477*57b16594SMichael D Labriola core_initcall(reboot_init); 4786c6c51e4SPaul Mackerras 4794d022e35SMiguel Boton static inline void kb_wait(void) 4804d022e35SMiguel Boton { 4814d022e35SMiguel Boton int i; 4824d022e35SMiguel Boton 483c84d6af8SAlan Cox for (i = 0; i < 0x10000; i++) { 484c84d6af8SAlan Cox if ((inb(0x64) & 0x02) == 0) 4854d022e35SMiguel Boton break; 486c84d6af8SAlan Cox udelay(2); 487c84d6af8SAlan Cox } 4884d022e35SMiguel Boton } 4894d022e35SMiguel Boton 4909c48f1c6SDon Zickus static void vmxoff_nmi(int cpu, struct pt_regs *regs) 491d176720dSEduardo Habkost { 492d176720dSEduardo Habkost cpu_emergency_vmxoff(); 493d176720dSEduardo Habkost } 494d176720dSEduardo Habkost 495d176720dSEduardo Habkost /* Use NMIs as IPIs to tell all CPUs to disable virtualization 496d176720dSEduardo Habkost */ 497d176720dSEduardo Habkost static void emergency_vmx_disable_all(void) 498d176720dSEduardo Habkost { 499d176720dSEduardo Habkost /* Just make sure we won't change CPUs while doing this */ 500d176720dSEduardo Habkost local_irq_disable(); 501d176720dSEduardo Habkost 502d176720dSEduardo Habkost /* We need to disable VMX on all CPUs before rebooting, otherwise 503d176720dSEduardo Habkost * we risk hanging up the machine, because the CPU ignore INIT 504d176720dSEduardo Habkost * signals when VMX is enabled. 505d176720dSEduardo Habkost * 506d176720dSEduardo Habkost * We can't take any locks and we may be on an inconsistent 507d176720dSEduardo Habkost * state, so we use NMIs as IPIs to tell the other CPUs to disable 508d176720dSEduardo Habkost * VMX and halt. 509d176720dSEduardo Habkost * 510d176720dSEduardo Habkost * For safety, we will avoid running the nmi_shootdown_cpus() 511d176720dSEduardo Habkost * stuff unnecessarily, but we don't have a way to check 512d176720dSEduardo Habkost * if other CPUs have VMX enabled. So we will call it only if the 513d176720dSEduardo Habkost * CPU we are running on has VMX enabled. 514d176720dSEduardo Habkost * 515d176720dSEduardo Habkost * We will miss cases where VMX is not enabled on all CPUs. This 516d176720dSEduardo Habkost * shouldn't do much harm because KVM always enable VMX on all 517d176720dSEduardo Habkost * CPUs anyway. But we can miss it on the small window where KVM 518d176720dSEduardo Habkost * is still enabling VMX. 519d176720dSEduardo Habkost */ 520d176720dSEduardo Habkost if (cpu_has_vmx() && cpu_vmx_enabled()) { 521d176720dSEduardo Habkost /* Disable VMX on this CPU. 522d176720dSEduardo Habkost */ 523d176720dSEduardo Habkost cpu_vmxoff(); 524d176720dSEduardo Habkost 525d176720dSEduardo Habkost /* Halt and disable VMX on the other CPUs */ 526d176720dSEduardo Habkost nmi_shootdown_cpus(vmxoff_nmi); 527d176720dSEduardo Habkost 528d176720dSEduardo Habkost } 529d176720dSEduardo Habkost } 530d176720dSEduardo Habkost 531d176720dSEduardo Habkost 5327432d149SIngo Molnar void __attribute__((weak)) mach_reboot_fixups(void) 5337432d149SIngo Molnar { 5347432d149SIngo Molnar } 5357432d149SIngo Molnar 536660e34ceSMatthew Garrett /* 537660e34ceSMatthew Garrett * Windows compatible x86 hardware expects the following on reboot: 538660e34ceSMatthew Garrett * 539660e34ceSMatthew Garrett * 1) If the FADT has the ACPI reboot register flag set, try it 540660e34ceSMatthew Garrett * 2) If still alive, write to the keyboard controller 541660e34ceSMatthew Garrett * 3) If still alive, write to the ACPI reboot register again 542660e34ceSMatthew Garrett * 4) If still alive, write to the keyboard controller again 543660e34ceSMatthew Garrett * 544660e34ceSMatthew Garrett * If the machine is still alive at this stage, it gives up. We default to 545660e34ceSMatthew Garrett * following the same pattern, except that if we're still alive after (4) we'll 546660e34ceSMatthew Garrett * try to force a triple fault and then cycle between hitting the keyboard 547660e34ceSMatthew Garrett * controller and doing that 548660e34ceSMatthew Garrett */ 549416e2d63SJody Belka static void native_machine_emergency_restart(void) 5504d022e35SMiguel Boton { 5514d022e35SMiguel Boton int i; 552660e34ceSMatthew Garrett int attempt = 0; 553660e34ceSMatthew Garrett int orig_reboot_type = reboot_type; 5544d022e35SMiguel Boton 555d176720dSEduardo Habkost if (reboot_emergency) 556d176720dSEduardo Habkost emergency_vmx_disable_all(); 557d176720dSEduardo Habkost 558840c2bafSJoseph Cihula tboot_shutdown(TB_SHUTDOWN_REBOOT); 559840c2bafSJoseph Cihula 5604d022e35SMiguel Boton /* Tell the BIOS if we want cold or warm reboot */ 5614d022e35SMiguel Boton *((unsigned short *)__va(0x472)) = reboot_mode; 5624d022e35SMiguel Boton 5634d022e35SMiguel Boton for (;;) { 5644d022e35SMiguel Boton /* Could also try the reset bit in the Hammer NB */ 5654d022e35SMiguel Boton switch (reboot_type) { 5664d022e35SMiguel Boton case BOOT_KBD: 5677432d149SIngo Molnar mach_reboot_fixups(); /* for board specific fixups */ 5687432d149SIngo Molnar 5694d022e35SMiguel Boton for (i = 0; i < 10; i++) { 5704d022e35SMiguel Boton kb_wait(); 5714d022e35SMiguel Boton udelay(50); 5724d022e35SMiguel Boton outb(0xfe, 0x64); /* pulse reset low */ 5734d022e35SMiguel Boton udelay(50); 5744d022e35SMiguel Boton } 575660e34ceSMatthew Garrett if (attempt == 0 && orig_reboot_type == BOOT_ACPI) { 576660e34ceSMatthew Garrett attempt = 1; 577660e34ceSMatthew Garrett reboot_type = BOOT_ACPI; 578660e34ceSMatthew Garrett } else { 579660e34ceSMatthew Garrett reboot_type = BOOT_TRIPLE; 580660e34ceSMatthew Garrett } 581660e34ceSMatthew Garrett break; 5824d022e35SMiguel Boton 5834d022e35SMiguel Boton case BOOT_TRIPLE: 584ebdd561aSJan Beulich load_idt(&no_idt); 5854d022e35SMiguel Boton __asm__ __volatile__("int3"); 5864d022e35SMiguel Boton 5874d022e35SMiguel Boton reboot_type = BOOT_KBD; 5884d022e35SMiguel Boton break; 5894d022e35SMiguel Boton 5904d022e35SMiguel Boton #ifdef CONFIG_X86_32 5914d022e35SMiguel Boton case BOOT_BIOS: 5923d35ac34SH. Peter Anvin machine_real_restart(MRR_BIOS); 5934d022e35SMiguel Boton 5944d022e35SMiguel Boton reboot_type = BOOT_KBD; 5954d022e35SMiguel Boton break; 5964d022e35SMiguel Boton #endif 5974d022e35SMiguel Boton 5984d022e35SMiguel Boton case BOOT_ACPI: 5994d022e35SMiguel Boton acpi_reboot(); 6004d022e35SMiguel Boton reboot_type = BOOT_KBD; 6014d022e35SMiguel Boton break; 6024d022e35SMiguel Boton 6034d022e35SMiguel Boton case BOOT_EFI: 6044d022e35SMiguel Boton if (efi_enabled) 60514d7ca5cSH. Peter Anvin efi.reset_system(reboot_mode ? 60614d7ca5cSH. Peter Anvin EFI_RESET_WARM : 60714d7ca5cSH. Peter Anvin EFI_RESET_COLD, 6084d022e35SMiguel Boton EFI_SUCCESS, 0, NULL); 609b47b9288SH. Peter Anvin reboot_type = BOOT_KBD; 61014d7ca5cSH. Peter Anvin break; 6114d022e35SMiguel Boton 61214d7ca5cSH. Peter Anvin case BOOT_CF9: 61314d7ca5cSH. Peter Anvin port_cf9_safe = true; 61414d7ca5cSH. Peter Anvin /* fall through */ 61514d7ca5cSH. Peter Anvin 61614d7ca5cSH. Peter Anvin case BOOT_CF9_COND: 61714d7ca5cSH. Peter Anvin if (port_cf9_safe) { 61814d7ca5cSH. Peter Anvin u8 cf9 = inb(0xcf9) & ~6; 61914d7ca5cSH. Peter Anvin outb(cf9|2, 0xcf9); /* Request hard reset */ 62014d7ca5cSH. Peter Anvin udelay(50); 62114d7ca5cSH. Peter Anvin outb(cf9|6, 0xcf9); /* Actually do the reset */ 62214d7ca5cSH. Peter Anvin udelay(50); 62314d7ca5cSH. Peter Anvin } 6244d022e35SMiguel Boton reboot_type = BOOT_KBD; 6254d022e35SMiguel Boton break; 6264d022e35SMiguel Boton } 6274d022e35SMiguel Boton } 6284d022e35SMiguel Boton } 6294d022e35SMiguel Boton 6303c62c625SGlauber Costa void native_machine_shutdown(void) 6314d022e35SMiguel Boton { 6324d022e35SMiguel Boton /* Stop the cpus and apics */ 6334d022e35SMiguel Boton #ifdef CONFIG_SMP 6344d022e35SMiguel Boton 6354d022e35SMiguel Boton /* The boot cpu is always logical cpu 0 */ 63665c01184SMike Travis int reboot_cpu_id = 0; 6374d022e35SMiguel Boton 6384d022e35SMiguel Boton #ifdef CONFIG_X86_32 6394d022e35SMiguel Boton /* See if there has been given a command line override */ 6409628937dSMike Travis if ((reboot_cpu != -1) && (reboot_cpu < nr_cpu_ids) && 6410bc3cc03SMike Travis cpu_online(reboot_cpu)) 6424d022e35SMiguel Boton reboot_cpu_id = reboot_cpu; 6434d022e35SMiguel Boton #endif 6444d022e35SMiguel Boton 6454d022e35SMiguel Boton /* Make certain the cpu I'm about to reboot on is online */ 6460bc3cc03SMike Travis if (!cpu_online(reboot_cpu_id)) 6474d022e35SMiguel Boton reboot_cpu_id = smp_processor_id(); 6484d022e35SMiguel Boton 6494d022e35SMiguel Boton /* Make certain I only run on the appropriate processor */ 6509628937dSMike Travis set_cpus_allowed_ptr(current, cpumask_of(reboot_cpu_id)); 6514d022e35SMiguel Boton 6524d022e35SMiguel Boton /* O.K Now that I'm on the appropriate processor, 6534d022e35SMiguel Boton * stop all of the others. 6544d022e35SMiguel Boton */ 65576fac077SAlok Kataria stop_other_cpus(); 6564d022e35SMiguel Boton #endif 6574d022e35SMiguel Boton 6584d022e35SMiguel Boton lapic_shutdown(); 6594d022e35SMiguel Boton 6604d022e35SMiguel Boton #ifdef CONFIG_X86_IO_APIC 6614d022e35SMiguel Boton disable_IO_APIC(); 6624d022e35SMiguel Boton #endif 6634d022e35SMiguel Boton 6644d022e35SMiguel Boton #ifdef CONFIG_HPET_TIMER 6654d022e35SMiguel Boton hpet_disable(); 6664d022e35SMiguel Boton #endif 6674d022e35SMiguel Boton 6684d022e35SMiguel Boton #ifdef CONFIG_X86_64 669338bac52SFUJITA Tomonori x86_platform.iommu_shutdown(); 6704d022e35SMiguel Boton #endif 6714d022e35SMiguel Boton } 6724d022e35SMiguel Boton 673d176720dSEduardo Habkost static void __machine_emergency_restart(int emergency) 674d176720dSEduardo Habkost { 675d176720dSEduardo Habkost reboot_emergency = emergency; 676d176720dSEduardo Habkost machine_ops.emergency_restart(); 677d176720dSEduardo Habkost } 678d176720dSEduardo Habkost 679416e2d63SJody Belka static void native_machine_restart(char *__unused) 6804d022e35SMiguel Boton { 6814d022e35SMiguel Boton printk("machine restart\n"); 6824d022e35SMiguel Boton 6834d022e35SMiguel Boton if (!reboot_force) 6844d022e35SMiguel Boton machine_shutdown(); 685d176720dSEduardo Habkost __machine_emergency_restart(0); 6864d022e35SMiguel Boton } 6874d022e35SMiguel Boton 688416e2d63SJody Belka static void native_machine_halt(void) 6894d022e35SMiguel Boton { 690d3ec5caeSIvan Vecera /* stop other cpus and apics */ 691d3ec5caeSIvan Vecera machine_shutdown(); 692d3ec5caeSIvan Vecera 693840c2bafSJoseph Cihula tboot_shutdown(TB_SHUTDOWN_HALT); 694840c2bafSJoseph Cihula 695d3ec5caeSIvan Vecera /* stop this cpu */ 696d3ec5caeSIvan Vecera stop_this_cpu(NULL); 6974d022e35SMiguel Boton } 6984d022e35SMiguel Boton 699416e2d63SJody Belka static void native_machine_power_off(void) 7004d022e35SMiguel Boton { 7014d022e35SMiguel Boton if (pm_power_off) { 7024d022e35SMiguel Boton if (!reboot_force) 7034d022e35SMiguel Boton machine_shutdown(); 7044d022e35SMiguel Boton pm_power_off(); 7054d022e35SMiguel Boton } 706840c2bafSJoseph Cihula /* a fallback in case there is no PM info available */ 707840c2bafSJoseph Cihula tboot_shutdown(TB_SHUTDOWN_HALT); 7084d022e35SMiguel Boton } 7094d022e35SMiguel Boton 7104d022e35SMiguel Boton struct machine_ops machine_ops = { 711416e2d63SJody Belka .power_off = native_machine_power_off, 712416e2d63SJody Belka .shutdown = native_machine_shutdown, 713416e2d63SJody Belka .emergency_restart = native_machine_emergency_restart, 714416e2d63SJody Belka .restart = native_machine_restart, 715ed23dc6fSGlauber Costa .halt = native_machine_halt, 716ed23dc6fSGlauber Costa #ifdef CONFIG_KEXEC 717ed23dc6fSGlauber Costa .crash_shutdown = native_machine_crash_shutdown, 718ed23dc6fSGlauber Costa #endif 7194d022e35SMiguel Boton }; 720416e2d63SJody Belka 721416e2d63SJody Belka void machine_power_off(void) 722416e2d63SJody Belka { 723416e2d63SJody Belka machine_ops.power_off(); 724416e2d63SJody Belka } 725416e2d63SJody Belka 726416e2d63SJody Belka void machine_shutdown(void) 727416e2d63SJody Belka { 728416e2d63SJody Belka machine_ops.shutdown(); 729416e2d63SJody Belka } 730416e2d63SJody Belka 731416e2d63SJody Belka void machine_emergency_restart(void) 732416e2d63SJody Belka { 733d176720dSEduardo Habkost __machine_emergency_restart(1); 734416e2d63SJody Belka } 735416e2d63SJody Belka 736416e2d63SJody Belka void machine_restart(char *cmd) 737416e2d63SJody Belka { 738416e2d63SJody Belka machine_ops.restart(cmd); 739416e2d63SJody Belka } 740416e2d63SJody Belka 741416e2d63SJody Belka void machine_halt(void) 742416e2d63SJody Belka { 743416e2d63SJody Belka machine_ops.halt(); 744416e2d63SJody Belka } 745416e2d63SJody Belka 746ed23dc6fSGlauber Costa #ifdef CONFIG_KEXEC 747ed23dc6fSGlauber Costa void machine_crash_shutdown(struct pt_regs *regs) 748ed23dc6fSGlauber Costa { 749ed23dc6fSGlauber Costa machine_ops.crash_shutdown(regs); 750ed23dc6fSGlauber Costa } 751ed23dc6fSGlauber Costa #endif 7522ddded21SEduardo Habkost 7532ddded21SEduardo Habkost 754bb8dd270SEduardo Habkost #if defined(CONFIG_SMP) 7552ddded21SEduardo Habkost 7562ddded21SEduardo Habkost /* This keeps a track of which one is crashing cpu. */ 7572ddded21SEduardo Habkost static int crashing_cpu; 7582ddded21SEduardo Habkost static nmi_shootdown_cb shootdown_callback; 7592ddded21SEduardo Habkost 7602ddded21SEduardo Habkost static atomic_t waiting_for_crash_ipi; 7612ddded21SEduardo Habkost 7629c48f1c6SDon Zickus static int crash_nmi_callback(unsigned int val, struct pt_regs *regs) 7632ddded21SEduardo Habkost { 7642ddded21SEduardo Habkost int cpu; 7652ddded21SEduardo Habkost 7662ddded21SEduardo Habkost cpu = raw_smp_processor_id(); 7672ddded21SEduardo Habkost 7682ddded21SEduardo Habkost /* Don't do anything if this handler is invoked on crashing cpu. 7692ddded21SEduardo Habkost * Otherwise, system will completely hang. Crashing cpu can get 7702ddded21SEduardo Habkost * an NMI if system was initially booted with nmi_watchdog parameter. 7712ddded21SEduardo Habkost */ 7722ddded21SEduardo Habkost if (cpu == crashing_cpu) 7739c48f1c6SDon Zickus return NMI_HANDLED; 7742ddded21SEduardo Habkost local_irq_disable(); 7752ddded21SEduardo Habkost 7769c48f1c6SDon Zickus shootdown_callback(cpu, regs); 7772ddded21SEduardo Habkost 7782ddded21SEduardo Habkost atomic_dec(&waiting_for_crash_ipi); 7792ddded21SEduardo Habkost /* Assume hlt works */ 7802ddded21SEduardo Habkost halt(); 7812ddded21SEduardo Habkost for (;;) 7822ddded21SEduardo Habkost cpu_relax(); 7832ddded21SEduardo Habkost 7849c48f1c6SDon Zickus return NMI_HANDLED; 7852ddded21SEduardo Habkost } 7862ddded21SEduardo Habkost 7872ddded21SEduardo Habkost static void smp_send_nmi_allbutself(void) 7882ddded21SEduardo Habkost { 789dac5f412SIngo Molnar apic->send_IPI_allbutself(NMI_VECTOR); 7902ddded21SEduardo Habkost } 7912ddded21SEduardo Habkost 792bb8dd270SEduardo Habkost /* Halt all other CPUs, calling the specified function on each of them 793bb8dd270SEduardo Habkost * 794bb8dd270SEduardo Habkost * This function can be used to halt all other CPUs on crash 795bb8dd270SEduardo Habkost * or emergency reboot time. The function passed as parameter 796bb8dd270SEduardo Habkost * will be called inside a NMI handler on all CPUs. 797bb8dd270SEduardo Habkost */ 7982ddded21SEduardo Habkost void nmi_shootdown_cpus(nmi_shootdown_cb callback) 7992ddded21SEduardo Habkost { 8002ddded21SEduardo Habkost unsigned long msecs; 801c415b3dcSEduardo Habkost local_irq_disable(); 8022ddded21SEduardo Habkost 8032ddded21SEduardo Habkost /* Make a note of crashing cpu. Will be used in NMI callback.*/ 8042ddded21SEduardo Habkost crashing_cpu = safe_smp_processor_id(); 8052ddded21SEduardo Habkost 8062ddded21SEduardo Habkost shootdown_callback = callback; 8072ddded21SEduardo Habkost 8082ddded21SEduardo Habkost atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1); 8092ddded21SEduardo Habkost /* Would it be better to replace the trap vector here? */ 8109c48f1c6SDon Zickus if (register_nmi_handler(NMI_LOCAL, crash_nmi_callback, 8119c48f1c6SDon Zickus NMI_FLAG_FIRST, "crash")) 8122ddded21SEduardo Habkost return; /* return what? */ 8132ddded21SEduardo Habkost /* Ensure the new callback function is set before sending 8142ddded21SEduardo Habkost * out the NMI 8152ddded21SEduardo Habkost */ 8162ddded21SEduardo Habkost wmb(); 8172ddded21SEduardo Habkost 8182ddded21SEduardo Habkost smp_send_nmi_allbutself(); 8192ddded21SEduardo Habkost 8202ddded21SEduardo Habkost msecs = 1000; /* Wait at most a second for the other cpus to stop */ 8212ddded21SEduardo Habkost while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) { 8222ddded21SEduardo Habkost mdelay(1); 8232ddded21SEduardo Habkost msecs--; 8242ddded21SEduardo Habkost } 8252ddded21SEduardo Habkost 8262ddded21SEduardo Habkost /* Leave the nmi callback set */ 8272ddded21SEduardo Habkost } 828bb8dd270SEduardo Habkost #else /* !CONFIG_SMP */ 829bb8dd270SEduardo Habkost void nmi_shootdown_cpus(nmi_shootdown_cb callback) 830bb8dd270SEduardo Habkost { 831bb8dd270SEduardo Habkost /* No other CPUs to shoot down */ 832bb8dd270SEduardo Habkost } 8332ddded21SEduardo Habkost #endif 834