]>
Commit | Line | Data |
---|---|---|
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 | #include "exec-memory.h" | |
24 | ||
25 | static ISABus *isabus; | |
26 | target_phys_addr_t isa_mem_base = 0; | |
27 | ||
28 | static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent); | |
29 | static char *isabus_get_fw_dev_path(DeviceState *dev); | |
30 | ||
31 | static struct BusInfo isa_bus_info = { | |
32 | .name = "ISA", | |
33 | .size = sizeof(ISABus), | |
34 | .print_dev = isabus_dev_print, | |
35 | .get_fw_dev_path = isabus_get_fw_dev_path, | |
36 | }; | |
37 | ||
38 | ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space_io) | |
39 | { | |
40 | if (isabus) { | |
41 | fprintf(stderr, "Can't create a second ISA bus\n"); | |
42 | return NULL; | |
43 | } | |
44 | if (NULL == dev) { | |
45 | dev = qdev_create(NULL, "isabus-bridge"); | |
46 | qdev_init_nofail(dev); | |
47 | } | |
48 | ||
49 | isabus = FROM_QBUS(ISABus, qbus_create(&isa_bus_info, dev, NULL)); | |
50 | isabus->address_space_io = address_space_io; | |
51 | return isabus; | |
52 | } | |
53 | ||
54 | void isa_bus_irqs(ISABus *bus, qemu_irq *irqs) | |
55 | { | |
56 | assert(!bus || bus == isabus); | |
57 | isabus->irqs = irqs; | |
58 | } | |
59 | ||
60 | /* | |
61 | * isa_get_irq() returns the corresponding qemu_irq entry for the i8259. | |
62 | * | |
63 | * This function is only for special cases such as the 'ferr', and | |
64 | * temporary use for normal devices until they are converted to qdev. | |
65 | */ | |
66 | qemu_irq isa_get_irq(ISADevice *dev, int isairq) | |
67 | { | |
68 | assert(!dev || DO_UPCAST(ISABus, qbus, dev->qdev.parent_bus) == isabus); | |
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(dev, isairq); | |
80 | dev->nirqs++; | |
81 | } | |
82 | ||
83 | static inline void isa_init_ioport(ISADevice *dev, uint16_t ioport) | |
84 | { | |
85 | if (dev && (dev->ioport_id == 0 || ioport < dev->ioport_id)) { | |
86 | dev->ioport_id = ioport; | |
87 | } | |
88 | } | |
89 | ||
90 | void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start) | |
91 | { | |
92 | memory_region_add_subregion(isabus->address_space_io, start, io); | |
93 | isa_init_ioport(dev, start); | |
94 | } | |
95 | ||
96 | void isa_register_portio_list(ISADevice *dev, uint16_t start, | |
97 | const MemoryRegionPortio *pio_start, | |
98 | void *opaque, const char *name) | |
99 | { | |
100 | PortioList *piolist = g_new(PortioList, 1); | |
101 | ||
102 | /* START is how we should treat DEV, regardless of the actual | |
103 | contents of the portio array. This is how the old code | |
104 | actually handled e.g. the FDC device. */ | |
105 | isa_init_ioport(dev, start); | |
106 | ||
107 | portio_list_init(piolist, pio_start, opaque, name); | |
108 | portio_list_add(piolist, isabus->address_space_io, start); | |
109 | } | |
110 | ||
111 | static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base) | |
112 | { | |
113 | ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev); | |
114 | ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base); | |
115 | ||
116 | dev->isairq[0] = -1; | |
117 | dev->isairq[1] = -1; | |
118 | ||
119 | return info->init(dev); | |
120 | } | |
121 | ||
122 | void isa_qdev_register(ISADeviceInfo *info) | |
123 | { | |
124 | info->qdev.init = isa_qdev_init; | |
125 | info->qdev.bus_info = &isa_bus_info; | |
126 | qdev_register(&info->qdev); | |
127 | } | |
128 | ||
129 | ISADevice *isa_create(ISABus *bus, const char *name) | |
130 | { | |
131 | DeviceState *dev; | |
132 | ||
133 | if (!bus) { | |
134 | hw_error("Tried to create isa device %s with no isa bus present.", | |
135 | name); | |
136 | } | |
137 | dev = qdev_create(&bus->qbus, name); | |
138 | return DO_UPCAST(ISADevice, qdev, dev); | |
139 | } | |
140 | ||
141 | ISADevice *isa_try_create(ISABus *bus, const char *name) | |
142 | { | |
143 | DeviceState *dev; | |
144 | ||
145 | if (!bus) { | |
146 | hw_error("Tried to create isa device %s with no isa bus present.", | |
147 | name); | |
148 | } | |
149 | dev = qdev_try_create(&bus->qbus, name); | |
150 | return DO_UPCAST(ISADevice, qdev, dev); | |
151 | } | |
152 | ||
153 | ISADevice *isa_create_simple(ISABus *bus, const char *name) | |
154 | { | |
155 | ISADevice *dev; | |
156 | ||
157 | dev = isa_create(bus, name); | |
158 | qdev_init_nofail(&dev->qdev); | |
159 | return dev; | |
160 | } | |
161 | ||
162 | static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent) | |
163 | { | |
164 | ISADevice *d = DO_UPCAST(ISADevice, qdev, dev); | |
165 | ||
166 | if (d->isairq[1] != -1) { | |
167 | monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "", | |
168 | d->isairq[0], d->isairq[1]); | |
169 | } else if (d->isairq[0] != -1) { | |
170 | monitor_printf(mon, "%*sisa irq %d\n", indent, "", | |
171 | d->isairq[0]); | |
172 | } | |
173 | } | |
174 | ||
175 | static int isabus_bridge_init(SysBusDevice *dev) | |
176 | { | |
177 | /* nothing */ | |
178 | return 0; | |
179 | } | |
180 | ||
181 | static SysBusDeviceInfo isabus_bridge_info = { | |
182 | .init = isabus_bridge_init, | |
183 | .qdev.name = "isabus-bridge", | |
184 | .qdev.fw_name = "isa", | |
185 | .qdev.size = sizeof(SysBusDevice), | |
186 | .qdev.no_user = 1, | |
187 | }; | |
188 | ||
189 | static void isabus_register_devices(void) | |
190 | { | |
191 | sysbus_register_withprop(&isabus_bridge_info); | |
192 | } | |
193 | ||
194 | static char *isabus_get_fw_dev_path(DeviceState *dev) | |
195 | { | |
196 | ISADevice *d = (ISADevice*)dev; | |
197 | char path[40]; | |
198 | int off; | |
199 | ||
200 | off = snprintf(path, sizeof(path), "%s", qdev_fw_name(dev)); | |
201 | if (d->ioport_id) { | |
202 | snprintf(path + off, sizeof(path) - off, "@%04x", d->ioport_id); | |
203 | } | |
204 | ||
205 | return strdup(path); | |
206 | } | |
207 | ||
208 | MemoryRegion *isa_address_space(ISADevice *dev) | |
209 | { | |
210 | return get_system_memory(); | |
211 | } | |
212 | ||
213 | device_init(isabus_register_devices) |