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" 129b5f952bSAndreas Färber #include "hw/intc/arm_gic.h" 13fc719d77SAndreas Färber #include "hw/misc/a9scu.h" 14*eb110bd8SAndreas Färber #include "hw/timer/arm_mptimer.h" 150434e30aSPaolo Bonzini 165126fec7SAndreas Färber #define TYPE_A9MPCORE_PRIV "a9mpcore_priv" 175126fec7SAndreas Färber #define A9MPCORE_PRIV(obj) \ 185126fec7SAndreas Färber OBJECT_CHECK(A9MPPrivState, (obj), TYPE_A9MPCORE_PRIV) 195126fec7SAndreas Färber 200434e30aSPaolo Bonzini typedef struct A9MPPrivState { 215126fec7SAndreas Färber /*< private >*/ 225126fec7SAndreas Färber SysBusDevice parent_obj; 235126fec7SAndreas Färber /*< public >*/ 245126fec7SAndreas Färber 250434e30aSPaolo Bonzini uint32_t num_cpu; 260434e30aSPaolo Bonzini MemoryRegion container; 270434e30aSPaolo Bonzini uint32_t num_irq; 289b5f952bSAndreas Färber 299b5f952bSAndreas Färber GICState gic; 30fc719d77SAndreas Färber A9SCUState scu; 31*eb110bd8SAndreas Färber ARMMPTimerState mptimer; 32*eb110bd8SAndreas Färber ARMMPTimerState wdt; 330434e30aSPaolo Bonzini } A9MPPrivState; 340434e30aSPaolo Bonzini 350434e30aSPaolo Bonzini static void a9mp_priv_set_irq(void *opaque, int irq, int level) 360434e30aSPaolo Bonzini { 370434e30aSPaolo Bonzini A9MPPrivState *s = (A9MPPrivState *)opaque; 389b5f952bSAndreas Färber 399b5f952bSAndreas Färber qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level); 400434e30aSPaolo Bonzini } 410434e30aSPaolo Bonzini 42753bc6e9SAndreas Färber static void a9mp_priv_initfn(Object *obj) 43753bc6e9SAndreas Färber { 44753bc6e9SAndreas Färber A9MPPrivState *s = A9MPCORE_PRIV(obj); 45753bc6e9SAndreas Färber 46753bc6e9SAndreas Färber memory_region_init(&s->container, obj, "a9mp-priv-container", 0x2000); 47753bc6e9SAndreas Färber sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->container); 489b5f952bSAndreas Färber 499b5f952bSAndreas Färber object_initialize(&s->gic, sizeof(s->gic), TYPE_ARM_GIC); 509b5f952bSAndreas Färber qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default()); 51fc719d77SAndreas Färber 52fc719d77SAndreas Färber object_initialize(&s->scu, sizeof(s->scu), TYPE_A9_SCU); 53fc719d77SAndreas Färber qdev_set_parent_bus(DEVICE(&s->scu), sysbus_get_default()); 54*eb110bd8SAndreas Färber 55*eb110bd8SAndreas Färber object_initialize(&s->mptimer, sizeof(s->mptimer), TYPE_ARM_MPTIMER); 56*eb110bd8SAndreas Färber qdev_set_parent_bus(DEVICE(&s->mptimer), sysbus_get_default()); 57*eb110bd8SAndreas Färber 58*eb110bd8SAndreas Färber object_initialize(&s->wdt, sizeof(s->wdt), TYPE_ARM_MPTIMER); 59*eb110bd8SAndreas Färber qdev_set_parent_bus(DEVICE(&s->wdt), sysbus_get_default()); 60753bc6e9SAndreas Färber } 61753bc6e9SAndreas Färber 620434e30aSPaolo Bonzini static int a9mp_priv_init(SysBusDevice *dev) 630434e30aSPaolo Bonzini { 645126fec7SAndreas Färber A9MPPrivState *s = A9MPCORE_PRIV(dev); 65*eb110bd8SAndreas Färber DeviceState *gicdev, *scudev, *mptimerdev, *wdtdev; 660434e30aSPaolo Bonzini SysBusDevice *timerbusdev, *wdtbusdev, *gicbusdev, *scubusdev; 670434e30aSPaolo Bonzini int i; 680434e30aSPaolo Bonzini 699b5f952bSAndreas Färber gicdev = DEVICE(&s->gic); 709b5f952bSAndreas Färber qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu); 719b5f952bSAndreas Färber qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq); 729b5f952bSAndreas Färber qdev_init_nofail(gicdev); 739b5f952bSAndreas Färber gicbusdev = SYS_BUS_DEVICE(&s->gic); 740434e30aSPaolo Bonzini 750434e30aSPaolo Bonzini /* Pass through outbound IRQ lines from the GIC */ 760434e30aSPaolo Bonzini sysbus_pass_irq(dev, gicbusdev); 770434e30aSPaolo Bonzini 780434e30aSPaolo Bonzini /* Pass through inbound GPIO lines to the GIC */ 795126fec7SAndreas Färber qdev_init_gpio_in(DEVICE(dev), a9mp_priv_set_irq, s->num_irq - 32); 800434e30aSPaolo Bonzini 81fc719d77SAndreas Färber scudev = DEVICE(&s->scu); 82fc719d77SAndreas Färber qdev_prop_set_uint32(scudev, "num-cpu", s->num_cpu); 83fc719d77SAndreas Färber qdev_init_nofail(scudev); 84fc719d77SAndreas Färber scubusdev = SYS_BUS_DEVICE(&s->scu); 850434e30aSPaolo Bonzini 86*eb110bd8SAndreas Färber mptimerdev = DEVICE(&s->mptimer); 87*eb110bd8SAndreas Färber qdev_prop_set_uint32(mptimerdev, "num-cpu", s->num_cpu); 88*eb110bd8SAndreas Färber qdev_init_nofail(mptimerdev); 89*eb110bd8SAndreas Färber timerbusdev = SYS_BUS_DEVICE(&s->mptimer); 900434e30aSPaolo Bonzini 91*eb110bd8SAndreas Färber wdtdev = DEVICE(&s->wdt); 92*eb110bd8SAndreas Färber qdev_prop_set_uint32(wdtdev, "num-cpu", s->num_cpu); 93*eb110bd8SAndreas Färber qdev_init_nofail(wdtdev); 94*eb110bd8SAndreas Färber wdtbusdev = SYS_BUS_DEVICE(&s->wdt); 950434e30aSPaolo Bonzini 960434e30aSPaolo Bonzini /* Memory map (addresses are offsets from PERIPHBASE): 970434e30aSPaolo Bonzini * 0x0000-0x00ff -- Snoop Control Unit 980434e30aSPaolo Bonzini * 0x0100-0x01ff -- GIC CPU interface 990434e30aSPaolo Bonzini * 0x0200-0x02ff -- Global Timer 1000434e30aSPaolo Bonzini * 0x0300-0x05ff -- nothing 1010434e30aSPaolo Bonzini * 0x0600-0x06ff -- private timers and watchdogs 1020434e30aSPaolo Bonzini * 0x0700-0x0fff -- nothing 1030434e30aSPaolo Bonzini * 0x1000-0x1fff -- GIC Distributor 1040434e30aSPaolo Bonzini * 1050434e30aSPaolo Bonzini * We should implement the global timer but don't currently do so. 1060434e30aSPaolo Bonzini */ 1070434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0, 1080434e30aSPaolo Bonzini sysbus_mmio_get_region(scubusdev, 0)); 1090434e30aSPaolo Bonzini /* GIC CPU interface */ 1100434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0x100, 1110434e30aSPaolo Bonzini sysbus_mmio_get_region(gicbusdev, 1)); 1120434e30aSPaolo Bonzini /* Note that the A9 exposes only the "timer/watchdog for this core" 1130434e30aSPaolo Bonzini * memory region, not the "timer/watchdog for core X" ones 11MPcore has. 1140434e30aSPaolo Bonzini */ 1150434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0x600, 1160434e30aSPaolo Bonzini sysbus_mmio_get_region(timerbusdev, 0)); 1170434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0x620, 1180434e30aSPaolo Bonzini sysbus_mmio_get_region(wdtbusdev, 0)); 1190434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0x1000, 1200434e30aSPaolo Bonzini sysbus_mmio_get_region(gicbusdev, 0)); 1210434e30aSPaolo Bonzini 1220434e30aSPaolo Bonzini /* Wire up the interrupt from each watchdog and timer. 1230434e30aSPaolo Bonzini * For each core the timer is PPI 29 and the watchdog PPI 30. 1240434e30aSPaolo Bonzini */ 1250434e30aSPaolo Bonzini for (i = 0; i < s->num_cpu; i++) { 1260434e30aSPaolo Bonzini int ppibase = (s->num_irq - 32) + i * 32; 1270434e30aSPaolo Bonzini sysbus_connect_irq(timerbusdev, i, 1289b5f952bSAndreas Färber qdev_get_gpio_in(gicdev, ppibase + 29)); 1290434e30aSPaolo Bonzini sysbus_connect_irq(wdtbusdev, i, 1309b5f952bSAndreas Färber qdev_get_gpio_in(gicdev, ppibase + 30)); 1310434e30aSPaolo Bonzini } 1320434e30aSPaolo Bonzini return 0; 1330434e30aSPaolo Bonzini } 1340434e30aSPaolo Bonzini 1350434e30aSPaolo Bonzini static Property a9mp_priv_properties[] = { 1360434e30aSPaolo Bonzini DEFINE_PROP_UINT32("num-cpu", A9MPPrivState, num_cpu, 1), 1370434e30aSPaolo Bonzini /* The Cortex-A9MP may have anything from 0 to 224 external interrupt 1380434e30aSPaolo Bonzini * IRQ lines (with another 32 internal). We default to 64+32, which 1390434e30aSPaolo Bonzini * is the number provided by the Cortex-A9MP test chip in the 1400434e30aSPaolo Bonzini * Realview PBX-A9 and Versatile Express A9 development boards. 1410434e30aSPaolo Bonzini * Other boards may differ and should set this property appropriately. 1420434e30aSPaolo Bonzini */ 1430434e30aSPaolo Bonzini DEFINE_PROP_UINT32("num-irq", A9MPPrivState, num_irq, 96), 1440434e30aSPaolo Bonzini DEFINE_PROP_END_OF_LIST(), 1450434e30aSPaolo Bonzini }; 1460434e30aSPaolo Bonzini 1470434e30aSPaolo Bonzini static void a9mp_priv_class_init(ObjectClass *klass, void *data) 1480434e30aSPaolo Bonzini { 1490434e30aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 1500434e30aSPaolo Bonzini SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); 1510434e30aSPaolo Bonzini 1520434e30aSPaolo Bonzini k->init = a9mp_priv_init; 1530434e30aSPaolo Bonzini dc->props = a9mp_priv_properties; 1540434e30aSPaolo Bonzini } 1550434e30aSPaolo Bonzini 1560434e30aSPaolo Bonzini static const TypeInfo a9mp_priv_info = { 1575126fec7SAndreas Färber .name = TYPE_A9MPCORE_PRIV, 1580434e30aSPaolo Bonzini .parent = TYPE_SYS_BUS_DEVICE, 1590434e30aSPaolo Bonzini .instance_size = sizeof(A9MPPrivState), 160753bc6e9SAndreas Färber .instance_init = a9mp_priv_initfn, 1610434e30aSPaolo Bonzini .class_init = a9mp_priv_class_init, 1620434e30aSPaolo Bonzini }; 1630434e30aSPaolo Bonzini 1640434e30aSPaolo Bonzini static void a9mp_register_types(void) 1650434e30aSPaolo Bonzini { 1660434e30aSPaolo Bonzini type_register_static(&a9mp_priv_info); 1670434e30aSPaolo Bonzini } 1680434e30aSPaolo Bonzini 1690434e30aSPaolo Bonzini type_init(a9mp_register_types) 170