]> git.proxmox.com Git - qemu.git/blame - hw/isa-bus.c
hw/eepro100.c: Use extended TBD only where applicable
[qemu.git] / hw / isa-bus.c
CommitLineData
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"
21#include "isa.h"
22
23struct ISABus {
24 BusState qbus;
25};
26static ISABus *isabus;
27
28static struct BusInfo isa_bus_info = {
29 .name = "ISA",
30 .size = sizeof(ISABus),
31 .props = (Property[]) {
aa7116cb
GH
32 DEFINE_PROP_HEX32("iobase", ISADevice, iobase[0], -1),
33 DEFINE_PROP_HEX32("iobase2", ISADevice, iobase[1], -1),
34 DEFINE_PROP_END_OF_LIST(),
f915a115
GH
35 }
36};
37
38ISABus *isa_bus_new(DeviceState *dev)
39{
40 if (isabus) {
41 fprintf(stderr, "Can't create a second ISA bus\n");
42 return NULL;
43 }
44
45 isabus = FROM_QBUS(ISABus, qbus_create(&isa_bus_info, dev, NULL));
46 return isabus;
47}
48
49void isa_connect_irq(ISADevice *dev, int n, qemu_irq irq)
50{
51 assert(n >= 0 && n < dev->nirqs);
52 if (dev->irqs[n])
53 *dev->irqs[n] = irq;
54}
55
56void isa_init_irq(ISADevice *dev, qemu_irq *p)
57{
58 assert(dev->nirqs < ARRAY_SIZE(dev->irqs));
59 dev->irqs[dev->nirqs] = p;
60 dev->nirqs++;
61}
62
63static void isa_qdev_init(DeviceState *qdev, DeviceInfo *base)
64{
65 ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev);
66 ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base);
67
68 info->init(dev);
69}
70
71void isa_qdev_register(ISADeviceInfo *info)
72{
73 info->qdev.init = isa_qdev_init;
74 info->qdev.bus_info = &isa_bus_info;
75 qdev_register(&info->qdev);
76}
77
78ISADevice *isa_create_simple(const char *name, uint32_t iobase, uint32_t iobase2)
79{
80 DeviceState *dev;
81 ISADevice *isa;
82
83 if (!isabus) {
84 fprintf(stderr, "Tried to create isa device %s with no isa bus present.\n", name);
85 return NULL;
86 }
87 dev = qdev_create(&isabus->qbus, name);
88 isa = DO_UPCAST(ISADevice, qdev, dev);
89 isa->iobase[0] = iobase;
90 isa->iobase[1] = iobase2;
91 qdev_init(dev);
92 return isa;
93}