]>
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; | |
fbe3288d | 31 | target_phys_addr_t isa_mem_base = 0; |
f915a115 | 32 | |
2091ba23 GH |
33 | static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent); |
34 | ||
f915a115 | 35 | static struct BusInfo isa_bus_info = { |
2091ba23 GH |
36 | .name = "ISA", |
37 | .size = sizeof(ISABus), | |
38 | .print_dev = isabus_dev_print, | |
f915a115 GH |
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 | } | |
2091ba23 GH |
47 | if (NULL == dev) { |
48 | dev = qdev_create(NULL, "isabus-bridge"); | |
e23a1b33 | 49 | qdev_init_nofail(dev); |
2091ba23 | 50 | } |
f915a115 GH |
51 | |
52 | isabus = FROM_QBUS(ISABus, qbus_create(&isa_bus_info, dev, NULL)); | |
53 | return isabus; | |
54 | } | |
55 | ||
2091ba23 | 56 | void isa_bus_irqs(qemu_irq *irqs) |
f915a115 | 57 | { |
2091ba23 GH |
58 | isabus->irqs = irqs; |
59 | } | |
60 | ||
3a38d437 JS |
61 | /* |
62 | * isa_reserve_irq() reserves the ISA irq and returns the corresponding | |
63 | * qemu_irq entry for the i8259. | |
64 | * | |
65 | * This function is only for special cases such as the 'ferr', and | |
66 | * temporary use for normal devices until they are converted to qdev. | |
67 | */ | |
68 | qemu_irq isa_reserve_irq(int isairq) | |
69 | { | |
70 | if (isairq < 0 || isairq > 15) { | |
74782223 | 71 | hw_error("isa irq %d invalid", isairq); |
3a38d437 JS |
72 | } |
73 | if (isabus->assigned & (1 << isairq)) { | |
74782223 | 74 | hw_error("isa irq %d already assigned", isairq); |
3a38d437 JS |
75 | } |
76 | isabus->assigned |= (1 << isairq); | |
77 | return isabus->irqs[isairq]; | |
78 | } | |
79 | ||
2e15e23b | 80 | void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq) |
f915a115 | 81 | { |
2e15e23b GH |
82 | assert(dev->nirqs < ARRAY_SIZE(dev->isairq)); |
83 | if (isabus->assigned & (1 << isairq)) { | |
74782223 | 84 | hw_error("isa irq %d already assigned", isairq); |
2e15e23b GH |
85 | } |
86 | isabus->assigned |= (1 << isairq); | |
87 | dev->isairq[dev->nirqs] = isairq; | |
88 | *p = isabus->irqs[isairq]; | |
f915a115 GH |
89 | dev->nirqs++; |
90 | } | |
91 | ||
81a322d4 | 92 | static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base) |
f915a115 GH |
93 | { |
94 | ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev); | |
95 | ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base); | |
96 | ||
2091ba23 GH |
97 | dev->isairq[0] = -1; |
98 | dev->isairq[1] = -1; | |
81a322d4 GH |
99 | |
100 | return info->init(dev); | |
f915a115 GH |
101 | } |
102 | ||
103 | void isa_qdev_register(ISADeviceInfo *info) | |
104 | { | |
105 | info->qdev.init = isa_qdev_init; | |
106 | info->qdev.bus_info = &isa_bus_info; | |
107 | qdev_register(&info->qdev); | |
108 | } | |
109 | ||
924f6d72 | 110 | ISADevice *isa_create(const char *name) |
f915a115 GH |
111 | { |
112 | DeviceState *dev; | |
f915a115 GH |
113 | |
114 | if (!isabus) { | |
74782223 | 115 | hw_error("Tried to create isa device %s with no isa bus present.", |
3f66aa9c | 116 | name); |
f915a115 GH |
117 | } |
118 | dev = qdev_create(&isabus->qbus, name); | |
2e15e23b | 119 | return DO_UPCAST(ISADevice, qdev, dev); |
f915a115 | 120 | } |
2091ba23 | 121 | |
924f6d72 GH |
122 | ISADevice *isa_create_simple(const char *name) |
123 | { | |
124 | ISADevice *dev; | |
125 | ||
126 | dev = isa_create(name); | |
3f66aa9c | 127 | qdev_init_nofail(&dev->qdev); |
924f6d72 GH |
128 | return dev; |
129 | } | |
130 | ||
2091ba23 GH |
131 | static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent) |
132 | { | |
133 | ISADevice *d = DO_UPCAST(ISADevice, qdev, dev); | |
134 | ||
135 | if (d->isairq[1] != -1) { | |
136 | monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "", | |
137 | d->isairq[0], d->isairq[1]); | |
138 | } else if (d->isairq[0] != -1) { | |
139 | monitor_printf(mon, "%*sisa irq %d\n", indent, "", | |
140 | d->isairq[0]); | |
141 | } | |
142 | } | |
143 | ||
81a322d4 | 144 | static int isabus_bridge_init(SysBusDevice *dev) |
2091ba23 GH |
145 | { |
146 | /* nothing */ | |
81a322d4 | 147 | return 0; |
2091ba23 GH |
148 | } |
149 | ||
150 | static SysBusDeviceInfo isabus_bridge_info = { | |
151 | .init = isabus_bridge_init, | |
152 | .qdev.name = "isabus-bridge", | |
779206de | 153 | .qdev.fw_name = "isa", |
2091ba23 | 154 | .qdev.size = sizeof(SysBusDevice), |
787aa97a | 155 | .qdev.no_user = 1, |
2091ba23 GH |
156 | }; |
157 | ||
158 | static void isabus_register_devices(void) | |
159 | { | |
160 | sysbus_register_withprop(&isabus_bridge_info); | |
161 | } | |
162 | ||
163 | device_init(isabus_register_devices) |