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