1f0a902f7SPeter Crosthwaite /* 2f0a902f7SPeter Crosthwaite * Xilinx Zynq MPSoC emulation 3f0a902f7SPeter Crosthwaite * 4f0a902f7SPeter Crosthwaite * Copyright (C) 2015 Xilinx Inc 5f0a902f7SPeter Crosthwaite * Written by Peter Crosthwaite <peter.crosthwaite@xilinx.com> 6f0a902f7SPeter Crosthwaite * 7f0a902f7SPeter Crosthwaite * This program is free software; you can redistribute it and/or modify it 8f0a902f7SPeter Crosthwaite * under the terms of the GNU General Public License as published by the 9f0a902f7SPeter Crosthwaite * Free Software Foundation; either version 2 of the License, or 10f0a902f7SPeter Crosthwaite * (at your option) any later version. 11f0a902f7SPeter Crosthwaite * 12f0a902f7SPeter Crosthwaite * This program is distributed in the hope that it will be useful, but WITHOUT 13f0a902f7SPeter Crosthwaite * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14f0a902f7SPeter Crosthwaite * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15f0a902f7SPeter Crosthwaite * for more details. 16f0a902f7SPeter Crosthwaite */ 17f0a902f7SPeter Crosthwaite 1812b16722SPeter Maydell #include "qemu/osdep.h" 19da34e65cSMarkus Armbruster #include "qapi/error.h" 204771d756SPaolo Bonzini #include "qemu-common.h" 214771d756SPaolo Bonzini #include "cpu.h" 22f0a902f7SPeter Crosthwaite #include "hw/arm/xlnx-zynqmp.h" 23bf4cb109SPeter Crosthwaite #include "hw/intc/arm_gic_common.h" 247729e1f4SPeter Crosthwaite #include "exec/address-spaces.h" 252a0ee672SEdgar E. Iglesias #include "sysemu/kvm.h" 262a0ee672SEdgar E. Iglesias #include "kvm_arm.h" 277729e1f4SPeter Crosthwaite 287729e1f4SPeter Crosthwaite #define GIC_NUM_SPI_INTR 160 297729e1f4SPeter Crosthwaite 30bf4cb109SPeter Crosthwaite #define ARM_PHYS_TIMER_PPI 30 31bf4cb109SPeter Crosthwaite #define ARM_VIRT_TIMER_PPI 27 32bf4cb109SPeter Crosthwaite 3320bff213SAlistair Francis #define GEM_REVISION 0x40070106 3420bff213SAlistair Francis 357729e1f4SPeter Crosthwaite #define GIC_BASE_ADDR 0xf9000000 367729e1f4SPeter Crosthwaite #define GIC_DIST_ADDR 0xf9010000 377729e1f4SPeter Crosthwaite #define GIC_CPU_ADDR 0xf9020000 387729e1f4SPeter Crosthwaite 396fdf3282SAlistair Francis #define SATA_INTR 133 406fdf3282SAlistair Francis #define SATA_ADDR 0xFD0C0000 416fdf3282SAlistair Francis #define SATA_NUM_PORTS 2 426fdf3282SAlistair Francis 43babc1f30SFrancisco Iglesias #define QSPI_ADDR 0xff0f0000 44babc1f30SFrancisco Iglesias #define LQSPI_ADDR 0xc0000000 45babc1f30SFrancisco Iglesias #define QSPI_IRQ 15 46babc1f30SFrancisco Iglesias 47b93dbcddSKONRAD Frederic #define DP_ADDR 0xfd4a0000 48b93dbcddSKONRAD Frederic #define DP_IRQ 113 49b93dbcddSKONRAD Frederic 50b93dbcddSKONRAD Frederic #define DPDMA_ADDR 0xfd4c0000 51b93dbcddSKONRAD Frederic #define DPDMA_IRQ 116 52b93dbcddSKONRAD Frederic 530ab7bbc7SAlistair Francis #define IPI_ADDR 0xFF300000 540ab7bbc7SAlistair Francis #define IPI_IRQ 64 550ab7bbc7SAlistair Francis 5608b2f15eSAlistair Francis #define RTC_ADDR 0xffa60000 5708b2f15eSAlistair Francis #define RTC_IRQ 26 5808b2f15eSAlistair Francis 59b630d3d4SPhilippe Mathieu-Daudé #define SDHCI_CAPABILITIES 0x280737ec6481 /* Datasheet: UG1085 (v1.7) */ 60b630d3d4SPhilippe Mathieu-Daudé 6114ca2e46SPeter Crosthwaite static const uint64_t gem_addr[XLNX_ZYNQMP_NUM_GEMS] = { 6214ca2e46SPeter Crosthwaite 0xFF0B0000, 0xFF0C0000, 0xFF0D0000, 0xFF0E0000, 6314ca2e46SPeter Crosthwaite }; 6414ca2e46SPeter Crosthwaite 6514ca2e46SPeter Crosthwaite static const int gem_intr[XLNX_ZYNQMP_NUM_GEMS] = { 6614ca2e46SPeter Crosthwaite 57, 59, 61, 63, 6714ca2e46SPeter Crosthwaite }; 6814ca2e46SPeter Crosthwaite 693bade2a9SPeter Crosthwaite static const uint64_t uart_addr[XLNX_ZYNQMP_NUM_UARTS] = { 703bade2a9SPeter Crosthwaite 0xFF000000, 0xFF010000, 713bade2a9SPeter Crosthwaite }; 723bade2a9SPeter Crosthwaite 733bade2a9SPeter Crosthwaite static const int uart_intr[XLNX_ZYNQMP_NUM_UARTS] = { 743bade2a9SPeter Crosthwaite 21, 22, 753bade2a9SPeter Crosthwaite }; 763bade2a9SPeter Crosthwaite 7733108e9fSSai Pavan Boddu static const uint64_t sdhci_addr[XLNX_ZYNQMP_NUM_SDHCI] = { 7833108e9fSSai Pavan Boddu 0xFF160000, 0xFF170000, 7933108e9fSSai Pavan Boddu }; 8033108e9fSSai Pavan Boddu 8133108e9fSSai Pavan Boddu static const int sdhci_intr[XLNX_ZYNQMP_NUM_SDHCI] = { 8233108e9fSSai Pavan Boddu 48, 49, 8333108e9fSSai Pavan Boddu }; 8433108e9fSSai Pavan Boddu 8502d07eb4SAlistair Francis static const uint64_t spi_addr[XLNX_ZYNQMP_NUM_SPIS] = { 8602d07eb4SAlistair Francis 0xFF040000, 0xFF050000, 8702d07eb4SAlistair Francis }; 8802d07eb4SAlistair Francis 8902d07eb4SAlistair Francis static const int spi_intr[XLNX_ZYNQMP_NUM_SPIS] = { 9002d07eb4SAlistair Francis 19, 20, 9102d07eb4SAlistair Francis }; 9202d07eb4SAlistair Francis 937729e1f4SPeter Crosthwaite typedef struct XlnxZynqMPGICRegion { 947729e1f4SPeter Crosthwaite int region_index; 957729e1f4SPeter Crosthwaite uint32_t address; 967729e1f4SPeter Crosthwaite } XlnxZynqMPGICRegion; 977729e1f4SPeter Crosthwaite 987729e1f4SPeter Crosthwaite static const XlnxZynqMPGICRegion xlnx_zynqmp_gic_regions[] = { 997729e1f4SPeter Crosthwaite { .region_index = 0, .address = GIC_DIST_ADDR, }, 1007729e1f4SPeter Crosthwaite { .region_index = 1, .address = GIC_CPU_ADDR, }, 1017729e1f4SPeter Crosthwaite }; 102f0a902f7SPeter Crosthwaite 103bf4cb109SPeter Crosthwaite static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index) 104bf4cb109SPeter Crosthwaite { 105bf4cb109SPeter Crosthwaite return GIC_NUM_SPI_INTR + cpu_nr * GIC_INTERNAL + ppi_index; 106bf4cb109SPeter Crosthwaite } 107bf4cb109SPeter Crosthwaite 1086ed92b14SEdgar E. Iglesias static void xlnx_zynqmp_create_rpu(XlnxZynqMPState *s, const char *boot_cpu, 1096ed92b14SEdgar E. Iglesias Error **errp) 1106ed92b14SEdgar E. Iglesias { 1116ed92b14SEdgar E. Iglesias Error *err = NULL; 1126ed92b14SEdgar E. Iglesias int i; 1136908ec44SAlistair Francis int num_rpus = MIN(smp_cpus - XLNX_ZYNQMP_NUM_APU_CPUS, XLNX_ZYNQMP_NUM_RPU_CPUS); 1146ed92b14SEdgar E. Iglesias 1156908ec44SAlistair Francis for (i = 0; i < num_rpus; i++) { 1166ed92b14SEdgar E. Iglesias char *name; 1176ed92b14SEdgar E. Iglesias 1186ed92b14SEdgar E. Iglesias object_initialize(&s->rpu_cpu[i], sizeof(s->rpu_cpu[i]), 1196ed92b14SEdgar E. Iglesias "cortex-r5-" TYPE_ARM_CPU); 1206ed92b14SEdgar E. Iglesias object_property_add_child(OBJECT(s), "rpu-cpu[*]", 1216ed92b14SEdgar E. Iglesias OBJECT(&s->rpu_cpu[i]), &error_abort); 1226ed92b14SEdgar E. Iglesias 1236ed92b14SEdgar E. Iglesias name = object_get_canonical_path_component(OBJECT(&s->rpu_cpu[i])); 1246ed92b14SEdgar E. Iglesias if (strcmp(name, boot_cpu)) { 1256ed92b14SEdgar E. Iglesias /* Secondary CPUs start in PSCI powered-down state */ 1266ed92b14SEdgar E. Iglesias object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, 1276ed92b14SEdgar E. Iglesias "start-powered-off", &error_abort); 1286ed92b14SEdgar E. Iglesias } else { 1296ed92b14SEdgar E. Iglesias s->boot_cpu_ptr = &s->rpu_cpu[i]; 1306ed92b14SEdgar E. Iglesias } 1316ed92b14SEdgar E. Iglesias g_free(name); 1326ed92b14SEdgar E. Iglesias 1336ed92b14SEdgar E. Iglesias object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, "reset-hivecs", 1346ed92b14SEdgar E. Iglesias &error_abort); 1356ed92b14SEdgar E. Iglesias object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, "realized", 1366ed92b14SEdgar E. Iglesias &err); 1376ed92b14SEdgar E. Iglesias if (err) { 1386ed92b14SEdgar E. Iglesias error_propagate(errp, err); 1396ed92b14SEdgar E. Iglesias return; 1406ed92b14SEdgar E. Iglesias } 1416ed92b14SEdgar E. Iglesias } 1426ed92b14SEdgar E. Iglesias } 1436ed92b14SEdgar E. Iglesias 144f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_init(Object *obj) 145f0a902f7SPeter Crosthwaite { 146f0a902f7SPeter Crosthwaite XlnxZynqMPState *s = XLNX_ZYNQMP(obj); 147f0a902f7SPeter Crosthwaite int i; 1486908ec44SAlistair Francis int num_apus = MIN(smp_cpus, XLNX_ZYNQMP_NUM_APU_CPUS); 149f0a902f7SPeter Crosthwaite 1506908ec44SAlistair Francis for (i = 0; i < num_apus; i++) { 1512e5577bcSPeter Crosthwaite object_initialize(&s->apu_cpu[i], sizeof(s->apu_cpu[i]), 152f0a902f7SPeter Crosthwaite "cortex-a53-" TYPE_ARM_CPU); 1532e5577bcSPeter Crosthwaite object_property_add_child(obj, "apu-cpu[*]", OBJECT(&s->apu_cpu[i]), 154f0a902f7SPeter Crosthwaite &error_abort); 155f0a902f7SPeter Crosthwaite } 1567729e1f4SPeter Crosthwaite 1572a0ee672SEdgar E. Iglesias object_initialize(&s->gic, sizeof(s->gic), gic_class_name()); 1587729e1f4SPeter Crosthwaite qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default()); 15914ca2e46SPeter Crosthwaite 16014ca2e46SPeter Crosthwaite for (i = 0; i < XLNX_ZYNQMP_NUM_GEMS; i++) { 16114ca2e46SPeter Crosthwaite object_initialize(&s->gem[i], sizeof(s->gem[i]), TYPE_CADENCE_GEM); 16214ca2e46SPeter Crosthwaite qdev_set_parent_bus(DEVICE(&s->gem[i]), sysbus_get_default()); 16314ca2e46SPeter Crosthwaite } 1643bade2a9SPeter Crosthwaite 1653bade2a9SPeter Crosthwaite for (i = 0; i < XLNX_ZYNQMP_NUM_UARTS; i++) { 1663bade2a9SPeter Crosthwaite object_initialize(&s->uart[i], sizeof(s->uart[i]), TYPE_CADENCE_UART); 1673bade2a9SPeter Crosthwaite qdev_set_parent_bus(DEVICE(&s->uart[i]), sysbus_get_default()); 1683bade2a9SPeter Crosthwaite } 1696fdf3282SAlistair Francis 1706fdf3282SAlistair Francis object_initialize(&s->sata, sizeof(s->sata), TYPE_SYSBUS_AHCI); 1716fdf3282SAlistair Francis qdev_set_parent_bus(DEVICE(&s->sata), sysbus_get_default()); 17233108e9fSSai Pavan Boddu 17333108e9fSSai Pavan Boddu for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) { 17433108e9fSSai Pavan Boddu object_initialize(&s->sdhci[i], sizeof(s->sdhci[i]), 17533108e9fSSai Pavan Boddu TYPE_SYSBUS_SDHCI); 17633108e9fSSai Pavan Boddu qdev_set_parent_bus(DEVICE(&s->sdhci[i]), 17733108e9fSSai Pavan Boddu sysbus_get_default()); 17833108e9fSSai Pavan Boddu } 17902d07eb4SAlistair Francis 18002d07eb4SAlistair Francis for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) { 18102d07eb4SAlistair Francis object_initialize(&s->spi[i], sizeof(s->spi[i]), 18202d07eb4SAlistair Francis TYPE_XILINX_SPIPS); 18302d07eb4SAlistair Francis qdev_set_parent_bus(DEVICE(&s->spi[i]), sysbus_get_default()); 18402d07eb4SAlistair Francis } 185b93dbcddSKONRAD Frederic 186babc1f30SFrancisco Iglesias object_initialize(&s->qspi, sizeof(s->qspi), TYPE_XLNX_ZYNQMP_QSPIPS); 187babc1f30SFrancisco Iglesias qdev_set_parent_bus(DEVICE(&s->qspi), sysbus_get_default()); 188babc1f30SFrancisco Iglesias 189b93dbcddSKONRAD Frederic object_initialize(&s->dp, sizeof(s->dp), TYPE_XLNX_DP); 190b93dbcddSKONRAD Frederic qdev_set_parent_bus(DEVICE(&s->dp), sysbus_get_default()); 191b93dbcddSKONRAD Frederic 192b93dbcddSKONRAD Frederic object_initialize(&s->dpdma, sizeof(s->dpdma), TYPE_XLNX_DPDMA); 193b93dbcddSKONRAD Frederic qdev_set_parent_bus(DEVICE(&s->dpdma), sysbus_get_default()); 1940ab7bbc7SAlistair Francis 1950ab7bbc7SAlistair Francis object_initialize(&s->ipi, sizeof(s->ipi), TYPE_XLNX_ZYNQMP_IPI); 1960ab7bbc7SAlistair Francis qdev_set_parent_bus(DEVICE(&s->ipi), sysbus_get_default()); 19708b2f15eSAlistair Francis 19808b2f15eSAlistair Francis object_initialize(&s->rtc, sizeof(s->rtc), TYPE_XLNX_ZYNQMP_RTC); 19908b2f15eSAlistair Francis qdev_set_parent_bus(DEVICE(&s->rtc), sysbus_get_default()); 200f0a902f7SPeter Crosthwaite } 201f0a902f7SPeter Crosthwaite 202f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) 203f0a902f7SPeter Crosthwaite { 204f0a902f7SPeter Crosthwaite XlnxZynqMPState *s = XLNX_ZYNQMP(dev); 2057729e1f4SPeter Crosthwaite MemoryRegion *system_memory = get_system_memory(); 206f0a902f7SPeter Crosthwaite uint8_t i; 207dc3b89efSAlistair Francis uint64_t ram_size; 2086908ec44SAlistair Francis int num_apus = MIN(smp_cpus, XLNX_ZYNQMP_NUM_APU_CPUS); 2096396a193SPeter Crosthwaite const char *boot_cpu = s->boot_cpu ? s->boot_cpu : "apu-cpu[0]"; 210dc3b89efSAlistair Francis ram_addr_t ddr_low_size, ddr_high_size; 21114ca2e46SPeter Crosthwaite qemu_irq gic_spi[GIC_NUM_SPI_INTR]; 212f0a902f7SPeter Crosthwaite Error *err = NULL; 213f0a902f7SPeter Crosthwaite 214dc3b89efSAlistair Francis ram_size = memory_region_size(s->ddr_ram); 215dc3b89efSAlistair Francis 216dc3b89efSAlistair Francis /* Create the DDR Memory Regions. User friendly checks should happen at 217dc3b89efSAlistair Francis * the board level 218dc3b89efSAlistair Francis */ 219dc3b89efSAlistair Francis if (ram_size > XLNX_ZYNQMP_MAX_LOW_RAM_SIZE) { 220dc3b89efSAlistair Francis /* The RAM size is above the maximum available for the low DDR. 221dc3b89efSAlistair Francis * Create the high DDR memory region as well. 222dc3b89efSAlistair Francis */ 223dc3b89efSAlistair Francis assert(ram_size <= XLNX_ZYNQMP_MAX_RAM_SIZE); 224dc3b89efSAlistair Francis ddr_low_size = XLNX_ZYNQMP_MAX_LOW_RAM_SIZE; 225dc3b89efSAlistair Francis ddr_high_size = ram_size - XLNX_ZYNQMP_MAX_LOW_RAM_SIZE; 226dc3b89efSAlistair Francis 227dc3b89efSAlistair Francis memory_region_init_alias(&s->ddr_ram_high, NULL, 228dc3b89efSAlistair Francis "ddr-ram-high", s->ddr_ram, 229dc3b89efSAlistair Francis ddr_low_size, ddr_high_size); 230dc3b89efSAlistair Francis memory_region_add_subregion(get_system_memory(), 231dc3b89efSAlistair Francis XLNX_ZYNQMP_HIGH_RAM_START, 232dc3b89efSAlistair Francis &s->ddr_ram_high); 233dc3b89efSAlistair Francis } else { 234dc3b89efSAlistair Francis /* RAM must be non-zero */ 235dc3b89efSAlistair Francis assert(ram_size); 236dc3b89efSAlistair Francis ddr_low_size = ram_size; 237dc3b89efSAlistair Francis } 238dc3b89efSAlistair Francis 239dc3b89efSAlistair Francis memory_region_init_alias(&s->ddr_ram_low, NULL, 240dc3b89efSAlistair Francis "ddr-ram-low", s->ddr_ram, 241dc3b89efSAlistair Francis 0, ddr_low_size); 242dc3b89efSAlistair Francis memory_region_add_subregion(get_system_memory(), 0, &s->ddr_ram_low); 243dc3b89efSAlistair Francis 2446675d719SAlistair Francis /* Create the four OCM banks */ 2456675d719SAlistair Francis for (i = 0; i < XLNX_ZYNQMP_NUM_OCM_BANKS; i++) { 2466675d719SAlistair Francis char *ocm_name = g_strdup_printf("zynqmp.ocm_ram_bank_%d", i); 2476675d719SAlistair Francis 24898a99ce0SPeter Maydell memory_region_init_ram(&s->ocm_ram[i], NULL, ocm_name, 249f8ed85acSMarkus Armbruster XLNX_ZYNQMP_OCM_RAM_SIZE, &error_fatal); 2506675d719SAlistair Francis memory_region_add_subregion(get_system_memory(), 2516675d719SAlistair Francis XLNX_ZYNQMP_OCM_RAM_0_ADDRESS + 2526675d719SAlistair Francis i * XLNX_ZYNQMP_OCM_RAM_SIZE, 2536675d719SAlistair Francis &s->ocm_ram[i]); 2546675d719SAlistair Francis 2556675d719SAlistair Francis g_free(ocm_name); 2566675d719SAlistair Francis } 2576675d719SAlistair Francis 2587729e1f4SPeter Crosthwaite qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", GIC_NUM_SPI_INTR + 32); 2597729e1f4SPeter Crosthwaite qdev_prop_set_uint32(DEVICE(&s->gic), "revision", 2); 2606908ec44SAlistair Francis qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", num_apus); 2617729e1f4SPeter Crosthwaite 2620776d967SEdgar E. Iglesias /* Realize APUs before realizing the GIC. KVM requires this. */ 2636908ec44SAlistair Francis for (i = 0; i < num_apus; i++) { 2646396a193SPeter Crosthwaite char *name; 265bf4cb109SPeter Crosthwaite 2662e5577bcSPeter Crosthwaite object_property_set_int(OBJECT(&s->apu_cpu[i]), QEMU_PSCI_CONDUIT_SMC, 267f0a902f7SPeter Crosthwaite "psci-conduit", &error_abort); 2686396a193SPeter Crosthwaite 2696396a193SPeter Crosthwaite name = object_get_canonical_path_component(OBJECT(&s->apu_cpu[i])); 2706396a193SPeter Crosthwaite if (strcmp(name, boot_cpu)) { 271f0a902f7SPeter Crosthwaite /* Secondary CPUs start in PSCI powered-down state */ 2722e5577bcSPeter Crosthwaite object_property_set_bool(OBJECT(&s->apu_cpu[i]), true, 273f0a902f7SPeter Crosthwaite "start-powered-off", &error_abort); 2746396a193SPeter Crosthwaite } else { 2756396a193SPeter Crosthwaite s->boot_cpu_ptr = &s->apu_cpu[i]; 276f0a902f7SPeter Crosthwaite } 2775348c62cSGonglei g_free(name); 278f0a902f7SPeter Crosthwaite 27937d42473SEdgar E. Iglesias object_property_set_bool(OBJECT(&s->apu_cpu[i]), 28037d42473SEdgar E. Iglesias s->secure, "has_el3", NULL); 281c25bd18aSPeter Maydell object_property_set_bool(OBJECT(&s->apu_cpu[i]), 2821946809eSAlistair Francis s->virt, "has_el2", NULL); 2832e5577bcSPeter Crosthwaite object_property_set_int(OBJECT(&s->apu_cpu[i]), GIC_BASE_ADDR, 284e1292517SAlistair Francis "reset-cbar", &error_abort); 2858f2ba1f2SAlistair Francis object_property_set_int(OBJECT(&s->apu_cpu[i]), num_apus, 2868f2ba1f2SAlistair Francis "core-count", &error_abort); 2872e5577bcSPeter Crosthwaite object_property_set_bool(OBJECT(&s->apu_cpu[i]), true, "realized", 2882e5577bcSPeter Crosthwaite &err); 289f0a902f7SPeter Crosthwaite if (err) { 29024cfc8dcSAlistair Francis error_propagate(errp, err); 291f0a902f7SPeter Crosthwaite return; 292f0a902f7SPeter Crosthwaite } 2930776d967SEdgar E. Iglesias } 2940776d967SEdgar E. Iglesias 2950776d967SEdgar E. Iglesias object_property_set_bool(OBJECT(&s->gic), true, "realized", &err); 2960776d967SEdgar E. Iglesias if (err) { 2970776d967SEdgar E. Iglesias error_propagate(errp, err); 2980776d967SEdgar E. Iglesias return; 2990776d967SEdgar E. Iglesias } 3000776d967SEdgar E. Iglesias 3010776d967SEdgar E. Iglesias assert(ARRAY_SIZE(xlnx_zynqmp_gic_regions) == XLNX_ZYNQMP_GIC_REGIONS); 3020776d967SEdgar E. Iglesias for (i = 0; i < XLNX_ZYNQMP_GIC_REGIONS; i++) { 3030776d967SEdgar E. Iglesias SysBusDevice *gic = SYS_BUS_DEVICE(&s->gic); 3040776d967SEdgar E. Iglesias const XlnxZynqMPGICRegion *r = &xlnx_zynqmp_gic_regions[i]; 3050776d967SEdgar E. Iglesias MemoryRegion *mr = sysbus_mmio_get_region(gic, r->region_index); 3060776d967SEdgar E. Iglesias uint32_t addr = r->address; 3070776d967SEdgar E. Iglesias int j; 3080776d967SEdgar E. Iglesias 3090776d967SEdgar E. Iglesias sysbus_mmio_map(gic, r->region_index, addr); 3100776d967SEdgar E. Iglesias 3110776d967SEdgar E. Iglesias for (j = 0; j < XLNX_ZYNQMP_GIC_ALIASES; j++) { 3120776d967SEdgar E. Iglesias MemoryRegion *alias = &s->gic_mr[i][j]; 3130776d967SEdgar E. Iglesias 3140776d967SEdgar E. Iglesias addr += XLNX_ZYNQMP_GIC_REGION_SIZE; 3150776d967SEdgar E. Iglesias memory_region_init_alias(alias, OBJECT(s), "zynqmp-gic-alias", mr, 3160776d967SEdgar E. Iglesias 0, XLNX_ZYNQMP_GIC_REGION_SIZE); 3170776d967SEdgar E. Iglesias memory_region_add_subregion(system_memory, addr, alias); 3180776d967SEdgar E. Iglesias } 3190776d967SEdgar E. Iglesias } 3200776d967SEdgar E. Iglesias 3216908ec44SAlistair Francis for (i = 0; i < num_apus; i++) { 3220776d967SEdgar E. Iglesias qemu_irq irq; 3237729e1f4SPeter Crosthwaite 3247729e1f4SPeter Crosthwaite sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i, 3252e5577bcSPeter Crosthwaite qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]), 3262e5577bcSPeter Crosthwaite ARM_CPU_IRQ)); 327bf4cb109SPeter Crosthwaite irq = qdev_get_gpio_in(DEVICE(&s->gic), 328bf4cb109SPeter Crosthwaite arm_gic_ppi_index(i, ARM_PHYS_TIMER_PPI)); 3292e5577bcSPeter Crosthwaite qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), 0, irq); 330bf4cb109SPeter Crosthwaite irq = qdev_get_gpio_in(DEVICE(&s->gic), 331bf4cb109SPeter Crosthwaite arm_gic_ppi_index(i, ARM_VIRT_TIMER_PPI)); 3322e5577bcSPeter Crosthwaite qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), 1, irq); 333f0a902f7SPeter Crosthwaite } 33414ca2e46SPeter Crosthwaite 3356ed92b14SEdgar E. Iglesias if (s->has_rpu) { 3366908ec44SAlistair Francis info_report("The 'has_rpu' property is no longer required, to use the " 3376908ec44SAlistair Francis "RPUs just use -smp 6."); 3386908ec44SAlistair Francis } 3396908ec44SAlistair Francis 3406ed92b14SEdgar E. Iglesias xlnx_zynqmp_create_rpu(s, boot_cpu, &err); 341b58850e7SPeter Crosthwaite if (err) { 34224cfc8dcSAlistair Francis error_propagate(errp, err); 343b58850e7SPeter Crosthwaite return; 344b58850e7SPeter Crosthwaite } 345b58850e7SPeter Crosthwaite 3466396a193SPeter Crosthwaite if (!s->boot_cpu_ptr) { 3479af9e0feSMarkus Armbruster error_setg(errp, "ZynqMP Boot cpu %s not found", boot_cpu); 3486396a193SPeter Crosthwaite return; 3496396a193SPeter Crosthwaite } 3506396a193SPeter Crosthwaite 35114ca2e46SPeter Crosthwaite for (i = 0; i < GIC_NUM_SPI_INTR; i++) { 35214ca2e46SPeter Crosthwaite gic_spi[i] = qdev_get_gpio_in(DEVICE(&s->gic), i); 35314ca2e46SPeter Crosthwaite } 35414ca2e46SPeter Crosthwaite 35514ca2e46SPeter Crosthwaite for (i = 0; i < XLNX_ZYNQMP_NUM_GEMS; i++) { 35614ca2e46SPeter Crosthwaite NICInfo *nd = &nd_table[i]; 35714ca2e46SPeter Crosthwaite 35814ca2e46SPeter Crosthwaite if (nd->used) { 35914ca2e46SPeter Crosthwaite qemu_check_nic_model(nd, TYPE_CADENCE_GEM); 36014ca2e46SPeter Crosthwaite qdev_set_nic_properties(DEVICE(&s->gem[i]), nd); 36114ca2e46SPeter Crosthwaite } 36220bff213SAlistair Francis object_property_set_int(OBJECT(&s->gem[i]), GEM_REVISION, "revision", 36320bff213SAlistair Francis &error_abort); 3641372fc0bSAlistair Francis object_property_set_int(OBJECT(&s->gem[i]), 2, "num-priority-queues", 3651372fc0bSAlistair Francis &error_abort); 36614ca2e46SPeter Crosthwaite object_property_set_bool(OBJECT(&s->gem[i]), true, "realized", &err); 36714ca2e46SPeter Crosthwaite if (err) { 36824cfc8dcSAlistair Francis error_propagate(errp, err); 36914ca2e46SPeter Crosthwaite return; 37014ca2e46SPeter Crosthwaite } 37114ca2e46SPeter Crosthwaite sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem[i]), 0, gem_addr[i]); 37214ca2e46SPeter Crosthwaite sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem[i]), 0, 37314ca2e46SPeter Crosthwaite gic_spi[gem_intr[i]]); 37414ca2e46SPeter Crosthwaite } 3753bade2a9SPeter Crosthwaite 3763bade2a9SPeter Crosthwaite for (i = 0; i < XLNX_ZYNQMP_NUM_UARTS; i++) { 377*9bca0edbSPeter Maydell qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i)); 3783bade2a9SPeter Crosthwaite object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err); 3793bade2a9SPeter Crosthwaite if (err) { 38024cfc8dcSAlistair Francis error_propagate(errp, err); 3813bade2a9SPeter Crosthwaite return; 3823bade2a9SPeter Crosthwaite } 3833bade2a9SPeter Crosthwaite sysbus_mmio_map(SYS_BUS_DEVICE(&s->uart[i]), 0, uart_addr[i]); 3843bade2a9SPeter Crosthwaite sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart[i]), 0, 3853bade2a9SPeter Crosthwaite gic_spi[uart_intr[i]]); 3863bade2a9SPeter Crosthwaite } 3876fdf3282SAlistair Francis 3886fdf3282SAlistair Francis object_property_set_int(OBJECT(&s->sata), SATA_NUM_PORTS, "num-ports", 3896fdf3282SAlistair Francis &error_abort); 3906fdf3282SAlistair Francis object_property_set_bool(OBJECT(&s->sata), true, "realized", &err); 3916fdf3282SAlistair Francis if (err) { 3926fdf3282SAlistair Francis error_propagate(errp, err); 3936fdf3282SAlistair Francis return; 3946fdf3282SAlistair Francis } 3956fdf3282SAlistair Francis 3966fdf3282SAlistair Francis sysbus_mmio_map(SYS_BUS_DEVICE(&s->sata), 0, SATA_ADDR); 3976fdf3282SAlistair Francis sysbus_connect_irq(SYS_BUS_DEVICE(&s->sata), 0, gic_spi[SATA_INTR]); 39833108e9fSSai Pavan Boddu 39933108e9fSSai Pavan Boddu for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) { 400b630d3d4SPhilippe Mathieu-Daudé char *bus_name = g_strdup_printf("sd-bus%d", i); 401b630d3d4SPhilippe Mathieu-Daudé SysBusDevice *sbd = SYS_BUS_DEVICE(&s->sdhci[i]); 402b630d3d4SPhilippe Mathieu-Daudé Object *sdhci = OBJECT(&s->sdhci[i]); 403eb4f566bSPeter Maydell 404b630d3d4SPhilippe Mathieu-Daudé /* Compatible with: 405b630d3d4SPhilippe Mathieu-Daudé * - SD Host Controller Specification Version 3.00 406b630d3d4SPhilippe Mathieu-Daudé * - SDIO Specification Version 3.0 407b630d3d4SPhilippe Mathieu-Daudé * - eMMC Specification Version 4.51 408b630d3d4SPhilippe Mathieu-Daudé */ 409b630d3d4SPhilippe Mathieu-Daudé object_property_set_uint(sdhci, 3, "sd-spec-version", &err); 410b630d3d4SPhilippe Mathieu-Daudé object_property_set_uint(sdhci, SDHCI_CAPABILITIES, "capareg", &err); 411a01c6554SPhilippe Mathieu-Daudé object_property_set_uint(sdhci, UHS_I, "uhs", &err); 412b630d3d4SPhilippe Mathieu-Daudé object_property_set_bool(sdhci, true, "realized", &err); 41333108e9fSSai Pavan Boddu if (err) { 41433108e9fSSai Pavan Boddu error_propagate(errp, err); 41533108e9fSSai Pavan Boddu return; 41633108e9fSSai Pavan Boddu } 417b630d3d4SPhilippe Mathieu-Daudé sysbus_mmio_map(sbd, 0, sdhci_addr[i]); 418b630d3d4SPhilippe Mathieu-Daudé sysbus_connect_irq(sbd, 0, gic_spi[sdhci_intr[i]]); 419b630d3d4SPhilippe Mathieu-Daudé 420eb4f566bSPeter Maydell /* Alias controller SD bus to the SoC itself */ 421b630d3d4SPhilippe Mathieu-Daudé object_property_add_alias(OBJECT(s), bus_name, sdhci, "sd-bus", 422eb4f566bSPeter Maydell &error_abort); 423eb4f566bSPeter Maydell g_free(bus_name); 42433108e9fSSai Pavan Boddu } 42502d07eb4SAlistair Francis 42602d07eb4SAlistair Francis for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) { 42702d07eb4SAlistair Francis gchar *bus_name; 42802d07eb4SAlistair Francis 42902d07eb4SAlistair Francis object_property_set_bool(OBJECT(&s->spi[i]), true, "realized", &err); 43002d07eb4SAlistair Francis 43102d07eb4SAlistair Francis sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0, spi_addr[i]); 43202d07eb4SAlistair Francis sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi[i]), 0, 43302d07eb4SAlistair Francis gic_spi[spi_intr[i]]); 43402d07eb4SAlistair Francis 43502d07eb4SAlistair Francis /* Alias controller SPI bus to the SoC itself */ 43602d07eb4SAlistair Francis bus_name = g_strdup_printf("spi%d", i); 43702d07eb4SAlistair Francis object_property_add_alias(OBJECT(s), bus_name, 43802d07eb4SAlistair Francis OBJECT(&s->spi[i]), "spi0", 43902d07eb4SAlistair Francis &error_abort); 44002d07eb4SAlistair Francis g_free(bus_name); 44102d07eb4SAlistair Francis } 442b93dbcddSKONRAD Frederic 443babc1f30SFrancisco Iglesias object_property_set_bool(OBJECT(&s->qspi), true, "realized", &err); 444babc1f30SFrancisco Iglesias sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi), 0, QSPI_ADDR); 445babc1f30SFrancisco Iglesias sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi), 1, LQSPI_ADDR); 446babc1f30SFrancisco Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(&s->qspi), 0, gic_spi[QSPI_IRQ]); 447babc1f30SFrancisco Iglesias 448babc1f30SFrancisco Iglesias for (i = 0; i < XLNX_ZYNQMP_NUM_QSPI_BUS; i++) { 449babc1f30SFrancisco Iglesias gchar *bus_name; 450babc1f30SFrancisco Iglesias gchar *target_bus; 451babc1f30SFrancisco Iglesias 452babc1f30SFrancisco Iglesias /* Alias controller SPI bus to the SoC itself */ 453babc1f30SFrancisco Iglesias bus_name = g_strdup_printf("qspi%d", i); 454babc1f30SFrancisco Iglesias target_bus = g_strdup_printf("spi%d", i); 455babc1f30SFrancisco Iglesias object_property_add_alias(OBJECT(s), bus_name, 456babc1f30SFrancisco Iglesias OBJECT(&s->qspi), target_bus, 457babc1f30SFrancisco Iglesias &error_abort); 458babc1f30SFrancisco Iglesias g_free(bus_name); 459babc1f30SFrancisco Iglesias g_free(target_bus); 460babc1f30SFrancisco Iglesias } 461babc1f30SFrancisco Iglesias 462b93dbcddSKONRAD Frederic object_property_set_bool(OBJECT(&s->dp), true, "realized", &err); 463b93dbcddSKONRAD Frederic if (err) { 464b93dbcddSKONRAD Frederic error_propagate(errp, err); 465b93dbcddSKONRAD Frederic return; 466b93dbcddSKONRAD Frederic } 467b93dbcddSKONRAD Frederic sysbus_mmio_map(SYS_BUS_DEVICE(&s->dp), 0, DP_ADDR); 468b93dbcddSKONRAD Frederic sysbus_connect_irq(SYS_BUS_DEVICE(&s->dp), 0, gic_spi[DP_IRQ]); 469b93dbcddSKONRAD Frederic 470b93dbcddSKONRAD Frederic object_property_set_bool(OBJECT(&s->dpdma), true, "realized", &err); 471b93dbcddSKONRAD Frederic if (err) { 472b93dbcddSKONRAD Frederic error_propagate(errp, err); 473b93dbcddSKONRAD Frederic return; 474b93dbcddSKONRAD Frederic } 475b93dbcddSKONRAD Frederic object_property_set_link(OBJECT(&s->dp), OBJECT(&s->dpdma), "dpdma", 476b93dbcddSKONRAD Frederic &error_abort); 477b93dbcddSKONRAD Frederic sysbus_mmio_map(SYS_BUS_DEVICE(&s->dpdma), 0, DPDMA_ADDR); 478b93dbcddSKONRAD Frederic sysbus_connect_irq(SYS_BUS_DEVICE(&s->dpdma), 0, gic_spi[DPDMA_IRQ]); 4790ab7bbc7SAlistair Francis 4800ab7bbc7SAlistair Francis object_property_set_bool(OBJECT(&s->ipi), true, "realized", &err); 4810ab7bbc7SAlistair Francis if (err) { 4820ab7bbc7SAlistair Francis error_propagate(errp, err); 4830ab7bbc7SAlistair Francis return; 4840ab7bbc7SAlistair Francis } 4850ab7bbc7SAlistair Francis sysbus_mmio_map(SYS_BUS_DEVICE(&s->ipi), 0, IPI_ADDR); 4860ab7bbc7SAlistair Francis sysbus_connect_irq(SYS_BUS_DEVICE(&s->ipi), 0, gic_spi[IPI_IRQ]); 48708b2f15eSAlistair Francis 48808b2f15eSAlistair Francis object_property_set_bool(OBJECT(&s->rtc), true, "realized", &err); 48908b2f15eSAlistair Francis if (err) { 49008b2f15eSAlistair Francis error_propagate(errp, err); 49108b2f15eSAlistair Francis return; 49208b2f15eSAlistair Francis } 49308b2f15eSAlistair Francis sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, RTC_ADDR); 49408b2f15eSAlistair Francis sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0, gic_spi[RTC_IRQ]); 495f0a902f7SPeter Crosthwaite } 496f0a902f7SPeter Crosthwaite 4976396a193SPeter Crosthwaite static Property xlnx_zynqmp_props[] = { 4986396a193SPeter Crosthwaite DEFINE_PROP_STRING("boot-cpu", XlnxZynqMPState, boot_cpu), 49937d42473SEdgar E. Iglesias DEFINE_PROP_BOOL("secure", XlnxZynqMPState, secure, false), 5001946809eSAlistair Francis DEFINE_PROP_BOOL("virtualization", XlnxZynqMPState, virt, false), 5016ed92b14SEdgar E. Iglesias DEFINE_PROP_BOOL("has_rpu", XlnxZynqMPState, has_rpu, false), 502c3acfa01SFam Zheng DEFINE_PROP_LINK("ddr-ram", XlnxZynqMPState, ddr_ram, TYPE_MEMORY_REGION, 503c3acfa01SFam Zheng MemoryRegion *), 5046396a193SPeter Crosthwaite DEFINE_PROP_END_OF_LIST() 5056396a193SPeter Crosthwaite }; 5066396a193SPeter Crosthwaite 507f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_class_init(ObjectClass *oc, void *data) 508f0a902f7SPeter Crosthwaite { 509f0a902f7SPeter Crosthwaite DeviceClass *dc = DEVICE_CLASS(oc); 510f0a902f7SPeter Crosthwaite 5116396a193SPeter Crosthwaite dc->props = xlnx_zynqmp_props; 512f0a902f7SPeter Crosthwaite dc->realize = xlnx_zynqmp_realize; 513d8589144SThomas Huth /* Reason: Uses serial_hds in realize function, thus can't be used twice */ 514d8589144SThomas Huth dc->user_creatable = false; 515f0a902f7SPeter Crosthwaite } 516f0a902f7SPeter Crosthwaite 517f0a902f7SPeter Crosthwaite static const TypeInfo xlnx_zynqmp_type_info = { 518f0a902f7SPeter Crosthwaite .name = TYPE_XLNX_ZYNQMP, 519f0a902f7SPeter Crosthwaite .parent = TYPE_DEVICE, 520f0a902f7SPeter Crosthwaite .instance_size = sizeof(XlnxZynqMPState), 521f0a902f7SPeter Crosthwaite .instance_init = xlnx_zynqmp_init, 522f0a902f7SPeter Crosthwaite .class_init = xlnx_zynqmp_class_init, 523f0a902f7SPeter Crosthwaite }; 524f0a902f7SPeter Crosthwaite 525f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_register_types(void) 526f0a902f7SPeter Crosthwaite { 527f0a902f7SPeter Crosthwaite type_register_static(&xlnx_zynqmp_type_info); 528f0a902f7SPeter Crosthwaite } 529f0a902f7SPeter Crosthwaite 530f0a902f7SPeter Crosthwaite type_init(xlnx_zynqmp_register_types) 531