2024-05-08 16:06:47 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/*
|
|
|
|
* Loongson ipi interrupt support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 Loongson Technology Corporation Limited
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "hw/intc/loongson_ipi.h"
|
|
|
|
#include "qapi/error.h"
|
2024-05-08 16:06:48 +03:00
|
|
|
#include "target/mips/cpu.h"
|
2024-05-08 16:06:47 +03:00
|
|
|
|
2024-07-15 18:50:05 +03:00
|
|
|
static AddressSpace *get_iocsr_as(CPUState *cpu)
|
|
|
|
{
|
2024-05-08 16:06:48 +03:00
|
|
|
if (ase_lcsr_available(&MIPS_CPU(cpu)->env)) {
|
|
|
|
return &MIPS_CPU(cpu)->env.iocsr.as;
|
|
|
|
}
|
2024-07-15 18:50:05 +03:00
|
|
|
|
2024-05-08 16:06:48 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2024-05-08 16:06:49 +03:00
|
|
|
static const MemoryRegionOps loongson_ipi_core_ops = {
|
|
|
|
.read_with_attrs = loongson_ipi_core_readl,
|
|
|
|
.write_with_attrs = loongson_ipi_core_writel,
|
|
|
|
.impl.min_access_size = 4,
|
|
|
|
.impl.max_access_size = 4,
|
|
|
|
.valid.min_access_size = 4,
|
|
|
|
.valid.max_access_size = 8,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2024-07-15 17:57:36 +03:00
|
|
|
static void loongson_ipi_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
2024-07-23 12:55:41 +03:00
|
|
|
LoongsonIPICommonState *sc = LOONGSON_IPI_COMMON(dev);
|
2024-07-15 17:57:36 +03:00
|
|
|
LoongsonIPIState *s = LOONGSON_IPI(dev);
|
2024-07-15 19:42:13 +03:00
|
|
|
LoongsonIPIClass *lic = LOONGSON_IPI_GET_CLASS(dev);
|
2024-07-15 17:57:36 +03:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
|
|
|
|
Error *local_err = NULL;
|
|
|
|
|
2024-07-15 19:42:13 +03:00
|
|
|
lic->parent_realize(dev, &local_err);
|
2024-07-15 17:57:36 +03:00
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
2024-05-08 16:06:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-07-23 12:55:41 +03:00
|
|
|
s->ipi_mmio_mem = g_new0(MemoryRegion, sc->num_cpu);
|
|
|
|
for (unsigned i = 0; i < sc->num_cpu; i++) {
|
2024-05-08 16:06:49 +03:00
|
|
|
g_autofree char *name = g_strdup_printf("loongson_ipi_cpu%d_mmio", i);
|
2024-07-23 12:55:41 +03:00
|
|
|
|
2024-07-15 17:58:55 +03:00
|
|
|
memory_region_init_io(&s->ipi_mmio_mem[i], OBJECT(dev),
|
2024-07-23 12:55:41 +03:00
|
|
|
&loongson_ipi_core_ops, &sc->cpu[i], name, 0x48);
|
2024-07-15 17:58:55 +03:00
|
|
|
sysbus_init_mmio(sbd, &s->ipi_mmio_mem[i]);
|
2024-05-08 16:06:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-15 17:57:36 +03:00
|
|
|
static void loongson_ipi_unrealize(DeviceState *dev)
|
|
|
|
{
|
2024-07-15 17:58:55 +03:00
|
|
|
LoongsonIPIState *s = LOONGSON_IPI(dev);
|
2024-07-15 19:42:13 +03:00
|
|
|
LoongsonIPIClass *k = LOONGSON_IPI_GET_CLASS(dev);
|
2024-07-15 17:58:55 +03:00
|
|
|
|
|
|
|
g_free(s->ipi_mmio_mem);
|
|
|
|
|
2024-07-15 19:42:13 +03:00
|
|
|
k->parent_unrealize(dev);
|
2024-07-15 17:57:36 +03:00
|
|
|
}
|
|
|
|
|
2024-05-08 16:06:47 +03:00
|
|
|
static void loongson_ipi_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2024-07-23 12:25:53 +03:00
|
|
|
LoongsonIPIClass *lic = LOONGSON_IPI_CLASS(klass);
|
2024-07-15 18:50:05 +03:00
|
|
|
LoongsonIPICommonClass *licc = LOONGSON_IPI_COMMON_CLASS(klass);
|
2024-05-08 16:06:47 +03:00
|
|
|
|
2024-07-23 12:25:53 +03:00
|
|
|
device_class_set_parent_realize(dc, loongson_ipi_realize,
|
|
|
|
&lic->parent_realize);
|
|
|
|
device_class_set_parent_unrealize(dc, loongson_ipi_unrealize,
|
|
|
|
&lic->parent_unrealize);
|
2024-07-15 18:50:05 +03:00
|
|
|
licc->get_iocsr_as = get_iocsr_as;
|
2024-07-15 19:24:02 +03:00
|
|
|
licc->cpu_by_arch_id = cpu_by_arch_id;
|
2024-05-08 16:06:47 +03:00
|
|
|
}
|
|
|
|
|
2023-07-10 21:24:51 +03:00
|
|
|
static const TypeInfo loongson_ipi_types[] = {
|
|
|
|
{
|
|
|
|
.name = TYPE_LOONGSON_IPI,
|
2024-07-23 12:25:53 +03:00
|
|
|
.parent = TYPE_LOONGSON_IPI_COMMON,
|
2024-07-15 17:50:51 +03:00
|
|
|
.instance_size = sizeof(LoongsonIPIState),
|
2024-07-23 12:25:53 +03:00
|
|
|
.class_size = sizeof(LoongsonIPIClass),
|
2023-07-10 21:24:51 +03:00
|
|
|
.class_init = loongson_ipi_class_init,
|
|
|
|
}
|
2024-05-08 16:06:47 +03:00
|
|
|
};
|
|
|
|
|
2023-07-10 21:24:51 +03:00
|
|
|
DEFINE_TYPES(loongson_ipi_types)
|