2021-03-13 00:41:43 +03:00
|
|
|
/*
|
2021-11-03 13:53:11 +03:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2021-03-13 00:41:43 +03:00
|
|
|
*
|
|
|
|
* QEMU Motorola 680x0 IRQ Controller
|
|
|
|
*
|
|
|
|
* (c) 2020 Laurent Vivier <laurent@vivier.eu>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "migration/vmstate.h"
|
2023-10-24 11:30:04 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2021-03-13 00:41:43 +03:00
|
|
|
#include "hw/nmi.h"
|
|
|
|
#include "hw/intc/intc.h"
|
|
|
|
#include "hw/intc/m68k_irqc.h"
|
|
|
|
|
|
|
|
|
|
|
|
static bool m68k_irqc_get_statistics(InterruptStatsProvider *obj,
|
|
|
|
uint64_t **irq_counts, unsigned int *nb_irqs)
|
|
|
|
{
|
|
|
|
M68KIRQCState *s = M68K_IRQC(obj);
|
|
|
|
|
|
|
|
*irq_counts = s->stats_irq_count;
|
|
|
|
*nb_irqs = ARRAY_SIZE(s->stats_irq_count);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-06-07 13:47:04 +03:00
|
|
|
static void m68k_irqc_print_info(InterruptStatsProvider *obj, GString *buf)
|
2021-03-13 00:41:43 +03:00
|
|
|
{
|
|
|
|
M68KIRQCState *s = M68K_IRQC(obj);
|
2024-06-07 13:47:04 +03:00
|
|
|
g_string_append_printf(buf, "m68k-irqc: ipr=0x%x\n", s->ipr);
|
2021-03-13 00:41:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void m68k_set_irq(void *opaque, int irq, int level)
|
|
|
|
{
|
|
|
|
M68KIRQCState *s = opaque;
|
2023-10-24 11:30:04 +03:00
|
|
|
M68kCPU *cpu = M68K_CPU(s->cpu);
|
2021-03-13 00:41:43 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (level) {
|
|
|
|
s->ipr |= 1 << irq;
|
|
|
|
s->stats_irq_count[irq]++;
|
|
|
|
} else {
|
|
|
|
s->ipr &= ~(1 << irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = M68K_IRQC_LEVEL_7; i >= M68K_IRQC_LEVEL_1; i--) {
|
|
|
|
if ((s->ipr >> i) & 1) {
|
|
|
|
m68k_set_irq_level(cpu, i + 1, i + M68K_IRQC_AUTOVECTOR_BASE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m68k_set_irq_level(cpu, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void m68k_irqc_reset(DeviceState *d)
|
|
|
|
{
|
|
|
|
M68KIRQCState *s = M68K_IRQC(d);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
s->ipr = 0;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(s->stats_irq_count); i++) {
|
|
|
|
s->stats_irq_count[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void m68k_irqc_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
qdev_init_gpio_in(DEVICE(obj), m68k_set_irq, M68K_IRQC_LEVEL_NUM);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void m68k_nmi(NMIState *n, int cpu_index, Error **errp)
|
|
|
|
{
|
|
|
|
m68k_set_irq(n, M68K_IRQC_LEVEL_7, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_m68k_irqc = {
|
|
|
|
.name = "m68k-irqc",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2023-12-21 06:16:15 +03:00
|
|
|
.fields = (const VMStateField[]) {
|
2021-03-13 00:41:43 +03:00
|
|
|
VMSTATE_UINT8(ipr, M68KIRQCState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-10-24 11:30:04 +03:00
|
|
|
static Property m68k_irqc_properties[] = {
|
|
|
|
DEFINE_PROP_LINK("m68k-cpu", M68KIRQCState, cpu,
|
|
|
|
TYPE_M68K_CPU, ArchCPU *),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2021-03-13 00:41:43 +03:00
|
|
|
static void m68k_irqc_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
NMIClass *nc = NMI_CLASS(oc);
|
|
|
|
InterruptStatsProviderClass *ic = INTERRUPT_STATS_PROVIDER_CLASS(oc);
|
|
|
|
|
2023-10-24 11:30:04 +03:00
|
|
|
device_class_set_props(dc, m68k_irqc_properties);
|
2021-03-13 00:41:43 +03:00
|
|
|
nc->nmi_monitor_handler = m68k_nmi;
|
2024-09-13 17:31:44 +03:00
|
|
|
device_class_set_legacy_reset(dc, m68k_irqc_reset);
|
2021-03-13 00:41:43 +03:00
|
|
|
dc->vmsd = &vmstate_m68k_irqc;
|
|
|
|
ic->get_statistics = m68k_irqc_get_statistics;
|
|
|
|
ic->print_info = m68k_irqc_print_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo m68k_irqc_type_info = {
|
|
|
|
.name = TYPE_M68K_IRQC,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(M68KIRQCState),
|
|
|
|
.instance_init = m68k_irqc_instance_init,
|
|
|
|
.class_init = m68k_irqc_class_init,
|
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_NMI },
|
|
|
|
{ TYPE_INTERRUPT_STATS_PROVIDER },
|
|
|
|
{ }
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void q800_irq_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&m68k_irqc_type_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(q800_irq_register_types);
|