root / hw / isa-bus.c @ f7b4f61f
History | View | Annotate | Download (4.2 kB)
1 | f915a115 | Gerd Hoffmann | /*
|
---|---|---|---|
2 | f915a115 | Gerd Hoffmann | * isa bus support for qdev.
|
3 | f915a115 | Gerd Hoffmann | *
|
4 | f915a115 | Gerd Hoffmann | * Copyright (c) 2009 Gerd Hoffmann <kraxel@redhat.com>
|
5 | f915a115 | Gerd Hoffmann | *
|
6 | f915a115 | Gerd Hoffmann | * This library is free software; you can redistribute it and/or
|
7 | f915a115 | Gerd Hoffmann | * modify it under the terms of the GNU Lesser General Public
|
8 | f915a115 | Gerd Hoffmann | * License as published by the Free Software Foundation; either
|
9 | f915a115 | Gerd Hoffmann | * version 2 of the License, or (at your option) any later version.
|
10 | f915a115 | Gerd Hoffmann | *
|
11 | f915a115 | Gerd Hoffmann | * This library is distributed in the hope that it will be useful,
|
12 | f915a115 | Gerd Hoffmann | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | f915a115 | Gerd Hoffmann | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | f915a115 | Gerd Hoffmann | * Lesser General Public License for more details.
|
15 | f915a115 | Gerd Hoffmann | *
|
16 | f915a115 | Gerd Hoffmann | * You should have received a copy of the GNU Lesser General Public
|
17 | f915a115 | Gerd Hoffmann | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
18 | f915a115 | Gerd Hoffmann | */
|
19 | f915a115 | Gerd Hoffmann | #include "hw.h" |
20 | f915a115 | Gerd Hoffmann | #include "sysemu.h" |
21 | 2091ba23 | Gerd Hoffmann | #include "monitor.h" |
22 | 2091ba23 | Gerd Hoffmann | #include "sysbus.h" |
23 | f915a115 | Gerd Hoffmann | #include "isa.h" |
24 | f915a115 | Gerd Hoffmann | |
25 | f915a115 | Gerd Hoffmann | struct ISABus {
|
26 | f915a115 | Gerd Hoffmann | BusState qbus; |
27 | 2091ba23 | Gerd Hoffmann | qemu_irq *irqs; |
28 | 2091ba23 | Gerd Hoffmann | uint32_t assigned; |
29 | f915a115 | Gerd Hoffmann | }; |
30 | f915a115 | Gerd Hoffmann | static ISABus *isabus;
|
31 | f915a115 | Gerd Hoffmann | |
32 | 2091ba23 | Gerd Hoffmann | static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent); |
33 | 2091ba23 | Gerd Hoffmann | |
34 | f915a115 | Gerd Hoffmann | static struct BusInfo isa_bus_info = { |
35 | 2091ba23 | Gerd Hoffmann | .name = "ISA",
|
36 | 2091ba23 | Gerd Hoffmann | .size = sizeof(ISABus),
|
37 | 2091ba23 | Gerd Hoffmann | .print_dev = isabus_dev_print, |
38 | f915a115 | Gerd Hoffmann | }; |
39 | f915a115 | Gerd Hoffmann | |
40 | f915a115 | Gerd Hoffmann | ISABus *isa_bus_new(DeviceState *dev) |
41 | f915a115 | Gerd Hoffmann | { |
42 | f915a115 | Gerd Hoffmann | if (isabus) {
|
43 | f915a115 | Gerd Hoffmann | fprintf(stderr, "Can't create a second ISA bus\n");
|
44 | f915a115 | Gerd Hoffmann | return NULL; |
45 | f915a115 | Gerd Hoffmann | } |
46 | 2091ba23 | Gerd Hoffmann | if (NULL == dev) { |
47 | 2091ba23 | Gerd Hoffmann | dev = qdev_create(NULL, "isabus-bridge"); |
48 | 2091ba23 | Gerd Hoffmann | qdev_init(dev); |
49 | 2091ba23 | Gerd Hoffmann | } |
50 | f915a115 | Gerd Hoffmann | |
51 | f915a115 | Gerd Hoffmann | isabus = FROM_QBUS(ISABus, qbus_create(&isa_bus_info, dev, NULL));
|
52 | f915a115 | Gerd Hoffmann | return isabus;
|
53 | f915a115 | Gerd Hoffmann | } |
54 | f915a115 | Gerd Hoffmann | |
55 | 2091ba23 | Gerd Hoffmann | void isa_bus_irqs(qemu_irq *irqs)
|
56 | f915a115 | Gerd Hoffmann | { |
57 | 2091ba23 | Gerd Hoffmann | isabus->irqs = irqs; |
58 | 2091ba23 | Gerd Hoffmann | } |
59 | 2091ba23 | Gerd Hoffmann | |
60 | 3a38d437 | Jes Sorensen | /*
|
61 | 3a38d437 | Jes Sorensen | * isa_reserve_irq() reserves the ISA irq and returns the corresponding
|
62 | 3a38d437 | Jes Sorensen | * qemu_irq entry for the i8259.
|
63 | 3a38d437 | Jes Sorensen | *
|
64 | 3a38d437 | Jes Sorensen | * This function is only for special cases such as the 'ferr', and
|
65 | 3a38d437 | Jes Sorensen | * temporary use for normal devices until they are converted to qdev.
|
66 | 3a38d437 | Jes Sorensen | */
|
67 | 3a38d437 | Jes Sorensen | qemu_irq isa_reserve_irq(int isairq)
|
68 | 3a38d437 | Jes Sorensen | { |
69 | 3a38d437 | Jes Sorensen | if (isairq < 0 || isairq > 15) { |
70 | 3a38d437 | Jes Sorensen | fprintf(stderr, "isa irq %d invalid\n", isairq);
|
71 | 3a38d437 | Jes Sorensen | exit(1);
|
72 | 3a38d437 | Jes Sorensen | } |
73 | 3a38d437 | Jes Sorensen | if (isabus->assigned & (1 << isairq)) { |
74 | 3a38d437 | Jes Sorensen | fprintf(stderr, "isa irq %d already assigned\n", isairq);
|
75 | 3a38d437 | Jes Sorensen | exit(1);
|
76 | 3a38d437 | Jes Sorensen | } |
77 | 3a38d437 | Jes Sorensen | isabus->assigned |= (1 << isairq);
|
78 | 3a38d437 | Jes Sorensen | return isabus->irqs[isairq];
|
79 | 3a38d437 | Jes Sorensen | } |
80 | 3a38d437 | Jes Sorensen | |
81 | 2e15e23b | Gerd Hoffmann | void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq) |
82 | f915a115 | Gerd Hoffmann | { |
83 | 2e15e23b | Gerd Hoffmann | assert(dev->nirqs < ARRAY_SIZE(dev->isairq)); |
84 | 2e15e23b | Gerd Hoffmann | if (isabus->assigned & (1 << isairq)) { |
85 | 2e15e23b | Gerd Hoffmann | fprintf(stderr, "isa irq %d already assigned\n", isairq);
|
86 | 2e15e23b | Gerd Hoffmann | exit(1);
|
87 | 2e15e23b | Gerd Hoffmann | } |
88 | 2e15e23b | Gerd Hoffmann | isabus->assigned |= (1 << isairq);
|
89 | 2e15e23b | Gerd Hoffmann | dev->isairq[dev->nirqs] = isairq; |
90 | 2e15e23b | Gerd Hoffmann | *p = isabus->irqs[isairq]; |
91 | f915a115 | Gerd Hoffmann | dev->nirqs++; |
92 | f915a115 | Gerd Hoffmann | } |
93 | f915a115 | Gerd Hoffmann | |
94 | 81a322d4 | Gerd Hoffmann | static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base) |
95 | f915a115 | Gerd Hoffmann | { |
96 | f915a115 | Gerd Hoffmann | ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev); |
97 | f915a115 | Gerd Hoffmann | ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base); |
98 | f915a115 | Gerd Hoffmann | |
99 | 2091ba23 | Gerd Hoffmann | dev->isairq[0] = -1; |
100 | 2091ba23 | Gerd Hoffmann | dev->isairq[1] = -1; |
101 | 81a322d4 | Gerd Hoffmann | |
102 | 81a322d4 | Gerd Hoffmann | return info->init(dev);
|
103 | f915a115 | Gerd Hoffmann | } |
104 | f915a115 | Gerd Hoffmann | |
105 | f915a115 | Gerd Hoffmann | void isa_qdev_register(ISADeviceInfo *info)
|
106 | f915a115 | Gerd Hoffmann | { |
107 | f915a115 | Gerd Hoffmann | info->qdev.init = isa_qdev_init; |
108 | f915a115 | Gerd Hoffmann | info->qdev.bus_info = &isa_bus_info; |
109 | f915a115 | Gerd Hoffmann | qdev_register(&info->qdev); |
110 | f915a115 | Gerd Hoffmann | } |
111 | f915a115 | Gerd Hoffmann | |
112 | 924f6d72 | Gerd Hoffmann | ISADevice *isa_create(const char *name) |
113 | f915a115 | Gerd Hoffmann | { |
114 | f915a115 | Gerd Hoffmann | DeviceState *dev; |
115 | f915a115 | Gerd Hoffmann | |
116 | f915a115 | Gerd Hoffmann | if (!isabus) {
|
117 | f915a115 | Gerd Hoffmann | fprintf(stderr, "Tried to create isa device %s with no isa bus present.\n", name);
|
118 | f915a115 | Gerd Hoffmann | return NULL; |
119 | f915a115 | Gerd Hoffmann | } |
120 | f915a115 | Gerd Hoffmann | dev = qdev_create(&isabus->qbus, name); |
121 | 2e15e23b | Gerd Hoffmann | return DO_UPCAST(ISADevice, qdev, dev);
|
122 | f915a115 | Gerd Hoffmann | } |
123 | 2091ba23 | Gerd Hoffmann | |
124 | 924f6d72 | Gerd Hoffmann | ISADevice *isa_create_simple(const char *name) |
125 | 924f6d72 | Gerd Hoffmann | { |
126 | 924f6d72 | Gerd Hoffmann | ISADevice *dev; |
127 | 924f6d72 | Gerd Hoffmann | |
128 | 924f6d72 | Gerd Hoffmann | dev = isa_create(name); |
129 | 924f6d72 | Gerd Hoffmann | if (qdev_init(&dev->qdev) != 0) { |
130 | 924f6d72 | Gerd Hoffmann | qdev_free(&dev->qdev); |
131 | 924f6d72 | Gerd Hoffmann | return NULL; |
132 | 924f6d72 | Gerd Hoffmann | } |
133 | 924f6d72 | Gerd Hoffmann | return dev;
|
134 | 924f6d72 | Gerd Hoffmann | } |
135 | 924f6d72 | Gerd Hoffmann | |
136 | 2091ba23 | Gerd Hoffmann | static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent) |
137 | 2091ba23 | Gerd Hoffmann | { |
138 | 2091ba23 | Gerd Hoffmann | ISADevice *d = DO_UPCAST(ISADevice, qdev, dev); |
139 | 2091ba23 | Gerd Hoffmann | |
140 | 2091ba23 | Gerd Hoffmann | if (d->isairq[1] != -1) { |
141 | 2091ba23 | Gerd Hoffmann | monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "", |
142 | 2091ba23 | Gerd Hoffmann | d->isairq[0], d->isairq[1]); |
143 | 2091ba23 | Gerd Hoffmann | } else if (d->isairq[0] != -1) { |
144 | 2091ba23 | Gerd Hoffmann | monitor_printf(mon, "%*sisa irq %d\n", indent, "", |
145 | 2091ba23 | Gerd Hoffmann | d->isairq[0]);
|
146 | 2091ba23 | Gerd Hoffmann | } |
147 | 2091ba23 | Gerd Hoffmann | } |
148 | 2091ba23 | Gerd Hoffmann | |
149 | 81a322d4 | Gerd Hoffmann | static int isabus_bridge_init(SysBusDevice *dev) |
150 | 2091ba23 | Gerd Hoffmann | { |
151 | 2091ba23 | Gerd Hoffmann | /* nothing */
|
152 | 81a322d4 | Gerd Hoffmann | return 0; |
153 | 2091ba23 | Gerd Hoffmann | } |
154 | 2091ba23 | Gerd Hoffmann | |
155 | 2091ba23 | Gerd Hoffmann | static SysBusDeviceInfo isabus_bridge_info = {
|
156 | 2091ba23 | Gerd Hoffmann | .init = isabus_bridge_init, |
157 | 2091ba23 | Gerd Hoffmann | .qdev.name = "isabus-bridge",
|
158 | 2091ba23 | Gerd Hoffmann | .qdev.size = sizeof(SysBusDevice),
|
159 | 787aa97a | Gerd Hoffmann | .qdev.no_user = 1,
|
160 | 2091ba23 | Gerd Hoffmann | }; |
161 | 2091ba23 | Gerd Hoffmann | |
162 | 2091ba23 | Gerd Hoffmann | static void isabus_register_devices(void) |
163 | 2091ba23 | Gerd Hoffmann | { |
164 | 2091ba23 | Gerd Hoffmann | sysbus_register_withprop(&isabus_bridge_info); |
165 | 2091ba23 | Gerd Hoffmann | } |
166 | 2091ba23 | Gerd Hoffmann | |
167 | 2091ba23 | Gerd Hoffmann | device_init(isabus_register_devices) |