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