1 /* Various gunk just to reboot the machine. */
2 #include <linux/reboot.h>
3 #include <linux/init.h>
5 #include <linux/kernel.h>
6 #include <linux/ctype.h>
7 #include <linux/string.h>
9 #include <asm/kdebug.h>
10 #include <asm/delay.h>
11 #include <asm/hw_irq.h>
12 #include <asm/system.h>
13 #include <asm/pgtable.h>
14 #include <asm/tlbflush.h>
18 * Power off function, if any
20 void (*pm_power_off)(void);
22 static long no_idt[3];
27 } reboot_type = BOOT_KBD;
28 static int reboot_mode = 0;
30 /* reboot=b[ios] | t[riple] | k[bd] [, [w]arm | [c]old]
31 bios Use the CPU reboto vector for warm reset
32 warm Don't set the cold reboot flag
33 cold Set the cold reboto flag
34 triple Force a triple fault (init)
35 kbd Use the keyboard controller. cold reset (default)
37 static int __init reboot_setup(char *str)
55 if((str = strchr(str,',')) != NULL)
63 __setup("reboot=", reboot_setup);
65 /* overwrites random kernel memory. Should not be kernel .text */
66 #define WARMBOOT_TRAMP 0x1000UL
68 static void reboot_warm(void)
70 extern unsigned char warm_reboot[], warm_reboot_end[];
71 printk("warm reboot\n");
75 /* restore identity mapping */
76 init_level4_pgt[0] = __pml4(__pa(level3_ident_pgt) | 7);
79 /* Move the trampoline to low memory */
80 memcpy(__va(WARMBOOT_TRAMP), warm_reboot, warm_reboot_end - warm_reboot);
82 /* Start it in compatibility mode. */
83 asm volatile( " pushq $0\n" /* ss */
84 " pushq $0x2000\n" /* rsp */
85 " pushfq\n" /* eflags */
89 [cs] "i" (__KERNEL_COMPAT32_CS),
90 [target] "b" (WARMBOOT_TRAMP));
94 static void smp_halt(void)
96 int cpuid = safe_smp_processor_id();
97 static int first_entry = 1;
101 smp_call_function((void *)machine_restart, NULL, 1, 0);
106 /* AP calling this. Just halt */
107 if (cpuid != boot_cpu_id) {
112 /* Wait for all other CPUs to have run smp_stop_cpu */
113 while (cpu_online_map)
118 static inline void kb_wait(void)
122 for (i=0; i<0x10000; i++)
123 if ((inb_p(0x64) & 0x02) == 0)
127 void machine_restart(char * __unused)
138 disable_local_APIC();
145 /* Tell the BIOS if we want cold or warm reboot */
146 *((unsigned short *)__va(0x472)) = reboot_mode;
149 /* Could also try the reset bit in the Hammer NB */
150 switch (reboot_type) {
155 for (i=0; i<100; i++) {
158 outb(0xfe,0x64); /* pulse reset low */
163 __asm__ __volatile__("lidt %0": :"m" (no_idt));
164 __asm__ __volatile__("int3");
166 reboot_type = BOOT_KBD;
172 void machine_halt(void)
176 void machine_power_off(void)