2 * SPDX-License-Identifier: GPL-2.0-or-later
4 * QEMU Motorola 680x0 IRQ Controller
6 * (c) 2020 Laurent Vivier <laurent@vivier.eu>
10 #include "qemu/osdep.h"
12 #include "migration/vmstate.h"
13 #include "hw/qdev-properties.h"
15 #include "hw/intc/intc.h"
16 #include "hw/intc/m68k_irqc.h"
19 static bool m68k_irqc_get_statistics(InterruptStatsProvider
*obj
,
20 uint64_t **irq_counts
, unsigned int *nb_irqs
)
22 M68KIRQCState
*s
= M68K_IRQC(obj
);
24 *irq_counts
= s
->stats_irq_count
;
25 *nb_irqs
= ARRAY_SIZE(s
->stats_irq_count
);
29 static void m68k_irqc_print_info(InterruptStatsProvider
*obj
, GString
*buf
)
31 M68KIRQCState
*s
= M68K_IRQC(obj
);
32 g_string_append_printf(buf
, "m68k-irqc: ipr=0x%x\n", s
->ipr
);
35 static void m68k_set_irq(void *opaque
, int irq
, int level
)
37 M68KIRQCState
*s
= opaque
;
38 M68kCPU
*cpu
= M68K_CPU(s
->cpu
);
43 s
->stats_irq_count
[irq
]++;
45 s
->ipr
&= ~(1 << irq
);
48 for (i
= M68K_IRQC_LEVEL_7
; i
>= M68K_IRQC_LEVEL_1
; i
--) {
49 if ((s
->ipr
>> i
) & 1) {
50 m68k_set_irq_level(cpu
, i
+ 1, i
+ M68K_IRQC_AUTOVECTOR_BASE
);
54 m68k_set_irq_level(cpu
, 0, 0);
57 static void m68k_irqc_reset(DeviceState
*d
)
59 M68KIRQCState
*s
= M68K_IRQC(d
);
63 for (i
= 0; i
< ARRAY_SIZE(s
->stats_irq_count
); i
++) {
64 s
->stats_irq_count
[i
] = 0;
68 static void m68k_irqc_instance_init(Object
*obj
)
70 qdev_init_gpio_in(DEVICE(obj
), m68k_set_irq
, M68K_IRQC_LEVEL_NUM
);
73 static void m68k_nmi(NMIState
*n
, int cpu_index
, Error
**errp
)
75 m68k_set_irq(n
, M68K_IRQC_LEVEL_7
, 1);
78 static const VMStateDescription vmstate_m68k_irqc
= {
81 .minimum_version_id
= 1,
82 .fields
= (const VMStateField
[]) {
83 VMSTATE_UINT8(ipr
, M68KIRQCState
),
88 static Property m68k_irqc_properties
[] = {
89 DEFINE_PROP_LINK("m68k-cpu", M68KIRQCState
, cpu
,
90 TYPE_M68K_CPU
, ArchCPU
*),
91 DEFINE_PROP_END_OF_LIST(),
94 static void m68k_irqc_class_init(ObjectClass
*oc
, void *data
)
96 DeviceClass
*dc
= DEVICE_CLASS(oc
);
97 NMIClass
*nc
= NMI_CLASS(oc
);
98 InterruptStatsProviderClass
*ic
= INTERRUPT_STATS_PROVIDER_CLASS(oc
);
100 device_class_set_props(dc
, m68k_irqc_properties
);
101 nc
->nmi_monitor_handler
= m68k_nmi
;
102 device_class_set_legacy_reset(dc
, m68k_irqc_reset
);
103 dc
->vmsd
= &vmstate_m68k_irqc
;
104 ic
->get_statistics
= m68k_irqc_get_statistics
;
105 ic
->print_info
= m68k_irqc_print_info
;
108 static const TypeInfo m68k_irqc_type_info
= {
109 .name
= TYPE_M68K_IRQC
,
110 .parent
= TYPE_SYS_BUS_DEVICE
,
111 .instance_size
= sizeof(M68KIRQCState
),
112 .instance_init
= m68k_irqc_instance_init
,
113 .class_init
= m68k_irqc_class_init
,
114 .interfaces
= (InterfaceInfo
[]) {
116 { TYPE_INTERRUPT_STATS_PROVIDER
},
121 static void q800_irq_register_types(void)
123 type_register_static(&m68k_irqc_type_info
);
126 type_init(q800_irq_register_types
);