xref: /openbmc/qemu/hw/cpu/a9mpcore.c (revision 5126fec7)
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"
120434e30aSPaolo Bonzini 
13*5126fec7SAndreas Färber #define TYPE_A9MPCORE_PRIV "a9mpcore_priv"
14*5126fec7SAndreas Färber #define A9MPCORE_PRIV(obj) \
15*5126fec7SAndreas Färber     OBJECT_CHECK(A9MPPrivState, (obj), TYPE_A9MPCORE_PRIV)
16*5126fec7SAndreas Färber 
170434e30aSPaolo Bonzini typedef struct A9MPPrivState {
18*5126fec7SAndreas Färber     /*< private >*/
19*5126fec7SAndreas Färber     SysBusDevice parent_obj;
20*5126fec7SAndreas Färber     /*< public >*/
21*5126fec7SAndreas Färber 
220434e30aSPaolo Bonzini     uint32_t num_cpu;
230434e30aSPaolo Bonzini     MemoryRegion container;
240434e30aSPaolo Bonzini     DeviceState *mptimer;
250434e30aSPaolo Bonzini     DeviceState *wdt;
260434e30aSPaolo Bonzini     DeviceState *gic;
270434e30aSPaolo Bonzini     DeviceState *scu;
280434e30aSPaolo Bonzini     uint32_t num_irq;
290434e30aSPaolo Bonzini } A9MPPrivState;
300434e30aSPaolo Bonzini 
310434e30aSPaolo Bonzini static void a9mp_priv_set_irq(void *opaque, int irq, int level)
320434e30aSPaolo Bonzini {
330434e30aSPaolo Bonzini     A9MPPrivState *s = (A9MPPrivState *)opaque;
340434e30aSPaolo Bonzini     qemu_set_irq(qdev_get_gpio_in(s->gic, irq), level);
350434e30aSPaolo Bonzini }
360434e30aSPaolo Bonzini 
370434e30aSPaolo Bonzini static int a9mp_priv_init(SysBusDevice *dev)
380434e30aSPaolo Bonzini {
39*5126fec7SAndreas Färber     A9MPPrivState *s = A9MPCORE_PRIV(dev);
400434e30aSPaolo Bonzini     SysBusDevice *timerbusdev, *wdtbusdev, *gicbusdev, *scubusdev;
410434e30aSPaolo Bonzini     int i;
420434e30aSPaolo Bonzini 
430434e30aSPaolo Bonzini     s->gic = qdev_create(NULL, "arm_gic");
440434e30aSPaolo Bonzini     qdev_prop_set_uint32(s->gic, "num-cpu", s->num_cpu);
450434e30aSPaolo Bonzini     qdev_prop_set_uint32(s->gic, "num-irq", s->num_irq);
460434e30aSPaolo Bonzini     qdev_init_nofail(s->gic);
470434e30aSPaolo Bonzini     gicbusdev = SYS_BUS_DEVICE(s->gic);
480434e30aSPaolo Bonzini 
490434e30aSPaolo Bonzini     /* Pass through outbound IRQ lines from the GIC */
500434e30aSPaolo Bonzini     sysbus_pass_irq(dev, gicbusdev);
510434e30aSPaolo Bonzini 
520434e30aSPaolo Bonzini     /* Pass through inbound GPIO lines to the GIC */
53*5126fec7SAndreas Färber     qdev_init_gpio_in(DEVICE(dev), a9mp_priv_set_irq, s->num_irq - 32);
540434e30aSPaolo Bonzini 
550434e30aSPaolo Bonzini     s->scu = qdev_create(NULL, "a9-scu");
560434e30aSPaolo Bonzini     qdev_prop_set_uint32(s->scu, "num-cpu", s->num_cpu);
570434e30aSPaolo Bonzini     qdev_init_nofail(s->scu);
580434e30aSPaolo Bonzini     scubusdev = SYS_BUS_DEVICE(s->scu);
590434e30aSPaolo Bonzini 
600434e30aSPaolo Bonzini     s->mptimer = qdev_create(NULL, "arm_mptimer");
610434e30aSPaolo Bonzini     qdev_prop_set_uint32(s->mptimer, "num-cpu", s->num_cpu);
620434e30aSPaolo Bonzini     qdev_init_nofail(s->mptimer);
630434e30aSPaolo Bonzini     timerbusdev = SYS_BUS_DEVICE(s->mptimer);
640434e30aSPaolo Bonzini 
650434e30aSPaolo Bonzini     s->wdt = qdev_create(NULL, "arm_mptimer");
660434e30aSPaolo Bonzini     qdev_prop_set_uint32(s->wdt, "num-cpu", s->num_cpu);
670434e30aSPaolo Bonzini     qdev_init_nofail(s->wdt);
680434e30aSPaolo Bonzini     wdtbusdev = SYS_BUS_DEVICE(s->wdt);
690434e30aSPaolo Bonzini 
700434e30aSPaolo Bonzini     /* Memory map (addresses are offsets from PERIPHBASE):
710434e30aSPaolo Bonzini      *  0x0000-0x00ff -- Snoop Control Unit
720434e30aSPaolo Bonzini      *  0x0100-0x01ff -- GIC CPU interface
730434e30aSPaolo Bonzini      *  0x0200-0x02ff -- Global Timer
740434e30aSPaolo Bonzini      *  0x0300-0x05ff -- nothing
750434e30aSPaolo Bonzini      *  0x0600-0x06ff -- private timers and watchdogs
760434e30aSPaolo Bonzini      *  0x0700-0x0fff -- nothing
770434e30aSPaolo Bonzini      *  0x1000-0x1fff -- GIC Distributor
780434e30aSPaolo Bonzini      *
790434e30aSPaolo Bonzini      * We should implement the global timer but don't currently do so.
800434e30aSPaolo Bonzini      */
81300b1fc6SPaolo Bonzini     memory_region_init(&s->container, OBJECT(s), "a9mp-priv-container", 0x2000);
820434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0,
830434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(scubusdev, 0));
840434e30aSPaolo Bonzini     /* GIC CPU interface */
850434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0x100,
860434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(gicbusdev, 1));
870434e30aSPaolo Bonzini     /* Note that the A9 exposes only the "timer/watchdog for this core"
880434e30aSPaolo Bonzini      * memory region, not the "timer/watchdog for core X" ones 11MPcore has.
890434e30aSPaolo Bonzini      */
900434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0x600,
910434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(timerbusdev, 0));
920434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0x620,
930434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(wdtbusdev, 0));
940434e30aSPaolo Bonzini     memory_region_add_subregion(&s->container, 0x1000,
950434e30aSPaolo Bonzini                                 sysbus_mmio_get_region(gicbusdev, 0));
960434e30aSPaolo Bonzini 
970434e30aSPaolo Bonzini     sysbus_init_mmio(dev, &s->container);
980434e30aSPaolo Bonzini 
990434e30aSPaolo Bonzini     /* Wire up the interrupt from each watchdog and timer.
1000434e30aSPaolo Bonzini      * For each core the timer is PPI 29 and the watchdog PPI 30.
1010434e30aSPaolo Bonzini      */
1020434e30aSPaolo Bonzini     for (i = 0; i < s->num_cpu; i++) {
1030434e30aSPaolo Bonzini         int ppibase = (s->num_irq - 32) + i * 32;
1040434e30aSPaolo Bonzini         sysbus_connect_irq(timerbusdev, i,
1050434e30aSPaolo Bonzini                            qdev_get_gpio_in(s->gic, ppibase + 29));
1060434e30aSPaolo Bonzini         sysbus_connect_irq(wdtbusdev, i,
1070434e30aSPaolo Bonzini                            qdev_get_gpio_in(s->gic, ppibase + 30));
1080434e30aSPaolo Bonzini     }
1090434e30aSPaolo Bonzini     return 0;
1100434e30aSPaolo Bonzini }
1110434e30aSPaolo Bonzini 
1120434e30aSPaolo Bonzini static Property a9mp_priv_properties[] = {
1130434e30aSPaolo Bonzini     DEFINE_PROP_UINT32("num-cpu", A9MPPrivState, num_cpu, 1),
1140434e30aSPaolo Bonzini     /* The Cortex-A9MP may have anything from 0 to 224 external interrupt
1150434e30aSPaolo Bonzini      * IRQ lines (with another 32 internal). We default to 64+32, which
1160434e30aSPaolo Bonzini      * is the number provided by the Cortex-A9MP test chip in the
1170434e30aSPaolo Bonzini      * Realview PBX-A9 and Versatile Express A9 development boards.
1180434e30aSPaolo Bonzini      * Other boards may differ and should set this property appropriately.
1190434e30aSPaolo Bonzini      */
1200434e30aSPaolo Bonzini     DEFINE_PROP_UINT32("num-irq", A9MPPrivState, num_irq, 96),
1210434e30aSPaolo Bonzini     DEFINE_PROP_END_OF_LIST(),
1220434e30aSPaolo Bonzini };
1230434e30aSPaolo Bonzini 
1240434e30aSPaolo Bonzini static void a9mp_priv_class_init(ObjectClass *klass, void *data)
1250434e30aSPaolo Bonzini {
1260434e30aSPaolo Bonzini     DeviceClass *dc = DEVICE_CLASS(klass);
1270434e30aSPaolo Bonzini     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
1280434e30aSPaolo Bonzini 
1290434e30aSPaolo Bonzini     k->init = a9mp_priv_init;
1300434e30aSPaolo Bonzini     dc->props = a9mp_priv_properties;
1310434e30aSPaolo Bonzini }
1320434e30aSPaolo Bonzini 
1330434e30aSPaolo Bonzini static const TypeInfo a9mp_priv_info = {
134*5126fec7SAndreas Färber     .name          = TYPE_A9MPCORE_PRIV,
1350434e30aSPaolo Bonzini     .parent        = TYPE_SYS_BUS_DEVICE,
1360434e30aSPaolo Bonzini     .instance_size = sizeof(A9MPPrivState),
1370434e30aSPaolo Bonzini     .class_init    = a9mp_priv_class_init,
1380434e30aSPaolo Bonzini };
1390434e30aSPaolo Bonzini 
1400434e30aSPaolo Bonzini static void a9mp_register_types(void)
1410434e30aSPaolo Bonzini {
1420434e30aSPaolo Bonzini     type_register_static(&a9mp_priv_info);
1430434e30aSPaolo Bonzini }
1440434e30aSPaolo Bonzini 
1450434e30aSPaolo Bonzini type_init(a9mp_register_types)
146