s390_flic.c 6.9 KB
Newer Older
1
/*
2
 * QEMU S390x floating interrupt controller (flic)
3 4 5
 *
 * Copyright 2014 IBM Corp.
 * Author(s): Jens Freimann <jfrei@linux.vnet.ibm.com>
6
 *            Cornelia Huck <cornelia.huck@de.ibm.com>
7 8 9 10 11 12
 *
 * 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.
 */

P
Peter Maydell 已提交
13
#include "qemu/osdep.h"
14 15
#include "qemu/error-report.h"
#include "hw/sysbus.h"
16
#include "hw/s390x/ioinst.h"
17
#include "hw/s390x/s390_flic.h"
18
#include "hw/s390x/css.h"
19
#include "trace.h"
20
#include "cpu.h"
21 22
#include "hw/qdev.h"
#include "qapi/error.h"
23
#include "hw/s390x/s390-virtio-ccw.h"
24

25
S390FLICState *s390_get_flic(void)
26
{
F
Fei Li 已提交
27
    static S390FLICState *fs;
28

29
    if (!fs) {
F
Fei Li 已提交
30 31 32 33 34
        fs = S390_FLIC_COMMON(object_resolve_path(TYPE_KVM_S390_FLIC, NULL));
        if (!fs) {
            fs = S390_FLIC_COMMON(object_resolve_path(TYPE_QEMU_S390_FLIC,
                                                      NULL));
        }
35
    }
36
    return fs;
37 38
}

39
void s390_flic_init(void)
40
{
41
    DeviceState *dev;
42

43 44 45 46 47
    dev = s390_flic_kvm_create();
    if (!dev) {
        dev = qdev_create(NULL, TYPE_QEMU_S390_FLIC);
        object_property_add_child(qdev_get_machine(), TYPE_QEMU_S390_FLIC,
                                  OBJECT(dev), NULL);
48
    }
49
    qdev_init_nofail(dev);
50 51
}

52 53
static int qemu_s390_register_io_adapter(S390FLICState *fs, uint32_t id,
                                         uint8_t isc, bool swap,
54
                                         bool is_maskable, uint8_t flags)
55 56 57 58 59
{
    /* nothing to do */
    return 0;
}

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
static int qemu_s390_io_adapter_map(S390FLICState *fs, uint32_t id,
                                    uint64_t map_addr, bool do_map)
{
    /* nothing to do */
    return 0;
}

static int qemu_s390_add_adapter_routes(S390FLICState *fs,
                                        AdapterRoutes *routes)
{
    return -ENOSYS;
}

static void qemu_s390_release_adapter_routes(S390FLICState *fs,
                                             AdapterRoutes *routes)
{
}

78 79 80 81 82 83 84
static int qemu_s390_clear_io_flic(S390FLICState *fs, uint16_t subchannel_id,
                           uint16_t subchannel_nr)
{
    /* Fixme TCG */
    return -ENOSYS;
}

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
static int qemu_s390_modify_ais_mode(S390FLICState *fs, uint8_t isc,
                                     uint16_t mode)
{
    QEMUS390FLICState *flic  = QEMU_S390_FLIC(fs);

    switch (mode) {
    case SIC_IRQ_MODE_ALL:
        flic->simm &= ~AIS_MODE_MASK(isc);
        flic->nimm &= ~AIS_MODE_MASK(isc);
        break;
    case SIC_IRQ_MODE_SINGLE:
        flic->simm |= AIS_MODE_MASK(isc);
        flic->nimm &= ~AIS_MODE_MASK(isc);
        break;
    default:
        return -EINVAL;
    }

    return 0;
}

106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
static int qemu_s390_inject_airq(S390FLICState *fs, uint8_t type,
                                 uint8_t isc, uint8_t flags)
{
    QEMUS390FLICState *flic = QEMU_S390_FLIC(fs);
    bool flag = flags & S390_ADAPTER_SUPPRESSIBLE;
    uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI;

    if (flag && (flic->nimm & AIS_MODE_MASK(isc))) {
        trace_qemu_s390_airq_suppressed(type, isc);
        return 0;
    }

    s390_io_interrupt(0, 0, 0, io_int_word);

    if (flag && (flic->simm & AIS_MODE_MASK(isc))) {
        flic->nimm |= AIS_MODE_MASK(isc);
        trace_qemu_s390_suppress_airq(isc, "Single-Interruption Mode",
                                      "NO-Interruptions Mode");
    }

    return 0;
}

129 130 131 132 133 134 135 136
static void qemu_s390_flic_reset(DeviceState *dev)
{
    QEMUS390FLICState *flic = QEMU_S390_FLIC(dev);

    flic->simm = 0;
    flic->nimm = 0;
}

137 138
static void qemu_s390_flic_class_init(ObjectClass *oc, void *data)
{
139
    DeviceClass *dc = DEVICE_CLASS(oc);
140 141
    S390FLICStateClass *fsc = S390_FLIC_COMMON_CLASS(oc);

142
    dc->reset = qemu_s390_flic_reset;
143
    fsc->register_io_adapter = qemu_s390_register_io_adapter;
144 145 146
    fsc->io_adapter_map = qemu_s390_io_adapter_map;
    fsc->add_adapter_routes = qemu_s390_add_adapter_routes;
    fsc->release_adapter_routes = qemu_s390_release_adapter_routes;
147
    fsc->clear_io_irq = qemu_s390_clear_io_flic;
148
    fsc->modify_ais_mode = qemu_s390_modify_ais_mode;
149
    fsc->inject_airq = qemu_s390_inject_airq;
150 151
}

152 153 154 155 156 157 158 159
static Property s390_flic_common_properties[] = {
    DEFINE_PROP_UINT32("adapter_routes_max_batch", S390FLICState,
                       adapter_routes_max_batch, ADAPTER_ROUTES_MAX_GSI),
    DEFINE_PROP_END_OF_LIST(),
};

static void s390_flic_common_realize(DeviceState *dev, Error **errp)
{
160 161
    S390FLICState *fs = S390_FLIC_COMMON(dev);
    uint32_t max_batch = fs->adapter_routes_max_batch;
162 163

    if (max_batch > ADAPTER_ROUTES_MAX_GSI) {
164 165
        error_setg(errp, "flic property adapter_routes_max_batch too big"
                   " (%d > %d)", max_batch, ADAPTER_ROUTES_MAX_GSI);
166
        return;
167
    }
168

169
    fs->ais_supported = s390_has_feat(S390_FEAT_ADAPTER_INT_SUPPRESSION);
170 171 172 173 174 175 176 177 178 179
}

static void s390_flic_class_init(ObjectClass *oc, void *data)
{
    DeviceClass *dc = DEVICE_CLASS(oc);

    dc->props = s390_flic_common_properties;
    dc->realize = s390_flic_common_realize;
}

180 181 182 183
static const TypeInfo qemu_s390_flic_info = {
    .name          = TYPE_QEMU_S390_FLIC,
    .parent        = TYPE_S390_FLIC_COMMON,
    .instance_size = sizeof(QEMUS390FLICState),
184
    .class_init    = qemu_s390_flic_class_init,
185
};
186

187

188 189
static const TypeInfo s390_flic_common_info = {
    .name          = TYPE_S390_FLIC_COMMON,
190
    .parent        = TYPE_SYS_BUS_DEVICE,
191
    .instance_size = sizeof(S390FLICState),
192
    .class_init    = s390_flic_class_init,
193
    .class_size    = sizeof(S390FLICStateClass),
194 195
};

196
static void qemu_s390_flic_register_types(void)
197
{
198 199
    type_register_static(&s390_flic_common_info);
    type_register_static(&qemu_s390_flic_info);
200 201
}

202
type_init(qemu_s390_flic_register_types)
203

204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
static bool adapter_info_so_needed(void *opaque)
{
    return css_migration_enabled();
}

const VMStateDescription vmstate_adapter_info_so = {
    .name = "s390_adapter_info/summary_offset",
    .version_id = 1,
    .minimum_version_id = 1,
    .needed = adapter_info_so_needed,
    .fields = (VMStateField[]) {
        VMSTATE_UINT32(summary_offset, AdapterInfo),
        VMSTATE_END_OF_LIST()
    }
};

220 221 222 223 224 225 226 227 228 229 230 231 232
const VMStateDescription vmstate_adapter_info = {
    .name = "s390_adapter_info",
    .version_id = 1,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_UINT64(ind_offset, AdapterInfo),
        /*
         * We do not have to migrate neither the id nor the addresses.
         * The id is set by css_register_io_adapter and the addresses
         * are set based on the IndAddr objects after those get mapped.
         */
        VMSTATE_END_OF_LIST()
    },
233 234 235 236
    .subsections = (const VMStateDescription * []) {
        &vmstate_adapter_info_so,
        NULL
    }
237 238 239 240 241 242 243 244 245 246 247 248 249
};

const VMStateDescription vmstate_adapter_routes = {

    .name = "s390_adapter_routes",
    .version_id = 1,
    .minimum_version_id = 1,
    .fields = (VMStateField[]) {
        VMSTATE_STRUCT(adapter, AdapterRoutes, 1, vmstate_adapter_info,
                       AdapterInfo),
        VMSTATE_END_OF_LIST()
    }
};