pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * ARM RealView Emulation Baseboard Interrupt Controller |
| 3 | * |
| 4 | * Copyright (c) 2006-2007 CodeSourcery. |
| 5 | * Written by Paul Brook |
| 6 | * |
Matthew Fernandez | 8e31bf3 | 2011-06-26 12:21:35 +1000 | [diff] [blame] | 7 | * This code is licensed under the GPL. |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Peter Maydell | 8ef94f0 | 2016-01-26 18:17:05 +0000 | [diff] [blame] | 10 | #include "qemu/osdep.h" |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 11 | #include "qapi/error.h" |
Andreas Färber | ce31825 | 2013-08-19 00:48:55 +0200 | [diff] [blame] | 12 | #include "hw/intc/realview_gic.h" |
Paul Brook | fe7e875 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 13 | |
Peter Maydell | fbbd05d | 2012-04-13 11:39:08 +0000 | [diff] [blame] | 14 | static void realview_gic_set_irq(void *opaque, int irq, int level) |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 15 | { |
Peter Maydell | fbbd05d | 2012-04-13 11:39:08 +0000 | [diff] [blame] | 16 | RealViewGICState *s = (RealViewGICState *)opaque; |
Andreas Färber | 612daf0 | 2013-08-19 00:37:07 +0200 | [diff] [blame] | 17 | |
| 18 | qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level); |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 19 | } |
Paul Brook | fe7e875 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 20 | |
Andreas Färber | 612daf0 | 2013-08-19 00:37:07 +0200 | [diff] [blame] | 21 | static void realview_gic_realize(DeviceState *dev, Error **errp) |
Paul Brook | fe7e875 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 22 | { |
Andreas Färber | 612daf0 | 2013-08-19 00:37:07 +0200 | [diff] [blame] | 23 | SysBusDevice *sbd = SYS_BUS_DEVICE(dev); |
Andreas Färber | b09a6f7 | 2013-07-26 20:34:29 +0200 | [diff] [blame] | 24 | RealViewGICState *s = REALVIEW_GIC(dev); |
Peter Maydell | fbbd05d | 2012-04-13 11:39:08 +0000 | [diff] [blame] | 25 | SysBusDevice *busdev; |
Andreas Färber | 612daf0 | 2013-08-19 00:37:07 +0200 | [diff] [blame] | 26 | Error *err = NULL; |
Mark Langsdorf | a32134a | 2012-01-17 10:54:07 +0000 | [diff] [blame] | 27 | /* The GICs on the RealView boards have a fixed nonconfigurable |
| 28 | * number of interrupt lines, so we don't need to expose this as |
| 29 | * a qdev property. |
| 30 | */ |
Peter Maydell | fbbd05d | 2012-04-13 11:39:08 +0000 | [diff] [blame] | 31 | int numirq = 96; |
| 32 | |
Andreas Färber | 612daf0 | 2013-08-19 00:37:07 +0200 | [diff] [blame] | 33 | qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", numirq); |
| 34 | object_property_set_bool(OBJECT(&s->gic), true, "realized", &err); |
| 35 | if (err != NULL) { |
| 36 | error_propagate(errp, err); |
| 37 | return; |
| 38 | } |
| 39 | busdev = SYS_BUS_DEVICE(&s->gic); |
Peter Maydell | fbbd05d | 2012-04-13 11:39:08 +0000 | [diff] [blame] | 40 | |
| 41 | /* Pass through outbound IRQ lines from the GIC */ |
Andreas Färber | b09a6f7 | 2013-07-26 20:34:29 +0200 | [diff] [blame] | 42 | sysbus_pass_irq(sbd, busdev); |
Peter Maydell | fbbd05d | 2012-04-13 11:39:08 +0000 | [diff] [blame] | 43 | |
| 44 | /* Pass through inbound GPIO lines to the GIC */ |
Andreas Färber | b09a6f7 | 2013-07-26 20:34:29 +0200 | [diff] [blame] | 45 | qdev_init_gpio_in(dev, realview_gic_set_irq, numirq - 32); |
Peter Maydell | fbbd05d | 2012-04-13 11:39:08 +0000 | [diff] [blame] | 46 | |
Peter Maydell | fbbd05d | 2012-04-13 11:39:08 +0000 | [diff] [blame] | 47 | memory_region_add_subregion(&s->container, 0, |
| 48 | sysbus_mmio_get_region(busdev, 1)); |
| 49 | memory_region_add_subregion(&s->container, 0x1000, |
| 50 | sysbus_mmio_get_region(busdev, 0)); |
Paul Brook | fe7e875 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Andreas Färber | 612daf0 | 2013-08-19 00:37:07 +0200 | [diff] [blame] | 53 | static void realview_gic_init(Object *obj) |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 54 | { |
Andreas Färber | 612daf0 | 2013-08-19 00:37:07 +0200 | [diff] [blame] | 55 | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); |
| 56 | RealViewGICState *s = REALVIEW_GIC(obj); |
| 57 | DeviceState *gicdev; |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 58 | |
Andreas Färber | 612daf0 | 2013-08-19 00:37:07 +0200 | [diff] [blame] | 59 | memory_region_init(&s->container, OBJECT(s), |
| 60 | "realview-gic-container", 0x2000); |
| 61 | sysbus_init_mmio(sbd, &s->container); |
| 62 | |
| 63 | object_initialize(&s->gic, sizeof(s->gic), TYPE_ARM_GIC); |
| 64 | gicdev = DEVICE(&s->gic); |
| 65 | qdev_set_parent_bus(gicdev, sysbus_get_default()); |
| 66 | qdev_prop_set_uint32(gicdev, "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; |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 74 | } |
| 75 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 76 | static const TypeInfo realview_gic_info = { |
Andreas Färber | b09a6f7 | 2013-07-26 20:34:29 +0200 | [diff] [blame] | 77 | .name = TYPE_REALVIEW_GIC, |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 78 | .parent = TYPE_SYS_BUS_DEVICE, |
| 79 | .instance_size = sizeof(RealViewGICState), |
Andreas Färber | 612daf0 | 2013-08-19 00:37:07 +0200 | [diff] [blame] | 80 | .instance_init = realview_gic_init, |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 81 | .class_init = realview_gic_class_init, |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 82 | }; |
| 83 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 84 | static void realview_gic_register_types(void) |
Paul Brook | fe7e875 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 85 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 86 | type_register_static(&realview_gic_info); |
Paul Brook | fe7e875 | 2009-05-14 22:35:08 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 89 | type_init(realview_gic_register_types) |