2013-07-16 11:04:04 +04:00
|
|
|
/*
|
2014-04-17 17:59:48 +04:00
|
|
|
* QEMU S390x floating interrupt controller (flic)
|
2013-07-16 11:04:04 +04:00
|
|
|
*
|
|
|
|
* Copyright 2014 IBM Corp.
|
|
|
|
* Author(s): Jens Freimann <jfrei@linux.vnet.ibm.com>
|
2014-04-17 17:59:48 +04:00
|
|
|
* Cornelia Huck <cornelia.huck@de.ibm.com>
|
2013-07-16 11:04:04 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:19 +03:00
|
|
|
#include "qemu/osdep.h"
|
2013-07-16 11:04:04 +04:00
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "hw/sysbus.h"
|
2017-02-17 10:00:59 +03:00
|
|
|
#include "hw/s390x/ioinst.h"
|
2013-07-16 11:04:04 +04:00
|
|
|
#include "hw/s390x/s390_flic.h"
|
2017-02-17 10:00:59 +03:00
|
|
|
#include "hw/s390x/css.h"
|
2013-07-16 11:04:04 +04:00
|
|
|
#include "trace.h"
|
2017-02-17 10:00:59 +03:00
|
|
|
#include "cpu.h"
|
2016-12-09 15:51:46 +03:00
|
|
|
#include "hw/qdev.h"
|
|
|
|
#include "qapi/error.h"
|
2017-07-04 00:34:14 +03:00
|
|
|
#include "hw/s390x/s390-virtio-ccw.h"
|
2013-07-16 11:04:04 +04:00
|
|
|
|
2014-04-17 17:59:48 +04:00
|
|
|
S390FLICState *s390_get_flic(void)
|
2013-09-05 15:54:39 +04:00
|
|
|
{
|
2017-03-17 12:28:30 +03:00
|
|
|
static S390FLICState *fs;
|
2013-09-05 15:54:39 +04:00
|
|
|
|
2014-04-17 17:59:48 +04:00
|
|
|
if (!fs) {
|
2018-01-29 15:56:08 +03:00
|
|
|
fs = S390_FLIC_COMMON(object_resolve_path_type("",
|
|
|
|
TYPE_S390_FLIC_COMMON,
|
|
|
|
NULL));
|
2013-09-05 15:54:39 +04:00
|
|
|
}
|
2014-04-17 17:59:48 +04:00
|
|
|
return fs;
|
2013-09-05 15:54:39 +04:00
|
|
|
}
|
|
|
|
|
2014-04-17 17:59:48 +04:00
|
|
|
void s390_flic_init(void)
|
2013-07-16 11:04:04 +04:00
|
|
|
{
|
2014-04-17 17:59:48 +04:00
|
|
|
DeviceState *dev;
|
2013-07-16 11:04:04 +04:00
|
|
|
|
2018-01-29 15:56:07 +03:00
|
|
|
if (kvm_enabled()) {
|
|
|
|
dev = qdev_create(NULL, TYPE_KVM_S390_FLIC);
|
|
|
|
object_property_add_child(qdev_get_machine(), TYPE_KVM_S390_FLIC,
|
|
|
|
OBJECT(dev), NULL);
|
|
|
|
} else {
|
2014-04-17 17:59:48 +04:00
|
|
|
dev = qdev_create(NULL, TYPE_QEMU_S390_FLIC);
|
|
|
|
object_property_add_child(qdev_get_machine(), TYPE_QEMU_S390_FLIC,
|
|
|
|
OBJECT(dev), NULL);
|
2013-07-16 11:04:04 +04:00
|
|
|
}
|
2015-02-05 12:34:49 +03:00
|
|
|
qdev_init_nofail(dev);
|
2013-07-16 11:04:04 +04:00
|
|
|
}
|
|
|
|
|
2013-07-15 19:45:03 +04:00
|
|
|
static int qemu_s390_register_io_adapter(S390FLICState *fs, uint32_t id,
|
|
|
|
uint8_t isc, bool swap,
|
2017-03-07 06:07:44 +03:00
|
|
|
bool is_maskable, uint8_t flags)
|
2013-07-15 19:45:03 +04:00
|
|
|
{
|
|
|
|
/* nothing to do */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-15 19:45:03 +04:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-01-27 15:03:44 +03:00
|
|
|
static int qemu_s390_clear_io_flic(S390FLICState *fs, uint16_t subchannel_id,
|
|
|
|
uint16_t subchannel_nr)
|
|
|
|
{
|
|
|
|
/* Fixme TCG */
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2017-02-17 09:23:44 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-02-17 10:00:59 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-01-29 15:56:10 +03:00
|
|
|
static void qemu_s390_inject_service(S390FLICState *fs, uint32_t parm)
|
|
|
|
{
|
|
|
|
|
|
|
|
S390CPU *dummy_cpu = s390_cpu_addr2state(0);
|
|
|
|
|
|
|
|
/* FIXME: don't inject into dummy CPU */
|
|
|
|
cpu_inject_service(dummy_cpu, parm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qemu_s390_inject_io(S390FLICState *fs, uint16_t subchannel_id,
|
|
|
|
uint16_t subchannel_nr, uint32_t io_int_parm,
|
|
|
|
uint32_t io_int_word)
|
|
|
|
{
|
|
|
|
S390CPU *dummy_cpu = s390_cpu_addr2state(0);
|
|
|
|
|
|
|
|
/* FIXME: don't inject into dummy CPU */
|
|
|
|
cpu_inject_io(dummy_cpu, subchannel_id, subchannel_nr, io_int_parm,
|
|
|
|
io_int_word);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qemu_s390_inject_crw_mchk(S390FLICState *fs)
|
|
|
|
{
|
|
|
|
S390CPU *dummy_cpu = s390_cpu_addr2state(0);
|
|
|
|
|
|
|
|
/* FIXME: don't inject into dummy CPU */
|
|
|
|
cpu_inject_crw_mchk(dummy_cpu);
|
|
|
|
}
|
|
|
|
|
2017-02-17 09:23:44 +03:00
|
|
|
static void qemu_s390_flic_reset(DeviceState *dev)
|
|
|
|
{
|
|
|
|
QEMUS390FLICState *flic = QEMU_S390_FLIC(dev);
|
|
|
|
|
|
|
|
flic->simm = 0;
|
|
|
|
flic->nimm = 0;
|
|
|
|
}
|
|
|
|
|
2017-05-16 13:58:44 +03:00
|
|
|
bool ais_needed(void *opaque)
|
|
|
|
{
|
|
|
|
S390FLICState *s = opaque;
|
|
|
|
|
|
|
|
return s->ais_supported;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription qemu_s390_flic_vmstate = {
|
|
|
|
.name = "qemu-s390-flic",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.needed = ais_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT8(simm, QEMUS390FLICState),
|
|
|
|
VMSTATE_UINT8(nimm, QEMUS390FLICState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-15 19:45:03 +04:00
|
|
|
static void qemu_s390_flic_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
2017-02-17 09:23:44 +03:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
2013-07-15 19:45:03 +04:00
|
|
|
S390FLICStateClass *fsc = S390_FLIC_COMMON_CLASS(oc);
|
|
|
|
|
2017-02-17 09:23:44 +03:00
|
|
|
dc->reset = qemu_s390_flic_reset;
|
2017-05-16 13:58:44 +03:00
|
|
|
dc->vmsd = &qemu_s390_flic_vmstate;
|
2013-07-15 19:45:03 +04:00
|
|
|
fsc->register_io_adapter = qemu_s390_register_io_adapter;
|
2013-07-15 19:45:03 +04:00
|
|
|
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;
|
2016-01-27 15:03:44 +03:00
|
|
|
fsc->clear_io_irq = qemu_s390_clear_io_flic;
|
2017-02-17 09:23:44 +03:00
|
|
|
fsc->modify_ais_mode = qemu_s390_modify_ais_mode;
|
2017-02-17 10:00:59 +03:00
|
|
|
fsc->inject_airq = qemu_s390_inject_airq;
|
2018-01-29 15:56:10 +03:00
|
|
|
fsc->inject_service = qemu_s390_inject_service;
|
|
|
|
fsc->inject_io = qemu_s390_inject_io;
|
|
|
|
fsc->inject_crw_mchk = qemu_s390_inject_crw_mchk;
|
2013-07-15 19:45:03 +04:00
|
|
|
}
|
|
|
|
|
2016-12-09 15:51:46 +03:00
|
|
|
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)
|
|
|
|
{
|
2017-02-17 09:23:44 +03:00
|
|
|
S390FLICState *fs = S390_FLIC_COMMON(dev);
|
|
|
|
uint32_t max_batch = fs->adapter_routes_max_batch;
|
2016-12-09 15:51:46 +03:00
|
|
|
|
|
|
|
if (max_batch > ADAPTER_ROUTES_MAX_GSI) {
|
2017-06-14 16:39:48 +03:00
|
|
|
error_setg(errp, "flic property adapter_routes_max_batch too big"
|
|
|
|
" (%d > %d)", max_batch, ADAPTER_ROUTES_MAX_GSI);
|
2017-06-14 08:25:58 +03:00
|
|
|
return;
|
2016-12-09 15:51:46 +03:00
|
|
|
}
|
2017-02-17 09:23:44 +03:00
|
|
|
|
2017-06-14 08:25:58 +03:00
|
|
|
fs->ais_supported = s390_has_feat(S390_FEAT_ADAPTER_INT_SUPPRESSION);
|
2016-12-09 15:51:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-04-17 17:59:48 +04:00
|
|
|
static const TypeInfo qemu_s390_flic_info = {
|
|
|
|
.name = TYPE_QEMU_S390_FLIC,
|
|
|
|
.parent = TYPE_S390_FLIC_COMMON,
|
|
|
|
.instance_size = sizeof(QEMUS390FLICState),
|
2013-07-15 19:45:03 +04:00
|
|
|
.class_init = qemu_s390_flic_class_init,
|
2014-04-17 17:59:48 +04:00
|
|
|
};
|
2013-07-16 11:04:04 +04:00
|
|
|
|
2016-12-09 15:51:46 +03:00
|
|
|
|
2014-04-17 17:59:48 +04:00
|
|
|
static const TypeInfo s390_flic_common_info = {
|
|
|
|
.name = TYPE_S390_FLIC_COMMON,
|
2013-07-16 11:04:04 +04:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2014-04-17 17:59:48 +04:00
|
|
|
.instance_size = sizeof(S390FLICState),
|
2016-12-09 15:51:46 +03:00
|
|
|
.class_init = s390_flic_class_init,
|
2014-04-17 17:59:48 +04:00
|
|
|
.class_size = sizeof(S390FLICStateClass),
|
2013-07-16 11:04:04 +04:00
|
|
|
};
|
|
|
|
|
2014-04-17 17:59:48 +04:00
|
|
|
static void qemu_s390_flic_register_types(void)
|
2013-07-16 11:04:04 +04:00
|
|
|
{
|
2014-04-17 17:59:48 +04:00
|
|
|
type_register_static(&s390_flic_common_info);
|
|
|
|
type_register_static(&qemu_s390_flic_info);
|
2013-07-16 11:04:04 +04:00
|
|
|
}
|
|
|
|
|
2014-04-17 17:59:48 +04:00
|
|
|
type_init(qemu_s390_flic_register_types)
|
2017-07-04 00:34:14 +03:00
|
|
|
|
2017-07-11 17:54:38 +03:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-04 00:34:14 +03:00
|
|
|
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()
|
|
|
|
},
|
2017-07-11 17:54:38 +03:00
|
|
|
.subsections = (const VMStateDescription * []) {
|
|
|
|
&vmstate_adapter_info_so,
|
|
|
|
NULL
|
|
|
|
}
|
2017-07-04 00:34:14 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
};
|