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];
27 } reboot_type = BOOT_KBD;
28 static int reboot_mode = 0;
31 /* reboot=t[riple] | k[bd] [, [w]arm | [c]old]
32 warm Don't set the cold reboot flag
33 cold Set the cold reboot flag
34 triple Force a triple fault (init)
35 kbd Use the keyboard controller. cold reset (default)
36 force Avoid anything that could hang.
38 static int __init reboot_setup(char *str)
59 if((str = strchr(str,',')) != NULL)
67 __setup("reboot=", reboot_setup);
69 /* overwrites random kernel memory. Should not be kernel .text */
70 #define WARMBOOT_TRAMP 0x1000UL
72 static void reboot_warm(void)
74 extern unsigned char warm_reboot[], warm_reboot_end[];
75 printk("warm reboot\n");
79 /* restore identity mapping */
80 init_level4_pgt[0] = __pml4(__pa(level3_ident_pgt) | 7);
83 /* Move the trampoline to low memory */
84 memcpy(__va(WARMBOOT_TRAMP), warm_reboot, warm_reboot_end - warm_reboot);
86 /* Start it in compatibility mode. */
87 asm volatile( " pushq $0\n" /* ss */
88 " pushq $0x2000\n" /* rsp */
89 " pushfq\n" /* eflags */
93 [cs] "i" (__KERNEL_COMPAT32_CS),
94 [target] "b" (WARMBOOT_TRAMP));
97 static inline void kb_wait(void)
101 for (i=0; i<0x10000; i++)
102 if ((inb_p(0x64) & 0x02) == 0)
106 void machine_shutdown(void)
108 /* Stop the cpus and apics */
112 /* The boot cpu is always logical cpu 0 */
115 /* Make certain the cpu I'm about to reboot on is online */
116 if (!cpu_isset(reboot_cpu_id, cpu_online_map)) {
117 reboot_cpu_id = smp_processor_id();
120 /* Make certain I only run on the appropriate processor */
121 set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id));
123 /* O.K Now that I'm on the appropriate processor,
124 * stop all of the others.
132 disable_local_APIC();
140 static void smp_halt(void)
142 int cpuid = safe_smp_processor_id();
143 static int first_entry = 1;
150 smp_call_function((void *)machine_restart, NULL, 1, 0);
155 /* AP calling this. Just halt */
156 if (cpuid != boot_cpu_id) {
161 /* Wait for all other CPUs to have run smp_stop_cpu */
162 while (!cpus_empty(cpu_online_map))
166 void machine_restart(char * __unused)
171 printk("machine restart\n");
180 disable_local_APIC();
186 /* Tell the BIOS if we want cold or warm reboot */
187 *((unsigned short *)__va(0x472)) = reboot_mode;
190 /* Could also try the reset bit in the Hammer NB */
191 switch (reboot_type) {
193 for (i=0; i<100; i++) {
196 outb(0xfe,0x64); /* pulse reset low */
201 __asm__ __volatile__("lidt (%0)": :"r" (&no_idt));
202 __asm__ __volatile__("int3");
204 reboot_type = BOOT_KBD;
210 EXPORT_SYMBOL(machine_restart);
212 void machine_halt(void)
216 EXPORT_SYMBOL(machine_halt);
218 void machine_power_off(void)
224 EXPORT_SYMBOL(machine_power_off);