Statistics
| Branch: | Revision:

root / hw / isa-bus.c @ 8ca209ad

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