xref: /qemu/hw/arm/xlnx-zynqmp.c (revision b3f5cc3f)
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 
5563320bcaSEdgar E. Iglesias #define CRF_ADDR            0xfd1a0000
5663320bcaSEdgar E. Iglesias #define CRF_IRQ             120
5763320bcaSEdgar E. Iglesias 
58c28d4b86SEdgar E. Iglesias /* Serializer/Deserializer.  */
59c28d4b86SEdgar E. Iglesias #define SERDES_ADDR         0xfd400000
60c28d4b86SEdgar E. Iglesias #define SERDES_SIZE         0x20000
61c28d4b86SEdgar E. Iglesias 
62b93dbcddSKONRAD Frederic #define DP_ADDR             0xfd4a0000
63*b3f5cc3fSFrederic Konrad #define DP_IRQ              0x77
64b93dbcddSKONRAD Frederic 
65b93dbcddSKONRAD Frederic #define DPDMA_ADDR          0xfd4c0000
66*b3f5cc3fSFrederic Konrad #define DPDMA_IRQ           0x7a
67b93dbcddSKONRAD Frederic 
68d2e6f370STong Ho #define APU_ADDR            0xfd5c0000
69eb7a38baSEdgar E. Iglesias #define APU_IRQ             153
70d2e6f370STong Ho 
7151af6231SEdgar E. Iglesias #define TTC0_ADDR           0xFF110000
7251af6231SEdgar E. Iglesias #define TTC0_IRQ            36
7351af6231SEdgar E. Iglesias 
740ab7bbc7SAlistair Francis #define IPI_ADDR            0xFF300000
750ab7bbc7SAlistair Francis #define IPI_IRQ             64
760ab7bbc7SAlistair Francis 
7708b2f15eSAlistair Francis #define RTC_ADDR            0xffa60000
7808b2f15eSAlistair Francis #define RTC_IRQ             26
7908b2f15eSAlistair Francis 
807e47e15cSTong Ho #define BBRAM_ADDR          0xffcd0000
817e47e15cSTong Ho #define BBRAM_IRQ           11
827e47e15cSTong Ho 
83db1264dfSTong Ho #define EFUSE_ADDR          0xffcc0000
84db1264dfSTong Ho #define EFUSE_IRQ           87
85db1264dfSTong Ho 
86b630d3d4SPhilippe Mathieu-Daudé #define SDHCI_CAPABILITIES  0x280737ec6481 /* Datasheet: UG1085 (v1.7) */
87b630d3d4SPhilippe Mathieu-Daudé 
8814ca2e46SPeter Crosthwaite static const uint64_t gem_addr[XLNX_ZYNQMP_NUM_GEMS] = {
8914ca2e46SPeter Crosthwaite     0xFF0B0000, 0xFF0C0000, 0xFF0D0000, 0xFF0E0000,
9014ca2e46SPeter Crosthwaite };
9114ca2e46SPeter Crosthwaite 
9214ca2e46SPeter Crosthwaite static const int gem_intr[XLNX_ZYNQMP_NUM_GEMS] = {
9314ca2e46SPeter Crosthwaite     57, 59, 61, 63,
9414ca2e46SPeter Crosthwaite };
9514ca2e46SPeter Crosthwaite 
963bade2a9SPeter Crosthwaite static const uint64_t uart_addr[XLNX_ZYNQMP_NUM_UARTS] = {
973bade2a9SPeter Crosthwaite     0xFF000000, 0xFF010000,
983bade2a9SPeter Crosthwaite };
993bade2a9SPeter Crosthwaite 
1003bade2a9SPeter Crosthwaite static const int uart_intr[XLNX_ZYNQMP_NUM_UARTS] = {
1013bade2a9SPeter Crosthwaite     21, 22,
1023bade2a9SPeter Crosthwaite };
1033bade2a9SPeter Crosthwaite 
104840c22cdSVikram Garhwal static const uint64_t can_addr[XLNX_ZYNQMP_NUM_CAN] = {
105840c22cdSVikram Garhwal     0xFF060000, 0xFF070000,
106840c22cdSVikram Garhwal };
107840c22cdSVikram Garhwal 
108840c22cdSVikram Garhwal static const int can_intr[XLNX_ZYNQMP_NUM_CAN] = {
109840c22cdSVikram Garhwal     23, 24,
110840c22cdSVikram Garhwal };
111840c22cdSVikram Garhwal 
11233108e9fSSai Pavan Boddu static const uint64_t sdhci_addr[XLNX_ZYNQMP_NUM_SDHCI] = {
11333108e9fSSai Pavan Boddu     0xFF160000, 0xFF170000,
11433108e9fSSai Pavan Boddu };
11533108e9fSSai Pavan Boddu 
11633108e9fSSai Pavan Boddu static const int sdhci_intr[XLNX_ZYNQMP_NUM_SDHCI] = {
11733108e9fSSai Pavan Boddu     48, 49,
11833108e9fSSai Pavan Boddu };
11933108e9fSSai Pavan Boddu 
12002d07eb4SAlistair Francis static const uint64_t spi_addr[XLNX_ZYNQMP_NUM_SPIS] = {
12102d07eb4SAlistair Francis     0xFF040000, 0xFF050000,
12202d07eb4SAlistair Francis };
12302d07eb4SAlistair Francis 
12402d07eb4SAlistair Francis static const int spi_intr[XLNX_ZYNQMP_NUM_SPIS] = {
12502d07eb4SAlistair Francis     19, 20,
12602d07eb4SAlistair Francis };
12702d07eb4SAlistair Francis 
12804965bcaSFrancisco Iglesias static const uint64_t gdma_ch_addr[XLNX_ZYNQMP_NUM_GDMA_CH] = {
12904965bcaSFrancisco Iglesias     0xFD500000, 0xFD510000, 0xFD520000, 0xFD530000,
13004965bcaSFrancisco Iglesias     0xFD540000, 0xFD550000, 0xFD560000, 0xFD570000
13104965bcaSFrancisco Iglesias };
13204965bcaSFrancisco Iglesias 
13304965bcaSFrancisco Iglesias static const int gdma_ch_intr[XLNX_ZYNQMP_NUM_GDMA_CH] = {
13404965bcaSFrancisco Iglesias     124, 125, 126, 127, 128, 129, 130, 131
13504965bcaSFrancisco Iglesias };
13604965bcaSFrancisco Iglesias 
13704965bcaSFrancisco Iglesias static const uint64_t adma_ch_addr[XLNX_ZYNQMP_NUM_ADMA_CH] = {
13804965bcaSFrancisco Iglesias     0xFFA80000, 0xFFA90000, 0xFFAA0000, 0xFFAB0000,
13904965bcaSFrancisco Iglesias     0xFFAC0000, 0xFFAD0000, 0xFFAE0000, 0xFFAF0000
14004965bcaSFrancisco Iglesias };
14104965bcaSFrancisco Iglesias 
14204965bcaSFrancisco Iglesias static const int adma_ch_intr[XLNX_ZYNQMP_NUM_ADMA_CH] = {
14304965bcaSFrancisco Iglesias     77, 78, 79, 80, 81, 82, 83, 84
14404965bcaSFrancisco Iglesias };
14504965bcaSFrancisco Iglesias 
1467729e1f4SPeter Crosthwaite typedef struct XlnxZynqMPGICRegion {
1477729e1f4SPeter Crosthwaite     int region_index;
1487729e1f4SPeter Crosthwaite     uint32_t address;
14975b749afSLuc Michel     uint32_t offset;
15075b749afSLuc Michel     bool virt;
1517729e1f4SPeter Crosthwaite } XlnxZynqMPGICRegion;
1527729e1f4SPeter Crosthwaite 
1537729e1f4SPeter Crosthwaite static const XlnxZynqMPGICRegion xlnx_zynqmp_gic_regions[] = {
15475b749afSLuc Michel     /* Distributor */
15575b749afSLuc Michel     {
15675b749afSLuc Michel         .region_index = 0,
15775b749afSLuc Michel         .address = GIC_DIST_ADDR,
15875b749afSLuc Michel         .offset = 0,
15975b749afSLuc Michel         .virt = false
16075b749afSLuc Michel     },
16175b749afSLuc Michel 
16275b749afSLuc Michel     /* CPU interface */
16375b749afSLuc Michel     {
16475b749afSLuc Michel         .region_index = 1,
16575b749afSLuc Michel         .address = GIC_CPU_ADDR,
16675b749afSLuc Michel         .offset = 0,
16775b749afSLuc Michel         .virt = false
16875b749afSLuc Michel     },
16975b749afSLuc Michel     {
17075b749afSLuc Michel         .region_index = 1,
17175b749afSLuc Michel         .address = GIC_CPU_ADDR + 0x10000,
17275b749afSLuc Michel         .offset = 0x1000,
17375b749afSLuc Michel         .virt = false
17475b749afSLuc Michel     },
17575b749afSLuc Michel 
17675b749afSLuc Michel     /* Virtual interface */
17775b749afSLuc Michel     {
17875b749afSLuc Michel         .region_index = 2,
17975b749afSLuc Michel         .address = GIC_VIFACE_ADDR,
18075b749afSLuc Michel         .offset = 0,
18175b749afSLuc Michel         .virt = true
18275b749afSLuc Michel     },
18375b749afSLuc Michel 
18475b749afSLuc Michel     /* Virtual CPU interface */
18575b749afSLuc Michel     {
18675b749afSLuc Michel         .region_index = 3,
18775b749afSLuc Michel         .address = GIC_VCPU_ADDR,
18875b749afSLuc Michel         .offset = 0,
18975b749afSLuc Michel         .virt = true
19075b749afSLuc Michel     },
19175b749afSLuc Michel     {
19275b749afSLuc Michel         .region_index = 3,
19375b749afSLuc Michel         .address = GIC_VCPU_ADDR + 0x10000,
19475b749afSLuc Michel         .offset = 0x1000,
19575b749afSLuc Michel         .virt = true
19675b749afSLuc Michel     },
1977729e1f4SPeter Crosthwaite };
198f0a902f7SPeter Crosthwaite 
199bf4cb109SPeter Crosthwaite static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index)
200bf4cb109SPeter Crosthwaite {
201bf4cb109SPeter Crosthwaite     return GIC_NUM_SPI_INTR + cpu_nr * GIC_INTERNAL + ppi_index;
202bf4cb109SPeter Crosthwaite }
203bf4cb109SPeter Crosthwaite 
204cc7d44c2SLike Xu static void xlnx_zynqmp_create_rpu(MachineState *ms, XlnxZynqMPState *s,
205cc7d44c2SLike Xu                                    const char *boot_cpu, Error **errp)
2066ed92b14SEdgar E. Iglesias {
2076ed92b14SEdgar E. Iglesias     int i;
208cc7d44c2SLike Xu     int num_rpus = MIN(ms->smp.cpus - XLNX_ZYNQMP_NUM_APU_CPUS,
209cc7d44c2SLike Xu                        XLNX_ZYNQMP_NUM_RPU_CPUS);
2106ed92b14SEdgar E. Iglesias 
211e5b51753SPeter Maydell     if (num_rpus <= 0) {
212e5b51753SPeter Maydell         /* Don't create rpu-cluster object if there's nothing to put in it */
213e5b51753SPeter Maydell         return;
214e5b51753SPeter Maydell     }
215e5b51753SPeter Maydell 
216816fd397SLuc Michel     object_initialize_child(OBJECT(s), "rpu-cluster", &s->rpu_cluster,
2179fc7fc4dSMarkus Armbruster                             TYPE_CPU_CLUSTER);
218816fd397SLuc Michel     qdev_prop_set_uint32(DEVICE(&s->rpu_cluster), "cluster-id", 1);
219816fd397SLuc Michel 
2206908ec44SAlistair Francis     for (i = 0; i < num_rpus; i++) {
2217a309cc9SMarkus Armbruster         const char *name;
2226ed92b14SEdgar E. Iglesias 
223d0313798SPhilippe Mathieu-Daudé         object_initialize_child(OBJECT(&s->rpu_cluster), "rpu-cpu[*]",
2249fc7fc4dSMarkus Armbruster                                 &s->rpu_cpu[i],
2259fc7fc4dSMarkus Armbruster                                 ARM_CPU_TYPE_NAME("cortex-r5f"));
2266ed92b14SEdgar E. Iglesias 
2276ed92b14SEdgar E. Iglesias         name = object_get_canonical_path_component(OBJECT(&s->rpu_cpu[i]));
2286ed92b14SEdgar E. Iglesias         if (strcmp(name, boot_cpu)) {
22950c785f2SPeter Maydell             /*
23050c785f2SPeter Maydell              * Secondary CPUs start in powered-down state.
23150c785f2SPeter Maydell              */
2325325cc34SMarkus Armbruster             object_property_set_bool(OBJECT(&s->rpu_cpu[i]),
2335325cc34SMarkus Armbruster                                      "start-powered-off", true, &error_abort);
2346ed92b14SEdgar E. Iglesias         } else {
2356ed92b14SEdgar E. Iglesias             s->boot_cpu_ptr = &s->rpu_cpu[i];
2366ed92b14SEdgar E. Iglesias         }
2376ed92b14SEdgar E. Iglesias 
2385325cc34SMarkus Armbruster         object_property_set_bool(OBJECT(&s->rpu_cpu[i]), "reset-hivecs", true,
2396ed92b14SEdgar E. Iglesias                                  &error_abort);
240668f62ecSMarkus Armbruster         if (!qdev_realize(DEVICE(&s->rpu_cpu[i]), NULL, errp)) {
2416ed92b14SEdgar E. Iglesias             return;
2426ed92b14SEdgar E. Iglesias         }
2436ed92b14SEdgar E. Iglesias     }
244fa434424SPeter Maydell 
245ce189ab2SMarkus Armbruster     qdev_realize(DEVICE(&s->rpu_cluster), NULL, &error_fatal);
2466ed92b14SEdgar E. Iglesias }
2476ed92b14SEdgar E. Iglesias 
2487e47e15cSTong Ho static void xlnx_zynqmp_create_bbram(XlnxZynqMPState *s, qemu_irq *gic)
2497e47e15cSTong Ho {
2507e47e15cSTong Ho     SysBusDevice *sbd;
2517e47e15cSTong Ho 
2527e47e15cSTong Ho     object_initialize_child_with_props(OBJECT(s), "bbram", &s->bbram,
2537e47e15cSTong Ho                                        sizeof(s->bbram), TYPE_XLNX_BBRAM,
2547e47e15cSTong Ho                                        &error_fatal,
2557e47e15cSTong Ho                                        "crc-zpads", "1",
2567e47e15cSTong Ho                                        NULL);
2577e47e15cSTong Ho     sbd = SYS_BUS_DEVICE(&s->bbram);
2587e47e15cSTong Ho 
2597e47e15cSTong Ho     sysbus_realize(sbd, &error_fatal);
2607e47e15cSTong Ho     sysbus_mmio_map(sbd, 0, BBRAM_ADDR);
2617e47e15cSTong Ho     sysbus_connect_irq(sbd, 0, gic[BBRAM_IRQ]);
2627e47e15cSTong Ho }
2637e47e15cSTong Ho 
264db1264dfSTong Ho static void xlnx_zynqmp_create_efuse(XlnxZynqMPState *s, qemu_irq *gic)
265db1264dfSTong Ho {
266db1264dfSTong Ho     Object *bits = OBJECT(&s->efuse);
267db1264dfSTong Ho     Object *ctrl = OBJECT(&s->efuse_ctrl);
268db1264dfSTong Ho     SysBusDevice *sbd;
269db1264dfSTong Ho 
270db1264dfSTong Ho     object_initialize_child(OBJECT(s), "efuse-ctrl", &s->efuse_ctrl,
271db1264dfSTong Ho                             TYPE_XLNX_ZYNQMP_EFUSE);
272db1264dfSTong Ho 
273db1264dfSTong Ho     object_initialize_child_with_props(ctrl, "xlnx-efuse@0", bits,
274db1264dfSTong Ho                                        sizeof(s->efuse),
275db1264dfSTong Ho                                        TYPE_XLNX_EFUSE, &error_abort,
276db1264dfSTong Ho                                        "efuse-nr", "3",
277db1264dfSTong Ho                                        "efuse-size", "2048",
278db1264dfSTong Ho                                        NULL);
279db1264dfSTong Ho 
280db1264dfSTong Ho     qdev_realize(DEVICE(bits), NULL, &error_abort);
281db1264dfSTong Ho     object_property_set_link(ctrl, "efuse", bits, &error_abort);
282db1264dfSTong Ho 
283db1264dfSTong Ho     sbd = SYS_BUS_DEVICE(ctrl);
284db1264dfSTong Ho     sysbus_realize(sbd, &error_abort);
285db1264dfSTong Ho     sysbus_mmio_map(sbd, 0, EFUSE_ADDR);
286db1264dfSTong Ho     sysbus_connect_irq(sbd, 0, gic[EFUSE_IRQ]);
287db1264dfSTong Ho }
288db1264dfSTong Ho 
289eb7a38baSEdgar E. Iglesias static void xlnx_zynqmp_create_apu_ctrl(XlnxZynqMPState *s, qemu_irq *gic)
290eb7a38baSEdgar E. Iglesias {
291eb7a38baSEdgar E. Iglesias     SysBusDevice *sbd;
292eb7a38baSEdgar E. Iglesias     int i;
293eb7a38baSEdgar E. Iglesias 
294eb7a38baSEdgar E. Iglesias     object_initialize_child(OBJECT(s), "apu-ctrl", &s->apu_ctrl,
295eb7a38baSEdgar E. Iglesias                             TYPE_XLNX_ZYNQMP_APU_CTRL);
296eb7a38baSEdgar E. Iglesias     sbd = SYS_BUS_DEVICE(&s->apu_ctrl);
297eb7a38baSEdgar E. Iglesias 
298eb7a38baSEdgar E. Iglesias     for (i = 0; i < XLNX_ZYNQMP_NUM_APU_CPUS; i++) {
299eb7a38baSEdgar E. Iglesias         g_autofree gchar *name = g_strdup_printf("cpu%d", i);
300eb7a38baSEdgar E. Iglesias 
301eb7a38baSEdgar E. Iglesias         object_property_set_link(OBJECT(&s->apu_ctrl), name,
302eb7a38baSEdgar E. Iglesias                                  OBJECT(&s->apu_cpu[i]), &error_abort);
303eb7a38baSEdgar E. Iglesias     }
304eb7a38baSEdgar E. Iglesias 
305eb7a38baSEdgar E. Iglesias     sysbus_realize(sbd, &error_fatal);
306eb7a38baSEdgar E. Iglesias     sysbus_mmio_map(sbd, 0, APU_ADDR);
307eb7a38baSEdgar E. Iglesias     sysbus_connect_irq(sbd, 0, gic[APU_IRQ]);
308eb7a38baSEdgar E. Iglesias }
309eb7a38baSEdgar E. Iglesias 
31063320bcaSEdgar E. Iglesias static void xlnx_zynqmp_create_crf(XlnxZynqMPState *s, qemu_irq *gic)
31163320bcaSEdgar E. Iglesias {
31263320bcaSEdgar E. Iglesias     SysBusDevice *sbd;
31363320bcaSEdgar E. Iglesias 
31463320bcaSEdgar E. Iglesias     object_initialize_child(OBJECT(s), "crf", &s->crf, TYPE_XLNX_ZYNQMP_CRF);
31563320bcaSEdgar E. Iglesias     sbd = SYS_BUS_DEVICE(&s->crf);
31663320bcaSEdgar E. Iglesias 
31763320bcaSEdgar E. Iglesias     sysbus_realize(sbd, &error_fatal);
31863320bcaSEdgar E. Iglesias     sysbus_mmio_map(sbd, 0, CRF_ADDR);
31963320bcaSEdgar E. Iglesias     sysbus_connect_irq(sbd, 0, gic[CRF_IRQ]);
32063320bcaSEdgar E. Iglesias }
32163320bcaSEdgar E. Iglesias 
32251af6231SEdgar E. Iglesias static void xlnx_zynqmp_create_ttc(XlnxZynqMPState *s, qemu_irq *gic)
32351af6231SEdgar E. Iglesias {
32451af6231SEdgar E. Iglesias     SysBusDevice *sbd;
32551af6231SEdgar E. Iglesias     int i, irq;
32651af6231SEdgar E. Iglesias 
32751af6231SEdgar E. Iglesias     for (i = 0; i < XLNX_ZYNQMP_NUM_TTC; i++) {
32851af6231SEdgar E. Iglesias         object_initialize_child(OBJECT(s), "ttc[*]", &s->ttc[i],
32951af6231SEdgar E. Iglesias                                 TYPE_CADENCE_TTC);
33051af6231SEdgar E. Iglesias         sbd = SYS_BUS_DEVICE(&s->ttc[i]);
33151af6231SEdgar E. Iglesias 
33251af6231SEdgar E. Iglesias         sysbus_realize(sbd, &error_fatal);
33351af6231SEdgar E. Iglesias         sysbus_mmio_map(sbd, 0, TTC0_ADDR + i * 0x10000);
33451af6231SEdgar E. Iglesias         for (irq = 0; irq < 3; irq++) {
33551af6231SEdgar E. Iglesias             sysbus_connect_irq(sbd, irq, gic[TTC0_IRQ + i * 3 + irq]);
33651af6231SEdgar E. Iglesias         }
33751af6231SEdgar E. Iglesias     }
33851af6231SEdgar E. Iglesias }
33951af6231SEdgar E. Iglesias 
340d2e6f370STong Ho static void xlnx_zynqmp_create_unimp_mmio(XlnxZynqMPState *s)
341d2e6f370STong Ho {
342d2e6f370STong Ho     static const struct UnimpInfo {
343d2e6f370STong Ho         const char *name;
344d2e6f370STong Ho         hwaddr base;
345d2e6f370STong Ho         hwaddr size;
346d2e6f370STong Ho     } unimp_areas[ARRAY_SIZE(s->mr_unimp)] = {
347c28d4b86SEdgar E. Iglesias         { .name = "serdes", SERDES_ADDR, SERDES_SIZE },
348d2e6f370STong Ho     };
349d2e6f370STong Ho     unsigned int nr;
350d2e6f370STong Ho 
351d2e6f370STong Ho     for (nr = 0; nr < ARRAY_SIZE(unimp_areas); nr++) {
352d2e6f370STong Ho         const struct UnimpInfo *info = &unimp_areas[nr];
353d2e6f370STong Ho         DeviceState *dev = qdev_new(TYPE_UNIMPLEMENTED_DEVICE);
354d2e6f370STong Ho         SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
355d2e6f370STong Ho 
356d2e6f370STong Ho         assert(info->name && info->base && info->size > 0);
357d2e6f370STong Ho         qdev_prop_set_string(dev, "name", info->name);
358d2e6f370STong Ho         qdev_prop_set_uint64(dev, "size", info->size);
359d2e6f370STong Ho         object_property_add_child(OBJECT(s), info->name, OBJECT(dev));
360d2e6f370STong Ho 
361d2e6f370STong Ho         sysbus_realize_and_unref(sbd, &error_fatal);
362d2e6f370STong Ho         sysbus_mmio_map(sbd, 0, info->base);
363d2e6f370STong Ho     }
364d2e6f370STong Ho }
365d2e6f370STong Ho 
366f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_init(Object *obj)
367f0a902f7SPeter Crosthwaite {
368cc7d44c2SLike Xu     MachineState *ms = MACHINE(qdev_get_machine());
369f0a902f7SPeter Crosthwaite     XlnxZynqMPState *s = XLNX_ZYNQMP(obj);
370f0a902f7SPeter Crosthwaite     int i;
371cc7d44c2SLike Xu     int num_apus = MIN(ms->smp.cpus, XLNX_ZYNQMP_NUM_APU_CPUS);
372f0a902f7SPeter Crosthwaite 
373816fd397SLuc Michel     object_initialize_child(obj, "apu-cluster", &s->apu_cluster,
3749fc7fc4dSMarkus Armbruster                             TYPE_CPU_CLUSTER);
375816fd397SLuc Michel     qdev_prop_set_uint32(DEVICE(&s->apu_cluster), "cluster-id", 0);
376816fd397SLuc Michel 
3776908ec44SAlistair Francis     for (i = 0; i < num_apus; i++) {
378816fd397SLuc Michel         object_initialize_child(OBJECT(&s->apu_cluster), "apu-cpu[*]",
3799fc7fc4dSMarkus Armbruster                                 &s->apu_cpu[i],
3809fc7fc4dSMarkus Armbruster                                 ARM_CPU_TYPE_NAME("cortex-a53"));
381f0a902f7SPeter Crosthwaite     }
3827729e1f4SPeter Crosthwaite 
383db873cc5SMarkus Armbruster     object_initialize_child(obj, "gic", &s->gic, gic_class_name());
38414ca2e46SPeter Crosthwaite 
38514ca2e46SPeter Crosthwaite     for (i = 0; i < XLNX_ZYNQMP_NUM_GEMS; i++) {
386db873cc5SMarkus Armbruster         object_initialize_child(obj, "gem[*]", &s->gem[i], TYPE_CADENCE_GEM);
38714ca2e46SPeter Crosthwaite     }
3883bade2a9SPeter Crosthwaite 
3893bade2a9SPeter Crosthwaite     for (i = 0; i < XLNX_ZYNQMP_NUM_UARTS; i++) {
390db873cc5SMarkus Armbruster         object_initialize_child(obj, "uart[*]", &s->uart[i],
391ccf02d73SThomas Huth                                 TYPE_CADENCE_UART);
3923bade2a9SPeter Crosthwaite     }
3936fdf3282SAlistair Francis 
394840c22cdSVikram Garhwal     for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) {
395840c22cdSVikram Garhwal         object_initialize_child(obj, "can[*]", &s->can[i],
396840c22cdSVikram Garhwal                                 TYPE_XLNX_ZYNQMP_CAN);
397840c22cdSVikram Garhwal     }
398840c22cdSVikram Garhwal 
399db873cc5SMarkus Armbruster     object_initialize_child(obj, "sata", &s->sata, TYPE_SYSBUS_AHCI);
40033108e9fSSai Pavan Boddu 
40133108e9fSSai Pavan Boddu     for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) {
4025a147c8cSMarkus Armbruster         object_initialize_child(obj, "sdhci[*]", &s->sdhci[i],
4035a147c8cSMarkus Armbruster                                 TYPE_SYSBUS_SDHCI);
40433108e9fSSai Pavan Boddu     }
40502d07eb4SAlistair Francis 
40602d07eb4SAlistair Francis     for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) {
407db873cc5SMarkus Armbruster         object_initialize_child(obj, "spi[*]", &s->spi[i], TYPE_XILINX_SPIPS);
40802d07eb4SAlistair Francis     }
409b93dbcddSKONRAD Frederic 
410db873cc5SMarkus Armbruster     object_initialize_child(obj, "qspi", &s->qspi, TYPE_XLNX_ZYNQMP_QSPIPS);
411babc1f30SFrancisco Iglesias 
412db873cc5SMarkus Armbruster     object_initialize_child(obj, "xxxdp", &s->dp, TYPE_XLNX_DP);
413b93dbcddSKONRAD Frederic 
414db873cc5SMarkus Armbruster     object_initialize_child(obj, "dp-dma", &s->dpdma, TYPE_XLNX_DPDMA);
4150ab7bbc7SAlistair Francis 
416db873cc5SMarkus Armbruster     object_initialize_child(obj, "ipi", &s->ipi, TYPE_XLNX_ZYNQMP_IPI);
41708b2f15eSAlistair Francis 
418db873cc5SMarkus Armbruster     object_initialize_child(obj, "rtc", &s->rtc, TYPE_XLNX_ZYNQMP_RTC);
41904965bcaSFrancisco Iglesias 
42004965bcaSFrancisco Iglesias     for (i = 0; i < XLNX_ZYNQMP_NUM_GDMA_CH; i++) {
421db873cc5SMarkus Armbruster         object_initialize_child(obj, "gdma[*]", &s->gdma[i], TYPE_XLNX_ZDMA);
42204965bcaSFrancisco Iglesias     }
42304965bcaSFrancisco Iglesias 
42404965bcaSFrancisco Iglesias     for (i = 0; i < XLNX_ZYNQMP_NUM_ADMA_CH; i++) {
425db873cc5SMarkus Armbruster         object_initialize_child(obj, "adma[*]", &s->adma[i], TYPE_XLNX_ZDMA);
42604965bcaSFrancisco Iglesias     }
427668351a5SXuzhou Cheng 
428668351a5SXuzhou Cheng     object_initialize_child(obj, "qspi-dma", &s->qspi_dma, TYPE_XLNX_CSU_DMA);
429c74ccb5dSFrancisco Iglesias     object_initialize_child(obj, "qspi-irq-orgate",
430c74ccb5dSFrancisco Iglesias                             &s->qspi_irq_orgate, TYPE_OR_IRQ);
431f0a902f7SPeter Crosthwaite }
432f0a902f7SPeter Crosthwaite 
433f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
434f0a902f7SPeter Crosthwaite {
435cc7d44c2SLike Xu     MachineState *ms = MACHINE(qdev_get_machine());
436f0a902f7SPeter Crosthwaite     XlnxZynqMPState *s = XLNX_ZYNQMP(dev);
4377729e1f4SPeter Crosthwaite     MemoryRegion *system_memory = get_system_memory();
438f0a902f7SPeter Crosthwaite     uint8_t i;
439dc3b89efSAlistair Francis     uint64_t ram_size;
440cc7d44c2SLike Xu     int num_apus = MIN(ms->smp.cpus, XLNX_ZYNQMP_NUM_APU_CPUS);
4416396a193SPeter Crosthwaite     const char *boot_cpu = s->boot_cpu ? s->boot_cpu : "apu-cpu[0]";
442dc3b89efSAlistair Francis     ram_addr_t ddr_low_size, ddr_high_size;
44314ca2e46SPeter Crosthwaite     qemu_irq gic_spi[GIC_NUM_SPI_INTR];
444f0a902f7SPeter Crosthwaite     Error *err = NULL;
445f0a902f7SPeter Crosthwaite 
446dc3b89efSAlistair Francis     ram_size = memory_region_size(s->ddr_ram);
447dc3b89efSAlistair Francis 
44821bce371SXuzhou Cheng     /*
44921bce371SXuzhou Cheng      * Create the DDR Memory Regions. User friendly checks should happen at
450dc3b89efSAlistair Francis      * the board level
451dc3b89efSAlistair Francis      */
452dc3b89efSAlistair Francis     if (ram_size > XLNX_ZYNQMP_MAX_LOW_RAM_SIZE) {
45321bce371SXuzhou Cheng         /*
45421bce371SXuzhou Cheng          * The RAM size is above the maximum available for the low DDR.
455dc3b89efSAlistair Francis          * Create the high DDR memory region as well.
456dc3b89efSAlistair Francis          */
457dc3b89efSAlistair Francis         assert(ram_size <= XLNX_ZYNQMP_MAX_RAM_SIZE);
458dc3b89efSAlistair Francis         ddr_low_size = XLNX_ZYNQMP_MAX_LOW_RAM_SIZE;
459dc3b89efSAlistair Francis         ddr_high_size = ram_size - XLNX_ZYNQMP_MAX_LOW_RAM_SIZE;
460dc3b89efSAlistair Francis 
46132b9523aSPhilippe Mathieu-Daudé         memory_region_init_alias(&s->ddr_ram_high, OBJECT(dev),
46232b9523aSPhilippe Mathieu-Daudé                                  "ddr-ram-high", s->ddr_ram, ddr_low_size,
46332b9523aSPhilippe Mathieu-Daudé                                  ddr_high_size);
464dc3b89efSAlistair Francis         memory_region_add_subregion(get_system_memory(),
465dc3b89efSAlistair Francis                                     XLNX_ZYNQMP_HIGH_RAM_START,
466dc3b89efSAlistair Francis                                     &s->ddr_ram_high);
467dc3b89efSAlistair Francis     } else {
468dc3b89efSAlistair Francis         /* RAM must be non-zero */
469dc3b89efSAlistair Francis         assert(ram_size);
470dc3b89efSAlistair Francis         ddr_low_size = ram_size;
471dc3b89efSAlistair Francis     }
472dc3b89efSAlistair Francis 
47332b9523aSPhilippe Mathieu-Daudé     memory_region_init_alias(&s->ddr_ram_low, OBJECT(dev), "ddr-ram-low",
47432b9523aSPhilippe Mathieu-Daudé                              s->ddr_ram, 0, ddr_low_size);
475dc3b89efSAlistair Francis     memory_region_add_subregion(get_system_memory(), 0, &s->ddr_ram_low);
476dc3b89efSAlistair Francis 
4776675d719SAlistair Francis     /* Create the four OCM banks */
4786675d719SAlistair Francis     for (i = 0; i < XLNX_ZYNQMP_NUM_OCM_BANKS; i++) {
4796675d719SAlistair Francis         char *ocm_name = g_strdup_printf("zynqmp.ocm_ram_bank_%d", i);
4806675d719SAlistair Francis 
48198a99ce0SPeter Maydell         memory_region_init_ram(&s->ocm_ram[i], NULL, ocm_name,
482f8ed85acSMarkus Armbruster                                XLNX_ZYNQMP_OCM_RAM_SIZE, &error_fatal);
4836675d719SAlistair Francis         memory_region_add_subregion(get_system_memory(),
4846675d719SAlistair Francis                                     XLNX_ZYNQMP_OCM_RAM_0_ADDRESS +
4856675d719SAlistair Francis                                         i * XLNX_ZYNQMP_OCM_RAM_SIZE,
4866675d719SAlistair Francis                                     &s->ocm_ram[i]);
4876675d719SAlistair Francis 
4886675d719SAlistair Francis         g_free(ocm_name);
4896675d719SAlistair Francis     }
4906675d719SAlistair Francis 
4917729e1f4SPeter Crosthwaite     qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", GIC_NUM_SPI_INTR + 32);
4927729e1f4SPeter Crosthwaite     qdev_prop_set_uint32(DEVICE(&s->gic), "revision", 2);
4936908ec44SAlistair Francis     qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", num_apus);
49475b749afSLuc Michel     qdev_prop_set_bit(DEVICE(&s->gic), "has-security-extensions", s->secure);
49575b749afSLuc Michel     qdev_prop_set_bit(DEVICE(&s->gic),
49675b749afSLuc Michel                       "has-virtualization-extensions", s->virt);
4977729e1f4SPeter Crosthwaite 
498ce189ab2SMarkus Armbruster     qdev_realize(DEVICE(&s->apu_cluster), NULL, &error_fatal);
499816fd397SLuc Michel 
5000776d967SEdgar E. Iglesias     /* Realize APUs before realizing the GIC. KVM requires this.  */
5016908ec44SAlistair Francis     for (i = 0; i < num_apus; i++) {
5027a309cc9SMarkus Armbruster         const char *name;
503bf4cb109SPeter Crosthwaite 
5046396a193SPeter Crosthwaite         name = object_get_canonical_path_component(OBJECT(&s->apu_cpu[i]));
5056396a193SPeter Crosthwaite         if (strcmp(name, boot_cpu)) {
50650c785f2SPeter Maydell             /*
50750c785f2SPeter Maydell              * Secondary CPUs start in powered-down state.
50850c785f2SPeter Maydell              */
5095325cc34SMarkus Armbruster             object_property_set_bool(OBJECT(&s->apu_cpu[i]),
5105325cc34SMarkus Armbruster                                      "start-powered-off", true, &error_abort);
5116396a193SPeter Crosthwaite         } else {
5126396a193SPeter Crosthwaite             s->boot_cpu_ptr = &s->apu_cpu[i];
513f0a902f7SPeter Crosthwaite         }
514f0a902f7SPeter Crosthwaite 
5155325cc34SMarkus Armbruster         object_property_set_bool(OBJECT(&s->apu_cpu[i]), "has_el3", s->secure,
5165325cc34SMarkus Armbruster                                  NULL);
5175325cc34SMarkus Armbruster         object_property_set_bool(OBJECT(&s->apu_cpu[i]), "has_el2", s->virt,
5185325cc34SMarkus Armbruster                                  NULL);
5195325cc34SMarkus Armbruster         object_property_set_int(OBJECT(&s->apu_cpu[i]), "reset-cbar",
5205325cc34SMarkus Armbruster                                 GIC_BASE_ADDR, &error_abort);
5215325cc34SMarkus Armbruster         object_property_set_int(OBJECT(&s->apu_cpu[i]), "core-count",
5225325cc34SMarkus Armbruster                                 num_apus, &error_abort);
523668f62ecSMarkus Armbruster         if (!qdev_realize(DEVICE(&s->apu_cpu[i]), NULL, errp)) {
524f0a902f7SPeter Crosthwaite             return;
525f0a902f7SPeter Crosthwaite         }
5260776d967SEdgar E. Iglesias     }
5270776d967SEdgar E. Iglesias 
528668f62ecSMarkus Armbruster     if (!sysbus_realize(SYS_BUS_DEVICE(&s->gic), errp)) {
5290776d967SEdgar E. Iglesias         return;
5300776d967SEdgar E. Iglesias     }
5310776d967SEdgar E. Iglesias 
5320776d967SEdgar E. Iglesias     assert(ARRAY_SIZE(xlnx_zynqmp_gic_regions) == XLNX_ZYNQMP_GIC_REGIONS);
5330776d967SEdgar E. Iglesias     for (i = 0; i < XLNX_ZYNQMP_GIC_REGIONS; i++) {
5340776d967SEdgar E. Iglesias         SysBusDevice *gic = SYS_BUS_DEVICE(&s->gic);
5350776d967SEdgar E. Iglesias         const XlnxZynqMPGICRegion *r = &xlnx_zynqmp_gic_regions[i];
53675b749afSLuc Michel         MemoryRegion *mr;
5370776d967SEdgar E. Iglesias         uint32_t addr = r->address;
5380776d967SEdgar E. Iglesias         int j;
5390776d967SEdgar E. Iglesias 
54075b749afSLuc Michel         if (r->virt && !s->virt) {
54175b749afSLuc Michel             continue;
54275b749afSLuc Michel         }
5430776d967SEdgar E. Iglesias 
54475b749afSLuc Michel         mr = sysbus_mmio_get_region(gic, r->region_index);
5450776d967SEdgar E. Iglesias         for (j = 0; j < XLNX_ZYNQMP_GIC_ALIASES; j++) {
5460776d967SEdgar E. Iglesias             MemoryRegion *alias = &s->gic_mr[i][j];
5470776d967SEdgar E. Iglesias 
5480776d967SEdgar E. Iglesias             memory_region_init_alias(alias, OBJECT(s), "zynqmp-gic-alias", mr,
54975b749afSLuc Michel                                      r->offset, XLNX_ZYNQMP_GIC_REGION_SIZE);
5500776d967SEdgar E. Iglesias             memory_region_add_subregion(system_memory, addr, alias);
55175b749afSLuc Michel 
55275b749afSLuc Michel             addr += XLNX_ZYNQMP_GIC_REGION_SIZE;
5530776d967SEdgar E. Iglesias         }
5540776d967SEdgar E. Iglesias     }
5550776d967SEdgar E. Iglesias 
5566908ec44SAlistair Francis     for (i = 0; i < num_apus; i++) {
5570776d967SEdgar E. Iglesias         qemu_irq irq;
5587729e1f4SPeter Crosthwaite 
5597729e1f4SPeter Crosthwaite         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i,
5602e5577bcSPeter Crosthwaite                            qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]),
5612e5577bcSPeter Crosthwaite                                             ARM_CPU_IRQ));
56275b749afSLuc Michel         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + num_apus,
56375b749afSLuc Michel                            qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]),
56475b749afSLuc Michel                                             ARM_CPU_FIQ));
56575b749afSLuc Michel         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + num_apus * 2,
56675b749afSLuc Michel                            qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]),
56775b749afSLuc Michel                                             ARM_CPU_VIRQ));
56875b749afSLuc Michel         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + num_apus * 3,
56975b749afSLuc Michel                            qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]),
57075b749afSLuc Michel                                             ARM_CPU_VFIQ));
571bf4cb109SPeter Crosthwaite         irq = qdev_get_gpio_in(DEVICE(&s->gic),
572bf4cb109SPeter Crosthwaite                                arm_gic_ppi_index(i, ARM_PHYS_TIMER_PPI));
57375b749afSLuc Michel         qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), GTIMER_PHYS, irq);
574bf4cb109SPeter Crosthwaite         irq = qdev_get_gpio_in(DEVICE(&s->gic),
575bf4cb109SPeter Crosthwaite                                arm_gic_ppi_index(i, ARM_VIRT_TIMER_PPI));
57675b749afSLuc Michel         qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), GTIMER_VIRT, irq);
57775b749afSLuc Michel         irq = qdev_get_gpio_in(DEVICE(&s->gic),
57875b749afSLuc Michel                                arm_gic_ppi_index(i, ARM_HYP_TIMER_PPI));
57975b749afSLuc Michel         qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), GTIMER_HYP, irq);
58075b749afSLuc Michel         irq = qdev_get_gpio_in(DEVICE(&s->gic),
58175b749afSLuc Michel                                arm_gic_ppi_index(i, ARM_SEC_TIMER_PPI));
58275b749afSLuc Michel         qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), GTIMER_SEC, irq);
58375b749afSLuc Michel 
58475b749afSLuc Michel         if (s->virt) {
58575b749afSLuc Michel             irq = qdev_get_gpio_in(DEVICE(&s->gic),
58675b749afSLuc Michel                                    arm_gic_ppi_index(i, GIC_MAINTENANCE_PPI));
58775b749afSLuc Michel             sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + num_apus * 4, irq);
58875b749afSLuc Michel         }
589f0a902f7SPeter Crosthwaite     }
59014ca2e46SPeter Crosthwaite 
591cc7d44c2SLike Xu     xlnx_zynqmp_create_rpu(ms, s, boot_cpu, &err);
592b58850e7SPeter Crosthwaite     if (err) {
59324cfc8dcSAlistair Francis         error_propagate(errp, err);
594b58850e7SPeter Crosthwaite         return;
595b58850e7SPeter Crosthwaite     }
596b58850e7SPeter Crosthwaite 
5976396a193SPeter Crosthwaite     if (!s->boot_cpu_ptr) {
5989af9e0feSMarkus Armbruster         error_setg(errp, "ZynqMP Boot cpu %s not found", boot_cpu);
5996396a193SPeter Crosthwaite         return;
6006396a193SPeter Crosthwaite     }
6016396a193SPeter Crosthwaite 
60214ca2e46SPeter Crosthwaite     for (i = 0; i < GIC_NUM_SPI_INTR; i++) {
60314ca2e46SPeter Crosthwaite         gic_spi[i] = qdev_get_gpio_in(DEVICE(&s->gic), i);
60414ca2e46SPeter Crosthwaite     }
60514ca2e46SPeter Crosthwaite 
60614ca2e46SPeter Crosthwaite     for (i = 0; i < XLNX_ZYNQMP_NUM_GEMS; i++) {
60714ca2e46SPeter Crosthwaite         NICInfo *nd = &nd_table[i];
60814ca2e46SPeter Crosthwaite 
6097ad36e2eSMarkus Armbruster         /* FIXME use qdev NIC properties instead of nd_table[] */
61014ca2e46SPeter Crosthwaite         if (nd->used) {
61114ca2e46SPeter Crosthwaite             qemu_check_nic_model(nd, TYPE_CADENCE_GEM);
61214ca2e46SPeter Crosthwaite             qdev_set_nic_properties(DEVICE(&s->gem[i]), nd);
61314ca2e46SPeter Crosthwaite         }
6145325cc34SMarkus Armbruster         object_property_set_int(OBJECT(&s->gem[i]), "revision", GEM_REVISION,
61520bff213SAlistair Francis                                 &error_abort);
616dfc38879SBin Meng         object_property_set_int(OBJECT(&s->gem[i]), "phy-addr", 23,
617dfc38879SBin Meng                                 &error_abort);
6185325cc34SMarkus Armbruster         object_property_set_int(OBJECT(&s->gem[i]), "num-priority-queues", 2,
6191372fc0bSAlistair Francis                                 &error_abort);
620668f62ecSMarkus Armbruster         if (!sysbus_realize(SYS_BUS_DEVICE(&s->gem[i]), errp)) {
62114ca2e46SPeter Crosthwaite             return;
62214ca2e46SPeter Crosthwaite         }
62314ca2e46SPeter Crosthwaite         sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem[i]), 0, gem_addr[i]);
62414ca2e46SPeter Crosthwaite         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem[i]), 0,
62514ca2e46SPeter Crosthwaite                            gic_spi[gem_intr[i]]);
62614ca2e46SPeter Crosthwaite     }
6273bade2a9SPeter Crosthwaite 
6283bade2a9SPeter Crosthwaite     for (i = 0; i < XLNX_ZYNQMP_NUM_UARTS; i++) {
6299bca0edbSPeter Maydell         qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
630668f62ecSMarkus Armbruster         if (!sysbus_realize(SYS_BUS_DEVICE(&s->uart[i]), errp)) {
6313bade2a9SPeter Crosthwaite             return;
6323bade2a9SPeter Crosthwaite         }
6333bade2a9SPeter Crosthwaite         sysbus_mmio_map(SYS_BUS_DEVICE(&s->uart[i]), 0, uart_addr[i]);
6343bade2a9SPeter Crosthwaite         sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart[i]), 0,
6353bade2a9SPeter Crosthwaite                            gic_spi[uart_intr[i]]);
6363bade2a9SPeter Crosthwaite     }
6376fdf3282SAlistair Francis 
638840c22cdSVikram Garhwal     for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) {
639840c22cdSVikram Garhwal         object_property_set_int(OBJECT(&s->can[i]), "ext_clk_freq",
640840c22cdSVikram Garhwal                                 XLNX_ZYNQMP_CAN_REF_CLK, &error_abort);
641840c22cdSVikram Garhwal 
642840c22cdSVikram Garhwal         object_property_set_link(OBJECT(&s->can[i]), "canbus",
643840c22cdSVikram Garhwal                                  OBJECT(s->canbus[i]), &error_fatal);
644840c22cdSVikram Garhwal 
645840c22cdSVikram Garhwal         sysbus_realize(SYS_BUS_DEVICE(&s->can[i]), &err);
646840c22cdSVikram Garhwal         if (err) {
647840c22cdSVikram Garhwal             error_propagate(errp, err);
648840c22cdSVikram Garhwal             return;
649840c22cdSVikram Garhwal         }
650840c22cdSVikram Garhwal         sysbus_mmio_map(SYS_BUS_DEVICE(&s->can[i]), 0, can_addr[i]);
651840c22cdSVikram Garhwal         sysbus_connect_irq(SYS_BUS_DEVICE(&s->can[i]), 0,
652840c22cdSVikram Garhwal                            gic_spi[can_intr[i]]);
653840c22cdSVikram Garhwal     }
654840c22cdSVikram Garhwal 
6555325cc34SMarkus Armbruster     object_property_set_int(OBJECT(&s->sata), "num-ports", SATA_NUM_PORTS,
6566fdf3282SAlistair Francis                             &error_abort);
657668f62ecSMarkus Armbruster     if (!sysbus_realize(SYS_BUS_DEVICE(&s->sata), errp)) {
6586fdf3282SAlistair Francis         return;
6596fdf3282SAlistair Francis     }
6606fdf3282SAlistair Francis 
6616fdf3282SAlistair Francis     sysbus_mmio_map(SYS_BUS_DEVICE(&s->sata), 0, SATA_ADDR);
6626fdf3282SAlistair Francis     sysbus_connect_irq(SYS_BUS_DEVICE(&s->sata), 0, gic_spi[SATA_INTR]);
66333108e9fSSai Pavan Boddu 
66433108e9fSSai Pavan Boddu     for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) {
66563fef628SPeter Maydell         char *bus_name;
666b630d3d4SPhilippe Mathieu-Daudé         SysBusDevice *sbd = SYS_BUS_DEVICE(&s->sdhci[i]);
667b630d3d4SPhilippe Mathieu-Daudé         Object *sdhci = OBJECT(&s->sdhci[i]);
668eb4f566bSPeter Maydell 
66921bce371SXuzhou Cheng         /*
67021bce371SXuzhou Cheng          * Compatible with:
671b630d3d4SPhilippe Mathieu-Daudé          * - SD Host Controller Specification Version 3.00
672b630d3d4SPhilippe Mathieu-Daudé          * - SDIO Specification Version 3.0
673b630d3d4SPhilippe Mathieu-Daudé          * - eMMC Specification Version 4.51
674b630d3d4SPhilippe Mathieu-Daudé          */
675668f62ecSMarkus Armbruster         if (!object_property_set_uint(sdhci, "sd-spec-version", 3, errp)) {
676660b4e70SPeter Maydell             return;
677660b4e70SPeter Maydell         }
678778a2dc5SMarkus Armbruster         if (!object_property_set_uint(sdhci, "capareg", SDHCI_CAPABILITIES,
679668f62ecSMarkus Armbruster                                       errp)) {
680660b4e70SPeter Maydell             return;
681660b4e70SPeter Maydell         }
682668f62ecSMarkus Armbruster         if (!object_property_set_uint(sdhci, "uhs", UHS_I, errp)) {
683660b4e70SPeter Maydell             return;
684660b4e70SPeter Maydell         }
685668f62ecSMarkus Armbruster         if (!sysbus_realize(SYS_BUS_DEVICE(sdhci), errp)) {
68633108e9fSSai Pavan Boddu             return;
68733108e9fSSai Pavan Boddu         }
688b630d3d4SPhilippe Mathieu-Daudé         sysbus_mmio_map(sbd, 0, sdhci_addr[i]);
689b630d3d4SPhilippe Mathieu-Daudé         sysbus_connect_irq(sbd, 0, gic_spi[sdhci_intr[i]]);
690b630d3d4SPhilippe Mathieu-Daudé 
691eb4f566bSPeter Maydell         /* Alias controller SD bus to the SoC itself */
69263fef628SPeter Maydell         bus_name = g_strdup_printf("sd-bus%d", i);
693d2623129SMarkus Armbruster         object_property_add_alias(OBJECT(s), bus_name, sdhci, "sd-bus");
694eb4f566bSPeter Maydell         g_free(bus_name);
69533108e9fSSai Pavan Boddu     }
69602d07eb4SAlistair Francis 
69702d07eb4SAlistair Francis     for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) {
69802d07eb4SAlistair Francis         gchar *bus_name;
69902d07eb4SAlistair Francis 
700668f62ecSMarkus Armbruster         if (!sysbus_realize(SYS_BUS_DEVICE(&s->spi[i]), errp)) {
701660b4e70SPeter Maydell             return;
702660b4e70SPeter Maydell         }
70302d07eb4SAlistair Francis 
70402d07eb4SAlistair Francis         sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0, spi_addr[i]);
70502d07eb4SAlistair Francis         sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi[i]), 0,
70602d07eb4SAlistair Francis                            gic_spi[spi_intr[i]]);
70702d07eb4SAlistair Francis 
70802d07eb4SAlistair Francis         /* Alias controller SPI bus to the SoC itself */
70902d07eb4SAlistair Francis         bus_name = g_strdup_printf("spi%d", i);
71002d07eb4SAlistair Francis         object_property_add_alias(OBJECT(s), bus_name,
711d2623129SMarkus Armbruster                                   OBJECT(&s->spi[i]), "spi0");
71202d07eb4SAlistair Francis         g_free(bus_name);
71302d07eb4SAlistair Francis     }
714b93dbcddSKONRAD Frederic 
715668f62ecSMarkus Armbruster     if (!sysbus_realize(SYS_BUS_DEVICE(&s->dp), errp)) {
716b93dbcddSKONRAD Frederic         return;
717b93dbcddSKONRAD Frederic     }
718b93dbcddSKONRAD Frederic     sysbus_mmio_map(SYS_BUS_DEVICE(&s->dp), 0, DP_ADDR);
719b93dbcddSKONRAD Frederic     sysbus_connect_irq(SYS_BUS_DEVICE(&s->dp), 0, gic_spi[DP_IRQ]);
720b93dbcddSKONRAD Frederic 
721668f62ecSMarkus Armbruster     if (!sysbus_realize(SYS_BUS_DEVICE(&s->dpdma), errp)) {
722b93dbcddSKONRAD Frederic         return;
723b93dbcddSKONRAD Frederic     }
7245325cc34SMarkus Armbruster     object_property_set_link(OBJECT(&s->dp), "dpdma", OBJECT(&s->dpdma),
725b93dbcddSKONRAD Frederic                              &error_abort);
726b93dbcddSKONRAD Frederic     sysbus_mmio_map(SYS_BUS_DEVICE(&s->dpdma), 0, DPDMA_ADDR);
727b93dbcddSKONRAD Frederic     sysbus_connect_irq(SYS_BUS_DEVICE(&s->dpdma), 0, gic_spi[DPDMA_IRQ]);
7280ab7bbc7SAlistair Francis 
729668f62ecSMarkus Armbruster     if (!sysbus_realize(SYS_BUS_DEVICE(&s->ipi), errp)) {
7300ab7bbc7SAlistair Francis         return;
7310ab7bbc7SAlistair Francis     }
7320ab7bbc7SAlistair Francis     sysbus_mmio_map(SYS_BUS_DEVICE(&s->ipi), 0, IPI_ADDR);
7330ab7bbc7SAlistair Francis     sysbus_connect_irq(SYS_BUS_DEVICE(&s->ipi), 0, gic_spi[IPI_IRQ]);
73408b2f15eSAlistair Francis 
735668f62ecSMarkus Armbruster     if (!sysbus_realize(SYS_BUS_DEVICE(&s->rtc), errp)) {
73608b2f15eSAlistair Francis         return;
73708b2f15eSAlistair Francis     }
73808b2f15eSAlistair Francis     sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, RTC_ADDR);
73908b2f15eSAlistair Francis     sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0, gic_spi[RTC_IRQ]);
74004965bcaSFrancisco Iglesias 
7417e47e15cSTong Ho     xlnx_zynqmp_create_bbram(s, gic_spi);
742db1264dfSTong Ho     xlnx_zynqmp_create_efuse(s, gic_spi);
743eb7a38baSEdgar E. Iglesias     xlnx_zynqmp_create_apu_ctrl(s, gic_spi);
74463320bcaSEdgar E. Iglesias     xlnx_zynqmp_create_crf(s, gic_spi);
74551af6231SEdgar E. Iglesias     xlnx_zynqmp_create_ttc(s, gic_spi);
746d2e6f370STong Ho     xlnx_zynqmp_create_unimp_mmio(s);
747d2e6f370STong Ho 
74804965bcaSFrancisco Iglesias     for (i = 0; i < XLNX_ZYNQMP_NUM_GDMA_CH; i++) {
749778a2dc5SMarkus Armbruster         if (!object_property_set_uint(OBJECT(&s->gdma[i]), "bus-width", 128,
750668f62ecSMarkus Armbruster                                       errp)) {
751660b4e70SPeter Maydell             return;
752660b4e70SPeter Maydell         }
753783dbab1SPhilippe Mathieu-Daudé         if (!object_property_set_link(OBJECT(&s->gdma[i]), "dma",
754783dbab1SPhilippe Mathieu-Daudé                                       OBJECT(system_memory), errp)) {
755783dbab1SPhilippe Mathieu-Daudé             return;
756783dbab1SPhilippe Mathieu-Daudé         }
757668f62ecSMarkus Armbruster         if (!sysbus_realize(SYS_BUS_DEVICE(&s->gdma[i]), errp)) {
75804965bcaSFrancisco Iglesias             return;
75904965bcaSFrancisco Iglesias         }
76004965bcaSFrancisco Iglesias 
76104965bcaSFrancisco Iglesias         sysbus_mmio_map(SYS_BUS_DEVICE(&s->gdma[i]), 0, gdma_ch_addr[i]);
76204965bcaSFrancisco Iglesias         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gdma[i]), 0,
76304965bcaSFrancisco Iglesias                            gic_spi[gdma_ch_intr[i]]);
76404965bcaSFrancisco Iglesias     }
76504965bcaSFrancisco Iglesias 
76604965bcaSFrancisco Iglesias     for (i = 0; i < XLNX_ZYNQMP_NUM_ADMA_CH; i++) {
767783dbab1SPhilippe Mathieu-Daudé         if (!object_property_set_link(OBJECT(&s->adma[i]), "dma",
768783dbab1SPhilippe Mathieu-Daudé                                       OBJECT(system_memory), errp)) {
769783dbab1SPhilippe Mathieu-Daudé             return;
770783dbab1SPhilippe Mathieu-Daudé         }
771668f62ecSMarkus Armbruster         if (!sysbus_realize(SYS_BUS_DEVICE(&s->adma[i]), errp)) {
77204965bcaSFrancisco Iglesias             return;
77304965bcaSFrancisco Iglesias         }
77404965bcaSFrancisco Iglesias 
77504965bcaSFrancisco Iglesias         sysbus_mmio_map(SYS_BUS_DEVICE(&s->adma[i]), 0, adma_ch_addr[i]);
77604965bcaSFrancisco Iglesias         sysbus_connect_irq(SYS_BUS_DEVICE(&s->adma[i]), 0,
77704965bcaSFrancisco Iglesias                            gic_spi[adma_ch_intr[i]]);
77804965bcaSFrancisco Iglesias     }
779668351a5SXuzhou Cheng 
780c74ccb5dSFrancisco Iglesias     object_property_set_int(OBJECT(&s->qspi_irq_orgate),
781c74ccb5dSFrancisco Iglesias                             "num-lines", NUM_QSPI_IRQ_LINES, &error_fatal);
782c74ccb5dSFrancisco Iglesias     qdev_realize(DEVICE(&s->qspi_irq_orgate), NULL, &error_fatal);
783c74ccb5dSFrancisco Iglesias     qdev_connect_gpio_out(DEVICE(&s->qspi_irq_orgate), 0, gic_spi[QSPI_IRQ]);
784c74ccb5dSFrancisco Iglesias 
785c31b7f59SPhilippe Mathieu-Daudé     if (!object_property_set_link(OBJECT(&s->qspi_dma), "dma",
786c31b7f59SPhilippe Mathieu-Daudé                                   OBJECT(system_memory), errp)) {
787c31b7f59SPhilippe Mathieu-Daudé         return;
788c31b7f59SPhilippe Mathieu-Daudé     }
789668351a5SXuzhou Cheng     if (!sysbus_realize(SYS_BUS_DEVICE(&s->qspi_dma), errp)) {
790668351a5SXuzhou Cheng         return;
791668351a5SXuzhou Cheng     }
792668351a5SXuzhou Cheng 
793668351a5SXuzhou Cheng     sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi_dma), 0, QSPI_DMA_ADDR);
794c74ccb5dSFrancisco Iglesias     sysbus_connect_irq(SYS_BUS_DEVICE(&s->qspi_dma), 0,
795c74ccb5dSFrancisco Iglesias                        qdev_get_gpio_in(DEVICE(&s->qspi_irq_orgate), 0));
79634a3a71dSPhilippe Mathieu-Daudé 
79734a3a71dSPhilippe Mathieu-Daudé     if (!object_property_set_link(OBJECT(&s->qspi), "stream-connected-dma",
79834a3a71dSPhilippe Mathieu-Daudé                                   OBJECT(&s->qspi_dma), errp)) {
79934a3a71dSPhilippe Mathieu-Daudé          return;
80034a3a71dSPhilippe Mathieu-Daudé     }
80134a3a71dSPhilippe Mathieu-Daudé     if (!sysbus_realize(SYS_BUS_DEVICE(&s->qspi), errp)) {
80234a3a71dSPhilippe Mathieu-Daudé         return;
80334a3a71dSPhilippe Mathieu-Daudé     }
80434a3a71dSPhilippe Mathieu-Daudé     sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi), 0, QSPI_ADDR);
80534a3a71dSPhilippe Mathieu-Daudé     sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi), 1, LQSPI_ADDR);
806c74ccb5dSFrancisco Iglesias     sysbus_connect_irq(SYS_BUS_DEVICE(&s->qspi), 0,
807c74ccb5dSFrancisco Iglesias                        qdev_get_gpio_in(DEVICE(&s->qspi_irq_orgate), 1));
80834a3a71dSPhilippe Mathieu-Daudé 
80934a3a71dSPhilippe Mathieu-Daudé     for (i = 0; i < XLNX_ZYNQMP_NUM_QSPI_BUS; i++) {
81034a3a71dSPhilippe Mathieu-Daudé         g_autofree gchar *bus_name = g_strdup_printf("qspi%d", i);
81134a3a71dSPhilippe Mathieu-Daudé         g_autofree gchar *target_bus = g_strdup_printf("spi%d", i);
81234a3a71dSPhilippe Mathieu-Daudé 
81334a3a71dSPhilippe Mathieu-Daudé         /* Alias controller SPI bus to the SoC itself */
81434a3a71dSPhilippe Mathieu-Daudé         object_property_add_alias(OBJECT(s), bus_name,
81534a3a71dSPhilippe Mathieu-Daudé                                   OBJECT(&s->qspi), target_bus);
81634a3a71dSPhilippe Mathieu-Daudé     }
817f0a902f7SPeter Crosthwaite }
818f0a902f7SPeter Crosthwaite 
8196396a193SPeter Crosthwaite static Property xlnx_zynqmp_props[] = {
8206396a193SPeter Crosthwaite     DEFINE_PROP_STRING("boot-cpu", XlnxZynqMPState, boot_cpu),
82137d42473SEdgar E. Iglesias     DEFINE_PROP_BOOL("secure", XlnxZynqMPState, secure, false),
8221946809eSAlistair Francis     DEFINE_PROP_BOOL("virtualization", XlnxZynqMPState, virt, false),
823c3acfa01SFam Zheng     DEFINE_PROP_LINK("ddr-ram", XlnxZynqMPState, ddr_ram, TYPE_MEMORY_REGION,
824c3acfa01SFam Zheng                      MemoryRegion *),
825840c22cdSVikram Garhwal     DEFINE_PROP_LINK("canbus0", XlnxZynqMPState, canbus[0], TYPE_CAN_BUS,
826840c22cdSVikram Garhwal                      CanBusState *),
827840c22cdSVikram Garhwal     DEFINE_PROP_LINK("canbus1", XlnxZynqMPState, canbus[1], TYPE_CAN_BUS,
828840c22cdSVikram Garhwal                      CanBusState *),
8296396a193SPeter Crosthwaite     DEFINE_PROP_END_OF_LIST()
8306396a193SPeter Crosthwaite };
8316396a193SPeter Crosthwaite 
832f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_class_init(ObjectClass *oc, void *data)
833f0a902f7SPeter Crosthwaite {
834f0a902f7SPeter Crosthwaite     DeviceClass *dc = DEVICE_CLASS(oc);
835f0a902f7SPeter Crosthwaite 
8364f67d30bSMarc-André Lureau     device_class_set_props(dc, xlnx_zynqmp_props);
837f0a902f7SPeter Crosthwaite     dc->realize = xlnx_zynqmp_realize;
838d8589144SThomas Huth     /* Reason: Uses serial_hds in realize function, thus can't be used twice */
839d8589144SThomas Huth     dc->user_creatable = false;
840f0a902f7SPeter Crosthwaite }
841f0a902f7SPeter Crosthwaite 
842f0a902f7SPeter Crosthwaite static const TypeInfo xlnx_zynqmp_type_info = {
843f0a902f7SPeter Crosthwaite     .name = TYPE_XLNX_ZYNQMP,
844f0a902f7SPeter Crosthwaite     .parent = TYPE_DEVICE,
845f0a902f7SPeter Crosthwaite     .instance_size = sizeof(XlnxZynqMPState),
846f0a902f7SPeter Crosthwaite     .instance_init = xlnx_zynqmp_init,
847f0a902f7SPeter Crosthwaite     .class_init = xlnx_zynqmp_class_init,
848f0a902f7SPeter Crosthwaite };
849f0a902f7SPeter Crosthwaite 
850f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_register_types(void)
851f0a902f7SPeter Crosthwaite {
852f0a902f7SPeter Crosthwaite     type_register_static(&xlnx_zynqmp_type_info);
853f0a902f7SPeter Crosthwaite }
854f0a902f7SPeter Crosthwaite 
855f0a902f7SPeter Crosthwaite type_init(xlnx_zynqmp_register_types)
856