blob: 97804bc2c0a0d9001943ff9b1e4b87628ae28c50 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static inline void kb_wait(void)
70{
71 int i;
72
73 for (i=0; i<0x10000; i++)
74 if ((inb_p(0x64) & 0x02) == 0)
75 break;
76}
77
Eric W. Biedermand8955952005-06-25 14:58:02 -070078void machine_shutdown(void)
79{
Andi Kleen35062292005-11-05 17:25:54 +010080 unsigned long flags;
Eric W. Biedermand8955952005-06-25 14:58:02 -070081 /* Stop the cpus and apics */
82#ifdef CONFIG_SMP
83 int reboot_cpu_id;
84
85 /* The boot cpu is always logical cpu 0 */
86 reboot_cpu_id = 0;
87
88 /* Make certain the cpu I'm about to reboot on is online */
89 if (!cpu_isset(reboot_cpu_id, cpu_online_map)) {
90 reboot_cpu_id = smp_processor_id();
91 }
92
93 /* Make certain I only run on the appropriate processor */
94 set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id));
95
96 /* O.K Now that I'm on the appropriate processor,
97 * stop all of the others.
98 */
99 smp_send_stop();
100#endif
101
Andi Kleen35062292005-11-05 17:25:54 +0100102 local_irq_save(flags);
Eric W. Biedermand8955952005-06-25 14:58:02 -0700103
104#ifndef CONFIG_SMP
105 disable_local_APIC();
106#endif
107
108 disable_IO_APIC();
109
Andi Kleen35062292005-11-05 17:25:54 +0100110 local_irq_restore(flags);
Eric W. Biedermand8955952005-06-25 14:58:02 -0700111}
112
Eric W. Biederman62b3a042005-07-26 11:45:31 -0600113void machine_emergency_restart(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
115 int i;
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 /* Tell the BIOS if we want cold or warm reboot */
118 *((unsigned short *)__va(0x472)) = reboot_mode;
119
120 for (;;) {
121 /* Could also try the reset bit in the Hammer NB */
122 switch (reboot_type) {
123 case BOOT_KBD:
124 for (i=0; i<100; i++) {
125 kb_wait();
126 udelay(50);
127 outb(0xfe,0x64); /* pulse reset low */
128 udelay(50);
129 }
130
131 case BOOT_TRIPLE:
132 __asm__ __volatile__("lidt (%0)": :"r" (&no_idt));
133 __asm__ __volatile__("int3");
134
135 reboot_type = BOOT_KBD;
136 break;
137 }
138 }
139}
140
Eric W. Biederman62b3a042005-07-26 11:45:31 -0600141void machine_restart(char * __unused)
142{
143 printk("machine restart\n");
144
145 if (!reboot_force) {
146 machine_shutdown();
147 }
148 machine_emergency_restart();
149}
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151void machine_halt(void)
152{
153}
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155void machine_power_off(void)
156{
Eric W. Biederman0963aba2005-07-26 12:14:16 -0600157 if (!reboot_force) {
158 machine_shutdown();
159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 if (pm_power_off)
161 pm_power_off();
162}
163