blob: a4c53c172db6440bc9e0892169dd7ec835e012ef [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Adrian Bunk83cc5ed2006-06-25 05:47:41 -070016#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/atomic.h>
18#include <asm/ptrace.h>
19#include <asm/sigp.h>
20
21#include "sclp.h"
22
23
24#ifdef CONFIG_SMP
25/* Signal completion of shutdown process. All CPUs except the first to enter
26 * this function: go to stopped state. First CPU: wait until all other
27 * CPUs are in stopped or check stop state. Afterwards, load special PSW
28 * to indicate completion. */
29static void
30do_load_quiesce_psw(void * __unused)
31{
32 static atomic_t cpuid = ATOMIC_INIT(-1);
33 psw_t quiesce_psw;
34 int cpu;
35
Martin Schwidefsky973bd992006-01-06 00:19:07 -080036 if (atomic_cmpxchg(&cpuid, -1, smp_processor_id()) != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 signal_processor(smp_processor_id(), sigp_stop);
38 /* Wait for all other cpus to enter stopped state */
39 for_each_online_cpu(cpu) {
40 if (cpu == smp_processor_id())
41 continue;
42 while(!smp_cpu_not_running(cpu))
43 cpu_relax();
44 }
45 /* Quiesce the last cpu with the special psw */
46 quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
47 quiesce_psw.addr = 0xfff;
48 __load_psw(quiesce_psw);
49}
50
51/* Shutdown handler. Perform shutdown function on all CPUs. */
52static void
53do_machine_quiesce(void)
54{
55 on_each_cpu(do_load_quiesce_psw, NULL, 0, 0);
56}
57#else
58/* Shutdown handler. Signal completion of shutdown by loading special PSW. */
59static void
60do_machine_quiesce(void)
61{
62 psw_t quiesce_psw;
63
64 quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
65 quiesce_psw.addr = 0xfff;
66 __load_psw(quiesce_psw);
67}
68#endif
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070/* Handler for quiesce event. Start shutdown procedure. */
71static void
72sclp_quiesce_handler(struct evbuf_header *evbuf)
73{
74 _machine_restart = (void *) do_machine_quiesce;
75 _machine_halt = do_machine_quiesce;
76 _machine_power_off = do_machine_quiesce;
77 ctrl_alt_del();
78}
79
80static struct sclp_register sclp_quiesce_event = {
81 .receive_mask = EvTyp_SigQuiesce_Mask,
82 .receiver_fn = sclp_quiesce_handler
83};
84
85/* Initialize quiesce driver. */
86static int __init
87sclp_quiesce_init(void)
88{
89 int rc;
90
91 rc = sclp_register(&sclp_quiesce_event);
92 if (rc)
93 printk(KERN_WARNING "sclp: could not register quiesce handler "
94 "(rc=%d)\n", rc);
95 return rc;
96}
97
98module_init(sclp_quiesce_init);