]> Git Repo - qemu.git/blame - hw/s390x/sclpquiesce.c
hw/misc: Mark most objects as "common" code to speed up compilation a litte bit
[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 <[email protected]>
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"
83c9f4ca 16#include "hw/s390x/sclp.h"
d6454270 17#include "migration/vmstate.h"
0b8fa32f 18#include "qemu/module.h"
54d31236 19#include "sysemu/runstate.h"
83c9f4ca 20#include "hw/s390x/event-facility.h"
ab9074b5
HG
21
22typedef struct SignalQuiesce {
23 EventBufferHeader ebh;
24 uint16_t timeout;
25 uint8_t unit;
26} QEMU_PACKED SignalQuiesce;
27
c3d9f24a 28static bool can_handle_event(uint8_t type)
ab9074b5 29{
c3d9f24a 30 return type == SCLP_EVENT_SIGNAL_QUIESCE;
ab9074b5
HG
31}
32
1ffed98f 33static sccb_mask_t send_mask(void)
ab9074b5
HG
34{
35 return SCLP_EVENT_MASK_SIGNAL_QUIESCE;
36}
37
1ffed98f 38static sccb_mask_t receive_mask(void)
ab9074b5
HG
39{
40 return 0;
41}
42
43static int read_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr,
44 int *slen)
45{
46 SignalQuiesce *sq = (SignalQuiesce *) evt_buf_hdr;
47
48 if (*slen < sizeof(SignalQuiesce)) {
49 return 0;
50 }
51
52 if (!event->event_pending) {
53 return 0;
54 }
55 event->event_pending = false;
56
57 sq->ebh.length = cpu_to_be16(sizeof(SignalQuiesce));
58 sq->ebh.type = SCLP_EVENT_SIGNAL_QUIESCE;
59 sq->ebh.flags |= SCLP_EVENT_BUFFER_ACCEPTED;
60 /*
61 * system_powerdown does not have a timeout. Fortunately the
62 * timeout value is currently ignored by Linux, anyway
63 */
64 sq->timeout = cpu_to_be16(0);
65 sq->unit = cpu_to_be16(0);
66 *slen -= sizeof(SignalQuiesce);
67
68 return 1;
69}
70
7e36b7a3 71static const VMStateDescription vmstate_sclpquiesce = {
35925a7a 72 .name = TYPE_SCLP_QUIESCE,
7e36b7a3
HG
73 .version_id = 0,
74 .minimum_version_id = 0,
35d08458 75 .fields = (VMStateField[]) {
7e36b7a3
HG
76 VMSTATE_BOOL(event_pending, SCLPEvent),
77 VMSTATE_END_OF_LIST()
78 }
79};
80
ab9074b5
HG
81typedef struct QuiesceNotifier QuiesceNotifier;
82
83static struct QuiesceNotifier {
84 Notifier notifier;
85 SCLPEvent *event;
86} qn;
87
88static void quiesce_powerdown_req(Notifier *n, void *opaque)
89{
90 QuiesceNotifier *qn = container_of(n, QuiesceNotifier, notifier);
91 SCLPEvent *event = qn->event;
92
93 event->event_pending = true;
94 /* trigger SCLP read operation */
95 sclp_service_interrupt(0);
96}
97
98static int quiesce_init(SCLPEvent *event)
99{
ab9074b5
HG
100 qn.notifier.notify = quiesce_powerdown_req;
101 qn.event = event;
102
103 qemu_register_powerdown_notifier(&qn.notifier);
104
105 return 0;
106}
107
3af6de32
HG
108static void quiesce_reset(DeviceState *dev)
109{
110 SCLPEvent *event = SCLP_EVENT(dev);
111
112 event->event_pending = false;
113}
114
ab9074b5
HG
115static void quiesce_class_init(ObjectClass *klass, void *data)
116{
7e36b7a3 117 DeviceClass *dc = DEVICE_CLASS(klass);
ab9074b5
HG
118 SCLPEventClass *k = SCLP_EVENT_CLASS(klass);
119
3af6de32 120 dc->reset = quiesce_reset;
7e36b7a3 121 dc->vmsd = &vmstate_sclpquiesce;
183f6b8d 122 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
b923ab31
TH
123 /*
124 * Reason: This is just an internal device - the notifier should
125 * not be registered multiple times in quiesce_init()
126 */
127 dc->user_creatable = false;
ab9074b5 128
b923ab31 129 k->init = quiesce_init;
ab9074b5
HG
130 k->get_send_mask = send_mask;
131 k->get_receive_mask = receive_mask;
c3d9f24a 132 k->can_handle_event = can_handle_event;
ab9074b5
HG
133 k->read_event_data = read_event_data;
134 k->write_event_data = NULL;
135}
136
8c43a6f0 137static const TypeInfo sclp_quiesce_info = {
35925a7a 138 .name = TYPE_SCLP_QUIESCE,
ab9074b5
HG
139 .parent = TYPE_SCLP_EVENT,
140 .instance_size = sizeof(SCLPEvent),
141 .class_init = quiesce_class_init,
142 .class_size = sizeof(SCLPEventClass),
143};
144
145static void register_types(void)
146{
147 type_register_static(&sclp_quiesce_info);
148}
149
150type_init(register_types)
This page took 0.338384 seconds and 4 git commands to generate.