]>
Commit | Line | Data |
---|---|---|
f915a115 GH |
1 | /* |
2 | * isa bus support for qdev. | |
3 | * | |
4 | * Copyright (c) 2009 Gerd Hoffmann <kraxel@redhat.com> | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
61f3c91a | 9 | * version 2.1 of the License, or (at your option) any later version. |
f915a115 GH |
10 | * |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
0b8fa32f | 19 | |
0430891c | 20 | #include "qemu/osdep.h" |
1081ed2c | 21 | #include "qemu/error-report.h" |
0b8fa32f | 22 | #include "qemu/module.h" |
da34e65c | 23 | #include "qapi/error.h" |
83c9f4ca | 24 | #include "hw/sysbus.h" |
9c17d615 | 25 | #include "sysemu/sysemu.h" |
0d09e41a | 26 | #include "hw/isa/isa.h" |
f915a115 | 27 | |
f915a115 GH |
28 | static ISABus *isabus; |
29 | ||
6a26e119 | 30 | static char *isabus_get_fw_dev_path(DeviceState *dev); |
2091ba23 | 31 | |
0d936928 AL |
32 | static void isa_bus_class_init(ObjectClass *klass, void *data) |
33 | { | |
34 | BusClass *k = BUS_CLASS(klass); | |
35 | ||
0d936928 AL |
36 | k->get_fw_dev_path = isabus_get_fw_dev_path; |
37 | } | |
38 | ||
5484f30b HP |
39 | static const TypeInfo isa_dma_info = { |
40 | .name = TYPE_ISADMA, | |
41 | .parent = TYPE_INTERFACE, | |
42 | .class_size = sizeof(IsaDmaClass), | |
43 | }; | |
44 | ||
0d936928 AL |
45 | static const TypeInfo isa_bus_info = { |
46 | .name = TYPE_ISA_BUS, | |
47 | .parent = TYPE_BUS, | |
48 | .instance_size = sizeof(ISABus), | |
49 | .class_init = isa_bus_class_init, | |
f915a115 GH |
50 | }; |
51 | ||
bb2ed009 | 52 | ISABus *isa_bus_new(DeviceState *dev, MemoryRegion* address_space, |
d10e5432 | 53 | MemoryRegion *address_space_io, Error **errp) |
f915a115 GH |
54 | { |
55 | if (isabus) { | |
d10e5432 | 56 | error_setg(errp, "Can't create a second ISA bus"); |
f915a115 GH |
57 | return NULL; |
58 | } | |
337a3e5c | 59 | if (!dev) { |
3e80f690 | 60 | dev = qdev_new("isabus-bridge"); |
3c6ef471 | 61 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
2091ba23 | 62 | } |
f915a115 | 63 | |
9388d170 | 64 | isabus = ISA_BUS(qbus_new(TYPE_ISA_BUS, dev, NULL)); |
bb2ed009 | 65 | isabus->address_space = address_space; |
c2d0d012 | 66 | isabus->address_space_io = address_space_io; |
f915a115 GH |
67 | return isabus; |
68 | } | |
69 | ||
48a18b3c | 70 | void isa_bus_irqs(ISABus *bus, qemu_irq *irqs) |
f915a115 | 71 | { |
d3c68e4f | 72 | bus->irqs = irqs; |
2091ba23 GH |
73 | } |
74 | ||
3a38d437 | 75 | /* |
ee951a37 | 76 | * isa_get_irq() returns the corresponding qemu_irq entry for the i8259. |
3a38d437 JS |
77 | * |
78 | * This function is only for special cases such as the 'ferr', and | |
79 | * temporary use for normal devices until they are converted to qdev. | |
80 | */ | |
3c29e188 | 81 | qemu_irq isa_get_irq(ISADevice *dev, unsigned isairq) |
3a38d437 | 82 | { |
2ae0e48d | 83 | assert(!dev || ISA_BUS(qdev_get_parent_bus(DEVICE(dev))) == isabus); |
0c666198 | 84 | assert(isairq < ISA_NUM_IRQS); |
3a38d437 JS |
85 | return isabus->irqs[isairq]; |
86 | } | |
87 | ||
3c29e188 | 88 | void isa_init_irq(ISADevice *dev, qemu_irq *p, unsigned isairq) |
f915a115 | 89 | { |
48a18b3c | 90 | *p = isa_get_irq(dev, isairq); |
f915a115 GH |
91 | } |
92 | ||
3c29e188 | 93 | void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, unsigned isairq) |
25026303 EV |
94 | { |
95 | qemu_irq irq; | |
96 | isa_init_irq(isadev, &irq, isairq); | |
97 | qdev_connect_gpio_out(DEVICE(isadev), gpioirq, irq); | |
98 | } | |
99 | ||
5484f30b HP |
100 | void isa_bus_dma(ISABus *bus, IsaDma *dma8, IsaDma *dma16) |
101 | { | |
102 | assert(bus && dma8 && dma16); | |
103 | assert(!bus->dma[0] && !bus->dma[1]); | |
104 | bus->dma[0] = dma8; | |
105 | bus->dma[1] = dma16; | |
106 | } | |
107 | ||
108 | IsaDma *isa_get_dma(ISABus *bus, int nchan) | |
109 | { | |
110 | assert(bus); | |
111 | return bus->dma[nchan > 3 ? 1 : 0]; | |
112 | } | |
113 | ||
0d959524 | 114 | static inline void isa_init_ioport(ISADevice *dev, uint16_t ioport) |
dee41d58 | 115 | { |
0d959524 RH |
116 | if (dev && (dev->ioport_id == 0 || ioport < dev->ioport_id)) { |
117 | dev->ioport_id = ioport; | |
dee41d58 | 118 | } |
dee41d58 GN |
119 | } |
120 | ||
78e20593 RH |
121 | void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start) |
122 | { | |
123 | memory_region_add_subregion(isabus->address_space_io, start, io); | |
0d959524 | 124 | isa_init_ioport(dev, start); |
78e20593 RH |
125 | } |
126 | ||
9405d87b TH |
127 | int isa_register_portio_list(ISADevice *dev, |
128 | PortioList *piolist, uint16_t start, | |
129 | const MemoryRegionPortio *pio_start, | |
130 | void *opaque, const char *name) | |
d7500734 | 131 | { |
e305a165 | 132 | assert(piolist && !piolist->owner); |
d7500734 | 133 | |
9405d87b TH |
134 | if (!isabus) { |
135 | return -ENODEV; | |
136 | } | |
137 | ||
d7500734 AK |
138 | /* START is how we should treat DEV, regardless of the actual |
139 | contents of the portio array. This is how the old code | |
140 | actually handled e.g. the FDC device. */ | |
0d959524 | 141 | isa_init_ioport(dev, start); |
d7500734 | 142 | |
e305a165 MAL |
143 | portio_list_init(piolist, OBJECT(dev), pio_start, opaque, name); |
144 | portio_list_add(piolist, isabus->address_space_io, start); | |
9405d87b TH |
145 | |
146 | return 0; | |
d7500734 AK |
147 | } |
148 | ||
0fe9d901 MA |
149 | ISADevice *isa_new(const char *name) |
150 | { | |
151 | return ISA_DEVICE(qdev_new(name)); | |
152 | } | |
153 | ||
154 | ISADevice *isa_try_new(const char *name) | |
155 | { | |
156 | return ISA_DEVICE(qdev_try_new(name)); | |
157 | } | |
158 | ||
48a18b3c | 159 | ISADevice *isa_create_simple(ISABus *bus, const char *name) |
924f6d72 GH |
160 | { |
161 | ISADevice *dev; | |
162 | ||
96927c74 MA |
163 | dev = isa_new(name); |
164 | isa_realize_and_unref(dev, bus, &error_fatal); | |
924f6d72 GH |
165 | return dev; |
166 | } | |
167 | ||
0fe9d901 MA |
168 | bool isa_realize_and_unref(ISADevice *dev, ISABus *bus, Error **errp) |
169 | { | |
170 | return qdev_realize_and_unref(&dev->parent_obj, &bus->parent_obj, errp); | |
171 | } | |
172 | ||
14e7a645 AJ |
173 | ISADevice *isa_vga_init(ISABus *bus) |
174 | { | |
175 | switch (vga_interface_type) { | |
176 | case VGA_CIRRUS: | |
177 | return isa_create_simple(bus, "isa-cirrus-vga"); | |
178 | case VGA_QXL: | |
1081ed2c | 179 | error_report("%s: qxl: no PCI bus", __func__); |
14e7a645 AJ |
180 | return NULL; |
181 | case VGA_STD: | |
182 | return isa_create_simple(bus, "isa-vga"); | |
183 | case VGA_VMWARE: | |
1081ed2c | 184 | error_report("%s: vmware_vga: no PCI bus", __func__); |
14e7a645 | 185 | return NULL; |
a94f0c5c | 186 | case VGA_VIRTIO: |
1081ed2c | 187 | error_report("%s: virtio-vga: no PCI bus", __func__); |
a94f0c5c | 188 | return NULL; |
14e7a645 AJ |
189 | case VGA_NONE: |
190 | default: | |
191 | return NULL; | |
192 | } | |
193 | } | |
194 | ||
a53e581e GH |
195 | void isa_build_aml(ISABus *bus, Aml *scope) |
196 | { | |
197 | BusChild *kid; | |
198 | ISADevice *dev; | |
199 | ISADeviceClass *dc; | |
200 | ||
201 | QTAILQ_FOREACH(kid, &bus->parent_obj.children, sibling) { | |
202 | dev = ISA_DEVICE(kid->child); | |
203 | dc = ISA_DEVICE_GET_CLASS(dev); | |
204 | if (dc->build_aml) { | |
205 | dc->build_aml(dev, scope); | |
206 | } | |
207 | } | |
208 | } | |
209 | ||
999e12bb AL |
210 | static void isabus_bridge_class_init(ObjectClass *klass, void *data) |
211 | { | |
39bffca2 | 212 | DeviceClass *dc = DEVICE_CLASS(klass); |
999e12bb | 213 | |
5658ffa3 | 214 | set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); |
39bffca2 | 215 | dc->fw_name = "isa"; |
999e12bb AL |
216 | } |
217 | ||
8c43a6f0 | 218 | static const TypeInfo isabus_bridge_info = { |
39bffca2 AL |
219 | .name = "isabus-bridge", |
220 | .parent = TYPE_SYS_BUS_DEVICE, | |
221 | .instance_size = sizeof(SysBusDevice), | |
222 | .class_init = isabus_bridge_class_init, | |
2091ba23 GH |
223 | }; |
224 | ||
39bffca2 AL |
225 | static void isa_device_class_init(ObjectClass *klass, void *data) |
226 | { | |
227 | DeviceClass *k = DEVICE_CLASS(klass); | |
0d936928 | 228 | k->bus_type = TYPE_ISA_BUS; |
39bffca2 AL |
229 | } |
230 | ||
8c43a6f0 | 231 | static const TypeInfo isa_device_type_info = { |
8f04ee08 AL |
232 | .name = TYPE_ISA_DEVICE, |
233 | .parent = TYPE_DEVICE, | |
234 | .instance_size = sizeof(ISADevice), | |
235 | .abstract = true, | |
236 | .class_size = sizeof(ISADeviceClass), | |
39bffca2 | 237 | .class_init = isa_device_class_init, |
8f04ee08 AL |
238 | }; |
239 | ||
83f7d43a | 240 | static void isabus_register_types(void) |
2091ba23 | 241 | { |
5484f30b | 242 | type_register_static(&isa_dma_info); |
0d936928 | 243 | type_register_static(&isa_bus_info); |
39bffca2 | 244 | type_register_static(&isabus_bridge_info); |
8f04ee08 | 245 | type_register_static(&isa_device_type_info); |
2091ba23 GH |
246 | } |
247 | ||
6a26e119 GN |
248 | static char *isabus_get_fw_dev_path(DeviceState *dev) |
249 | { | |
4a17cc4f | 250 | ISADevice *d = ISA_DEVICE(dev); |
6a26e119 GN |
251 | char path[40]; |
252 | int off; | |
253 | ||
254 | off = snprintf(path, sizeof(path), "%s", qdev_fw_name(dev)); | |
ebf47c24 RH |
255 | if (d->ioport_id) { |
256 | snprintf(path + off, sizeof(path) - off, "@%04x", d->ioport_id); | |
6a26e119 GN |
257 | } |
258 | ||
a5cf8262 | 259 | return g_strdup(path); |
6a26e119 GN |
260 | } |
261 | ||
c839adec AK |
262 | MemoryRegion *isa_address_space(ISADevice *dev) |
263 | { | |
bb2ed009 HP |
264 | if (dev) { |
265 | return isa_bus_from_device(dev)->address_space; | |
266 | } | |
267 | ||
268 | return isabus->address_space; | |
c839adec AK |
269 | } |
270 | ||
ac100273 JG |
271 | MemoryRegion *isa_address_space_io(ISADevice *dev) |
272 | { | |
273 | if (dev) { | |
274 | return isa_bus_from_device(dev)->address_space_io; | |
275 | } | |
276 | ||
277 | return isabus->address_space_io; | |
278 | } | |
279 | ||
83f7d43a | 280 | type_init(isabus_register_types) |