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 1117b7f2dbSPeter Maydell #include "qemu/osdep.h" 12da34e65cSMarkus Armbruster #include "qapi/error.h" 13de4c2dcfSAndreas Färber #include "hw/cpu/a9mpcore.h" 147d0c99a9SPaolo Bonzini #include "qom/cpu.h" 150434e30aSPaolo Bonzini 160434e30aSPaolo Bonzini static void a9mp_priv_set_irq(void *opaque, int irq, int level) 170434e30aSPaolo Bonzini { 180434e30aSPaolo Bonzini A9MPPrivState *s = (A9MPPrivState *)opaque; 199b5f952bSAndreas Färber 209b5f952bSAndreas Färber qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level); 210434e30aSPaolo Bonzini } 220434e30aSPaolo Bonzini 23753bc6e9SAndreas Färber static void a9mp_priv_initfn(Object *obj) 24753bc6e9SAndreas Färber { 25753bc6e9SAndreas Färber A9MPPrivState *s = A9MPCORE_PRIV(obj); 26753bc6e9SAndreas Färber 27753bc6e9SAndreas Färber memory_region_init(&s->container, obj, "a9mp-priv-container", 0x2000); 28753bc6e9SAndreas Färber sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->container); 299b5f952bSAndreas Färber 30*2ba486e7SThomas Huth sysbus_init_child_obj(obj, "scu", &s->scu, sizeof(s->scu), TYPE_A9_SCU); 31eb110bd8SAndreas Färber 32*2ba486e7SThomas Huth sysbus_init_child_obj(obj, "gic", &s->gic, sizeof(s->gic), TYPE_ARM_GIC); 334c25f365SPeter Crosthwaite 34*2ba486e7SThomas Huth sysbus_init_child_obj(obj, "gtimer", &s->gtimer, sizeof(s->gtimer), 35*2ba486e7SThomas Huth TYPE_A9_GTIMER); 3657e72f2aSFrançois LEGAL 37*2ba486e7SThomas Huth sysbus_init_child_obj(obj, "mptimer", &s->mptimer, sizeof(s->mptimer), 38*2ba486e7SThomas Huth TYPE_ARM_MPTIMER); 39eb110bd8SAndreas Färber 40*2ba486e7SThomas Huth sysbus_init_child_obj(obj, "wdt", &s->wdt, sizeof(s->wdt), 41*2ba486e7SThomas Huth TYPE_ARM_MPTIMER); 42753bc6e9SAndreas Färber } 43753bc6e9SAndreas Färber 44837cf101SAndreas Färber static void a9mp_priv_realize(DeviceState *dev, Error **errp) 450434e30aSPaolo Bonzini { 46837cf101SAndreas Färber SysBusDevice *sbd = SYS_BUS_DEVICE(dev); 475126fec7SAndreas Färber A9MPPrivState *s = A9MPCORE_PRIV(dev); 4857e72f2aSFrançois LEGAL DeviceState *scudev, *gicdev, *gtimerdev, *mptimerdev, *wdtdev; 4957e72f2aSFrançois LEGAL SysBusDevice *scubusdev, *gicbusdev, *gtimerbusdev, *mptimerbusdev, 5057e72f2aSFrançois LEGAL *wdtbusdev; 51837cf101SAndreas Färber Error *err = NULL; 520434e30aSPaolo Bonzini int i; 534182bbb1SPeter Maydell bool has_el3; 544182bbb1SPeter Maydell Object *cpuobj; 550434e30aSPaolo Bonzini 564c25f365SPeter Crosthwaite scudev = DEVICE(&s->scu); 574c25f365SPeter Crosthwaite qdev_prop_set_uint32(scudev, "num-cpu", s->num_cpu); 584c25f365SPeter Crosthwaite object_property_set_bool(OBJECT(&s->scu), true, "realized", &err); 594c25f365SPeter Crosthwaite if (err != NULL) { 604c25f365SPeter Crosthwaite error_propagate(errp, err); 614c25f365SPeter Crosthwaite return; 624c25f365SPeter Crosthwaite } 634c25f365SPeter Crosthwaite scubusdev = SYS_BUS_DEVICE(&s->scu); 644c25f365SPeter Crosthwaite 659b5f952bSAndreas Färber gicdev = DEVICE(&s->gic); 669b5f952bSAndreas Färber qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu); 679b5f952bSAndreas Färber qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq); 684182bbb1SPeter Maydell 694182bbb1SPeter Maydell /* Make the GIC's TZ support match the CPUs. We assume that 704182bbb1SPeter Maydell * either all the CPUs have TZ, or none do. 714182bbb1SPeter Maydell */ 724182bbb1SPeter Maydell cpuobj = OBJECT(qemu_get_cpu(0)); 736533a1fcSEdgar E. Iglesias has_el3 = object_property_find(cpuobj, "has_el3", NULL) && 744182bbb1SPeter Maydell object_property_get_bool(cpuobj, "has_el3", &error_abort); 754182bbb1SPeter Maydell qdev_prop_set_bit(gicdev, "has-security-extensions", has_el3); 764182bbb1SPeter Maydell 77837cf101SAndreas Färber object_property_set_bool(OBJECT(&s->gic), true, "realized", &err); 78837cf101SAndreas Färber if (err != NULL) { 79837cf101SAndreas Färber error_propagate(errp, err); 80837cf101SAndreas Färber return; 81837cf101SAndreas Färber } 829b5f952bSAndreas Färber gicbusdev = SYS_BUS_DEVICE(&s->gic); 830434e30aSPaolo Bonzini 840434e30aSPaolo Bonzini /* Pass through outbound IRQ lines from the GIC */ 85837cf101SAndreas Färber sysbus_pass_irq(sbd, gicbusdev); 860434e30aSPaolo Bonzini 870434e30aSPaolo Bonzini /* Pass through inbound GPIO lines to the GIC */ 88837cf101SAndreas Färber qdev_init_gpio_in(dev, a9mp_priv_set_irq, s->num_irq - 32); 890434e30aSPaolo Bonzini 9057e72f2aSFrançois LEGAL gtimerdev = DEVICE(&s->gtimer); 9157e72f2aSFrançois LEGAL qdev_prop_set_uint32(gtimerdev, "num-cpu", s->num_cpu); 9257e72f2aSFrançois LEGAL object_property_set_bool(OBJECT(&s->gtimer), true, "realized", &err); 9357e72f2aSFrançois LEGAL if (err != NULL) { 9457e72f2aSFrançois LEGAL error_propagate(errp, err); 9557e72f2aSFrançois LEGAL return; 9657e72f2aSFrançois LEGAL } 9757e72f2aSFrançois LEGAL gtimerbusdev = SYS_BUS_DEVICE(&s->gtimer); 9857e72f2aSFrançois LEGAL 99eb110bd8SAndreas Färber mptimerdev = DEVICE(&s->mptimer); 100eb110bd8SAndreas Färber qdev_prop_set_uint32(mptimerdev, "num-cpu", s->num_cpu); 101837cf101SAndreas Färber object_property_set_bool(OBJECT(&s->mptimer), true, "realized", &err); 102837cf101SAndreas Färber if (err != NULL) { 103837cf101SAndreas Färber error_propagate(errp, err); 104837cf101SAndreas Färber return; 105837cf101SAndreas Färber } 106d3053e6bSPeter Crosthwaite mptimerbusdev = SYS_BUS_DEVICE(&s->mptimer); 1070434e30aSPaolo Bonzini 108eb110bd8SAndreas Färber wdtdev = DEVICE(&s->wdt); 109eb110bd8SAndreas Färber qdev_prop_set_uint32(wdtdev, "num-cpu", s->num_cpu); 110837cf101SAndreas Färber object_property_set_bool(OBJECT(&s->wdt), true, "realized", &err); 111837cf101SAndreas Färber if (err != NULL) { 112837cf101SAndreas Färber error_propagate(errp, err); 113837cf101SAndreas Färber return; 114837cf101SAndreas Färber } 115eb110bd8SAndreas Färber wdtbusdev = SYS_BUS_DEVICE(&s->wdt); 1160434e30aSPaolo Bonzini 1170434e30aSPaolo Bonzini /* Memory map (addresses are offsets from PERIPHBASE): 1180434e30aSPaolo Bonzini * 0x0000-0x00ff -- Snoop Control Unit 1190434e30aSPaolo Bonzini * 0x0100-0x01ff -- GIC CPU interface 1200434e30aSPaolo Bonzini * 0x0200-0x02ff -- Global Timer 1210434e30aSPaolo Bonzini * 0x0300-0x05ff -- nothing 1220434e30aSPaolo Bonzini * 0x0600-0x06ff -- private timers and watchdogs 1230434e30aSPaolo Bonzini * 0x0700-0x0fff -- nothing 1240434e30aSPaolo Bonzini * 0x1000-0x1fff -- GIC Distributor 1250434e30aSPaolo Bonzini */ 1260434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0, 1270434e30aSPaolo Bonzini sysbus_mmio_get_region(scubusdev, 0)); 1280434e30aSPaolo Bonzini /* GIC CPU interface */ 1290434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0x100, 1300434e30aSPaolo Bonzini sysbus_mmio_get_region(gicbusdev, 1)); 13157e72f2aSFrançois LEGAL memory_region_add_subregion(&s->container, 0x200, 13257e72f2aSFrançois LEGAL sysbus_mmio_get_region(gtimerbusdev, 0)); 1330434e30aSPaolo Bonzini /* Note that the A9 exposes only the "timer/watchdog for this core" 1340434e30aSPaolo Bonzini * memory region, not the "timer/watchdog for core X" ones 11MPcore has. 1350434e30aSPaolo Bonzini */ 1360434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0x600, 137d3053e6bSPeter Crosthwaite sysbus_mmio_get_region(mptimerbusdev, 0)); 1380434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0x620, 1390434e30aSPaolo Bonzini sysbus_mmio_get_region(wdtbusdev, 0)); 1400434e30aSPaolo Bonzini memory_region_add_subregion(&s->container, 0x1000, 1410434e30aSPaolo Bonzini sysbus_mmio_get_region(gicbusdev, 0)); 1420434e30aSPaolo Bonzini 1430434e30aSPaolo Bonzini /* Wire up the interrupt from each watchdog and timer. 14457e72f2aSFrançois LEGAL * For each core the global timer is PPI 27, the private 14557e72f2aSFrançois LEGAL * timer is PPI 29 and the watchdog PPI 30. 1460434e30aSPaolo Bonzini */ 1470434e30aSPaolo Bonzini for (i = 0; i < s->num_cpu; i++) { 1480434e30aSPaolo Bonzini int ppibase = (s->num_irq - 32) + i * 32; 14957e72f2aSFrançois LEGAL sysbus_connect_irq(gtimerbusdev, i, 15057e72f2aSFrançois LEGAL qdev_get_gpio_in(gicdev, ppibase + 27)); 151d3053e6bSPeter Crosthwaite sysbus_connect_irq(mptimerbusdev, i, 1529b5f952bSAndreas Färber qdev_get_gpio_in(gicdev, ppibase + 29)); 1530434e30aSPaolo Bonzini sysbus_connect_irq(wdtbusdev, i, 1549b5f952bSAndreas Färber qdev_get_gpio_in(gicdev, ppibase + 30)); 1550434e30aSPaolo Bonzini } 1560434e30aSPaolo Bonzini } 1570434e30aSPaolo Bonzini 1580434e30aSPaolo Bonzini static Property a9mp_priv_properties[] = { 1590434e30aSPaolo Bonzini DEFINE_PROP_UINT32("num-cpu", A9MPPrivState, num_cpu, 1), 1600434e30aSPaolo Bonzini /* The Cortex-A9MP may have anything from 0 to 224 external interrupt 1610434e30aSPaolo Bonzini * IRQ lines (with another 32 internal). We default to 64+32, which 1620434e30aSPaolo Bonzini * is the number provided by the Cortex-A9MP test chip in the 1630434e30aSPaolo Bonzini * Realview PBX-A9 and Versatile Express A9 development boards. 1640434e30aSPaolo Bonzini * Other boards may differ and should set this property appropriately. 1650434e30aSPaolo Bonzini */ 1660434e30aSPaolo Bonzini DEFINE_PROP_UINT32("num-irq", A9MPPrivState, num_irq, 96), 1670434e30aSPaolo Bonzini DEFINE_PROP_END_OF_LIST(), 1680434e30aSPaolo Bonzini }; 1690434e30aSPaolo Bonzini 1700434e30aSPaolo Bonzini static void a9mp_priv_class_init(ObjectClass *klass, void *data) 1710434e30aSPaolo Bonzini { 1720434e30aSPaolo Bonzini DeviceClass *dc = DEVICE_CLASS(klass); 1730434e30aSPaolo Bonzini 174837cf101SAndreas Färber dc->realize = a9mp_priv_realize; 1750434e30aSPaolo Bonzini dc->props = a9mp_priv_properties; 1760434e30aSPaolo Bonzini } 1770434e30aSPaolo Bonzini 1780434e30aSPaolo Bonzini static const TypeInfo a9mp_priv_info = { 1795126fec7SAndreas Färber .name = TYPE_A9MPCORE_PRIV, 1800434e30aSPaolo Bonzini .parent = TYPE_SYS_BUS_DEVICE, 1810434e30aSPaolo Bonzini .instance_size = sizeof(A9MPPrivState), 182753bc6e9SAndreas Färber .instance_init = a9mp_priv_initfn, 1830434e30aSPaolo Bonzini .class_init = a9mp_priv_class_init, 1840434e30aSPaolo Bonzini }; 1850434e30aSPaolo Bonzini 1860434e30aSPaolo Bonzini static void a9mp_register_types(void) 1870434e30aSPaolo Bonzini { 1880434e30aSPaolo Bonzini type_register_static(&a9mp_priv_info); 1890434e30aSPaolo Bonzini } 1900434e30aSPaolo Bonzini 1910434e30aSPaolo Bonzini type_init(a9mp_register_types) 192