1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include "qemu/osdep.h"
27#include "hw/core/split-irq.h"
28#include "hw/irq.h"
29#include "hw/qdev-properties.h"
30#include "qapi/error.h"
31#include "qemu/module.h"
32
33static void split_irq_handler(void *opaque, int n, int level)
34{
35 SplitIRQ *s = SPLIT_IRQ(opaque);
36 int i;
37
38 for (i = 0; i < s->num_lines; i++) {
39 qemu_set_irq(s->out_irq[i], level);
40 }
41}
42
43static void split_irq_init(Object *obj)
44{
45 qdev_init_gpio_in(DEVICE(obj), split_irq_handler, 1);
46}
47
48static void split_irq_realize(DeviceState *dev, Error **errp)
49{
50 SplitIRQ *s = SPLIT_IRQ(dev);
51
52 if (s->num_lines < 1 || s->num_lines >= MAX_SPLIT_LINES) {
53 error_setg(errp,
54 "IRQ splitter number of lines %d is not between 1 and %d",
55 s->num_lines, MAX_SPLIT_LINES);
56 return;
57 }
58
59 qdev_init_gpio_out(dev, s->out_irq, s->num_lines);
60}
61
62static Property split_irq_properties[] = {
63 DEFINE_PROP_UINT16("num-lines", SplitIRQ, num_lines, 1),
64 DEFINE_PROP_END_OF_LIST(),
65};
66
67static void split_irq_class_init(ObjectClass *klass, void *data)
68{
69 DeviceClass *dc = DEVICE_CLASS(klass);
70
71
72 device_class_set_props(dc, split_irq_properties);
73 dc->realize = split_irq_realize;
74
75
76 dc->user_creatable = false;
77}
78
79static const TypeInfo split_irq_type_info = {
80 .name = TYPE_SPLIT_IRQ,
81 .parent = TYPE_DEVICE,
82 .instance_size = sizeof(SplitIRQ),
83 .instance_init = split_irq_init,
84 .class_init = split_irq_class_init,
85};
86
87static void split_irq_register_types(void)
88{
89 type_register_static(&split_irq_type_info);
90}
91
92type_init(split_irq_register_types)
93