2 * isa bus support for qdev.
4 * Copyright (c) 2009 Gerd Hoffmann <kraxel@redhat.com>
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.1 of the License, or (at your option) any later version.
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.
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/>.
20 #include "qemu/osdep.h"
21 #include "qemu/error-report.h"
22 #include "qemu/module.h"
23 #include "qapi/error.h"
24 #include "hw/sysbus.h"
25 #include "sysemu/sysemu.h"
26 #include "hw/isa/isa.h"
28 static ISABus
*isabus
;
30 static char *isabus_get_fw_dev_path(DeviceState
*dev
);
32 static void isa_bus_class_init(ObjectClass
*klass
, void *data
)
34 BusClass
*k
= BUS_CLASS(klass
);
36 k
->get_fw_dev_path
= isabus_get_fw_dev_path
;
39 static const TypeInfo isa_dma_info
= {
41 .parent
= TYPE_INTERFACE
,
42 .class_size
= sizeof(IsaDmaClass
),
45 static const TypeInfo isa_bus_info
= {
48 .instance_size
= sizeof(ISABus
),
49 .class_init
= isa_bus_class_init
,
52 ISABus
*isa_bus_new(DeviceState
*dev
, MemoryRegion
* address_space
,
53 MemoryRegion
*address_space_io
, Error
**errp
)
55 DeviceState
*bridge
= NULL
;
58 error_setg(errp
, "Can't create a second ISA bus");
62 bridge
= qdev_new("isabus-bridge");
66 isabus
= ISA_BUS(qbus_new(TYPE_ISA_BUS
, dev
, NULL
));
67 isabus
->address_space
= address_space
;
68 isabus
->address_space_io
= address_space_io
;
71 sysbus_realize_and_unref(SYS_BUS_DEVICE(bridge
), &error_fatal
);
77 void isa_bus_register_input_irqs(ISABus
*bus
, qemu_irq
*irqs_in
)
79 bus
->irqs_in
= irqs_in
;
82 qemu_irq
isa_bus_get_irq(ISABus
*bus
, unsigned irqnum
)
84 assert(irqnum
< ISA_NUM_IRQS
);
86 return bus
->irqs_in
[irqnum
];
90 * isa_get_irq() returns the corresponding input qemu_irq entry for the i8259.
92 * This function is only for special cases such as the 'ferr', and
93 * temporary use for normal devices until they are converted to qdev.
95 qemu_irq
isa_get_irq(ISADevice
*dev
, unsigned isairq
)
97 assert(!dev
|| ISA_BUS(qdev_get_parent_bus(DEVICE(dev
))) == isabus
);
98 return isa_bus_get_irq(isabus
, isairq
);
101 void isa_connect_gpio_out(ISADevice
*isadev
, int gpioirq
, unsigned isairq
)
103 qemu_irq input_irq
= isa_get_irq(isadev
, isairq
);
104 qdev_connect_gpio_out(DEVICE(isadev
), gpioirq
, input_irq
);
107 void isa_bus_dma(ISABus
*bus
, IsaDma
*dma8
, IsaDma
*dma16
)
109 assert(bus
&& dma8
&& dma16
);
110 assert(!bus
->dma
[0] && !bus
->dma
[1]);
115 IsaDma
*isa_bus_get_dma(ISABus
*bus
, int nchan
)
118 return bus
->dma
[nchan
> 3 ? 1 : 0];
121 static inline void isa_init_ioport(ISADevice
*dev
, uint16_t ioport
)
123 if (dev
&& (dev
->ioport_id
== 0 || ioport
< dev
->ioport_id
)) {
124 dev
->ioport_id
= ioport
;
128 void isa_register_ioport(ISADevice
*dev
, MemoryRegion
*io
, uint16_t start
)
130 memory_region_add_subregion(isa_address_space_io(dev
), start
, io
);
131 isa_init_ioport(dev
, start
);
134 int isa_register_portio_list(ISADevice
*dev
,
135 PortioList
*piolist
, uint16_t start
,
136 const MemoryRegionPortio
*pio_start
,
137 void *opaque
, const char *name
)
139 assert(piolist
&& !piolist
->owner
);
145 /* START is how we should treat DEV, regardless of the actual
146 contents of the portio array. This is how the old code
147 actually handled e.g. the FDC device. */
148 isa_init_ioport(dev
, start
);
150 portio_list_init(piolist
, OBJECT(dev
), pio_start
, opaque
, name
);
151 portio_list_add(piolist
, isa_address_space_io(dev
), start
);
156 ISADevice
*isa_new(const char *name
)
158 return ISA_DEVICE(qdev_new(name
));
161 ISADevice
*isa_try_new(const char *name
)
163 return ISA_DEVICE(qdev_try_new(name
));
166 ISADevice
*isa_create_simple(ISABus
*bus
, const char *name
)
171 isa_realize_and_unref(dev
, bus
, &error_fatal
);
175 bool isa_realize_and_unref(ISADevice
*dev
, ISABus
*bus
, Error
**errp
)
177 return qdev_realize_and_unref(&dev
->parent_obj
, &bus
->parent_obj
, errp
);
180 ISABus
*isa_bus_from_device(ISADevice
*dev
)
182 return ISA_BUS(qdev_get_parent_bus(DEVICE(dev
)));
185 ISADevice
*isa_vga_init(ISABus
*bus
)
187 vga_interface_created
= true;
188 switch (vga_interface_type
) {
190 return isa_create_simple(bus
, "isa-cirrus-vga");
192 error_report("%s: qxl: no PCI bus", __func__
);
195 return isa_create_simple(bus
, "isa-vga");
197 error_report("%s: vmware_vga: no PCI bus", __func__
);
200 error_report("%s: virtio-vga: no PCI bus", __func__
);
208 static void isabus_bridge_class_init(ObjectClass
*klass
, void *data
)
210 DeviceClass
*dc
= DEVICE_CLASS(klass
);
212 set_bit(DEVICE_CATEGORY_BRIDGE
, dc
->categories
);
216 static const TypeInfo isabus_bridge_info
= {
217 .name
= "isabus-bridge",
218 .parent
= TYPE_SYS_BUS_DEVICE
,
219 .instance_size
= sizeof(SysBusDevice
),
220 .class_init
= isabus_bridge_class_init
,
223 static void isa_device_class_init(ObjectClass
*klass
, void *data
)
225 DeviceClass
*k
= DEVICE_CLASS(klass
);
226 k
->bus_type
= TYPE_ISA_BUS
;
229 static const TypeInfo isa_device_type_info
= {
230 .name
= TYPE_ISA_DEVICE
,
231 .parent
= TYPE_DEVICE
,
232 .instance_size
= sizeof(ISADevice
),
234 .class_init
= isa_device_class_init
,
237 static void isabus_register_types(void)
239 type_register_static(&isa_dma_info
);
240 type_register_static(&isa_bus_info
);
241 type_register_static(&isabus_bridge_info
);
242 type_register_static(&isa_device_type_info
);
245 static char *isabus_get_fw_dev_path(DeviceState
*dev
)
247 ISADevice
*d
= ISA_DEVICE(dev
);
251 off
= snprintf(path
, sizeof(path
), "%s", qdev_fw_name(dev
));
253 snprintf(path
+ off
, sizeof(path
) - off
, "@%04x", d
->ioport_id
);
256 return g_strdup(path
);
259 MemoryRegion
*isa_address_space(ISADevice
*dev
)
262 return isa_bus_from_device(dev
)->address_space
;
265 return isabus
->address_space
;
268 MemoryRegion
*isa_address_space_io(ISADevice
*dev
)
271 return isa_bus_from_device(dev
)->address_space_io
;
274 return isabus
->address_space_io
;
277 type_init(isabus_register_types
)