1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include "hw/i386/ioapic.h"
23#include "hw/i386/ioapic_internal.h"
24#include "hw/sysbus.h"
25
26
27
28
29
30
31
32int ioapic_no;
33
34void ioapic_reset_common(DeviceState *dev)
35{
36 IOAPICCommonState *s = IOAPIC_COMMON(dev);
37 int i;
38
39 s->id = 0;
40 s->ioregsel = 0;
41 s->irr = 0;
42 for (i = 0; i < IOAPIC_NUM_PINS; i++) {
43 s->ioredtbl[i] = 1 << IOAPIC_LVT_MASKED_SHIFT;
44 }
45}
46
47static void ioapic_dispatch_pre_save(void *opaque)
48{
49 IOAPICCommonState *s = IOAPIC_COMMON(opaque);
50 IOAPICCommonClass *info = IOAPIC_COMMON_GET_CLASS(s);
51
52 if (info->pre_save) {
53 info->pre_save(s);
54 }
55}
56
57static int ioapic_dispatch_post_load(void *opaque, int version_id)
58{
59 IOAPICCommonState *s = IOAPIC_COMMON(opaque);
60 IOAPICCommonClass *info = IOAPIC_COMMON_GET_CLASS(s);
61
62 if (info->post_load) {
63 info->post_load(s);
64 }
65 return 0;
66}
67
68static void ioapic_common_realize(DeviceState *dev, Error **errp)
69{
70 IOAPICCommonState *s = IOAPIC_COMMON(dev);
71 IOAPICCommonClass *info;
72
73 if (ioapic_no >= MAX_IOAPICS) {
74 error_setg(errp, "Only %d ioapics allowed", MAX_IOAPICS);
75 return;
76 }
77
78 info = IOAPIC_COMMON_GET_CLASS(s);
79 info->realize(dev, errp);
80
81 sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->io_memory);
82 ioapic_no++;
83}
84
85static const VMStateDescription vmstate_ioapic_common = {
86 .name = "ioapic",
87 .version_id = 3,
88 .minimum_version_id = 1,
89 .pre_save = ioapic_dispatch_pre_save,
90 .post_load = ioapic_dispatch_post_load,
91 .fields = (VMStateField[]) {
92 VMSTATE_UINT8(id, IOAPICCommonState),
93 VMSTATE_UINT8(ioregsel, IOAPICCommonState),
94 VMSTATE_UNUSED_V(2, 8),
95 VMSTATE_UINT32_V(irr, IOAPICCommonState, 2),
96 VMSTATE_UINT64_ARRAY(ioredtbl, IOAPICCommonState, IOAPIC_NUM_PINS),
97 VMSTATE_END_OF_LIST()
98 }
99};
100
101static void ioapic_common_class_init(ObjectClass *klass, void *data)
102{
103 DeviceClass *dc = DEVICE_CLASS(klass);
104
105 dc->realize = ioapic_common_realize;
106 dc->vmsd = &vmstate_ioapic_common;
107}
108
109static const TypeInfo ioapic_common_type = {
110 .name = TYPE_IOAPIC_COMMON,
111 .parent = TYPE_SYS_BUS_DEVICE,
112 .instance_size = sizeof(IOAPICCommonState),
113 .class_size = sizeof(IOAPICCommonClass),
114 .class_init = ioapic_common_class_init,
115 .abstract = true,
116};
117
118static void ioapic_common_register_types(void)
119{
120 type_register_static(&ioapic_common_type);
121}
122
123type_init(ioapic_common_register_types)
124