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