strongarm: mask off high[31:28] bits from dir and state registers
[qemu/ar7.git] / hw / isa / isa-bus.c
blob63fa77effc90c96e65f42dcb36b8103df195d46a
1 /*
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 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/>.
19 #include "qemu/osdep.h"
20 #include "qemu/error-report.h"
21 #include "qapi/error.h"
22 #include "hw/hw.h"
23 #include "monitor/monitor.h"
24 #include "hw/sysbus.h"
25 #include "sysemu/sysemu.h"
26 #include "hw/isa/isa.h"
28 static ISABus *isabus;
30 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent);
31 static char *isabus_get_fw_dev_path(DeviceState *dev);
33 static void isa_bus_class_init(ObjectClass *klass, void *data)
35 BusClass *k = BUS_CLASS(klass);
37 k->print_dev = isabus_dev_print;
38 k->get_fw_dev_path = isabus_get_fw_dev_path;
41 static const TypeInfo isa_dma_info = {
42 .name = TYPE_ISADMA,
43 .parent = TYPE_INTERFACE,
44 .class_size = sizeof(IsaDmaClass),
47 static const TypeInfo isa_bus_info = {
48 .name = TYPE_ISA_BUS,
49 .parent = TYPE_BUS,
50 .instance_size = sizeof(ISABus),
51 .class_init = isa_bus_class_init,
54 ISABus *isa_bus_new(DeviceState *dev, MemoryRegion* address_space,
55 MemoryRegion *address_space_io, Error **errp)
57 if (isabus) {
58 error_setg(errp, "Can't create a second ISA bus");
59 return NULL;
61 if (!dev) {
62 dev = qdev_create(NULL, "isabus-bridge");
63 qdev_init_nofail(dev);
66 isabus = ISA_BUS(qbus_create(TYPE_ISA_BUS, dev, NULL));
67 isabus->address_space = address_space;
68 isabus->address_space_io = address_space_io;
69 return isabus;
72 void isa_bus_irqs(ISABus *bus, qemu_irq *irqs)
74 bus->irqs = irqs;
78 * isa_get_irq() returns the corresponding qemu_irq entry for the i8259.
80 * This function is only for special cases such as the 'ferr', and
81 * temporary use for normal devices until they are converted to qdev.
83 qemu_irq isa_get_irq(ISADevice *dev, int isairq)
85 assert(!dev || ISA_BUS(qdev_get_parent_bus(DEVICE(dev))) == isabus);
86 if (isairq < 0 || isairq > 15) {
87 hw_error("isa irq %d invalid", isairq);
89 return isabus->irqs[isairq];
92 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq)
94 assert(dev->nirqs < ARRAY_SIZE(dev->isairq));
95 dev->isairq[dev->nirqs] = isairq;
96 *p = isa_get_irq(dev, isairq);
97 dev->nirqs++;
100 void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, int isairq)
102 qemu_irq irq;
103 isa_init_irq(isadev, &irq, isairq);
104 qdev_connect_gpio_out(DEVICE(isadev), gpioirq, 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]);
111 bus->dma[0] = dma8;
112 bus->dma[1] = dma16;
115 IsaDma *isa_get_dma(ISABus *bus, int nchan)
117 assert(bus);
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(isabus->address_space_io, start, io);
131 isa_init_ioport(dev, start);
134 void 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);
141 /* START is how we should treat DEV, regardless of the actual
142 contents of the portio array. This is how the old code
143 actually handled e.g. the FDC device. */
144 isa_init_ioport(dev, start);
146 portio_list_init(piolist, OBJECT(dev), pio_start, opaque, name);
147 portio_list_add(piolist, isabus->address_space_io, start);
150 static void isa_device_init(Object *obj)
152 ISADevice *dev = ISA_DEVICE(obj);
154 dev->isairq[0] = -1;
155 dev->isairq[1] = -1;
158 ISADevice *isa_create(ISABus *bus, const char *name)
160 DeviceState *dev;
162 dev = qdev_create(BUS(bus), name);
163 return ISA_DEVICE(dev);
166 ISADevice *isa_try_create(ISABus *bus, const char *name)
168 DeviceState *dev;
170 dev = qdev_try_create(BUS(bus), name);
171 return ISA_DEVICE(dev);
174 ISADevice *isa_create_simple(ISABus *bus, const char *name)
176 ISADevice *dev;
178 dev = isa_create(bus, name);
179 qdev_init_nofail(DEVICE(dev));
180 return dev;
183 ISADevice *isa_vga_init(ISABus *bus)
185 switch (vga_interface_type) {
186 case VGA_CIRRUS:
187 return isa_create_simple(bus, "isa-cirrus-vga");
188 case VGA_QXL:
189 error_report("%s: qxl: no PCI bus", __func__);
190 return NULL;
191 case VGA_STD:
192 return isa_create_simple(bus, "isa-vga");
193 case VGA_VMWARE:
194 error_report("%s: vmware_vga: no PCI bus", __func__);
195 return NULL;
196 case VGA_VIRTIO:
197 error_report("%s: virtio-vga: no PCI bus", __func__);
198 return NULL;
199 case VGA_NONE:
200 default:
201 return NULL;
205 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent)
207 ISADevice *d = ISA_DEVICE(dev);
209 if (d->isairq[1] != -1) {
210 monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "",
211 d->isairq[0], d->isairq[1]);
212 } else if (d->isairq[0] != -1) {
213 monitor_printf(mon, "%*sisa irq %d\n", indent, "",
214 d->isairq[0]);
218 static void isabus_bridge_class_init(ObjectClass *klass, void *data)
220 DeviceClass *dc = DEVICE_CLASS(klass);
222 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
223 dc->fw_name = "isa";
226 static const TypeInfo isabus_bridge_info = {
227 .name = "isabus-bridge",
228 .parent = TYPE_SYS_BUS_DEVICE,
229 .instance_size = sizeof(SysBusDevice),
230 .class_init = isabus_bridge_class_init,
233 static void isa_device_class_init(ObjectClass *klass, void *data)
235 DeviceClass *k = DEVICE_CLASS(klass);
236 k->bus_type = TYPE_ISA_BUS;
239 static const TypeInfo isa_device_type_info = {
240 .name = TYPE_ISA_DEVICE,
241 .parent = TYPE_DEVICE,
242 .instance_size = sizeof(ISADevice),
243 .instance_init = isa_device_init,
244 .abstract = true,
245 .class_size = sizeof(ISADeviceClass),
246 .class_init = isa_device_class_init,
249 static void isabus_register_types(void)
251 type_register_static(&isa_dma_info);
252 type_register_static(&isa_bus_info);
253 type_register_static(&isabus_bridge_info);
254 type_register_static(&isa_device_type_info);
257 static char *isabus_get_fw_dev_path(DeviceState *dev)
259 ISADevice *d = ISA_DEVICE(dev);
260 char path[40];
261 int off;
263 off = snprintf(path, sizeof(path), "%s", qdev_fw_name(dev));
264 if (d->ioport_id) {
265 snprintf(path + off, sizeof(path) - off, "@%04x", d->ioport_id);
268 return g_strdup(path);
271 MemoryRegion *isa_address_space(ISADevice *dev)
273 if (dev) {
274 return isa_bus_from_device(dev)->address_space;
277 return isabus->address_space;
280 MemoryRegion *isa_address_space_io(ISADevice *dev)
282 if (dev) {
283 return isa_bus_from_device(dev)->address_space_io;
286 return isabus->address_space_io;
289 type_init(isabus_register_types)