This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / s390 / char / sclp_quiesce.c
1 /*
2  *  drivers/s390/char/sclp_quiesce.c
3  *     signal quiesce handler
4  *
5  *  (C) Copyright IBM Corp. 1999,2004
6  *  Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
7  *             Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
8  */
9
10 #include <linux/config.h>
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/cpumask.h>
14 #include <linux/smp.h>
15 #include <linux/init.h>
16 #include <asm/atomic.h>
17 #include <asm/ptrace.h>
18 #include <asm/sigp.h>
19
20 #include "sclp.h"
21
22
23 #ifdef CONFIG_SMP
24 /* Signal completion of shutdown process. All CPUs except the first to enter
25  * this function: go to stopped state. First CPU: wait until all other
26  * CPUs are in stopped or check stop state. Afterwards, load special PSW
27  * to indicate completion. */
28 static void
29 do_load_quiesce_psw(void * __unused)
30 {
31         static atomic_t cpuid = ATOMIC_INIT(-1);
32         psw_t quiesce_psw;
33         __u32 status;
34         int i;
35
36         if (atomic_compare_and_swap(-1, smp_processor_id(), &cpuid))
37                 signal_processor(smp_processor_id(), sigp_stop);
38         /* Wait for all other cpus to enter stopped state */
39         i = 1;
40         while (i < NR_CPUS) {
41                 if (!cpu_online(i)) {
42                         i++;
43                         continue;
44                 }
45                 switch (signal_processor_ps(&status, 0, i, sigp_sense)) {
46                 case sigp_order_code_accepted:
47                 case sigp_status_stored:
48                         /* Check for stopped and check stop state */
49                         if (status & 0x50)
50                                 i++;
51                         break;
52                 case sigp_busy:
53                         break;
54                 case sigp_not_operational:
55                         i++;
56                         break;
57                 }
58         }
59         /* Quiesce the last cpu with the special psw */
60         quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
61         quiesce_psw.addr = 0xfff;
62         __load_psw(quiesce_psw);
63 }
64
65 /* Shutdown handler. Perform shutdown function on all CPUs. */
66 static void
67 do_machine_quiesce(void)
68 {
69         on_each_cpu(do_load_quiesce_psw, NULL, 0, 0);
70 }
71 #else
72 /* Shutdown handler. Signal completion of shutdown by loading special PSW. */
73 static void
74 do_machine_quiesce(void)
75 {
76         psw_t quiesce_psw;
77
78         quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
79         quiesce_psw.addr = 0xfff;
80         __load_psw(quiesce_psw);
81 }
82 #endif
83
84 extern void ctrl_alt_del(void);
85
86 /* Handler for quiesce event. Start shutdown procedure. */
87 static void
88 sclp_quiesce_handler(struct evbuf_header *evbuf)
89 {
90         _machine_restart = (void *) do_machine_quiesce;
91         _machine_halt = do_machine_quiesce;
92         _machine_power_off = do_machine_quiesce;
93         ctrl_alt_del();
94 }
95
96 static struct sclp_register sclp_quiesce_event = {
97         .receive_mask = EvTyp_SigQuiesce_Mask,
98         .receiver_fn = sclp_quiesce_handler
99 };
100
101 /* Initialize quiesce driver. */
102 static int __init
103 sclp_quiesce_init(void)
104 {
105         int rc;
106
107         rc = sclp_register(&sclp_quiesce_event);
108         if (rc)
109                 printk(KERN_WARNING "sclp: could not register quiesce handler "
110                        "(rc=%d)\n", rc);
111         return rc;
112 }
113
114 module_init(sclp_quiesce_init);