]>
Commit | Line | Data |
---|---|---|
f915a115 GH |
1 | /* |
2 | * isa bus support for qdev. | |
3 | * | |
4 | * Copyright (c) 2009 Gerd Hoffmann <[email protected]> | |
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 | ||
79 | void isa_init_irq(ISADevice *dev, qemu_irq *p) | |
80 | { | |
81 | assert(dev->nirqs < ARRAY_SIZE(dev->irqs)); | |
82 | dev->irqs[dev->nirqs] = p; | |
83 | dev->nirqs++; | |
84 | } | |
85 | ||
86 | static void isa_qdev_init(DeviceState *qdev, DeviceInfo *base) | |
87 | { | |
88 | ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev); | |
89 | ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base); | |
90 | ||
2091ba23 GH |
91 | dev->isairq[0] = -1; |
92 | dev->isairq[1] = -1; | |
f915a115 GH |
93 | info->init(dev); |
94 | } | |
95 | ||
96 | void isa_qdev_register(ISADeviceInfo *info) | |
97 | { | |
98 | info->qdev.init = isa_qdev_init; | |
99 | info->qdev.bus_info = &isa_bus_info; | |
100 | qdev_register(&info->qdev); | |
101 | } | |
102 | ||
103 | ISADevice *isa_create_simple(const char *name, uint32_t iobase, uint32_t iobase2) | |
104 | { | |
105 | DeviceState *dev; | |
106 | ISADevice *isa; | |
107 | ||
108 | if (!isabus) { | |
109 | fprintf(stderr, "Tried to create isa device %s with no isa bus present.\n", name); | |
110 | return NULL; | |
111 | } | |
112 | dev = qdev_create(&isabus->qbus, name); | |
113 | isa = DO_UPCAST(ISADevice, qdev, dev); | |
114 | isa->iobase[0] = iobase; | |
115 | isa->iobase[1] = iobase2; | |
116 | qdev_init(dev); | |
117 | return isa; | |
118 | } | |
2091ba23 GH |
119 | |
120 | static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent) | |
121 | { | |
122 | ISADevice *d = DO_UPCAST(ISADevice, qdev, dev); | |
123 | ||
124 | if (d->isairq[1] != -1) { | |
125 | monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "", | |
126 | d->isairq[0], d->isairq[1]); | |
127 | } else if (d->isairq[0] != -1) { | |
128 | monitor_printf(mon, "%*sisa irq %d\n", indent, "", | |
129 | d->isairq[0]); | |
130 | } | |
131 | } | |
132 | ||
133 | static void isabus_bridge_init(SysBusDevice *dev) | |
134 | { | |
135 | /* nothing */ | |
136 | } | |
137 | ||
138 | static SysBusDeviceInfo isabus_bridge_info = { | |
139 | .init = isabus_bridge_init, | |
140 | .qdev.name = "isabus-bridge", | |
141 | .qdev.size = sizeof(SysBusDevice), | |
142 | }; | |
143 | ||
144 | static void isabus_register_devices(void) | |
145 | { | |
146 | sysbus_register_withprop(&isabus_bridge_info); | |
147 | } | |
148 | ||
149 | device_init(isabus_register_devices) |