1 /* Various gunk just to reboot the machine. */
2 #include <linux/module.h>
3 #include <linux/reboot.h>
4 #include <linux/init.h>
5 #include <linux/smp.h>
6 #include <linux/kernel.h>
7 #include <linux/ctype.h>
8 #include <linux/string.h>
9 #include <linux/pm.h>
10 #include <asm/io.h>
11 #include <asm/kdebug.h>
12 #include <asm/delay.h>
13 #include <asm/hw_irq.h>
14 #include <asm/system.h>
15 #include <asm/pgtable.h>
16 #include <asm/tlbflush.h>
17 #include <asm/apic.h>
18
19 /*
20 * Power off function, if any
21 */
22 void (*pm_power_off)(void);
23
24 static long no_idt[3];
25 static enum {
26 BOOT_TRIPLE = 't',
27 BOOT_KBD = 'k'
28 } reboot_type = BOOT_KBD;
29 static int reboot_mode = 0;
30 int reboot_force;
31
32 /* reboot=t[riple] | k[bd] [, [w]arm | [c]old]
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)
37 force Avoid anything that could hang.
38 */
39 static int __init reboot_setup(char *str)
40 {
41 for (;;) {
42 switch (*str) {
43 case 'w':
44 reboot_mode = 0x1234;
45 break;
46
47 case 'c':
48 reboot_mode = 0;
49 break;
50
51 case 't':
52 case 'b':
53 case 'k':
54 reboot_type = *str;
55 break;
56 case 'f':
57 reboot_force = 1;
58 break;
59 }
60 if((str = strchr(str,',')) != NULL)
61 str++;
62 else
63 break;
64 }
65 return 1;
66 }
67
68 __setup("reboot=", reboot_setup);
69
70 static inline void kb_wait(void)
71 {
72 int i;
73
74 for (i=0; i<0x10000; i++)
75 if ((inb_p(0x64) & 0x02) == 0)
76 break;
77 }
78
79 void machine_shutdown(void)
80 {
81 unsigned long flags;
82 /* Stop the cpus and apics */
83 #ifdef CONFIG_SMP
84 int reboot_cpu_id;
85
86 /* The boot cpu is always logical cpu 0 */
87 reboot_cpu_id = 0;
88
89 /* Make certain the cpu I'm about to reboot on is online */
90 if (!cpu_isset(reboot_cpu_id, cpu_online_map)) {
91 reboot_cpu_id = smp_processor_id();
92 }
93
94 /* Make certain I only run on the appropriate processor */
95 set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id));
96
97 /* O.K Now that I'm on the appropriate processor,
98 * stop all of the others.
99 */
100 smp_send_stop();
101 #endif
102
103 local_irq_save(flags);
104
105 #ifndef CONFIG_SMP
106 disable_local_APIC();
107 #endif
108
109 disable_IO_APIC();
110
111 local_irq_restore(flags);
112 }
113
114 void machine_emergency_restart(void)
115 {
116 int i;
117
118 /* Tell the BIOS if we want cold or warm reboot */
119 *((unsigned short *)__va(0x472)) = reboot_mode;
120
121 for (;;) {
122 /* Could also try the reset bit in the Hammer NB */
123 switch (reboot_type) {
124 case BOOT_KBD:
125 for (i=0; i<10; i++) {
126 kb_wait();
127 udelay(50);
128 outb(0xfe,0x64); /* pulse reset low */
129 udelay(50);
130 }
131
132 case BOOT_TRIPLE:
133 __asm__ __volatile__("lidt (%0)": :"r" (&no_idt));
134 __asm__ __volatile__("int3");
135
136 reboot_type = BOOT_KBD;
137 break;
138 }
139 }
140 }
141
142 void machine_restart(char * __unused)
143 {
144 printk("machine restart\n");
145
146 if (!reboot_force) {
147 machine_shutdown();
148 }
149 machine_emergency_restart();
150 }
151
152 void machine_halt(void)
153 {
154 }
155
156 void machine_power_off(void)
157 {
158 if (pm_power_off) {
159 if (!reboot_force) {
160 machine_shutdown();
161 }
162 pm_power_off();
163 }
164 }
165
166
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.