1c767a54bSJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 2c767a54bSJoe Perches 34d022e35SMiguel Boton #include <linux/module.h> 44d022e35SMiguel Boton #include <linux/reboot.h> 54d022e35SMiguel Boton #include <linux/init.h> 64d022e35SMiguel Boton #include <linux/pm.h> 74d022e35SMiguel Boton #include <linux/efi.h> 86c6c51e4SPaul Mackerras #include <linux/dmi.h> 9d43c36dcSAlexey Dobriyan #include <linux/sched.h> 1069575d38SShane Wang #include <linux/tboot.h> 11ca444564SJean Delvare #include <linux/delay.h> 124d022e35SMiguel Boton #include <acpi/reboot.h> 134d022e35SMiguel Boton #include <asm/io.h> 144d022e35SMiguel Boton #include <asm/apic.h> 154d022e35SMiguel Boton #include <asm/desc.h> 164d022e35SMiguel Boton #include <asm/hpet.h> 1768db065cSJeremy Fitzhardinge #include <asm/pgtable.h> 184412620fSDmitri Vorobiev #include <asm/proto.h> 194d022e35SMiguel Boton #include <asm/reboot_fixups.h> 204d022e35SMiguel Boton #include <asm/reboot.h> 2182487711SJaswinder Singh Rajput #include <asm/pci_x86.h> 22d176720dSEduardo Habkost #include <asm/virtext.h> 2396b89dc6SJaswinder Singh Rajput #include <asm/cpu.h> 24c410b830SDon Zickus #include <asm/nmi.h> 2565051397SH. Peter Anvin #include <asm/smp.h> 264d022e35SMiguel Boton 274d022e35SMiguel Boton #include <linux/ctype.h> 284d022e35SMiguel Boton #include <linux/mc146818rtc.h> 295a8c9aebSJarkko Sakkinen #include <asm/realmode.h> 30338bac52SFUJITA Tomonori #include <asm/x86_init.h> 314d022e35SMiguel Boton 324d022e35SMiguel Boton /* 334d022e35SMiguel Boton * Power off function, if any 344d022e35SMiguel Boton */ 354d022e35SMiguel Boton void (*pm_power_off)(void); 364d022e35SMiguel Boton EXPORT_SYMBOL(pm_power_off); 374d022e35SMiguel Boton 38ebdd561aSJan Beulich static const struct desc_ptr no_idt = {}; 394d022e35SMiguel Boton 40144d102bSMichael D Labriola /* 41144d102bSMichael D Labriola * This is set if we need to go through the 'emergency' path. 42d176720dSEduardo Habkost * When machine_emergency_restart() is called, we may be on 43d176720dSEduardo Habkost * an inconsistent state and won't be able to do a clean cleanup 44d176720dSEduardo Habkost */ 45d176720dSEduardo Habkost static int reboot_emergency; 46d176720dSEduardo Habkost 4714d7ca5cSH. Peter Anvin /* This is set by the PCI code if either type 1 or type 2 PCI is detected */ 4814d7ca5cSH. Peter Anvin bool port_cf9_safe = false; 4914d7ca5cSH. Peter Anvin 50144d102bSMichael D Labriola /* 514d022e35SMiguel Boton * Reboot options and system auto-detection code provided by 524d022e35SMiguel Boton * Dell Inc. so their systems "just work". :-) 534d022e35SMiguel Boton */ 544d022e35SMiguel Boton 554d022e35SMiguel Boton /* 561ef03890SPeter Chubb * Some machines require the "reboot=b" or "reboot=k" commandline options, 574d022e35SMiguel Boton * this quirk makes that automatic. 584d022e35SMiguel Boton */ 594d022e35SMiguel Boton static int __init set_bios_reboot(const struct dmi_system_id *d) 604d022e35SMiguel Boton { 614d022e35SMiguel Boton if (reboot_type != BOOT_BIOS) { 624d022e35SMiguel Boton reboot_type = BOOT_BIOS; 63c767a54bSJoe Perches pr_info("%s series board detected. Selecting %s-method for reboots.\n", 64c767a54bSJoe Perches "BIOS", d->ident); 654d022e35SMiguel Boton } 664d022e35SMiguel Boton return 0; 674d022e35SMiguel Boton } 684d022e35SMiguel Boton 6965051397SH. Peter Anvin void __noreturn machine_real_restart(unsigned int type) 7057b16594SMichael D Labriola { 7157b16594SMichael D Labriola local_irq_disable(); 7257b16594SMichael D Labriola 73144d102bSMichael D Labriola /* 74144d102bSMichael D Labriola * Write zero to CMOS register number 0x0f, which the BIOS POST 75144d102bSMichael D Labriola * routine will recognize as telling it to do a proper reboot. (Well 76144d102bSMichael D Labriola * that's what this book in front of me says -- it may only apply to 77144d102bSMichael D Labriola * the Phoenix BIOS though, it's not clear). At the same time, 78144d102bSMichael D Labriola * disable NMIs by setting the top bit in the CMOS address register, 79144d102bSMichael D Labriola * as we're about to do peculiar things to the CPU. I'm not sure if 80144d102bSMichael D Labriola * `outb_p' is needed instead of just `outb'. Use it to be on the 81144d102bSMichael D Labriola * safe side. (Yes, CMOS_WRITE does outb_p's. - Paul G.) 8257b16594SMichael D Labriola */ 8357b16594SMichael D Labriola spin_lock(&rtc_lock); 8457b16594SMichael D Labriola CMOS_WRITE(0x00, 0x8f); 8557b16594SMichael D Labriola spin_unlock(&rtc_lock); 8657b16594SMichael D Labriola 8757b16594SMichael D Labriola /* 8857b16594SMichael D Labriola * Switch back to the initial page table. 8957b16594SMichael D Labriola */ 9065051397SH. Peter Anvin #ifdef CONFIG_X86_32 9157b16594SMichael D Labriola load_cr3(initial_page_table); 9265051397SH. Peter Anvin #else 9365051397SH. Peter Anvin write_cr3(real_mode_header->trampoline_pgd); 9465051397SH. Peter Anvin #endif 9557b16594SMichael D Labriola 9657b16594SMichael D Labriola /* Jump to the identity-mapped low memory code */ 9765051397SH. Peter Anvin #ifdef CONFIG_X86_32 9865051397SH. Peter Anvin asm volatile("jmpl *%0" : : 9965051397SH. Peter Anvin "rm" (real_mode_header->machine_real_restart_asm), 10065051397SH. Peter Anvin "a" (type)); 10165051397SH. Peter Anvin #else 10265051397SH. Peter Anvin asm volatile("ljmpl *%0" : : 10365051397SH. Peter Anvin "m" (real_mode_header->machine_real_restart_asm), 10465051397SH. Peter Anvin "D" (type)); 10565051397SH. Peter Anvin #endif 10665051397SH. Peter Anvin unreachable(); 10757b16594SMichael D Labriola } 10857b16594SMichael D Labriola #ifdef CONFIG_APM_MODULE 10957b16594SMichael D Labriola EXPORT_SYMBOL(machine_real_restart); 11057b16594SMichael D Labriola #endif 11157b16594SMichael D Labriola 11257b16594SMichael D Labriola /* 11357b16594SMichael D Labriola * Some Apple MacBook and MacBookPro's needs reboot=p to be able to reboot 11457b16594SMichael D Labriola */ 11557b16594SMichael D Labriola static int __init set_pci_reboot(const struct dmi_system_id *d) 11657b16594SMichael D Labriola { 11757b16594SMichael D Labriola if (reboot_type != BOOT_CF9) { 11857b16594SMichael D Labriola reboot_type = BOOT_CF9; 119c767a54bSJoe Perches pr_info("%s series board detected. Selecting %s-method for reboots.\n", 120c767a54bSJoe Perches "PCI", d->ident); 12157b16594SMichael D Labriola } 12257b16594SMichael D Labriola return 0; 12357b16594SMichael D Labriola } 12457b16594SMichael D Labriola 1251ef03890SPeter Chubb static int __init set_kbd_reboot(const struct dmi_system_id *d) 1261ef03890SPeter Chubb { 1271ef03890SPeter Chubb if (reboot_type != BOOT_KBD) { 1281ef03890SPeter Chubb reboot_type = BOOT_KBD; 129c767a54bSJoe Perches pr_info("%s series board detected. Selecting %s-method for reboot.\n", 130c767a54bSJoe Perches "KBD", d->ident); 1311ef03890SPeter Chubb } 1321ef03890SPeter Chubb return 0; 1331ef03890SPeter Chubb } 1341ef03890SPeter Chubb 135144d102bSMichael D Labriola /* 13665051397SH. Peter Anvin * This is a single dmi_table handling all reboot quirks. 13757b16594SMichael D Labriola */ 1384d022e35SMiguel Boton static struct dmi_system_id __initdata reboot_dmi_table[] = { 1394d022e35SMiguel Boton { /* Handle problems with rebooting on Dell E520's */ 1404d022e35SMiguel Boton .callback = set_bios_reboot, 1414d022e35SMiguel Boton .ident = "Dell E520", 1424d022e35SMiguel Boton .matches = { 1434d022e35SMiguel Boton DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 1444d022e35SMiguel Boton DMI_MATCH(DMI_PRODUCT_NAME, "Dell DM061"), 1454d022e35SMiguel Boton }, 1464d022e35SMiguel Boton }, 1474d022e35SMiguel Boton { /* Handle problems with rebooting on Dell 1300's */ 1484d022e35SMiguel Boton .callback = set_bios_reboot, 1494d022e35SMiguel Boton .ident = "Dell PowerEdge 1300", 1504d022e35SMiguel Boton .matches = { 1514d022e35SMiguel Boton DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), 1524d022e35SMiguel Boton DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1300/"), 1534d022e35SMiguel Boton }, 1544d022e35SMiguel Boton }, 1554d022e35SMiguel Boton { /* Handle problems with rebooting on Dell 300's */ 1564d022e35SMiguel Boton .callback = set_bios_reboot, 1574d022e35SMiguel Boton .ident = "Dell PowerEdge 300", 1584d022e35SMiguel Boton .matches = { 1594d022e35SMiguel Boton DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), 1604d022e35SMiguel Boton DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 300/"), 1614d022e35SMiguel Boton }, 1624d022e35SMiguel Boton }, 1634d022e35SMiguel Boton { /* Handle problems with rebooting on Dell Optiplex 745's SFF */ 1644d022e35SMiguel Boton .callback = set_bios_reboot, 1654d022e35SMiguel Boton .ident = "Dell OptiPlex 745", 1664d022e35SMiguel Boton .matches = { 1674d022e35SMiguel Boton DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 1684d022e35SMiguel Boton DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"), 1694d022e35SMiguel Boton }, 1704d022e35SMiguel Boton }, 171fc115bf1SColeman Kane { /* Handle problems with rebooting on Dell Optiplex 745's DFF */ 172fc115bf1SColeman Kane .callback = set_bios_reboot, 173fc115bf1SColeman Kane .ident = "Dell OptiPlex 745", 174fc115bf1SColeman Kane .matches = { 175fc115bf1SColeman Kane DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 176fc115bf1SColeman Kane DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"), 177fc115bf1SColeman Kane DMI_MATCH(DMI_BOARD_NAME, "0MM599"), 178fc115bf1SColeman Kane }, 179fc115bf1SColeman Kane }, 180fc1c8925SHeinz-Ado Arnolds { /* Handle problems with rebooting on Dell Optiplex 745 with 0KW626 */ 181fc1c8925SHeinz-Ado Arnolds .callback = set_bios_reboot, 182fc1c8925SHeinz-Ado Arnolds .ident = "Dell OptiPlex 745", 183fc1c8925SHeinz-Ado Arnolds .matches = { 184fc1c8925SHeinz-Ado Arnolds DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 185fc1c8925SHeinz-Ado Arnolds DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"), 186fc1c8925SHeinz-Ado Arnolds DMI_MATCH(DMI_BOARD_NAME, "0KW626"), 187fc1c8925SHeinz-Ado Arnolds }, 188fc1c8925SHeinz-Ado Arnolds }, 189093bac15SSteve Conklin { /* Handle problems with rebooting on Dell Optiplex 330 with 0KP561 */ 190093bac15SSteve Conklin .callback = set_bios_reboot, 191093bac15SSteve Conklin .ident = "Dell OptiPlex 330", 192093bac15SSteve Conklin .matches = { 193093bac15SSteve Conklin DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 194093bac15SSteve Conklin DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 330"), 195093bac15SSteve Conklin DMI_MATCH(DMI_BOARD_NAME, "0KP561"), 196093bac15SSteve Conklin }, 197093bac15SSteve Conklin }, 1984a4aca64SJean Delvare { /* Handle problems with rebooting on Dell Optiplex 360 with 0T656F */ 1994a4aca64SJean Delvare .callback = set_bios_reboot, 2004a4aca64SJean Delvare .ident = "Dell OptiPlex 360", 2014a4aca64SJean Delvare .matches = { 2024a4aca64SJean Delvare DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 2034a4aca64SJean Delvare DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 360"), 2044a4aca64SJean Delvare DMI_MATCH(DMI_BOARD_NAME, "0T656F"), 2054a4aca64SJean Delvare }, 2064a4aca64SJean Delvare }, 20735ea63d7SLeann Ogasawara { /* Handle problems with rebooting on Dell OptiPlex 760 with 0G919G */ 20835ea63d7SLeann Ogasawara .callback = set_bios_reboot, 20935ea63d7SLeann Ogasawara .ident = "Dell OptiPlex 760", 21035ea63d7SLeann Ogasawara .matches = { 21135ea63d7SLeann Ogasawara DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 21235ea63d7SLeann Ogasawara DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 760"), 21335ea63d7SLeann Ogasawara DMI_MATCH(DMI_BOARD_NAME, "0G919G"), 21435ea63d7SLeann Ogasawara }, 21535ea63d7SLeann Ogasawara }, 2164d022e35SMiguel Boton { /* Handle problems with rebooting on Dell 2400's */ 2174d022e35SMiguel Boton .callback = set_bios_reboot, 2184d022e35SMiguel Boton .ident = "Dell PowerEdge 2400", 2194d022e35SMiguel Boton .matches = { 2204d022e35SMiguel Boton DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), 2214d022e35SMiguel Boton DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2400"), 2224d022e35SMiguel Boton }, 2234d022e35SMiguel Boton }, 224fab3b58dSIngo Molnar { /* Handle problems with rebooting on Dell T5400's */ 225fab3b58dSIngo Molnar .callback = set_bios_reboot, 226fab3b58dSIngo Molnar .ident = "Dell Precision T5400", 227fab3b58dSIngo Molnar .matches = { 228fab3b58dSIngo Molnar DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 229fab3b58dSIngo Molnar DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T5400"), 230fab3b58dSIngo Molnar }, 231fab3b58dSIngo Molnar }, 232890ffedcSThomas Backlund { /* Handle problems with rebooting on Dell T7400's */ 233890ffedcSThomas Backlund .callback = set_bios_reboot, 234890ffedcSThomas Backlund .ident = "Dell Precision T7400", 235890ffedcSThomas Backlund .matches = { 236890ffedcSThomas Backlund DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 237890ffedcSThomas Backlund DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T7400"), 238890ffedcSThomas Backlund }, 239890ffedcSThomas Backlund }, 2404d022e35SMiguel Boton { /* Handle problems with rebooting on HP laptops */ 2414d022e35SMiguel Boton .callback = set_bios_reboot, 2424d022e35SMiguel Boton .ident = "HP Compaq Laptop", 2434d022e35SMiguel Boton .matches = { 2444d022e35SMiguel Boton DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), 2454d022e35SMiguel Boton DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq"), 2464d022e35SMiguel Boton }, 2474d022e35SMiguel Boton }, 248dd4124a8SLeann Ogasawara { /* Handle problems with rebooting on Dell XPS710 */ 249dd4124a8SLeann Ogasawara .callback = set_bios_reboot, 250dd4124a8SLeann Ogasawara .ident = "Dell XPS710", 251dd4124a8SLeann Ogasawara .matches = { 252dd4124a8SLeann Ogasawara DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 253dd4124a8SLeann Ogasawara DMI_MATCH(DMI_PRODUCT_NAME, "Dell XPS710"), 254dd4124a8SLeann Ogasawara }, 255dd4124a8SLeann Ogasawara }, 256c5da9a2bSAlan Cox { /* Handle problems with rebooting on Dell DXP061 */ 257c5da9a2bSAlan Cox .callback = set_bios_reboot, 258c5da9a2bSAlan Cox .ident = "Dell DXP061", 259c5da9a2bSAlan Cox .matches = { 260c5da9a2bSAlan Cox DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 261c5da9a2bSAlan Cox DMI_MATCH(DMI_PRODUCT_NAME, "Dell DXP061"), 262c5da9a2bSAlan Cox }, 263c5da9a2bSAlan Cox }, 26488dff493SZhang Rui { /* Handle problems with rebooting on Sony VGN-Z540N */ 26588dff493SZhang Rui .callback = set_bios_reboot, 26688dff493SZhang Rui .ident = "Sony VGN-Z540N", 26788dff493SZhang Rui .matches = { 26888dff493SZhang Rui DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), 26988dff493SZhang Rui DMI_MATCH(DMI_PRODUCT_NAME, "VGN-Z540N"), 27088dff493SZhang Rui }, 27188dff493SZhang Rui }, 2724832dddaSLeann Ogasawara { /* Handle problems with rebooting on ASUS P4S800 */ 2734832dddaSLeann Ogasawara .callback = set_bios_reboot, 2744832dddaSLeann Ogasawara .ident = "ASUS P4S800", 2754832dddaSLeann Ogasawara .matches = { 2764832dddaSLeann Ogasawara DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), 2774832dddaSLeann Ogasawara DMI_MATCH(DMI_BOARD_NAME, "P4S800"), 2784832dddaSLeann Ogasawara }, 2794832dddaSLeann Ogasawara }, 28057b16594SMichael D Labriola 281b49c78d4SPeter Chubb { /* Handle reboot issue on Acer Aspire one */ 2821ef03890SPeter Chubb .callback = set_kbd_reboot, 283b49c78d4SPeter Chubb .ident = "Acer Aspire One A110", 284b49c78d4SPeter Chubb .matches = { 285b49c78d4SPeter Chubb DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 286b49c78d4SPeter Chubb DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"), 287b49c78d4SPeter Chubb }, 288b49c78d4SPeter Chubb }, 2893e03bbeaSShunichi Fuji { /* Handle problems with rebooting on Apple MacBook5 */ 2906c6c51e4SPaul Mackerras .callback = set_pci_reboot, 2913e03bbeaSShunichi Fuji .ident = "Apple MacBook5", 2926c6c51e4SPaul Mackerras .matches = { 2936c6c51e4SPaul Mackerras DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 2943e03bbeaSShunichi Fuji DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5"), 2956c6c51e4SPaul Mackerras }, 2966c6c51e4SPaul Mackerras }, 2973e03bbeaSShunichi Fuji { /* Handle problems with rebooting on Apple MacBookPro5 */ 298498cdbfbSOzan Çağlayan .callback = set_pci_reboot, 2993e03bbeaSShunichi Fuji .ident = "Apple MacBookPro5", 300498cdbfbSOzan Çağlayan .matches = { 301498cdbfbSOzan Çağlayan DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 3023e03bbeaSShunichi Fuji DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5"), 303498cdbfbSOzan Çağlayan }, 304498cdbfbSOzan Çağlayan }, 30505154752SGottfried Haider { /* Handle problems with rebooting on Apple Macmini3,1 */ 30605154752SGottfried Haider .callback = set_pci_reboot, 30705154752SGottfried Haider .ident = "Apple Macmini3,1", 30805154752SGottfried Haider .matches = { 30905154752SGottfried Haider DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 31005154752SGottfried Haider DMI_MATCH(DMI_PRODUCT_NAME, "Macmini3,1"), 31105154752SGottfried Haider }, 31205154752SGottfried Haider }, 3130a832320SJustin P. Mattock { /* Handle problems with rebooting on the iMac9,1. */ 3140a832320SJustin P. Mattock .callback = set_pci_reboot, 3150a832320SJustin P. Mattock .ident = "Apple iMac9,1", 3160a832320SJustin P. Mattock .matches = { 3170a832320SJustin P. Mattock DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), 3180a832320SJustin P. Mattock DMI_MATCH(DMI_PRODUCT_NAME, "iMac9,1"), 3190a832320SJustin P. Mattock }, 3200a832320SJustin P. Mattock }, 3213628c3f5SMaxime Ripard { /* Handle problems with rebooting on the Latitude E6320. */ 3223628c3f5SMaxime Ripard .callback = set_pci_reboot, 3233628c3f5SMaxime Ripard .ident = "Dell Latitude E6320", 3243628c3f5SMaxime Ripard .matches = { 3253628c3f5SMaxime Ripard DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 3263628c3f5SMaxime Ripard DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6320"), 3273628c3f5SMaxime Ripard }, 3283628c3f5SMaxime Ripard }, 329b7798d28SDaniel J Blueman { /* Handle problems with rebooting on the Latitude E5420. */ 330b7798d28SDaniel J Blueman .callback = set_pci_reboot, 331b7798d28SDaniel J Blueman .ident = "Dell Latitude E5420", 332b7798d28SDaniel J Blueman .matches = { 333b7798d28SDaniel J Blueman DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 334b7798d28SDaniel J Blueman DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5420"), 335b7798d28SDaniel J Blueman }, 336b7798d28SDaniel J Blueman }, 337a536877eSH. Peter Anvin { /* Handle problems with rebooting on the Latitude E6420. */ 338a536877eSH. Peter Anvin .callback = set_pci_reboot, 339a536877eSH. Peter Anvin .ident = "Dell Latitude E6420", 340a536877eSH. Peter Anvin .matches = { 341a536877eSH. Peter Anvin DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 342a536877eSH. Peter Anvin DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6420"), 343a536877eSH. Peter Anvin }, 344a536877eSH. Peter Anvin }, 3456be30bb7SRafael J. Wysocki { /* Handle problems with rebooting on the OptiPlex 990. */ 3466be30bb7SRafael J. Wysocki .callback = set_pci_reboot, 3476be30bb7SRafael J. Wysocki .ident = "Dell OptiPlex 990", 3486be30bb7SRafael J. Wysocki .matches = { 3496be30bb7SRafael J. Wysocki DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 3506be30bb7SRafael J. Wysocki DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 990"), 3516be30bb7SRafael J. Wysocki }, 3526be30bb7SRafael J. Wysocki }, 35376eb9a30SZhang Rui { /* Handle problems with rebooting on the Precision M6600. */ 35476eb9a30SZhang Rui .callback = set_pci_reboot, 35576eb9a30SZhang Rui .ident = "Dell OptiPlex 990", 35676eb9a30SZhang Rui .matches = { 35776eb9a30SZhang Rui DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 35876eb9a30SZhang Rui DMI_MATCH(DMI_PRODUCT_NAME, "Precision M6600"), 35976eb9a30SZhang Rui }, 36076eb9a30SZhang Rui }, 3616c6c51e4SPaul Mackerras { } 3626c6c51e4SPaul Mackerras }; 3636c6c51e4SPaul Mackerras 36457b16594SMichael D Labriola static int __init reboot_init(void) 3656c6c51e4SPaul Mackerras { 366144d102bSMichael D Labriola /* 367144d102bSMichael D Labriola * Only do the DMI check if reboot_type hasn't been overridden 3685955633eSMichael D Labriola * on the command line 3695955633eSMichael D Labriola */ 370144d102bSMichael D Labriola if (reboot_default) 37157b16594SMichael D Labriola dmi_check_system(reboot_dmi_table); 3726c6c51e4SPaul Mackerras return 0; 3736c6c51e4SPaul Mackerras } 37457b16594SMichael D Labriola core_initcall(reboot_init); 3756c6c51e4SPaul Mackerras 3764d022e35SMiguel Boton static inline void kb_wait(void) 3774d022e35SMiguel Boton { 3784d022e35SMiguel Boton int i; 3794d022e35SMiguel Boton 380c84d6af8SAlan Cox for (i = 0; i < 0x10000; i++) { 381c84d6af8SAlan Cox if ((inb(0x64) & 0x02) == 0) 3824d022e35SMiguel Boton break; 383c84d6af8SAlan Cox udelay(2); 384c84d6af8SAlan Cox } 3854d022e35SMiguel Boton } 3864d022e35SMiguel Boton 3879c48f1c6SDon Zickus static void vmxoff_nmi(int cpu, struct pt_regs *regs) 388d176720dSEduardo Habkost { 389d176720dSEduardo Habkost cpu_emergency_vmxoff(); 390d176720dSEduardo Habkost } 391d176720dSEduardo Habkost 392144d102bSMichael D Labriola /* Use NMIs as IPIs to tell all CPUs to disable virtualization */ 393d176720dSEduardo Habkost static void emergency_vmx_disable_all(void) 394d176720dSEduardo Habkost { 395d176720dSEduardo Habkost /* Just make sure we won't change CPUs while doing this */ 396d176720dSEduardo Habkost local_irq_disable(); 397d176720dSEduardo Habkost 398144d102bSMichael D Labriola /* 399144d102bSMichael D Labriola * We need to disable VMX on all CPUs before rebooting, otherwise 400d176720dSEduardo Habkost * we risk hanging up the machine, because the CPU ignore INIT 401d176720dSEduardo Habkost * signals when VMX is enabled. 402d176720dSEduardo Habkost * 403d176720dSEduardo Habkost * We can't take any locks and we may be on an inconsistent 404d176720dSEduardo Habkost * state, so we use NMIs as IPIs to tell the other CPUs to disable 405d176720dSEduardo Habkost * VMX and halt. 406d176720dSEduardo Habkost * 407d176720dSEduardo Habkost * For safety, we will avoid running the nmi_shootdown_cpus() 408d176720dSEduardo Habkost * stuff unnecessarily, but we don't have a way to check 409d176720dSEduardo Habkost * if other CPUs have VMX enabled. So we will call it only if the 410d176720dSEduardo Habkost * CPU we are running on has VMX enabled. 411d176720dSEduardo Habkost * 412d176720dSEduardo Habkost * We will miss cases where VMX is not enabled on all CPUs. This 413d176720dSEduardo Habkost * shouldn't do much harm because KVM always enable VMX on all 414d176720dSEduardo Habkost * CPUs anyway. But we can miss it on the small window where KVM 415d176720dSEduardo Habkost * is still enabling VMX. 416d176720dSEduardo Habkost */ 417d176720dSEduardo Habkost if (cpu_has_vmx() && cpu_vmx_enabled()) { 418144d102bSMichael D Labriola /* Disable VMX on this CPU. */ 419d176720dSEduardo Habkost cpu_vmxoff(); 420d176720dSEduardo Habkost 421d176720dSEduardo Habkost /* Halt and disable VMX on the other CPUs */ 422d176720dSEduardo Habkost nmi_shootdown_cpus(vmxoff_nmi); 423d176720dSEduardo Habkost 424d176720dSEduardo Habkost } 425d176720dSEduardo Habkost } 426d176720dSEduardo Habkost 427d176720dSEduardo Habkost 4287432d149SIngo Molnar void __attribute__((weak)) mach_reboot_fixups(void) 4297432d149SIngo Molnar { 4307432d149SIngo Molnar } 4317432d149SIngo Molnar 432660e34ceSMatthew Garrett /* 433660e34ceSMatthew Garrett * Windows compatible x86 hardware expects the following on reboot: 434660e34ceSMatthew Garrett * 435660e34ceSMatthew Garrett * 1) If the FADT has the ACPI reboot register flag set, try it 436660e34ceSMatthew Garrett * 2) If still alive, write to the keyboard controller 437660e34ceSMatthew Garrett * 3) If still alive, write to the ACPI reboot register again 438660e34ceSMatthew Garrett * 4) If still alive, write to the keyboard controller again 439660e34ceSMatthew Garrett * 440660e34ceSMatthew Garrett * If the machine is still alive at this stage, it gives up. We default to 441660e34ceSMatthew Garrett * following the same pattern, except that if we're still alive after (4) we'll 442660e34ceSMatthew Garrett * try to force a triple fault and then cycle between hitting the keyboard 443660e34ceSMatthew Garrett * controller and doing that 444660e34ceSMatthew Garrett */ 445416e2d63SJody Belka static void native_machine_emergency_restart(void) 4464d022e35SMiguel Boton { 4474d022e35SMiguel Boton int i; 448660e34ceSMatthew Garrett int attempt = 0; 449660e34ceSMatthew Garrett int orig_reboot_type = reboot_type; 450edf2b139SRobin Holt unsigned short mode; 4514d022e35SMiguel Boton 452d176720dSEduardo Habkost if (reboot_emergency) 453d176720dSEduardo Habkost emergency_vmx_disable_all(); 454d176720dSEduardo Habkost 455840c2bafSJoseph Cihula tboot_shutdown(TB_SHUTDOWN_REBOOT); 456840c2bafSJoseph Cihula 4574d022e35SMiguel Boton /* Tell the BIOS if we want cold or warm reboot */ 458edf2b139SRobin Holt mode = reboot_mode == REBOOT_WARM ? 0x1234 : 0; 459edf2b139SRobin Holt *((unsigned short *)__va(0x472)) = mode; 4604d022e35SMiguel Boton 4614d022e35SMiguel Boton for (;;) { 4624d022e35SMiguel Boton /* Could also try the reset bit in the Hammer NB */ 4634d022e35SMiguel Boton switch (reboot_type) { 4644d022e35SMiguel Boton case BOOT_KBD: 465144d102bSMichael D Labriola mach_reboot_fixups(); /* For board specific fixups */ 4667432d149SIngo Molnar 4674d022e35SMiguel Boton for (i = 0; i < 10; i++) { 4684d022e35SMiguel Boton kb_wait(); 4694d022e35SMiguel Boton udelay(50); 470144d102bSMichael D Labriola outb(0xfe, 0x64); /* Pulse reset low */ 4714d022e35SMiguel Boton udelay(50); 4724d022e35SMiguel Boton } 473660e34ceSMatthew Garrett if (attempt == 0 && orig_reboot_type == BOOT_ACPI) { 474660e34ceSMatthew Garrett attempt = 1; 475660e34ceSMatthew Garrett reboot_type = BOOT_ACPI; 476660e34ceSMatthew Garrett } else { 477660e34ceSMatthew Garrett reboot_type = BOOT_TRIPLE; 478660e34ceSMatthew Garrett } 479660e34ceSMatthew Garrett break; 4804d022e35SMiguel Boton 4814d022e35SMiguel Boton case BOOT_TRIPLE: 482ebdd561aSJan Beulich load_idt(&no_idt); 4834d022e35SMiguel Boton __asm__ __volatile__("int3"); 4844d022e35SMiguel Boton 4854d022e35SMiguel Boton reboot_type = BOOT_KBD; 4864d022e35SMiguel Boton break; 4874d022e35SMiguel Boton 4884d022e35SMiguel Boton case BOOT_BIOS: 4893d35ac34SH. Peter Anvin machine_real_restart(MRR_BIOS); 4904d022e35SMiguel Boton 4914d022e35SMiguel Boton reboot_type = BOOT_KBD; 4924d022e35SMiguel Boton break; 4934d022e35SMiguel Boton 4944d022e35SMiguel Boton case BOOT_ACPI: 4954d022e35SMiguel Boton acpi_reboot(); 4964d022e35SMiguel Boton reboot_type = BOOT_KBD; 4974d022e35SMiguel Boton break; 4984d022e35SMiguel Boton 4994d022e35SMiguel Boton case BOOT_EFI: 50083e68189SMatt Fleming if (efi_enabled(EFI_RUNTIME_SERVICES)) 501edf2b139SRobin Holt efi.reset_system(reboot_mode == REBOOT_WARM ? 50214d7ca5cSH. Peter Anvin EFI_RESET_WARM : 50314d7ca5cSH. Peter Anvin EFI_RESET_COLD, 5044d022e35SMiguel Boton EFI_SUCCESS, 0, NULL); 505b47b9288SH. Peter Anvin reboot_type = BOOT_KBD; 50614d7ca5cSH. Peter Anvin break; 5074d022e35SMiguel Boton 50814d7ca5cSH. Peter Anvin case BOOT_CF9: 50914d7ca5cSH. Peter Anvin port_cf9_safe = true; 510144d102bSMichael D Labriola /* Fall through */ 51114d7ca5cSH. Peter Anvin 51214d7ca5cSH. Peter Anvin case BOOT_CF9_COND: 51314d7ca5cSH. Peter Anvin if (port_cf9_safe) { 51414d7ca5cSH. Peter Anvin u8 cf9 = inb(0xcf9) & ~6; 51514d7ca5cSH. Peter Anvin outb(cf9|2, 0xcf9); /* Request hard reset */ 51614d7ca5cSH. Peter Anvin udelay(50); 51714d7ca5cSH. Peter Anvin outb(cf9|6, 0xcf9); /* Actually do the reset */ 51814d7ca5cSH. Peter Anvin udelay(50); 51914d7ca5cSH. Peter Anvin } 5204d022e35SMiguel Boton reboot_type = BOOT_KBD; 5214d022e35SMiguel Boton break; 5224d022e35SMiguel Boton } 5234d022e35SMiguel Boton } 5244d022e35SMiguel Boton } 5254d022e35SMiguel Boton 5263c62c625SGlauber Costa void native_machine_shutdown(void) 5274d022e35SMiguel Boton { 5284d022e35SMiguel Boton /* Stop the cpus and apics */ 5294d022e35SMiguel Boton #ifdef CONFIG_SMP 530144d102bSMichael D Labriola /* 531*1b3a5d02SRobin Holt * Stop all of the others. Also disable the local irq to 532*1b3a5d02SRobin Holt * not receive the per-cpu timer interrupt which may trigger 533*1b3a5d02SRobin Holt * scheduler's load balance. 5344d022e35SMiguel Boton */ 53555c844a4SFeng Tang local_irq_disable(); 53676fac077SAlok Kataria stop_other_cpus(); 5374d022e35SMiguel Boton #endif 5384d022e35SMiguel Boton 5394d022e35SMiguel Boton lapic_shutdown(); 5404d022e35SMiguel Boton 5414d022e35SMiguel Boton #ifdef CONFIG_X86_IO_APIC 5424d022e35SMiguel Boton disable_IO_APIC(); 5434d022e35SMiguel Boton #endif 5444d022e35SMiguel Boton 5454d022e35SMiguel Boton #ifdef CONFIG_HPET_TIMER 5464d022e35SMiguel Boton hpet_disable(); 5474d022e35SMiguel Boton #endif 5484d022e35SMiguel Boton 5494d022e35SMiguel Boton #ifdef CONFIG_X86_64 550338bac52SFUJITA Tomonori x86_platform.iommu_shutdown(); 5514d022e35SMiguel Boton #endif 5524d022e35SMiguel Boton } 5534d022e35SMiguel Boton 554d176720dSEduardo Habkost static void __machine_emergency_restart(int emergency) 555d176720dSEduardo Habkost { 556d176720dSEduardo Habkost reboot_emergency = emergency; 557d176720dSEduardo Habkost machine_ops.emergency_restart(); 558d176720dSEduardo Habkost } 559d176720dSEduardo Habkost 560416e2d63SJody Belka static void native_machine_restart(char *__unused) 5614d022e35SMiguel Boton { 562c767a54bSJoe Perches pr_notice("machine restart\n"); 5634d022e35SMiguel Boton 5644d022e35SMiguel Boton if (!reboot_force) 5654d022e35SMiguel Boton machine_shutdown(); 566d176720dSEduardo Habkost __machine_emergency_restart(0); 5674d022e35SMiguel Boton } 5684d022e35SMiguel Boton 569416e2d63SJody Belka static void native_machine_halt(void) 5704d022e35SMiguel Boton { 571144d102bSMichael D Labriola /* Stop other cpus and apics */ 572d3ec5caeSIvan Vecera machine_shutdown(); 573d3ec5caeSIvan Vecera 574840c2bafSJoseph Cihula tboot_shutdown(TB_SHUTDOWN_HALT); 575840c2bafSJoseph Cihula 576d3ec5caeSIvan Vecera stop_this_cpu(NULL); 5774d022e35SMiguel Boton } 5784d022e35SMiguel Boton 579416e2d63SJody Belka static void native_machine_power_off(void) 5804d022e35SMiguel Boton { 5814d022e35SMiguel Boton if (pm_power_off) { 5824d022e35SMiguel Boton if (!reboot_force) 5834d022e35SMiguel Boton machine_shutdown(); 5844d022e35SMiguel Boton pm_power_off(); 5854d022e35SMiguel Boton } 586144d102bSMichael D Labriola /* A fallback in case there is no PM info available */ 587840c2bafSJoseph Cihula tboot_shutdown(TB_SHUTDOWN_HALT); 5884d022e35SMiguel Boton } 5894d022e35SMiguel Boton 5904d022e35SMiguel Boton struct machine_ops machine_ops = { 591416e2d63SJody Belka .power_off = native_machine_power_off, 592416e2d63SJody Belka .shutdown = native_machine_shutdown, 593416e2d63SJody Belka .emergency_restart = native_machine_emergency_restart, 594416e2d63SJody Belka .restart = native_machine_restart, 595ed23dc6fSGlauber Costa .halt = native_machine_halt, 596ed23dc6fSGlauber Costa #ifdef CONFIG_KEXEC 597ed23dc6fSGlauber Costa .crash_shutdown = native_machine_crash_shutdown, 598ed23dc6fSGlauber Costa #endif 5994d022e35SMiguel Boton }; 600416e2d63SJody Belka 601416e2d63SJody Belka void machine_power_off(void) 602416e2d63SJody Belka { 603416e2d63SJody Belka machine_ops.power_off(); 604416e2d63SJody Belka } 605416e2d63SJody Belka 606416e2d63SJody Belka void machine_shutdown(void) 607416e2d63SJody Belka { 608416e2d63SJody Belka machine_ops.shutdown(); 609416e2d63SJody Belka } 610416e2d63SJody Belka 611416e2d63SJody Belka void machine_emergency_restart(void) 612416e2d63SJody Belka { 613d176720dSEduardo Habkost __machine_emergency_restart(1); 614416e2d63SJody Belka } 615416e2d63SJody Belka 616416e2d63SJody Belka void machine_restart(char *cmd) 617416e2d63SJody Belka { 618416e2d63SJody Belka machine_ops.restart(cmd); 619416e2d63SJody Belka } 620416e2d63SJody Belka 621416e2d63SJody Belka void machine_halt(void) 622416e2d63SJody Belka { 623416e2d63SJody Belka machine_ops.halt(); 624416e2d63SJody Belka } 625416e2d63SJody Belka 626ed23dc6fSGlauber Costa #ifdef CONFIG_KEXEC 627ed23dc6fSGlauber Costa void machine_crash_shutdown(struct pt_regs *regs) 628ed23dc6fSGlauber Costa { 629ed23dc6fSGlauber Costa machine_ops.crash_shutdown(regs); 630ed23dc6fSGlauber Costa } 631ed23dc6fSGlauber Costa #endif 6322ddded21SEduardo Habkost 6332ddded21SEduardo Habkost 634bb8dd270SEduardo Habkost #if defined(CONFIG_SMP) 6352ddded21SEduardo Habkost 6362ddded21SEduardo Habkost /* This keeps a track of which one is crashing cpu. */ 6372ddded21SEduardo Habkost static int crashing_cpu; 6382ddded21SEduardo Habkost static nmi_shootdown_cb shootdown_callback; 6392ddded21SEduardo Habkost 6402ddded21SEduardo Habkost static atomic_t waiting_for_crash_ipi; 6412ddded21SEduardo Habkost 6429c48f1c6SDon Zickus static int crash_nmi_callback(unsigned int val, struct pt_regs *regs) 6432ddded21SEduardo Habkost { 6442ddded21SEduardo Habkost int cpu; 6452ddded21SEduardo Habkost 6462ddded21SEduardo Habkost cpu = raw_smp_processor_id(); 6472ddded21SEduardo Habkost 648144d102bSMichael D Labriola /* 649144d102bSMichael D Labriola * Don't do anything if this handler is invoked on crashing cpu. 6502ddded21SEduardo Habkost * Otherwise, system will completely hang. Crashing cpu can get 6512ddded21SEduardo Habkost * an NMI if system was initially booted with nmi_watchdog parameter. 6522ddded21SEduardo Habkost */ 6532ddded21SEduardo Habkost if (cpu == crashing_cpu) 6549c48f1c6SDon Zickus return NMI_HANDLED; 6552ddded21SEduardo Habkost local_irq_disable(); 6562ddded21SEduardo Habkost 6579c48f1c6SDon Zickus shootdown_callback(cpu, regs); 6582ddded21SEduardo Habkost 6592ddded21SEduardo Habkost atomic_dec(&waiting_for_crash_ipi); 6602ddded21SEduardo Habkost /* Assume hlt works */ 6612ddded21SEduardo Habkost halt(); 6622ddded21SEduardo Habkost for (;;) 6632ddded21SEduardo Habkost cpu_relax(); 6642ddded21SEduardo Habkost 6659c48f1c6SDon Zickus return NMI_HANDLED; 6662ddded21SEduardo Habkost } 6672ddded21SEduardo Habkost 6682ddded21SEduardo Habkost static void smp_send_nmi_allbutself(void) 6692ddded21SEduardo Habkost { 670dac5f412SIngo Molnar apic->send_IPI_allbutself(NMI_VECTOR); 6712ddded21SEduardo Habkost } 6722ddded21SEduardo Habkost 673144d102bSMichael D Labriola /* 674144d102bSMichael D Labriola * Halt all other CPUs, calling the specified function on each of them 675bb8dd270SEduardo Habkost * 676bb8dd270SEduardo Habkost * This function can be used to halt all other CPUs on crash 677bb8dd270SEduardo Habkost * or emergency reboot time. The function passed as parameter 678bb8dd270SEduardo Habkost * will be called inside a NMI handler on all CPUs. 679bb8dd270SEduardo Habkost */ 6802ddded21SEduardo Habkost void nmi_shootdown_cpus(nmi_shootdown_cb callback) 6812ddded21SEduardo Habkost { 6822ddded21SEduardo Habkost unsigned long msecs; 683c415b3dcSEduardo Habkost local_irq_disable(); 6842ddded21SEduardo Habkost 6852ddded21SEduardo Habkost /* Make a note of crashing cpu. Will be used in NMI callback. */ 6862ddded21SEduardo Habkost crashing_cpu = safe_smp_processor_id(); 6872ddded21SEduardo Habkost 6882ddded21SEduardo Habkost shootdown_callback = callback; 6892ddded21SEduardo Habkost 6902ddded21SEduardo Habkost atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1); 6912ddded21SEduardo Habkost /* Would it be better to replace the trap vector here? */ 6929c48f1c6SDon Zickus if (register_nmi_handler(NMI_LOCAL, crash_nmi_callback, 6939c48f1c6SDon Zickus NMI_FLAG_FIRST, "crash")) 694144d102bSMichael D Labriola return; /* Return what? */ 695144d102bSMichael D Labriola /* 696144d102bSMichael D Labriola * Ensure the new callback function is set before sending 6972ddded21SEduardo Habkost * out the NMI 6982ddded21SEduardo Habkost */ 6992ddded21SEduardo Habkost wmb(); 7002ddded21SEduardo Habkost 7012ddded21SEduardo Habkost smp_send_nmi_allbutself(); 7022ddded21SEduardo Habkost 7032ddded21SEduardo Habkost msecs = 1000; /* Wait at most a second for the other cpus to stop */ 7042ddded21SEduardo Habkost while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) { 7052ddded21SEduardo Habkost mdelay(1); 7062ddded21SEduardo Habkost msecs--; 7072ddded21SEduardo Habkost } 7082ddded21SEduardo Habkost 7092ddded21SEduardo Habkost /* Leave the nmi callback set */ 7102ddded21SEduardo Habkost } 711bb8dd270SEduardo Habkost #else /* !CONFIG_SMP */ 712bb8dd270SEduardo Habkost void nmi_shootdown_cpus(nmi_shootdown_cb callback) 713bb8dd270SEduardo Habkost { 714bb8dd270SEduardo Habkost /* No other CPUs to shoot down */ 715bb8dd270SEduardo Habkost } 7162ddded21SEduardo Habkost #endif 717