]> git.proxmox.com Git - qemu.git/blob - hw/isa-bus.c
report serial devices created with -device in the PIIX4 config space
[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 "monitor.h"
21 #include "sysbus.h"
22 #include "isa.h"
23
24 struct ISABus {
25 BusState qbus;
26 qemu_irq *irqs;
27 };
28 static ISABus *isabus;
29 target_phys_addr_t isa_mem_base = 0;
30
31 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent);
32 static char *isabus_get_fw_dev_path(DeviceState *dev);
33
34 static struct BusInfo isa_bus_info = {
35 .name = "ISA",
36 .size = sizeof(ISABus),
37 .print_dev = isabus_dev_print,
38 .get_fw_dev_path = isabus_get_fw_dev_path,
39 };
40
41 ISABus *isa_bus_new(DeviceState *dev)
42 {
43 if (isabus) {
44 fprintf(stderr, "Can't create a second ISA bus\n");
45 return NULL;
46 }
47 if (NULL == dev) {
48 dev = qdev_create(NULL, "isabus-bridge");
49 qdev_init_nofail(dev);
50 }
51
52 isabus = FROM_QBUS(ISABus, qbus_create(&isa_bus_info, dev, NULL));
53 return isabus;
54 }
55
56 void isa_bus_irqs(qemu_irq *irqs)
57 {
58 isabus->irqs = irqs;
59 }
60
61 /*
62 * isa_get_irq() returns the corresponding qemu_irq entry for the i8259.
63 *
64 * This function is only for special cases such as the 'ferr', and
65 * temporary use for normal devices until they are converted to qdev.
66 */
67 qemu_irq isa_get_irq(int isairq)
68 {
69 if (isairq < 0 || isairq > 15) {
70 hw_error("isa irq %d invalid", isairq);
71 }
72 return isabus->irqs[isairq];
73 }
74
75 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq)
76 {
77 assert(dev->nirqs < ARRAY_SIZE(dev->isairq));
78 dev->isairq[dev->nirqs] = isairq;
79 *p = isa_get_irq(isairq);
80 dev->nirqs++;
81 }
82
83 static void isa_init_ioport_one(ISADevice *dev, uint16_t ioport)
84 {
85 assert(dev->nioports < ARRAY_SIZE(dev->ioports));
86 dev->ioports[dev->nioports++] = ioport;
87 }
88
89 static int isa_cmp_ports(const void *p1, const void *p2)
90 {
91 return *(uint16_t*)p1 - *(uint16_t*)p2;
92 }
93
94 void isa_init_ioport_range(ISADevice *dev, uint16_t start, uint16_t length)
95 {
96 int i;
97 for (i = start; i < start + length; i++) {
98 isa_init_ioport_one(dev, i);
99 }
100 qsort(dev->ioports, dev->nioports, sizeof(dev->ioports[0]), isa_cmp_ports);
101 }
102
103 void isa_init_ioport(ISADevice *dev, uint16_t ioport)
104 {
105 isa_init_ioport_range(dev, ioport, 1);
106 }
107
108 static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base)
109 {
110 ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev);
111 ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base);
112
113 dev->isairq[0] = -1;
114 dev->isairq[1] = -1;
115
116 return info->init(dev);
117 }
118
119 void isa_qdev_register(ISADeviceInfo *info)
120 {
121 info->qdev.init = isa_qdev_init;
122 info->qdev.bus_info = &isa_bus_info;
123 qdev_register(&info->qdev);
124 }
125
126 ISADevice *isa_create(const char *name)
127 {
128 DeviceState *dev;
129
130 if (!isabus) {
131 hw_error("Tried to create isa device %s with no isa bus present.",
132 name);
133 }
134 dev = qdev_create(&isabus->qbus, name);
135 return DO_UPCAST(ISADevice, qdev, dev);
136 }
137
138 ISADevice *isa_try_create(const char *name)
139 {
140 DeviceState *dev;
141
142 if (!isabus) {
143 hw_error("Tried to create isa device %s with no isa bus present.",
144 name);
145 }
146 dev = qdev_try_create(&isabus->qbus, name);
147 return DO_UPCAST(ISADevice, qdev, dev);
148 }
149
150 ISADevice *isa_create_simple(const char *name)
151 {
152 ISADevice *dev;
153
154 dev = isa_create(name);
155 qdev_init_nofail(&dev->qdev);
156 return dev;
157 }
158
159 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent)
160 {
161 ISADevice *d = DO_UPCAST(ISADevice, qdev, dev);
162
163 if (d->isairq[1] != -1) {
164 monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "",
165 d->isairq[0], d->isairq[1]);
166 } else if (d->isairq[0] != -1) {
167 monitor_printf(mon, "%*sisa irq %d\n", indent, "",
168 d->isairq[0]);
169 }
170 }
171
172 static int isabus_bridge_init(SysBusDevice *dev)
173 {
174 /* nothing */
175 return 0;
176 }
177
178 static SysBusDeviceInfo isabus_bridge_info = {
179 .init = isabus_bridge_init,
180 .qdev.name = "isabus-bridge",
181 .qdev.fw_name = "isa",
182 .qdev.size = sizeof(SysBusDevice),
183 .qdev.no_user = 1,
184 };
185
186 static void isabus_register_devices(void)
187 {
188 sysbus_register_withprop(&isabus_bridge_info);
189 }
190
191 static char *isabus_get_fw_dev_path(DeviceState *dev)
192 {
193 ISADevice *d = (ISADevice*)dev;
194 char path[40];
195 int off;
196
197 off = snprintf(path, sizeof(path), "%s", qdev_fw_name(dev));
198 if (d->nioports) {
199 snprintf(path + off, sizeof(path) - off, "@%04x", d->ioports[0]);
200 }
201
202 return strdup(path);
203 }
204
205 device_init(isabus_register_devices)