blob: 53620a92a8fdd74cc2885d28d65eaa7eb34d89d1 [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>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070010#include <linux/kdebug.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040011#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/delay.h>
Glauber de Oliveira Costa9d1c6e72007-10-19 20:35:03 +020014#include <asm/desc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#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>
OGAWA Hirofumic86c7fb2007-12-03 17:17:10 +010020#include <asm/hpet.h>
Joerg Roedel395624f2007-10-24 12:49:47 +020021#include <asm/gart.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23/*
24 * Power off function, if any
25 */
26void (*pm_power_off)(void);
Andi Kleen2ee60e172006-06-26 13:59:44 +020027EXPORT_SYMBOL(pm_power_off);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29static long no_idt[3];
30static enum {
31 BOOT_TRIPLE = 't',
32 BOOT_KBD = 'k'
33} reboot_type = BOOT_KBD;
34static int reboot_mode = 0;
35int reboot_force;
36
37/* reboot=t[riple] | k[bd] [, [w]arm | [c]old]
38 warm Don't set the cold reboot flag
39 cold Set the cold reboot flag
40 triple Force a triple fault (init)
41 kbd Use the keyboard controller. cold reset (default)
42 force Avoid anything that could hang.
43 */
44static int __init reboot_setup(char *str)
45{
46 for (;;) {
47 switch (*str) {
48 case 'w':
49 reboot_mode = 0x1234;
50 break;
51
52 case 'c':
53 reboot_mode = 0;
54 break;
55
56 case 't':
57 case 'b':
58 case 'k':
59 reboot_type = *str;
60 break;
61 case 'f':
62 reboot_force = 1;
63 break;
64 }
65 if((str = strchr(str,',')) != NULL)
66 str++;
67 else
68 break;
69 }
70 return 1;
71}
72
73__setup("reboot=", reboot_setup);
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075static inline void kb_wait(void)
76{
77 int i;
78
79 for (i=0; i<0x10000; i++)
80 if ((inb_p(0x64) & 0x02) == 0)
81 break;
82}
83
Eric W. Biedermand8955952005-06-25 14:58:02 -070084void machine_shutdown(void)
85{
Andi Kleen35062292005-11-05 17:25:54 +010086 unsigned long flags;
Yinghai Lubc2cea62007-07-21 17:11:28 +020087
Eric W. Biedermand8955952005-06-25 14:58:02 -070088 /* Stop the cpus and apics */
89#ifdef CONFIG_SMP
90 int reboot_cpu_id;
91
92 /* The boot cpu is always logical cpu 0 */
93 reboot_cpu_id = 0;
94
95 /* Make certain the cpu I'm about to reboot on is online */
96 if (!cpu_isset(reboot_cpu_id, cpu_online_map)) {
97 reboot_cpu_id = smp_processor_id();
98 }
99
100 /* Make certain I only run on the appropriate processor */
101 set_cpus_allowed(current, cpumask_of_cpu(reboot_cpu_id));
102
103 /* O.K Now that I'm on the appropriate processor,
104 * stop all of the others.
105 */
106 smp_send_stop();
107#endif
108
Andi Kleen35062292005-11-05 17:25:54 +0100109 local_irq_save(flags);
Eric W. Biedermand8955952005-06-25 14:58:02 -0700110
111#ifndef CONFIG_SMP
112 disable_local_APIC();
113#endif
114
115 disable_IO_APIC();
116
OGAWA Hirofumic86c7fb2007-12-03 17:17:10 +0100117#ifdef CONFIG_HPET_TIMER
118 hpet_disable();
119#endif
Andi Kleen35062292005-11-05 17:25:54 +0100120 local_irq_restore(flags);
Yinghai Lubc2cea62007-07-21 17:11:28 +0200121
122 pci_iommu_shutdown();
Eric W. Biedermand8955952005-06-25 14:58:02 -0700123}
124
Eric W. Biederman62b3a042005-07-26 11:45:31 -0600125void machine_emergency_restart(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 int i;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 /* Tell the BIOS if we want cold or warm reboot */
130 *((unsigned short *)__va(0x472)) = reboot_mode;
131
132 for (;;) {
133 /* Could also try the reset bit in the Hammer NB */
134 switch (reboot_type) {
135 case BOOT_KBD:
Andi Kleena6f5deb2005-11-05 17:25:54 +0100136 for (i=0; i<10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 kb_wait();
138 udelay(50);
139 outb(0xfe,0x64); /* pulse reset low */
140 udelay(50);
141 }
142
143 case BOOT_TRIPLE:
Glauber de Oliveira Costa9d1c6e72007-10-19 20:35:03 +0200144 load_idt((const struct desc_ptr *)&no_idt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 __asm__ __volatile__("int3");
146
147 reboot_type = BOOT_KBD;
148 break;
149 }
150 }
151}
152
Eric W. Biederman62b3a042005-07-26 11:45:31 -0600153void machine_restart(char * __unused)
154{
155 printk("machine restart\n");
156
157 if (!reboot_force) {
158 machine_shutdown();
159 }
160 machine_emergency_restart();
161}
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163void machine_halt(void)
164{
165}
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167void machine_power_off(void)
168{
Eric W. Biederman6e3fbee2006-01-11 22:43:12 +0100169 if (pm_power_off) {
170 if (!reboot_force) {
171 machine_shutdown();
172 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 pm_power_off();
Eric W. Biederman6e3fbee2006-01-11 22:43:12 +0100174 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175}
176