xref: /linux/arch/x86/kernel/reboot.c (revision 76eb9a30db4bc8fd172f9155247264b5f2686d7b)
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>
275a8c9aebSJarkko Sakkinen # include <asm/realmode.h>
284d022e35SMiguel Boton #else
29338bac52SFUJITA Tomonori # include <asm/x86_init.h>
304d022e35SMiguel Boton #endif
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 static int reboot_mode;
40660e34ceSMatthew Garrett enum reboot_type reboot_type = BOOT_ACPI;
414d022e35SMiguel Boton int reboot_force;
424d022e35SMiguel Boton 
43144d102bSMichael D Labriola /*
44144d102bSMichael D Labriola  * This variable is used privately to keep track of whether or not
455955633eSMichael D Labriola  * reboot_type is still set to its default value (i.e., reboot= hasn't
465955633eSMichael D Labriola  * been set on the command line).  This is needed so that we can
475955633eSMichael D Labriola  * suppress DMI scanning for reboot quirks.  Without it, it's
485955633eSMichael D Labriola  * impossible to override a faulty reboot quirk without recompiling.
495955633eSMichael D Labriola  */
505955633eSMichael D Labriola static int reboot_default = 1;
515955633eSMichael D Labriola 
524d022e35SMiguel Boton #if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
534d022e35SMiguel Boton static int reboot_cpu = -1;
544d022e35SMiguel Boton #endif
554d022e35SMiguel Boton 
56144d102bSMichael D Labriola /*
57144d102bSMichael D Labriola  * This is set if we need to go through the 'emergency' path.
58d176720dSEduardo Habkost  * When machine_emergency_restart() is called, we may be on
59d176720dSEduardo Habkost  * an inconsistent state and won't be able to do a clean cleanup
60d176720dSEduardo Habkost  */
61d176720dSEduardo Habkost static int reboot_emergency;
62d176720dSEduardo Habkost 
6314d7ca5cSH. Peter Anvin /* This is set by the PCI code if either type 1 or type 2 PCI is detected */
6414d7ca5cSH. Peter Anvin bool port_cf9_safe = false;
6514d7ca5cSH. Peter Anvin 
66144d102bSMichael D Labriola /*
67144d102bSMichael D Labriola  * reboot=b[ios] | s[mp] | t[riple] | k[bd] | e[fi] [, [w]arm | [c]old] | p[ci]
68144d102bSMichael D Labriola  * warm   Don't set the cold reboot flag
69144d102bSMichael D Labriola  * cold   Set the cold reboot flag
70144d102bSMichael D Labriola  * bios   Reboot by jumping through the BIOS (only for X86_32)
71144d102bSMichael D Labriola  * smp    Reboot by executing reset on BSP or other CPU (only for X86_32)
72144d102bSMichael D Labriola  * triple Force a triple fault (init)
73144d102bSMichael D Labriola  * kbd    Use the keyboard controller. cold reset (default)
74144d102bSMichael D Labriola  * acpi   Use the RESET_REG in the FADT
75144d102bSMichael D Labriola  * efi    Use efi reset_system runtime service
76144d102bSMichael D Labriola  * pci    Use the so-called "PCI reset register", CF9
77144d102bSMichael D Labriola  * force  Avoid anything that could hang.
784d022e35SMiguel Boton  */
794d022e35SMiguel Boton static int __init reboot_setup(char *str)
804d022e35SMiguel Boton {
814d022e35SMiguel Boton 	for (;;) {
82144d102bSMichael D Labriola 		/*
83144d102bSMichael D Labriola 		 * Having anything passed on the command line via
845955633eSMichael D Labriola 		 * reboot= will cause us to disable DMI checking
855955633eSMichael D Labriola 		 * below.
865955633eSMichael D Labriola 		 */
875955633eSMichael D Labriola 		reboot_default = 0;
885955633eSMichael D Labriola 
894d022e35SMiguel Boton 		switch (*str) {
904d022e35SMiguel Boton 		case 'w':
914d022e35SMiguel Boton 			reboot_mode = 0x1234;
924d022e35SMiguel Boton 			break;
934d022e35SMiguel Boton 
944d022e35SMiguel Boton 		case 'c':
954d022e35SMiguel Boton 			reboot_mode = 0;
964d022e35SMiguel Boton 			break;
974d022e35SMiguel Boton 
984d022e35SMiguel Boton #ifdef CONFIG_X86_32
994d022e35SMiguel Boton #ifdef CONFIG_SMP
1004d022e35SMiguel Boton 		case 's':
1014d022e35SMiguel Boton 			if (isdigit(*(str+1))) {
1024d022e35SMiguel Boton 				reboot_cpu = (int) (*(str+1) - '0');
1034d022e35SMiguel Boton 				if (isdigit(*(str+2)))
1044d022e35SMiguel Boton 					reboot_cpu = reboot_cpu*10 + (int)(*(str+2) - '0');
1054d022e35SMiguel Boton 			}
106144d102bSMichael D Labriola 			/*
107144d102bSMichael D Labriola 			 * We will leave sorting out the final value
108144d102bSMichael D Labriola 			 * when we are ready to reboot, since we might not
109144d102bSMichael D Labriola 			 * have detected BSP APIC ID or smp_num_cpu
110144d102bSMichael D Labriola 			 */
1114d022e35SMiguel Boton 			break;
1124d022e35SMiguel Boton #endif /* CONFIG_SMP */
1134d022e35SMiguel Boton 
1144d022e35SMiguel Boton 		case 'b':
1154d022e35SMiguel Boton #endif
1164d022e35SMiguel Boton 		case 'a':
1174d022e35SMiguel Boton 		case 'k':
1184d022e35SMiguel Boton 		case 't':
1194d022e35SMiguel Boton 		case 'e':
12014d7ca5cSH. Peter Anvin 		case 'p':
1214d022e35SMiguel Boton 			reboot_type = *str;
1224d022e35SMiguel Boton 			break;
1234d022e35SMiguel Boton 
1244d022e35SMiguel Boton 		case 'f':
1254d022e35SMiguel Boton 			reboot_force = 1;
1264d022e35SMiguel Boton 			break;
1274d022e35SMiguel Boton 		}
1284d022e35SMiguel Boton 
1294d022e35SMiguel Boton 		str = strchr(str, ',');
1304d022e35SMiguel Boton 		if (str)
1314d022e35SMiguel Boton 			str++;
1324d022e35SMiguel Boton 		else
1334d022e35SMiguel Boton 			break;
1344d022e35SMiguel Boton 	}
1354d022e35SMiguel Boton 	return 1;
1364d022e35SMiguel Boton }
1374d022e35SMiguel Boton 
1384d022e35SMiguel Boton __setup("reboot=", reboot_setup);
1394d022e35SMiguel Boton 
1404d022e35SMiguel Boton 
1414d022e35SMiguel Boton #ifdef CONFIG_X86_32
1424d022e35SMiguel Boton /*
1434d022e35SMiguel Boton  * Reboot options and system auto-detection code provided by
1444d022e35SMiguel Boton  * Dell Inc. so their systems "just work". :-)
1454d022e35SMiguel Boton  */
1464d022e35SMiguel Boton 
1474d022e35SMiguel Boton /*
1481ef03890SPeter Chubb  * Some machines require the "reboot=b" or "reboot=k"  commandline options,
1494d022e35SMiguel Boton  * this quirk makes that automatic.
1504d022e35SMiguel Boton  */
1514d022e35SMiguel Boton static int __init set_bios_reboot(const struct dmi_system_id *d)
1524d022e35SMiguel Boton {
1534d022e35SMiguel Boton 	if (reboot_type != BOOT_BIOS) {
1544d022e35SMiguel Boton 		reboot_type = BOOT_BIOS;
1554d022e35SMiguel Boton 		printk(KERN_INFO "%s series board detected. Selecting BIOS-method for reboots.\n", d->ident);
1564d022e35SMiguel Boton 	}
1574d022e35SMiguel Boton 	return 0;
1584d022e35SMiguel Boton }
1594d022e35SMiguel Boton 
16057b16594SMichael D Labriola void machine_real_restart(unsigned int type)
16157b16594SMichael D Labriola {
162731a7378SLinus Torvalds 	void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
163731a7378SLinus Torvalds 		real_mode_header->machine_real_restart_asm;
16457b16594SMichael D Labriola 
16557b16594SMichael D Labriola 	local_irq_disable();
16657b16594SMichael D Labriola 
167144d102bSMichael D Labriola 	/*
168144d102bSMichael D Labriola 	 * Write zero to CMOS register number 0x0f, which the BIOS POST
169144d102bSMichael D Labriola 	 * routine will recognize as telling it to do a proper reboot.  (Well
170144d102bSMichael D Labriola 	 * that's what this book in front of me says -- it may only apply to
171144d102bSMichael D Labriola 	 * the Phoenix BIOS though, it's not clear).  At the same time,
172144d102bSMichael D Labriola 	 * disable NMIs by setting the top bit in the CMOS address register,
173144d102bSMichael D Labriola 	 * as we're about to do peculiar things to the CPU.  I'm not sure if
174144d102bSMichael D Labriola 	 * `outb_p' is needed instead of just `outb'.  Use it to be on the
175144d102bSMichael D Labriola 	 * safe side.  (Yes, CMOS_WRITE does outb_p's. -  Paul G.)
17657b16594SMichael D Labriola 	 */
17757b16594SMichael D Labriola 	spin_lock(&rtc_lock);
17857b16594SMichael D Labriola 	CMOS_WRITE(0x00, 0x8f);
17957b16594SMichael D Labriola 	spin_unlock(&rtc_lock);
18057b16594SMichael D Labriola 
18157b16594SMichael D Labriola 	/*
18257b16594SMichael D Labriola 	 * Switch back to the initial page table.
18357b16594SMichael D Labriola 	 */
18457b16594SMichael D Labriola 	load_cr3(initial_page_table);
18557b16594SMichael D Labriola 
186144d102bSMichael D Labriola 	/*
187144d102bSMichael D Labriola 	 * Write 0x1234 to absolute memory location 0x472.  The BIOS reads
188144d102bSMichael D Labriola 	 * this on booting to tell it to "Bypass memory test (also warm
189144d102bSMichael D Labriola 	 * boot)".  This seems like a fairly standard thing that gets set by
190144d102bSMichael D Labriola 	 * REBOOT.COM programs, and the previous reset routine did this
191144d102bSMichael D Labriola 	 * too. */
19257b16594SMichael D Labriola 	*((unsigned short *)0x472) = reboot_mode;
19357b16594SMichael D Labriola 
19457b16594SMichael D Labriola 	/* Jump to the identity-mapped low memory code */
19557b16594SMichael D Labriola 	restart_lowmem(type);
19657b16594SMichael D Labriola }
19757b16594SMichael D Labriola #ifdef CONFIG_APM_MODULE
19857b16594SMichael D Labriola EXPORT_SYMBOL(machine_real_restart);
19957b16594SMichael D Labriola #endif
20057b16594SMichael D Labriola 
20157b16594SMichael D Labriola #endif /* CONFIG_X86_32 */
20257b16594SMichael D Labriola 
20357b16594SMichael D Labriola /*
20457b16594SMichael D Labriola  * Some Apple MacBook and MacBookPro's needs reboot=p to be able to reboot
20557b16594SMichael D Labriola  */
20657b16594SMichael D Labriola static int __init set_pci_reboot(const struct dmi_system_id *d)
20757b16594SMichael D Labriola {
20857b16594SMichael D Labriola 	if (reboot_type != BOOT_CF9) {
20957b16594SMichael D Labriola 		reboot_type = BOOT_CF9;
21057b16594SMichael D Labriola 		printk(KERN_INFO "%s series board detected. "
21157b16594SMichael D Labriola 		       "Selecting PCI-method for reboots.\n", d->ident);
21257b16594SMichael D Labriola 	}
21357b16594SMichael D Labriola 	return 0;
21457b16594SMichael D Labriola }
21557b16594SMichael D Labriola 
2161ef03890SPeter Chubb static int __init set_kbd_reboot(const struct dmi_system_id *d)
2171ef03890SPeter Chubb {
2181ef03890SPeter Chubb 	if (reboot_type != BOOT_KBD) {
2191ef03890SPeter Chubb 		reboot_type = BOOT_KBD;
2201ef03890SPeter Chubb 		printk(KERN_INFO "%s series board detected. Selecting KBD-method for reboot.\n", d->ident);
2211ef03890SPeter Chubb 	}
2221ef03890SPeter Chubb 	return 0;
2231ef03890SPeter Chubb }
2241ef03890SPeter Chubb 
225144d102bSMichael D Labriola /*
226144d102bSMichael D Labriola  * This is a single dmi_table handling all reboot quirks.  Note that
22757b16594SMichael D Labriola  * REBOOT_BIOS is only available for 32bit
22857b16594SMichael D Labriola  */
2294d022e35SMiguel Boton static struct dmi_system_id __initdata reboot_dmi_table[] = {
23057b16594SMichael D Labriola #ifdef CONFIG_X86_32
2314d022e35SMiguel Boton 	{	/* Handle problems with rebooting on Dell E520's */
2324d022e35SMiguel Boton 		.callback = set_bios_reboot,
2334d022e35SMiguel Boton 		.ident = "Dell E520",
2344d022e35SMiguel Boton 		.matches = {
2354d022e35SMiguel Boton 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
2364d022e35SMiguel Boton 			DMI_MATCH(DMI_PRODUCT_NAME, "Dell DM061"),
2374d022e35SMiguel Boton 		},
2384d022e35SMiguel Boton 	},
2394d022e35SMiguel Boton 	{	/* Handle problems with rebooting on Dell 1300's */
2404d022e35SMiguel Boton 		.callback = set_bios_reboot,
2414d022e35SMiguel Boton 		.ident = "Dell PowerEdge 1300",
2424d022e35SMiguel Boton 		.matches = {
2434d022e35SMiguel Boton 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
2444d022e35SMiguel Boton 			DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1300/"),
2454d022e35SMiguel Boton 		},
2464d022e35SMiguel Boton 	},
2474d022e35SMiguel Boton 	{	/* Handle problems with rebooting on Dell 300's */
2484d022e35SMiguel Boton 		.callback = set_bios_reboot,
2494d022e35SMiguel Boton 		.ident = "Dell PowerEdge 300",
2504d022e35SMiguel Boton 		.matches = {
2514d022e35SMiguel Boton 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
2524d022e35SMiguel Boton 			DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 300/"),
2534d022e35SMiguel Boton 		},
2544d022e35SMiguel Boton 	},
2554d022e35SMiguel Boton 	{	/* Handle problems with rebooting on Dell Optiplex 745's SFF */
2564d022e35SMiguel Boton 		.callback = set_bios_reboot,
2574d022e35SMiguel Boton 		.ident = "Dell OptiPlex 745",
2584d022e35SMiguel Boton 		.matches = {
2594d022e35SMiguel Boton 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
2604d022e35SMiguel Boton 			DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"),
2614d022e35SMiguel Boton 		},
2624d022e35SMiguel Boton 	},
263fc115bf1SColeman Kane 	{	/* Handle problems with rebooting on Dell Optiplex 745's DFF */
264fc115bf1SColeman Kane 		.callback = set_bios_reboot,
265fc115bf1SColeman Kane 		.ident = "Dell OptiPlex 745",
266fc115bf1SColeman Kane 		.matches = {
267fc115bf1SColeman Kane 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
268fc115bf1SColeman Kane 			DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"),
269fc115bf1SColeman Kane 			DMI_MATCH(DMI_BOARD_NAME, "0MM599"),
270fc115bf1SColeman Kane 		},
271fc115bf1SColeman Kane 	},
272fc1c8925SHeinz-Ado Arnolds 	{	/* Handle problems with rebooting on Dell Optiplex 745 with 0KW626 */
273fc1c8925SHeinz-Ado Arnolds 		.callback = set_bios_reboot,
274fc1c8925SHeinz-Ado Arnolds 		.ident = "Dell OptiPlex 745",
275fc1c8925SHeinz-Ado Arnolds 		.matches = {
276fc1c8925SHeinz-Ado Arnolds 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
277fc1c8925SHeinz-Ado Arnolds 			DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"),
278fc1c8925SHeinz-Ado Arnolds 			DMI_MATCH(DMI_BOARD_NAME, "0KW626"),
279fc1c8925SHeinz-Ado Arnolds 		},
280fc1c8925SHeinz-Ado Arnolds 	},
281093bac15SSteve Conklin 	{	/* Handle problems with rebooting on Dell Optiplex 330 with 0KP561 */
282093bac15SSteve Conklin 		.callback = set_bios_reboot,
283093bac15SSteve Conklin 		.ident = "Dell OptiPlex 330",
284093bac15SSteve Conklin 		.matches = {
285093bac15SSteve Conklin 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
286093bac15SSteve Conklin 			DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 330"),
287093bac15SSteve Conklin 			DMI_MATCH(DMI_BOARD_NAME, "0KP561"),
288093bac15SSteve Conklin 		},
289093bac15SSteve Conklin 	},
2904a4aca64SJean Delvare 	{	/* Handle problems with rebooting on Dell Optiplex 360 with 0T656F */
2914a4aca64SJean Delvare 		.callback = set_bios_reboot,
2924a4aca64SJean Delvare 		.ident = "Dell OptiPlex 360",
2934a4aca64SJean Delvare 		.matches = {
2944a4aca64SJean Delvare 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
2954a4aca64SJean Delvare 			DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 360"),
2964a4aca64SJean Delvare 			DMI_MATCH(DMI_BOARD_NAME, "0T656F"),
2974a4aca64SJean Delvare 		},
2984a4aca64SJean Delvare 	},
29935ea63d7SLeann Ogasawara 	{	/* Handle problems with rebooting on Dell OptiPlex 760 with 0G919G */
30035ea63d7SLeann Ogasawara 		.callback = set_bios_reboot,
30135ea63d7SLeann Ogasawara 		.ident = "Dell OptiPlex 760",
30235ea63d7SLeann Ogasawara 		.matches = {
30335ea63d7SLeann Ogasawara 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
30435ea63d7SLeann Ogasawara 			DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 760"),
30535ea63d7SLeann Ogasawara 			DMI_MATCH(DMI_BOARD_NAME, "0G919G"),
30635ea63d7SLeann Ogasawara 		},
30735ea63d7SLeann Ogasawara 	},
3084d022e35SMiguel Boton 	{	/* Handle problems with rebooting on Dell 2400's */
3094d022e35SMiguel Boton 		.callback = set_bios_reboot,
3104d022e35SMiguel Boton 		.ident = "Dell PowerEdge 2400",
3114d022e35SMiguel Boton 		.matches = {
3124d022e35SMiguel Boton 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
3134d022e35SMiguel Boton 			DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2400"),
3144d022e35SMiguel Boton 		},
3154d022e35SMiguel Boton 	},
316fab3b58dSIngo Molnar 	{	/* Handle problems with rebooting on Dell T5400's */
317fab3b58dSIngo Molnar 		.callback = set_bios_reboot,
318fab3b58dSIngo Molnar 		.ident = "Dell Precision T5400",
319fab3b58dSIngo Molnar 		.matches = {
320fab3b58dSIngo Molnar 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
321fab3b58dSIngo Molnar 			DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T5400"),
322fab3b58dSIngo Molnar 		},
323fab3b58dSIngo Molnar 	},
324890ffedcSThomas Backlund 	{	/* Handle problems with rebooting on Dell T7400's */
325890ffedcSThomas Backlund 		.callback = set_bios_reboot,
326890ffedcSThomas Backlund 		.ident = "Dell Precision T7400",
327890ffedcSThomas Backlund 		.matches = {
328890ffedcSThomas Backlund 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
329890ffedcSThomas Backlund 			DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T7400"),
330890ffedcSThomas Backlund 		},
331890ffedcSThomas Backlund 	},
3324d022e35SMiguel Boton 	{	/* Handle problems with rebooting on HP laptops */
3334d022e35SMiguel Boton 		.callback = set_bios_reboot,
3344d022e35SMiguel Boton 		.ident = "HP Compaq Laptop",
3354d022e35SMiguel Boton 		.matches = {
3364d022e35SMiguel Boton 			DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
3374d022e35SMiguel Boton 			DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq"),
3384d022e35SMiguel Boton 		},
3394d022e35SMiguel Boton 	},
340dd4124a8SLeann Ogasawara 	{	/* Handle problems with rebooting on Dell XPS710 */
341dd4124a8SLeann Ogasawara 		.callback = set_bios_reboot,
342dd4124a8SLeann Ogasawara 		.ident = "Dell XPS710",
343dd4124a8SLeann Ogasawara 		.matches = {
344dd4124a8SLeann Ogasawara 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
345dd4124a8SLeann Ogasawara 			DMI_MATCH(DMI_PRODUCT_NAME, "Dell XPS710"),
346dd4124a8SLeann Ogasawara 		},
347dd4124a8SLeann Ogasawara 	},
348c5da9a2bSAlan Cox 	{	/* Handle problems with rebooting on Dell DXP061 */
349c5da9a2bSAlan Cox 		.callback = set_bios_reboot,
350c5da9a2bSAlan Cox 		.ident = "Dell DXP061",
351c5da9a2bSAlan Cox 		.matches = {
352c5da9a2bSAlan Cox 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
353c5da9a2bSAlan Cox 			DMI_MATCH(DMI_PRODUCT_NAME, "Dell DXP061"),
354c5da9a2bSAlan Cox 		},
355c5da9a2bSAlan Cox 	},
35688dff493SZhang Rui 	{	/* Handle problems with rebooting on Sony VGN-Z540N */
35788dff493SZhang Rui 		.callback = set_bios_reboot,
35888dff493SZhang Rui 		.ident = "Sony VGN-Z540N",
35988dff493SZhang Rui 		.matches = {
36088dff493SZhang Rui 			DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
36188dff493SZhang Rui 			DMI_MATCH(DMI_PRODUCT_NAME, "VGN-Z540N"),
36288dff493SZhang Rui 		},
36388dff493SZhang Rui 	},
36477f32dfdSDenis Turischev 	{	/* Handle problems with rebooting on CompuLab SBC-FITPC2 */
36577f32dfdSDenis Turischev 		.callback = set_bios_reboot,
36677f32dfdSDenis Turischev 		.ident = "CompuLab SBC-FITPC2",
36777f32dfdSDenis Turischev 		.matches = {
36877f32dfdSDenis Turischev 			DMI_MATCH(DMI_SYS_VENDOR, "CompuLab"),
36977f32dfdSDenis Turischev 			DMI_MATCH(DMI_PRODUCT_NAME, "SBC-FITPC2"),
37077f32dfdSDenis Turischev 		},
37177f32dfdSDenis Turischev 	},
3724832dddaSLeann Ogasawara 	{	/* Handle problems with rebooting on ASUS P4S800 */
3734832dddaSLeann Ogasawara 		.callback = set_bios_reboot,
3744832dddaSLeann Ogasawara 		.ident = "ASUS P4S800",
3754832dddaSLeann Ogasawara 		.matches = {
3764832dddaSLeann Ogasawara 			DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
3774832dddaSLeann Ogasawara 			DMI_MATCH(DMI_BOARD_NAME, "P4S800"),
3784832dddaSLeann Ogasawara 		},
3794832dddaSLeann Ogasawara 	},
38057b16594SMichael D Labriola #endif /* CONFIG_X86_32 */
38157b16594SMichael D Labriola 
382b49c78d4SPeter Chubb 	{	/* Handle reboot issue on Acer Aspire one */
3831ef03890SPeter Chubb 		.callback = set_kbd_reboot,
384b49c78d4SPeter Chubb 		.ident = "Acer Aspire One A110",
385b49c78d4SPeter Chubb 		.matches = {
386b49c78d4SPeter Chubb 			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
387b49c78d4SPeter Chubb 			DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
388b49c78d4SPeter Chubb 		},
389b49c78d4SPeter Chubb 	},
3903e03bbeaSShunichi Fuji 	{	/* Handle problems with rebooting on Apple MacBook5 */
3916c6c51e4SPaul Mackerras 		.callback = set_pci_reboot,
3923e03bbeaSShunichi Fuji 		.ident = "Apple MacBook5",
3936c6c51e4SPaul Mackerras 		.matches = {
3946c6c51e4SPaul Mackerras 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
3953e03bbeaSShunichi Fuji 			DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5"),
3966c6c51e4SPaul Mackerras 		},
3976c6c51e4SPaul Mackerras 	},
3983e03bbeaSShunichi Fuji 	{	/* Handle problems with rebooting on Apple MacBookPro5 */
399498cdbfbSOzan Çağlayan 		.callback = set_pci_reboot,
4003e03bbeaSShunichi Fuji 		.ident = "Apple MacBookPro5",
401498cdbfbSOzan Çağlayan 		.matches = {
402498cdbfbSOzan Çağlayan 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
4033e03bbeaSShunichi Fuji 			DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5"),
404498cdbfbSOzan Çağlayan 		},
405498cdbfbSOzan Çağlayan 	},
40605154752SGottfried Haider 	{	/* Handle problems with rebooting on Apple Macmini3,1 */
40705154752SGottfried Haider 		.callback = set_pci_reboot,
40805154752SGottfried Haider 		.ident = "Apple Macmini3,1",
40905154752SGottfried Haider 		.matches = {
41005154752SGottfried Haider 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
41105154752SGottfried Haider 			DMI_MATCH(DMI_PRODUCT_NAME, "Macmini3,1"),
41205154752SGottfried Haider 		},
41305154752SGottfried Haider 	},
4140a832320SJustin P. Mattock 	{	/* Handle problems with rebooting on the iMac9,1. */
4150a832320SJustin P. Mattock 		.callback = set_pci_reboot,
4160a832320SJustin P. Mattock 		.ident = "Apple iMac9,1",
4170a832320SJustin P. Mattock 		.matches = {
4180a832320SJustin P. Mattock 			DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
4190a832320SJustin P. Mattock 			DMI_MATCH(DMI_PRODUCT_NAME, "iMac9,1"),
4200a832320SJustin P. Mattock 		},
4210a832320SJustin P. Mattock 	},
4223628c3f5SMaxime Ripard 	{	/* Handle problems with rebooting on the Latitude E6320. */
4233628c3f5SMaxime Ripard 		.callback = set_pci_reboot,
4243628c3f5SMaxime Ripard 		.ident = "Dell Latitude E6320",
4253628c3f5SMaxime Ripard 		.matches = {
4263628c3f5SMaxime Ripard 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
4273628c3f5SMaxime Ripard 			DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6320"),
4283628c3f5SMaxime Ripard 		},
4293628c3f5SMaxime Ripard 	},
430b7798d28SDaniel J Blueman 	{	/* Handle problems with rebooting on the Latitude E5420. */
431b7798d28SDaniel J Blueman 		.callback = set_pci_reboot,
432b7798d28SDaniel J Blueman 		.ident = "Dell Latitude E5420",
433b7798d28SDaniel J Blueman 		.matches = {
434b7798d28SDaniel J Blueman 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
435b7798d28SDaniel J Blueman 			DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5420"),
436b7798d28SDaniel J Blueman 		},
437b7798d28SDaniel J Blueman 	},
438a536877eSH. Peter Anvin 	{	/* Handle problems with rebooting on the Latitude E6420. */
439a536877eSH. Peter Anvin 		.callback = set_pci_reboot,
440a536877eSH. Peter Anvin 		.ident = "Dell Latitude E6420",
441a536877eSH. Peter Anvin 		.matches = {
442a536877eSH. Peter Anvin 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
443a536877eSH. Peter Anvin 			DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6420"),
444a536877eSH. Peter Anvin 		},
445a536877eSH. Peter Anvin 	},
4466be30bb7SRafael J. Wysocki 	{	/* Handle problems with rebooting on the OptiPlex 990. */
4476be30bb7SRafael J. Wysocki 		.callback = set_pci_reboot,
4486be30bb7SRafael J. Wysocki 		.ident = "Dell OptiPlex 990",
4496be30bb7SRafael J. Wysocki 		.matches = {
4506be30bb7SRafael J. Wysocki 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
4516be30bb7SRafael J. Wysocki 			DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 990"),
4526be30bb7SRafael J. Wysocki 		},
4536be30bb7SRafael J. Wysocki 	},
454*76eb9a30SZhang Rui 	{	/* Handle problems with rebooting on the Precision M6600. */
455*76eb9a30SZhang Rui 		.callback = set_pci_reboot,
456*76eb9a30SZhang Rui 		.ident = "Dell OptiPlex 990",
457*76eb9a30SZhang Rui 		.matches = {
458*76eb9a30SZhang Rui 			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
459*76eb9a30SZhang Rui 			DMI_MATCH(DMI_PRODUCT_NAME, "Precision M6600"),
460*76eb9a30SZhang Rui 		},
461*76eb9a30SZhang Rui 	},
4626c6c51e4SPaul Mackerras 	{ }
4636c6c51e4SPaul Mackerras };
4646c6c51e4SPaul Mackerras 
46557b16594SMichael D Labriola static int __init reboot_init(void)
4666c6c51e4SPaul Mackerras {
467144d102bSMichael D Labriola 	/*
468144d102bSMichael D Labriola 	 * Only do the DMI check if reboot_type hasn't been overridden
4695955633eSMichael D Labriola 	 * on the command line
4705955633eSMichael D Labriola 	 */
471144d102bSMichael D Labriola 	if (reboot_default)
47257b16594SMichael D Labriola 		dmi_check_system(reboot_dmi_table);
4736c6c51e4SPaul Mackerras 	return 0;
4746c6c51e4SPaul Mackerras }
47557b16594SMichael D Labriola core_initcall(reboot_init);
4766c6c51e4SPaul Mackerras 
4774d022e35SMiguel Boton static inline void kb_wait(void)
4784d022e35SMiguel Boton {
4794d022e35SMiguel Boton 	int i;
4804d022e35SMiguel Boton 
481c84d6af8SAlan Cox 	for (i = 0; i < 0x10000; i++) {
482c84d6af8SAlan Cox 		if ((inb(0x64) & 0x02) == 0)
4834d022e35SMiguel Boton 			break;
484c84d6af8SAlan Cox 		udelay(2);
485c84d6af8SAlan Cox 	}
4864d022e35SMiguel Boton }
4874d022e35SMiguel Boton 
4889c48f1c6SDon Zickus static void vmxoff_nmi(int cpu, struct pt_regs *regs)
489d176720dSEduardo Habkost {
490d176720dSEduardo Habkost 	cpu_emergency_vmxoff();
491d176720dSEduardo Habkost }
492d176720dSEduardo Habkost 
493144d102bSMichael D Labriola /* Use NMIs as IPIs to tell all CPUs to disable virtualization */
494d176720dSEduardo Habkost static void emergency_vmx_disable_all(void)
495d176720dSEduardo Habkost {
496d176720dSEduardo Habkost 	/* Just make sure we won't change CPUs while doing this */
497d176720dSEduardo Habkost 	local_irq_disable();
498d176720dSEduardo Habkost 
499144d102bSMichael D Labriola 	/*
500144d102bSMichael D Labriola 	 * We need to disable VMX on all CPUs before rebooting, otherwise
501d176720dSEduardo Habkost 	 * we risk hanging up the machine, because the CPU ignore INIT
502d176720dSEduardo Habkost 	 * signals when VMX is enabled.
503d176720dSEduardo Habkost 	 *
504d176720dSEduardo Habkost 	 * We can't take any locks and we may be on an inconsistent
505d176720dSEduardo Habkost 	 * state, so we use NMIs as IPIs to tell the other CPUs to disable
506d176720dSEduardo Habkost 	 * VMX and halt.
507d176720dSEduardo Habkost 	 *
508d176720dSEduardo Habkost 	 * For safety, we will avoid running the nmi_shootdown_cpus()
509d176720dSEduardo Habkost 	 * stuff unnecessarily, but we don't have a way to check
510d176720dSEduardo Habkost 	 * if other CPUs have VMX enabled. So we will call it only if the
511d176720dSEduardo Habkost 	 * CPU we are running on has VMX enabled.
512d176720dSEduardo Habkost 	 *
513d176720dSEduardo Habkost 	 * We will miss cases where VMX is not enabled on all CPUs. This
514d176720dSEduardo Habkost 	 * shouldn't do much harm because KVM always enable VMX on all
515d176720dSEduardo Habkost 	 * CPUs anyway. But we can miss it on the small window where KVM
516d176720dSEduardo Habkost 	 * is still enabling VMX.
517d176720dSEduardo Habkost 	 */
518d176720dSEduardo Habkost 	if (cpu_has_vmx() && cpu_vmx_enabled()) {
519144d102bSMichael D Labriola 		/* Disable VMX on this CPU. */
520d176720dSEduardo Habkost 		cpu_vmxoff();
521d176720dSEduardo Habkost 
522d176720dSEduardo Habkost 		/* Halt and disable VMX on the other CPUs */
523d176720dSEduardo Habkost 		nmi_shootdown_cpus(vmxoff_nmi);
524d176720dSEduardo Habkost 
525d176720dSEduardo Habkost 	}
526d176720dSEduardo Habkost }
527d176720dSEduardo Habkost 
528d176720dSEduardo Habkost 
5297432d149SIngo Molnar void __attribute__((weak)) mach_reboot_fixups(void)
5307432d149SIngo Molnar {
5317432d149SIngo Molnar }
5327432d149SIngo Molnar 
533660e34ceSMatthew Garrett /*
534660e34ceSMatthew Garrett  * Windows compatible x86 hardware expects the following on reboot:
535660e34ceSMatthew Garrett  *
536660e34ceSMatthew Garrett  * 1) If the FADT has the ACPI reboot register flag set, try it
537660e34ceSMatthew Garrett  * 2) If still alive, write to the keyboard controller
538660e34ceSMatthew Garrett  * 3) If still alive, write to the ACPI reboot register again
539660e34ceSMatthew Garrett  * 4) If still alive, write to the keyboard controller again
540660e34ceSMatthew Garrett  *
541660e34ceSMatthew Garrett  * If the machine is still alive at this stage, it gives up. We default to
542660e34ceSMatthew Garrett  * following the same pattern, except that if we're still alive after (4) we'll
543660e34ceSMatthew Garrett  * try to force a triple fault and then cycle between hitting the keyboard
544660e34ceSMatthew Garrett  * controller and doing that
545660e34ceSMatthew Garrett  */
546416e2d63SJody Belka static void native_machine_emergency_restart(void)
5474d022e35SMiguel Boton {
5484d022e35SMiguel Boton 	int i;
549660e34ceSMatthew Garrett 	int attempt = 0;
550660e34ceSMatthew Garrett 	int orig_reboot_type = reboot_type;
5514d022e35SMiguel Boton 
552d176720dSEduardo Habkost 	if (reboot_emergency)
553d176720dSEduardo Habkost 		emergency_vmx_disable_all();
554d176720dSEduardo Habkost 
555840c2bafSJoseph Cihula 	tboot_shutdown(TB_SHUTDOWN_REBOOT);
556840c2bafSJoseph Cihula 
5574d022e35SMiguel Boton 	/* Tell the BIOS if we want cold or warm reboot */
5584d022e35SMiguel Boton 	*((unsigned short *)__va(0x472)) = reboot_mode;
5594d022e35SMiguel Boton 
5604d022e35SMiguel Boton 	for (;;) {
5614d022e35SMiguel Boton 		/* Could also try the reset bit in the Hammer NB */
5624d022e35SMiguel Boton 		switch (reboot_type) {
5634d022e35SMiguel Boton 		case BOOT_KBD:
564144d102bSMichael D Labriola 			mach_reboot_fixups(); /* For board specific fixups */
5657432d149SIngo Molnar 
5664d022e35SMiguel Boton 			for (i = 0; i < 10; i++) {
5674d022e35SMiguel Boton 				kb_wait();
5684d022e35SMiguel Boton 				udelay(50);
569144d102bSMichael D Labriola 				outb(0xfe, 0x64); /* Pulse reset low */
5704d022e35SMiguel Boton 				udelay(50);
5714d022e35SMiguel Boton 			}
572660e34ceSMatthew Garrett 			if (attempt == 0 && orig_reboot_type == BOOT_ACPI) {
573660e34ceSMatthew Garrett 				attempt = 1;
574660e34ceSMatthew Garrett 				reboot_type = BOOT_ACPI;
575660e34ceSMatthew Garrett 			} else {
576660e34ceSMatthew Garrett 				reboot_type = BOOT_TRIPLE;
577660e34ceSMatthew Garrett 			}
578660e34ceSMatthew Garrett 			break;
5794d022e35SMiguel Boton 
5804d022e35SMiguel Boton 		case BOOT_TRIPLE:
581ebdd561aSJan Beulich 			load_idt(&no_idt);
5824d022e35SMiguel Boton 			__asm__ __volatile__("int3");
5834d022e35SMiguel Boton 
5844d022e35SMiguel Boton 			reboot_type = BOOT_KBD;
5854d022e35SMiguel Boton 			break;
5864d022e35SMiguel Boton 
5874d022e35SMiguel Boton #ifdef CONFIG_X86_32
5884d022e35SMiguel Boton 		case BOOT_BIOS:
5893d35ac34SH. Peter Anvin 			machine_real_restart(MRR_BIOS);
5904d022e35SMiguel Boton 
5914d022e35SMiguel Boton 			reboot_type = BOOT_KBD;
5924d022e35SMiguel Boton 			break;
5934d022e35SMiguel Boton #endif
5944d022e35SMiguel Boton 
5954d022e35SMiguel Boton 		case BOOT_ACPI:
5964d022e35SMiguel Boton 			acpi_reboot();
5974d022e35SMiguel Boton 			reboot_type = BOOT_KBD;
5984d022e35SMiguel Boton 			break;
5994d022e35SMiguel Boton 
6004d022e35SMiguel Boton 		case BOOT_EFI:
6014d022e35SMiguel Boton 			if (efi_enabled)
60214d7ca5cSH. Peter Anvin 				efi.reset_system(reboot_mode ?
60314d7ca5cSH. Peter Anvin 						 EFI_RESET_WARM :
60414d7ca5cSH. Peter Anvin 						 EFI_RESET_COLD,
6054d022e35SMiguel Boton 						 EFI_SUCCESS, 0, NULL);
606b47b9288SH. Peter Anvin 			reboot_type = BOOT_KBD;
60714d7ca5cSH. Peter Anvin 			break;
6084d022e35SMiguel Boton 
60914d7ca5cSH. Peter Anvin 		case BOOT_CF9:
61014d7ca5cSH. Peter Anvin 			port_cf9_safe = true;
611144d102bSMichael D Labriola 			/* Fall through */
61214d7ca5cSH. Peter Anvin 
61314d7ca5cSH. Peter Anvin 		case BOOT_CF9_COND:
61414d7ca5cSH. Peter Anvin 			if (port_cf9_safe) {
61514d7ca5cSH. Peter Anvin 				u8 cf9 = inb(0xcf9) & ~6;
61614d7ca5cSH. Peter Anvin 				outb(cf9|2, 0xcf9); /* Request hard reset */
61714d7ca5cSH. Peter Anvin 				udelay(50);
61814d7ca5cSH. Peter Anvin 				outb(cf9|6, 0xcf9); /* Actually do the reset */
61914d7ca5cSH. Peter Anvin 				udelay(50);
62014d7ca5cSH. Peter Anvin 			}
6214d022e35SMiguel Boton 			reboot_type = BOOT_KBD;
6224d022e35SMiguel Boton 			break;
6234d022e35SMiguel Boton 		}
6244d022e35SMiguel Boton 	}
6254d022e35SMiguel Boton }
6264d022e35SMiguel Boton 
6273c62c625SGlauber Costa void native_machine_shutdown(void)
6284d022e35SMiguel Boton {
6294d022e35SMiguel Boton 	/* Stop the cpus and apics */
6304d022e35SMiguel Boton #ifdef CONFIG_SMP
6314d022e35SMiguel Boton 
6324d022e35SMiguel Boton 	/* The boot cpu is always logical cpu 0 */
63365c01184SMike Travis 	int reboot_cpu_id = 0;
6344d022e35SMiguel Boton 
6354d022e35SMiguel Boton #ifdef CONFIG_X86_32
6364d022e35SMiguel Boton 	/* See if there has been given a command line override */
6379628937dSMike Travis 	if ((reboot_cpu != -1) && (reboot_cpu < nr_cpu_ids) &&
6380bc3cc03SMike Travis 		cpu_online(reboot_cpu))
6394d022e35SMiguel Boton 		reboot_cpu_id = reboot_cpu;
6404d022e35SMiguel Boton #endif
6414d022e35SMiguel Boton 
6424d022e35SMiguel Boton 	/* Make certain the cpu I'm about to reboot on is online */
6430bc3cc03SMike Travis 	if (!cpu_online(reboot_cpu_id))
6444d022e35SMiguel Boton 		reboot_cpu_id = smp_processor_id();
6454d022e35SMiguel Boton 
6464d022e35SMiguel Boton 	/* Make certain I only run on the appropriate processor */
6479628937dSMike Travis 	set_cpus_allowed_ptr(current, cpumask_of(reboot_cpu_id));
6484d022e35SMiguel Boton 
649144d102bSMichael D Labriola 	/*
650144d102bSMichael D Labriola 	 * O.K Now that I'm on the appropriate processor,
6514d022e35SMiguel Boton 	 * stop all of the others.
6524d022e35SMiguel Boton 	 */
65376fac077SAlok Kataria 	stop_other_cpus();
6544d022e35SMiguel Boton #endif
6554d022e35SMiguel Boton 
6564d022e35SMiguel Boton 	lapic_shutdown();
6574d022e35SMiguel Boton 
6584d022e35SMiguel Boton #ifdef CONFIG_X86_IO_APIC
6594d022e35SMiguel Boton 	disable_IO_APIC();
6604d022e35SMiguel Boton #endif
6614d022e35SMiguel Boton 
6624d022e35SMiguel Boton #ifdef CONFIG_HPET_TIMER
6634d022e35SMiguel Boton 	hpet_disable();
6644d022e35SMiguel Boton #endif
6654d022e35SMiguel Boton 
6664d022e35SMiguel Boton #ifdef CONFIG_X86_64
667338bac52SFUJITA Tomonori 	x86_platform.iommu_shutdown();
6684d022e35SMiguel Boton #endif
6694d022e35SMiguel Boton }
6704d022e35SMiguel Boton 
671d176720dSEduardo Habkost static void __machine_emergency_restart(int emergency)
672d176720dSEduardo Habkost {
673d176720dSEduardo Habkost 	reboot_emergency = emergency;
674d176720dSEduardo Habkost 	machine_ops.emergency_restart();
675d176720dSEduardo Habkost }
676d176720dSEduardo Habkost 
677416e2d63SJody Belka static void native_machine_restart(char *__unused)
6784d022e35SMiguel Boton {
6794d022e35SMiguel Boton 	printk("machine restart\n");
6804d022e35SMiguel Boton 
6814d022e35SMiguel Boton 	if (!reboot_force)
6824d022e35SMiguel Boton 		machine_shutdown();
683d176720dSEduardo Habkost 	__machine_emergency_restart(0);
6844d022e35SMiguel Boton }
6854d022e35SMiguel Boton 
686416e2d63SJody Belka static void native_machine_halt(void)
6874d022e35SMiguel Boton {
688144d102bSMichael D Labriola 	/* Stop other cpus and apics */
689d3ec5caeSIvan Vecera 	machine_shutdown();
690d3ec5caeSIvan Vecera 
691840c2bafSJoseph Cihula 	tboot_shutdown(TB_SHUTDOWN_HALT);
692840c2bafSJoseph Cihula 
693d3ec5caeSIvan Vecera 	stop_this_cpu(NULL);
6944d022e35SMiguel Boton }
6954d022e35SMiguel Boton 
696416e2d63SJody Belka static void native_machine_power_off(void)
6974d022e35SMiguel Boton {
6984d022e35SMiguel Boton 	if (pm_power_off) {
6994d022e35SMiguel Boton 		if (!reboot_force)
7004d022e35SMiguel Boton 			machine_shutdown();
7014d022e35SMiguel Boton 		pm_power_off();
7024d022e35SMiguel Boton 	}
703144d102bSMichael D Labriola 	/* A fallback in case there is no PM info available */
704840c2bafSJoseph Cihula 	tboot_shutdown(TB_SHUTDOWN_HALT);
7054d022e35SMiguel Boton }
7064d022e35SMiguel Boton 
7074d022e35SMiguel Boton struct machine_ops machine_ops = {
708416e2d63SJody Belka 	.power_off = native_machine_power_off,
709416e2d63SJody Belka 	.shutdown = native_machine_shutdown,
710416e2d63SJody Belka 	.emergency_restart = native_machine_emergency_restart,
711416e2d63SJody Belka 	.restart = native_machine_restart,
712ed23dc6fSGlauber Costa 	.halt = native_machine_halt,
713ed23dc6fSGlauber Costa #ifdef CONFIG_KEXEC
714ed23dc6fSGlauber Costa 	.crash_shutdown = native_machine_crash_shutdown,
715ed23dc6fSGlauber Costa #endif
7164d022e35SMiguel Boton };
717416e2d63SJody Belka 
718416e2d63SJody Belka void machine_power_off(void)
719416e2d63SJody Belka {
720416e2d63SJody Belka 	machine_ops.power_off();
721416e2d63SJody Belka }
722416e2d63SJody Belka 
723416e2d63SJody Belka void machine_shutdown(void)
724416e2d63SJody Belka {
725416e2d63SJody Belka 	machine_ops.shutdown();
726416e2d63SJody Belka }
727416e2d63SJody Belka 
728416e2d63SJody Belka void machine_emergency_restart(void)
729416e2d63SJody Belka {
730d176720dSEduardo Habkost 	__machine_emergency_restart(1);
731416e2d63SJody Belka }
732416e2d63SJody Belka 
733416e2d63SJody Belka void machine_restart(char *cmd)
734416e2d63SJody Belka {
735416e2d63SJody Belka 	machine_ops.restart(cmd);
736416e2d63SJody Belka }
737416e2d63SJody Belka 
738416e2d63SJody Belka void machine_halt(void)
739416e2d63SJody Belka {
740416e2d63SJody Belka 	machine_ops.halt();
741416e2d63SJody Belka }
742416e2d63SJody Belka 
743ed23dc6fSGlauber Costa #ifdef CONFIG_KEXEC
744ed23dc6fSGlauber Costa void machine_crash_shutdown(struct pt_regs *regs)
745ed23dc6fSGlauber Costa {
746ed23dc6fSGlauber Costa 	machine_ops.crash_shutdown(regs);
747ed23dc6fSGlauber Costa }
748ed23dc6fSGlauber Costa #endif
7492ddded21SEduardo Habkost 
7502ddded21SEduardo Habkost 
751bb8dd270SEduardo Habkost #if defined(CONFIG_SMP)
7522ddded21SEduardo Habkost 
7532ddded21SEduardo Habkost /* This keeps a track of which one is crashing cpu. */
7542ddded21SEduardo Habkost static int crashing_cpu;
7552ddded21SEduardo Habkost static nmi_shootdown_cb shootdown_callback;
7562ddded21SEduardo Habkost 
7572ddded21SEduardo Habkost static atomic_t waiting_for_crash_ipi;
7582ddded21SEduardo Habkost 
7599c48f1c6SDon Zickus static int crash_nmi_callback(unsigned int val, struct pt_regs *regs)
7602ddded21SEduardo Habkost {
7612ddded21SEduardo Habkost 	int cpu;
7622ddded21SEduardo Habkost 
7632ddded21SEduardo Habkost 	cpu = raw_smp_processor_id();
7642ddded21SEduardo Habkost 
765144d102bSMichael D Labriola 	/*
766144d102bSMichael D Labriola 	 * Don't do anything if this handler is invoked on crashing cpu.
7672ddded21SEduardo Habkost 	 * Otherwise, system will completely hang. Crashing cpu can get
7682ddded21SEduardo Habkost 	 * an NMI if system was initially booted with nmi_watchdog parameter.
7692ddded21SEduardo Habkost 	 */
7702ddded21SEduardo Habkost 	if (cpu == crashing_cpu)
7719c48f1c6SDon Zickus 		return NMI_HANDLED;
7722ddded21SEduardo Habkost 	local_irq_disable();
7732ddded21SEduardo Habkost 
7749c48f1c6SDon Zickus 	shootdown_callback(cpu, regs);
7752ddded21SEduardo Habkost 
7762ddded21SEduardo Habkost 	atomic_dec(&waiting_for_crash_ipi);
7772ddded21SEduardo Habkost 	/* Assume hlt works */
7782ddded21SEduardo Habkost 	halt();
7792ddded21SEduardo Habkost 	for (;;)
7802ddded21SEduardo Habkost 		cpu_relax();
7812ddded21SEduardo Habkost 
7829c48f1c6SDon Zickus 	return NMI_HANDLED;
7832ddded21SEduardo Habkost }
7842ddded21SEduardo Habkost 
7852ddded21SEduardo Habkost static void smp_send_nmi_allbutself(void)
7862ddded21SEduardo Habkost {
787dac5f412SIngo Molnar 	apic->send_IPI_allbutself(NMI_VECTOR);
7882ddded21SEduardo Habkost }
7892ddded21SEduardo Habkost 
790144d102bSMichael D Labriola /*
791144d102bSMichael D Labriola  * Halt all other CPUs, calling the specified function on each of them
792bb8dd270SEduardo Habkost  *
793bb8dd270SEduardo Habkost  * This function can be used to halt all other CPUs on crash
794bb8dd270SEduardo Habkost  * or emergency reboot time. The function passed as parameter
795bb8dd270SEduardo Habkost  * will be called inside a NMI handler on all CPUs.
796bb8dd270SEduardo Habkost  */
7972ddded21SEduardo Habkost void nmi_shootdown_cpus(nmi_shootdown_cb callback)
7982ddded21SEduardo Habkost {
7992ddded21SEduardo Habkost 	unsigned long msecs;
800c415b3dcSEduardo Habkost 	local_irq_disable();
8012ddded21SEduardo Habkost 
8022ddded21SEduardo Habkost 	/* Make a note of crashing cpu. Will be used in NMI callback. */
8032ddded21SEduardo Habkost 	crashing_cpu = safe_smp_processor_id();
8042ddded21SEduardo Habkost 
8052ddded21SEduardo Habkost 	shootdown_callback = callback;
8062ddded21SEduardo Habkost 
8072ddded21SEduardo Habkost 	atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
8082ddded21SEduardo Habkost 	/* Would it be better to replace the trap vector here? */
8099c48f1c6SDon Zickus 	if (register_nmi_handler(NMI_LOCAL, crash_nmi_callback,
8109c48f1c6SDon Zickus 				 NMI_FLAG_FIRST, "crash"))
811144d102bSMichael D Labriola 		return;		/* Return what? */
812144d102bSMichael D Labriola 	/*
813144d102bSMichael D Labriola 	 * 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