realview_gic.c 2.5 KB
Newer Older
P
pbrook 已提交
1 2 3 4 5 6
/*
 * ARM RealView Emulation Baseboard Interrupt Controller
 *
 * Copyright (c) 2006-2007 CodeSourcery.
 * Written by Paul Brook
 *
M
Matthew Fernandez 已提交
7
 * This code is licensed under the GPL.
P
pbrook 已提交
8 9
 */

P
Peter Maydell 已提交
10
#include "qemu/osdep.h"
11
#include "hw/intc/realview_gic.h"
P
Paul Brook 已提交
12

13
static void realview_gic_set_irq(void *opaque, int irq, int level)
P
pbrook 已提交
14
{
15
    RealViewGICState *s = (RealViewGICState *)opaque;
16 17

    qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level);
P
Paul Brook 已提交
18 19
}

20
static void realview_gic_realize(DeviceState *dev, Error **errp)
P
Paul Brook 已提交
21
{
22
    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
A
Andreas Färber 已提交
23
    RealViewGICState *s = REALVIEW_GIC(dev);
24
    SysBusDevice *busdev;
25
    Error *err = NULL;
26 27 28 29
    /* The GICs on the RealView boards have a fixed nonconfigurable
     * number of interrupt lines, so we don't need to expose this as
     * a qdev property.
     */
30 31
    int numirq = 96;

32 33 34 35 36 37 38
    qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", numirq);
    object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
    if (err != NULL) {
        error_propagate(errp, err);
        return;
    }
    busdev = SYS_BUS_DEVICE(&s->gic);
39 40

    /* Pass through outbound IRQ lines from the GIC */
A
Andreas Färber 已提交
41
    sysbus_pass_irq(sbd, busdev);
42 43

    /* Pass through inbound GPIO lines to the GIC */
A
Andreas Färber 已提交
44
    qdev_init_gpio_in(dev, realview_gic_set_irq, numirq - 32);
45 46 47 48 49

    memory_region_add_subregion(&s->container, 0,
                                sysbus_mmio_get_region(busdev, 1));
    memory_region_add_subregion(&s->container, 0x1000,
                                sysbus_mmio_get_region(busdev, 0));
50 51 52 53 54 55 56 57 58 59
}

static void realview_gic_init(Object *obj)
{
    SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
    RealViewGICState *s = REALVIEW_GIC(obj);
    DeviceState *gicdev;

    memory_region_init(&s->container, OBJECT(s),
                       "realview-gic-container", 0x2000);
A
Andreas Färber 已提交
60
    sysbus_init_mmio(sbd, &s->container);
61 62 63 64 65

    object_initialize(&s->gic, sizeof(s->gic), TYPE_ARM_GIC);
    gicdev = DEVICE(&s->gic);
    qdev_set_parent_bus(gicdev, sysbus_get_default());
    qdev_prop_set_uint32(gicdev, "num-cpu", 1);
P
pbrook 已提交
66
}
P
Paul Brook 已提交
67

68
static void realview_gic_class_init(ObjectClass *oc, void *data)
69
{
70
    DeviceClass *dc = DEVICE_CLASS(oc);
71

72
    dc->realize = realview_gic_realize;
73 74
}

75
static const TypeInfo realview_gic_info = {
A
Andreas Färber 已提交
76
    .name          = TYPE_REALVIEW_GIC,
77 78
    .parent        = TYPE_SYS_BUS_DEVICE,
    .instance_size = sizeof(RealViewGICState),
79
    .instance_init = realview_gic_init,
80
    .class_init    = realview_gic_class_init,
81 82
};

A
Andreas Färber 已提交
83
static void realview_gic_register_types(void)
P
Paul Brook 已提交
84
{
85
    type_register_static(&realview_gic_info);
P
Paul Brook 已提交
86 87
}

A
Andreas Färber 已提交
88
type_init(realview_gic_register_types)