blob: 475e470d9768ea729adc9ba95feee801f942dda1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * signal quiesce handler
3 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02004 * Copyright IBM Corp. 1999, 2004
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
7 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/module.h>
10#include <linux/types.h>
11#include <linux/cpumask.h>
12#include <linux/smp.h>
13#include <linux/init.h>
Adrian Bunk83cc5ed2006-06-25 05:47:41 -070014#include <linux/reboot.h>
Arun Sharma600634972011-07-26 16:09:06 -070015#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/ptrace.h>
Jan Glauber188596f2007-02-21 10:55:03 +010017#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#include "sclp.h"
20
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010021static void (*old_machine_restart)(char *);
22static void (*old_machine_halt)(void);
23static void (*old_machine_power_off)(void);
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025/* Shutdown handler. Signal completion of shutdown by loading special PSW. */
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010026static void do_machine_quiesce(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
28 psw_t quiesce_psw;
29
Heiko Carstensc6b5b842006-12-04 15:40:33 +010030 smp_send_stop();
Martin Schwidefskyb50511e2011-10-30 15:16:50 +010031 quiesce_psw.mask =
32 PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA | PSW_MASK_WAIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 quiesce_psw.addr = 0xfff;
34 __load_psw(quiesce_psw);
35}
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037/* Handler for quiesce event. Start shutdown procedure. */
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010038static void sclp_quiesce_handler(struct evbuf_header *evbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010040 if (_machine_restart != (void *) do_machine_quiesce) {
41 old_machine_restart = _machine_restart;
42 old_machine_halt = _machine_halt;
43 old_machine_power_off = _machine_power_off;
44 _machine_restart = (void *) do_machine_quiesce;
45 _machine_halt = do_machine_quiesce;
46 _machine_power_off = do_machine_quiesce;
47 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 ctrl_alt_del();
49}
50
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010051/* Undo machine restart/halt/power_off modification on resume */
52static void sclp_quiesce_pm_event(struct sclp_register *reg,
53 enum sclp_pm_event sclp_pm_event)
54{
55 switch (sclp_pm_event) {
56 case SCLP_PM_EVENT_RESTORE:
57 if (old_machine_restart) {
58 _machine_restart = old_machine_restart;
59 _machine_halt = old_machine_halt;
60 _machine_power_off = old_machine_power_off;
61 old_machine_restart = NULL;
62 old_machine_halt = NULL;
63 old_machine_power_off = NULL;
64 }
65 break;
66 case SCLP_PM_EVENT_FREEZE:
67 case SCLP_PM_EVENT_THAW:
68 break;
69 }
70}
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072static struct sclp_register sclp_quiesce_event = {
Stefan Haberland6d4740c2007-04-27 16:01:53 +020073 .receive_mask = EVTYP_SIGQUIESCE_MASK,
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010074 .receiver_fn = sclp_quiesce_handler,
75 .pm_event_fn = sclp_quiesce_pm_event
Linus Torvalds1da177e2005-04-16 15:20:36 -070076};
77
78/* Initialize quiesce driver. */
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010079static int __init sclp_quiesce_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Martin Schwidefskya12c53f2008-07-14 09:59:28 +020081 return sclp_register(&sclp_quiesce_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
84module_init(sclp_quiesce_init);