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