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];
28 } reboot_type
= BOOT_KBD
;
29 static int reboot_mode
= 0;
31 /* reboot=b[ios] | t[riple] | k[bd] [, [w]arm | [c]old]
32 bios Use the CPU reboot vector for warm reset
33 warm Don't set the cold reboot flag
34 cold Set the cold reboot flag
35 triple Force a triple fault (init)
36 kbd Use the keyboard controller. cold reset (default)
38 static int __init
reboot_setup(char *str
)
56 if((str
= strchr(str
,',')) != NULL
)
64 __setup("reboot=", reboot_setup
);
66 /* overwrites random kernel memory. Should not be kernel .text */
67 #define WARMBOOT_TRAMP 0x1000UL
69 static void reboot_warm(void)
71 extern unsigned char warm_reboot
[], warm_reboot_end
[];
72 printk("warm reboot\n");
76 /* restore identity mapping */
77 init_level4_pgt
[0] = __pml4(__pa(level3_ident_pgt
) | 7);
80 /* Move the trampoline to low memory */
81 memcpy(__va(WARMBOOT_TRAMP
), warm_reboot
, warm_reboot_end
- warm_reboot
);
83 /* Start it in compatibility mode. */
84 asm volatile( " pushq $0\n" /* ss */
85 " pushq $0x2000\n" /* rsp */
86 " pushfq\n" /* eflags */
90 [cs
] "i" (__KERNEL_COMPAT32_CS
),
91 [target
] "b" (WARMBOOT_TRAMP
));
95 static void smp_halt(void)
97 int cpuid
= safe_smp_processor_id();
98 static int first_entry
= 1;
102 smp_call_function((void *)machine_restart
, NULL
, 1, 0);
107 /* AP calling this. Just halt */
108 if (cpuid
!= boot_cpu_id
) {
113 /* Wait for all other CPUs to have run smp_stop_cpu */
114 while (!cpus_empty(cpu_online_map
))
119 static inline void kb_wait(void)
123 for (i
=0; i
<0x10000; i
++)
124 if ((inb_p(0x64) & 0x02) == 0)
128 void machine_restart(char * __unused
)
139 disable_local_APIC();
146 /* Tell the BIOS if we want cold or warm reboot */
147 *((unsigned short *)__va(0x472)) = reboot_mode
;
150 /* Could also try the reset bit in the Hammer NB */
151 switch (reboot_type
) {
156 for (i
=0; i
<100; i
++) {
159 outb(0xfe,0x64); /* pulse reset low */
164 __asm__
__volatile__("lidt (%0)": :"r" (&no_idt
));
165 __asm__
__volatile__("int3");
167 reboot_type
= BOOT_KBD
;
173 EXPORT_SYMBOL(machine_restart
);
175 void machine_halt(void)
179 EXPORT_SYMBOL(machine_halt
);
181 void machine_power_off(void)
187 EXPORT_SYMBOL(machine_power_off
);