]> git.proxmox.com Git - mirror_qemu.git/blob - hw/isa-bus.c
qdev: drop iobase properties from isa bus
[mirror_qemu.git] / hw / isa-bus.c
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 */
19 #include "hw.h"
20 #include "sysemu.h"
21 #include "monitor.h"
22 #include "sysbus.h"
23 #include "isa.h"
24
25 struct ISABus {
26 BusState qbus;
27 qemu_irq *irqs;
28 uint32_t assigned;
29 };
30 static ISABus *isabus;
31
32 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent);
33
34 static struct BusInfo isa_bus_info = {
35 .name = "ISA",
36 .size = sizeof(ISABus),
37 .print_dev = isabus_dev_print,
38 };
39
40 ISABus *isa_bus_new(DeviceState *dev)
41 {
42 if (isabus) {
43 fprintf(stderr, "Can't create a second ISA bus\n");
44 return NULL;
45 }
46 if (NULL == dev) {
47 dev = qdev_create(NULL, "isabus-bridge");
48 qdev_init(dev);
49 }
50
51 isabus = FROM_QBUS(ISABus, qbus_create(&isa_bus_info, dev, NULL));
52 return isabus;
53 }
54
55 void isa_bus_irqs(qemu_irq *irqs)
56 {
57 isabus->irqs = irqs;
58 }
59
60 void isa_connect_irq(ISADevice *dev, int devnr, int isairq)
61 {
62 assert(devnr >= 0 && devnr < dev->nirqs);
63 if (isabus->assigned & (1 << isairq)) {
64 fprintf(stderr, "isa irq %d already assigned\n", isairq);
65 exit(1);
66 }
67 if (dev->irqs[devnr]) {
68 isabus->assigned |= (1 << isairq);
69 dev->isairq[devnr] = isairq;
70 *dev->irqs[devnr] = isabus->irqs[isairq];
71 }
72 }
73
74 /*
75 * isa_reserve_irq() reserves the ISA irq and returns the corresponding
76 * qemu_irq entry for the i8259.
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 */
81 qemu_irq isa_reserve_irq(int isairq)
82 {
83 if (isairq < 0 || isairq > 15) {
84 fprintf(stderr, "isa irq %d invalid\n", isairq);
85 exit(1);
86 }
87 if (isabus->assigned & (1 << isairq)) {
88 fprintf(stderr, "isa irq %d already assigned\n", isairq);
89 exit(1);
90 }
91 isabus->assigned |= (1 << isairq);
92 return isabus->irqs[isairq];
93 }
94
95 void isa_init_irq(ISADevice *dev, qemu_irq *p)
96 {
97 assert(dev->nirqs < ARRAY_SIZE(dev->irqs));
98 dev->irqs[dev->nirqs] = p;
99 dev->nirqs++;
100 }
101
102 static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base)
103 {
104 ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev);
105 ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base);
106
107 dev->isairq[0] = -1;
108 dev->isairq[1] = -1;
109
110 return info->init(dev);
111 }
112
113 void isa_qdev_register(ISADeviceInfo *info)
114 {
115 info->qdev.init = isa_qdev_init;
116 info->qdev.bus_info = &isa_bus_info;
117 qdev_register(&info->qdev);
118 }
119
120 ISADevice *isa_create_simple(const char *name, uint32_t irq, uint32 irq2)
121 {
122 DeviceState *dev;
123 ISADevice *isa;
124
125 if (!isabus) {
126 fprintf(stderr, "Tried to create isa device %s with no isa bus present.\n", name);
127 return NULL;
128 }
129 dev = qdev_create(&isabus->qbus, name);
130 isa = DO_UPCAST(ISADevice, qdev, dev);
131 qdev_init(dev);
132 if (irq != -1) {
133 isa_connect_irq(isa, 0, irq);
134 }
135 if (irq2 != -1) {
136 isa_connect_irq(isa, 1, irq2);
137 }
138 return isa;
139 }
140
141 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent)
142 {
143 ISADevice *d = DO_UPCAST(ISADevice, qdev, dev);
144
145 if (d->isairq[1] != -1) {
146 monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "",
147 d->isairq[0], d->isairq[1]);
148 } else if (d->isairq[0] != -1) {
149 monitor_printf(mon, "%*sisa irq %d\n", indent, "",
150 d->isairq[0]);
151 }
152 }
153
154 static int isabus_bridge_init(SysBusDevice *dev)
155 {
156 /* nothing */
157 return 0;
158 }
159
160 static SysBusDeviceInfo isabus_bridge_info = {
161 .init = isabus_bridge_init,
162 .qdev.name = "isabus-bridge",
163 .qdev.size = sizeof(SysBusDevice),
164 };
165
166 static void isabus_register_devices(void)
167 {
168 sysbus_register_withprop(&isabus_bridge_info);
169 }
170
171 device_init(isabus_register_devices)