root / hw / s390x / sclpquiesce.c @ 7e36b7a3
History | View | Annotate | Download (3.2 kB)
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 |
#include <hw/qdev.h> |
15 |
#include "sysemu/sysemu.h" |
16 |
#include "hw/s390x/sclp.h" |
17 |
#include "hw/s390x/event-facility.h" |
18 |
|
19 |
typedef struct SignalQuiesce { |
20 |
EventBufferHeader ebh; |
21 |
uint16_t timeout; |
22 |
uint8_t unit; |
23 |
} QEMU_PACKED SignalQuiesce; |
24 |
|
25 |
static int event_type(void) |
26 |
{ |
27 |
return SCLP_EVENT_SIGNAL_QUIESCE;
|
28 |
} |
29 |
|
30 |
static unsigned int send_mask(void) |
31 |
{ |
32 |
return SCLP_EVENT_MASK_SIGNAL_QUIESCE;
|
33 |
} |
34 |
|
35 |
static unsigned int receive_mask(void) |
36 |
{ |
37 |
return 0; |
38 |
} |
39 |
|
40 |
static int read_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr, |
41 |
int *slen)
|
42 |
{ |
43 |
SignalQuiesce *sq = (SignalQuiesce *) evt_buf_hdr; |
44 |
|
45 |
if (*slen < sizeof(SignalQuiesce)) { |
46 |
return 0; |
47 |
} |
48 |
|
49 |
if (!event->event_pending) {
|
50 |
return 0; |
51 |
} |
52 |
event->event_pending = false;
|
53 |
|
54 |
sq->ebh.length = cpu_to_be16(sizeof(SignalQuiesce));
|
55 |
sq->ebh.type = SCLP_EVENT_SIGNAL_QUIESCE; |
56 |
sq->ebh.flags |= SCLP_EVENT_BUFFER_ACCEPTED; |
57 |
/*
|
58 |
* system_powerdown does not have a timeout. Fortunately the
|
59 |
* timeout value is currently ignored by Linux, anyway
|
60 |
*/
|
61 |
sq->timeout = cpu_to_be16(0);
|
62 |
sq->unit = cpu_to_be16(0);
|
63 |
*slen -= sizeof(SignalQuiesce);
|
64 |
|
65 |
return 1; |
66 |
} |
67 |
|
68 |
static const VMStateDescription vmstate_sclpquiesce = { |
69 |
.name = "sclpquiesce",
|
70 |
.version_id = 0,
|
71 |
.minimum_version_id = 0,
|
72 |
.minimum_version_id_old = 0,
|
73 |
.fields = (VMStateField[]) { |
74 |
VMSTATE_BOOL(event_pending, SCLPEvent), |
75 |
VMSTATE_END_OF_LIST() |
76 |
} |
77 |
}; |
78 |
|
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 |
{ |
98 |
event->event_type = SCLP_EVENT_SIGNAL_QUIESCE; |
99 |
|
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 |
|
108 |
static void quiesce_class_init(ObjectClass *klass, void *data) |
109 |
{ |
110 |
DeviceClass *dc = DEVICE_CLASS(klass); |
111 |
SCLPEventClass *k = SCLP_EVENT_CLASS(klass); |
112 |
|
113 |
dc->vmsd = &vmstate_sclpquiesce; |
114 |
k->init = quiesce_init; |
115 |
|
116 |
k->get_send_mask = send_mask; |
117 |
k->get_receive_mask = receive_mask; |
118 |
k->event_type = event_type; |
119 |
k->read_event_data = read_event_data; |
120 |
k->write_event_data = NULL;
|
121 |
} |
122 |
|
123 |
static const TypeInfo sclp_quiesce_info = { |
124 |
.name = "sclpquiesce",
|
125 |
.parent = TYPE_SCLP_EVENT, |
126 |
.instance_size = sizeof(SCLPEvent),
|
127 |
.class_init = quiesce_class_init, |
128 |
.class_size = sizeof(SCLPEventClass),
|
129 |
}; |
130 |
|
131 |
static void register_types(void) |
132 |
{ |
133 |
type_register_static(&sclp_quiesce_info); |
134 |
} |
135 |
|
136 |
type_init(register_types) |