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