blob: 05909a7df8b30df91009c01146acae763f110da4 [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>
Jan Glauber188596f2007-02-21 10:55:03 +010019#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include "sclp.h"
22
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010023static void (*old_machine_restart)(char *);
24static void (*old_machine_halt)(void);
25static void (*old_machine_power_off)(void);
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027/* Shutdown handler. Signal completion of shutdown by loading special PSW. */
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010028static void do_machine_quiesce(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
30 psw_t quiesce_psw;
31
Heiko Carstensc6b5b842006-12-04 15:40:33 +010032 smp_send_stop();
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
34 quiesce_psw.addr = 0xfff;
35 __load_psw(quiesce_psw);
36}
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/* Handler for quiesce event. Start shutdown procedure. */
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010039static void sclp_quiesce_handler(struct evbuf_header *evbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010041 if (_machine_restart != (void *) do_machine_quiesce) {
42 old_machine_restart = _machine_restart;
43 old_machine_halt = _machine_halt;
44 old_machine_power_off = _machine_power_off;
45 _machine_restart = (void *) do_machine_quiesce;
46 _machine_halt = do_machine_quiesce;
47 _machine_power_off = do_machine_quiesce;
48 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 ctrl_alt_del();
50}
51
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010052/* Undo machine restart/halt/power_off modification on resume */
53static void sclp_quiesce_pm_event(struct sclp_register *reg,
54 enum sclp_pm_event sclp_pm_event)
55{
56 switch (sclp_pm_event) {
57 case SCLP_PM_EVENT_RESTORE:
58 if (old_machine_restart) {
59 _machine_restart = old_machine_restart;
60 _machine_halt = old_machine_halt;
61 _machine_power_off = old_machine_power_off;
62 old_machine_restart = NULL;
63 old_machine_halt = NULL;
64 old_machine_power_off = NULL;
65 }
66 break;
67 case SCLP_PM_EVENT_FREEZE:
68 case SCLP_PM_EVENT_THAW:
69 break;
70 }
71}
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static struct sclp_register sclp_quiesce_event = {
Stefan Haberland6d4740c2007-04-27 16:01:53 +020074 .receive_mask = EVTYP_SIGQUIESCE_MASK,
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010075 .receiver_fn = sclp_quiesce_handler,
76 .pm_event_fn = sclp_quiesce_pm_event
Linus Torvalds1da177e2005-04-16 15:20:36 -070077};
78
79/* Initialize quiesce driver. */
Martin Schwidefsky8b94c1e2009-11-13 15:43:53 +010080static int __init sclp_quiesce_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Martin Schwidefskya12c53f2008-07-14 09:59:28 +020082 return sclp_register(&sclp_quiesce_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
84
85module_init(sclp_quiesce_init);