xref: /qemu/hw/arm/xlnx-zynqmp.c (revision 20bff213)
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 
33*20bff213SAlistair Francis #define GEM_REVISION        0x40070106
34*20bff213SAlistair 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 
43b93dbcddSKONRAD Frederic #define DP_ADDR             0xfd4a0000
44b93dbcddSKONRAD Frederic #define DP_IRQ              113
45b93dbcddSKONRAD Frederic 
46b93dbcddSKONRAD Frederic #define DPDMA_ADDR          0xfd4c0000
47b93dbcddSKONRAD Frederic #define DPDMA_IRQ           116
48b93dbcddSKONRAD Frederic 
4914ca2e46SPeter Crosthwaite static const uint64_t gem_addr[XLNX_ZYNQMP_NUM_GEMS] = {
5014ca2e46SPeter Crosthwaite     0xFF0B0000, 0xFF0C0000, 0xFF0D0000, 0xFF0E0000,
5114ca2e46SPeter Crosthwaite };
5214ca2e46SPeter Crosthwaite 
5314ca2e46SPeter Crosthwaite static const int gem_intr[XLNX_ZYNQMP_NUM_GEMS] = {
5414ca2e46SPeter Crosthwaite     57, 59, 61, 63,
5514ca2e46SPeter Crosthwaite };
5614ca2e46SPeter Crosthwaite 
573bade2a9SPeter Crosthwaite static const uint64_t uart_addr[XLNX_ZYNQMP_NUM_UARTS] = {
583bade2a9SPeter Crosthwaite     0xFF000000, 0xFF010000,
593bade2a9SPeter Crosthwaite };
603bade2a9SPeter Crosthwaite 
613bade2a9SPeter Crosthwaite static const int uart_intr[XLNX_ZYNQMP_NUM_UARTS] = {
623bade2a9SPeter Crosthwaite     21, 22,
633bade2a9SPeter Crosthwaite };
643bade2a9SPeter Crosthwaite 
6533108e9fSSai Pavan Boddu static const uint64_t sdhci_addr[XLNX_ZYNQMP_NUM_SDHCI] = {
6633108e9fSSai Pavan Boddu     0xFF160000, 0xFF170000,
6733108e9fSSai Pavan Boddu };
6833108e9fSSai Pavan Boddu 
6933108e9fSSai Pavan Boddu static const int sdhci_intr[XLNX_ZYNQMP_NUM_SDHCI] = {
7033108e9fSSai Pavan Boddu     48, 49,
7133108e9fSSai Pavan Boddu };
7233108e9fSSai Pavan Boddu 
7302d07eb4SAlistair Francis static const uint64_t spi_addr[XLNX_ZYNQMP_NUM_SPIS] = {
7402d07eb4SAlistair Francis     0xFF040000, 0xFF050000,
7502d07eb4SAlistair Francis };
7602d07eb4SAlistair Francis 
7702d07eb4SAlistair Francis static const int spi_intr[XLNX_ZYNQMP_NUM_SPIS] = {
7802d07eb4SAlistair Francis     19, 20,
7902d07eb4SAlistair Francis };
8002d07eb4SAlistair Francis 
817729e1f4SPeter Crosthwaite typedef struct XlnxZynqMPGICRegion {
827729e1f4SPeter Crosthwaite     int region_index;
837729e1f4SPeter Crosthwaite     uint32_t address;
847729e1f4SPeter Crosthwaite } XlnxZynqMPGICRegion;
857729e1f4SPeter Crosthwaite 
867729e1f4SPeter Crosthwaite static const XlnxZynqMPGICRegion xlnx_zynqmp_gic_regions[] = {
877729e1f4SPeter Crosthwaite     { .region_index = 0, .address = GIC_DIST_ADDR, },
887729e1f4SPeter Crosthwaite     { .region_index = 1, .address = GIC_CPU_ADDR,  },
897729e1f4SPeter Crosthwaite };
90f0a902f7SPeter Crosthwaite 
91bf4cb109SPeter Crosthwaite static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index)
92bf4cb109SPeter Crosthwaite {
93bf4cb109SPeter Crosthwaite     return GIC_NUM_SPI_INTR + cpu_nr * GIC_INTERNAL + ppi_index;
94bf4cb109SPeter Crosthwaite }
95bf4cb109SPeter Crosthwaite 
966ed92b14SEdgar E. Iglesias static void xlnx_zynqmp_create_rpu(XlnxZynqMPState *s, const char *boot_cpu,
976ed92b14SEdgar E. Iglesias                                    Error **errp)
986ed92b14SEdgar E. Iglesias {
996ed92b14SEdgar E. Iglesias     Error *err = NULL;
1006ed92b14SEdgar E. Iglesias     int i;
1016ed92b14SEdgar E. Iglesias 
1026ed92b14SEdgar E. Iglesias     for (i = 0; i < XLNX_ZYNQMP_NUM_RPU_CPUS; i++) {
1036ed92b14SEdgar E. Iglesias         char *name;
1046ed92b14SEdgar E. Iglesias 
1056ed92b14SEdgar E. Iglesias         object_initialize(&s->rpu_cpu[i], sizeof(s->rpu_cpu[i]),
1066ed92b14SEdgar E. Iglesias                           "cortex-r5-" TYPE_ARM_CPU);
1076ed92b14SEdgar E. Iglesias         object_property_add_child(OBJECT(s), "rpu-cpu[*]",
1086ed92b14SEdgar E. Iglesias                                   OBJECT(&s->rpu_cpu[i]), &error_abort);
1096ed92b14SEdgar E. Iglesias 
1106ed92b14SEdgar E. Iglesias         name = object_get_canonical_path_component(OBJECT(&s->rpu_cpu[i]));
1116ed92b14SEdgar E. Iglesias         if (strcmp(name, boot_cpu)) {
1126ed92b14SEdgar E. Iglesias             /* Secondary CPUs start in PSCI powered-down state */
1136ed92b14SEdgar E. Iglesias             object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true,
1146ed92b14SEdgar E. Iglesias                                      "start-powered-off", &error_abort);
1156ed92b14SEdgar E. Iglesias         } else {
1166ed92b14SEdgar E. Iglesias             s->boot_cpu_ptr = &s->rpu_cpu[i];
1176ed92b14SEdgar E. Iglesias         }
1186ed92b14SEdgar E. Iglesias         g_free(name);
1196ed92b14SEdgar E. Iglesias 
1206ed92b14SEdgar E. Iglesias         object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, "reset-hivecs",
1216ed92b14SEdgar E. Iglesias                                  &error_abort);
1226ed92b14SEdgar E. Iglesias         object_property_set_bool(OBJECT(&s->rpu_cpu[i]), true, "realized",
1236ed92b14SEdgar E. Iglesias                                  &err);
1246ed92b14SEdgar E. Iglesias         if (err) {
1256ed92b14SEdgar E. Iglesias             error_propagate(errp, err);
1266ed92b14SEdgar E. Iglesias             return;
1276ed92b14SEdgar E. Iglesias         }
1286ed92b14SEdgar E. Iglesias     }
1296ed92b14SEdgar E. Iglesias }
1306ed92b14SEdgar E. Iglesias 
131f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_init(Object *obj)
132f0a902f7SPeter Crosthwaite {
133f0a902f7SPeter Crosthwaite     XlnxZynqMPState *s = XLNX_ZYNQMP(obj);
134f0a902f7SPeter Crosthwaite     int i;
135f0a902f7SPeter Crosthwaite 
1362e5577bcSPeter Crosthwaite     for (i = 0; i < XLNX_ZYNQMP_NUM_APU_CPUS; i++) {
1372e5577bcSPeter Crosthwaite         object_initialize(&s->apu_cpu[i], sizeof(s->apu_cpu[i]),
138f0a902f7SPeter Crosthwaite                           "cortex-a53-" TYPE_ARM_CPU);
1392e5577bcSPeter Crosthwaite         object_property_add_child(obj, "apu-cpu[*]", OBJECT(&s->apu_cpu[i]),
140f0a902f7SPeter Crosthwaite                                   &error_abort);
141f0a902f7SPeter Crosthwaite     }
1427729e1f4SPeter Crosthwaite 
143dc3b89efSAlistair Francis     object_property_add_link(obj, "ddr-ram", TYPE_MEMORY_REGION,
144dc3b89efSAlistair Francis                              (Object **)&s->ddr_ram,
145dc3b89efSAlistair Francis                              qdev_prop_allow_set_link_before_realize,
146dc3b89efSAlistair Francis                              OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);
147dc3b89efSAlistair Francis 
1482a0ee672SEdgar E. Iglesias     object_initialize(&s->gic, sizeof(s->gic), gic_class_name());
1497729e1f4SPeter Crosthwaite     qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default());
15014ca2e46SPeter Crosthwaite 
15114ca2e46SPeter Crosthwaite     for (i = 0; i < XLNX_ZYNQMP_NUM_GEMS; i++) {
15214ca2e46SPeter Crosthwaite         object_initialize(&s->gem[i], sizeof(s->gem[i]), TYPE_CADENCE_GEM);
15314ca2e46SPeter Crosthwaite         qdev_set_parent_bus(DEVICE(&s->gem[i]), sysbus_get_default());
15414ca2e46SPeter Crosthwaite     }
1553bade2a9SPeter Crosthwaite 
1563bade2a9SPeter Crosthwaite     for (i = 0; i < XLNX_ZYNQMP_NUM_UARTS; i++) {
1573bade2a9SPeter Crosthwaite         object_initialize(&s->uart[i], sizeof(s->uart[i]), TYPE_CADENCE_UART);
1583bade2a9SPeter Crosthwaite         qdev_set_parent_bus(DEVICE(&s->uart[i]), sysbus_get_default());
1593bade2a9SPeter Crosthwaite     }
1606fdf3282SAlistair Francis 
1616fdf3282SAlistair Francis     object_initialize(&s->sata, sizeof(s->sata), TYPE_SYSBUS_AHCI);
1626fdf3282SAlistair Francis     qdev_set_parent_bus(DEVICE(&s->sata), sysbus_get_default());
16333108e9fSSai Pavan Boddu 
16433108e9fSSai Pavan Boddu     for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) {
16533108e9fSSai Pavan Boddu         object_initialize(&s->sdhci[i], sizeof(s->sdhci[i]),
16633108e9fSSai Pavan Boddu                           TYPE_SYSBUS_SDHCI);
16733108e9fSSai Pavan Boddu         qdev_set_parent_bus(DEVICE(&s->sdhci[i]),
16833108e9fSSai Pavan Boddu                             sysbus_get_default());
16933108e9fSSai Pavan Boddu     }
17002d07eb4SAlistair Francis 
17102d07eb4SAlistair Francis     for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) {
17202d07eb4SAlistair Francis         object_initialize(&s->spi[i], sizeof(s->spi[i]),
17302d07eb4SAlistair Francis                           TYPE_XILINX_SPIPS);
17402d07eb4SAlistair Francis         qdev_set_parent_bus(DEVICE(&s->spi[i]), sysbus_get_default());
17502d07eb4SAlistair Francis     }
176b93dbcddSKONRAD Frederic 
177b93dbcddSKONRAD Frederic     object_initialize(&s->dp, sizeof(s->dp), TYPE_XLNX_DP);
178b93dbcddSKONRAD Frederic     qdev_set_parent_bus(DEVICE(&s->dp), sysbus_get_default());
179b93dbcddSKONRAD Frederic 
180b93dbcddSKONRAD Frederic     object_initialize(&s->dpdma, sizeof(s->dpdma), TYPE_XLNX_DPDMA);
181b93dbcddSKONRAD Frederic     qdev_set_parent_bus(DEVICE(&s->dpdma), sysbus_get_default());
182f0a902f7SPeter Crosthwaite }
183f0a902f7SPeter Crosthwaite 
184f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
185f0a902f7SPeter Crosthwaite {
186f0a902f7SPeter Crosthwaite     XlnxZynqMPState *s = XLNX_ZYNQMP(dev);
1877729e1f4SPeter Crosthwaite     MemoryRegion *system_memory = get_system_memory();
188f0a902f7SPeter Crosthwaite     uint8_t i;
189dc3b89efSAlistair Francis     uint64_t ram_size;
1906396a193SPeter Crosthwaite     const char *boot_cpu = s->boot_cpu ? s->boot_cpu : "apu-cpu[0]";
191dc3b89efSAlistair Francis     ram_addr_t ddr_low_size, ddr_high_size;
19214ca2e46SPeter Crosthwaite     qemu_irq gic_spi[GIC_NUM_SPI_INTR];
193f0a902f7SPeter Crosthwaite     Error *err = NULL;
194f0a902f7SPeter Crosthwaite 
195dc3b89efSAlistair Francis     ram_size = memory_region_size(s->ddr_ram);
196dc3b89efSAlistair Francis 
197dc3b89efSAlistair Francis     /* Create the DDR Memory Regions. User friendly checks should happen at
198dc3b89efSAlistair Francis      * the board level
199dc3b89efSAlistair Francis      */
200dc3b89efSAlistair Francis     if (ram_size > XLNX_ZYNQMP_MAX_LOW_RAM_SIZE) {
201dc3b89efSAlistair Francis         /* The RAM size is above the maximum available for the low DDR.
202dc3b89efSAlistair Francis          * Create the high DDR memory region as well.
203dc3b89efSAlistair Francis          */
204dc3b89efSAlistair Francis         assert(ram_size <= XLNX_ZYNQMP_MAX_RAM_SIZE);
205dc3b89efSAlistair Francis         ddr_low_size = XLNX_ZYNQMP_MAX_LOW_RAM_SIZE;
206dc3b89efSAlistair Francis         ddr_high_size = ram_size - XLNX_ZYNQMP_MAX_LOW_RAM_SIZE;
207dc3b89efSAlistair Francis 
208dc3b89efSAlistair Francis         memory_region_init_alias(&s->ddr_ram_high, NULL,
209dc3b89efSAlistair Francis                                  "ddr-ram-high", s->ddr_ram,
210dc3b89efSAlistair Francis                                   ddr_low_size, ddr_high_size);
211dc3b89efSAlistair Francis         memory_region_add_subregion(get_system_memory(),
212dc3b89efSAlistair Francis                                     XLNX_ZYNQMP_HIGH_RAM_START,
213dc3b89efSAlistair Francis                                     &s->ddr_ram_high);
214dc3b89efSAlistair Francis     } else {
215dc3b89efSAlistair Francis         /* RAM must be non-zero */
216dc3b89efSAlistair Francis         assert(ram_size);
217dc3b89efSAlistair Francis         ddr_low_size = ram_size;
218dc3b89efSAlistair Francis     }
219dc3b89efSAlistair Francis 
220dc3b89efSAlistair Francis     memory_region_init_alias(&s->ddr_ram_low, NULL,
221dc3b89efSAlistair Francis                              "ddr-ram-low", s->ddr_ram,
222dc3b89efSAlistair Francis                               0, ddr_low_size);
223dc3b89efSAlistair Francis     memory_region_add_subregion(get_system_memory(), 0, &s->ddr_ram_low);
224dc3b89efSAlistair Francis 
2256675d719SAlistair Francis     /* Create the four OCM banks */
2266675d719SAlistair Francis     for (i = 0; i < XLNX_ZYNQMP_NUM_OCM_BANKS; i++) {
2276675d719SAlistair Francis         char *ocm_name = g_strdup_printf("zynqmp.ocm_ram_bank_%d", i);
2286675d719SAlistair Francis 
2296675d719SAlistair Francis         memory_region_init_ram(&s->ocm_ram[i], NULL, ocm_name,
230f8ed85acSMarkus Armbruster                                XLNX_ZYNQMP_OCM_RAM_SIZE, &error_fatal);
2316675d719SAlistair Francis         vmstate_register_ram_global(&s->ocm_ram[i]);
2326675d719SAlistair Francis         memory_region_add_subregion(get_system_memory(),
2336675d719SAlistair Francis                                     XLNX_ZYNQMP_OCM_RAM_0_ADDRESS +
2346675d719SAlistair Francis                                         i * XLNX_ZYNQMP_OCM_RAM_SIZE,
2356675d719SAlistair Francis                                     &s->ocm_ram[i]);
2366675d719SAlistair Francis 
2376675d719SAlistair Francis         g_free(ocm_name);
2386675d719SAlistair Francis     }
2396675d719SAlistair Francis 
2407729e1f4SPeter Crosthwaite     qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", GIC_NUM_SPI_INTR + 32);
2417729e1f4SPeter Crosthwaite     qdev_prop_set_uint32(DEVICE(&s->gic), "revision", 2);
2422e5577bcSPeter Crosthwaite     qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", XLNX_ZYNQMP_NUM_APU_CPUS);
2437729e1f4SPeter Crosthwaite 
2440776d967SEdgar E. Iglesias     /* Realize APUs before realizing the GIC. KVM requires this.  */
2452e5577bcSPeter Crosthwaite     for (i = 0; i < XLNX_ZYNQMP_NUM_APU_CPUS; i++) {
2466396a193SPeter Crosthwaite         char *name;
247bf4cb109SPeter Crosthwaite 
2482e5577bcSPeter Crosthwaite         object_property_set_int(OBJECT(&s->apu_cpu[i]), QEMU_PSCI_CONDUIT_SMC,
249f0a902f7SPeter Crosthwaite                                 "psci-conduit", &error_abort);
2506396a193SPeter Crosthwaite 
2516396a193SPeter Crosthwaite         name = object_get_canonical_path_component(OBJECT(&s->apu_cpu[i]));
2526396a193SPeter Crosthwaite         if (strcmp(name, boot_cpu)) {
253f0a902f7SPeter Crosthwaite             /* Secondary CPUs start in PSCI powered-down state */
2542e5577bcSPeter Crosthwaite             object_property_set_bool(OBJECT(&s->apu_cpu[i]), true,
255f0a902f7SPeter Crosthwaite                                      "start-powered-off", &error_abort);
2566396a193SPeter Crosthwaite         } else {
2576396a193SPeter Crosthwaite             s->boot_cpu_ptr = &s->apu_cpu[i];
258f0a902f7SPeter Crosthwaite         }
2595348c62cSGonglei         g_free(name);
260f0a902f7SPeter Crosthwaite 
26137d42473SEdgar E. Iglesias         object_property_set_bool(OBJECT(&s->apu_cpu[i]),
26237d42473SEdgar E. Iglesias                                  s->secure, "has_el3", NULL);
263c25bd18aSPeter Maydell         object_property_set_bool(OBJECT(&s->apu_cpu[i]),
264c25bd18aSPeter Maydell                                  false, "has_el2", NULL);
2652e5577bcSPeter Crosthwaite         object_property_set_int(OBJECT(&s->apu_cpu[i]), GIC_BASE_ADDR,
266e1292517SAlistair Francis                                 "reset-cbar", &error_abort);
2672e5577bcSPeter Crosthwaite         object_property_set_bool(OBJECT(&s->apu_cpu[i]), true, "realized",
2682e5577bcSPeter Crosthwaite                                  &err);
269f0a902f7SPeter Crosthwaite         if (err) {
27024cfc8dcSAlistair Francis             error_propagate(errp, err);
271f0a902f7SPeter Crosthwaite             return;
272f0a902f7SPeter Crosthwaite         }
2730776d967SEdgar E. Iglesias     }
2740776d967SEdgar E. Iglesias 
2750776d967SEdgar E. Iglesias     object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
2760776d967SEdgar E. Iglesias     if (err) {
2770776d967SEdgar E. Iglesias         error_propagate(errp, err);
2780776d967SEdgar E. Iglesias         return;
2790776d967SEdgar E. Iglesias     }
2800776d967SEdgar E. Iglesias 
2810776d967SEdgar E. Iglesias     assert(ARRAY_SIZE(xlnx_zynqmp_gic_regions) == XLNX_ZYNQMP_GIC_REGIONS);
2820776d967SEdgar E. Iglesias     for (i = 0; i < XLNX_ZYNQMP_GIC_REGIONS; i++) {
2830776d967SEdgar E. Iglesias         SysBusDevice *gic = SYS_BUS_DEVICE(&s->gic);
2840776d967SEdgar E. Iglesias         const XlnxZynqMPGICRegion *r = &xlnx_zynqmp_gic_regions[i];
2850776d967SEdgar E. Iglesias         MemoryRegion *mr = sysbus_mmio_get_region(gic, r->region_index);
2860776d967SEdgar E. Iglesias         uint32_t addr = r->address;
2870776d967SEdgar E. Iglesias         int j;
2880776d967SEdgar E. Iglesias 
2890776d967SEdgar E. Iglesias         sysbus_mmio_map(gic, r->region_index, addr);
2900776d967SEdgar E. Iglesias 
2910776d967SEdgar E. Iglesias         for (j = 0; j < XLNX_ZYNQMP_GIC_ALIASES; j++) {
2920776d967SEdgar E. Iglesias             MemoryRegion *alias = &s->gic_mr[i][j];
2930776d967SEdgar E. Iglesias 
2940776d967SEdgar E. Iglesias             addr += XLNX_ZYNQMP_GIC_REGION_SIZE;
2950776d967SEdgar E. Iglesias             memory_region_init_alias(alias, OBJECT(s), "zynqmp-gic-alias", mr,
2960776d967SEdgar E. Iglesias                                      0, XLNX_ZYNQMP_GIC_REGION_SIZE);
2970776d967SEdgar E. Iglesias             memory_region_add_subregion(system_memory, addr, alias);
2980776d967SEdgar E. Iglesias         }
2990776d967SEdgar E. Iglesias     }
3000776d967SEdgar E. Iglesias 
3010776d967SEdgar E. Iglesias     for (i = 0; i < XLNX_ZYNQMP_NUM_APU_CPUS; i++) {
3020776d967SEdgar E. Iglesias         qemu_irq irq;
3037729e1f4SPeter Crosthwaite 
3047729e1f4SPeter Crosthwaite         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i,
3052e5577bcSPeter Crosthwaite                            qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]),
3062e5577bcSPeter Crosthwaite                                             ARM_CPU_IRQ));
307bf4cb109SPeter Crosthwaite         irq = qdev_get_gpio_in(DEVICE(&s->gic),
308bf4cb109SPeter Crosthwaite                                arm_gic_ppi_index(i, ARM_PHYS_TIMER_PPI));
3092e5577bcSPeter Crosthwaite         qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), 0, irq);
310bf4cb109SPeter Crosthwaite         irq = qdev_get_gpio_in(DEVICE(&s->gic),
311bf4cb109SPeter Crosthwaite                                arm_gic_ppi_index(i, ARM_VIRT_TIMER_PPI));
3122e5577bcSPeter Crosthwaite         qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), 1, irq);
313f0a902f7SPeter Crosthwaite     }
31414ca2e46SPeter Crosthwaite 
3156ed92b14SEdgar E. Iglesias     if (s->has_rpu) {
3166ed92b14SEdgar E. Iglesias         xlnx_zynqmp_create_rpu(s, boot_cpu, &err);
317b58850e7SPeter Crosthwaite         if (err) {
31824cfc8dcSAlistair Francis             error_propagate(errp, err);
319b58850e7SPeter Crosthwaite             return;
320b58850e7SPeter Crosthwaite         }
321b58850e7SPeter Crosthwaite     }
322b58850e7SPeter Crosthwaite 
3236396a193SPeter Crosthwaite     if (!s->boot_cpu_ptr) {
3249af9e0feSMarkus Armbruster         error_setg(errp, "ZynqMP Boot cpu %s not found", boot_cpu);
3256396a193SPeter Crosthwaite         return;
3266396a193SPeter Crosthwaite     }
3276396a193SPeter Crosthwaite 
32814ca2e46SPeter Crosthwaite     for (i = 0; i < GIC_NUM_SPI_INTR; i++) {
32914ca2e46SPeter Crosthwaite         gic_spi[i] = qdev_get_gpio_in(DEVICE(&s->gic), i);
33014ca2e46SPeter Crosthwaite     }
33114ca2e46SPeter Crosthwaite 
33214ca2e46SPeter Crosthwaite     for (i = 0; i < XLNX_ZYNQMP_NUM_GEMS; i++) {
33314ca2e46SPeter Crosthwaite         NICInfo *nd = &nd_table[i];
33414ca2e46SPeter Crosthwaite 
33514ca2e46SPeter Crosthwaite         if (nd->used) {
33614ca2e46SPeter Crosthwaite             qemu_check_nic_model(nd, TYPE_CADENCE_GEM);
33714ca2e46SPeter Crosthwaite             qdev_set_nic_properties(DEVICE(&s->gem[i]), nd);
33814ca2e46SPeter Crosthwaite         }
339*20bff213SAlistair Francis         object_property_set_int(OBJECT(&s->gem[i]), GEM_REVISION, "revision",
340*20bff213SAlistair Francis                                 &error_abort);
3411372fc0bSAlistair Francis         object_property_set_int(OBJECT(&s->gem[i]), 2, "num-priority-queues",
3421372fc0bSAlistair Francis                                 &error_abort);
34314ca2e46SPeter Crosthwaite         object_property_set_bool(OBJECT(&s->gem[i]), true, "realized", &err);
34414ca2e46SPeter Crosthwaite         if (err) {
34524cfc8dcSAlistair Francis             error_propagate(errp, err);
34614ca2e46SPeter Crosthwaite             return;
34714ca2e46SPeter Crosthwaite         }
34814ca2e46SPeter Crosthwaite         sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem[i]), 0, gem_addr[i]);
34914ca2e46SPeter Crosthwaite         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem[i]), 0,
35014ca2e46SPeter Crosthwaite                            gic_spi[gem_intr[i]]);
35114ca2e46SPeter Crosthwaite     }
3523bade2a9SPeter Crosthwaite 
3533bade2a9SPeter Crosthwaite     for (i = 0; i < XLNX_ZYNQMP_NUM_UARTS; i++) {
3544be12ea0Sxiaoqiang zhao         qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hds[i]);
3553bade2a9SPeter Crosthwaite         object_property_set_bool(OBJECT(&s->uart[i]), true, "realized", &err);
3563bade2a9SPeter Crosthwaite         if (err) {
35724cfc8dcSAlistair Francis             error_propagate(errp, err);
3583bade2a9SPeter Crosthwaite             return;
3593bade2a9SPeter Crosthwaite         }
3603bade2a9SPeter Crosthwaite         sysbus_mmio_map(SYS_BUS_DEVICE(&s->uart[i]), 0, uart_addr[i]);
3613bade2a9SPeter Crosthwaite         sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart[i]), 0,
3623bade2a9SPeter Crosthwaite                            gic_spi[uart_intr[i]]);
3633bade2a9SPeter Crosthwaite     }
3646fdf3282SAlistair Francis 
3656fdf3282SAlistair Francis     object_property_set_int(OBJECT(&s->sata), SATA_NUM_PORTS, "num-ports",
3666fdf3282SAlistair Francis                             &error_abort);
3676fdf3282SAlistair Francis     object_property_set_bool(OBJECT(&s->sata), true, "realized", &err);
3686fdf3282SAlistair Francis     if (err) {
3696fdf3282SAlistair Francis         error_propagate(errp, err);
3706fdf3282SAlistair Francis         return;
3716fdf3282SAlistair Francis     }
3726fdf3282SAlistair Francis 
3736fdf3282SAlistair Francis     sysbus_mmio_map(SYS_BUS_DEVICE(&s->sata), 0, SATA_ADDR);
3746fdf3282SAlistair Francis     sysbus_connect_irq(SYS_BUS_DEVICE(&s->sata), 0, gic_spi[SATA_INTR]);
37533108e9fSSai Pavan Boddu 
37633108e9fSSai Pavan Boddu     for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) {
377eb4f566bSPeter Maydell         char *bus_name;
378eb4f566bSPeter Maydell 
37933108e9fSSai Pavan Boddu         object_property_set_bool(OBJECT(&s->sdhci[i]), true,
38033108e9fSSai Pavan Boddu                                  "realized", &err);
38133108e9fSSai Pavan Boddu         if (err) {
38233108e9fSSai Pavan Boddu             error_propagate(errp, err);
38333108e9fSSai Pavan Boddu             return;
38433108e9fSSai Pavan Boddu         }
38533108e9fSSai Pavan Boddu         sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdhci[i]), 0,
38633108e9fSSai Pavan Boddu                         sdhci_addr[i]);
38733108e9fSSai Pavan Boddu         sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci[i]), 0,
38833108e9fSSai Pavan Boddu                            gic_spi[sdhci_intr[i]]);
389eb4f566bSPeter Maydell         /* Alias controller SD bus to the SoC itself */
390eb4f566bSPeter Maydell         bus_name = g_strdup_printf("sd-bus%d", i);
391eb4f566bSPeter Maydell         object_property_add_alias(OBJECT(s), bus_name,
392eb4f566bSPeter Maydell                                   OBJECT(&s->sdhci[i]), "sd-bus",
393eb4f566bSPeter Maydell                                   &error_abort);
394eb4f566bSPeter Maydell         g_free(bus_name);
39533108e9fSSai Pavan Boddu     }
39602d07eb4SAlistair Francis 
39702d07eb4SAlistair Francis     for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) {
39802d07eb4SAlistair Francis         gchar *bus_name;
39902d07eb4SAlistair Francis 
40002d07eb4SAlistair Francis         object_property_set_bool(OBJECT(&s->spi[i]), true, "realized", &err);
40102d07eb4SAlistair Francis 
40202d07eb4SAlistair Francis         sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0, spi_addr[i]);
40302d07eb4SAlistair Francis         sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi[i]), 0,
40402d07eb4SAlistair Francis                            gic_spi[spi_intr[i]]);
40502d07eb4SAlistair Francis 
40602d07eb4SAlistair Francis         /* Alias controller SPI bus to the SoC itself */
40702d07eb4SAlistair Francis         bus_name = g_strdup_printf("spi%d", i);
40802d07eb4SAlistair Francis         object_property_add_alias(OBJECT(s), bus_name,
40902d07eb4SAlistair Francis                                   OBJECT(&s->spi[i]), "spi0",
41002d07eb4SAlistair Francis                                   &error_abort);
41102d07eb4SAlistair Francis         g_free(bus_name);
41202d07eb4SAlistair Francis     }
413b93dbcddSKONRAD Frederic 
414b93dbcddSKONRAD Frederic     object_property_set_bool(OBJECT(&s->dp), true, "realized", &err);
415b93dbcddSKONRAD Frederic     if (err) {
416b93dbcddSKONRAD Frederic         error_propagate(errp, err);
417b93dbcddSKONRAD Frederic         return;
418b93dbcddSKONRAD Frederic     }
419b93dbcddSKONRAD Frederic     sysbus_mmio_map(SYS_BUS_DEVICE(&s->dp), 0, DP_ADDR);
420b93dbcddSKONRAD Frederic     sysbus_connect_irq(SYS_BUS_DEVICE(&s->dp), 0, gic_spi[DP_IRQ]);
421b93dbcddSKONRAD Frederic 
422b93dbcddSKONRAD Frederic     object_property_set_bool(OBJECT(&s->dpdma), true, "realized", &err);
423b93dbcddSKONRAD Frederic     if (err) {
424b93dbcddSKONRAD Frederic         error_propagate(errp, err);
425b93dbcddSKONRAD Frederic         return;
426b93dbcddSKONRAD Frederic     }
427b93dbcddSKONRAD Frederic     object_property_set_link(OBJECT(&s->dp), OBJECT(&s->dpdma), "dpdma",
428b93dbcddSKONRAD Frederic                              &error_abort);
429b93dbcddSKONRAD Frederic     sysbus_mmio_map(SYS_BUS_DEVICE(&s->dpdma), 0, DPDMA_ADDR);
430b93dbcddSKONRAD Frederic     sysbus_connect_irq(SYS_BUS_DEVICE(&s->dpdma), 0, gic_spi[DPDMA_IRQ]);
431f0a902f7SPeter Crosthwaite }
432f0a902f7SPeter Crosthwaite 
4336396a193SPeter Crosthwaite static Property xlnx_zynqmp_props[] = {
4346396a193SPeter Crosthwaite     DEFINE_PROP_STRING("boot-cpu", XlnxZynqMPState, boot_cpu),
43537d42473SEdgar E. Iglesias     DEFINE_PROP_BOOL("secure", XlnxZynqMPState, secure, false),
4366ed92b14SEdgar E. Iglesias     DEFINE_PROP_BOOL("has_rpu", XlnxZynqMPState, has_rpu, false),
4376396a193SPeter Crosthwaite     DEFINE_PROP_END_OF_LIST()
4386396a193SPeter Crosthwaite };
4396396a193SPeter Crosthwaite 
440f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_class_init(ObjectClass *oc, void *data)
441f0a902f7SPeter Crosthwaite {
442f0a902f7SPeter Crosthwaite     DeviceClass *dc = DEVICE_CLASS(oc);
443f0a902f7SPeter Crosthwaite 
4446396a193SPeter Crosthwaite     dc->props = xlnx_zynqmp_props;
445f0a902f7SPeter Crosthwaite     dc->realize = xlnx_zynqmp_realize;
4464c315c27SMarkus Armbruster 
4474c315c27SMarkus Armbruster     /*
4484c315c27SMarkus Armbruster      * Reason: creates an ARM CPU, thus use after free(), see
4494c315c27SMarkus Armbruster      * arm_cpu_class_init()
4504c315c27SMarkus Armbruster      */
4514c315c27SMarkus Armbruster     dc->cannot_destroy_with_object_finalize_yet = true;
452f0a902f7SPeter Crosthwaite }
453f0a902f7SPeter Crosthwaite 
454f0a902f7SPeter Crosthwaite static const TypeInfo xlnx_zynqmp_type_info = {
455f0a902f7SPeter Crosthwaite     .name = TYPE_XLNX_ZYNQMP,
456f0a902f7SPeter Crosthwaite     .parent = TYPE_DEVICE,
457f0a902f7SPeter Crosthwaite     .instance_size = sizeof(XlnxZynqMPState),
458f0a902f7SPeter Crosthwaite     .instance_init = xlnx_zynqmp_init,
459f0a902f7SPeter Crosthwaite     .class_init = xlnx_zynqmp_class_init,
460f0a902f7SPeter Crosthwaite };
461f0a902f7SPeter Crosthwaite 
462f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_register_types(void)
463f0a902f7SPeter Crosthwaite {
464f0a902f7SPeter Crosthwaite     type_register_static(&xlnx_zynqmp_type_info);
465f0a902f7SPeter Crosthwaite }
466f0a902f7SPeter Crosthwaite 
467f0a902f7SPeter Crosthwaite type_init(xlnx_zynqmp_register_types)
468