blob: 57117b8beb2bfd14e7fc51a618f56fff36176826 [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>
Eric W. Biederman6e3fbee2006-01-11 22:43:12 +01009#include <linux/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <asm/io.h>
11#include <asm/kdebug.h>
12#include <asm/delay.h>
13#include <asm/hw_irq.h>
14#include <asm/system.h>
15#include <asm/pgtable.h>
16#include <asm/tlbflush.h>
17#include <asm/apic.h>
18
19/*
20 * Power off function, if any
21 */
22void (*pm_power_off)(void);
23
24static long no_idt[3];
25static enum {
26 BOOT_TRIPLE = 't',
27 BOOT_KBD = 'k'
28} reboot_type = BOOT_KBD;
29static int reboot_mode = 0;
30int reboot_force;
31
32/* reboot=t[riple] | k[bd] [, [w]arm | [c]old]
33 warm Don't set the cold reboot flag
34 cold Set the cold reboot flag
35 triple Force a triple fault (init)
36 kbd Use the keyboard controller. cold reset (default)
37 force Avoid anything that could hang.
38 */
39static int __init reboot_setup(char *str)
40{
41 for (;;) {
42 switch (*str) {
43 case 'w':
44 reboot_mode = 0x1234;
45 break;
46
47 case 'c':
48 reboot_mode = 0;
49 break;
50
51 case 't':
52 case 'b':
53 case 'k':
54 reboot_type = *str;
55 break;
56 case 'f':
57 reboot_force = 1;
58 break;
59 }
60 if((str = strchr(str,',')) != NULL)
61 str++;
62 else
63 break;
64 }
65 return 1;
66}
67
68__setup("reboot=", reboot_setup);
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070static inline void kb_wait(void)
71{
72 int i;
73
74 for (i=0; i<0x10000; i++)
75 if ((inb_p(0x64) & 0x02) == 0)
76 break;
77}
78
Eric W. Biedermand8955952005-06-25 14:58:02 -070079void machine_shutdown(void)
80{
Andi Kleen35062292005-11-05 17:25:54 +010081 unsigned long flags;
Eric W. Biedermand8955952005-06-25 14:58:02 -070082 /* Stop the cpus and apics */
83#ifdef CONFIG_SMP
84 int reboot_cpu_id;
85
86 /* The boot cpu is always logical cpu 0 */
87 reboot_cpu_id = 0;
88
89 /* Make certain the cpu I'm about to reboot on is online */
90 if (!cpu_isset(reboot_cpu_id, cpu_online_map)) {
91 reboot_cpu_id = smp_processor_id();
92 }
93
94 /* Make certain I only run on the appropriate processor */
95 set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id));
96
97 /* O.K Now that I'm on the appropriate processor,
98 * stop all of the others.
99 */
100 smp_send_stop();
101#endif
102
Andi Kleen35062292005-11-05 17:25:54 +0100103 local_irq_save(flags);
Eric W. Biedermand8955952005-06-25 14:58:02 -0700104
105#ifndef CONFIG_SMP
106 disable_local_APIC();
107#endif
108
109 disable_IO_APIC();
110
Andi Kleen35062292005-11-05 17:25:54 +0100111 local_irq_restore(flags);
Eric W. Biedermand8955952005-06-25 14:58:02 -0700112}
113
Eric W. Biederman62b3a042005-07-26 11:45:31 -0600114void machine_emergency_restart(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 int i;
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 /* Tell the BIOS if we want cold or warm reboot */
119 *((unsigned short *)__va(0x472)) = reboot_mode;
120
121 for (;;) {
122 /* Could also try the reset bit in the Hammer NB */
123 switch (reboot_type) {
124 case BOOT_KBD:
Andi Kleena6f5deb2005-11-05 17:25:54 +0100125 for (i=0; i<10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 kb_wait();
127 udelay(50);
128 outb(0xfe,0x64); /* pulse reset low */
129 udelay(50);
130 }
131
132 case BOOT_TRIPLE:
133 __asm__ __volatile__("lidt (%0)": :"r" (&no_idt));
134 __asm__ __volatile__("int3");
135
136 reboot_type = BOOT_KBD;
137 break;
138 }
139 }
140}
141
Eric W. Biederman62b3a042005-07-26 11:45:31 -0600142void machine_restart(char * __unused)
143{
144 printk("machine restart\n");
145
146 if (!reboot_force) {
147 machine_shutdown();
148 }
149 machine_emergency_restart();
150}
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152void machine_halt(void)
153{
154}
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156void machine_power_off(void)
157{
Eric W. Biederman6e3fbee2006-01-11 22:43:12 +0100158 if (pm_power_off) {
159 if (!reboot_force) {
160 machine_shutdown();
161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 pm_power_off();
Eric W. Biederman6e3fbee2006-01-11 22:43:12 +0100163 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164}
165