xref: /openbmc/qemu/hw/intc/realview_gic.c (revision 6a0acfff)
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 #include "hw/irq.h"
15 
16 static void realview_gic_set_irq(void *opaque, int irq, int level)
17 {
18     RealViewGICState *s = (RealViewGICState *)opaque;
19 
20     qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level);
21 }
22 
23 static void realview_gic_realize(DeviceState *dev, Error **errp)
24 {
25     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
26     RealViewGICState *s = REALVIEW_GIC(dev);
27     SysBusDevice *busdev;
28     Error *err = NULL;
29     /* The GICs on the RealView boards have a fixed nonconfigurable
30      * number of interrupt lines, so we don't need to expose this as
31      * a qdev property.
32      */
33     int numirq = 96;
34 
35     qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", numirq);
36     object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
37     if (err != NULL) {
38         error_propagate(errp, err);
39         return;
40     }
41     busdev = SYS_BUS_DEVICE(&s->gic);
42 
43     /* Pass through outbound IRQ lines from the GIC */
44     sysbus_pass_irq(sbd, busdev);
45 
46     /* Pass through inbound GPIO lines to the GIC */
47     qdev_init_gpio_in(dev, realview_gic_set_irq, numirq - 32);
48 
49     memory_region_add_subregion(&s->container, 0,
50                                 sysbus_mmio_get_region(busdev, 1));
51     memory_region_add_subregion(&s->container, 0x1000,
52                                 sysbus_mmio_get_region(busdev, 0));
53 }
54 
55 static void realview_gic_init(Object *obj)
56 {
57     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
58     RealViewGICState *s = REALVIEW_GIC(obj);
59 
60     memory_region_init(&s->container, OBJECT(s),
61                        "realview-gic-container", 0x2000);
62     sysbus_init_mmio(sbd, &s->container);
63 
64     sysbus_init_child_obj(obj, "gic", &s->gic, sizeof(s->gic), TYPE_ARM_GIC);
65     qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", 1);
66 }
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 = {
76     .name          = TYPE_REALVIEW_GIC,
77     .parent        = TYPE_SYS_BUS_DEVICE,
78     .instance_size = sizeof(RealViewGICState),
79     .instance_init = realview_gic_init,
80     .class_init    = realview_gic_class_init,
81 };
82 
83 static void realview_gic_register_types(void)
84 {
85     type_register_static(&realview_gic_info);
86 }
87 
88 type_init(realview_gic_register_types)
89