xref: /openbmc/qemu/hw/intc/realview_gic.c (revision 500eb6db)
1 /*
2  * ARM RealView Emulation Baseboard Interrupt Controller
3  *
4  * Copyright (c) 2006-2007 CodeSourcery.
5  * Written by Paul Brook
6  *
7  * This code is licensed under the GPL.
8  */
9 
10 #include "qemu/osdep.h"
11 #include "qapi/error.h"
12 #include "qemu/module.h"
13 #include "hw/intc/realview_gic.h"
14 
15 static void realview_gic_set_irq(void *opaque, int irq, int level)
16 {
17     RealViewGICState *s = (RealViewGICState *)opaque;
18 
19     qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level);
20 }
21 
22 static void realview_gic_realize(DeviceState *dev, Error **errp)
23 {
24     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
25     RealViewGICState *s = REALVIEW_GIC(dev);
26     SysBusDevice *busdev;
27     Error *err = NULL;
28     /* The GICs on the RealView boards have a fixed nonconfigurable
29      * number of interrupt lines, so we don't need to expose this as
30      * a qdev property.
31      */
32     int numirq = 96;
33 
34     qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", numirq);
35     object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
36     if (err != NULL) {
37         error_propagate(errp, err);
38         return;
39     }
40     busdev = SYS_BUS_DEVICE(&s->gic);
41 
42     /* Pass through outbound IRQ lines from the GIC */
43     sysbus_pass_irq(sbd, busdev);
44 
45     /* Pass through inbound GPIO lines to the GIC */
46     qdev_init_gpio_in(dev, realview_gic_set_irq, numirq - 32);
47 
48     memory_region_add_subregion(&s->container, 0,
49                                 sysbus_mmio_get_region(busdev, 1));
50     memory_region_add_subregion(&s->container, 0x1000,
51                                 sysbus_mmio_get_region(busdev, 0));
52 }
53 
54 static void realview_gic_init(Object *obj)
55 {
56     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
57     RealViewGICState *s = REALVIEW_GIC(obj);
58 
59     memory_region_init(&s->container, OBJECT(s),
60                        "realview-gic-container", 0x2000);
61     sysbus_init_mmio(sbd, &s->container);
62 
63     sysbus_init_child_obj(obj, "gic", &s->gic, sizeof(s->gic), TYPE_ARM_GIC);
64     qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", 1);
65 }
66 
67 static void realview_gic_class_init(ObjectClass *oc, void *data)
68 {
69     DeviceClass *dc = DEVICE_CLASS(oc);
70 
71     dc->realize = realview_gic_realize;
72 }
73 
74 static const TypeInfo realview_gic_info = {
75     .name          = TYPE_REALVIEW_GIC,
76     .parent        = TYPE_SYS_BUS_DEVICE,
77     .instance_size = sizeof(RealViewGICState),
78     .instance_init = realview_gic_init,
79     .class_init    = realview_gic_class_init,
80 };
81 
82 static void realview_gic_register_types(void)
83 {
84     type_register_static(&realview_gic_info);
85 }
86 
87 type_init(realview_gic_register_types)
88