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