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" 13*fc719d77SAndreas Färber #include "hw/misc/a9scu.h" 140434e30aSPaolo Bonzini 155126fec7SAndreas Färber #define TYPE_A9MPCORE_PRIV "a9mpcore_priv" 165126fec7SAndreas Färber #define A9MPCORE_PRIV(obj) \ 175126fec7SAndreas Färber OBJECT_CHECK(A9MPPrivState, (obj), TYPE_A9MPCORE_PRIV) 185126fec7SAndreas Färber 190434e30aSPaolo Bonzini typedef struct A9MPPrivState { 205126fec7SAndreas Färber /*< private >*/ 215126fec7SAndreas Färber SysBusDevice parent_obj; 225126fec7SAndreas Färber /*< public >*/ 235126fec7SAndreas Färber 240434e30aSPaolo Bonzini uint32_t num_cpu; 250434e30aSPaolo Bonzini MemoryRegion container; 260434e30aSPaolo Bonzini DeviceState *mptimer; 270434e30aSPaolo Bonzini DeviceState *wdt; 280434e30aSPaolo Bonzini uint32_t num_irq; 299b5f952bSAndreas Färber 309b5f952bSAndreas Färber GICState gic; 31*fc719d77SAndreas Färber A9SCUState scu; 320434e30aSPaolo Bonzini } A9MPPrivState; 330434e30aSPaolo Bonzini 340434e30aSPaolo Bonzini static void a9mp_priv_set_irq(void *opaque, int irq, int level) 350434e30aSPaolo Bonzini { 360434e30aSPaolo Bonzini A9MPPrivState *s = (A9MPPrivState *)opaque; 379b5f952bSAndreas Färber 389b5f952bSAndreas Färber qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level); 390434e30aSPaolo Bonzini } 400434e30aSPaolo Bonzini 41753bc6e9SAndreas Färber static void a9mp_priv_initfn(Object *obj) 42753bc6e9SAndreas Färber { 43753bc6e9SAndreas Färber A9MPPrivState *s = A9MPCORE_PRIV(obj); 44753bc6e9SAndreas Färber 45753bc6e9SAndreas Färber memory_region_init(&s->container, obj, "a9mp-priv-container", 0x2000); 46753bc6e9SAndreas Färber sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->container); 479b5f952bSAndreas Färber 489b5f952bSAndreas Färber object_initialize(&s->gic, sizeof(s->gic), TYPE_ARM_GIC); 499b5f952bSAndreas Färber qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default()); 50*fc719d77SAndreas Färber 51*fc719d77SAndreas Färber object_initialize(&s->scu, sizeof(s->scu), TYPE_A9_SCU); 52*fc719d77SAndreas Färber qdev_set_parent_bus(DEVICE(&s->scu), sysbus_get_default()); 53753bc6e9SAndreas Färber } 54753bc6e9SAndreas Färber 550434e30aSPaolo Bonzini static int a9mp_priv_init(SysBusDevice *dev) 560434e30aSPaolo Bonzini { 575126fec7SAndreas Färber A9MPPrivState *s = A9MPCORE_PRIV(dev); 58*fc719d77SAndreas Färber DeviceState *gicdev, *scudev; 590434e30aSPaolo Bonzini SysBusDevice *timerbusdev, *wdtbusdev, *gicbusdev, *scubusdev; 600434e30aSPaolo Bonzini int i; 610434e30aSPaolo Bonzini 629b5f952bSAndreas Färber gicdev = DEVICE(&s->gic); 639b5f952bSAndreas Färber qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu); 649b5f952bSAndreas Färber qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq); 659b5f952bSAndreas Färber qdev_init_nofail(gicdev); 669b5f952bSAndreas Färber gicbusdev = SYS_BUS_DEVICE(&s->gic); 670434e30aSPaolo Bonzini 680434e30aSPaolo Bonzini /* Pass through outbound IRQ lines from the GIC */ 690434e30aSPaolo Bonzini sysbus_pass_irq(dev, gicbusdev); 700434e30aSPaolo Bonzini 710434e30aSPaolo Bonzini /* Pass through inbound GPIO lines to the GIC */ 725126fec7SAndreas Färber qdev_init_gpio_in(DEVICE(dev), a9mp_priv_set_irq, s->num_irq - 32); 730434e30aSPaolo Bonzini 74*fc719d77SAndreas Färber scudev = DEVICE(&s->scu); 75*fc719d77SAndreas Färber qdev_prop_set_uint32(scudev, "num-cpu", s->num_cpu); 76*fc719d77SAndreas Färber qdev_init_nofail(scudev); 77*fc719d77SAndreas Färber scubusdev = SYS_BUS_DEVICE(&s->scu); 780434e30aSPaolo Bonzini 790434e30aSPaolo Bonzini s->mptimer = qdev_create(NULL, "arm_mptimer"); 800434e30aSPaolo Bonzini qdev_prop_set_uint32(s->mptimer, "num-cpu", s->num_cpu); 810434e30aSPaolo Bonzini qdev_init_nofail(s->mptimer); 820434e30aSPaolo Bonzini timerbusdev = SYS_BUS_DEVICE(s->mptimer); 830434e30aSPaolo Bonzini 840434e30aSPaolo Bonzini s->wdt = qdev_create(NULL, "arm_mptimer"); 850434e30aSPaolo Bonzini qdev_prop_set_uint32(s->wdt, "num-cpu", s->num_cpu); 860434e30aSPaolo Bonzini qdev_init_nofail(s->wdt); 870434e30aSPaolo Bonzini wdtbusdev = SYS_BUS_DEVICE(s->wdt); 880434e30aSPaolo Bonzini 890434e30aSPaolo Bonzini /* Memory map (addresses are offsets from PERIPHBASE): 900434e30aSPaolo Bonzini * 0x0000-0x00ff -- Snoop Control Unit 910434e30aSPaolo Bonzini * 0x0100-0x01ff -- GIC CPU interface 920434e30aSPaolo Bonzini * 0x0200-0x02ff -- Global Timer 930434e30aSPaolo Bonzini * 0x0300-0x05ff -- nothing 940434e30aSPaolo Bonzini * 0x0600-0x06ff -- private timers and watchdogs 950434e30aSPaolo Bonzini * 0x0700-0x0fff -- nothing 960434e30aSPaolo Bonzini * 0x1000-0x1fff -- GIC Distributor 970434e30aSPaolo Bonzini * 980434e30aSPaolo Bonzini * We should implement the global timer but don't currently do so. 990434e30aSPaolo Bonzini */ 1000434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0, 1010434e30aSPaolo Bonzini sysbus_mmio_get_region(scubusdev, 0)); 1020434e30aSPaolo Bonzini /* GIC CPU interface */ 1030434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0x100, 1040434e30aSPaolo Bonzini sysbus_mmio_get_region(gicbusdev, 1)); 1050434e30aSPaolo Bonzini /* Note that the A9 exposes only the "timer/watchdog for this core" 1060434e30aSPaolo Bonzini * memory region, not the "timer/watchdog for core X" ones 11MPcore has. 1070434e30aSPaolo Bonzini */ 1080434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0x600, 1090434e30aSPaolo Bonzini sysbus_mmio_get_region(timerbusdev, 0)); 1100434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0x620, 1110434e30aSPaolo Bonzini sysbus_mmio_get_region(wdtbusdev, 0)); 1120434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0x1000, 1130434e30aSPaolo Bonzini sysbus_mmio_get_region(gicbusdev, 0)); 1140434e30aSPaolo Bonzini 1150434e30aSPaolo Bonzini /* Wire up the interrupt from each watchdog and timer. 1160434e30aSPaolo Bonzini * For each core the timer is PPI 29 and the watchdog PPI 30. 1170434e30aSPaolo Bonzini */ 1180434e30aSPaolo Bonzini for (i = 0; i < s->num_cpu; i++) { 1190434e30aSPaolo Bonzini int ppibase = (s->num_irq - 32) + i * 32; 1200434e30aSPaolo Bonzini sysbus_connect_irq(timerbusdev, i, 1219b5f952bSAndreas Färber qdev_get_gpio_in(gicdev, ppibase + 29)); 1220434e30aSPaolo Bonzini sysbus_connect_irq(wdtbusdev, i, 1239b5f952bSAndreas Färber qdev_get_gpio_in(gicdev, ppibase + 30)); 1240434e30aSPaolo Bonzini } 1250434e30aSPaolo Bonzini return 0; 1260434e30aSPaolo Bonzini } 1270434e30aSPaolo Bonzini 1280434e30aSPaolo Bonzini static Property a9mp_priv_properties[] = { 1290434e30aSPaolo Bonzini DEFINE_PROP_UINT32("num-cpu", A9MPPrivState, num_cpu, 1), 1300434e30aSPaolo Bonzini /* The Cortex-A9MP may have anything from 0 to 224 external interrupt 1310434e30aSPaolo Bonzini * IRQ lines (with another 32 internal). We default to 64+32, which 1320434e30aSPaolo Bonzini * is the number provided by the Cortex-A9MP test chip in the 1330434e30aSPaolo Bonzini * Realview PBX-A9 and Versatile Express A9 development boards. 1340434e30aSPaolo Bonzini * Other boards may differ and should set this property appropriately. 1350434e30aSPaolo Bonzini */ 1360434e30aSPaolo Bonzini DEFINE_PROP_UINT32("num-irq", A9MPPrivState, num_irq, 96), 1370434e30aSPaolo Bonzini DEFINE_PROP_END_OF_LIST(), 1380434e30aSPaolo Bonzini }; 1390434e30aSPaolo Bonzini 1400434e30aSPaolo Bonzini static void a9mp_priv_class_init(ObjectClass *klass, void *data) 1410434e30aSPaolo Bonzini { 1420434e30aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 1430434e30aSPaolo Bonzini SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); 1440434e30aSPaolo Bonzini 1450434e30aSPaolo Bonzini k->init = a9mp_priv_init; 1460434e30aSPaolo Bonzini dc->props = a9mp_priv_properties; 1470434e30aSPaolo Bonzini } 1480434e30aSPaolo Bonzini 1490434e30aSPaolo Bonzini static const TypeInfo a9mp_priv_info = { 1505126fec7SAndreas Färber .name = TYPE_A9MPCORE_PRIV, 1510434e30aSPaolo Bonzini .parent = TYPE_SYS_BUS_DEVICE, 1520434e30aSPaolo Bonzini .instance_size = sizeof(A9MPPrivState), 153753bc6e9SAndreas Färber .instance_init = a9mp_priv_initfn, 1540434e30aSPaolo Bonzini .class_init = a9mp_priv_class_init, 1550434e30aSPaolo Bonzini }; 1560434e30aSPaolo Bonzini 1570434e30aSPaolo Bonzini static void a9mp_register_types(void) 1580434e30aSPaolo Bonzini { 1590434e30aSPaolo Bonzini type_register_static(&a9mp_priv_info); 1600434e30aSPaolo Bonzini } 1610434e30aSPaolo Bonzini 1620434e30aSPaolo Bonzini type_init(a9mp_register_types) 163