2012-10-29 03:13:24 +01:00
|
|
|
/*
|
|
|
|
* SCLP event type
|
|
|
|
* Signal Quiesce - trigger system powerdown request
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2012
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Heinz Graalfs <graalfs@de.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or (at your
|
|
|
|
* option) any later version. See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
2019-05-23 16:35:07 +02:00
|
|
|
|
2016-01-26 19:17:00 +01:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/s390x/sclp.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2019-08-12 07:23:59 +02:00
|
|
|
#include "sysemu/runstate.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/s390x/event-facility.h"
|
2012-10-29 03:13:24 +01:00
|
|
|
|
|
|
|
typedef struct SignalQuiesce {
|
|
|
|
EventBufferHeader ebh;
|
|
|
|
uint16_t timeout;
|
|
|
|
uint8_t unit;
|
|
|
|
} QEMU_PACKED SignalQuiesce;
|
|
|
|
|
2013-09-17 13:07:30 +02:00
|
|
|
static bool can_handle_event(uint8_t type)
|
2012-10-29 03:13:24 +01:00
|
|
|
{
|
2013-09-17 13:07:30 +02:00
|
|
|
return type == SCLP_EVENT_SIGNAL_QUIESCE;
|
2012-10-29 03:13:24 +01:00
|
|
|
}
|
|
|
|
|
2018-02-23 18:42:57 +01:00
|
|
|
static sccb_mask_t send_mask(void)
|
2012-10-29 03:13:24 +01:00
|
|
|
{
|
|
|
|
return SCLP_EVENT_MASK_SIGNAL_QUIESCE;
|
|
|
|
}
|
|
|
|
|
2018-02-23 18:42:57 +01:00
|
|
|
static sccb_mask_t receive_mask(void)
|
2012-10-29 03:13:24 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr,
|
|
|
|
int *slen)
|
|
|
|
{
|
|
|
|
SignalQuiesce *sq = (SignalQuiesce *) evt_buf_hdr;
|
|
|
|
|
|
|
|
if (*slen < sizeof(SignalQuiesce)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!event->event_pending) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
event->event_pending = false;
|
|
|
|
|
|
|
|
sq->ebh.length = cpu_to_be16(sizeof(SignalQuiesce));
|
|
|
|
sq->ebh.type = SCLP_EVENT_SIGNAL_QUIESCE;
|
|
|
|
sq->ebh.flags |= SCLP_EVENT_BUFFER_ACCEPTED;
|
|
|
|
/*
|
|
|
|
* system_powerdown does not have a timeout. Fortunately the
|
|
|
|
* timeout value is currently ignored by Linux, anyway
|
|
|
|
*/
|
|
|
|
sq->timeout = cpu_to_be16(0);
|
|
|
|
sq->unit = cpu_to_be16(0);
|
|
|
|
*slen -= sizeof(SignalQuiesce);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-09-11 13:41:26 +02:00
|
|
|
static const VMStateDescription vmstate_sclpquiesce = {
|
2015-05-11 15:31:47 +02:00
|
|
|
.name = TYPE_SCLP_QUIESCE,
|
2012-09-11 13:41:26 +02:00
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
2014-04-16 16:01:33 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2012-09-11 13:41:26 +02:00
|
|
|
VMSTATE_BOOL(event_pending, SCLPEvent),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-29 03:13:24 +01:00
|
|
|
typedef struct QuiesceNotifier QuiesceNotifier;
|
|
|
|
|
|
|
|
static struct QuiesceNotifier {
|
|
|
|
Notifier notifier;
|
|
|
|
SCLPEvent *event;
|
|
|
|
} qn;
|
|
|
|
|
|
|
|
static void quiesce_powerdown_req(Notifier *n, void *opaque)
|
|
|
|
{
|
|
|
|
QuiesceNotifier *qn = container_of(n, QuiesceNotifier, notifier);
|
|
|
|
SCLPEvent *event = qn->event;
|
|
|
|
|
|
|
|
event->event_pending = true;
|
|
|
|
/* trigger SCLP read operation */
|
|
|
|
sclp_service_interrupt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int quiesce_init(SCLPEvent *event)
|
|
|
|
{
|
|
|
|
qn.notifier.notify = quiesce_powerdown_req;
|
|
|
|
qn.event = event;
|
|
|
|
|
|
|
|
qemu_register_powerdown_notifier(&qn.notifier);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-04 12:55:45 +02:00
|
|
|
static void quiesce_reset(DeviceState *dev)
|
|
|
|
{
|
|
|
|
SCLPEvent *event = SCLP_EVENT(dev);
|
|
|
|
|
|
|
|
event->event_pending = false;
|
|
|
|
}
|
|
|
|
|
2012-10-29 03:13:24 +01:00
|
|
|
static void quiesce_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2012-09-11 13:41:26 +02:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-10-29 03:13:24 +01:00
|
|
|
SCLPEventClass *k = SCLP_EVENT_CLASS(klass);
|
|
|
|
|
2013-09-04 12:55:45 +02:00
|
|
|
dc->reset = quiesce_reset;
|
2012-09-11 13:41:26 +02:00
|
|
|
dc->vmsd = &vmstate_sclpquiesce;
|
2015-03-17 13:44:39 +01:00
|
|
|
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
|
2017-10-05 10:45:05 +02:00
|
|
|
/*
|
|
|
|
* Reason: This is just an internal device - the notifier should
|
|
|
|
* not be registered multiple times in quiesce_init()
|
|
|
|
*/
|
|
|
|
dc->user_creatable = false;
|
2012-10-29 03:13:24 +01:00
|
|
|
|
2017-10-05 10:45:05 +02:00
|
|
|
k->init = quiesce_init;
|
2012-10-29 03:13:24 +01:00
|
|
|
k->get_send_mask = send_mask;
|
|
|
|
k->get_receive_mask = receive_mask;
|
2013-09-17 13:07:30 +02:00
|
|
|
k->can_handle_event = can_handle_event;
|
2012-10-29 03:13:24 +01:00
|
|
|
k->read_event_data = read_event_data;
|
|
|
|
k->write_event_data = NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo sclp_quiesce_info = {
|
2015-05-11 15:31:47 +02:00
|
|
|
.name = TYPE_SCLP_QUIESCE,
|
2012-10-29 03:13:24 +01:00
|
|
|
.parent = TYPE_SCLP_EVENT,
|
|
|
|
.instance_size = sizeof(SCLPEvent),
|
|
|
|
.class_init = quiesce_class_init,
|
|
|
|
.class_size = sizeof(SCLPEventClass),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&sclp_quiesce_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(register_types)
|