qemu/hw/s390x/sclpquiesce.c
<<
>>
Prefs
   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
  15#include "qemu/osdep.h"
  16#include "hw/s390x/sclp.h"
  17#include "migration/vmstate.h"
  18#include "qemu/module.h"
  19#include "sysemu/runstate.h"
  20#include "hw/s390x/event-facility.h"
  21
  22typedef struct SignalQuiesce {
  23    EventBufferHeader ebh;
  24    uint16_t timeout;
  25    uint8_t unit;
  26} QEMU_PACKED SignalQuiesce;
  27
  28static bool can_handle_event(uint8_t type)
  29{
  30    return type == SCLP_EVENT_SIGNAL_QUIESCE;
  31}
  32
  33static sccb_mask_t send_mask(void)
  34{
  35    return SCLP_EVENT_MASK_SIGNAL_QUIESCE;
  36}
  37
  38static sccb_mask_t receive_mask(void)
  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
  71static const VMStateDescription vmstate_sclpquiesce = {
  72    .name = TYPE_SCLP_QUIESCE,
  73    .version_id = 0,
  74    .minimum_version_id = 0,
  75    .fields = (VMStateField[]) {
  76        VMSTATE_BOOL(event_pending, SCLPEvent),
  77        VMSTATE_END_OF_LIST()
  78     }
  79};
  80
  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{
 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
 108static void quiesce_reset(DeviceState *dev)
 109{
 110   SCLPEvent *event = SCLP_EVENT(dev);
 111
 112   event->event_pending = false;
 113}
 114
 115static void quiesce_class_init(ObjectClass *klass, void *data)
 116{
 117    DeviceClass *dc = DEVICE_CLASS(klass);
 118    SCLPEventClass *k = SCLP_EVENT_CLASS(klass);
 119
 120    dc->reset = quiesce_reset;
 121    dc->vmsd = &vmstate_sclpquiesce;
 122    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
 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;
 128
 129    k->init = quiesce_init;
 130    k->get_send_mask = send_mask;
 131    k->get_receive_mask = receive_mask;
 132    k->can_handle_event = can_handle_event;
 133    k->read_event_data = read_event_data;
 134    k->write_event_data = NULL;
 135}
 136
 137static const TypeInfo sclp_quiesce_info = {
 138    .name          = TYPE_SCLP_QUIESCE,
 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)
 151