xref: /openbmc/qemu/hw/cpu/a9mpcore.c (revision d3053e6b)
10434e30aSPaolo Bonzini /*
20434e30aSPaolo Bonzini  * Cortex-A9MPCore internal peripheral emulation.
30434e30aSPaolo Bonzini  *
40434e30aSPaolo Bonzini  * Copyright (c) 2009 CodeSourcery.
50434e30aSPaolo Bonzini  * Copyright (c) 2011 Linaro Limited.
60434e30aSPaolo Bonzini  * Written by Paul Brook, Peter Maydell.
70434e30aSPaolo Bonzini  *
80434e30aSPaolo Bonzini  * This code is licensed under the GPL.
90434e30aSPaolo Bonzini  */
100434e30aSPaolo Bonzini 
11de4c2dcfSAndreas Färber #include "hw/cpu/a9mpcore.h"
120434e30aSPaolo Bonzini 
130434e30aSPaolo Bonzini static void a9mp_priv_set_irq(void *opaque, int irq, int level)
140434e30aSPaolo Bonzini {
150434e30aSPaolo Bonzini     A9MPPrivState *s = (A9MPPrivState *)opaque;
169b5f952bSAndreas Färber 
179b5f952bSAndreas Färber     qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level);
180434e30aSPaolo Bonzini }
190434e30aSPaolo Bonzini 
20753bc6e9SAndreas Färber static void a9mp_priv_initfn(Object *obj)
21753bc6e9SAndreas Färber {
22753bc6e9SAndreas Färber     A9MPPrivState *s = A9MPCORE_PRIV(obj);
23753bc6e9SAndreas Färber 
24753bc6e9SAndreas Färber     memory_region_init(&s->container, obj, "a9mp-priv-container", 0x2000);
25753bc6e9SAndreas Färber     sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->container);
269b5f952bSAndreas Färber 
279b5f952bSAndreas Färber     object_initialize(&s->gic, sizeof(s->gic), TYPE_ARM_GIC);
289b5f952bSAndreas Färber     qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default());
29fc719d77SAndreas Färber 
30fc719d77SAndreas Färber     object_initialize(&s->scu, sizeof(s->scu), TYPE_A9_SCU);
31fc719d77SAndreas Färber     qdev_set_parent_bus(DEVICE(&s->scu), sysbus_get_default());
32eb110bd8SAndreas Färber 
33eb110bd8SAndreas Färber     object_initialize(&s->mptimer, sizeof(s->mptimer), TYPE_ARM_MPTIMER);
34eb110bd8SAndreas Färber     qdev_set_parent_bus(DEVICE(&s->mptimer), sysbus_get_default());
35eb110bd8SAndreas Färber 
36eb110bd8SAndreas Färber     object_initialize(&s->wdt, sizeof(s->wdt), TYPE_ARM_MPTIMER);
37eb110bd8SAndreas Färber     qdev_set_parent_bus(DEVICE(&s->wdt), sysbus_get_default());
38753bc6e9SAndreas Färber }
39753bc6e9SAndreas Färber 
40837cf101SAndreas Färber static void a9mp_priv_realize(DeviceState *dev, Error **errp)
410434e30aSPaolo Bonzini {
42837cf101SAndreas Färber     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
435126fec7SAndreas Färber     A9MPPrivState *s = A9MPCORE_PRIV(dev);
44eb110bd8SAndreas Färber     DeviceState *gicdev, *scudev, *mptimerdev, *wdtdev;
45*d3053e6bSPeter Crosthwaite     SysBusDevice *mptimerbusdev, *wdtbusdev, *gicbusdev, *scubusdev;
46837cf101SAndreas Färber     Error *err = NULL;
470434e30aSPaolo Bonzini     int i;
480434e30aSPaolo Bonzini 
499b5f952bSAndreas Färber     gicdev = DEVICE(&s->gic);
509b5f952bSAndreas Färber     qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu);
519b5f952bSAndreas Färber     qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq);
52837cf101SAndreas Färber     object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
53837cf101SAndreas Färber     if (err != NULL) {
54837cf101SAndreas Färber         error_propagate(errp, err);
55837cf101SAndreas Färber         return;
56837cf101SAndreas Färber     }
579b5f952bSAndreas Färber     gicbusdev = SYS_BUS_DEVICE(&s->gic);
580434e30aSPaolo Bonzini 
590434e30aSPaolo Bonzini     /* Pass through outbound IRQ lines from the GIC */
60837cf101SAndreas Färber     sysbus_pass_irq(sbd, gicbusdev);
610434e30aSPaolo Bonzini 
620434e30aSPaolo Bonzini     /* Pass through inbound GPIO lines to the GIC */
63837cf101SAndreas Färber     qdev_init_gpio_in(dev, a9mp_priv_set_irq, s->num_irq - 32);
640434e30aSPaolo Bonzini 
65fc719d77SAndreas Färber     scudev = DEVICE(&s->scu);
66fc719d77SAndreas Färber     qdev_prop_set_uint32(scudev, "num-cpu", s->num_cpu);
67837cf101SAndreas Färber     object_property_set_bool(OBJECT(&s->scu), true, "realized", &err);
68837cf101SAndreas Färber     if (err != NULL) {
69837cf101SAndreas Färber         error_propagate(errp, err);
70837cf101SAndreas Färber         return;
71837cf101SAndreas Färber     }
72fc719d77SAndreas Färber     scubusdev = SYS_BUS_DEVICE(&s->scu);
730434e30aSPaolo Bonzini 
74eb110bd8SAndreas Färber     mptimerdev = DEVICE(&s->mptimer);
75eb110bd8SAndreas Färber     qdev_prop_set_uint32(mptimerdev, "num-cpu", s->num_cpu);
76837cf101SAndreas Färber     object_property_set_bool(OBJECT(&s->mptimer), true, "realized", &err);
77837cf101SAndreas Färber     if (err != NULL) {
78837cf101SAndreas Färber         error_propagate(errp, err);
79837cf101SAndreas Färber         return;
80837cf101SAndreas Färber     }
81*d3053e6bSPeter Crosthwaite     mptimerbusdev = SYS_BUS_DEVICE(&s->mptimer);
820434e30aSPaolo Bonzini 
83eb110bd8SAndreas Färber     wdtdev = DEVICE(&s->wdt);
84eb110bd8SAndreas Färber     qdev_prop_set_uint32(wdtdev, "num-cpu", s->num_cpu);
85837cf101SAndreas Färber     object_property_set_bool(OBJECT(&s->wdt), true, "realized", &err);
86837cf101SAndreas Färber     if (err != NULL) {
87837cf101SAndreas Färber         error_propagate(errp, err);
88837cf101SAndreas Färber         return;
89837cf101SAndreas Färber     }
90eb110bd8SAndreas Färber     wdtbusdev = SYS_BUS_DEVICE(&s->wdt);
910434e30aSPaolo Bonzini 
920434e30aSPaolo Bonzini     /* Memory map (addresses are offsets from PERIPHBASE):
930434e30aSPaolo Bonzini      *  0x0000-0x00ff -- Snoop Control Unit
940434e30aSPaolo Bonzini      *  0x0100-0x01ff -- GIC CPU interface
950434e30aSPaolo Bonzini      *  0x0200-0x02ff -- Global Timer
960434e30aSPaolo Bonzini      *  0x0300-0x05ff -- nothing
970434e30aSPaolo Bonzini      *  0x0600-0x06ff -- private timers and watchdogs
980434e30aSPaolo Bonzini      *  0x0700-0x0fff -- nothing
990434e30aSPaolo Bonzini      *  0x1000-0x1fff -- GIC Distributor
1000434e30aSPaolo Bonzini      *
1010434e30aSPaolo Bonzini      * We should implement the global timer but don't currently do so.
1020434e30aSPaolo Bonzini      */
1030434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0,
1040434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(scubusdev, 0));
1050434e30aSPaolo Bonzini     /* GIC CPU interface */
1060434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0x100,
1070434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(gicbusdev, 1));
1080434e30aSPaolo Bonzini     /* Note that the A9 exposes only the "timer/watchdog for this core"
1090434e30aSPaolo Bonzini      * memory region, not the "timer/watchdog for core X" ones 11MPcore has.
1100434e30aSPaolo Bonzini      */
1110434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0x600,
112*d3053e6bSPeter Crosthwaite                                 sysbus_mmio_get_region(mptimerbusdev, 0));
1130434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0x620,
1140434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(wdtbusdev, 0));
1150434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0x1000,
1160434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(gicbusdev, 0));
1170434e30aSPaolo Bonzini 
1180434e30aSPaolo Bonzini     /* Wire up the interrupt from each watchdog and timer.
1190434e30aSPaolo Bonzini      * For each core the timer is PPI 29 and the watchdog PPI 30.
1200434e30aSPaolo Bonzini      */
1210434e30aSPaolo Bonzini     for (i = 0; i < s->num_cpu; i++) {
1220434e30aSPaolo Bonzini         int ppibase = (s->num_irq - 32) + i * 32;
123*d3053e6bSPeter Crosthwaite         sysbus_connect_irq(mptimerbusdev, i,
1249b5f952bSAndreas Färber                            qdev_get_gpio_in(gicdev, ppibase + 29));
1250434e30aSPaolo Bonzini         sysbus_connect_irq(wdtbusdev, i,
1269b5f952bSAndreas Färber                            qdev_get_gpio_in(gicdev, ppibase + 30));
1270434e30aSPaolo Bonzini     }
1280434e30aSPaolo Bonzini }
1290434e30aSPaolo Bonzini 
1300434e30aSPaolo Bonzini static Property a9mp_priv_properties[] = {
1310434e30aSPaolo Bonzini     DEFINE_PROP_UINT32("num-cpu", A9MPPrivState, num_cpu, 1),
1320434e30aSPaolo Bonzini     /* The Cortex-A9MP may have anything from 0 to 224 external interrupt
1330434e30aSPaolo Bonzini      * IRQ lines (with another 32 internal). We default to 64+32, which
1340434e30aSPaolo Bonzini      * is the number provided by the Cortex-A9MP test chip in the
1350434e30aSPaolo Bonzini      * Realview PBX-A9 and Versatile Express A9 development boards.
1360434e30aSPaolo Bonzini      * Other boards may differ and should set this property appropriately.
1370434e30aSPaolo Bonzini      */
1380434e30aSPaolo Bonzini     DEFINE_PROP_UINT32("num-irq", A9MPPrivState, num_irq, 96),
1390434e30aSPaolo Bonzini     DEFINE_PROP_END_OF_LIST(),
1400434e30aSPaolo Bonzini };
1410434e30aSPaolo Bonzini 
1420434e30aSPaolo Bonzini static void a9mp_priv_class_init(ObjectClass *klass, void *data)
1430434e30aSPaolo Bonzini {
1440434e30aSPaolo Bonzini     DeviceClass *dc = DEVICE_CLASS(klass);
1450434e30aSPaolo Bonzini 
146837cf101SAndreas Färber     dc->realize = a9mp_priv_realize;
1470434e30aSPaolo Bonzini     dc->props = a9mp_priv_properties;
1480434e30aSPaolo Bonzini }
1490434e30aSPaolo Bonzini 
1500434e30aSPaolo Bonzini static const TypeInfo a9mp_priv_info = {
1515126fec7SAndreas Färber     .name          = TYPE_A9MPCORE_PRIV,
1520434e30aSPaolo Bonzini     .parent        = TYPE_SYS_BUS_DEVICE,
1530434e30aSPaolo Bonzini     .instance_size = sizeof(A9MPPrivState),
154753bc6e9SAndreas Färber     .instance_init = a9mp_priv_initfn,
1550434e30aSPaolo Bonzini     .class_init    = a9mp_priv_class_init,
1560434e30aSPaolo Bonzini };
1570434e30aSPaolo Bonzini 
1580434e30aSPaolo Bonzini static void a9mp_register_types(void)
1590434e30aSPaolo Bonzini {
1600434e30aSPaolo Bonzini     type_register_static(&a9mp_priv_info);
1610434e30aSPaolo Bonzini }
1620434e30aSPaolo Bonzini 
1630434e30aSPaolo Bonzini type_init(a9mp_register_types)
164