Statistics
| Branch: | Revision:

root / hw / isa-bus.c @ 4445b0a6

History | View | Annotate | Download (2.7 kB)

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

    
23
struct ISABus {
24
    BusState qbus;
25
};
26
static ISABus *isabus;
27

    
28
static struct BusInfo isa_bus_info = {
29
    .name  = "ISA",
30
    .size  = sizeof(ISABus),
31
    .props = (Property[]) {
32
        {
33
            .name   = "iobase",
34
            .info   = &qdev_prop_hex32,
35
            .offset = offsetof(ISADevice, iobase[0]),
36
            .defval = (uint32_t[]) { -1 },
37
        },{
38
            .name   = "iobase2",
39
            .info   = &qdev_prop_hex32,
40
            .offset = offsetof(ISADevice, iobase[1]),
41
            .defval = (uint32_t[]) { -1 },
42
        },
43
        {/* end of list */}
44
    }
45
};
46

    
47
ISABus *isa_bus_new(DeviceState *dev)
48
{
49
    if (isabus) {
50
        fprintf(stderr, "Can't create a second ISA bus\n");
51
        return NULL;
52
    }
53

    
54
    isabus = FROM_QBUS(ISABus, qbus_create(&isa_bus_info, dev, NULL));
55
    return isabus;
56
}
57

    
58
void isa_connect_irq(ISADevice *dev, int n, qemu_irq irq)
59
{
60
    assert(n >= 0 && n < dev->nirqs);
61
    if (dev->irqs[n])
62
        *dev->irqs[n] = irq;
63
}
64

    
65
void isa_init_irq(ISADevice *dev, qemu_irq *p)
66
{
67
    assert(dev->nirqs < ARRAY_SIZE(dev->irqs));
68
    dev->irqs[dev->nirqs] = p;
69
    dev->nirqs++;
70
}
71

    
72
static void isa_qdev_init(DeviceState *qdev, DeviceInfo *base)
73
{
74
    ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev);
75
    ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base);
76

    
77
    info->init(dev);
78
}
79

    
80
void isa_qdev_register(ISADeviceInfo *info)
81
{
82
    info->qdev.init = isa_qdev_init;
83
    info->qdev.bus_info = &isa_bus_info;
84
    qdev_register(&info->qdev);
85
}
86

    
87
ISADevice *isa_create_simple(const char *name, uint32_t iobase, uint32_t iobase2)
88
{
89
    DeviceState *dev;
90
    ISADevice *isa;
91

    
92
    if (!isabus) {
93
        fprintf(stderr, "Tried to create isa device %s with no isa bus present.\n", name);
94
        return NULL;
95
    }
96
    dev = qdev_create(&isabus->qbus, name);
97
    isa = DO_UPCAST(ISADevice, qdev, dev);
98
    isa->iobase[0] = iobase;
99
    isa->iobase[1] = iobase2;
100
    qdev_init(dev);
101
    return isa;
102
}