2016-10-04 15:28:08 +03:00
|
|
|
/*
|
|
|
|
* ITS base class for a GICv3-based system
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015 Samsung Electronics Co., Ltd.
|
|
|
|
* Written by Pavel Fedin
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "hw/pci/msi.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2016-10-04 15:28:08 +03:00
|
|
|
#include "hw/intc/arm_gicv3_its_common.h"
|
|
|
|
#include "qemu/log.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2023-04-05 14:48:26 +03:00
|
|
|
#include "sysemu/kvm.h"
|
2016-10-04 15:28:08 +03:00
|
|
|
|
2017-09-25 14:29:12 +03:00
|
|
|
static int gicv3_its_pre_save(void *opaque)
|
2016-10-04 15:28:08 +03:00
|
|
|
{
|
|
|
|
GICv3ITSState *s = (GICv3ITSState *)opaque;
|
|
|
|
GICv3ITSCommonClass *c = ARM_GICV3_ITS_COMMON_GET_CLASS(s);
|
|
|
|
|
|
|
|
if (c->pre_save) {
|
|
|
|
c->pre_save(s);
|
|
|
|
}
|
2017-09-25 14:29:12 +03:00
|
|
|
|
|
|
|
return 0;
|
2016-10-04 15:28:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int gicv3_its_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
GICv3ITSState *s = (GICv3ITSState *)opaque;
|
|
|
|
GICv3ITSCommonClass *c = ARM_GICV3_ITS_COMMON_GET_CLASS(s);
|
|
|
|
|
|
|
|
if (c->post_load) {
|
|
|
|
c->post_load(s);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_its = {
|
|
|
|
.name = "arm_gicv3_its",
|
|
|
|
.pre_save = gicv3_its_pre_save,
|
|
|
|
.post_load = gicv3_its_post_load,
|
2017-06-13 16:57:01 +03:00
|
|
|
.priority = MIG_PRI_GICV3_ITS,
|
2017-06-13 16:57:00 +03:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(ctlr, GICv3ITSState),
|
|
|
|
VMSTATE_UINT32(iidr, GICv3ITSState),
|
|
|
|
VMSTATE_UINT64(cbaser, GICv3ITSState),
|
|
|
|
VMSTATE_UINT64(cwriter, GICv3ITSState),
|
|
|
|
VMSTATE_UINT64(creadr, GICv3ITSState),
|
|
|
|
VMSTATE_UINT64_ARRAY(baser, GICv3ITSState, 8),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
},
|
2016-10-04 15:28:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static MemTxResult gicv3_its_trans_read(void *opaque, hwaddr offset,
|
|
|
|
uint64_t *data, unsigned size,
|
|
|
|
MemTxAttrs attrs)
|
|
|
|
{
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "ITS read at offset 0x%"PRIx64"\n", offset);
|
2018-01-11 16:25:40 +03:00
|
|
|
*data = 0;
|
|
|
|
return MEMTX_OK;
|
2016-10-04 15:28:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static MemTxResult gicv3_its_trans_write(void *opaque, hwaddr offset,
|
|
|
|
uint64_t value, unsigned size,
|
|
|
|
MemTxAttrs attrs)
|
|
|
|
{
|
|
|
|
if (offset == 0x0040 && ((size == 2) || (size == 4))) {
|
|
|
|
GICv3ITSState *s = ARM_GICV3_ITS_COMMON(opaque);
|
|
|
|
GICv3ITSCommonClass *c = ARM_GICV3_ITS_COMMON_GET_CLASS(s);
|
|
|
|
int ret = c->send_msi(s, le64_to_cpu(value), attrs.requester_id);
|
|
|
|
|
|
|
|
if (ret <= 0) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"ITS: Error sending MSI: %s\n", strerror(-ret));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"ITS write at bad offset 0x%"PRIx64"\n", offset);
|
|
|
|
}
|
2018-01-11 16:25:40 +03:00
|
|
|
return MEMTX_OK;
|
2016-10-04 15:28:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps gicv3_its_trans_ops = {
|
|
|
|
.read_with_attrs = gicv3_its_trans_read,
|
|
|
|
.write_with_attrs = gicv3_its_trans_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2021-09-13 18:07:23 +03:00
|
|
|
void gicv3_its_init_mmio(GICv3ITSState *s, const MemoryRegionOps *ops,
|
|
|
|
const MemoryRegionOps *tops)
|
2016-10-04 15:28:08 +03:00
|
|
|
{
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(s);
|
|
|
|
|
|
|
|
memory_region_init_io(&s->iomem_its_cntrl, OBJECT(s), ops, s,
|
|
|
|
"control", ITS_CONTROL_SIZE);
|
|
|
|
memory_region_init_io(&s->iomem_its_translation, OBJECT(s),
|
2021-09-13 18:07:23 +03:00
|
|
|
tops ? tops : &gicv3_its_trans_ops, s,
|
2016-10-04 15:28:08 +03:00
|
|
|
"translation", ITS_TRANS_SIZE);
|
|
|
|
|
|
|
|
/* Our two regions are always adjacent, therefore we now combine them
|
|
|
|
* into a single one in order to make our users' life easier.
|
|
|
|
*/
|
|
|
|
memory_region_init(&s->iomem_main, OBJECT(s), "gicv3_its", ITS_SIZE);
|
|
|
|
memory_region_add_subregion(&s->iomem_main, 0, &s->iomem_its_cntrl);
|
|
|
|
memory_region_add_subregion(&s->iomem_main, ITS_CONTROL_SIZE,
|
|
|
|
&s->iomem_its_translation);
|
|
|
|
sysbus_init_mmio(sbd, &s->iomem_main);
|
|
|
|
|
|
|
|
msi_nonbroken = true;
|
|
|
|
}
|
|
|
|
|
2022-12-14 17:27:12 +03:00
|
|
|
static void gicv3_its_common_reset_hold(Object *obj)
|
2016-10-04 15:28:08 +03:00
|
|
|
{
|
2022-12-14 17:27:12 +03:00
|
|
|
GICv3ITSState *s = ARM_GICV3_ITS_COMMON(obj);
|
2016-10-04 15:28:08 +03:00
|
|
|
|
|
|
|
s->ctlr = 0;
|
|
|
|
s->cbaser = 0;
|
|
|
|
s->cwriter = 0;
|
|
|
|
s->creadr = 0;
|
2017-06-13 16:57:00 +03:00
|
|
|
s->iidr = 0;
|
2016-10-04 15:28:08 +03:00
|
|
|
memset(&s->baser, 0, sizeof(s->baser));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gicv3_its_common_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2022-12-14 17:27:12 +03:00
|
|
|
ResettableClass *rc = RESETTABLE_CLASS(klass);
|
2016-10-04 15:28:08 +03:00
|
|
|
|
2022-12-14 17:27:12 +03:00
|
|
|
rc->phases.hold = gicv3_its_common_reset_hold;
|
2016-10-04 15:28:08 +03:00
|
|
|
dc->vmsd = &vmstate_its;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo gicv3_its_common_info = {
|
|
|
|
.name = TYPE_ARM_GICV3_ITS_COMMON,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(GICv3ITSState),
|
|
|
|
.class_size = sizeof(GICv3ITSCommonClass),
|
|
|
|
.class_init = gicv3_its_common_class_init,
|
|
|
|
.abstract = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void gicv3_its_common_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&gicv3_its_common_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(gicv3_its_common_register_types)
|
2023-04-05 14:48:26 +03:00
|
|
|
|
|
|
|
const char *its_class_name(void)
|
|
|
|
{
|
|
|
|
if (kvm_irqchip_in_kernel()) {
|
2023-10-17 14:24:33 +03:00
|
|
|
return "arm-its-kvm";
|
2023-04-05 14:48:26 +03:00
|
|
|
} else {
|
|
|
|
/* Software emulation based model */
|
|
|
|
return "arm-gicv3-its";
|
|
|
|
}
|
|
|
|
}
|