ia64/xen-unstable

view linux-2.6.11-xen-sparse/arch/xen/kernel/reboot.c @ 5273:d823045eab51

bitkeeper revision 1.1637.1.1 (429f100et_8vOZLTej8un3-WOmraFg)

Fix bug #68: x86_64 build break - `pgd_cache' undeclared
http://bugzilla.xensource.com/cgi-bin/bugzilla/show_bug.cgi?id=68
reboot.c:
Fix x86_64 build.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu Jun 02 13:56:30 2005 +0000 (2005-06-02)
parents d8410197d991
children 7d4fe5930112
line source
2 #define __KERNEL_SYSCALLS__
3 static int errno;
4 #include <linux/errno.h>
5 #include <linux/version.h>
6 #include <linux/kernel.h>
7 #include <linux/mm.h>
8 #include <linux/unistd.h>
9 #include <linux/module.h>
10 #include <linux/reboot.h>
11 #include <linux/sysrq.h>
12 #include <asm/irq.h>
13 #include <asm/mmu_context.h>
14 #include <asm-xen/ctrl_if.h>
15 #include <asm-xen/hypervisor.h>
16 #include <asm-xen/xen-public/dom0_ops.h>
17 #include <asm-xen/linux-public/suspend.h>
18 #include <asm-xen/queues.h>
20 void machine_restart(char * __unused)
21 {
22 /* We really want to get pending console data out before we die. */
23 extern void xencons_force_flush(void);
24 xencons_force_flush();
25 HYPERVISOR_reboot();
26 }
28 void machine_halt(void)
29 {
30 machine_power_off();
31 }
33 void machine_power_off(void)
34 {
35 /* We really want to get pending console data out before we die. */
36 extern void xencons_force_flush(void);
37 xencons_force_flush();
38 HYPERVISOR_shutdown();
39 }
41 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
42 int reboot_thru_bios = 0; /* for dmi_scan.c */
43 EXPORT_SYMBOL(machine_restart);
44 EXPORT_SYMBOL(machine_halt);
45 EXPORT_SYMBOL(machine_power_off);
46 #endif
49 /******************************************************************************
50 * Stop/pickle callback handling.
51 */
53 /* Ignore multiple shutdown requests. */
54 static int shutting_down = -1;
56 static void __do_suspend(void)
57 {
58 int i, j;
59 suspend_record_t *suspend_record;
61 /* Hmmm... a cleaner interface to suspend/resume blkdevs would be nice. */
62 /* XXX SMH: yes it would :-( */
63 #ifdef CONFIG_XEN_BLKDEV_FRONTEND
64 extern void blkdev_suspend(void);
65 extern void blkdev_resume(void);
66 #else
67 #define blkdev_suspend() do{}while(0)
68 #define blkdev_resume() do{}while(0)
69 #endif
71 #ifdef CONFIG_XEN_NETDEV_FRONTEND
72 extern void netif_suspend(void);
73 extern void netif_resume(void);
74 #else
75 #define netif_suspend() do{}while(0)
76 #define netif_resume() do{}while(0)
77 #endif
79 #ifdef CONFIG_XEN_USB_FRONTEND
80 extern void usbif_resume();
81 #else
82 #define usbif_resume() do{}while(0)
83 #endif
85 #ifdef CONFIG_XEN_BLKDEV_GRANT
86 extern int gnttab_suspend(void);
87 extern int gnttab_resume(void);
88 #else
89 #define gnttab_suspend() do{}while(0)
90 #define gnttab_resume() do{}while(0)
91 #endif
93 extern void time_suspend(void);
94 extern void time_resume(void);
95 extern unsigned long max_pfn;
96 extern unsigned int *pfn_to_mfn_frame_list;
98 suspend_record = (suspend_record_t *)__get_free_page(GFP_KERNEL);
99 if ( suspend_record == NULL )
100 goto out;
102 suspend_record->nr_pfns = max_pfn; /* final number of pfns */
104 __cli();
106 #ifdef __i386__
107 mm_pin_all();
108 kmem_cache_shrink(pgd_cache);
109 #endif
111 netif_suspend();
113 blkdev_suspend();
115 time_suspend();
117 ctrl_if_suspend();
119 irq_suspend();
121 gnttab_suspend();
123 HYPERVISOR_shared_info = (shared_info_t *)empty_zero_page;
124 clear_fixmap(FIX_SHARED_INFO);
126 memcpy(&suspend_record->resume_info, &xen_start_info,
127 sizeof(xen_start_info));
129 HYPERVISOR_suspend(virt_to_machine(suspend_record) >> PAGE_SHIFT);
131 shutting_down = -1;
133 memcpy(&xen_start_info, &suspend_record->resume_info,
134 sizeof(xen_start_info));
136 set_fixmap(FIX_SHARED_INFO, xen_start_info.shared_info);
138 HYPERVISOR_shared_info = (shared_info_t *)fix_to_virt(FIX_SHARED_INFO);
140 memset(empty_zero_page, 0, PAGE_SIZE);
142 for ( i=0, j=0; i < max_pfn; i+=(PAGE_SIZE/sizeof(unsigned long)), j++ )
143 {
144 pfn_to_mfn_frame_list[j] =
145 virt_to_machine(&phys_to_machine_mapping[i]) >> PAGE_SHIFT;
146 }
147 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list =
148 virt_to_machine(pfn_to_mfn_frame_list) >> PAGE_SHIFT;
150 gnttab_resume();
152 irq_resume();
154 ctrl_if_resume();
156 time_resume();
158 blkdev_resume();
160 netif_resume();
162 usbif_resume();
164 __sti();
166 out:
167 if ( suspend_record != NULL )
168 free_page((unsigned long)suspend_record);
169 }
171 static int shutdown_process(void *__unused)
172 {
173 static char *envp[] = { "HOME=/", "TERM=linux",
174 "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
175 static char *restart_argv[] = { "/sbin/shutdown", "-r", "now", NULL };
176 static char *poweroff_argv[] = { "/sbin/halt", "-p", NULL };
178 extern asmlinkage long sys_reboot(int magic1, int magic2,
179 unsigned int cmd, void *arg);
181 daemonize(
182 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
183 "shutdown"
184 #endif
185 );
187 switch ( shutting_down )
188 {
189 case CMSG_SHUTDOWN_POWEROFF:
190 if ( execve("/sbin/halt", poweroff_argv, envp) < 0 )
191 {
192 sys_reboot(LINUX_REBOOT_MAGIC1,
193 LINUX_REBOOT_MAGIC2,
194 LINUX_REBOOT_CMD_POWER_OFF,
195 NULL);
196 }
197 break;
199 case CMSG_SHUTDOWN_REBOOT:
200 if ( execve("/sbin/shutdown", restart_argv, envp) < 0 )
201 {
202 sys_reboot(LINUX_REBOOT_MAGIC1,
203 LINUX_REBOOT_MAGIC2,
204 LINUX_REBOOT_CMD_RESTART,
205 NULL);
206 }
207 break;
208 }
210 shutting_down = -1; /* could try again */
212 return 0;
213 }
215 static void __shutdown_handler(void *unused)
216 {
217 int err;
219 if ( shutting_down != CMSG_SHUTDOWN_SUSPEND )
220 {
221 err = kernel_thread(shutdown_process, NULL, CLONE_FS | CLONE_FILES);
222 if ( err < 0 )
223 printk(KERN_ALERT "Error creating shutdown process!\n");
224 }
225 else
226 {
227 __do_suspend();
228 }
229 }
231 static void shutdown_handler(ctrl_msg_t *msg, unsigned long id)
232 {
233 static DECLARE_WORK(shutdown_work, __shutdown_handler, NULL);
235 if ( msg->subtype == CMSG_SHUTDOWN_SYSRQ )
236 {
237 int sysrq = ((shutdown_sysrq_t *)&msg->msg[0])->key;
239 #ifdef CONFIG_MAGIC_SYSRQ
240 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
241 handle_sysrq(sysrq, NULL, NULL);
242 #else
243 handle_sysrq(sysrq, NULL, NULL, NULL);
244 #endif
245 #endif
246 }
247 else if ( (shutting_down == -1) &&
248 ((msg->subtype == CMSG_SHUTDOWN_POWEROFF) ||
249 (msg->subtype == CMSG_SHUTDOWN_REBOOT) ||
250 (msg->subtype == CMSG_SHUTDOWN_SUSPEND)) )
251 {
252 shutting_down = msg->subtype;
253 schedule_work(&shutdown_work);
254 }
255 else
256 {
257 printk("Ignore spurious shutdown request\n");
258 }
260 ctrl_if_send_response(msg);
261 }
263 static int __init setup_shutdown_event(void)
264 {
265 ctrl_if_register_receiver(CMSG_SHUTDOWN, shutdown_handler, 0);
266 return 0;
267 }
269 __initcall(setup_shutdown_event);