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" 200b8fa32fSMarkus Armbruster #include "qemu/module.h" 21f0a902f7SPeter Crosthwaite #include "hw/arm/xlnx-zynqmp.h" 22bf4cb109SPeter Crosthwaite #include "hw/intc/arm_gic_common.h" 23d2e6f370STong Ho #include "hw/misc/unimp.h" 24cc7d44c2SLike Xu #include "hw/boards.h" 252a0ee672SEdgar E. Iglesias #include "sysemu/kvm.h" 265a720b1eSMarkus Armbruster #include "sysemu/sysemu.h" 272a0ee672SEdgar E. Iglesias #include "kvm_arm.h" 287729e1f4SPeter Crosthwaite 297729e1f4SPeter Crosthwaite #define GIC_NUM_SPI_INTR 160 307729e1f4SPeter Crosthwaite 31bf4cb109SPeter Crosthwaite #define ARM_PHYS_TIMER_PPI 30 32bf4cb109SPeter Crosthwaite #define ARM_VIRT_TIMER_PPI 27 3375b749afSLuc Michel #define ARM_HYP_TIMER_PPI 26 3475b749afSLuc Michel #define ARM_SEC_TIMER_PPI 29 3575b749afSLuc Michel #define GIC_MAINTENANCE_PPI 25 36bf4cb109SPeter Crosthwaite 3720bff213SAlistair Francis #define GEM_REVISION 0x40070106 3820bff213SAlistair Francis 397729e1f4SPeter Crosthwaite #define GIC_BASE_ADDR 0xf9000000 407729e1f4SPeter Crosthwaite #define GIC_DIST_ADDR 0xf9010000 417729e1f4SPeter Crosthwaite #define GIC_CPU_ADDR 0xf9020000 4275b749afSLuc Michel #define GIC_VIFACE_ADDR 0xf9040000 4375b749afSLuc Michel #define GIC_VCPU_ADDR 0xf9060000 447729e1f4SPeter Crosthwaite 456fdf3282SAlistair Francis #define SATA_INTR 133 466fdf3282SAlistair Francis #define SATA_ADDR 0xFD0C0000 476fdf3282SAlistair Francis #define SATA_NUM_PORTS 2 486fdf3282SAlistair Francis 49babc1f30SFrancisco Iglesias #define QSPI_ADDR 0xff0f0000 50babc1f30SFrancisco Iglesias #define LQSPI_ADDR 0xc0000000 51babc1f30SFrancisco Iglesias #define QSPI_IRQ 15 52668351a5SXuzhou Cheng #define QSPI_DMA_ADDR 0xff0f0800 53c74ccb5dSFrancisco Iglesias #define NUM_QSPI_IRQ_LINES 2 54babc1f30SFrancisco Iglesias 55b93dbcddSKONRAD Frederic #define DP_ADDR 0xfd4a0000 56b93dbcddSKONRAD Frederic #define DP_IRQ 113 57b93dbcddSKONRAD Frederic 58b93dbcddSKONRAD Frederic #define DPDMA_ADDR 0xfd4c0000 59b93dbcddSKONRAD Frederic #define DPDMA_IRQ 116 60b93dbcddSKONRAD Frederic 61d2e6f370STong Ho #define APU_ADDR 0xfd5c0000 62d2e6f370STong Ho #define APU_SIZE 0x100 63d2e6f370STong Ho 640ab7bbc7SAlistair Francis #define IPI_ADDR 0xFF300000 650ab7bbc7SAlistair Francis #define IPI_IRQ 64 660ab7bbc7SAlistair Francis 6708b2f15eSAlistair Francis #define RTC_ADDR 0xffa60000 6808b2f15eSAlistair Francis #define RTC_IRQ 26 6908b2f15eSAlistair Francis 707e47e15cSTong Ho #define BBRAM_ADDR 0xffcd0000 717e47e15cSTong Ho #define BBRAM_IRQ 11 727e47e15cSTong Ho 73db1264dfSTong Ho #define EFUSE_ADDR 0xffcc0000 74db1264dfSTong Ho #define EFUSE_IRQ 87 75db1264dfSTong Ho 76b630d3d4SPhilippe Mathieu-Daudé #define SDHCI_CAPABILITIES 0x280737ec6481 /* Datasheet: UG1085 (v1.7) */ 77b630d3d4SPhilippe Mathieu-Daudé 7814ca2e46SPeter Crosthwaite static const uint64_t gem_addr[XLNX_ZYNQMP_NUM_GEMS] = { 7914ca2e46SPeter Crosthwaite 0xFF0B0000, 0xFF0C0000, 0xFF0D0000, 0xFF0E0000, 8014ca2e46SPeter Crosthwaite }; 8114ca2e46SPeter Crosthwaite 8214ca2e46SPeter Crosthwaite static const int gem_intr[XLNX_ZYNQMP_NUM_GEMS] = { 8314ca2e46SPeter Crosthwaite 57, 59, 61, 63, 8414ca2e46SPeter Crosthwaite }; 8514ca2e46SPeter Crosthwaite 863bade2a9SPeter Crosthwaite static const uint64_t uart_addr[XLNX_ZYNQMP_NUM_UARTS] = { 873bade2a9SPeter Crosthwaite 0xFF000000, 0xFF010000, 883bade2a9SPeter Crosthwaite }; 893bade2a9SPeter Crosthwaite 903bade2a9SPeter Crosthwaite static const int uart_intr[XLNX_ZYNQMP_NUM_UARTS] = { 913bade2a9SPeter Crosthwaite 21, 22, 923bade2a9SPeter Crosthwaite }; 933bade2a9SPeter Crosthwaite 94840c22cdSVikram Garhwal static const uint64_t can_addr[XLNX_ZYNQMP_NUM_CAN] = { 95840c22cdSVikram Garhwal 0xFF060000, 0xFF070000, 96840c22cdSVikram Garhwal }; 97840c22cdSVikram Garhwal 98840c22cdSVikram Garhwal static const int can_intr[XLNX_ZYNQMP_NUM_CAN] = { 99840c22cdSVikram Garhwal 23, 24, 100840c22cdSVikram Garhwal }; 101840c22cdSVikram Garhwal 10233108e9fSSai Pavan Boddu static const uint64_t sdhci_addr[XLNX_ZYNQMP_NUM_SDHCI] = { 10333108e9fSSai Pavan Boddu 0xFF160000, 0xFF170000, 10433108e9fSSai Pavan Boddu }; 10533108e9fSSai Pavan Boddu 10633108e9fSSai Pavan Boddu static const int sdhci_intr[XLNX_ZYNQMP_NUM_SDHCI] = { 10733108e9fSSai Pavan Boddu 48, 49, 10833108e9fSSai Pavan Boddu }; 10933108e9fSSai Pavan Boddu 11002d07eb4SAlistair Francis static const uint64_t spi_addr[XLNX_ZYNQMP_NUM_SPIS] = { 11102d07eb4SAlistair Francis 0xFF040000, 0xFF050000, 11202d07eb4SAlistair Francis }; 11302d07eb4SAlistair Francis 11402d07eb4SAlistair Francis static const int spi_intr[XLNX_ZYNQMP_NUM_SPIS] = { 11502d07eb4SAlistair Francis 19, 20, 11602d07eb4SAlistair Francis }; 11702d07eb4SAlistair Francis 11804965bcaSFrancisco Iglesias static const uint64_t gdma_ch_addr[XLNX_ZYNQMP_NUM_GDMA_CH] = { 11904965bcaSFrancisco Iglesias 0xFD500000, 0xFD510000, 0xFD520000, 0xFD530000, 12004965bcaSFrancisco Iglesias 0xFD540000, 0xFD550000, 0xFD560000, 0xFD570000 12104965bcaSFrancisco Iglesias }; 12204965bcaSFrancisco Iglesias 12304965bcaSFrancisco Iglesias static const int gdma_ch_intr[XLNX_ZYNQMP_NUM_GDMA_CH] = { 12404965bcaSFrancisco Iglesias 124, 125, 126, 127, 128, 129, 130, 131 12504965bcaSFrancisco Iglesias }; 12604965bcaSFrancisco Iglesias 12704965bcaSFrancisco Iglesias static const uint64_t adma_ch_addr[XLNX_ZYNQMP_NUM_ADMA_CH] = { 12804965bcaSFrancisco Iglesias 0xFFA80000, 0xFFA90000, 0xFFAA0000, 0xFFAB0000, 12904965bcaSFrancisco Iglesias 0xFFAC0000, 0xFFAD0000, 0xFFAE0000, 0xFFAF0000 13004965bcaSFrancisco Iglesias }; 13104965bcaSFrancisco Iglesias 13204965bcaSFrancisco Iglesias static const int adma_ch_intr[XLNX_ZYNQMP_NUM_ADMA_CH] = { 13304965bcaSFrancisco Iglesias 77, 78, 79, 80, 81, 82, 83, 84 13404965bcaSFrancisco Iglesias }; 13504965bcaSFrancisco Iglesias 1367729e1f4SPeter Crosthwaite typedef struct XlnxZynqMPGICRegion { 1377729e1f4SPeter Crosthwaite int region_index; 1387729e1f4SPeter Crosthwaite uint32_t address; 13975b749afSLuc Michel uint32_t offset; 14075b749afSLuc Michel bool virt; 1417729e1f4SPeter Crosthwaite } XlnxZynqMPGICRegion; 1427729e1f4SPeter Crosthwaite 1437729e1f4SPeter Crosthwaite static const XlnxZynqMPGICRegion xlnx_zynqmp_gic_regions[] = { 14475b749afSLuc Michel /* Distributor */ 14575b749afSLuc Michel { 14675b749afSLuc Michel .region_index = 0, 14775b749afSLuc Michel .address = GIC_DIST_ADDR, 14875b749afSLuc Michel .offset = 0, 14975b749afSLuc Michel .virt = false 15075b749afSLuc Michel }, 15175b749afSLuc Michel 15275b749afSLuc Michel /* CPU interface */ 15375b749afSLuc Michel { 15475b749afSLuc Michel .region_index = 1, 15575b749afSLuc Michel .address = GIC_CPU_ADDR, 15675b749afSLuc Michel .offset = 0, 15775b749afSLuc Michel .virt = false 15875b749afSLuc Michel }, 15975b749afSLuc Michel { 16075b749afSLuc Michel .region_index = 1, 16175b749afSLuc Michel .address = GIC_CPU_ADDR + 0x10000, 16275b749afSLuc Michel .offset = 0x1000, 16375b749afSLuc Michel .virt = false 16475b749afSLuc Michel }, 16575b749afSLuc Michel 16675b749afSLuc Michel /* Virtual interface */ 16775b749afSLuc Michel { 16875b749afSLuc Michel .region_index = 2, 16975b749afSLuc Michel .address = GIC_VIFACE_ADDR, 17075b749afSLuc Michel .offset = 0, 17175b749afSLuc Michel .virt = true 17275b749afSLuc Michel }, 17375b749afSLuc Michel 17475b749afSLuc Michel /* Virtual CPU interface */ 17575b749afSLuc Michel { 17675b749afSLuc Michel .region_index = 3, 17775b749afSLuc Michel .address = GIC_VCPU_ADDR, 17875b749afSLuc Michel .offset = 0, 17975b749afSLuc Michel .virt = true 18075b749afSLuc Michel }, 18175b749afSLuc Michel { 18275b749afSLuc Michel .region_index = 3, 18375b749afSLuc Michel .address = GIC_VCPU_ADDR + 0x10000, 18475b749afSLuc Michel .offset = 0x1000, 18575b749afSLuc Michel .virt = true 18675b749afSLuc Michel }, 1877729e1f4SPeter Crosthwaite }; 188f0a902f7SPeter Crosthwaite 189bf4cb109SPeter Crosthwaite static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index) 190bf4cb109SPeter Crosthwaite { 191bf4cb109SPeter Crosthwaite return GIC_NUM_SPI_INTR + cpu_nr * GIC_INTERNAL + ppi_index; 192bf4cb109SPeter Crosthwaite } 193bf4cb109SPeter Crosthwaite 194cc7d44c2SLike Xu static void xlnx_zynqmp_create_rpu(MachineState *ms, XlnxZynqMPState *s, 195cc7d44c2SLike Xu const char *boot_cpu, Error **errp) 1966ed92b14SEdgar E. Iglesias { 1976ed92b14SEdgar E. Iglesias int i; 198cc7d44c2SLike Xu int num_rpus = MIN(ms->smp.cpus - XLNX_ZYNQMP_NUM_APU_CPUS, 199cc7d44c2SLike Xu XLNX_ZYNQMP_NUM_RPU_CPUS); 2006ed92b14SEdgar E. Iglesias 201e5b51753SPeter Maydell if (num_rpus <= 0) { 202e5b51753SPeter Maydell /* Don't create rpu-cluster object if there's nothing to put in it */ 203e5b51753SPeter Maydell return; 204e5b51753SPeter Maydell } 205e5b51753SPeter Maydell 206816fd397SLuc Michel object_initialize_child(OBJECT(s), "rpu-cluster", &s->rpu_cluster, 2079fc7fc4dSMarkus Armbruster TYPE_CPU_CLUSTER); 208816fd397SLuc Michel qdev_prop_set_uint32(DEVICE(&s->rpu_cluster), "cluster-id", 1); 209816fd397SLuc Michel 2106908ec44SAlistair Francis for (i = 0; i < num_rpus; i++) { 2117a309cc9SMarkus Armbruster const char *name; 2126ed92b14SEdgar E. Iglesias 213d0313798SPhilippe Mathieu-Daudé object_initialize_child(OBJECT(&s->rpu_cluster), "rpu-cpu[*]", 2149fc7fc4dSMarkus Armbruster &s->rpu_cpu[i], 2159fc7fc4dSMarkus Armbruster ARM_CPU_TYPE_NAME("cortex-r5f")); 2166ed92b14SEdgar E. Iglesias 2176ed92b14SEdgar E. Iglesias name = object_get_canonical_path_component(OBJECT(&s->rpu_cpu[i])); 2186ed92b14SEdgar E. Iglesias if (strcmp(name, boot_cpu)) { 219*50c785f2SPeter Maydell /* 220*50c785f2SPeter Maydell * Secondary CPUs start in powered-down state. 221*50c785f2SPeter Maydell */ 2225325cc34SMarkus Armbruster object_property_set_bool(OBJECT(&s->rpu_cpu[i]), 2235325cc34SMarkus Armbruster "start-powered-off", true, &error_abort); 2246ed92b14SEdgar E. Iglesias } else { 2256ed92b14SEdgar E. Iglesias s->boot_cpu_ptr = &s->rpu_cpu[i]; 2266ed92b14SEdgar E. Iglesias } 2276ed92b14SEdgar E. Iglesias 2285325cc34SMarkus Armbruster object_property_set_bool(OBJECT(&s->rpu_cpu[i]), "reset-hivecs", true, 2296ed92b14SEdgar E. Iglesias &error_abort); 230668f62ecSMarkus Armbruster if (!qdev_realize(DEVICE(&s->rpu_cpu[i]), NULL, errp)) { 2316ed92b14SEdgar E. Iglesias return; 2326ed92b14SEdgar E. Iglesias } 2336ed92b14SEdgar E. Iglesias } 234fa434424SPeter Maydell 235ce189ab2SMarkus Armbruster qdev_realize(DEVICE(&s->rpu_cluster), NULL, &error_fatal); 2366ed92b14SEdgar E. Iglesias } 2376ed92b14SEdgar E. Iglesias 2387e47e15cSTong Ho static void xlnx_zynqmp_create_bbram(XlnxZynqMPState *s, qemu_irq *gic) 2397e47e15cSTong Ho { 2407e47e15cSTong Ho SysBusDevice *sbd; 2417e47e15cSTong Ho 2427e47e15cSTong Ho object_initialize_child_with_props(OBJECT(s), "bbram", &s->bbram, 2437e47e15cSTong Ho sizeof(s->bbram), TYPE_XLNX_BBRAM, 2447e47e15cSTong Ho &error_fatal, 2457e47e15cSTong Ho "crc-zpads", "1", 2467e47e15cSTong Ho NULL); 2477e47e15cSTong Ho sbd = SYS_BUS_DEVICE(&s->bbram); 2487e47e15cSTong Ho 2497e47e15cSTong Ho sysbus_realize(sbd, &error_fatal); 2507e47e15cSTong Ho sysbus_mmio_map(sbd, 0, BBRAM_ADDR); 2517e47e15cSTong Ho sysbus_connect_irq(sbd, 0, gic[BBRAM_IRQ]); 2527e47e15cSTong Ho } 2537e47e15cSTong Ho 254db1264dfSTong Ho static void xlnx_zynqmp_create_efuse(XlnxZynqMPState *s, qemu_irq *gic) 255db1264dfSTong Ho { 256db1264dfSTong Ho Object *bits = OBJECT(&s->efuse); 257db1264dfSTong Ho Object *ctrl = OBJECT(&s->efuse_ctrl); 258db1264dfSTong Ho SysBusDevice *sbd; 259db1264dfSTong Ho 260db1264dfSTong Ho object_initialize_child(OBJECT(s), "efuse-ctrl", &s->efuse_ctrl, 261db1264dfSTong Ho TYPE_XLNX_ZYNQMP_EFUSE); 262db1264dfSTong Ho 263db1264dfSTong Ho object_initialize_child_with_props(ctrl, "xlnx-efuse@0", bits, 264db1264dfSTong Ho sizeof(s->efuse), 265db1264dfSTong Ho TYPE_XLNX_EFUSE, &error_abort, 266db1264dfSTong Ho "efuse-nr", "3", 267db1264dfSTong Ho "efuse-size", "2048", 268db1264dfSTong Ho NULL); 269db1264dfSTong Ho 270db1264dfSTong Ho qdev_realize(DEVICE(bits), NULL, &error_abort); 271db1264dfSTong Ho object_property_set_link(ctrl, "efuse", bits, &error_abort); 272db1264dfSTong Ho 273db1264dfSTong Ho sbd = SYS_BUS_DEVICE(ctrl); 274db1264dfSTong Ho sysbus_realize(sbd, &error_abort); 275db1264dfSTong Ho sysbus_mmio_map(sbd, 0, EFUSE_ADDR); 276db1264dfSTong Ho sysbus_connect_irq(sbd, 0, gic[EFUSE_IRQ]); 277db1264dfSTong Ho } 278db1264dfSTong Ho 279d2e6f370STong Ho static void xlnx_zynqmp_create_unimp_mmio(XlnxZynqMPState *s) 280d2e6f370STong Ho { 281d2e6f370STong Ho static const struct UnimpInfo { 282d2e6f370STong Ho const char *name; 283d2e6f370STong Ho hwaddr base; 284d2e6f370STong Ho hwaddr size; 285d2e6f370STong Ho } unimp_areas[ARRAY_SIZE(s->mr_unimp)] = { 286d2e6f370STong Ho { .name = "apu", APU_ADDR, APU_SIZE }, 287d2e6f370STong Ho }; 288d2e6f370STong Ho unsigned int nr; 289d2e6f370STong Ho 290d2e6f370STong Ho for (nr = 0; nr < ARRAY_SIZE(unimp_areas); nr++) { 291d2e6f370STong Ho const struct UnimpInfo *info = &unimp_areas[nr]; 292d2e6f370STong Ho DeviceState *dev = qdev_new(TYPE_UNIMPLEMENTED_DEVICE); 293d2e6f370STong Ho SysBusDevice *sbd = SYS_BUS_DEVICE(dev); 294d2e6f370STong Ho 295d2e6f370STong Ho assert(info->name && info->base && info->size > 0); 296d2e6f370STong Ho qdev_prop_set_string(dev, "name", info->name); 297d2e6f370STong Ho qdev_prop_set_uint64(dev, "size", info->size); 298d2e6f370STong Ho object_property_add_child(OBJECT(s), info->name, OBJECT(dev)); 299d2e6f370STong Ho 300d2e6f370STong Ho sysbus_realize_and_unref(sbd, &error_fatal); 301d2e6f370STong Ho sysbus_mmio_map(sbd, 0, info->base); 302d2e6f370STong Ho } 303d2e6f370STong Ho } 304d2e6f370STong Ho 305f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_init(Object *obj) 306f0a902f7SPeter Crosthwaite { 307cc7d44c2SLike Xu MachineState *ms = MACHINE(qdev_get_machine()); 308f0a902f7SPeter Crosthwaite XlnxZynqMPState *s = XLNX_ZYNQMP(obj); 309f0a902f7SPeter Crosthwaite int i; 310cc7d44c2SLike Xu int num_apus = MIN(ms->smp.cpus, XLNX_ZYNQMP_NUM_APU_CPUS); 311f0a902f7SPeter Crosthwaite 312816fd397SLuc Michel object_initialize_child(obj, "apu-cluster", &s->apu_cluster, 3139fc7fc4dSMarkus Armbruster TYPE_CPU_CLUSTER); 314816fd397SLuc Michel qdev_prop_set_uint32(DEVICE(&s->apu_cluster), "cluster-id", 0); 315816fd397SLuc Michel 3166908ec44SAlistair Francis for (i = 0; i < num_apus; i++) { 317816fd397SLuc Michel object_initialize_child(OBJECT(&s->apu_cluster), "apu-cpu[*]", 3189fc7fc4dSMarkus Armbruster &s->apu_cpu[i], 3199fc7fc4dSMarkus Armbruster ARM_CPU_TYPE_NAME("cortex-a53")); 320f0a902f7SPeter Crosthwaite } 3217729e1f4SPeter Crosthwaite 322db873cc5SMarkus Armbruster object_initialize_child(obj, "gic", &s->gic, gic_class_name()); 32314ca2e46SPeter Crosthwaite 32414ca2e46SPeter Crosthwaite for (i = 0; i < XLNX_ZYNQMP_NUM_GEMS; i++) { 325db873cc5SMarkus Armbruster object_initialize_child(obj, "gem[*]", &s->gem[i], TYPE_CADENCE_GEM); 32614ca2e46SPeter Crosthwaite } 3273bade2a9SPeter Crosthwaite 3283bade2a9SPeter Crosthwaite for (i = 0; i < XLNX_ZYNQMP_NUM_UARTS; i++) { 329db873cc5SMarkus Armbruster object_initialize_child(obj, "uart[*]", &s->uart[i], 330ccf02d73SThomas Huth TYPE_CADENCE_UART); 3313bade2a9SPeter Crosthwaite } 3326fdf3282SAlistair Francis 333840c22cdSVikram Garhwal for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) { 334840c22cdSVikram Garhwal object_initialize_child(obj, "can[*]", &s->can[i], 335840c22cdSVikram Garhwal TYPE_XLNX_ZYNQMP_CAN); 336840c22cdSVikram Garhwal } 337840c22cdSVikram Garhwal 338db873cc5SMarkus Armbruster object_initialize_child(obj, "sata", &s->sata, TYPE_SYSBUS_AHCI); 33933108e9fSSai Pavan Boddu 34033108e9fSSai Pavan Boddu for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) { 3415a147c8cSMarkus Armbruster object_initialize_child(obj, "sdhci[*]", &s->sdhci[i], 3425a147c8cSMarkus Armbruster TYPE_SYSBUS_SDHCI); 34333108e9fSSai Pavan Boddu } 34402d07eb4SAlistair Francis 34502d07eb4SAlistair Francis for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) { 346db873cc5SMarkus Armbruster object_initialize_child(obj, "spi[*]", &s->spi[i], TYPE_XILINX_SPIPS); 34702d07eb4SAlistair Francis } 348b93dbcddSKONRAD Frederic 349db873cc5SMarkus Armbruster object_initialize_child(obj, "qspi", &s->qspi, TYPE_XLNX_ZYNQMP_QSPIPS); 350babc1f30SFrancisco Iglesias 351db873cc5SMarkus Armbruster object_initialize_child(obj, "xxxdp", &s->dp, TYPE_XLNX_DP); 352b93dbcddSKONRAD Frederic 353db873cc5SMarkus Armbruster object_initialize_child(obj, "dp-dma", &s->dpdma, TYPE_XLNX_DPDMA); 3540ab7bbc7SAlistair Francis 355db873cc5SMarkus Armbruster object_initialize_child(obj, "ipi", &s->ipi, TYPE_XLNX_ZYNQMP_IPI); 35608b2f15eSAlistair Francis 357db873cc5SMarkus Armbruster object_initialize_child(obj, "rtc", &s->rtc, TYPE_XLNX_ZYNQMP_RTC); 35804965bcaSFrancisco Iglesias 35904965bcaSFrancisco Iglesias for (i = 0; i < XLNX_ZYNQMP_NUM_GDMA_CH; i++) { 360db873cc5SMarkus Armbruster object_initialize_child(obj, "gdma[*]", &s->gdma[i], TYPE_XLNX_ZDMA); 36104965bcaSFrancisco Iglesias } 36204965bcaSFrancisco Iglesias 36304965bcaSFrancisco Iglesias for (i = 0; i < XLNX_ZYNQMP_NUM_ADMA_CH; i++) { 364db873cc5SMarkus Armbruster object_initialize_child(obj, "adma[*]", &s->adma[i], TYPE_XLNX_ZDMA); 36504965bcaSFrancisco Iglesias } 366668351a5SXuzhou Cheng 367668351a5SXuzhou Cheng object_initialize_child(obj, "qspi-dma", &s->qspi_dma, TYPE_XLNX_CSU_DMA); 368c74ccb5dSFrancisco Iglesias object_initialize_child(obj, "qspi-irq-orgate", 369c74ccb5dSFrancisco Iglesias &s->qspi_irq_orgate, TYPE_OR_IRQ); 370f0a902f7SPeter Crosthwaite } 371f0a902f7SPeter Crosthwaite 372f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) 373f0a902f7SPeter Crosthwaite { 374cc7d44c2SLike Xu MachineState *ms = MACHINE(qdev_get_machine()); 375f0a902f7SPeter Crosthwaite XlnxZynqMPState *s = XLNX_ZYNQMP(dev); 3767729e1f4SPeter Crosthwaite MemoryRegion *system_memory = get_system_memory(); 377f0a902f7SPeter Crosthwaite uint8_t i; 378dc3b89efSAlistair Francis uint64_t ram_size; 379cc7d44c2SLike Xu int num_apus = MIN(ms->smp.cpus, XLNX_ZYNQMP_NUM_APU_CPUS); 3806396a193SPeter Crosthwaite const char *boot_cpu = s->boot_cpu ? s->boot_cpu : "apu-cpu[0]"; 381dc3b89efSAlistair Francis ram_addr_t ddr_low_size, ddr_high_size; 38214ca2e46SPeter Crosthwaite qemu_irq gic_spi[GIC_NUM_SPI_INTR]; 383f0a902f7SPeter Crosthwaite Error *err = NULL; 384f0a902f7SPeter Crosthwaite 385dc3b89efSAlistair Francis ram_size = memory_region_size(s->ddr_ram); 386dc3b89efSAlistair Francis 38721bce371SXuzhou Cheng /* 38821bce371SXuzhou Cheng * Create the DDR Memory Regions. User friendly checks should happen at 389dc3b89efSAlistair Francis * the board level 390dc3b89efSAlistair Francis */ 391dc3b89efSAlistair Francis if (ram_size > XLNX_ZYNQMP_MAX_LOW_RAM_SIZE) { 39221bce371SXuzhou Cheng /* 39321bce371SXuzhou Cheng * The RAM size is above the maximum available for the low DDR. 394dc3b89efSAlistair Francis * Create the high DDR memory region as well. 395dc3b89efSAlistair Francis */ 396dc3b89efSAlistair Francis assert(ram_size <= XLNX_ZYNQMP_MAX_RAM_SIZE); 397dc3b89efSAlistair Francis ddr_low_size = XLNX_ZYNQMP_MAX_LOW_RAM_SIZE; 398dc3b89efSAlistair Francis ddr_high_size = ram_size - XLNX_ZYNQMP_MAX_LOW_RAM_SIZE; 399dc3b89efSAlistair Francis 40032b9523aSPhilippe Mathieu-Daudé memory_region_init_alias(&s->ddr_ram_high, OBJECT(dev), 40132b9523aSPhilippe Mathieu-Daudé "ddr-ram-high", s->ddr_ram, ddr_low_size, 40232b9523aSPhilippe Mathieu-Daudé ddr_high_size); 403dc3b89efSAlistair Francis memory_region_add_subregion(get_system_memory(), 404dc3b89efSAlistair Francis XLNX_ZYNQMP_HIGH_RAM_START, 405dc3b89efSAlistair Francis &s->ddr_ram_high); 406dc3b89efSAlistair Francis } else { 407dc3b89efSAlistair Francis /* RAM must be non-zero */ 408dc3b89efSAlistair Francis assert(ram_size); 409dc3b89efSAlistair Francis ddr_low_size = ram_size; 410dc3b89efSAlistair Francis } 411dc3b89efSAlistair Francis 41232b9523aSPhilippe Mathieu-Daudé memory_region_init_alias(&s->ddr_ram_low, OBJECT(dev), "ddr-ram-low", 41332b9523aSPhilippe Mathieu-Daudé s->ddr_ram, 0, ddr_low_size); 414dc3b89efSAlistair Francis memory_region_add_subregion(get_system_memory(), 0, &s->ddr_ram_low); 415dc3b89efSAlistair Francis 4166675d719SAlistair Francis /* Create the four OCM banks */ 4176675d719SAlistair Francis for (i = 0; i < XLNX_ZYNQMP_NUM_OCM_BANKS; i++) { 4186675d719SAlistair Francis char *ocm_name = g_strdup_printf("zynqmp.ocm_ram_bank_%d", i); 4196675d719SAlistair Francis 42098a99ce0SPeter Maydell memory_region_init_ram(&s->ocm_ram[i], NULL, ocm_name, 421f8ed85acSMarkus Armbruster XLNX_ZYNQMP_OCM_RAM_SIZE, &error_fatal); 4226675d719SAlistair Francis memory_region_add_subregion(get_system_memory(), 4236675d719SAlistair Francis XLNX_ZYNQMP_OCM_RAM_0_ADDRESS + 4246675d719SAlistair Francis i * XLNX_ZYNQMP_OCM_RAM_SIZE, 4256675d719SAlistair Francis &s->ocm_ram[i]); 4266675d719SAlistair Francis 4276675d719SAlistair Francis g_free(ocm_name); 4286675d719SAlistair Francis } 4296675d719SAlistair Francis 4307729e1f4SPeter Crosthwaite qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", GIC_NUM_SPI_INTR + 32); 4317729e1f4SPeter Crosthwaite qdev_prop_set_uint32(DEVICE(&s->gic), "revision", 2); 4326908ec44SAlistair Francis qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", num_apus); 43375b749afSLuc Michel qdev_prop_set_bit(DEVICE(&s->gic), "has-security-extensions", s->secure); 43475b749afSLuc Michel qdev_prop_set_bit(DEVICE(&s->gic), 43575b749afSLuc Michel "has-virtualization-extensions", s->virt); 4367729e1f4SPeter Crosthwaite 437ce189ab2SMarkus Armbruster qdev_realize(DEVICE(&s->apu_cluster), NULL, &error_fatal); 438816fd397SLuc Michel 4390776d967SEdgar E. Iglesias /* Realize APUs before realizing the GIC. KVM requires this. */ 4406908ec44SAlistair Francis for (i = 0; i < num_apus; i++) { 4417a309cc9SMarkus Armbruster const char *name; 442bf4cb109SPeter Crosthwaite 4436396a193SPeter Crosthwaite name = object_get_canonical_path_component(OBJECT(&s->apu_cpu[i])); 4446396a193SPeter Crosthwaite if (strcmp(name, boot_cpu)) { 445*50c785f2SPeter Maydell /* 446*50c785f2SPeter Maydell * Secondary CPUs start in powered-down state. 447*50c785f2SPeter Maydell */ 4485325cc34SMarkus Armbruster object_property_set_bool(OBJECT(&s->apu_cpu[i]), 4495325cc34SMarkus Armbruster "start-powered-off", true, &error_abort); 4506396a193SPeter Crosthwaite } else { 4516396a193SPeter Crosthwaite s->boot_cpu_ptr = &s->apu_cpu[i]; 452f0a902f7SPeter Crosthwaite } 453f0a902f7SPeter Crosthwaite 4545325cc34SMarkus Armbruster object_property_set_bool(OBJECT(&s->apu_cpu[i]), "has_el3", s->secure, 4555325cc34SMarkus Armbruster NULL); 4565325cc34SMarkus Armbruster object_property_set_bool(OBJECT(&s->apu_cpu[i]), "has_el2", s->virt, 4575325cc34SMarkus Armbruster NULL); 4585325cc34SMarkus Armbruster object_property_set_int(OBJECT(&s->apu_cpu[i]), "reset-cbar", 4595325cc34SMarkus Armbruster GIC_BASE_ADDR, &error_abort); 4605325cc34SMarkus Armbruster object_property_set_int(OBJECT(&s->apu_cpu[i]), "core-count", 4615325cc34SMarkus Armbruster num_apus, &error_abort); 462668f62ecSMarkus Armbruster if (!qdev_realize(DEVICE(&s->apu_cpu[i]), NULL, errp)) { 463f0a902f7SPeter Crosthwaite return; 464f0a902f7SPeter Crosthwaite } 4650776d967SEdgar E. Iglesias } 4660776d967SEdgar E. Iglesias 467668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->gic), errp)) { 4680776d967SEdgar E. Iglesias return; 4690776d967SEdgar E. Iglesias } 4700776d967SEdgar E. Iglesias 4710776d967SEdgar E. Iglesias assert(ARRAY_SIZE(xlnx_zynqmp_gic_regions) == XLNX_ZYNQMP_GIC_REGIONS); 4720776d967SEdgar E. Iglesias for (i = 0; i < XLNX_ZYNQMP_GIC_REGIONS; i++) { 4730776d967SEdgar E. Iglesias SysBusDevice *gic = SYS_BUS_DEVICE(&s->gic); 4740776d967SEdgar E. Iglesias const XlnxZynqMPGICRegion *r = &xlnx_zynqmp_gic_regions[i]; 47575b749afSLuc Michel MemoryRegion *mr; 4760776d967SEdgar E. Iglesias uint32_t addr = r->address; 4770776d967SEdgar E. Iglesias int j; 4780776d967SEdgar E. Iglesias 47975b749afSLuc Michel if (r->virt && !s->virt) { 48075b749afSLuc Michel continue; 48175b749afSLuc Michel } 4820776d967SEdgar E. Iglesias 48375b749afSLuc Michel mr = sysbus_mmio_get_region(gic, r->region_index); 4840776d967SEdgar E. Iglesias for (j = 0; j < XLNX_ZYNQMP_GIC_ALIASES; j++) { 4850776d967SEdgar E. Iglesias MemoryRegion *alias = &s->gic_mr[i][j]; 4860776d967SEdgar E. Iglesias 4870776d967SEdgar E. Iglesias memory_region_init_alias(alias, OBJECT(s), "zynqmp-gic-alias", mr, 48875b749afSLuc Michel r->offset, XLNX_ZYNQMP_GIC_REGION_SIZE); 4890776d967SEdgar E. Iglesias memory_region_add_subregion(system_memory, addr, alias); 49075b749afSLuc Michel 49175b749afSLuc Michel addr += XLNX_ZYNQMP_GIC_REGION_SIZE; 4920776d967SEdgar E. Iglesias } 4930776d967SEdgar E. Iglesias } 4940776d967SEdgar E. Iglesias 4956908ec44SAlistair Francis for (i = 0; i < num_apus; i++) { 4960776d967SEdgar E. Iglesias qemu_irq irq; 4977729e1f4SPeter Crosthwaite 4987729e1f4SPeter Crosthwaite sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i, 4992e5577bcSPeter Crosthwaite qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]), 5002e5577bcSPeter Crosthwaite ARM_CPU_IRQ)); 50175b749afSLuc Michel sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + num_apus, 50275b749afSLuc Michel qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]), 50375b749afSLuc Michel ARM_CPU_FIQ)); 50475b749afSLuc Michel sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + num_apus * 2, 50575b749afSLuc Michel qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]), 50675b749afSLuc Michel ARM_CPU_VIRQ)); 50775b749afSLuc Michel sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + num_apus * 3, 50875b749afSLuc Michel qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]), 50975b749afSLuc Michel ARM_CPU_VFIQ)); 510bf4cb109SPeter Crosthwaite irq = qdev_get_gpio_in(DEVICE(&s->gic), 511bf4cb109SPeter Crosthwaite arm_gic_ppi_index(i, ARM_PHYS_TIMER_PPI)); 51275b749afSLuc Michel qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), GTIMER_PHYS, irq); 513bf4cb109SPeter Crosthwaite irq = qdev_get_gpio_in(DEVICE(&s->gic), 514bf4cb109SPeter Crosthwaite arm_gic_ppi_index(i, ARM_VIRT_TIMER_PPI)); 51575b749afSLuc Michel qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), GTIMER_VIRT, irq); 51675b749afSLuc Michel irq = qdev_get_gpio_in(DEVICE(&s->gic), 51775b749afSLuc Michel arm_gic_ppi_index(i, ARM_HYP_TIMER_PPI)); 51875b749afSLuc Michel qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), GTIMER_HYP, irq); 51975b749afSLuc Michel irq = qdev_get_gpio_in(DEVICE(&s->gic), 52075b749afSLuc Michel arm_gic_ppi_index(i, ARM_SEC_TIMER_PPI)); 52175b749afSLuc Michel qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), GTIMER_SEC, irq); 52275b749afSLuc Michel 52375b749afSLuc Michel if (s->virt) { 52475b749afSLuc Michel irq = qdev_get_gpio_in(DEVICE(&s->gic), 52575b749afSLuc Michel arm_gic_ppi_index(i, GIC_MAINTENANCE_PPI)); 52675b749afSLuc Michel sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + num_apus * 4, irq); 52775b749afSLuc Michel } 528f0a902f7SPeter Crosthwaite } 52914ca2e46SPeter Crosthwaite 530cc7d44c2SLike Xu xlnx_zynqmp_create_rpu(ms, s, boot_cpu, &err); 531b58850e7SPeter Crosthwaite if (err) { 53224cfc8dcSAlistair Francis error_propagate(errp, err); 533b58850e7SPeter Crosthwaite return; 534b58850e7SPeter Crosthwaite } 535b58850e7SPeter Crosthwaite 5366396a193SPeter Crosthwaite if (!s->boot_cpu_ptr) { 5379af9e0feSMarkus Armbruster error_setg(errp, "ZynqMP Boot cpu %s not found", boot_cpu); 5386396a193SPeter Crosthwaite return; 5396396a193SPeter Crosthwaite } 5406396a193SPeter Crosthwaite 54114ca2e46SPeter Crosthwaite for (i = 0; i < GIC_NUM_SPI_INTR; i++) { 54214ca2e46SPeter Crosthwaite gic_spi[i] = qdev_get_gpio_in(DEVICE(&s->gic), i); 54314ca2e46SPeter Crosthwaite } 54414ca2e46SPeter Crosthwaite 54514ca2e46SPeter Crosthwaite for (i = 0; i < XLNX_ZYNQMP_NUM_GEMS; i++) { 54614ca2e46SPeter Crosthwaite NICInfo *nd = &nd_table[i]; 54714ca2e46SPeter Crosthwaite 5487ad36e2eSMarkus Armbruster /* FIXME use qdev NIC properties instead of nd_table[] */ 54914ca2e46SPeter Crosthwaite if (nd->used) { 55014ca2e46SPeter Crosthwaite qemu_check_nic_model(nd, TYPE_CADENCE_GEM); 55114ca2e46SPeter Crosthwaite qdev_set_nic_properties(DEVICE(&s->gem[i]), nd); 55214ca2e46SPeter Crosthwaite } 5535325cc34SMarkus Armbruster object_property_set_int(OBJECT(&s->gem[i]), "revision", GEM_REVISION, 55420bff213SAlistair Francis &error_abort); 555dfc38879SBin Meng object_property_set_int(OBJECT(&s->gem[i]), "phy-addr", 23, 556dfc38879SBin Meng &error_abort); 5575325cc34SMarkus Armbruster object_property_set_int(OBJECT(&s->gem[i]), "num-priority-queues", 2, 5581372fc0bSAlistair Francis &error_abort); 559668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->gem[i]), errp)) { 56014ca2e46SPeter Crosthwaite return; 56114ca2e46SPeter Crosthwaite } 56214ca2e46SPeter Crosthwaite sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem[i]), 0, gem_addr[i]); 56314ca2e46SPeter Crosthwaite sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem[i]), 0, 56414ca2e46SPeter Crosthwaite gic_spi[gem_intr[i]]); 56514ca2e46SPeter Crosthwaite } 5663bade2a9SPeter Crosthwaite 5673bade2a9SPeter Crosthwaite for (i = 0; i < XLNX_ZYNQMP_NUM_UARTS; i++) { 5689bca0edbSPeter Maydell qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i)); 569668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->uart[i]), errp)) { 5703bade2a9SPeter Crosthwaite return; 5713bade2a9SPeter Crosthwaite } 5723bade2a9SPeter Crosthwaite sysbus_mmio_map(SYS_BUS_DEVICE(&s->uart[i]), 0, uart_addr[i]); 5733bade2a9SPeter Crosthwaite sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart[i]), 0, 5743bade2a9SPeter Crosthwaite gic_spi[uart_intr[i]]); 5753bade2a9SPeter Crosthwaite } 5766fdf3282SAlistair Francis 577840c22cdSVikram Garhwal for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) { 578840c22cdSVikram Garhwal object_property_set_int(OBJECT(&s->can[i]), "ext_clk_freq", 579840c22cdSVikram Garhwal XLNX_ZYNQMP_CAN_REF_CLK, &error_abort); 580840c22cdSVikram Garhwal 581840c22cdSVikram Garhwal object_property_set_link(OBJECT(&s->can[i]), "canbus", 582840c22cdSVikram Garhwal OBJECT(s->canbus[i]), &error_fatal); 583840c22cdSVikram Garhwal 584840c22cdSVikram Garhwal sysbus_realize(SYS_BUS_DEVICE(&s->can[i]), &err); 585840c22cdSVikram Garhwal if (err) { 586840c22cdSVikram Garhwal error_propagate(errp, err); 587840c22cdSVikram Garhwal return; 588840c22cdSVikram Garhwal } 589840c22cdSVikram Garhwal sysbus_mmio_map(SYS_BUS_DEVICE(&s->can[i]), 0, can_addr[i]); 590840c22cdSVikram Garhwal sysbus_connect_irq(SYS_BUS_DEVICE(&s->can[i]), 0, 591840c22cdSVikram Garhwal gic_spi[can_intr[i]]); 592840c22cdSVikram Garhwal } 593840c22cdSVikram Garhwal 5945325cc34SMarkus Armbruster object_property_set_int(OBJECT(&s->sata), "num-ports", SATA_NUM_PORTS, 5956fdf3282SAlistair Francis &error_abort); 596668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->sata), errp)) { 5976fdf3282SAlistair Francis return; 5986fdf3282SAlistair Francis } 5996fdf3282SAlistair Francis 6006fdf3282SAlistair Francis sysbus_mmio_map(SYS_BUS_DEVICE(&s->sata), 0, SATA_ADDR); 6016fdf3282SAlistair Francis sysbus_connect_irq(SYS_BUS_DEVICE(&s->sata), 0, gic_spi[SATA_INTR]); 60233108e9fSSai Pavan Boddu 60333108e9fSSai Pavan Boddu for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) { 60463fef628SPeter Maydell char *bus_name; 605b630d3d4SPhilippe Mathieu-Daudé SysBusDevice *sbd = SYS_BUS_DEVICE(&s->sdhci[i]); 606b630d3d4SPhilippe Mathieu-Daudé Object *sdhci = OBJECT(&s->sdhci[i]); 607eb4f566bSPeter Maydell 60821bce371SXuzhou Cheng /* 60921bce371SXuzhou Cheng * Compatible with: 610b630d3d4SPhilippe Mathieu-Daudé * - SD Host Controller Specification Version 3.00 611b630d3d4SPhilippe Mathieu-Daudé * - SDIO Specification Version 3.0 612b630d3d4SPhilippe Mathieu-Daudé * - eMMC Specification Version 4.51 613b630d3d4SPhilippe Mathieu-Daudé */ 614668f62ecSMarkus Armbruster if (!object_property_set_uint(sdhci, "sd-spec-version", 3, errp)) { 615660b4e70SPeter Maydell return; 616660b4e70SPeter Maydell } 617778a2dc5SMarkus Armbruster if (!object_property_set_uint(sdhci, "capareg", SDHCI_CAPABILITIES, 618668f62ecSMarkus Armbruster errp)) { 619660b4e70SPeter Maydell return; 620660b4e70SPeter Maydell } 621668f62ecSMarkus Armbruster if (!object_property_set_uint(sdhci, "uhs", UHS_I, errp)) { 622660b4e70SPeter Maydell return; 623660b4e70SPeter Maydell } 624668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(sdhci), errp)) { 62533108e9fSSai Pavan Boddu return; 62633108e9fSSai Pavan Boddu } 627b630d3d4SPhilippe Mathieu-Daudé sysbus_mmio_map(sbd, 0, sdhci_addr[i]); 628b630d3d4SPhilippe Mathieu-Daudé sysbus_connect_irq(sbd, 0, gic_spi[sdhci_intr[i]]); 629b630d3d4SPhilippe Mathieu-Daudé 630eb4f566bSPeter Maydell /* Alias controller SD bus to the SoC itself */ 63163fef628SPeter Maydell bus_name = g_strdup_printf("sd-bus%d", i); 632d2623129SMarkus Armbruster object_property_add_alias(OBJECT(s), bus_name, sdhci, "sd-bus"); 633eb4f566bSPeter Maydell g_free(bus_name); 63433108e9fSSai Pavan Boddu } 63502d07eb4SAlistair Francis 63602d07eb4SAlistair Francis for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) { 63702d07eb4SAlistair Francis gchar *bus_name; 63802d07eb4SAlistair Francis 639668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->spi[i]), errp)) { 640660b4e70SPeter Maydell return; 641660b4e70SPeter Maydell } 64202d07eb4SAlistair Francis 64302d07eb4SAlistair Francis sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0, spi_addr[i]); 64402d07eb4SAlistair Francis sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi[i]), 0, 64502d07eb4SAlistair Francis gic_spi[spi_intr[i]]); 64602d07eb4SAlistair Francis 64702d07eb4SAlistair Francis /* Alias controller SPI bus to the SoC itself */ 64802d07eb4SAlistair Francis bus_name = g_strdup_printf("spi%d", i); 64902d07eb4SAlistair Francis object_property_add_alias(OBJECT(s), bus_name, 650d2623129SMarkus Armbruster OBJECT(&s->spi[i]), "spi0"); 65102d07eb4SAlistair Francis g_free(bus_name); 65202d07eb4SAlistair Francis } 653b93dbcddSKONRAD Frederic 654668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->dp), errp)) { 655b93dbcddSKONRAD Frederic return; 656b93dbcddSKONRAD Frederic } 657b93dbcddSKONRAD Frederic sysbus_mmio_map(SYS_BUS_DEVICE(&s->dp), 0, DP_ADDR); 658b93dbcddSKONRAD Frederic sysbus_connect_irq(SYS_BUS_DEVICE(&s->dp), 0, gic_spi[DP_IRQ]); 659b93dbcddSKONRAD Frederic 660668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->dpdma), errp)) { 661b93dbcddSKONRAD Frederic return; 662b93dbcddSKONRAD Frederic } 6635325cc34SMarkus Armbruster object_property_set_link(OBJECT(&s->dp), "dpdma", OBJECT(&s->dpdma), 664b93dbcddSKONRAD Frederic &error_abort); 665b93dbcddSKONRAD Frederic sysbus_mmio_map(SYS_BUS_DEVICE(&s->dpdma), 0, DPDMA_ADDR); 666b93dbcddSKONRAD Frederic sysbus_connect_irq(SYS_BUS_DEVICE(&s->dpdma), 0, gic_spi[DPDMA_IRQ]); 6670ab7bbc7SAlistair Francis 668668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->ipi), errp)) { 6690ab7bbc7SAlistair Francis return; 6700ab7bbc7SAlistair Francis } 6710ab7bbc7SAlistair Francis sysbus_mmio_map(SYS_BUS_DEVICE(&s->ipi), 0, IPI_ADDR); 6720ab7bbc7SAlistair Francis sysbus_connect_irq(SYS_BUS_DEVICE(&s->ipi), 0, gic_spi[IPI_IRQ]); 67308b2f15eSAlistair Francis 674668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->rtc), errp)) { 67508b2f15eSAlistair Francis return; 67608b2f15eSAlistair Francis } 67708b2f15eSAlistair Francis sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, RTC_ADDR); 67808b2f15eSAlistair Francis sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0, gic_spi[RTC_IRQ]); 67904965bcaSFrancisco Iglesias 6807e47e15cSTong Ho xlnx_zynqmp_create_bbram(s, gic_spi); 681db1264dfSTong Ho xlnx_zynqmp_create_efuse(s, gic_spi); 682d2e6f370STong Ho xlnx_zynqmp_create_unimp_mmio(s); 683d2e6f370STong Ho 68404965bcaSFrancisco Iglesias for (i = 0; i < XLNX_ZYNQMP_NUM_GDMA_CH; i++) { 685778a2dc5SMarkus Armbruster if (!object_property_set_uint(OBJECT(&s->gdma[i]), "bus-width", 128, 686668f62ecSMarkus Armbruster errp)) { 687660b4e70SPeter Maydell return; 688660b4e70SPeter Maydell } 689783dbab1SPhilippe Mathieu-Daudé if (!object_property_set_link(OBJECT(&s->gdma[i]), "dma", 690783dbab1SPhilippe Mathieu-Daudé OBJECT(system_memory), errp)) { 691783dbab1SPhilippe Mathieu-Daudé return; 692783dbab1SPhilippe Mathieu-Daudé } 693668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->gdma[i]), errp)) { 69404965bcaSFrancisco Iglesias return; 69504965bcaSFrancisco Iglesias } 69604965bcaSFrancisco Iglesias 69704965bcaSFrancisco Iglesias sysbus_mmio_map(SYS_BUS_DEVICE(&s->gdma[i]), 0, gdma_ch_addr[i]); 69804965bcaSFrancisco Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(&s->gdma[i]), 0, 69904965bcaSFrancisco Iglesias gic_spi[gdma_ch_intr[i]]); 70004965bcaSFrancisco Iglesias } 70104965bcaSFrancisco Iglesias 70204965bcaSFrancisco Iglesias for (i = 0; i < XLNX_ZYNQMP_NUM_ADMA_CH; i++) { 703783dbab1SPhilippe Mathieu-Daudé if (!object_property_set_link(OBJECT(&s->adma[i]), "dma", 704783dbab1SPhilippe Mathieu-Daudé OBJECT(system_memory), errp)) { 705783dbab1SPhilippe Mathieu-Daudé return; 706783dbab1SPhilippe Mathieu-Daudé } 707668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->adma[i]), errp)) { 70804965bcaSFrancisco Iglesias return; 70904965bcaSFrancisco Iglesias } 71004965bcaSFrancisco Iglesias 71104965bcaSFrancisco Iglesias sysbus_mmio_map(SYS_BUS_DEVICE(&s->adma[i]), 0, adma_ch_addr[i]); 71204965bcaSFrancisco Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(&s->adma[i]), 0, 71304965bcaSFrancisco Iglesias gic_spi[adma_ch_intr[i]]); 71404965bcaSFrancisco Iglesias } 715668351a5SXuzhou Cheng 716c74ccb5dSFrancisco Iglesias object_property_set_int(OBJECT(&s->qspi_irq_orgate), 717c74ccb5dSFrancisco Iglesias "num-lines", NUM_QSPI_IRQ_LINES, &error_fatal); 718c74ccb5dSFrancisco Iglesias qdev_realize(DEVICE(&s->qspi_irq_orgate), NULL, &error_fatal); 719c74ccb5dSFrancisco Iglesias qdev_connect_gpio_out(DEVICE(&s->qspi_irq_orgate), 0, gic_spi[QSPI_IRQ]); 720c74ccb5dSFrancisco Iglesias 721c31b7f59SPhilippe Mathieu-Daudé if (!object_property_set_link(OBJECT(&s->qspi_dma), "dma", 722c31b7f59SPhilippe Mathieu-Daudé OBJECT(system_memory), errp)) { 723c31b7f59SPhilippe Mathieu-Daudé return; 724c31b7f59SPhilippe Mathieu-Daudé } 725668351a5SXuzhou Cheng if (!sysbus_realize(SYS_BUS_DEVICE(&s->qspi_dma), errp)) { 726668351a5SXuzhou Cheng return; 727668351a5SXuzhou Cheng } 728668351a5SXuzhou Cheng 729668351a5SXuzhou Cheng sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi_dma), 0, QSPI_DMA_ADDR); 730c74ccb5dSFrancisco Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(&s->qspi_dma), 0, 731c74ccb5dSFrancisco Iglesias qdev_get_gpio_in(DEVICE(&s->qspi_irq_orgate), 0)); 73234a3a71dSPhilippe Mathieu-Daudé 73334a3a71dSPhilippe Mathieu-Daudé if (!object_property_set_link(OBJECT(&s->qspi), "stream-connected-dma", 73434a3a71dSPhilippe Mathieu-Daudé OBJECT(&s->qspi_dma), errp)) { 73534a3a71dSPhilippe Mathieu-Daudé return; 73634a3a71dSPhilippe Mathieu-Daudé } 73734a3a71dSPhilippe Mathieu-Daudé if (!sysbus_realize(SYS_BUS_DEVICE(&s->qspi), errp)) { 73834a3a71dSPhilippe Mathieu-Daudé return; 73934a3a71dSPhilippe Mathieu-Daudé } 74034a3a71dSPhilippe Mathieu-Daudé sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi), 0, QSPI_ADDR); 74134a3a71dSPhilippe Mathieu-Daudé sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi), 1, LQSPI_ADDR); 742c74ccb5dSFrancisco Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(&s->qspi), 0, 743c74ccb5dSFrancisco Iglesias qdev_get_gpio_in(DEVICE(&s->qspi_irq_orgate), 1)); 74434a3a71dSPhilippe Mathieu-Daudé 74534a3a71dSPhilippe Mathieu-Daudé for (i = 0; i < XLNX_ZYNQMP_NUM_QSPI_BUS; i++) { 74634a3a71dSPhilippe Mathieu-Daudé g_autofree gchar *bus_name = g_strdup_printf("qspi%d", i); 74734a3a71dSPhilippe Mathieu-Daudé g_autofree gchar *target_bus = g_strdup_printf("spi%d", i); 74834a3a71dSPhilippe Mathieu-Daudé 74934a3a71dSPhilippe Mathieu-Daudé /* Alias controller SPI bus to the SoC itself */ 75034a3a71dSPhilippe Mathieu-Daudé object_property_add_alias(OBJECT(s), bus_name, 75134a3a71dSPhilippe Mathieu-Daudé OBJECT(&s->qspi), target_bus); 75234a3a71dSPhilippe Mathieu-Daudé } 753f0a902f7SPeter Crosthwaite } 754f0a902f7SPeter Crosthwaite 7556396a193SPeter Crosthwaite static Property xlnx_zynqmp_props[] = { 7566396a193SPeter Crosthwaite DEFINE_PROP_STRING("boot-cpu", XlnxZynqMPState, boot_cpu), 75737d42473SEdgar E. Iglesias DEFINE_PROP_BOOL("secure", XlnxZynqMPState, secure, false), 7581946809eSAlistair Francis DEFINE_PROP_BOOL("virtualization", XlnxZynqMPState, virt, false), 759c3acfa01SFam Zheng DEFINE_PROP_LINK("ddr-ram", XlnxZynqMPState, ddr_ram, TYPE_MEMORY_REGION, 760c3acfa01SFam Zheng MemoryRegion *), 761840c22cdSVikram Garhwal DEFINE_PROP_LINK("canbus0", XlnxZynqMPState, canbus[0], TYPE_CAN_BUS, 762840c22cdSVikram Garhwal CanBusState *), 763840c22cdSVikram Garhwal DEFINE_PROP_LINK("canbus1", XlnxZynqMPState, canbus[1], TYPE_CAN_BUS, 764840c22cdSVikram Garhwal CanBusState *), 7656396a193SPeter Crosthwaite DEFINE_PROP_END_OF_LIST() 7666396a193SPeter Crosthwaite }; 7676396a193SPeter Crosthwaite 768f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_class_init(ObjectClass *oc, void *data) 769f0a902f7SPeter Crosthwaite { 770f0a902f7SPeter Crosthwaite DeviceClass *dc = DEVICE_CLASS(oc); 771f0a902f7SPeter Crosthwaite 7724f67d30bSMarc-André Lureau device_class_set_props(dc, xlnx_zynqmp_props); 773f0a902f7SPeter Crosthwaite dc->realize = xlnx_zynqmp_realize; 774d8589144SThomas Huth /* Reason: Uses serial_hds in realize function, thus can't be used twice */ 775d8589144SThomas Huth dc->user_creatable = false; 776f0a902f7SPeter Crosthwaite } 777f0a902f7SPeter Crosthwaite 778f0a902f7SPeter Crosthwaite static const TypeInfo xlnx_zynqmp_type_info = { 779f0a902f7SPeter Crosthwaite .name = TYPE_XLNX_ZYNQMP, 780f0a902f7SPeter Crosthwaite .parent = TYPE_DEVICE, 781f0a902f7SPeter Crosthwaite .instance_size = sizeof(XlnxZynqMPState), 782f0a902f7SPeter Crosthwaite .instance_init = xlnx_zynqmp_init, 783f0a902f7SPeter Crosthwaite .class_init = xlnx_zynqmp_class_init, 784f0a902f7SPeter Crosthwaite }; 785f0a902f7SPeter Crosthwaite 786f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_register_types(void) 787f0a902f7SPeter Crosthwaite { 788f0a902f7SPeter Crosthwaite type_register_static(&xlnx_zynqmp_type_info); 789f0a902f7SPeter Crosthwaite } 790f0a902f7SPeter Crosthwaite 791f0a902f7SPeter Crosthwaite type_init(xlnx_zynqmp_register_types) 792