ia64/xen-unstable

changeset 2212:9840fcd30668

bitkeeper revision 1.1159.17.21 (411baa1dkWXzaVHGnr6yk4SeGTJAHA)

Merge 2.4/2.6 shutdown/suspend control message handling code.
author cl349@freefall.cl.cam.ac.uk
date Thu Aug 12 17:34:21 2004 +0000 (2004-08-12)
parents 8d02fbe8e19e
children 8481b2eee50a
files linux-2.4.26-xen-sparse/arch/xen/kernel/setup.c linux-2.6.7-xen-sparse/arch/xen/i386/kernel/time.c linux-2.6.7-xen-sparse/arch/xen/kernel/reboot.c linux-2.6.7-xen-sparse/include/asm-xen/asm-i386/mach-xen/irq_vectors.h
line diff
     1.1 --- a/linux-2.4.26-xen-sparse/arch/xen/kernel/setup.c	Thu Aug 12 16:58:27 2004 +0000
     1.2 +++ b/linux-2.4.26-xen-sparse/arch/xen/kernel/setup.c	Thu Aug 12 17:34:21 2004 +0000
     1.3 @@ -1184,173 +1184,3 @@ void __init cpu_init (void)
     1.4      current->used_math = 0;
     1.5      stts();
     1.6  }
     1.7 -
     1.8 -
     1.9 -/******************************************************************************
    1.10 - * Stop/pickle callback handling.
    1.11 - */
    1.12 -
    1.13 -#include <asm/suspend.h>
    1.14 -
    1.15 -/* Ignore multiple shutdown requests. */
    1.16 -static int shutting_down = -1;
    1.17 -
    1.18 -static void __do_suspend(void)
    1.19 -{
    1.20 -    int i,j;
    1.21 -    /* Hmmm... a cleaner interface to suspend/resume blkdevs would be nice. */
    1.22 -    extern void blkdev_suspend(void);
    1.23 -    extern void blkdev_resume(void);
    1.24 -    extern void netif_suspend(void);
    1.25 -    extern void netif_resume(void);    
    1.26 -    extern void time_suspend(void);
    1.27 -    extern void time_resume(void);
    1.28 -
    1.29 -    suspend_record_t *suspend_record     = NULL;
    1.30 -
    1.31 -    if ( (suspend_record = (suspend_record_t *)__get_free_page(GFP_KERNEL))
    1.32 -         == NULL )
    1.33 -        goto out;
    1.34 -
    1.35 -    suspend_record->nr_pfns = max_pfn; /* final number of pfns */
    1.36 -
    1.37 -    __cli();
    1.38 -
    1.39 -    netif_suspend();
    1.40 -
    1.41 -    blkdev_suspend();
    1.42 -
    1.43 -    time_suspend();
    1.44 -
    1.45 -    ctrl_if_suspend();
    1.46 -
    1.47 -    irq_suspend();
    1.48 -
    1.49 -    HYPERVISOR_shared_info = (shared_info_t *)empty_zero_page;
    1.50 -    clear_fixmap(FIX_SHARED_INFO);
    1.51 -
    1.52 -    memcpy(&suspend_record->resume_info, &start_info, sizeof(start_info));
    1.53 -
    1.54 -    HYPERVISOR_suspend(virt_to_machine(suspend_record) >> PAGE_SHIFT);
    1.55 -
    1.56 -    shutting_down = -1; 
    1.57 -
    1.58 -    memcpy(&start_info, &suspend_record->resume_info, sizeof(start_info));
    1.59 -
    1.60 -    set_fixmap(FIX_SHARED_INFO, start_info.shared_info);
    1.61 -
    1.62 -    HYPERVISOR_shared_info = (shared_info_t *)fix_to_virt(FIX_SHARED_INFO);
    1.63 -
    1.64 -    memset(empty_zero_page, 0, PAGE_SIZE);
    1.65 -
    1.66 -    for ( i=0, j=0; i < max_pfn; i+=(PAGE_SIZE/sizeof(unsigned long)), j++ )
    1.67 -    {	
    1.68 -        pfn_to_mfn_frame_list[j] = 
    1.69 -            virt_to_machine(&phys_to_machine_mapping[i]) >> PAGE_SHIFT;
    1.70 -    }
    1.71 -    HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list =
    1.72 -	virt_to_machine(pfn_to_mfn_frame_list) >> PAGE_SHIFT;
    1.73 -
    1.74 -
    1.75 -    irq_resume();
    1.76 -
    1.77 -    ctrl_if_resume();
    1.78 -
    1.79 -    time_resume();
    1.80 -
    1.81 -    blkdev_resume();
    1.82 -
    1.83 -    netif_resume();
    1.84 -
    1.85 -    __sti();
    1.86 -
    1.87 -
    1.88 - out:
    1.89 -    if ( suspend_record != NULL )
    1.90 -        free_page((unsigned long)suspend_record);
    1.91 -}
    1.92 -
    1.93 -static int shutdown_process(void *__unused)
    1.94 -{
    1.95 -    static char *envp[] = { "HOME=/", "TERM=linux", 
    1.96 -                            "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
    1.97 -    static char *restart_argv[]  = { "/sbin/shutdown", "-r", "now", NULL };
    1.98 -    static char *poweroff_argv[] = { "/sbin/halt",     "-p",        NULL };
    1.99 -
   1.100 -    extern asmlinkage long sys_reboot(int magic1, int magic2,
   1.101 -                                      unsigned int cmd, void *arg);
   1.102 -
   1.103 -    daemonize();
   1.104 -
   1.105 -    switch ( shutting_down )
   1.106 -    {
   1.107 -    case CMSG_SHUTDOWN_POWEROFF:
   1.108 -        if ( execve("/sbin/halt", poweroff_argv, envp) < 0 )
   1.109 -        {
   1.110 -            sys_reboot(LINUX_REBOOT_MAGIC1,
   1.111 -                       LINUX_REBOOT_MAGIC2,
   1.112 -                       LINUX_REBOOT_CMD_POWER_OFF,
   1.113 -                       NULL);
   1.114 -        }
   1.115 -        break;
   1.116 -
   1.117 -    case CMSG_SHUTDOWN_REBOOT:
   1.118 -        if ( execve("/sbin/shutdown", restart_argv, envp) < 0 )
   1.119 -        {
   1.120 -            sys_reboot(LINUX_REBOOT_MAGIC1,
   1.121 -                       LINUX_REBOOT_MAGIC2,
   1.122 -                       LINUX_REBOOT_CMD_RESTART,
   1.123 -                       NULL);
   1.124 -        }
   1.125 -        break;
   1.126 -    }
   1.127 -
   1.128 -    return 0;
   1.129 -}
   1.130 -
   1.131 -static void __shutdown_handler(void *unused)
   1.132 -{
   1.133 -    int err;
   1.134 -
   1.135 -    if ( shutting_down != CMSG_SHUTDOWN_SUSPEND )
   1.136 -    {
   1.137 -        err = kernel_thread(shutdown_process, NULL, CLONE_FS | CLONE_FILES);
   1.138 -        if ( err < 0 )
   1.139 -            printk(KERN_ALERT "Error creating shutdown process!\n");
   1.140 -        else
   1.141 -            shutting_down = -1; /* could try again */
   1.142 -    }
   1.143 -    else
   1.144 -    {
   1.145 -        __do_suspend();
   1.146 -    }
   1.147 -}
   1.148 -
   1.149 -static void shutdown_handler(ctrl_msg_t *msg, unsigned long id)
   1.150 -{
   1.151 -    static struct tq_struct shutdown_tq;
   1.152 -
   1.153 -    if ( (shutting_down == -1) &&
   1.154 -         ((msg->subtype == CMSG_SHUTDOWN_POWEROFF) ||
   1.155 -          (msg->subtype == CMSG_SHUTDOWN_REBOOT) ||
   1.156 -          (msg->subtype == CMSG_SHUTDOWN_SUSPEND)) )
   1.157 -    {
   1.158 -        shutting_down = msg->subtype;
   1.159 -        shutdown_tq.routine = __shutdown_handler;
   1.160 -        schedule_task(&shutdown_tq);
   1.161 -    }
   1.162 -    else
   1.163 -    {
   1.164 -	printk("Ignore spurious shutdown request\n");
   1.165 -    }
   1.166 -
   1.167 -    ctrl_if_send_response(msg);
   1.168 -}
   1.169 -
   1.170 -static int __init setup_shutdown_event(void)
   1.171 -{
   1.172 -    ctrl_if_register_receiver(CMSG_SHUTDOWN, shutdown_handler, 0);
   1.173 -    return 0;
   1.174 -}
   1.175 -
   1.176 -__initcall(setup_shutdown_event);
     2.1 --- a/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/time.c	Thu Aug 12 16:58:27 2004 +0000
     2.2 +++ b/linux-2.6.7-xen-sparse/arch/xen/i386/kernel/time.c	Thu Aug 12 17:34:21 2004 +0000
     2.3 @@ -510,7 +510,7 @@ unsigned long get_cmos_time(void)
     2.4  
     2.5  static long clock_cmos_diff;
     2.6  
     2.7 -static int time_suspend(struct sys_device *dev, u32 state)
     2.8 +static int __time_suspend(struct sys_device *dev, u32 state)
     2.9  {
    2.10  	/*
    2.11  	 * Estimate time zone so that set_time can update the clock
    2.12 @@ -520,7 +520,7 @@ static int time_suspend(struct sys_devic
    2.13  	return 0;
    2.14  }
    2.15  
    2.16 -static int time_resume(struct sys_device *dev)
    2.17 +static int __time_resume(struct sys_device *dev)
    2.18  {
    2.19  	unsigned long sec = get_cmos_time() + clock_cmos_diff;
    2.20  	write_seqlock_irq(&xtime_lock);
    2.21 @@ -531,8 +531,8 @@ static int time_resume(struct sys_device
    2.22  }
    2.23  
    2.24  static struct sysdev_class pit_sysclass = {
    2.25 -	.resume = time_resume,
    2.26 -	.suspend = time_suspend,
    2.27 +	.resume = __time_resume,
    2.28 +	.suspend = __time_suspend,
    2.29  	set_kset_name("pit"),
    2.30  };
    2.31  
    2.32 @@ -647,6 +647,25 @@ int set_timeout_timer(void)
    2.33  	return ret;
    2.34  }
    2.35  
    2.36 +void time_suspend(void)
    2.37 +{
    2.38 +}
    2.39 +
    2.40 +void time_resume(void)
    2.41 +{
    2.42 +    unsigned long flags;
    2.43 +    write_lock_irqsave(&xtime_lock, flags);
    2.44 +    /* Get timebases for new environment. */ 
    2.45 +    __get_time_values_from_xen();
    2.46 +    /* Reset our own concept of passage of system time. */
    2.47 +    processed_system_time = shadow_system_time;
    2.48 +    /* Accept a warp in UTC (wall-clock) time. */
    2.49 +    last_seen_tv.tv_sec = 0;
    2.50 +    /* Make sure we resync UTC time with Xen on next timer interrupt. */
    2.51 +    last_update_from_xen = 0;
    2.52 +    write_unlock_irqrestore(&xtime_lock, flags);
    2.53 +}
    2.54 +
    2.55  /*
    2.56   * /proc/sys/xen: This really belongs in another file. It can stay here for
    2.57   * now however.
     3.1 --- a/linux-2.6.7-xen-sparse/arch/xen/kernel/reboot.c	Thu Aug 12 16:58:27 2004 +0000
     3.2 +++ b/linux-2.6.7-xen-sparse/arch/xen/kernel/reboot.c	Thu Aug 12 17:34:21 2004 +0000
     3.3 @@ -1,8 +1,19 @@
     3.4  
     3.5 +#define __KERNEL_SYSCALLS__
     3.6 +static int errno;
     3.7 +#include <linux/errno.h>
     3.8  #include <linux/version.h>
     3.9 +#include <linux/kernel.h>
    3.10 +#include <linux/mm.h>
    3.11 +#include <linux/unistd.h>
    3.12  #include <linux/module.h>
    3.13  #include <linux/reboot.h>
    3.14 +#include <asm/irq.h>
    3.15 +#include <asm/mmu_context.h>
    3.16 +#include <asm-xen/ctrl_if.h>
    3.17  #include <asm-xen/hypervisor.h>
    3.18 +#include <asm-xen/hypervisor-ifs/dom0_ops.h>
    3.19 +#include <asm-xen/suspend.h>
    3.20  
    3.21  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    3.22  int reboot_thru_bios = 0;	/* for dmi_scan.c */
    3.23 @@ -40,3 +51,188 @@ void machine_power_off(void)
    3.24  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    3.25  EXPORT_SYMBOL(machine_power_off);
    3.26  #endif
    3.27 +
    3.28 +
    3.29 +
    3.30 +/******************************************************************************
    3.31 + * Stop/pickle callback handling.
    3.32 + */
    3.33 +
    3.34 +#include <asm/suspend.h>
    3.35 +
    3.36 +/* Ignore multiple shutdown requests. */
    3.37 +static int shutting_down = -1;
    3.38 +
    3.39 +static void __do_suspend(void)
    3.40 +{
    3.41 +    int i,j;
    3.42 +    /* Hmmm... a cleaner interface to suspend/resume blkdevs would be nice. */
    3.43 +    extern void blkdev_suspend(void);
    3.44 +    extern void blkdev_resume(void);
    3.45 +    extern void netif_suspend(void);
    3.46 +    extern void netif_resume(void);    
    3.47 +    extern void time_suspend(void);
    3.48 +    extern void time_resume(void);
    3.49 +    extern unsigned long max_pfn;
    3.50 +    extern unsigned long *pfn_to_mfn_frame_list;
    3.51 +
    3.52 +    suspend_record_t *suspend_record     = NULL;
    3.53 +
    3.54 +    if ( (suspend_record = (suspend_record_t *)__get_free_page(GFP_KERNEL))
    3.55 +         == NULL )
    3.56 +        goto out;
    3.57 +
    3.58 +    suspend_record->nr_pfns = max_pfn; /* final number of pfns */
    3.59 +
    3.60 +    __cli();
    3.61 +
    3.62 +    netif_suspend();
    3.63 +
    3.64 +    blkdev_suspend();
    3.65 +
    3.66 +    time_suspend();
    3.67 +
    3.68 +    ctrl_if_suspend();
    3.69 +
    3.70 +    irq_suspend();
    3.71 +
    3.72 +    HYPERVISOR_shared_info = (shared_info_t *)empty_zero_page;
    3.73 +    clear_fixmap(FIX_SHARED_INFO);
    3.74 +
    3.75 +    memcpy(&suspend_record->resume_info, &start_info, sizeof(start_info));
    3.76 +
    3.77 +    HYPERVISOR_suspend(virt_to_machine(suspend_record) >> PAGE_SHIFT);
    3.78 +
    3.79 +    shutting_down = -1; 
    3.80 +
    3.81 +    memcpy(&start_info, &suspend_record->resume_info, sizeof(start_info));
    3.82 +
    3.83 +    set_fixmap(FIX_SHARED_INFO, start_info.shared_info);
    3.84 +
    3.85 +    HYPERVISOR_shared_info = (shared_info_t *)fix_to_virt(FIX_SHARED_INFO);
    3.86 +
    3.87 +    memset(empty_zero_page, 0, PAGE_SIZE);
    3.88 +
    3.89 +    for ( i=0, j=0; i < max_pfn; i+=(PAGE_SIZE/sizeof(unsigned long)), j++ )
    3.90 +    {
    3.91 +        pfn_to_mfn_frame_list[j] = 
    3.92 +            virt_to_machine(&phys_to_machine_mapping[i]) >> PAGE_SHIFT;
    3.93 +    }
    3.94 +    HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list =
    3.95 +        virt_to_machine(pfn_to_mfn_frame_list) >> PAGE_SHIFT;
    3.96 +
    3.97 +
    3.98 +    irq_resume();
    3.99 +
   3.100 +    ctrl_if_resume();
   3.101 +
   3.102 +    time_resume();
   3.103 +
   3.104 +    blkdev_resume();
   3.105 +
   3.106 +    netif_resume();
   3.107 +
   3.108 +    __sti();
   3.109 +
   3.110 +
   3.111 + out:
   3.112 +    if ( suspend_record != NULL )
   3.113 +        free_page((unsigned long)suspend_record);
   3.114 +}
   3.115 +
   3.116 +static int shutdown_process(void *__unused)
   3.117 +{
   3.118 +    static char *envp[] = { "HOME=/", "TERM=linux", 
   3.119 +                            "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
   3.120 +    static char *restart_argv[]  = { "/sbin/shutdown", "-r", "now", NULL };
   3.121 +    static char *poweroff_argv[] = { "/sbin/halt",     "-p",        NULL };
   3.122 +
   3.123 +    extern asmlinkage long sys_reboot(int magic1, int magic2,
   3.124 +                                      unsigned int cmd, void *arg);
   3.125 +
   3.126 +    daemonize(
   3.127 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
   3.128 +        "shutdown"
   3.129 +#endif
   3.130 +        );
   3.131 +
   3.132 +    switch ( shutting_down )
   3.133 +    {
   3.134 +    case CMSG_SHUTDOWN_POWEROFF:
   3.135 +        if ( execve("/sbin/halt", poweroff_argv, envp) < 0 )
   3.136 +        {
   3.137 +            sys_reboot(LINUX_REBOOT_MAGIC1,
   3.138 +                       LINUX_REBOOT_MAGIC2,
   3.139 +                       LINUX_REBOOT_CMD_POWER_OFF,
   3.140 +                       NULL);
   3.141 +        }
   3.142 +        break;
   3.143 +
   3.144 +    case CMSG_SHUTDOWN_REBOOT:
   3.145 +        if ( execve("/sbin/shutdown", restart_argv, envp) < 0 )
   3.146 +        {
   3.147 +            sys_reboot(LINUX_REBOOT_MAGIC1,
   3.148 +                       LINUX_REBOOT_MAGIC2,
   3.149 +                       LINUX_REBOOT_CMD_RESTART,
   3.150 +                       NULL);
   3.151 +        }
   3.152 +        break;
   3.153 +    }
   3.154 +
   3.155 +    shutting_down = -1; /* could try again */
   3.156 +
   3.157 +    return 0;
   3.158 +}
   3.159 +
   3.160 +static void __shutdown_handler(void *unused)
   3.161 +{
   3.162 +    int err;
   3.163 +
   3.164 +    if ( shutting_down != CMSG_SHUTDOWN_SUSPEND )
   3.165 +    {
   3.166 +        err = kernel_thread(shutdown_process, NULL, CLONE_FS | CLONE_FILES);
   3.167 +        if ( err < 0 )
   3.168 +            printk(KERN_ALERT "Error creating shutdown process!\n");
   3.169 +    }
   3.170 +    else
   3.171 +    {
   3.172 +        __do_suspend();
   3.173 +    }
   3.174 +}
   3.175 +
   3.176 +static void shutdown_handler(ctrl_msg_t *msg, unsigned long id)
   3.177 +{
   3.178 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
   3.179 +    static DECLARE_WORK(shutdown_work, __shutdown_handler, NULL);
   3.180 +#else
   3.181 +    static struct tq_struct shutdown_tq;
   3.182 +#endif
   3.183 +
   3.184 +    if ( (shutting_down == -1) &&
   3.185 +         ((msg->subtype == CMSG_SHUTDOWN_POWEROFF) ||
   3.186 +          (msg->subtype == CMSG_SHUTDOWN_REBOOT) ||
   3.187 +          (msg->subtype == CMSG_SHUTDOWN_SUSPEND)) )
   3.188 +    {
   3.189 +        shutting_down = msg->subtype;
   3.190 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
   3.191 +        schedule_work(&shutdown_work);
   3.192 +#else
   3.193 +        shutdown_tq.routine = __shutdown_handler;
   3.194 +        schedule_task(&shutdown_tq);
   3.195 +#endif
   3.196 +    }
   3.197 +    else
   3.198 +    {
   3.199 +        printk("Ignore spurious shutdown request\n");
   3.200 +    }
   3.201 +
   3.202 +    ctrl_if_send_response(msg);
   3.203 +}
   3.204 +
   3.205 +static int __init setup_shutdown_event(void)
   3.206 +{
   3.207 +    ctrl_if_register_receiver(CMSG_SHUTDOWN, shutdown_handler, 0);
   3.208 +    return 0;
   3.209 +}
   3.210 +
   3.211 +__initcall(setup_shutdown_event);
     4.1 --- a/linux-2.6.7-xen-sparse/include/asm-xen/asm-i386/mach-xen/irq_vectors.h	Thu Aug 12 16:58:27 2004 +0000
     4.2 +++ b/linux-2.6.7-xen-sparse/include/asm-xen/asm-i386/mach-xen/irq_vectors.h	Thu Aug 12 17:34:21 2004 +0000
     4.3 @@ -140,6 +140,9 @@ extern int  bind_virq_to_irq(int virq);
     4.4  extern void unbind_virq_from_irq(int virq);
     4.5  extern int  bind_evtchn_to_irq(int evtchn);
     4.6  extern void unbind_evtchn_from_irq(int evtchn);
     4.7 +
     4.8 +extern void irq_suspend(void);
     4.9 +extern void irq_resume(void);
    4.10  #endif /* __ASSEMBLY__ */
    4.11  
    4.12  #endif /* _ASM_IRQ_VECTORS_H */