]> git.ipfire.org Git - thirdparty/qemu.git/blame - hw/s390x/sclpquiesce.c
Include migration/vmstate.h less
[thirdparty/qemu.git] / hw / s390x / sclpquiesce.c
CommitLineData
ab9074b5
HG
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 */
0b8fa32f 14
9615495a 15#include "qemu/osdep.h"
a9c94277 16#include "hw/qdev.h"
9c17d615 17#include "sysemu/sysemu.h"
83c9f4ca 18#include "hw/s390x/sclp.h"
d6454270 19#include "migration/vmstate.h"
0b8fa32f 20#include "qemu/module.h"
83c9f4ca 21#include "hw/s390x/event-facility.h"
ab9074b5
HG
22
23typedef struct SignalQuiesce {
24 EventBufferHeader ebh;
25 uint16_t timeout;
26 uint8_t unit;
27} QEMU_PACKED SignalQuiesce;
28
c3d9f24a 29static bool can_handle_event(uint8_t type)
ab9074b5 30{
c3d9f24a 31 return type == SCLP_EVENT_SIGNAL_QUIESCE;
ab9074b5
HG
32}
33
1ffed98f 34static sccb_mask_t send_mask(void)
ab9074b5
HG
35{
36 return SCLP_EVENT_MASK_SIGNAL_QUIESCE;
37}
38
1ffed98f 39static sccb_mask_t receive_mask(void)
ab9074b5
HG
40{
41 return 0;
42}
43
44static 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
7e36b7a3 72static const VMStateDescription vmstate_sclpquiesce = {
35925a7a 73 .name = TYPE_SCLP_QUIESCE,
7e36b7a3
HG
74 .version_id = 0,
75 .minimum_version_id = 0,
35d08458 76 .fields = (VMStateField[]) {
7e36b7a3
HG
77 VMSTATE_BOOL(event_pending, SCLPEvent),
78 VMSTATE_END_OF_LIST()
79 }
80};
81
ab9074b5
HG
82typedef struct QuiesceNotifier QuiesceNotifier;
83
84static struct QuiesceNotifier {
85 Notifier notifier;
86 SCLPEvent *event;
87} qn;
88
89static 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
99static int quiesce_init(SCLPEvent *event)
100{
ab9074b5
HG
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
3af6de32
HG
109static void quiesce_reset(DeviceState *dev)
110{
111 SCLPEvent *event = SCLP_EVENT(dev);
112
113 event->event_pending = false;
114}
115
ab9074b5
HG
116static void quiesce_class_init(ObjectClass *klass, void *data)
117{
7e36b7a3 118 DeviceClass *dc = DEVICE_CLASS(klass);
ab9074b5
HG
119 SCLPEventClass *k = SCLP_EVENT_CLASS(klass);
120
3af6de32 121 dc->reset = quiesce_reset;
7e36b7a3 122 dc->vmsd = &vmstate_sclpquiesce;
183f6b8d 123 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
b923ab31
TH
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;
ab9074b5 129
b923ab31 130 k->init = quiesce_init;
ab9074b5
HG
131 k->get_send_mask = send_mask;
132 k->get_receive_mask = receive_mask;
c3d9f24a 133 k->can_handle_event = can_handle_event;
ab9074b5
HG
134 k->read_event_data = read_event_data;
135 k->write_event_data = NULL;
136}
137
8c43a6f0 138static const TypeInfo sclp_quiesce_info = {
35925a7a 139 .name = TYPE_SCLP_QUIESCE,
ab9074b5
HG
140 .parent = TYPE_SCLP_EVENT,
141 .instance_size = sizeof(SCLPEvent),
142 .class_init = quiesce_class_init,
143 .class_size = sizeof(SCLPEventClass),
144};
145
146static void register_types(void)
147{
148 type_register_static(&sclp_quiesce_info);
149}
150
151type_init(register_types)