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