[PATCH] i386: avoid checking for cpu gone when CONFIG_HOTPLUG_CPU not defined
[deliverable/linux.git] / arch / i386 / kernel / reboot.c
CommitLineData
1da177e4
LT
1/*
2 * linux/arch/i386/kernel/reboot.c
3 */
4
5#include <linux/mm.h>
6#include <linux/module.h>
7#include <linux/delay.h>
8#include <linux/init.h>
9#include <linux/interrupt.h>
10#include <linux/mc146818rtc.h>
11#include <linux/efi.h>
12#include <linux/dmi.h>
6f673d83 13#include <linux/ctype.h>
6e3fbee5 14#include <linux/pm.h>
cd6ed525 15#include <linux/reboot.h>
1da177e4
LT
16#include <asm/uaccess.h>
17#include <asm/apic.h>
4d37e7e3 18#include <asm/desc.h>
1da177e4 19#include "mach_reboot.h"
973efae2 20#include <asm/reboot_fixups.h>
07f3331c 21#include <asm/reboot.h>
1da177e4
LT
22
23/*
24 * Power off function, if any
25 */
26void (*pm_power_off)(void);
129f6946 27EXPORT_SYMBOL(pm_power_off);
1da177e4
LT
28
29static int reboot_mode;
30static int reboot_thru_bios;
31
32#ifdef CONFIG_SMP
1da177e4 33static int reboot_cpu = -1;
1da177e4
LT
34#endif
35static int __init reboot_setup(char *str)
36{
37 while(1) {
38 switch (*str) {
39 case 'w': /* "warm" reboot (no memory testing etc) */
40 reboot_mode = 0x1234;
41 break;
42 case 'c': /* "cold" reboot (with memory testing etc) */
43 reboot_mode = 0x0;
44 break;
45 case 'b': /* "bios" reboot by jumping through the BIOS */
46 reboot_thru_bios = 1;
47 break;
48 case 'h': /* "hard" reboot by toggling RESET and/or crashing the CPU */
49 reboot_thru_bios = 0;
50 break;
51#ifdef CONFIG_SMP
52 case 's': /* "smp" reboot by executing reset on BSP or other CPU*/
6f673d83 53 if (isdigit(*(str+1))) {
1da177e4 54 reboot_cpu = (int) (*(str+1) - '0');
6f673d83 55 if (isdigit(*(str+2)))
1da177e4
LT
56 reboot_cpu = reboot_cpu*10 + (int)(*(str+2) - '0');
57 }
58 /* we will leave sorting out the final value
59 when we are ready to reboot, since we might not
60 have set up boot_cpu_id or smp_num_cpu */
61 break;
62#endif
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/*
75 * Reboot options and system auto-detection code provided by
76 * Dell Inc. so their systems "just work". :-)
77 */
78
79/*
80 * Some machines require the "reboot=b" commandline option, this quirk makes that automatic.
81 */
82static int __init set_bios_reboot(struct dmi_system_id *d)
83{
84 if (!reboot_thru_bios) {
85 reboot_thru_bios = 1;
86 printk(KERN_INFO "%s series board detected. Selecting BIOS-method for reboots.\n", d->ident);
87 }
88 return 0;
89}
90
1da177e4
LT
91static struct dmi_system_id __initdata reboot_dmi_table[] = {
92 { /* Handle problems with rebooting on Dell 1300's */
dd2a1305 93 .callback = set_bios_reboot,
1da177e4
LT
94 .ident = "Dell PowerEdge 1300",
95 .matches = {
96 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
97 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1300/"),
98 },
99 },
100 { /* Handle problems with rebooting on Dell 300's */
101 .callback = set_bios_reboot,
102 .ident = "Dell PowerEdge 300",
103 .matches = {
104 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
105 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 300/"),
106 },
107 },
108 { /* Handle problems with rebooting on Dell 2400's */
109 .callback = set_bios_reboot,
110 .ident = "Dell PowerEdge 2400",
111 .matches = {
112 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
113 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2400"),
114 },
115 },
766c3f94 116 { /* Handle problems with rebooting on HP laptops */
d91b14c4 117 .callback = set_bios_reboot,
766c3f94 118 .ident = "HP Compaq Laptop",
d91b14c4
TV
119 .matches = {
120 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
766c3f94 121 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq"),
d91b14c4
TV
122 },
123 },
1da177e4
LT
124 { }
125};
126
127static int __init reboot_init(void)
128{
129 dmi_check_system(reboot_dmi_table);
130 return 0;
131}
132
133core_initcall(reboot_init);
134
135/* The following code and data reboots the machine by switching to real
136 mode and jumping to the BIOS reset entry point, as if the CPU has
137 really been reset. The previous version asked the keyboard
138 controller to pulse the CPU reset line, which is more thorough, but
139 doesn't work with at least one type of 486 motherboard. It is easy
140 to stop this code working; hence the copious comments. */
141
142static unsigned long long
143real_mode_gdt_entries [3] =
144{
145 0x0000000000000000ULL, /* Null descriptor */
146 0x00009a000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
147 0x000092000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
148};
149
05f4a3ec
RR
150static struct Xgt_desc_struct
151real_mode_gdt = { sizeof (real_mode_gdt_entries) - 1, (long)real_mode_gdt_entries },
152real_mode_idt = { 0x3ff, 0 },
153no_idt = { 0, 0 };
1da177e4
LT
154
155
156/* This is 16-bit protected mode code to disable paging and the cache,
157 switch to real mode and jump to the BIOS reset code.
158
159 The instruction that switches to real mode by writing to CR0 must be
160 followed immediately by a far jump instruction, which set CS to a
161 valid value for real mode, and flushes the prefetch queue to avoid
162 running instructions that have already been decoded in protected
163 mode.
164
165 Clears all the flags except ET, especially PG (paging), PE
166 (protected-mode enable) and TS (task switch for coprocessor state
167 save). Flushes the TLB after paging has been disabled. Sets CD and
168 NW, to disable the cache on a 486, and invalidates the cache. This
169 is more like the state of a 486 after reset. I don't know if
170 something else should be done for other chips.
171
172 More could be done here to set up the registers as if a CPU reset had
173 occurred; hopefully real BIOSs don't assume much. */
174
175static unsigned char real_mode_switch [] =
176{
177 0x66, 0x0f, 0x20, 0xc0, /* movl %cr0,%eax */
178 0x66, 0x83, 0xe0, 0x11, /* andl $0x00000011,%eax */
179 0x66, 0x0d, 0x00, 0x00, 0x00, 0x60, /* orl $0x60000000,%eax */
180 0x66, 0x0f, 0x22, 0xc0, /* movl %eax,%cr0 */
181 0x66, 0x0f, 0x22, 0xd8, /* movl %eax,%cr3 */
182 0x66, 0x0f, 0x20, 0xc3, /* movl %cr0,%ebx */
183 0x66, 0x81, 0xe3, 0x00, 0x00, 0x00, 0x60, /* andl $0x60000000,%ebx */
184 0x74, 0x02, /* jz f */
185 0x0f, 0x09, /* wbinvd */
186 0x24, 0x10, /* f: andb $0x10,al */
187 0x66, 0x0f, 0x22, 0xc0 /* movl %eax,%cr0 */
188};
189static unsigned char jump_to_bios [] =
190{
191 0xea, 0x00, 0x00, 0xff, 0xff /* ljmp $0xffff,$0x0000 */
192};
193
194/*
195 * Switch to real mode and then execute the code
196 * specified by the code and length parameters.
197 * We assume that length will aways be less that 100!
198 */
199void machine_real_restart(unsigned char *code, int length)
200{
201 unsigned long flags;
202
203 local_irq_disable();
204
205 /* Write zero to CMOS register number 0x0f, which the BIOS POST
206 routine will recognize as telling it to do a proper reboot. (Well
207 that's what this book in front of me says -- it may only apply to
208 the Phoenix BIOS though, it's not clear). At the same time,
209 disable NMIs by setting the top bit in the CMOS address register,
210 as we're about to do peculiar things to the CPU. I'm not sure if
211 `outb_p' is needed instead of just `outb'. Use it to be on the
212 safe side. (Yes, CMOS_WRITE does outb_p's. - Paul G.)
213 */
214
215 spin_lock_irqsave(&rtc_lock, flags);
216 CMOS_WRITE(0x00, 0x8f);
217 spin_unlock_irqrestore(&rtc_lock, flags);
218
219 /* Remap the kernel at virtual address zero, as well as offset zero
220 from the kernel segment. This assumes the kernel segment starts at
221 virtual address PAGE_OFFSET. */
222
223 memcpy (swapper_pg_dir, swapper_pg_dir + USER_PGD_PTRS,
224 sizeof (swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
225
226 /*
227 * Use `swapper_pg_dir' as our page directory.
228 */
229 load_cr3(swapper_pg_dir);
230
231 /* Write 0x1234 to absolute memory location 0x472. The BIOS reads
232 this on booting to tell it to "Bypass memory test (also warm
233 boot)". This seems like a fairly standard thing that gets set by
234 REBOOT.COM programs, and the previous reset routine did this
235 too. */
236
237 *((unsigned short *)0x472) = reboot_mode;
238
239 /* For the switch to real mode, copy some code to low memory. It has
240 to be in the first 64k because it is running in 16-bit mode, and it
241 has to have the same physical and virtual address, because it turns
242 off paging. Copy it near the end of the first page, out of the way
243 of BIOS variables. */
244
245 memcpy ((void *) (0x1000 - sizeof (real_mode_switch) - 100),
246 real_mode_switch, sizeof (real_mode_switch));
247 memcpy ((void *) (0x1000 - 100), code, length);
248
249 /* Set up the IDT for real mode. */
250
4d37e7e3 251 load_idt(&real_mode_idt);
1da177e4
LT
252
253 /* Set up a GDT from which we can load segment descriptors for real
254 mode. The GDT is not used in real mode; it is just needed here to
255 prepare the descriptors. */
256
4d37e7e3 257 load_gdt(&real_mode_gdt);
1da177e4
LT
258
259 /* Load the data segment registers, and thus the descriptors ready for
260 real mode. The base address of each segment is 0x100, 16 times the
261 selector value being loaded here. This is so that the segment
262 registers don't have to be reloaded after switching to real mode:
263 the values are consistent for real mode operation already. */
264
265 __asm__ __volatile__ ("movl $0x0010,%%eax\n"
266 "\tmovl %%eax,%%ds\n"
267 "\tmovl %%eax,%%es\n"
268 "\tmovl %%eax,%%fs\n"
269 "\tmovl %%eax,%%gs\n"
270 "\tmovl %%eax,%%ss" : : : "eax");
271
272 /* Jump to the 16-bit code that we copied earlier. It disables paging
273 and the cache, switches to real mode, and jumps to the BIOS reset
274 entry point. */
275
276 __asm__ __volatile__ ("ljmp $0x0008,%0"
277 :
278 : "i" ((void *) (0x1000 - sizeof (real_mode_switch) - 100)));
279}
129f6946
AD
280#ifdef CONFIG_APM_MODULE
281EXPORT_SYMBOL(machine_real_restart);
282#endif
1da177e4 283
07f3331c 284static void native_machine_shutdown(void)
1da177e4
LT
285{
286#ifdef CONFIG_SMP
dd2a1305
EB
287 int reboot_cpu_id;
288
289 /* The boot cpu is always logical cpu 0 */
290 reboot_cpu_id = 0;
291
292 /* See if there has been given a command line override */
d8e392e7 293 if ((reboot_cpu != -1) && (reboot_cpu < NR_CPUS) &&
dd2a1305
EB
294 cpu_isset(reboot_cpu, cpu_online_map)) {
295 reboot_cpu_id = reboot_cpu;
1da177e4
LT
296 }
297
dd2a1305
EB
298 /* Make certain the cpu I'm rebooting on is online */
299 if (!cpu_isset(reboot_cpu_id, cpu_online_map)) {
300 reboot_cpu_id = smp_processor_id();
1da177e4 301 }
dd2a1305
EB
302
303 /* Make certain I only run on the appropriate processor */
304 set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id));
305
306 /* O.K. Now that I'm on the appropriate processor, stop
307 * all of the others, and disable their local APICs.
1da177e4 308 */
dd2a1305 309
1da177e4
LT
310 smp_send_stop();
311#endif /* CONFIG_SMP */
312
313 lapic_shutdown();
314
315#ifdef CONFIG_X86_IO_APIC
316 disable_IO_APIC();
317#endif
dd2a1305
EB
318}
319
973efae2
JF
320void __attribute__((weak)) mach_reboot_fixups(void)
321{
322}
323
07f3331c 324static void native_machine_emergency_restart(void)
dd2a1305 325{
1da177e4
LT
326 if (!reboot_thru_bios) {
327 if (efi_enabled) {
328 efi.reset_system(EFI_RESET_COLD, EFI_SUCCESS, 0, NULL);
4d37e7e3 329 load_idt(&no_idt);
1da177e4
LT
330 __asm__ __volatile__("int3");
331 }
332 /* rebooting needs to touch the page at absolute addr 0 */
333 *((unsigned short *)__va(0x472)) = reboot_mode;
334 for (;;) {
a2f7c354 335 mach_reboot_fixups(); /* for board specific fixups */
1da177e4
LT
336 mach_reboot();
337 /* That didn't work - force a triple fault.. */
4d37e7e3 338 load_idt(&no_idt);
1da177e4
LT
339 __asm__ __volatile__("int3");
340 }
341 }
342 if (efi_enabled)
343 efi.reset_system(EFI_RESET_WARM, EFI_SUCCESS, 0, NULL);
344
345 machine_real_restart(jump_to_bios, sizeof(jump_to_bios));
346}
347
07f3331c 348static void native_machine_restart(char * __unused)
4a1421f8
EB
349{
350 machine_shutdown();
351 machine_emergency_restart();
352}
353
07f3331c 354static void native_machine_halt(void)
1da177e4
LT
355{
356}
357
07f3331c 358static void native_machine_power_off(void)
1da177e4 359{
6e3fbee5
EB
360 if (pm_power_off) {
361 machine_shutdown();
1da177e4 362 pm_power_off();
6e3fbee5 363 }
1da177e4
LT
364}
365
1da177e4 366
07f3331c
JF
367struct machine_ops machine_ops = {
368 .power_off = native_machine_power_off,
369 .shutdown = native_machine_shutdown,
370 .emergency_restart = native_machine_emergency_restart,
371 .restart = native_machine_restart,
372 .halt = native_machine_halt,
373};
374
375void machine_power_off(void)
376{
377 machine_ops.power_off();
378}
379
380void machine_shutdown(void)
381{
382 machine_ops.shutdown();
383}
384
385void machine_emergency_restart(void)
386{
387 machine_ops.emergency_restart();
388}
389
390void machine_restart(char *cmd)
391{
392 machine_ops.restart(cmd);
393}
394
395void machine_halt(void)
396{
397 machine_ops.halt();
398}
This page took 0.246328 seconds and 5 git commands to generate.