direct-io.hg

view linux-2.6.9-xen-sparse/arch/xen/kernel/reboot.c @ 2821:724449a888fe

bitkeeper revision 1.1159.1.332 (41874e954CLIDA2J3phVFD2RnzVTpA)

Clean up public XenLinux header files. Now accessible from userspace as
#include <xen/linux...>
Got rid of the linux-xen-sparse symlink as it's no longer needed.
author kaf24@freefall.cl.cam.ac.uk
date Tue Nov 02 09:08:37 2004 +0000 (2004-11-02)
parents 3f929065a1d1
children 3772ff7c4023
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 <asm/irq.h>
12 #include <asm/mmu_context.h>
13 #include <asm-xen/ctrl_if.h>
14 #include <asm-xen/hypervisor.h>
15 #include <asm-xen/xen-public/dom0_ops.h>
16 #include <asm-xen/linux-public/suspend.h>
17 #include <asm-xen/queues.h>
19 void machine_restart(char * __unused)
20 {
21 /* We really want to get pending console data out before we die. */
22 extern void xencons_force_flush(void);
23 xencons_force_flush();
24 HYPERVISOR_reboot();
25 }
27 void machine_halt(void)
28 {
29 machine_power_off();
30 }
32 void machine_power_off(void)
33 {
34 /* We really want to get pending console data out before we die. */
35 extern void xencons_force_flush(void);
36 xencons_force_flush();
37 HYPERVISOR_shutdown();
38 }
40 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
41 int reboot_thru_bios = 0; /* for dmi_scan.c */
42 EXPORT_SYMBOL(machine_restart);
43 EXPORT_SYMBOL(machine_halt);
44 EXPORT_SYMBOL(machine_power_off);
45 #endif
48 /******************************************************************************
49 * Stop/pickle callback handling.
50 */
52 #include <asm/suspend.h>
54 /* Ignore multiple shutdown requests. */
55 static int shutting_down = -1;
57 static void __do_suspend(void)
58 {
59 int i, j;
60 suspend_record_t *suspend_record;
62 /* Hmmm... a cleaner interface to suspend/resume blkdevs would be nice. */
63 /* XXX SMH: yes it would :-( */
64 #ifdef CONFIG_XEN_BLKDEV_FRONTEND
65 extern void blkdev_suspend(void);
66 extern void blkdev_resume(void);
67 #else
68 #define blkdev_suspend() do{}while(0)
69 #define blkdev_resume() do{}while(0)
70 #endif
72 #ifdef CONFIG_XEN_NETDEV_FRONTEND
73 extern void netif_suspend(void);
74 extern void netif_resume(void);
75 #else
76 #define netif_suspend() do{}while(0)
77 #define netif_resume() do{}while(0)
78 #endif
80 extern void time_suspend(void);
81 extern void time_resume(void);
82 extern unsigned long max_pfn;
83 extern unsigned long *pfn_to_mfn_frame_list;
85 suspend_record = (suspend_record_t *)__get_free_page(GFP_KERNEL);
86 if ( suspend_record == NULL )
87 goto out;
89 suspend_record->nr_pfns = max_pfn; /* final number of pfns */
91 __cli();
93 netif_suspend();
95 blkdev_suspend();
97 time_suspend();
99 ctrl_if_suspend();
101 irq_suspend();
103 HYPERVISOR_shared_info = (shared_info_t *)empty_zero_page;
104 clear_fixmap(FIX_SHARED_INFO);
106 memcpy(&suspend_record->resume_info, &xen_start_info, sizeof(xen_start_info));
108 HYPERVISOR_suspend(virt_to_machine(suspend_record) >> PAGE_SHIFT);
110 HYPERVISOR_vm_assist(VMASST_CMD_enable,
111 VMASST_TYPE_4gb_segments);
112 #ifdef CONFIG_XEN_WRITABLE_PAGETABLES
113 HYPERVISOR_vm_assist(VMASST_CMD_enable,
114 VMASST_TYPE_writable_pagetables);
115 #endif
117 shutting_down = -1;
119 memcpy(&xen_start_info, &suspend_record->resume_info, sizeof(xen_start_info));
121 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
122 set_fixmap_ma(FIX_SHARED_INFO, xen_start_info.shared_info);
123 #else
124 set_fixmap(FIX_SHARED_INFO, xen_start_info.shared_info);
125 #endif
127 HYPERVISOR_shared_info = (shared_info_t *)fix_to_virt(FIX_SHARED_INFO);
129 memset(empty_zero_page, 0, PAGE_SIZE);
131 for ( i=0, j=0; i < max_pfn; i+=(PAGE_SIZE/sizeof(unsigned long)), j++ )
132 {
133 pfn_to_mfn_frame_list[j] =
134 virt_to_machine(&phys_to_machine_mapping[i]) >> PAGE_SHIFT;
135 }
136 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list =
137 virt_to_machine(pfn_to_mfn_frame_list) >> PAGE_SHIFT;
140 irq_resume();
142 ctrl_if_resume();
144 time_resume();
146 blkdev_resume();
148 netif_resume();
150 __sti();
152 out:
153 if ( suspend_record != NULL )
154 free_page((unsigned long)suspend_record);
155 }
157 static int shutdown_process(void *__unused)
158 {
159 static char *envp[] = { "HOME=/", "TERM=linux",
160 "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
161 static char *restart_argv[] = { "/sbin/shutdown", "-r", "now", NULL };
162 static char *poweroff_argv[] = { "/sbin/halt", "-p", NULL };
164 extern asmlinkage long sys_reboot(int magic1, int magic2,
165 unsigned int cmd, void *arg);
167 daemonize(
168 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
169 "shutdown"
170 #endif
171 );
173 switch ( shutting_down )
174 {
175 case CMSG_SHUTDOWN_POWEROFF:
176 if ( execve("/sbin/halt", poweroff_argv, envp) < 0 )
177 {
178 sys_reboot(LINUX_REBOOT_MAGIC1,
179 LINUX_REBOOT_MAGIC2,
180 LINUX_REBOOT_CMD_POWER_OFF,
181 NULL);
182 }
183 break;
185 case CMSG_SHUTDOWN_REBOOT:
186 if ( execve("/sbin/shutdown", restart_argv, envp) < 0 )
187 {
188 sys_reboot(LINUX_REBOOT_MAGIC1,
189 LINUX_REBOOT_MAGIC2,
190 LINUX_REBOOT_CMD_RESTART,
191 NULL);
192 }
193 break;
194 }
196 shutting_down = -1; /* could try again */
198 return 0;
199 }
201 static void __shutdown_handler(void *unused)
202 {
203 int err;
205 if ( shutting_down != CMSG_SHUTDOWN_SUSPEND )
206 {
207 err = kernel_thread(shutdown_process, NULL, CLONE_FS | CLONE_FILES);
208 if ( err < 0 )
209 printk(KERN_ALERT "Error creating shutdown process!\n");
210 }
211 else
212 {
213 __do_suspend();
214 }
215 }
217 static void shutdown_handler(ctrl_msg_t *msg, unsigned long id)
218 {
219 static DECLARE_WORK(shutdown_work, __shutdown_handler, NULL);
221 if ( (shutting_down == -1) &&
222 ((msg->subtype == CMSG_SHUTDOWN_POWEROFF) ||
223 (msg->subtype == CMSG_SHUTDOWN_REBOOT) ||
224 (msg->subtype == CMSG_SHUTDOWN_SUSPEND)) )
225 {
226 shutting_down = msg->subtype;
227 schedule_work(&shutdown_work);
228 }
229 else
230 {
231 printk("Ignore spurious shutdown request\n");
232 }
234 ctrl_if_send_response(msg);
235 }
237 static int __init setup_shutdown_event(void)
238 {
239 ctrl_if_register_receiver(CMSG_SHUTDOWN, shutdown_handler, 0);
240 return 0;
241 }
243 __initcall(setup_shutdown_event);