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