blob: 32004aae95c1738629b74c437ed9303d8f32197d [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/module.h>
11#include <linux/types.h>
12#include <linux/cpumask.h>
13#include <linux/smp.h>
14#include <linux/init.h>
Adrian Bunk83cc5ed2006-06-25 05:47:41 -070015#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#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. */
28static void
29do_load_quiesce_psw(void * __unused)
30{
31 static atomic_t cpuid = ATOMIC_INIT(-1);
32 psw_t quiesce_psw;
33 int cpu;
34
Martin Schwidefsky973bd992006-01-06 00:19:07 -080035 if (atomic_cmpxchg(&cpuid, -1, smp_processor_id()) != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 signal_processor(smp_processor_id(), sigp_stop);
37 /* Wait for all other cpus to enter stopped state */
38 for_each_online_cpu(cpu) {
39 if (cpu == smp_processor_id())
40 continue;
41 while(!smp_cpu_not_running(cpu))
42 cpu_relax();
43 }
44 /* Quiesce the last cpu with the special psw */
45 quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
46 quiesce_psw.addr = 0xfff;
47 __load_psw(quiesce_psw);
48}
49
50/* Shutdown handler. Perform shutdown function on all CPUs. */
51static void
52do_machine_quiesce(void)
53{
54 on_each_cpu(do_load_quiesce_psw, NULL, 0, 0);
55}
56#else
57/* Shutdown handler. Signal completion of shutdown by loading special PSW. */
58static void
59do_machine_quiesce(void)
60{
61 psw_t quiesce_psw;
62
63 quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
64 quiesce_psw.addr = 0xfff;
65 __load_psw(quiesce_psw);
66}
67#endif
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/* Handler for quiesce event. Start shutdown procedure. */
70static void
71sclp_quiesce_handler(struct evbuf_header *evbuf)
72{
73 _machine_restart = (void *) do_machine_quiesce;
74 _machine_halt = do_machine_quiesce;
75 _machine_power_off = do_machine_quiesce;
76 ctrl_alt_del();
77}
78
79static struct sclp_register sclp_quiesce_event = {
80 .receive_mask = EvTyp_SigQuiesce_Mask,
81 .receiver_fn = sclp_quiesce_handler
82};
83
84/* Initialize quiesce driver. */
85static int __init
86sclp_quiesce_init(void)
87{
88 int rc;
89
90 rc = sclp_register(&sclp_quiesce_event);
91 if (rc)
92 printk(KERN_WARNING "sclp: could not register quiesce handler "
93 "(rc=%d)\n", rc);
94 return rc;
95}
96
97module_init(sclp_quiesce_init);