xref: /openbmc/linux/drivers/s390/char/sclp_quiesce.c (revision 726bd223)
1 /*
2  *     signal quiesce handler
3  *
4  *  Copyright IBM Corp. 1999, 2004
5  *  Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
6  *             Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
7  */
8 
9 #include <linux/types.h>
10 #include <linux/cpumask.h>
11 #include <linux/smp.h>
12 #include <linux/init.h>
13 #include <linux/reboot.h>
14 #include <linux/atomic.h>
15 #include <asm/ptrace.h>
16 #include <asm/smp.h>
17 
18 #include "sclp.h"
19 
20 static void (*old_machine_restart)(char *);
21 static void (*old_machine_halt)(void);
22 static void (*old_machine_power_off)(void);
23 
24 /* Shutdown handler. Signal completion of shutdown by loading special PSW. */
25 static void do_machine_quiesce(void)
26 {
27 	psw_t quiesce_psw;
28 
29 	smp_send_stop();
30 	quiesce_psw.mask =
31 		PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA | PSW_MASK_WAIT;
32 	quiesce_psw.addr = 0xfff;
33 	__load_psw(quiesce_psw);
34 }
35 
36 /* Handler for quiesce event. Start shutdown procedure. */
37 static void sclp_quiesce_handler(struct evbuf_header *evbuf)
38 {
39 	if (_machine_restart != (void *) do_machine_quiesce) {
40 		old_machine_restart = _machine_restart;
41 		old_machine_halt = _machine_halt;
42 		old_machine_power_off = _machine_power_off;
43 		_machine_restart = (void *) do_machine_quiesce;
44 		_machine_halt = do_machine_quiesce;
45 		_machine_power_off = do_machine_quiesce;
46 	}
47 	ctrl_alt_del();
48 }
49 
50 /* Undo machine restart/halt/power_off modification on resume */
51 static void sclp_quiesce_pm_event(struct sclp_register *reg,
52 				  enum sclp_pm_event sclp_pm_event)
53 {
54 	switch (sclp_pm_event) {
55 	case SCLP_PM_EVENT_RESTORE:
56 		if (old_machine_restart) {
57 			_machine_restart = old_machine_restart;
58 			_machine_halt = old_machine_halt;
59 			_machine_power_off = old_machine_power_off;
60 			old_machine_restart = NULL;
61 			old_machine_halt = NULL;
62 			old_machine_power_off = NULL;
63 		}
64 		break;
65 	case SCLP_PM_EVENT_FREEZE:
66 	case SCLP_PM_EVENT_THAW:
67 		break;
68 	}
69 }
70 
71 static struct sclp_register sclp_quiesce_event = {
72 	.receive_mask = EVTYP_SIGQUIESCE_MASK,
73 	.receiver_fn = sclp_quiesce_handler,
74 	.pm_event_fn = sclp_quiesce_pm_event
75 };
76 
77 /* Initialize quiesce driver. */
78 static int __init sclp_quiesce_init(void)
79 {
80 	return sclp_register(&sclp_quiesce_event);
81 }
82 device_initcall(sclp_quiesce_init);
83