root / hw / isa-bus.c @ f7b4f61f
History | View | Annotate | Download (4.2 kB)
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 |
/*
|
61 |
* isa_reserve_irq() reserves the ISA irq and returns the corresponding
|
62 |
* 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_reserve_irq(int isairq)
|
68 |
{ |
69 |
if (isairq < 0 || isairq > 15) { |
70 |
fprintf(stderr, "isa irq %d invalid\n", isairq);
|
71 |
exit(1);
|
72 |
} |
73 |
if (isabus->assigned & (1 << isairq)) { |
74 |
fprintf(stderr, "isa irq %d already assigned\n", isairq);
|
75 |
exit(1);
|
76 |
} |
77 |
isabus->assigned |= (1 << isairq);
|
78 |
return isabus->irqs[isairq];
|
79 |
} |
80 |
|
81 |
void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq) |
82 |
{ |
83 |
assert(dev->nirqs < ARRAY_SIZE(dev->isairq)); |
84 |
if (isabus->assigned & (1 << isairq)) { |
85 |
fprintf(stderr, "isa irq %d already assigned\n", isairq);
|
86 |
exit(1);
|
87 |
} |
88 |
isabus->assigned |= (1 << isairq);
|
89 |
dev->isairq[dev->nirqs] = isairq; |
90 |
*p = isabus->irqs[isairq]; |
91 |
dev->nirqs++; |
92 |
} |
93 |
|
94 |
static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base) |
95 |
{ |
96 |
ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev); |
97 |
ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base); |
98 |
|
99 |
dev->isairq[0] = -1; |
100 |
dev->isairq[1] = -1; |
101 |
|
102 |
return info->init(dev);
|
103 |
} |
104 |
|
105 |
void isa_qdev_register(ISADeviceInfo *info)
|
106 |
{ |
107 |
info->qdev.init = isa_qdev_init; |
108 |
info->qdev.bus_info = &isa_bus_info; |
109 |
qdev_register(&info->qdev); |
110 |
} |
111 |
|
112 |
ISADevice *isa_create(const char *name) |
113 |
{ |
114 |
DeviceState *dev; |
115 |
|
116 |
if (!isabus) {
|
117 |
fprintf(stderr, "Tried to create isa device %s with no isa bus present.\n", name);
|
118 |
return NULL; |
119 |
} |
120 |
dev = qdev_create(&isabus->qbus, name); |
121 |
return DO_UPCAST(ISADevice, qdev, dev);
|
122 |
} |
123 |
|
124 |
ISADevice *isa_create_simple(const char *name) |
125 |
{ |
126 |
ISADevice *dev; |
127 |
|
128 |
dev = isa_create(name); |
129 |
if (qdev_init(&dev->qdev) != 0) { |
130 |
qdev_free(&dev->qdev); |
131 |
return NULL; |
132 |
} |
133 |
return dev;
|
134 |
} |
135 |
|
136 |
static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent) |
137 |
{ |
138 |
ISADevice *d = DO_UPCAST(ISADevice, qdev, dev); |
139 |
|
140 |
if (d->isairq[1] != -1) { |
141 |
monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "", |
142 |
d->isairq[0], d->isairq[1]); |
143 |
} else if (d->isairq[0] != -1) { |
144 |
monitor_printf(mon, "%*sisa irq %d\n", indent, "", |
145 |
d->isairq[0]);
|
146 |
} |
147 |
} |
148 |
|
149 |
static int isabus_bridge_init(SysBusDevice *dev) |
150 |
{ |
151 |
/* nothing */
|
152 |
return 0; |
153 |
} |
154 |
|
155 |
static SysBusDeviceInfo isabus_bridge_info = {
|
156 |
.init = isabus_bridge_init, |
157 |
.qdev.name = "isabus-bridge",
|
158 |
.qdev.size = sizeof(SysBusDevice),
|
159 |
.qdev.no_user = 1,
|
160 |
}; |
161 |
|
162 |
static void isabus_register_devices(void) |
163 |
{ |
164 |
sysbus_register_withprop(&isabus_bridge_info); |
165 |
} |
166 |
|
167 |
device_init(isabus_register_devices) |