]>
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 | |
9 | * version 2 of the License, or (at your option) any later version. | |
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/hw.h" |
83c9089e | 25 | #include "monitor/monitor.h" |
83c9f4ca | 26 | #include "hw/sysbus.h" |
9c17d615 | 27 | #include "sysemu/sysemu.h" |
0d09e41a | 28 | #include "hw/isa/isa.h" |
f915a115 | 29 | |
f915a115 GH |
30 | static ISABus *isabus; |
31 | ||
2091ba23 | 32 | static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent); |
6a26e119 | 33 | static char *isabus_get_fw_dev_path(DeviceState *dev); |
2091ba23 | 34 | |
0d936928 AL |
35 | static void isa_bus_class_init(ObjectClass *klass, void *data) |
36 | { | |
37 | BusClass *k = BUS_CLASS(klass); | |
38 | ||
39 | k->print_dev = isabus_dev_print; | |
40 | k->get_fw_dev_path = isabus_get_fw_dev_path; | |
41 | } | |
42 | ||
5484f30b HP |
43 | static const TypeInfo isa_dma_info = { |
44 | .name = TYPE_ISADMA, | |
45 | .parent = TYPE_INTERFACE, | |
46 | .class_size = sizeof(IsaDmaClass), | |
47 | }; | |
48 | ||
0d936928 AL |
49 | static const TypeInfo isa_bus_info = { |
50 | .name = TYPE_ISA_BUS, | |
51 | .parent = TYPE_BUS, | |
52 | .instance_size = sizeof(ISABus), | |
53 | .class_init = isa_bus_class_init, | |
f915a115 GH |
54 | }; |
55 | ||
bb2ed009 | 56 | ISABus *isa_bus_new(DeviceState *dev, MemoryRegion* address_space, |
d10e5432 | 57 | MemoryRegion *address_space_io, Error **errp) |
f915a115 GH |
58 | { |
59 | if (isabus) { | |
d10e5432 | 60 | error_setg(errp, "Can't create a second ISA bus"); |
f915a115 GH |
61 | return NULL; |
62 | } | |
337a3e5c | 63 | if (!dev) { |
2091ba23 | 64 | dev = qdev_create(NULL, "isabus-bridge"); |
e23a1b33 | 65 | qdev_init_nofail(dev); |
2091ba23 | 66 | } |
f915a115 | 67 | |
2ae0e48d | 68 | isabus = ISA_BUS(qbus_create(TYPE_ISA_BUS, dev, NULL)); |
bb2ed009 | 69 | isabus->address_space = address_space; |
c2d0d012 | 70 | isabus->address_space_io = address_space_io; |
f915a115 GH |
71 | return isabus; |
72 | } | |
73 | ||
48a18b3c | 74 | void isa_bus_irqs(ISABus *bus, qemu_irq *irqs) |
f915a115 | 75 | { |
d3c68e4f | 76 | bus->irqs = irqs; |
2091ba23 GH |
77 | } |
78 | ||
3a38d437 | 79 | /* |
ee951a37 | 80 | * isa_get_irq() returns the corresponding qemu_irq entry for the i8259. |
3a38d437 JS |
81 | * |
82 | * This function is only for special cases such as the 'ferr', and | |
83 | * temporary use for normal devices until they are converted to qdev. | |
84 | */ | |
48a18b3c | 85 | qemu_irq isa_get_irq(ISADevice *dev, int isairq) |
3a38d437 | 86 | { |
2ae0e48d | 87 | assert(!dev || ISA_BUS(qdev_get_parent_bus(DEVICE(dev))) == isabus); |
3a38d437 | 88 | if (isairq < 0 || isairq > 15) { |
74782223 | 89 | hw_error("isa irq %d invalid", isairq); |
3a38d437 | 90 | } |
3a38d437 JS |
91 | return isabus->irqs[isairq]; |
92 | } | |
93 | ||
2e15e23b | 94 | void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq) |
f915a115 | 95 | { |
2e15e23b | 96 | assert(dev->nirqs < ARRAY_SIZE(dev->isairq)); |
2e15e23b | 97 | dev->isairq[dev->nirqs] = isairq; |
48a18b3c | 98 | *p = isa_get_irq(dev, isairq); |
f915a115 GH |
99 | dev->nirqs++; |
100 | } | |
101 | ||
25026303 EV |
102 | void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, int isairq) |
103 | { | |
104 | qemu_irq irq; | |
105 | isa_init_irq(isadev, &irq, isairq); | |
106 | qdev_connect_gpio_out(DEVICE(isadev), gpioirq, irq); | |
107 | } | |
108 | ||
5484f30b HP |
109 | void isa_bus_dma(ISABus *bus, IsaDma *dma8, IsaDma *dma16) |
110 | { | |
111 | assert(bus && dma8 && dma16); | |
112 | assert(!bus->dma[0] && !bus->dma[1]); | |
113 | bus->dma[0] = dma8; | |
114 | bus->dma[1] = dma16; | |
115 | } | |
116 | ||
117 | IsaDma *isa_get_dma(ISABus *bus, int nchan) | |
118 | { | |
119 | assert(bus); | |
120 | return bus->dma[nchan > 3 ? 1 : 0]; | |
121 | } | |
122 | ||
0d959524 | 123 | static inline void isa_init_ioport(ISADevice *dev, uint16_t ioport) |
dee41d58 | 124 | { |
0d959524 RH |
125 | if (dev && (dev->ioport_id == 0 || ioport < dev->ioport_id)) { |
126 | dev->ioport_id = ioport; | |
dee41d58 | 127 | } |
dee41d58 GN |
128 | } |
129 | ||
78e20593 RH |
130 | void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start) |
131 | { | |
132 | memory_region_add_subregion(isabus->address_space_io, start, io); | |
0d959524 | 133 | isa_init_ioport(dev, start); |
78e20593 RH |
134 | } |
135 | ||
e305a165 MAL |
136 | void isa_register_portio_list(ISADevice *dev, |
137 | PortioList *piolist, uint16_t start, | |
d7500734 AK |
138 | const MemoryRegionPortio *pio_start, |
139 | void *opaque, const char *name) | |
140 | { | |
e305a165 | 141 | assert(piolist && !piolist->owner); |
d7500734 AK |
142 | |
143 | /* START is how we should treat DEV, regardless of the actual | |
144 | contents of the portio array. This is how the old code | |
145 | actually handled e.g. the FDC device. */ | |
0d959524 | 146 | isa_init_ioport(dev, start); |
d7500734 | 147 | |
e305a165 MAL |
148 | portio_list_init(piolist, OBJECT(dev), pio_start, opaque, name); |
149 | portio_list_add(piolist, isabus->address_space_io, start); | |
d7500734 AK |
150 | } |
151 | ||
c538ca66 AF |
152 | static void isa_device_init(Object *obj) |
153 | { | |
154 | ISADevice *dev = ISA_DEVICE(obj); | |
155 | ||
156 | dev->isairq[0] = -1; | |
157 | dev->isairq[1] = -1; | |
158 | } | |
159 | ||
48a18b3c | 160 | ISADevice *isa_create(ISABus *bus, const char *name) |
f915a115 GH |
161 | { |
162 | DeviceState *dev; | |
f915a115 | 163 | |
2ae0e48d | 164 | dev = qdev_create(BUS(bus), name); |
8f04ee08 | 165 | return ISA_DEVICE(dev); |
f915a115 | 166 | } |
2091ba23 | 167 | |
48a18b3c | 168 | ISADevice *isa_try_create(ISABus *bus, const char *name) |
86f4a9a5 BS |
169 | { |
170 | DeviceState *dev; | |
171 | ||
2ae0e48d | 172 | dev = qdev_try_create(BUS(bus), name); |
8f04ee08 | 173 | return ISA_DEVICE(dev); |
86f4a9a5 BS |
174 | } |
175 | ||
48a18b3c | 176 | ISADevice *isa_create_simple(ISABus *bus, const char *name) |
924f6d72 GH |
177 | { |
178 | ISADevice *dev; | |
179 | ||
48a18b3c | 180 | dev = isa_create(bus, name); |
4a17cc4f | 181 | qdev_init_nofail(DEVICE(dev)); |
924f6d72 GH |
182 | return dev; |
183 | } | |
184 | ||
14e7a645 AJ |
185 | ISADevice *isa_vga_init(ISABus *bus) |
186 | { | |
187 | switch (vga_interface_type) { | |
188 | case VGA_CIRRUS: | |
189 | return isa_create_simple(bus, "isa-cirrus-vga"); | |
190 | case VGA_QXL: | |
1081ed2c | 191 | error_report("%s: qxl: no PCI bus", __func__); |
14e7a645 AJ |
192 | return NULL; |
193 | case VGA_STD: | |
194 | return isa_create_simple(bus, "isa-vga"); | |
195 | case VGA_VMWARE: | |
1081ed2c | 196 | error_report("%s: vmware_vga: no PCI bus", __func__); |
14e7a645 | 197 | return NULL; |
a94f0c5c | 198 | case VGA_VIRTIO: |
1081ed2c | 199 | error_report("%s: virtio-vga: no PCI bus", __func__); |
a94f0c5c | 200 | return NULL; |
14e7a645 AJ |
201 | case VGA_NONE: |
202 | default: | |
203 | return NULL; | |
204 | } | |
205 | } | |
206 | ||
2091ba23 GH |
207 | static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent) |
208 | { | |
8f04ee08 | 209 | ISADevice *d = ISA_DEVICE(dev); |
2091ba23 GH |
210 | |
211 | if (d->isairq[1] != -1) { | |
212 | monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "", | |
213 | d->isairq[0], d->isairq[1]); | |
214 | } else if (d->isairq[0] != -1) { | |
215 | monitor_printf(mon, "%*sisa irq %d\n", indent, "", | |
216 | d->isairq[0]); | |
217 | } | |
218 | } | |
219 | ||
999e12bb AL |
220 | static void isabus_bridge_class_init(ObjectClass *klass, void *data) |
221 | { | |
39bffca2 | 222 | DeviceClass *dc = DEVICE_CLASS(klass); |
999e12bb | 223 | |
5658ffa3 | 224 | set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); |
39bffca2 | 225 | dc->fw_name = "isa"; |
999e12bb AL |
226 | } |
227 | ||
8c43a6f0 | 228 | static const TypeInfo isabus_bridge_info = { |
39bffca2 AL |
229 | .name = "isabus-bridge", |
230 | .parent = TYPE_SYS_BUS_DEVICE, | |
231 | .instance_size = sizeof(SysBusDevice), | |
232 | .class_init = isabus_bridge_class_init, | |
2091ba23 GH |
233 | }; |
234 | ||
39bffca2 AL |
235 | static void isa_device_class_init(ObjectClass *klass, void *data) |
236 | { | |
237 | DeviceClass *k = DEVICE_CLASS(klass); | |
0d936928 | 238 | k->bus_type = TYPE_ISA_BUS; |
39bffca2 AL |
239 | } |
240 | ||
8c43a6f0 | 241 | static const TypeInfo isa_device_type_info = { |
8f04ee08 AL |
242 | .name = TYPE_ISA_DEVICE, |
243 | .parent = TYPE_DEVICE, | |
244 | .instance_size = sizeof(ISADevice), | |
c538ca66 | 245 | .instance_init = isa_device_init, |
8f04ee08 AL |
246 | .abstract = true, |
247 | .class_size = sizeof(ISADeviceClass), | |
39bffca2 | 248 | .class_init = isa_device_class_init, |
8f04ee08 AL |
249 | }; |
250 | ||
83f7d43a | 251 | static void isabus_register_types(void) |
2091ba23 | 252 | { |
5484f30b | 253 | type_register_static(&isa_dma_info); |
0d936928 | 254 | type_register_static(&isa_bus_info); |
39bffca2 | 255 | type_register_static(&isabus_bridge_info); |
8f04ee08 | 256 | type_register_static(&isa_device_type_info); |
2091ba23 GH |
257 | } |
258 | ||
6a26e119 GN |
259 | static char *isabus_get_fw_dev_path(DeviceState *dev) |
260 | { | |
4a17cc4f | 261 | ISADevice *d = ISA_DEVICE(dev); |
6a26e119 GN |
262 | char path[40]; |
263 | int off; | |
264 | ||
265 | off = snprintf(path, sizeof(path), "%s", qdev_fw_name(dev)); | |
ebf47c24 RH |
266 | if (d->ioport_id) { |
267 | snprintf(path + off, sizeof(path) - off, "@%04x", d->ioport_id); | |
6a26e119 GN |
268 | } |
269 | ||
a5cf8262 | 270 | return g_strdup(path); |
6a26e119 GN |
271 | } |
272 | ||
c839adec AK |
273 | MemoryRegion *isa_address_space(ISADevice *dev) |
274 | { | |
bb2ed009 HP |
275 | if (dev) { |
276 | return isa_bus_from_device(dev)->address_space; | |
277 | } | |
278 | ||
279 | return isabus->address_space; | |
c839adec AK |
280 | } |
281 | ||
ac100273 JG |
282 | MemoryRegion *isa_address_space_io(ISADevice *dev) |
283 | { | |
284 | if (dev) { | |
285 | return isa_bus_from_device(dev)->address_space_io; | |
286 | } | |
287 | ||
288 | return isabus->address_space_io; | |
289 | } | |
290 | ||
83f7d43a | 291 | type_init(isabus_register_types) |