1 /* 2 * SCLP event type 3 * Signal Quiesce - trigger system powerdown request 4 * 5 * Copyright IBM, Corp. 2012 6 * 7 * Authors: 8 * Heinz Graalfs <graalfs@de.ibm.com> 9 * 10 * This work is licensed under the terms of the GNU GPL, version 2 or (at your 11 * option) any later version. See the COPYING file in the top-level directory. 12 * 13 */ 14 15 #include "qemu/osdep.h" 16 #include "hw/qdev.h" 17 #include "sysemu/sysemu.h" 18 #include "hw/s390x/sclp.h" 19 #include "migration/vmstate.h" 20 #include "qemu/module.h" 21 #include "hw/s390x/event-facility.h" 22 23 typedef struct SignalQuiesce { 24 EventBufferHeader ebh; 25 uint16_t timeout; 26 uint8_t unit; 27 } QEMU_PACKED SignalQuiesce; 28 29 static bool can_handle_event(uint8_t type) 30 { 31 return type == SCLP_EVENT_SIGNAL_QUIESCE; 32 } 33 34 static sccb_mask_t send_mask(void) 35 { 36 return SCLP_EVENT_MASK_SIGNAL_QUIESCE; 37 } 38 39 static sccb_mask_t receive_mask(void) 40 { 41 return 0; 42 } 43 44 static int read_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr, 45 int *slen) 46 { 47 SignalQuiesce *sq = (SignalQuiesce *) evt_buf_hdr; 48 49 if (*slen < sizeof(SignalQuiesce)) { 50 return 0; 51 } 52 53 if (!event->event_pending) { 54 return 0; 55 } 56 event->event_pending = false; 57 58 sq->ebh.length = cpu_to_be16(sizeof(SignalQuiesce)); 59 sq->ebh.type = SCLP_EVENT_SIGNAL_QUIESCE; 60 sq->ebh.flags |= SCLP_EVENT_BUFFER_ACCEPTED; 61 /* 62 * system_powerdown does not have a timeout. Fortunately the 63 * timeout value is currently ignored by Linux, anyway 64 */ 65 sq->timeout = cpu_to_be16(0); 66 sq->unit = cpu_to_be16(0); 67 *slen -= sizeof(SignalQuiesce); 68 69 return 1; 70 } 71 72 static const VMStateDescription vmstate_sclpquiesce = { 73 .name = TYPE_SCLP_QUIESCE, 74 .version_id = 0, 75 .minimum_version_id = 0, 76 .fields = (VMStateField[]) { 77 VMSTATE_BOOL(event_pending, SCLPEvent), 78 VMSTATE_END_OF_LIST() 79 } 80 }; 81 82 typedef struct QuiesceNotifier QuiesceNotifier; 83 84 static struct QuiesceNotifier { 85 Notifier notifier; 86 SCLPEvent *event; 87 } qn; 88 89 static void quiesce_powerdown_req(Notifier *n, void *opaque) 90 { 91 QuiesceNotifier *qn = container_of(n, QuiesceNotifier, notifier); 92 SCLPEvent *event = qn->event; 93 94 event->event_pending = true; 95 /* trigger SCLP read operation */ 96 sclp_service_interrupt(0); 97 } 98 99 static int quiesce_init(SCLPEvent *event) 100 { 101 qn.notifier.notify = quiesce_powerdown_req; 102 qn.event = event; 103 104 qemu_register_powerdown_notifier(&qn.notifier); 105 106 return 0; 107 } 108 109 static void quiesce_reset(DeviceState *dev) 110 { 111 SCLPEvent *event = SCLP_EVENT(dev); 112 113 event->event_pending = false; 114 } 115 116 static void quiesce_class_init(ObjectClass *klass, void *data) 117 { 118 DeviceClass *dc = DEVICE_CLASS(klass); 119 SCLPEventClass *k = SCLP_EVENT_CLASS(klass); 120 121 dc->reset = quiesce_reset; 122 dc->vmsd = &vmstate_sclpquiesce; 123 set_bit(DEVICE_CATEGORY_MISC, dc->categories); 124 /* 125 * Reason: This is just an internal device - the notifier should 126 * not be registered multiple times in quiesce_init() 127 */ 128 dc->user_creatable = false; 129 130 k->init = quiesce_init; 131 k->get_send_mask = send_mask; 132 k->get_receive_mask = receive_mask; 133 k->can_handle_event = can_handle_event; 134 k->read_event_data = read_event_data; 135 k->write_event_data = NULL; 136 } 137 138 static const TypeInfo sclp_quiesce_info = { 139 .name = TYPE_SCLP_QUIESCE, 140 .parent = TYPE_SCLP_EVENT, 141 .instance_size = sizeof(SCLPEvent), 142 .class_init = quiesce_class_init, 143 .class_size = sizeof(SCLPEventClass), 144 }; 145 146 static void register_types(void) 147 { 148 type_register_static(&sclp_quiesce_info); 149 } 150 151 type_init(register_types) 152