xref: /openbmc/qemu/hw/intc/realview_gic.c (revision 56c4bfb3)
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 "hw/sysbus.h"
11 
12 #define TYPE_REALVIEW_GIC "realview_gic"
13 #define REALVIEW_GIC(obj) \
14     OBJECT_CHECK(RealViewGICState, (obj), TYPE_REALVIEW_GIC)
15 
16 typedef struct {
17     SysBusDevice parent_obj;
18 
19     DeviceState *gic;
20     MemoryRegion container;
21 } RealViewGICState;
22 
23 static void realview_gic_set_irq(void *opaque, int irq, int level)
24 {
25     RealViewGICState *s = (RealViewGICState *)opaque;
26     qemu_set_irq(qdev_get_gpio_in(s->gic, irq), level);
27 }
28 
29 static int realview_gic_init(SysBusDevice *sbd)
30 {
31     DeviceState *dev = DEVICE(sbd);
32     RealViewGICState *s = REALVIEW_GIC(dev);
33     SysBusDevice *busdev;
34     /* The GICs on the RealView boards have a fixed nonconfigurable
35      * number of interrupt lines, so we don't need to expose this as
36      * a qdev property.
37      */
38     int numirq = 96;
39 
40     s->gic = qdev_create(NULL, "arm_gic");
41     qdev_prop_set_uint32(s->gic, "num-cpu", 1);
42     qdev_prop_set_uint32(s->gic, "num-irq", numirq);
43     qdev_init_nofail(s->gic);
44     busdev = SYS_BUS_DEVICE(s->gic);
45 
46     /* Pass through outbound IRQ lines from the GIC */
47     sysbus_pass_irq(sbd, busdev);
48 
49     /* Pass through inbound GPIO lines to the GIC */
50     qdev_init_gpio_in(dev, realview_gic_set_irq, numirq - 32);
51 
52     memory_region_init(&s->container, OBJECT(s),
53                        "realview-gic-container", 0x2000);
54     memory_region_add_subregion(&s->container, 0,
55                                 sysbus_mmio_get_region(busdev, 1));
56     memory_region_add_subregion(&s->container, 0x1000,
57                                 sysbus_mmio_get_region(busdev, 0));
58     sysbus_init_mmio(sbd, &s->container);
59     return 0;
60 }
61 
62 static void realview_gic_class_init(ObjectClass *klass, void *data)
63 {
64     SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
65 
66     sdc->init = realview_gic_init;
67 }
68 
69 static const TypeInfo realview_gic_info = {
70     .name          = TYPE_REALVIEW_GIC,
71     .parent        = TYPE_SYS_BUS_DEVICE,
72     .instance_size = sizeof(RealViewGICState),
73     .class_init    = realview_gic_class_init,
74 };
75 
76 static void realview_gic_register_types(void)
77 {
78     type_register_static(&realview_gic_info);
79 }
80 
81 type_init(realview_gic_register_types)
82