root / hw / s390x / event-facility.c @ 7e0a9247
History | View | Annotate | Download (10.9 kB)
1 | 559a17a1 | Heinz Graalfs | /*
|
---|---|---|---|
2 | 559a17a1 | Heinz Graalfs | * SCLP
|
3 | 559a17a1 | Heinz Graalfs | * Event Facility
|
4 | 559a17a1 | Heinz Graalfs | * handles SCLP event types
|
5 | 559a17a1 | Heinz Graalfs | * - Signal Quiesce - system power down
|
6 | 559a17a1 | Heinz Graalfs | * - ASCII Console Data - VT220 read and write
|
7 | 559a17a1 | Heinz Graalfs | *
|
8 | 559a17a1 | Heinz Graalfs | * Copyright IBM, Corp. 2012
|
9 | 559a17a1 | Heinz Graalfs | *
|
10 | 559a17a1 | Heinz Graalfs | * Authors:
|
11 | 559a17a1 | Heinz Graalfs | * Heinz Graalfs <graalfs@de.ibm.com>
|
12 | 559a17a1 | Heinz Graalfs | *
|
13 | 559a17a1 | Heinz Graalfs | * This work is licensed under the terms of the GNU GPL, version 2 or (at your
|
14 | 559a17a1 | Heinz Graalfs | * option) any later version. See the COPYING file in the top-level directory.
|
15 | 559a17a1 | Heinz Graalfs | *
|
16 | 559a17a1 | Heinz Graalfs | */
|
17 | 559a17a1 | Heinz Graalfs | |
18 | 559a17a1 | Heinz Graalfs | #include "monitor.h" |
19 | 559a17a1 | Heinz Graalfs | #include "sysemu.h" |
20 | 559a17a1 | Heinz Graalfs | |
21 | 559a17a1 | Heinz Graalfs | #include "sclp.h" |
22 | 559a17a1 | Heinz Graalfs | #include "event-facility.h" |
23 | 559a17a1 | Heinz Graalfs | |
24 | 559a17a1 | Heinz Graalfs | typedef struct EventTypesBus { |
25 | 559a17a1 | Heinz Graalfs | BusState qbus; |
26 | 559a17a1 | Heinz Graalfs | } EventTypesBus; |
27 | 559a17a1 | Heinz Graalfs | |
28 | 559a17a1 | Heinz Graalfs | struct SCLPEventFacility {
|
29 | 559a17a1 | Heinz Graalfs | EventTypesBus sbus; |
30 | 559a17a1 | Heinz Graalfs | DeviceState *qdev; |
31 | 559a17a1 | Heinz Graalfs | /* guest' receive mask */
|
32 | 559a17a1 | Heinz Graalfs | unsigned int receive_mask; |
33 | 559a17a1 | Heinz Graalfs | }; |
34 | 559a17a1 | Heinz Graalfs | |
35 | 559a17a1 | Heinz Graalfs | /* return true if any child has event pending set */
|
36 | 559a17a1 | Heinz Graalfs | static bool event_pending(SCLPEventFacility *ef) |
37 | 559a17a1 | Heinz Graalfs | { |
38 | 559a17a1 | Heinz Graalfs | BusChild *kid; |
39 | 559a17a1 | Heinz Graalfs | SCLPEvent *event; |
40 | 559a17a1 | Heinz Graalfs | SCLPEventClass *event_class; |
41 | 559a17a1 | Heinz Graalfs | |
42 | 559a17a1 | Heinz Graalfs | QTAILQ_FOREACH(kid, &ef->sbus.qbus.children, sibling) { |
43 | 559a17a1 | Heinz Graalfs | DeviceState *qdev = kid->child; |
44 | 559a17a1 | Heinz Graalfs | event = DO_UPCAST(SCLPEvent, qdev, qdev); |
45 | 559a17a1 | Heinz Graalfs | event_class = SCLP_EVENT_GET_CLASS(event); |
46 | 559a17a1 | Heinz Graalfs | if (event->event_pending &&
|
47 | 559a17a1 | Heinz Graalfs | event_class->get_send_mask() & ef->receive_mask) { |
48 | 559a17a1 | Heinz Graalfs | return true; |
49 | 559a17a1 | Heinz Graalfs | } |
50 | 559a17a1 | Heinz Graalfs | } |
51 | 559a17a1 | Heinz Graalfs | return false; |
52 | 559a17a1 | Heinz Graalfs | } |
53 | 559a17a1 | Heinz Graalfs | |
54 | 559a17a1 | Heinz Graalfs | static unsigned int get_host_send_mask(SCLPEventFacility *ef) |
55 | 559a17a1 | Heinz Graalfs | { |
56 | 559a17a1 | Heinz Graalfs | unsigned int mask; |
57 | 559a17a1 | Heinz Graalfs | BusChild *kid; |
58 | 559a17a1 | Heinz Graalfs | SCLPEventClass *child; |
59 | 559a17a1 | Heinz Graalfs | |
60 | 559a17a1 | Heinz Graalfs | mask = 0;
|
61 | 559a17a1 | Heinz Graalfs | |
62 | 559a17a1 | Heinz Graalfs | QTAILQ_FOREACH(kid, &ef->sbus.qbus.children, sibling) { |
63 | 559a17a1 | Heinz Graalfs | DeviceState *qdev = kid->child; |
64 | 559a17a1 | Heinz Graalfs | child = SCLP_EVENT_GET_CLASS((SCLPEvent *) qdev); |
65 | 559a17a1 | Heinz Graalfs | mask |= child->get_send_mask(); |
66 | 559a17a1 | Heinz Graalfs | } |
67 | 559a17a1 | Heinz Graalfs | return mask;
|
68 | 559a17a1 | Heinz Graalfs | } |
69 | 559a17a1 | Heinz Graalfs | |
70 | 559a17a1 | Heinz Graalfs | static unsigned int get_host_receive_mask(SCLPEventFacility *ef) |
71 | 559a17a1 | Heinz Graalfs | { |
72 | 559a17a1 | Heinz Graalfs | unsigned int mask; |
73 | 559a17a1 | Heinz Graalfs | BusChild *kid; |
74 | 559a17a1 | Heinz Graalfs | SCLPEventClass *child; |
75 | 559a17a1 | Heinz Graalfs | |
76 | 559a17a1 | Heinz Graalfs | mask = 0;
|
77 | 559a17a1 | Heinz Graalfs | |
78 | 559a17a1 | Heinz Graalfs | QTAILQ_FOREACH(kid, &ef->sbus.qbus.children, sibling) { |
79 | 559a17a1 | Heinz Graalfs | DeviceState *qdev = kid->child; |
80 | 559a17a1 | Heinz Graalfs | child = SCLP_EVENT_GET_CLASS((SCLPEvent *) qdev); |
81 | 559a17a1 | Heinz Graalfs | mask |= child->get_receive_mask(); |
82 | 559a17a1 | Heinz Graalfs | } |
83 | 559a17a1 | Heinz Graalfs | return mask;
|
84 | 559a17a1 | Heinz Graalfs | } |
85 | 559a17a1 | Heinz Graalfs | |
86 | 559a17a1 | Heinz Graalfs | static uint16_t write_event_length_check(SCCB *sccb)
|
87 | 559a17a1 | Heinz Graalfs | { |
88 | 559a17a1 | Heinz Graalfs | int slen;
|
89 | 559a17a1 | Heinz Graalfs | unsigned elen = 0; |
90 | 559a17a1 | Heinz Graalfs | EventBufferHeader *event; |
91 | 559a17a1 | Heinz Graalfs | WriteEventData *wed = (WriteEventData *) sccb; |
92 | 559a17a1 | Heinz Graalfs | |
93 | 559a17a1 | Heinz Graalfs | event = (EventBufferHeader *) &wed->ebh; |
94 | 559a17a1 | Heinz Graalfs | for (slen = sccb_data_len(sccb); slen > 0; slen -= elen) { |
95 | 559a17a1 | Heinz Graalfs | elen = be16_to_cpu(event->length); |
96 | 559a17a1 | Heinz Graalfs | if (elen < sizeof(*event) || elen > slen) { |
97 | 559a17a1 | Heinz Graalfs | return SCLP_RC_EVENT_BUFFER_SYNTAX_ERROR;
|
98 | 559a17a1 | Heinz Graalfs | } |
99 | 559a17a1 | Heinz Graalfs | event = (void *) event + elen;
|
100 | 559a17a1 | Heinz Graalfs | } |
101 | 559a17a1 | Heinz Graalfs | if (slen) {
|
102 | 559a17a1 | Heinz Graalfs | return SCLP_RC_INCONSISTENT_LENGTHS;
|
103 | 559a17a1 | Heinz Graalfs | } |
104 | 559a17a1 | Heinz Graalfs | return SCLP_RC_NORMAL_COMPLETION;
|
105 | 559a17a1 | Heinz Graalfs | } |
106 | 559a17a1 | Heinz Graalfs | |
107 | 559a17a1 | Heinz Graalfs | static uint16_t handle_write_event_buf(SCLPEventFacility *ef,
|
108 | 559a17a1 | Heinz Graalfs | EventBufferHeader *event_buf, SCCB *sccb) |
109 | 559a17a1 | Heinz Graalfs | { |
110 | 559a17a1 | Heinz Graalfs | uint16_t rc; |
111 | 559a17a1 | Heinz Graalfs | BusChild *kid; |
112 | 559a17a1 | Heinz Graalfs | SCLPEvent *event; |
113 | 559a17a1 | Heinz Graalfs | SCLPEventClass *ec; |
114 | 559a17a1 | Heinz Graalfs | |
115 | 773de5c7 | Cornelia Huck | rc = SCLP_RC_INVALID_FUNCTION; |
116 | 773de5c7 | Cornelia Huck | |
117 | 559a17a1 | Heinz Graalfs | QTAILQ_FOREACH(kid, &ef->sbus.qbus.children, sibling) { |
118 | 559a17a1 | Heinz Graalfs | DeviceState *qdev = kid->child; |
119 | 559a17a1 | Heinz Graalfs | event = (SCLPEvent *) qdev; |
120 | 559a17a1 | Heinz Graalfs | ec = SCLP_EVENT_GET_CLASS(event); |
121 | 559a17a1 | Heinz Graalfs | |
122 | 559a17a1 | Heinz Graalfs | if (ec->write_event_data &&
|
123 | 559a17a1 | Heinz Graalfs | ec->event_type() == event_buf->type) { |
124 | 559a17a1 | Heinz Graalfs | rc = ec->write_event_data(event, event_buf); |
125 | 559a17a1 | Heinz Graalfs | break;
|
126 | 559a17a1 | Heinz Graalfs | } |
127 | 559a17a1 | Heinz Graalfs | } |
128 | 559a17a1 | Heinz Graalfs | return rc;
|
129 | 559a17a1 | Heinz Graalfs | } |
130 | 559a17a1 | Heinz Graalfs | |
131 | 559a17a1 | Heinz Graalfs | static uint16_t handle_sccb_write_events(SCLPEventFacility *ef, SCCB *sccb)
|
132 | 559a17a1 | Heinz Graalfs | { |
133 | 559a17a1 | Heinz Graalfs | uint16_t rc; |
134 | 559a17a1 | Heinz Graalfs | int slen;
|
135 | 559a17a1 | Heinz Graalfs | unsigned elen = 0; |
136 | 559a17a1 | Heinz Graalfs | EventBufferHeader *event_buf; |
137 | 559a17a1 | Heinz Graalfs | WriteEventData *wed = (WriteEventData *) sccb; |
138 | 559a17a1 | Heinz Graalfs | |
139 | 559a17a1 | Heinz Graalfs | event_buf = &wed->ebh; |
140 | 559a17a1 | Heinz Graalfs | rc = SCLP_RC_NORMAL_COMPLETION; |
141 | 559a17a1 | Heinz Graalfs | |
142 | 559a17a1 | Heinz Graalfs | /* loop over all contained event buffers */
|
143 | 559a17a1 | Heinz Graalfs | for (slen = sccb_data_len(sccb); slen > 0; slen -= elen) { |
144 | 559a17a1 | Heinz Graalfs | elen = be16_to_cpu(event_buf->length); |
145 | 559a17a1 | Heinz Graalfs | |
146 | 559a17a1 | Heinz Graalfs | /* in case of a previous error mark all trailing buffers
|
147 | 559a17a1 | Heinz Graalfs | * as not accepted */
|
148 | 559a17a1 | Heinz Graalfs | if (rc != SCLP_RC_NORMAL_COMPLETION) {
|
149 | 559a17a1 | Heinz Graalfs | event_buf->flags &= ~(SCLP_EVENT_BUFFER_ACCEPTED); |
150 | 559a17a1 | Heinz Graalfs | } else {
|
151 | 559a17a1 | Heinz Graalfs | rc = handle_write_event_buf(ef, event_buf, sccb); |
152 | 559a17a1 | Heinz Graalfs | } |
153 | 559a17a1 | Heinz Graalfs | event_buf = (void *) event_buf + elen;
|
154 | 559a17a1 | Heinz Graalfs | } |
155 | 559a17a1 | Heinz Graalfs | return rc;
|
156 | 559a17a1 | Heinz Graalfs | } |
157 | 559a17a1 | Heinz Graalfs | |
158 | 559a17a1 | Heinz Graalfs | static void write_event_data(SCLPEventFacility *ef, SCCB *sccb) |
159 | 559a17a1 | Heinz Graalfs | { |
160 | 559a17a1 | Heinz Graalfs | if (sccb->h.function_code != SCLP_FC_NORMAL_WRITE) {
|
161 | 559a17a1 | Heinz Graalfs | sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_FUNCTION); |
162 | 559a17a1 | Heinz Graalfs | goto out;
|
163 | 559a17a1 | Heinz Graalfs | } |
164 | 559a17a1 | Heinz Graalfs | if (be16_to_cpu(sccb->h.length) < 8) { |
165 | 559a17a1 | Heinz Graalfs | sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH); |
166 | 559a17a1 | Heinz Graalfs | goto out;
|
167 | 559a17a1 | Heinz Graalfs | } |
168 | 559a17a1 | Heinz Graalfs | /* first do a sanity check of the write events */
|
169 | 559a17a1 | Heinz Graalfs | sccb->h.response_code = cpu_to_be16(write_event_length_check(sccb)); |
170 | 559a17a1 | Heinz Graalfs | |
171 | 559a17a1 | Heinz Graalfs | /* if no early error, then execute */
|
172 | 559a17a1 | Heinz Graalfs | if (sccb->h.response_code == be16_to_cpu(SCLP_RC_NORMAL_COMPLETION)) {
|
173 | 559a17a1 | Heinz Graalfs | sccb->h.response_code = |
174 | 559a17a1 | Heinz Graalfs | cpu_to_be16(handle_sccb_write_events(ef, sccb)); |
175 | 559a17a1 | Heinz Graalfs | } |
176 | 559a17a1 | Heinz Graalfs | |
177 | 559a17a1 | Heinz Graalfs | out:
|
178 | 559a17a1 | Heinz Graalfs | return;
|
179 | 559a17a1 | Heinz Graalfs | } |
180 | 559a17a1 | Heinz Graalfs | |
181 | 559a17a1 | Heinz Graalfs | static uint16_t handle_sccb_read_events(SCLPEventFacility *ef, SCCB *sccb,
|
182 | 559a17a1 | Heinz Graalfs | unsigned int mask) |
183 | 559a17a1 | Heinz Graalfs | { |
184 | 559a17a1 | Heinz Graalfs | uint16_t rc; |
185 | 559a17a1 | Heinz Graalfs | int slen;
|
186 | 559a17a1 | Heinz Graalfs | unsigned elen = 0; |
187 | 559a17a1 | Heinz Graalfs | BusChild *kid; |
188 | 559a17a1 | Heinz Graalfs | SCLPEvent *event; |
189 | 559a17a1 | Heinz Graalfs | SCLPEventClass *ec; |
190 | 559a17a1 | Heinz Graalfs | EventBufferHeader *event_buf; |
191 | 559a17a1 | Heinz Graalfs | ReadEventData *red = (ReadEventData *) sccb; |
192 | 559a17a1 | Heinz Graalfs | |
193 | 559a17a1 | Heinz Graalfs | event_buf = &red->ebh; |
194 | 559a17a1 | Heinz Graalfs | event_buf->length = 0;
|
195 | 559a17a1 | Heinz Graalfs | slen = sizeof(sccb->data);
|
196 | 559a17a1 | Heinz Graalfs | |
197 | 559a17a1 | Heinz Graalfs | rc = SCLP_RC_NO_EVENT_BUFFERS_STORED; |
198 | 559a17a1 | Heinz Graalfs | |
199 | 559a17a1 | Heinz Graalfs | QTAILQ_FOREACH(kid, &ef->sbus.qbus.children, sibling) { |
200 | 559a17a1 | Heinz Graalfs | DeviceState *qdev = kid->child; |
201 | 559a17a1 | Heinz Graalfs | event = (SCLPEvent *) qdev; |
202 | 559a17a1 | Heinz Graalfs | ec = SCLP_EVENT_GET_CLASS(event); |
203 | 559a17a1 | Heinz Graalfs | |
204 | 559a17a1 | Heinz Graalfs | if (mask & ec->get_send_mask()) {
|
205 | 559a17a1 | Heinz Graalfs | if (ec->read_event_data(event, event_buf, &slen)) {
|
206 | 559a17a1 | Heinz Graalfs | rc = SCLP_RC_NORMAL_COMPLETION; |
207 | 559a17a1 | Heinz Graalfs | } |
208 | 559a17a1 | Heinz Graalfs | } |
209 | 559a17a1 | Heinz Graalfs | elen = be16_to_cpu(event_buf->length); |
210 | 559a17a1 | Heinz Graalfs | event_buf = (void *) event_buf + elen;
|
211 | 559a17a1 | Heinz Graalfs | } |
212 | 559a17a1 | Heinz Graalfs | |
213 | 559a17a1 | Heinz Graalfs | if (sccb->h.control_mask[2] & SCLP_VARIABLE_LENGTH_RESPONSE) { |
214 | 559a17a1 | Heinz Graalfs | /* architecture suggests to reset variable-length-response bit */
|
215 | 559a17a1 | Heinz Graalfs | sccb->h.control_mask[2] &= ~SCLP_VARIABLE_LENGTH_RESPONSE;
|
216 | 559a17a1 | Heinz Graalfs | /* with a new length value */
|
217 | 559a17a1 | Heinz Graalfs | sccb->h.length = cpu_to_be16(SCCB_SIZE - slen); |
218 | 559a17a1 | Heinz Graalfs | } |
219 | 559a17a1 | Heinz Graalfs | return rc;
|
220 | 559a17a1 | Heinz Graalfs | } |
221 | 559a17a1 | Heinz Graalfs | |
222 | 559a17a1 | Heinz Graalfs | static void read_event_data(SCLPEventFacility *ef, SCCB *sccb) |
223 | 559a17a1 | Heinz Graalfs | { |
224 | 559a17a1 | Heinz Graalfs | unsigned int sclp_active_selection_mask; |
225 | 559a17a1 | Heinz Graalfs | unsigned int sclp_cp_receive_mask; |
226 | 559a17a1 | Heinz Graalfs | |
227 | 559a17a1 | Heinz Graalfs | ReadEventData *red = (ReadEventData *) sccb; |
228 | 559a17a1 | Heinz Graalfs | |
229 | 559a17a1 | Heinz Graalfs | if (be16_to_cpu(sccb->h.length) != SCCB_SIZE) {
|
230 | 559a17a1 | Heinz Graalfs | sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH); |
231 | 559a17a1 | Heinz Graalfs | goto out;
|
232 | 559a17a1 | Heinz Graalfs | } |
233 | 559a17a1 | Heinz Graalfs | |
234 | 559a17a1 | Heinz Graalfs | sclp_cp_receive_mask = ef->receive_mask; |
235 | 559a17a1 | Heinz Graalfs | |
236 | 559a17a1 | Heinz Graalfs | /* get active selection mask */
|
237 | 559a17a1 | Heinz Graalfs | switch (sccb->h.function_code) {
|
238 | 559a17a1 | Heinz Graalfs | case SCLP_UNCONDITIONAL_READ:
|
239 | 559a17a1 | Heinz Graalfs | sclp_active_selection_mask = sclp_cp_receive_mask; |
240 | 559a17a1 | Heinz Graalfs | break;
|
241 | 559a17a1 | Heinz Graalfs | case SCLP_SELECTIVE_READ:
|
242 | 559a17a1 | Heinz Graalfs | if (!(sclp_cp_receive_mask & be32_to_cpu(red->mask))) {
|
243 | 559a17a1 | Heinz Graalfs | sccb->h.response_code = |
244 | 559a17a1 | Heinz Graalfs | cpu_to_be16(SCLP_RC_INVALID_SELECTION_MASK); |
245 | 559a17a1 | Heinz Graalfs | goto out;
|
246 | 559a17a1 | Heinz Graalfs | } |
247 | 559a17a1 | Heinz Graalfs | sclp_active_selection_mask = be32_to_cpu(red->mask); |
248 | 559a17a1 | Heinz Graalfs | break;
|
249 | 559a17a1 | Heinz Graalfs | default:
|
250 | 559a17a1 | Heinz Graalfs | sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_FUNCTION); |
251 | 559a17a1 | Heinz Graalfs | goto out;
|
252 | 559a17a1 | Heinz Graalfs | } |
253 | 559a17a1 | Heinz Graalfs | sccb->h.response_code = cpu_to_be16( |
254 | 559a17a1 | Heinz Graalfs | handle_sccb_read_events(ef, sccb, sclp_active_selection_mask)); |
255 | 559a17a1 | Heinz Graalfs | |
256 | 559a17a1 | Heinz Graalfs | out:
|
257 | 559a17a1 | Heinz Graalfs | return;
|
258 | 559a17a1 | Heinz Graalfs | } |
259 | 559a17a1 | Heinz Graalfs | |
260 | 559a17a1 | Heinz Graalfs | static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb) |
261 | 559a17a1 | Heinz Graalfs | { |
262 | 559a17a1 | Heinz Graalfs | WriteEventMask *we_mask = (WriteEventMask *) sccb; |
263 | 559a17a1 | Heinz Graalfs | |
264 | 559a17a1 | Heinz Graalfs | /* Attention: We assume that Linux uses 4-byte masks, what it actually
|
265 | 559a17a1 | Heinz Graalfs | does. Architecture allows for masks of variable size, though */
|
266 | 559a17a1 | Heinz Graalfs | if (be16_to_cpu(we_mask->mask_length) != 4) { |
267 | 559a17a1 | Heinz Graalfs | sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_MASK_LENGTH); |
268 | 559a17a1 | Heinz Graalfs | goto out;
|
269 | 559a17a1 | Heinz Graalfs | } |
270 | 559a17a1 | Heinz Graalfs | |
271 | 559a17a1 | Heinz Graalfs | /* keep track of the guest's capability masks */
|
272 | 559a17a1 | Heinz Graalfs | ef->receive_mask = be32_to_cpu(we_mask->cp_receive_mask); |
273 | 559a17a1 | Heinz Graalfs | |
274 | 559a17a1 | Heinz Graalfs | /* return the SCLP's capability masks to the guest */
|
275 | 559a17a1 | Heinz Graalfs | we_mask->send_mask = cpu_to_be32(get_host_send_mask(ef)); |
276 | 559a17a1 | Heinz Graalfs | we_mask->receive_mask = cpu_to_be32(get_host_receive_mask(ef)); |
277 | 559a17a1 | Heinz Graalfs | |
278 | 559a17a1 | Heinz Graalfs | sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_COMPLETION); |
279 | 559a17a1 | Heinz Graalfs | |
280 | 559a17a1 | Heinz Graalfs | out:
|
281 | 559a17a1 | Heinz Graalfs | return;
|
282 | 559a17a1 | Heinz Graalfs | } |
283 | 559a17a1 | Heinz Graalfs | |
284 | 559a17a1 | Heinz Graalfs | /* qemu object creation and initialization functions */
|
285 | 559a17a1 | Heinz Graalfs | |
286 | 559a17a1 | Heinz Graalfs | #define TYPE_SCLP_EVENTS_BUS "s390-sclp-events-bus" |
287 | 559a17a1 | Heinz Graalfs | |
288 | 559a17a1 | Heinz Graalfs | static void sclp_events_bus_class_init(ObjectClass *klass, void *data) |
289 | 559a17a1 | Heinz Graalfs | { |
290 | 559a17a1 | Heinz Graalfs | } |
291 | 559a17a1 | Heinz Graalfs | |
292 | 559a17a1 | Heinz Graalfs | static const TypeInfo s390_sclp_events_bus_info = { |
293 | 559a17a1 | Heinz Graalfs | .name = TYPE_SCLP_EVENTS_BUS, |
294 | 559a17a1 | Heinz Graalfs | .parent = TYPE_BUS, |
295 | 559a17a1 | Heinz Graalfs | .class_init = sclp_events_bus_class_init, |
296 | 559a17a1 | Heinz Graalfs | }; |
297 | 559a17a1 | Heinz Graalfs | |
298 | 559a17a1 | Heinz Graalfs | static void command_handler(SCLPEventFacility *ef, SCCB *sccb, uint64_t code) |
299 | 559a17a1 | Heinz Graalfs | { |
300 | 559a17a1 | Heinz Graalfs | switch (code) {
|
301 | 559a17a1 | Heinz Graalfs | case SCLP_CMD_READ_EVENT_DATA:
|
302 | 559a17a1 | Heinz Graalfs | read_event_data(ef, sccb); |
303 | 559a17a1 | Heinz Graalfs | break;
|
304 | 559a17a1 | Heinz Graalfs | case SCLP_CMD_WRITE_EVENT_DATA:
|
305 | 559a17a1 | Heinz Graalfs | write_event_data(ef, sccb); |
306 | 559a17a1 | Heinz Graalfs | break;
|
307 | 559a17a1 | Heinz Graalfs | case SCLP_CMD_WRITE_EVENT_MASK:
|
308 | 559a17a1 | Heinz Graalfs | write_event_mask(ef, sccb); |
309 | 559a17a1 | Heinz Graalfs | break;
|
310 | 559a17a1 | Heinz Graalfs | default:
|
311 | 559a17a1 | Heinz Graalfs | sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND); |
312 | 559a17a1 | Heinz Graalfs | break;
|
313 | 559a17a1 | Heinz Graalfs | } |
314 | 559a17a1 | Heinz Graalfs | } |
315 | 559a17a1 | Heinz Graalfs | |
316 | 559a17a1 | Heinz Graalfs | static int init_event_facility(S390SCLPDevice *sdev) |
317 | 559a17a1 | Heinz Graalfs | { |
318 | 559a17a1 | Heinz Graalfs | SCLPEventFacility *event_facility; |
319 | ab9074b5 | Heinz Graalfs | DeviceState *quiesce; |
320 | 559a17a1 | Heinz Graalfs | |
321 | 559a17a1 | Heinz Graalfs | event_facility = g_malloc0(sizeof(SCLPEventFacility));
|
322 | 559a17a1 | Heinz Graalfs | sdev->ef = event_facility; |
323 | 559a17a1 | Heinz Graalfs | sdev->sclp_command_handler = command_handler; |
324 | 559a17a1 | Heinz Graalfs | sdev->event_pending = event_pending; |
325 | 559a17a1 | Heinz Graalfs | |
326 | 559a17a1 | Heinz Graalfs | /* Spawn a new sclp-events facility */
|
327 | 559a17a1 | Heinz Graalfs | qbus_create_inplace(&event_facility->sbus.qbus, |
328 | 559a17a1 | Heinz Graalfs | TYPE_SCLP_EVENTS_BUS, (DeviceState *)sdev, NULL);
|
329 | 559a17a1 | Heinz Graalfs | event_facility->sbus.qbus.allow_hotplug = 0;
|
330 | 559a17a1 | Heinz Graalfs | event_facility->qdev = (DeviceState *) sdev; |
331 | 559a17a1 | Heinz Graalfs | |
332 | ab9074b5 | Heinz Graalfs | quiesce = qdev_create(&event_facility->sbus.qbus, "sclpquiesce");
|
333 | ab9074b5 | Heinz Graalfs | if (!quiesce) {
|
334 | ab9074b5 | Heinz Graalfs | return -1; |
335 | ab9074b5 | Heinz Graalfs | } |
336 | ab9074b5 | Heinz Graalfs | qdev_init_nofail(quiesce); |
337 | ab9074b5 | Heinz Graalfs | |
338 | 559a17a1 | Heinz Graalfs | return 0; |
339 | 559a17a1 | Heinz Graalfs | } |
340 | 559a17a1 | Heinz Graalfs | |
341 | 559a17a1 | Heinz Graalfs | static void init_event_facility_class(ObjectClass *klass, void *data) |
342 | 559a17a1 | Heinz Graalfs | { |
343 | 559a17a1 | Heinz Graalfs | S390SCLPDeviceClass *k = SCLP_S390_DEVICE_CLASS(klass); |
344 | 559a17a1 | Heinz Graalfs | |
345 | 559a17a1 | Heinz Graalfs | k->init = init_event_facility; |
346 | 559a17a1 | Heinz Graalfs | } |
347 | 559a17a1 | Heinz Graalfs | |
348 | 559a17a1 | Heinz Graalfs | static TypeInfo s390_sclp_event_facility_info = {
|
349 | 559a17a1 | Heinz Graalfs | .name = "s390-sclp-event-facility",
|
350 | 559a17a1 | Heinz Graalfs | .parent = TYPE_DEVICE_S390_SCLP, |
351 | 559a17a1 | Heinz Graalfs | .instance_size = sizeof(S390SCLPDevice),
|
352 | 559a17a1 | Heinz Graalfs | .class_init = init_event_facility_class, |
353 | 559a17a1 | Heinz Graalfs | }; |
354 | 559a17a1 | Heinz Graalfs | |
355 | 559a17a1 | Heinz Graalfs | static int event_qdev_init(DeviceState *qdev) |
356 | 559a17a1 | Heinz Graalfs | { |
357 | 559a17a1 | Heinz Graalfs | SCLPEvent *event = DO_UPCAST(SCLPEvent, qdev, qdev); |
358 | 559a17a1 | Heinz Graalfs | SCLPEventClass *child = SCLP_EVENT_GET_CLASS(event); |
359 | 559a17a1 | Heinz Graalfs | |
360 | 559a17a1 | Heinz Graalfs | return child->init(event);
|
361 | 559a17a1 | Heinz Graalfs | } |
362 | 559a17a1 | Heinz Graalfs | |
363 | 559a17a1 | Heinz Graalfs | static int event_qdev_exit(DeviceState *qdev) |
364 | 559a17a1 | Heinz Graalfs | { |
365 | 559a17a1 | Heinz Graalfs | SCLPEvent *event = DO_UPCAST(SCLPEvent, qdev, qdev); |
366 | 559a17a1 | Heinz Graalfs | SCLPEventClass *child = SCLP_EVENT_GET_CLASS(event); |
367 | 559a17a1 | Heinz Graalfs | if (child->exit) {
|
368 | 559a17a1 | Heinz Graalfs | child->exit(event); |
369 | 559a17a1 | Heinz Graalfs | } |
370 | 559a17a1 | Heinz Graalfs | return 0; |
371 | 559a17a1 | Heinz Graalfs | } |
372 | 559a17a1 | Heinz Graalfs | |
373 | 559a17a1 | Heinz Graalfs | static void event_class_init(ObjectClass *klass, void *data) |
374 | 559a17a1 | Heinz Graalfs | { |
375 | 559a17a1 | Heinz Graalfs | DeviceClass *dc = DEVICE_CLASS(klass); |
376 | 559a17a1 | Heinz Graalfs | |
377 | 559a17a1 | Heinz Graalfs | dc->bus_type = TYPE_SCLP_EVENTS_BUS; |
378 | 559a17a1 | Heinz Graalfs | dc->unplug = qdev_simple_unplug_cb; |
379 | 559a17a1 | Heinz Graalfs | dc->init = event_qdev_init; |
380 | 559a17a1 | Heinz Graalfs | dc->exit = event_qdev_exit; |
381 | 559a17a1 | Heinz Graalfs | } |
382 | 559a17a1 | Heinz Graalfs | |
383 | 559a17a1 | Heinz Graalfs | static TypeInfo s390_sclp_event_type_info = {
|
384 | 559a17a1 | Heinz Graalfs | .name = TYPE_SCLP_EVENT, |
385 | 559a17a1 | Heinz Graalfs | .parent = TYPE_DEVICE, |
386 | 559a17a1 | Heinz Graalfs | .instance_size = sizeof(SCLPEvent),
|
387 | 559a17a1 | Heinz Graalfs | .class_init = event_class_init, |
388 | 559a17a1 | Heinz Graalfs | .class_size = sizeof(SCLPEventClass),
|
389 | 559a17a1 | Heinz Graalfs | .abstract = true,
|
390 | 559a17a1 | Heinz Graalfs | }; |
391 | 559a17a1 | Heinz Graalfs | |
392 | 559a17a1 | Heinz Graalfs | static void register_types(void) |
393 | 559a17a1 | Heinz Graalfs | { |
394 | 559a17a1 | Heinz Graalfs | type_register_static(&s390_sclp_events_bus_info); |
395 | 559a17a1 | Heinz Graalfs | type_register_static(&s390_sclp_event_facility_info); |
396 | 559a17a1 | Heinz Graalfs | type_register_static(&s390_sclp_event_type_info); |
397 | 559a17a1 | Heinz Graalfs | } |
398 | 559a17a1 | Heinz Graalfs | |
399 | 559a17a1 | Heinz Graalfs | type_init(register_types) |