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#include "qemu/osdep.h"
26#include "hw/i386/pc.h"
27#include "hw/isa/i8259_internal.h"
28
29void pic_reset_common(PICCommonState *s)
30{
31 s->last_irr = 0;
32 s->irr &= s->elcr;
33 s->imr = 0;
34 s->isr = 0;
35 s->priority_add = 0;
36 s->irq_base = 0;
37 s->read_reg_select = 0;
38 s->poll = 0;
39 s->special_mask = 0;
40 s->init_state = 0;
41 s->auto_eoi = 0;
42 s->rotate_on_auto_eoi = 0;
43 s->special_fully_nested_mode = 0;
44 s->init4 = 0;
45 s->single_mode = 0;
46
47}
48
49static int pic_dispatch_pre_save(void *opaque)
50{
51 PICCommonState *s = opaque;
52 PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
53
54 if (info->pre_save) {
55 info->pre_save(s);
56 }
57
58 return 0;
59}
60
61static int pic_dispatch_post_load(void *opaque, int version_id)
62{
63 PICCommonState *s = opaque;
64 PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
65
66 if (info->post_load) {
67 info->post_load(s);
68 }
69 return 0;
70}
71
72static void pic_common_realize(DeviceState *dev, Error **errp)
73{
74 PICCommonState *s = PIC_COMMON(dev);
75 ISADevice *isa = ISA_DEVICE(dev);
76
77 isa_register_ioport(isa, &s->base_io, s->iobase);
78 if (s->elcr_addr != -1) {
79 isa_register_ioport(isa, &s->elcr_io, s->elcr_addr);
80 }
81
82 qdev_set_legacy_instance_id(dev, s->iobase, 1);
83}
84
85ISADevice *i8259_init_chip(const char *name, ISABus *bus, bool master)
86{
87 DeviceState *dev;
88 ISADevice *isadev;
89
90 isadev = isa_create(bus, name);
91 dev = DEVICE(isadev);
92 qdev_prop_set_uint32(dev, "iobase", master ? 0x20 : 0xa0);
93 qdev_prop_set_uint32(dev, "elcr_addr", master ? 0x4d0 : 0x4d1);
94 qdev_prop_set_uint8(dev, "elcr_mask", master ? 0xf8 : 0xde);
95 qdev_prop_set_bit(dev, "master", master);
96 qdev_init_nofail(dev);
97
98 return isadev;
99}
100
101static const VMStateDescription vmstate_pic_common = {
102 .name = "i8259",
103 .version_id = 1,
104 .minimum_version_id = 1,
105 .pre_save = pic_dispatch_pre_save,
106 .post_load = pic_dispatch_post_load,
107 .fields = (VMStateField[]) {
108 VMSTATE_UINT8(last_irr, PICCommonState),
109 VMSTATE_UINT8(irr, PICCommonState),
110 VMSTATE_UINT8(imr, PICCommonState),
111 VMSTATE_UINT8(isr, PICCommonState),
112 VMSTATE_UINT8(priority_add, PICCommonState),
113 VMSTATE_UINT8(irq_base, PICCommonState),
114 VMSTATE_UINT8(read_reg_select, PICCommonState),
115 VMSTATE_UINT8(poll, PICCommonState),
116 VMSTATE_UINT8(special_mask, PICCommonState),
117 VMSTATE_UINT8(init_state, PICCommonState),
118 VMSTATE_UINT8(auto_eoi, PICCommonState),
119 VMSTATE_UINT8(rotate_on_auto_eoi, PICCommonState),
120 VMSTATE_UINT8(special_fully_nested_mode, PICCommonState),
121 VMSTATE_UINT8(init4, PICCommonState),
122 VMSTATE_UINT8(single_mode, PICCommonState),
123 VMSTATE_UINT8(elcr, PICCommonState),
124 VMSTATE_END_OF_LIST()
125 }
126};
127
128static Property pic_properties_common[] = {
129 DEFINE_PROP_UINT32("iobase", PICCommonState, iobase, -1),
130 DEFINE_PROP_UINT32("elcr_addr", PICCommonState, elcr_addr, -1),
131 DEFINE_PROP_UINT8("elcr_mask", PICCommonState, elcr_mask, -1),
132 DEFINE_PROP_BIT("master", PICCommonState, master, 0, false),
133 DEFINE_PROP_END_OF_LIST(),
134};
135
136static void pic_common_class_init(ObjectClass *klass, void *data)
137{
138 DeviceClass *dc = DEVICE_CLASS(klass);
139
140 dc->vmsd = &vmstate_pic_common;
141 dc->props = pic_properties_common;
142 dc->realize = pic_common_realize;
143
144
145
146
147
148
149 dc->user_creatable = false;
150}
151
152static const TypeInfo pic_common_type = {
153 .name = TYPE_PIC_COMMON,
154 .parent = TYPE_ISA_DEVICE,
155 .instance_size = sizeof(PICCommonState),
156 .class_size = sizeof(PICCommonClass),
157 .class_init = pic_common_class_init,
158 .abstract = true,
159};
160
161static void pic_common_register_types(void)
162{
163 type_register_static(&pic_common_type);
164}
165
166type_init(pic_common_register_types)
167