1 /* Various gunk just to reboot the machine. */
2 #include <linux/module.h>
3 #include <linux/reboot.h>
4 #include <linux/init.h>
6 #include <linux/kernel.h>
7 #include <linux/ctype.h>
8 #include <linux/string.h>
10 #include <asm/kdebug.h>
11 #include <asm/delay.h>
12 #include <asm/hw_irq.h>
13 #include <asm/system.h>
14 #include <asm/pgtable.h>
15 #include <asm/tlbflush.h>
19 * Power off function, if any
21 void (*pm_power_off)(void);
23 static long no_idt[3];
24 static int reboot_mode = 0;
25 enum reboot_types reboot_type = BOOT_KBD;
26 EXPORT_SYMBOL(reboot_type);
28 EXPORT_SYMBOL(reboot_override);
30 void (*machine_reset)(void);
31 EXPORT_SYMBOL(machine_reset);
33 /* reboot=b[ios] | t[riple] | k[bd] [, [w]arm | [c]old] | [a]cpi
34 bios Use the CPU reboot vector for warm reset
35 warm Don't set the cold reboot flag
36 cold Set the cold reboot flag
37 triple Force a triple fault (init)
38 kbd Use the keyboard controller. cold reset (default)
39 acpi Use the ACPI reset mechanism defined in the FADT
41 static int __init reboot_setup(char *str)
61 if((str = strchr(str,',')) != NULL)
69 __setup("reboot=", reboot_setup);
71 /* overwrites random kernel memory. Should not be kernel .text */
72 #define WARMBOOT_TRAMP 0x1000UL
74 static void reboot_warm(void)
76 extern unsigned char warm_reboot[], warm_reboot_end[];
77 printk("warm reboot\n");
81 /* restore identity mapping */
82 init_level4_pgt[0] = __pml4(__pa(level3_ident_pgt) | 7);
85 /* Move the trampoline to low memory */
86 memcpy(__va(WARMBOOT_TRAMP), warm_reboot, warm_reboot_end - warm_reboot);
88 /* Start it in compatibility mode. */
89 asm volatile( " pushq $0\n" /* ss */
90 " pushq $0x2000\n" /* rsp */
91 " pushfq\n" /* eflags */
95 [cs] "i" (__KERNEL_COMPAT32_CS),
96 [target] "b" (WARMBOOT_TRAMP));
99 static inline void kb_wait(void)
103 for (i=0; i<0x10000; i++)
104 if ((inb_p(0x64) & 0x02) == 0)
108 void machine_shutdown(void)
110 /* Stop the cpus and apics */
114 /* The boot cpu is always logical cpu 0 */
117 /* Make certain the cpu I'm about to reboot on is online */
118 if (!cpu_isset(reboot_cpu_id, cpu_online_map)) {
119 reboot_cpu_id = smp_processor_id();
122 /* Make certain I only run on the appropriate processor */
123 set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id));
125 /* O.K Now that I'm on the appropriate processor,
126 * stop all of the others.
134 disable_local_APIC();
142 void machine_restart(char * __unused)
148 /* Tell the BIOS if we want cold or warm reboot */
149 *((unsigned short *)__va(0x472)) = reboot_mode;
152 /* Could also try the reset bit in the Hammer NB */
153 switch (reboot_type) {
158 reboot_type = BOOT_KBD;
165 for (i=0; i<100; i++) {
168 outb(0xfe,0x64); /* pulse reset low */
173 __asm__ __volatile__("lidt (%0)": :"r" (&no_idt));
174 __asm__ __volatile__("int3");
176 reboot_type = BOOT_KBD;
182 EXPORT_SYMBOL(machine_restart);
184 void machine_halt(void)
188 EXPORT_SYMBOL(machine_halt);
190 void machine_power_off(void)
196 EXPORT_SYMBOL(machine_power_off);