1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *     signal quiesce handler
4  *
5  *  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/types.h>
11 #include <linux/cpumask.h>
12 #include <linux/smp.h>
13 #include <linux/init.h>
14 #include <linux/reboot.h>
15 #include <linux/atomic.h>
16 #include <asm/ptrace.h>
17 #include <asm/smp.h>
18 
19 #include "sclp.h"
20 
21 /* Shutdown handler. Signal completion of shutdown by loading special PSW. */
do_machine_quiesce(void)22 static void do_machine_quiesce(void)
23 {
24 	psw_t quiesce_psw;
25 
26 	smp_send_stop();
27 	quiesce_psw.mask =
28 		PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA | PSW_MASK_WAIT;
29 	quiesce_psw.addr = 0xfff;
30 	__load_psw(quiesce_psw);
31 }
32 
33 /* Handler for quiesce event. Start shutdown procedure. */
sclp_quiesce_handler(struct evbuf_header * evbuf)34 static void sclp_quiesce_handler(struct evbuf_header *evbuf)
35 {
36 	_machine_restart = (void *) do_machine_quiesce;
37 	_machine_halt = do_machine_quiesce;
38 	_machine_power_off = do_machine_quiesce;
39 	ctrl_alt_del();
40 }
41 
42 static struct sclp_register sclp_quiesce_event = {
43 	.receive_mask = EVTYP_SIGQUIESCE_MASK,
44 	.receiver_fn = sclp_quiesce_handler,
45 };
46 
47 /* Initialize quiesce driver. */
sclp_quiesce_init(void)48 static int __init sclp_quiesce_init(void)
49 {
50 	return sclp_register(&sclp_quiesce_event);
51 }
52 device_initcall(sclp_quiesce_init);
53