xref: /openbmc/qemu/hw/cpu/a9mpcore.c (revision 9b5f952b)
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 
110434e30aSPaolo Bonzini #include "hw/sysbus.h"
12*9b5f952bSAndreas Färber #include "hw/intc/arm_gic.h"
130434e30aSPaolo Bonzini 
145126fec7SAndreas Färber #define TYPE_A9MPCORE_PRIV "a9mpcore_priv"
155126fec7SAndreas Färber #define A9MPCORE_PRIV(obj) \
165126fec7SAndreas Färber     OBJECT_CHECK(A9MPPrivState, (obj), TYPE_A9MPCORE_PRIV)
175126fec7SAndreas Färber 
180434e30aSPaolo Bonzini typedef struct A9MPPrivState {
195126fec7SAndreas Färber     /*< private >*/
205126fec7SAndreas Färber     SysBusDevice parent_obj;
215126fec7SAndreas Färber     /*< public >*/
225126fec7SAndreas Färber 
230434e30aSPaolo Bonzini     uint32_t num_cpu;
240434e30aSPaolo Bonzini     MemoryRegion container;
250434e30aSPaolo Bonzini     DeviceState *mptimer;
260434e30aSPaolo Bonzini     DeviceState *wdt;
270434e30aSPaolo Bonzini     DeviceState *scu;
280434e30aSPaolo Bonzini     uint32_t num_irq;
29*9b5f952bSAndreas Färber 
30*9b5f952bSAndreas Färber     GICState gic;
310434e30aSPaolo Bonzini } A9MPPrivState;
320434e30aSPaolo Bonzini 
330434e30aSPaolo Bonzini static void a9mp_priv_set_irq(void *opaque, int irq, int level)
340434e30aSPaolo Bonzini {
350434e30aSPaolo Bonzini     A9MPPrivState *s = (A9MPPrivState *)opaque;
36*9b5f952bSAndreas Färber 
37*9b5f952bSAndreas Färber     qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level);
380434e30aSPaolo Bonzini }
390434e30aSPaolo Bonzini 
40753bc6e9SAndreas Färber static void a9mp_priv_initfn(Object *obj)
41753bc6e9SAndreas Färber {
42753bc6e9SAndreas Färber     A9MPPrivState *s = A9MPCORE_PRIV(obj);
43753bc6e9SAndreas Färber 
44753bc6e9SAndreas Färber     memory_region_init(&s->container, obj, "a9mp-priv-container", 0x2000);
45753bc6e9SAndreas Färber     sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->container);
46*9b5f952bSAndreas Färber 
47*9b5f952bSAndreas Färber     object_initialize(&s->gic, sizeof(s->gic), TYPE_ARM_GIC);
48*9b5f952bSAndreas Färber     qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default());
49753bc6e9SAndreas Färber }
50753bc6e9SAndreas Färber 
510434e30aSPaolo Bonzini static int a9mp_priv_init(SysBusDevice *dev)
520434e30aSPaolo Bonzini {
535126fec7SAndreas Färber     A9MPPrivState *s = A9MPCORE_PRIV(dev);
54*9b5f952bSAndreas Färber     DeviceState *gicdev;
550434e30aSPaolo Bonzini     SysBusDevice *timerbusdev, *wdtbusdev, *gicbusdev, *scubusdev;
560434e30aSPaolo Bonzini     int i;
570434e30aSPaolo Bonzini 
58*9b5f952bSAndreas Färber     gicdev = DEVICE(&s->gic);
59*9b5f952bSAndreas Färber     qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu);
60*9b5f952bSAndreas Färber     qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq);
61*9b5f952bSAndreas Färber     qdev_init_nofail(gicdev);
62*9b5f952bSAndreas Färber     gicbusdev = SYS_BUS_DEVICE(&s->gic);
630434e30aSPaolo Bonzini 
640434e30aSPaolo Bonzini     /* Pass through outbound IRQ lines from the GIC */
650434e30aSPaolo Bonzini     sysbus_pass_irq(dev, gicbusdev);
660434e30aSPaolo Bonzini 
670434e30aSPaolo Bonzini     /* Pass through inbound GPIO lines to the GIC */
685126fec7SAndreas Färber     qdev_init_gpio_in(DEVICE(dev), a9mp_priv_set_irq, s->num_irq - 32);
690434e30aSPaolo Bonzini 
700434e30aSPaolo Bonzini     s->scu = qdev_create(NULL, "a9-scu");
710434e30aSPaolo Bonzini     qdev_prop_set_uint32(s->scu, "num-cpu", s->num_cpu);
720434e30aSPaolo Bonzini     qdev_init_nofail(s->scu);
730434e30aSPaolo Bonzini     scubusdev = SYS_BUS_DEVICE(s->scu);
740434e30aSPaolo Bonzini 
750434e30aSPaolo Bonzini     s->mptimer = qdev_create(NULL, "arm_mptimer");
760434e30aSPaolo Bonzini     qdev_prop_set_uint32(s->mptimer, "num-cpu", s->num_cpu);
770434e30aSPaolo Bonzini     qdev_init_nofail(s->mptimer);
780434e30aSPaolo Bonzini     timerbusdev = SYS_BUS_DEVICE(s->mptimer);
790434e30aSPaolo Bonzini 
800434e30aSPaolo Bonzini     s->wdt = qdev_create(NULL, "arm_mptimer");
810434e30aSPaolo Bonzini     qdev_prop_set_uint32(s->wdt, "num-cpu", s->num_cpu);
820434e30aSPaolo Bonzini     qdev_init_nofail(s->wdt);
830434e30aSPaolo Bonzini     wdtbusdev = SYS_BUS_DEVICE(s->wdt);
840434e30aSPaolo Bonzini 
850434e30aSPaolo Bonzini     /* Memory map (addresses are offsets from PERIPHBASE):
860434e30aSPaolo Bonzini      *  0x0000-0x00ff -- Snoop Control Unit
870434e30aSPaolo Bonzini      *  0x0100-0x01ff -- GIC CPU interface
880434e30aSPaolo Bonzini      *  0x0200-0x02ff -- Global Timer
890434e30aSPaolo Bonzini      *  0x0300-0x05ff -- nothing
900434e30aSPaolo Bonzini      *  0x0600-0x06ff -- private timers and watchdogs
910434e30aSPaolo Bonzini      *  0x0700-0x0fff -- nothing
920434e30aSPaolo Bonzini      *  0x1000-0x1fff -- GIC Distributor
930434e30aSPaolo Bonzini      *
940434e30aSPaolo Bonzini      * We should implement the global timer but don't currently do so.
950434e30aSPaolo Bonzini      */
960434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0,
970434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(scubusdev, 0));
980434e30aSPaolo Bonzini     /* GIC CPU interface */
990434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0x100,
1000434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(gicbusdev, 1));
1010434e30aSPaolo Bonzini     /* Note that the A9 exposes only the "timer/watchdog for this core"
1020434e30aSPaolo Bonzini      * memory region, not the "timer/watchdog for core X" ones 11MPcore has.
1030434e30aSPaolo Bonzini      */
1040434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0x600,
1050434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(timerbusdev, 0));
1060434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0x620,
1070434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(wdtbusdev, 0));
1080434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0x1000,
1090434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(gicbusdev, 0));
1100434e30aSPaolo Bonzini 
1110434e30aSPaolo Bonzini     /* Wire up the interrupt from each watchdog and timer.
1120434e30aSPaolo Bonzini      * For each core the timer is PPI 29 and the watchdog PPI 30.
1130434e30aSPaolo Bonzini      */
1140434e30aSPaolo Bonzini     for (i = 0; i < s->num_cpu; i++) {
1150434e30aSPaolo Bonzini         int ppibase = (s->num_irq - 32) + i * 32;
1160434e30aSPaolo Bonzini         sysbus_connect_irq(timerbusdev, i,
117*9b5f952bSAndreas Färber                            qdev_get_gpio_in(gicdev, ppibase + 29));
1180434e30aSPaolo Bonzini         sysbus_connect_irq(wdtbusdev, i,
119*9b5f952bSAndreas Färber                            qdev_get_gpio_in(gicdev, ppibase + 30));
1200434e30aSPaolo Bonzini     }
1210434e30aSPaolo Bonzini     return 0;
1220434e30aSPaolo Bonzini }
1230434e30aSPaolo Bonzini 
1240434e30aSPaolo Bonzini static Property a9mp_priv_properties[] = {
1250434e30aSPaolo Bonzini     DEFINE_PROP_UINT32("num-cpu", A9MPPrivState, num_cpu, 1),
1260434e30aSPaolo Bonzini     /* The Cortex-A9MP may have anything from 0 to 224 external interrupt
1270434e30aSPaolo Bonzini      * IRQ lines (with another 32 internal). We default to 64+32, which
1280434e30aSPaolo Bonzini      * is the number provided by the Cortex-A9MP test chip in the
1290434e30aSPaolo Bonzini      * Realview PBX-A9 and Versatile Express A9 development boards.
1300434e30aSPaolo Bonzini      * Other boards may differ and should set this property appropriately.
1310434e30aSPaolo Bonzini      */
1320434e30aSPaolo Bonzini     DEFINE_PROP_UINT32("num-irq", A9MPPrivState, num_irq, 96),
1330434e30aSPaolo Bonzini     DEFINE_PROP_END_OF_LIST(),
1340434e30aSPaolo Bonzini };
1350434e30aSPaolo Bonzini 
1360434e30aSPaolo Bonzini static void a9mp_priv_class_init(ObjectClass *klass, void *data)
1370434e30aSPaolo Bonzini {
1380434e30aSPaolo Bonzini     DeviceClass *dc = DEVICE_CLASS(klass);
1390434e30aSPaolo Bonzini     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
1400434e30aSPaolo Bonzini 
1410434e30aSPaolo Bonzini     k->init = a9mp_priv_init;
1420434e30aSPaolo Bonzini     dc->props = a9mp_priv_properties;
1430434e30aSPaolo Bonzini }
1440434e30aSPaolo Bonzini 
1450434e30aSPaolo Bonzini static const TypeInfo a9mp_priv_info = {
1465126fec7SAndreas Färber     .name          = TYPE_A9MPCORE_PRIV,
1470434e30aSPaolo Bonzini     .parent        = TYPE_SYS_BUS_DEVICE,
1480434e30aSPaolo Bonzini     .instance_size = sizeof(A9MPPrivState),
149753bc6e9SAndreas Färber     .instance_init = a9mp_priv_initfn,
1500434e30aSPaolo Bonzini     .class_init    = a9mp_priv_class_init,
1510434e30aSPaolo Bonzini };
1520434e30aSPaolo Bonzini 
1530434e30aSPaolo Bonzini static void a9mp_register_types(void)
1540434e30aSPaolo Bonzini {
1550434e30aSPaolo Bonzini     type_register_static(&a9mp_priv_info);
1560434e30aSPaolo Bonzini }
1570434e30aSPaolo Bonzini 
1580434e30aSPaolo Bonzini type_init(a9mp_register_types)
159