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"
28d780d056SPhilippe Mathieu-Daudé #include "target/arm/cpu-qom.h"
29f4f318b4SPhilippe Mathieu-Daudé #include "target/arm/gtimer.h"
307729e1f4SPeter Crosthwaite
317729e1f4SPeter Crosthwaite #define GIC_NUM_SPI_INTR 160
327729e1f4SPeter Crosthwaite
33bf4cb109SPeter Crosthwaite #define ARM_PHYS_TIMER_PPI 30
34bf4cb109SPeter Crosthwaite #define ARM_VIRT_TIMER_PPI 27
3575b749afSLuc Michel #define ARM_HYP_TIMER_PPI 26
3675b749afSLuc Michel #define ARM_SEC_TIMER_PPI 29
3775b749afSLuc Michel #define GIC_MAINTENANCE_PPI 25
38bf4cb109SPeter Crosthwaite
3920bff213SAlistair Francis #define GEM_REVISION 0x40070106
4020bff213SAlistair Francis
417729e1f4SPeter Crosthwaite #define GIC_BASE_ADDR 0xf9000000
427729e1f4SPeter Crosthwaite #define GIC_DIST_ADDR 0xf9010000
437729e1f4SPeter Crosthwaite #define GIC_CPU_ADDR 0xf9020000
4475b749afSLuc Michel #define GIC_VIFACE_ADDR 0xf9040000
4575b749afSLuc Michel #define GIC_VCPU_ADDR 0xf9060000
467729e1f4SPeter Crosthwaite
476fdf3282SAlistair Francis #define SATA_INTR 133
486fdf3282SAlistair Francis #define SATA_ADDR 0xFD0C0000
496fdf3282SAlistair Francis #define SATA_NUM_PORTS 2
506fdf3282SAlistair Francis
51babc1f30SFrancisco Iglesias #define QSPI_ADDR 0xff0f0000
52babc1f30SFrancisco Iglesias #define LQSPI_ADDR 0xc0000000
53babc1f30SFrancisco Iglesias #define QSPI_IRQ 15
54668351a5SXuzhou Cheng #define QSPI_DMA_ADDR 0xff0f0800
55c74ccb5dSFrancisco Iglesias #define NUM_QSPI_IRQ_LINES 2
56babc1f30SFrancisco Iglesias
5763320bcaSEdgar E. Iglesias #define CRF_ADDR 0xfd1a0000
5863320bcaSEdgar E. Iglesias #define CRF_IRQ 120
5963320bcaSEdgar E. Iglesias
60c28d4b86SEdgar E. Iglesias /* Serializer/Deserializer. */
61c28d4b86SEdgar E. Iglesias #define SERDES_ADDR 0xfd400000
62c28d4b86SEdgar E. Iglesias #define SERDES_SIZE 0x20000
63c28d4b86SEdgar E. Iglesias
64b93dbcddSKONRAD Frederic #define DP_ADDR 0xfd4a0000
65b3f5cc3fSFrederic Konrad #define DP_IRQ 0x77
66b93dbcddSKONRAD Frederic
67b93dbcddSKONRAD Frederic #define DPDMA_ADDR 0xfd4c0000
68b3f5cc3fSFrederic Konrad #define DPDMA_IRQ 0x7a
69b93dbcddSKONRAD Frederic
70d2e6f370STong Ho #define APU_ADDR 0xfd5c0000
71eb7a38baSEdgar E. Iglesias #define APU_IRQ 153
72d2e6f370STong Ho
7351af6231SEdgar E. Iglesias #define TTC0_ADDR 0xFF110000
7451af6231SEdgar E. Iglesias #define TTC0_IRQ 36
7551af6231SEdgar E. Iglesias
760ab7bbc7SAlistair Francis #define IPI_ADDR 0xFF300000
770ab7bbc7SAlistair Francis #define IPI_IRQ 64
780ab7bbc7SAlistair Francis
7908b2f15eSAlistair Francis #define RTC_ADDR 0xffa60000
8008b2f15eSAlistair Francis #define RTC_IRQ 26
8108b2f15eSAlistair Francis
827e47e15cSTong Ho #define BBRAM_ADDR 0xffcd0000
837e47e15cSTong Ho #define BBRAM_IRQ 11
847e47e15cSTong Ho
85db1264dfSTong Ho #define EFUSE_ADDR 0xffcc0000
86db1264dfSTong Ho #define EFUSE_IRQ 87
87db1264dfSTong Ho
88b630d3d4SPhilippe Mathieu-Daudé #define SDHCI_CAPABILITIES 0x280737ec6481 /* Datasheet: UG1085 (v1.7) */
89b630d3d4SPhilippe Mathieu-Daudé
9014ca2e46SPeter Crosthwaite static const uint64_t gem_addr[XLNX_ZYNQMP_NUM_GEMS] = {
9114ca2e46SPeter Crosthwaite 0xFF0B0000, 0xFF0C0000, 0xFF0D0000, 0xFF0E0000,
9214ca2e46SPeter Crosthwaite };
9314ca2e46SPeter Crosthwaite
9414ca2e46SPeter Crosthwaite static const int gem_intr[XLNX_ZYNQMP_NUM_GEMS] = {
9514ca2e46SPeter Crosthwaite 57, 59, 61, 63,
9614ca2e46SPeter Crosthwaite };
9714ca2e46SPeter Crosthwaite
983bade2a9SPeter Crosthwaite static const uint64_t uart_addr[XLNX_ZYNQMP_NUM_UARTS] = {
993bade2a9SPeter Crosthwaite 0xFF000000, 0xFF010000,
1003bade2a9SPeter Crosthwaite };
1013bade2a9SPeter Crosthwaite
1023bade2a9SPeter Crosthwaite static const int uart_intr[XLNX_ZYNQMP_NUM_UARTS] = {
1033bade2a9SPeter Crosthwaite 21, 22,
1043bade2a9SPeter Crosthwaite };
1053bade2a9SPeter Crosthwaite
106840c22cdSVikram Garhwal static const uint64_t can_addr[XLNX_ZYNQMP_NUM_CAN] = {
107840c22cdSVikram Garhwal 0xFF060000, 0xFF070000,
108840c22cdSVikram Garhwal };
109840c22cdSVikram Garhwal
110840c22cdSVikram Garhwal static const int can_intr[XLNX_ZYNQMP_NUM_CAN] = {
111840c22cdSVikram Garhwal 23, 24,
112840c22cdSVikram Garhwal };
113840c22cdSVikram Garhwal
11433108e9fSSai Pavan Boddu static const uint64_t sdhci_addr[XLNX_ZYNQMP_NUM_SDHCI] = {
11533108e9fSSai Pavan Boddu 0xFF160000, 0xFF170000,
11633108e9fSSai Pavan Boddu };
11733108e9fSSai Pavan Boddu
11833108e9fSSai Pavan Boddu static const int sdhci_intr[XLNX_ZYNQMP_NUM_SDHCI] = {
11933108e9fSSai Pavan Boddu 48, 49,
12033108e9fSSai Pavan Boddu };
12133108e9fSSai Pavan Boddu
12202d07eb4SAlistair Francis static const uint64_t spi_addr[XLNX_ZYNQMP_NUM_SPIS] = {
12302d07eb4SAlistair Francis 0xFF040000, 0xFF050000,
12402d07eb4SAlistair Francis };
12502d07eb4SAlistair Francis
12602d07eb4SAlistair Francis static const int spi_intr[XLNX_ZYNQMP_NUM_SPIS] = {
12702d07eb4SAlistair Francis 19, 20,
12802d07eb4SAlistair Francis };
12902d07eb4SAlistair Francis
13004965bcaSFrancisco Iglesias static const uint64_t gdma_ch_addr[XLNX_ZYNQMP_NUM_GDMA_CH] = {
13104965bcaSFrancisco Iglesias 0xFD500000, 0xFD510000, 0xFD520000, 0xFD530000,
13204965bcaSFrancisco Iglesias 0xFD540000, 0xFD550000, 0xFD560000, 0xFD570000
13304965bcaSFrancisco Iglesias };
13404965bcaSFrancisco Iglesias
13504965bcaSFrancisco Iglesias static const int gdma_ch_intr[XLNX_ZYNQMP_NUM_GDMA_CH] = {
13604965bcaSFrancisco Iglesias 124, 125, 126, 127, 128, 129, 130, 131
13704965bcaSFrancisco Iglesias };
13804965bcaSFrancisco Iglesias
13904965bcaSFrancisco Iglesias static const uint64_t adma_ch_addr[XLNX_ZYNQMP_NUM_ADMA_CH] = {
14004965bcaSFrancisco Iglesias 0xFFA80000, 0xFFA90000, 0xFFAA0000, 0xFFAB0000,
14104965bcaSFrancisco Iglesias 0xFFAC0000, 0xFFAD0000, 0xFFAE0000, 0xFFAF0000
14204965bcaSFrancisco Iglesias };
14304965bcaSFrancisco Iglesias
14404965bcaSFrancisco Iglesias static const int adma_ch_intr[XLNX_ZYNQMP_NUM_ADMA_CH] = {
14504965bcaSFrancisco Iglesias 77, 78, 79, 80, 81, 82, 83, 84
14604965bcaSFrancisco Iglesias };
14704965bcaSFrancisco Iglesias
148acc0b8b0SFrancisco Iglesias static const uint64_t usb_addr[XLNX_ZYNQMP_NUM_USB] = {
149acc0b8b0SFrancisco Iglesias 0xFE200000, 0xFE300000
150acc0b8b0SFrancisco Iglesias };
151acc0b8b0SFrancisco Iglesias
152acc0b8b0SFrancisco Iglesias static const int usb_intr[XLNX_ZYNQMP_NUM_USB] = {
153acc0b8b0SFrancisco Iglesias 65, 70
154acc0b8b0SFrancisco Iglesias };
155acc0b8b0SFrancisco Iglesias
1567729e1f4SPeter Crosthwaite typedef struct XlnxZynqMPGICRegion {
1577729e1f4SPeter Crosthwaite int region_index;
1587729e1f4SPeter Crosthwaite uint32_t address;
15975b749afSLuc Michel uint32_t offset;
16075b749afSLuc Michel bool virt;
1617729e1f4SPeter Crosthwaite } XlnxZynqMPGICRegion;
1627729e1f4SPeter Crosthwaite
1637729e1f4SPeter Crosthwaite static const XlnxZynqMPGICRegion xlnx_zynqmp_gic_regions[] = {
16475b749afSLuc Michel /* Distributor */
16575b749afSLuc Michel {
16675b749afSLuc Michel .region_index = 0,
16775b749afSLuc Michel .address = GIC_DIST_ADDR,
16875b749afSLuc Michel .offset = 0,
16975b749afSLuc Michel .virt = false
17075b749afSLuc Michel },
17175b749afSLuc Michel
17275b749afSLuc Michel /* CPU interface */
17375b749afSLuc Michel {
17475b749afSLuc Michel .region_index = 1,
17575b749afSLuc Michel .address = GIC_CPU_ADDR,
17675b749afSLuc Michel .offset = 0,
17775b749afSLuc Michel .virt = false
17875b749afSLuc Michel },
17975b749afSLuc Michel {
18075b749afSLuc Michel .region_index = 1,
18175b749afSLuc Michel .address = GIC_CPU_ADDR + 0x10000,
18275b749afSLuc Michel .offset = 0x1000,
18375b749afSLuc Michel .virt = false
18475b749afSLuc Michel },
18575b749afSLuc Michel
18675b749afSLuc Michel /* Virtual interface */
18775b749afSLuc Michel {
18875b749afSLuc Michel .region_index = 2,
18975b749afSLuc Michel .address = GIC_VIFACE_ADDR,
19075b749afSLuc Michel .offset = 0,
19175b749afSLuc Michel .virt = true
19275b749afSLuc Michel },
19375b749afSLuc Michel
19475b749afSLuc Michel /* Virtual CPU interface */
19575b749afSLuc Michel {
19675b749afSLuc Michel .region_index = 3,
19775b749afSLuc Michel .address = GIC_VCPU_ADDR,
19875b749afSLuc Michel .offset = 0,
19975b749afSLuc Michel .virt = true
20075b749afSLuc Michel },
20175b749afSLuc Michel {
20275b749afSLuc Michel .region_index = 3,
20375b749afSLuc Michel .address = GIC_VCPU_ADDR + 0x10000,
20475b749afSLuc Michel .offset = 0x1000,
20575b749afSLuc Michel .virt = true
20675b749afSLuc Michel },
2077729e1f4SPeter Crosthwaite };
208f0a902f7SPeter Crosthwaite
arm_gic_ppi_index(int cpu_nr,int ppi_index)209bf4cb109SPeter Crosthwaite static inline int arm_gic_ppi_index(int cpu_nr, int ppi_index)
210bf4cb109SPeter Crosthwaite {
211bf4cb109SPeter Crosthwaite return GIC_NUM_SPI_INTR + cpu_nr * GIC_INTERNAL + ppi_index;
212bf4cb109SPeter Crosthwaite }
213bf4cb109SPeter Crosthwaite
xlnx_zynqmp_create_rpu(MachineState * ms,XlnxZynqMPState * s,const char * boot_cpu,Error ** errp)214cc7d44c2SLike Xu static void xlnx_zynqmp_create_rpu(MachineState *ms, XlnxZynqMPState *s,
215cc7d44c2SLike Xu const char *boot_cpu, Error **errp)
2166ed92b14SEdgar E. Iglesias {
2176ed92b14SEdgar E. Iglesias int i;
218c9ba1c9fSClément Chigot int num_rpus = MIN((int)(ms->smp.cpus - XLNX_ZYNQMP_NUM_APU_CPUS),
219cc7d44c2SLike Xu XLNX_ZYNQMP_NUM_RPU_CPUS);
2206ed92b14SEdgar E. Iglesias
221e5b51753SPeter Maydell if (num_rpus <= 0) {
222e5b51753SPeter Maydell /* Don't create rpu-cluster object if there's nothing to put in it */
223e5b51753SPeter Maydell return;
224e5b51753SPeter Maydell }
225e5b51753SPeter Maydell
226816fd397SLuc Michel object_initialize_child(OBJECT(s), "rpu-cluster", &s->rpu_cluster,
2279fc7fc4dSMarkus Armbruster TYPE_CPU_CLUSTER);
228816fd397SLuc Michel qdev_prop_set_uint32(DEVICE(&s->rpu_cluster), "cluster-id", 1);
229816fd397SLuc Michel
2306908ec44SAlistair Francis for (i = 0; i < num_rpus; i++) {
2317a309cc9SMarkus Armbruster const char *name;
2326ed92b14SEdgar E. Iglesias
233d0313798SPhilippe Mathieu-Daudé object_initialize_child(OBJECT(&s->rpu_cluster), "rpu-cpu[*]",
2349fc7fc4dSMarkus Armbruster &s->rpu_cpu[i],
2359fc7fc4dSMarkus Armbruster ARM_CPU_TYPE_NAME("cortex-r5f"));
2366ed92b14SEdgar E. Iglesias
2376ed92b14SEdgar E. Iglesias name = object_get_canonical_path_component(OBJECT(&s->rpu_cpu[i]));
2386ed92b14SEdgar E. Iglesias if (strcmp(name, boot_cpu)) {
23950c785f2SPeter Maydell /*
24050c785f2SPeter Maydell * Secondary CPUs start in powered-down state.
24150c785f2SPeter Maydell */
2425325cc34SMarkus Armbruster object_property_set_bool(OBJECT(&s->rpu_cpu[i]),
2435325cc34SMarkus Armbruster "start-powered-off", true, &error_abort);
2446ed92b14SEdgar E. Iglesias } else {
2456ed92b14SEdgar E. Iglesias s->boot_cpu_ptr = &s->rpu_cpu[i];
2466ed92b14SEdgar E. Iglesias }
2476ed92b14SEdgar E. Iglesias
2485325cc34SMarkus Armbruster object_property_set_bool(OBJECT(&s->rpu_cpu[i]), "reset-hivecs", true,
2496ed92b14SEdgar E. Iglesias &error_abort);
250668f62ecSMarkus Armbruster if (!qdev_realize(DEVICE(&s->rpu_cpu[i]), NULL, errp)) {
2516ed92b14SEdgar E. Iglesias return;
2526ed92b14SEdgar E. Iglesias }
2536ed92b14SEdgar E. Iglesias }
254fa434424SPeter Maydell
255ce189ab2SMarkus Armbruster qdev_realize(DEVICE(&s->rpu_cluster), NULL, &error_fatal);
2566ed92b14SEdgar E. Iglesias }
2576ed92b14SEdgar E. Iglesias
xlnx_zynqmp_create_bbram(XlnxZynqMPState * s,qemu_irq * gic)2587e47e15cSTong Ho static void xlnx_zynqmp_create_bbram(XlnxZynqMPState *s, qemu_irq *gic)
2597e47e15cSTong Ho {
2607e47e15cSTong Ho SysBusDevice *sbd;
2617e47e15cSTong Ho
2627e47e15cSTong Ho object_initialize_child_with_props(OBJECT(s), "bbram", &s->bbram,
2637e47e15cSTong Ho sizeof(s->bbram), TYPE_XLNX_BBRAM,
2647e47e15cSTong Ho &error_fatal,
2657e47e15cSTong Ho "crc-zpads", "1",
2667e47e15cSTong Ho NULL);
2677e47e15cSTong Ho sbd = SYS_BUS_DEVICE(&s->bbram);
2687e47e15cSTong Ho
2697e47e15cSTong Ho sysbus_realize(sbd, &error_fatal);
2707e47e15cSTong Ho sysbus_mmio_map(sbd, 0, BBRAM_ADDR);
2717e47e15cSTong Ho sysbus_connect_irq(sbd, 0, gic[BBRAM_IRQ]);
2727e47e15cSTong Ho }
2737e47e15cSTong Ho
xlnx_zynqmp_create_efuse(XlnxZynqMPState * s,qemu_irq * gic)274db1264dfSTong Ho static void xlnx_zynqmp_create_efuse(XlnxZynqMPState *s, qemu_irq *gic)
275db1264dfSTong Ho {
276db1264dfSTong Ho Object *bits = OBJECT(&s->efuse);
277db1264dfSTong Ho Object *ctrl = OBJECT(&s->efuse_ctrl);
278db1264dfSTong Ho SysBusDevice *sbd;
279db1264dfSTong Ho
280db1264dfSTong Ho object_initialize_child(OBJECT(s), "efuse-ctrl", &s->efuse_ctrl,
281db1264dfSTong Ho TYPE_XLNX_ZYNQMP_EFUSE);
282db1264dfSTong Ho
283db1264dfSTong Ho object_initialize_child_with_props(ctrl, "xlnx-efuse@0", bits,
284db1264dfSTong Ho sizeof(s->efuse),
285db1264dfSTong Ho TYPE_XLNX_EFUSE, &error_abort,
286db1264dfSTong Ho "efuse-nr", "3",
287db1264dfSTong Ho "efuse-size", "2048",
288db1264dfSTong Ho NULL);
289db1264dfSTong Ho
290db1264dfSTong Ho qdev_realize(DEVICE(bits), NULL, &error_abort);
291db1264dfSTong Ho object_property_set_link(ctrl, "efuse", bits, &error_abort);
292db1264dfSTong Ho
293db1264dfSTong Ho sbd = SYS_BUS_DEVICE(ctrl);
294db1264dfSTong Ho sysbus_realize(sbd, &error_abort);
295db1264dfSTong Ho sysbus_mmio_map(sbd, 0, EFUSE_ADDR);
296db1264dfSTong Ho sysbus_connect_irq(sbd, 0, gic[EFUSE_IRQ]);
297db1264dfSTong Ho }
298db1264dfSTong Ho
xlnx_zynqmp_create_apu_ctrl(XlnxZynqMPState * s,qemu_irq * gic)299eb7a38baSEdgar E. Iglesias static void xlnx_zynqmp_create_apu_ctrl(XlnxZynqMPState *s, qemu_irq *gic)
300eb7a38baSEdgar E. Iglesias {
301eb7a38baSEdgar E. Iglesias SysBusDevice *sbd;
302eb7a38baSEdgar E. Iglesias int i;
303eb7a38baSEdgar E. Iglesias
304eb7a38baSEdgar E. Iglesias object_initialize_child(OBJECT(s), "apu-ctrl", &s->apu_ctrl,
305eb7a38baSEdgar E. Iglesias TYPE_XLNX_ZYNQMP_APU_CTRL);
306eb7a38baSEdgar E. Iglesias sbd = SYS_BUS_DEVICE(&s->apu_ctrl);
307eb7a38baSEdgar E. Iglesias
308eb7a38baSEdgar E. Iglesias for (i = 0; i < XLNX_ZYNQMP_NUM_APU_CPUS; i++) {
309eb7a38baSEdgar E. Iglesias g_autofree gchar *name = g_strdup_printf("cpu%d", i);
310eb7a38baSEdgar E. Iglesias
311eb7a38baSEdgar E. Iglesias object_property_set_link(OBJECT(&s->apu_ctrl), name,
312eb7a38baSEdgar E. Iglesias OBJECT(&s->apu_cpu[i]), &error_abort);
313eb7a38baSEdgar E. Iglesias }
314eb7a38baSEdgar E. Iglesias
315eb7a38baSEdgar E. Iglesias sysbus_realize(sbd, &error_fatal);
316eb7a38baSEdgar E. Iglesias sysbus_mmio_map(sbd, 0, APU_ADDR);
317eb7a38baSEdgar E. Iglesias sysbus_connect_irq(sbd, 0, gic[APU_IRQ]);
318eb7a38baSEdgar E. Iglesias }
319eb7a38baSEdgar E. Iglesias
xlnx_zynqmp_create_crf(XlnxZynqMPState * s,qemu_irq * gic)32063320bcaSEdgar E. Iglesias static void xlnx_zynqmp_create_crf(XlnxZynqMPState *s, qemu_irq *gic)
32163320bcaSEdgar E. Iglesias {
32263320bcaSEdgar E. Iglesias SysBusDevice *sbd;
32363320bcaSEdgar E. Iglesias
32463320bcaSEdgar E. Iglesias object_initialize_child(OBJECT(s), "crf", &s->crf, TYPE_XLNX_ZYNQMP_CRF);
32563320bcaSEdgar E. Iglesias sbd = SYS_BUS_DEVICE(&s->crf);
32663320bcaSEdgar E. Iglesias
32763320bcaSEdgar E. Iglesias sysbus_realize(sbd, &error_fatal);
32863320bcaSEdgar E. Iglesias sysbus_mmio_map(sbd, 0, CRF_ADDR);
32963320bcaSEdgar E. Iglesias sysbus_connect_irq(sbd, 0, gic[CRF_IRQ]);
33063320bcaSEdgar E. Iglesias }
33163320bcaSEdgar E. Iglesias
xlnx_zynqmp_create_ttc(XlnxZynqMPState * s,qemu_irq * gic)33251af6231SEdgar E. Iglesias static void xlnx_zynqmp_create_ttc(XlnxZynqMPState *s, qemu_irq *gic)
33351af6231SEdgar E. Iglesias {
33451af6231SEdgar E. Iglesias SysBusDevice *sbd;
33551af6231SEdgar E. Iglesias int i, irq;
33651af6231SEdgar E. Iglesias
33751af6231SEdgar E. Iglesias for (i = 0; i < XLNX_ZYNQMP_NUM_TTC; i++) {
33851af6231SEdgar E. Iglesias object_initialize_child(OBJECT(s), "ttc[*]", &s->ttc[i],
33951af6231SEdgar E. Iglesias TYPE_CADENCE_TTC);
34051af6231SEdgar E. Iglesias sbd = SYS_BUS_DEVICE(&s->ttc[i]);
34151af6231SEdgar E. Iglesias
34251af6231SEdgar E. Iglesias sysbus_realize(sbd, &error_fatal);
34351af6231SEdgar E. Iglesias sysbus_mmio_map(sbd, 0, TTC0_ADDR + i * 0x10000);
34451af6231SEdgar E. Iglesias for (irq = 0; irq < 3; irq++) {
34551af6231SEdgar E. Iglesias sysbus_connect_irq(sbd, irq, gic[TTC0_IRQ + i * 3 + irq]);
34651af6231SEdgar E. Iglesias }
34751af6231SEdgar E. Iglesias }
34851af6231SEdgar E. Iglesias }
34951af6231SEdgar E. Iglesias
xlnx_zynqmp_create_unimp_mmio(XlnxZynqMPState * s)350d2e6f370STong Ho static void xlnx_zynqmp_create_unimp_mmio(XlnxZynqMPState *s)
351d2e6f370STong Ho {
352d2e6f370STong Ho static const struct UnimpInfo {
353d2e6f370STong Ho const char *name;
354d2e6f370STong Ho hwaddr base;
355d2e6f370STong Ho hwaddr size;
356d2e6f370STong Ho } unimp_areas[ARRAY_SIZE(s->mr_unimp)] = {
357c28d4b86SEdgar E. Iglesias { .name = "serdes", SERDES_ADDR, SERDES_SIZE },
358d2e6f370STong Ho };
359d2e6f370STong Ho unsigned int nr;
360d2e6f370STong Ho
361d2e6f370STong Ho for (nr = 0; nr < ARRAY_SIZE(unimp_areas); nr++) {
362d2e6f370STong Ho const struct UnimpInfo *info = &unimp_areas[nr];
363d2e6f370STong Ho DeviceState *dev = qdev_new(TYPE_UNIMPLEMENTED_DEVICE);
364d2e6f370STong Ho SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
365d2e6f370STong Ho
366d2e6f370STong Ho assert(info->name && info->base && info->size > 0);
367d2e6f370STong Ho qdev_prop_set_string(dev, "name", info->name);
368d2e6f370STong Ho qdev_prop_set_uint64(dev, "size", info->size);
369d2e6f370STong Ho object_property_add_child(OBJECT(s), info->name, OBJECT(dev));
370d2e6f370STong Ho
371d2e6f370STong Ho sysbus_realize_and_unref(sbd, &error_fatal);
372d2e6f370STong Ho sysbus_mmio_map(sbd, 0, info->base);
373d2e6f370STong Ho }
374d2e6f370STong Ho }
375d2e6f370STong Ho
xlnx_zynqmp_init(Object * obj)376f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_init(Object *obj)
377f0a902f7SPeter Crosthwaite {
378cc7d44c2SLike Xu MachineState *ms = MACHINE(qdev_get_machine());
379f0a902f7SPeter Crosthwaite XlnxZynqMPState *s = XLNX_ZYNQMP(obj);
380f0a902f7SPeter Crosthwaite int i;
381cc7d44c2SLike Xu int num_apus = MIN(ms->smp.cpus, XLNX_ZYNQMP_NUM_APU_CPUS);
382f0a902f7SPeter Crosthwaite
383816fd397SLuc Michel object_initialize_child(obj, "apu-cluster", &s->apu_cluster,
3849fc7fc4dSMarkus Armbruster TYPE_CPU_CLUSTER);
385816fd397SLuc Michel qdev_prop_set_uint32(DEVICE(&s->apu_cluster), "cluster-id", 0);
386816fd397SLuc Michel
3876908ec44SAlistair Francis for (i = 0; i < num_apus; i++) {
388816fd397SLuc Michel object_initialize_child(OBJECT(&s->apu_cluster), "apu-cpu[*]",
3899fc7fc4dSMarkus Armbruster &s->apu_cpu[i],
3909fc7fc4dSMarkus Armbruster ARM_CPU_TYPE_NAME("cortex-a53"));
391f0a902f7SPeter Crosthwaite }
3927729e1f4SPeter Crosthwaite
393db873cc5SMarkus Armbruster object_initialize_child(obj, "gic", &s->gic, gic_class_name());
39414ca2e46SPeter Crosthwaite
39514ca2e46SPeter Crosthwaite for (i = 0; i < XLNX_ZYNQMP_NUM_GEMS; i++) {
396db873cc5SMarkus Armbruster object_initialize_child(obj, "gem[*]", &s->gem[i], TYPE_CADENCE_GEM);
397*604b72ddSKinsey Moore object_initialize_child(obj, "gem-irq-orgate[*]",
398*604b72ddSKinsey Moore &s->gem_irq_orgate[i], TYPE_OR_IRQ);
39914ca2e46SPeter Crosthwaite }
4003bade2a9SPeter Crosthwaite
4013bade2a9SPeter Crosthwaite for (i = 0; i < XLNX_ZYNQMP_NUM_UARTS; i++) {
402db873cc5SMarkus Armbruster object_initialize_child(obj, "uart[*]", &s->uart[i],
403ccf02d73SThomas Huth TYPE_CADENCE_UART);
4043bade2a9SPeter Crosthwaite }
4056fdf3282SAlistair Francis
406840c22cdSVikram Garhwal for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) {
407840c22cdSVikram Garhwal object_initialize_child(obj, "can[*]", &s->can[i],
408840c22cdSVikram Garhwal TYPE_XLNX_ZYNQMP_CAN);
409840c22cdSVikram Garhwal }
410840c22cdSVikram Garhwal
411db873cc5SMarkus Armbruster object_initialize_child(obj, "sata", &s->sata, TYPE_SYSBUS_AHCI);
41233108e9fSSai Pavan Boddu
41333108e9fSSai Pavan Boddu for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) {
4145a147c8cSMarkus Armbruster object_initialize_child(obj, "sdhci[*]", &s->sdhci[i],
4155a147c8cSMarkus Armbruster TYPE_SYSBUS_SDHCI);
41633108e9fSSai Pavan Boddu }
41702d07eb4SAlistair Francis
41802d07eb4SAlistair Francis for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) {
419db873cc5SMarkus Armbruster object_initialize_child(obj, "spi[*]", &s->spi[i], TYPE_XILINX_SPIPS);
42002d07eb4SAlistair Francis }
421b93dbcddSKONRAD Frederic
422db873cc5SMarkus Armbruster object_initialize_child(obj, "qspi", &s->qspi, TYPE_XLNX_ZYNQMP_QSPIPS);
423babc1f30SFrancisco Iglesias
424db873cc5SMarkus Armbruster object_initialize_child(obj, "xxxdp", &s->dp, TYPE_XLNX_DP);
425b93dbcddSKONRAD Frederic
426db873cc5SMarkus Armbruster object_initialize_child(obj, "dp-dma", &s->dpdma, TYPE_XLNX_DPDMA);
4270ab7bbc7SAlistair Francis
428db873cc5SMarkus Armbruster object_initialize_child(obj, "ipi", &s->ipi, TYPE_XLNX_ZYNQMP_IPI);
42908b2f15eSAlistair Francis
430db873cc5SMarkus Armbruster object_initialize_child(obj, "rtc", &s->rtc, TYPE_XLNX_ZYNQMP_RTC);
43104965bcaSFrancisco Iglesias
43204965bcaSFrancisco Iglesias for (i = 0; i < XLNX_ZYNQMP_NUM_GDMA_CH; i++) {
433db873cc5SMarkus Armbruster object_initialize_child(obj, "gdma[*]", &s->gdma[i], TYPE_XLNX_ZDMA);
43404965bcaSFrancisco Iglesias }
43504965bcaSFrancisco Iglesias
43604965bcaSFrancisco Iglesias for (i = 0; i < XLNX_ZYNQMP_NUM_ADMA_CH; i++) {
437db873cc5SMarkus Armbruster object_initialize_child(obj, "adma[*]", &s->adma[i], TYPE_XLNX_ZDMA);
43804965bcaSFrancisco Iglesias }
439668351a5SXuzhou Cheng
440668351a5SXuzhou Cheng object_initialize_child(obj, "qspi-dma", &s->qspi_dma, TYPE_XLNX_CSU_DMA);
441c74ccb5dSFrancisco Iglesias object_initialize_child(obj, "qspi-irq-orgate",
442c74ccb5dSFrancisco Iglesias &s->qspi_irq_orgate, TYPE_OR_IRQ);
443acc0b8b0SFrancisco Iglesias
444acc0b8b0SFrancisco Iglesias for (i = 0; i < XLNX_ZYNQMP_NUM_USB; i++) {
445acc0b8b0SFrancisco Iglesias object_initialize_child(obj, "usb[*]", &s->usb[i], TYPE_USB_DWC3);
446acc0b8b0SFrancisco Iglesias }
447f0a902f7SPeter Crosthwaite }
448f0a902f7SPeter Crosthwaite
xlnx_zynqmp_realize(DeviceState * dev,Error ** errp)449f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
450f0a902f7SPeter Crosthwaite {
451cc7d44c2SLike Xu MachineState *ms = MACHINE(qdev_get_machine());
452f0a902f7SPeter Crosthwaite XlnxZynqMPState *s = XLNX_ZYNQMP(dev);
4537729e1f4SPeter Crosthwaite MemoryRegion *system_memory = get_system_memory();
454f0a902f7SPeter Crosthwaite uint8_t i;
455dc3b89efSAlistair Francis uint64_t ram_size;
456cc7d44c2SLike Xu int num_apus = MIN(ms->smp.cpus, XLNX_ZYNQMP_NUM_APU_CPUS);
4576396a193SPeter Crosthwaite const char *boot_cpu = s->boot_cpu ? s->boot_cpu : "apu-cpu[0]";
458dc3b89efSAlistair Francis ram_addr_t ddr_low_size, ddr_high_size;
45914ca2e46SPeter Crosthwaite qemu_irq gic_spi[GIC_NUM_SPI_INTR];
460f0a902f7SPeter Crosthwaite Error *err = NULL;
461f0a902f7SPeter Crosthwaite
462dc3b89efSAlistair Francis ram_size = memory_region_size(s->ddr_ram);
463dc3b89efSAlistair Francis
46421bce371SXuzhou Cheng /*
46521bce371SXuzhou Cheng * Create the DDR Memory Regions. User friendly checks should happen at
466dc3b89efSAlistair Francis * the board level
467dc3b89efSAlistair Francis */
468dc3b89efSAlistair Francis if (ram_size > XLNX_ZYNQMP_MAX_LOW_RAM_SIZE) {
46921bce371SXuzhou Cheng /*
47021bce371SXuzhou Cheng * The RAM size is above the maximum available for the low DDR.
471dc3b89efSAlistair Francis * Create the high DDR memory region as well.
472dc3b89efSAlistair Francis */
473dc3b89efSAlistair Francis assert(ram_size <= XLNX_ZYNQMP_MAX_RAM_SIZE);
474dc3b89efSAlistair Francis ddr_low_size = XLNX_ZYNQMP_MAX_LOW_RAM_SIZE;
475dc3b89efSAlistair Francis ddr_high_size = ram_size - XLNX_ZYNQMP_MAX_LOW_RAM_SIZE;
476dc3b89efSAlistair Francis
47732b9523aSPhilippe Mathieu-Daudé memory_region_init_alias(&s->ddr_ram_high, OBJECT(dev),
47832b9523aSPhilippe Mathieu-Daudé "ddr-ram-high", s->ddr_ram, ddr_low_size,
47932b9523aSPhilippe Mathieu-Daudé ddr_high_size);
480dc3b89efSAlistair Francis memory_region_add_subregion(get_system_memory(),
481dc3b89efSAlistair Francis XLNX_ZYNQMP_HIGH_RAM_START,
482dc3b89efSAlistair Francis &s->ddr_ram_high);
483dc3b89efSAlistair Francis } else {
484dc3b89efSAlistair Francis /* RAM must be non-zero */
485dc3b89efSAlistair Francis assert(ram_size);
486dc3b89efSAlistair Francis ddr_low_size = ram_size;
487dc3b89efSAlistair Francis }
488dc3b89efSAlistair Francis
48932b9523aSPhilippe Mathieu-Daudé memory_region_init_alias(&s->ddr_ram_low, OBJECT(dev), "ddr-ram-low",
49032b9523aSPhilippe Mathieu-Daudé s->ddr_ram, 0, ddr_low_size);
491dc3b89efSAlistair Francis memory_region_add_subregion(get_system_memory(), 0, &s->ddr_ram_low);
492dc3b89efSAlistair Francis
4936675d719SAlistair Francis /* Create the four OCM banks */
4946675d719SAlistair Francis for (i = 0; i < XLNX_ZYNQMP_NUM_OCM_BANKS; i++) {
4956675d719SAlistair Francis char *ocm_name = g_strdup_printf("zynqmp.ocm_ram_bank_%d", i);
4966675d719SAlistair Francis
49798a99ce0SPeter Maydell memory_region_init_ram(&s->ocm_ram[i], NULL, ocm_name,
498f8ed85acSMarkus Armbruster XLNX_ZYNQMP_OCM_RAM_SIZE, &error_fatal);
4996675d719SAlistair Francis memory_region_add_subregion(get_system_memory(),
5006675d719SAlistair Francis XLNX_ZYNQMP_OCM_RAM_0_ADDRESS +
5016675d719SAlistair Francis i * XLNX_ZYNQMP_OCM_RAM_SIZE,
5026675d719SAlistair Francis &s->ocm_ram[i]);
5036675d719SAlistair Francis
5046675d719SAlistair Francis g_free(ocm_name);
5056675d719SAlistair Francis }
5066675d719SAlistair Francis
5077729e1f4SPeter Crosthwaite qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", GIC_NUM_SPI_INTR + 32);
5087729e1f4SPeter Crosthwaite qdev_prop_set_uint32(DEVICE(&s->gic), "revision", 2);
5096908ec44SAlistair Francis qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", num_apus);
51075b749afSLuc Michel qdev_prop_set_bit(DEVICE(&s->gic), "has-security-extensions", s->secure);
51175b749afSLuc Michel qdev_prop_set_bit(DEVICE(&s->gic),
51275b749afSLuc Michel "has-virtualization-extensions", s->virt);
5137729e1f4SPeter Crosthwaite
514ce189ab2SMarkus Armbruster qdev_realize(DEVICE(&s->apu_cluster), NULL, &error_fatal);
515816fd397SLuc Michel
5160776d967SEdgar E. Iglesias /* Realize APUs before realizing the GIC. KVM requires this. */
5176908ec44SAlistair Francis for (i = 0; i < num_apus; i++) {
5187a309cc9SMarkus Armbruster const char *name;
519bf4cb109SPeter Crosthwaite
5206396a193SPeter Crosthwaite name = object_get_canonical_path_component(OBJECT(&s->apu_cpu[i]));
5216396a193SPeter Crosthwaite if (strcmp(name, boot_cpu)) {
52250c785f2SPeter Maydell /*
52350c785f2SPeter Maydell * Secondary CPUs start in powered-down state.
52450c785f2SPeter Maydell */
5255325cc34SMarkus Armbruster object_property_set_bool(OBJECT(&s->apu_cpu[i]),
5265325cc34SMarkus Armbruster "start-powered-off", true, &error_abort);
5276396a193SPeter Crosthwaite } else {
5286396a193SPeter Crosthwaite s->boot_cpu_ptr = &s->apu_cpu[i];
529f0a902f7SPeter Crosthwaite }
530f0a902f7SPeter Crosthwaite
5315325cc34SMarkus Armbruster object_property_set_bool(OBJECT(&s->apu_cpu[i]), "has_el3", s->secure,
5325325cc34SMarkus Armbruster NULL);
5335325cc34SMarkus Armbruster object_property_set_bool(OBJECT(&s->apu_cpu[i]), "has_el2", s->virt,
5345325cc34SMarkus Armbruster NULL);
5355325cc34SMarkus Armbruster object_property_set_int(OBJECT(&s->apu_cpu[i]), "reset-cbar",
5365325cc34SMarkus Armbruster GIC_BASE_ADDR, &error_abort);
5375325cc34SMarkus Armbruster object_property_set_int(OBJECT(&s->apu_cpu[i]), "core-count",
5385325cc34SMarkus Armbruster num_apus, &error_abort);
539668f62ecSMarkus Armbruster if (!qdev_realize(DEVICE(&s->apu_cpu[i]), NULL, errp)) {
540f0a902f7SPeter Crosthwaite return;
541f0a902f7SPeter Crosthwaite }
5420776d967SEdgar E. Iglesias }
5430776d967SEdgar E. Iglesias
544668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->gic), errp)) {
5450776d967SEdgar E. Iglesias return;
5460776d967SEdgar E. Iglesias }
5470776d967SEdgar E. Iglesias
5480776d967SEdgar E. Iglesias assert(ARRAY_SIZE(xlnx_zynqmp_gic_regions) == XLNX_ZYNQMP_GIC_REGIONS);
5490776d967SEdgar E. Iglesias for (i = 0; i < XLNX_ZYNQMP_GIC_REGIONS; i++) {
5500776d967SEdgar E. Iglesias SysBusDevice *gic = SYS_BUS_DEVICE(&s->gic);
5510776d967SEdgar E. Iglesias const XlnxZynqMPGICRegion *r = &xlnx_zynqmp_gic_regions[i];
55275b749afSLuc Michel MemoryRegion *mr;
5530776d967SEdgar E. Iglesias uint32_t addr = r->address;
5540776d967SEdgar E. Iglesias int j;
5550776d967SEdgar E. Iglesias
55675b749afSLuc Michel if (r->virt && !s->virt) {
55775b749afSLuc Michel continue;
55875b749afSLuc Michel }
5590776d967SEdgar E. Iglesias
56075b749afSLuc Michel mr = sysbus_mmio_get_region(gic, r->region_index);
5610776d967SEdgar E. Iglesias for (j = 0; j < XLNX_ZYNQMP_GIC_ALIASES; j++) {
5620776d967SEdgar E. Iglesias MemoryRegion *alias = &s->gic_mr[i][j];
5630776d967SEdgar E. Iglesias
5640776d967SEdgar E. Iglesias memory_region_init_alias(alias, OBJECT(s), "zynqmp-gic-alias", mr,
56575b749afSLuc Michel r->offset, XLNX_ZYNQMP_GIC_REGION_SIZE);
5660776d967SEdgar E. Iglesias memory_region_add_subregion(system_memory, addr, alias);
56775b749afSLuc Michel
56875b749afSLuc Michel addr += XLNX_ZYNQMP_GIC_REGION_SIZE;
5690776d967SEdgar E. Iglesias }
5700776d967SEdgar E. Iglesias }
5710776d967SEdgar E. Iglesias
5726908ec44SAlistair Francis for (i = 0; i < num_apus; i++) {
5730776d967SEdgar E. Iglesias qemu_irq irq;
5747729e1f4SPeter Crosthwaite
5757729e1f4SPeter Crosthwaite sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i,
5762e5577bcSPeter Crosthwaite qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]),
5772e5577bcSPeter Crosthwaite ARM_CPU_IRQ));
57875b749afSLuc Michel sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + num_apus,
57975b749afSLuc Michel qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]),
58075b749afSLuc Michel ARM_CPU_FIQ));
58175b749afSLuc Michel sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + num_apus * 2,
58275b749afSLuc Michel qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]),
58375b749afSLuc Michel ARM_CPU_VIRQ));
58475b749afSLuc Michel sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + num_apus * 3,
58575b749afSLuc Michel qdev_get_gpio_in(DEVICE(&s->apu_cpu[i]),
58675b749afSLuc Michel ARM_CPU_VFIQ));
587bf4cb109SPeter Crosthwaite irq = qdev_get_gpio_in(DEVICE(&s->gic),
588bf4cb109SPeter Crosthwaite arm_gic_ppi_index(i, ARM_PHYS_TIMER_PPI));
58975b749afSLuc Michel qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), GTIMER_PHYS, irq);
590bf4cb109SPeter Crosthwaite irq = qdev_get_gpio_in(DEVICE(&s->gic),
591bf4cb109SPeter Crosthwaite arm_gic_ppi_index(i, ARM_VIRT_TIMER_PPI));
59275b749afSLuc Michel qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), GTIMER_VIRT, irq);
59375b749afSLuc Michel irq = qdev_get_gpio_in(DEVICE(&s->gic),
59475b749afSLuc Michel arm_gic_ppi_index(i, ARM_HYP_TIMER_PPI));
59575b749afSLuc Michel qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), GTIMER_HYP, irq);
59675b749afSLuc Michel irq = qdev_get_gpio_in(DEVICE(&s->gic),
59775b749afSLuc Michel arm_gic_ppi_index(i, ARM_SEC_TIMER_PPI));
59875b749afSLuc Michel qdev_connect_gpio_out(DEVICE(&s->apu_cpu[i]), GTIMER_SEC, irq);
59975b749afSLuc Michel
60075b749afSLuc Michel if (s->virt) {
60175b749afSLuc Michel irq = qdev_get_gpio_in(DEVICE(&s->gic),
60275b749afSLuc Michel arm_gic_ppi_index(i, GIC_MAINTENANCE_PPI));
60375b749afSLuc Michel sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + num_apus * 4, irq);
60475b749afSLuc Michel }
605f0a902f7SPeter Crosthwaite }
60614ca2e46SPeter Crosthwaite
607cc7d44c2SLike Xu xlnx_zynqmp_create_rpu(ms, s, boot_cpu, &err);
608b58850e7SPeter Crosthwaite if (err) {
60924cfc8dcSAlistair Francis error_propagate(errp, err);
610b58850e7SPeter Crosthwaite return;
611b58850e7SPeter Crosthwaite }
612b58850e7SPeter Crosthwaite
6136396a193SPeter Crosthwaite if (!s->boot_cpu_ptr) {
6149af9e0feSMarkus Armbruster error_setg(errp, "ZynqMP Boot cpu %s not found", boot_cpu);
6156396a193SPeter Crosthwaite return;
6166396a193SPeter Crosthwaite }
6176396a193SPeter Crosthwaite
61814ca2e46SPeter Crosthwaite for (i = 0; i < GIC_NUM_SPI_INTR; i++) {
61914ca2e46SPeter Crosthwaite gic_spi[i] = qdev_get_gpio_in(DEVICE(&s->gic), i);
62014ca2e46SPeter Crosthwaite }
62114ca2e46SPeter Crosthwaite
62214ca2e46SPeter Crosthwaite for (i = 0; i < XLNX_ZYNQMP_NUM_GEMS; i++) {
623e8c003c4SDavid Woodhouse qemu_configure_nic_device(DEVICE(&s->gem[i]), true, NULL);
6245325cc34SMarkus Armbruster object_property_set_int(OBJECT(&s->gem[i]), "revision", GEM_REVISION,
62520bff213SAlistair Francis &error_abort);
626dfc38879SBin Meng object_property_set_int(OBJECT(&s->gem[i]), "phy-addr", 23,
627dfc38879SBin Meng &error_abort);
6285325cc34SMarkus Armbruster object_property_set_int(OBJECT(&s->gem[i]), "num-priority-queues", 2,
6291372fc0bSAlistair Francis &error_abort);
630*604b72ddSKinsey Moore object_property_set_int(OBJECT(&s->gem_irq_orgate[i]),
631*604b72ddSKinsey Moore "num-lines", 2, &error_fatal);
632*604b72ddSKinsey Moore qdev_realize(DEVICE(&s->gem_irq_orgate[i]), NULL, &error_fatal);
633*604b72ddSKinsey Moore qdev_connect_gpio_out(DEVICE(&s->gem_irq_orgate[i]), 0, gic_spi[gem_intr[i]]);
634*604b72ddSKinsey Moore
635668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->gem[i]), errp)) {
63614ca2e46SPeter Crosthwaite return;
63714ca2e46SPeter Crosthwaite }
63814ca2e46SPeter Crosthwaite sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem[i]), 0, gem_addr[i]);
63914ca2e46SPeter Crosthwaite sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem[i]), 0,
640*604b72ddSKinsey Moore qdev_get_gpio_in(DEVICE(&s->gem_irq_orgate[i]), 0));
641*604b72ddSKinsey Moore sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem[i]), 1,
642*604b72ddSKinsey Moore qdev_get_gpio_in(DEVICE(&s->gem_irq_orgate[i]), 1));
64314ca2e46SPeter Crosthwaite }
6443bade2a9SPeter Crosthwaite
6453bade2a9SPeter Crosthwaite for (i = 0; i < XLNX_ZYNQMP_NUM_UARTS; i++) {
6469bca0edbSPeter Maydell qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
647668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->uart[i]), errp)) {
6483bade2a9SPeter Crosthwaite return;
6493bade2a9SPeter Crosthwaite }
6503bade2a9SPeter Crosthwaite sysbus_mmio_map(SYS_BUS_DEVICE(&s->uart[i]), 0, uart_addr[i]);
6513bade2a9SPeter Crosthwaite sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart[i]), 0,
6523bade2a9SPeter Crosthwaite gic_spi[uart_intr[i]]);
6533bade2a9SPeter Crosthwaite }
6546fdf3282SAlistair Francis
655840c22cdSVikram Garhwal for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) {
656840c22cdSVikram Garhwal object_property_set_int(OBJECT(&s->can[i]), "ext_clk_freq",
657840c22cdSVikram Garhwal XLNX_ZYNQMP_CAN_REF_CLK, &error_abort);
658840c22cdSVikram Garhwal
659840c22cdSVikram Garhwal object_property_set_link(OBJECT(&s->can[i]), "canbus",
660840c22cdSVikram Garhwal OBJECT(s->canbus[i]), &error_fatal);
661840c22cdSVikram Garhwal
662840c22cdSVikram Garhwal sysbus_realize(SYS_BUS_DEVICE(&s->can[i]), &err);
663840c22cdSVikram Garhwal if (err) {
664840c22cdSVikram Garhwal error_propagate(errp, err);
665840c22cdSVikram Garhwal return;
666840c22cdSVikram Garhwal }
667840c22cdSVikram Garhwal sysbus_mmio_map(SYS_BUS_DEVICE(&s->can[i]), 0, can_addr[i]);
668840c22cdSVikram Garhwal sysbus_connect_irq(SYS_BUS_DEVICE(&s->can[i]), 0,
669840c22cdSVikram Garhwal gic_spi[can_intr[i]]);
670840c22cdSVikram Garhwal }
671840c22cdSVikram Garhwal
6725325cc34SMarkus Armbruster object_property_set_int(OBJECT(&s->sata), "num-ports", SATA_NUM_PORTS,
6736fdf3282SAlistair Francis &error_abort);
674668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->sata), errp)) {
6756fdf3282SAlistair Francis return;
6766fdf3282SAlistair Francis }
6776fdf3282SAlistair Francis
6786fdf3282SAlistair Francis sysbus_mmio_map(SYS_BUS_DEVICE(&s->sata), 0, SATA_ADDR);
6796fdf3282SAlistair Francis sysbus_connect_irq(SYS_BUS_DEVICE(&s->sata), 0, gic_spi[SATA_INTR]);
68033108e9fSSai Pavan Boddu
68133108e9fSSai Pavan Boddu for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) {
68263fef628SPeter Maydell char *bus_name;
683b630d3d4SPhilippe Mathieu-Daudé SysBusDevice *sbd = SYS_BUS_DEVICE(&s->sdhci[i]);
684b630d3d4SPhilippe Mathieu-Daudé Object *sdhci = OBJECT(&s->sdhci[i]);
685eb4f566bSPeter Maydell
68621bce371SXuzhou Cheng /*
68721bce371SXuzhou Cheng * Compatible with:
688b630d3d4SPhilippe Mathieu-Daudé * - SD Host Controller Specification Version 3.00
689b630d3d4SPhilippe Mathieu-Daudé * - SDIO Specification Version 3.0
690b630d3d4SPhilippe Mathieu-Daudé * - eMMC Specification Version 4.51
691b630d3d4SPhilippe Mathieu-Daudé */
692668f62ecSMarkus Armbruster if (!object_property_set_uint(sdhci, "sd-spec-version", 3, errp)) {
693660b4e70SPeter Maydell return;
694660b4e70SPeter Maydell }
695778a2dc5SMarkus Armbruster if (!object_property_set_uint(sdhci, "capareg", SDHCI_CAPABILITIES,
696668f62ecSMarkus Armbruster errp)) {
697660b4e70SPeter Maydell return;
698660b4e70SPeter Maydell }
699668f62ecSMarkus Armbruster if (!object_property_set_uint(sdhci, "uhs", UHS_I, errp)) {
700660b4e70SPeter Maydell return;
701660b4e70SPeter Maydell }
702668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(sdhci), errp)) {
70333108e9fSSai Pavan Boddu return;
70433108e9fSSai Pavan Boddu }
705b630d3d4SPhilippe Mathieu-Daudé sysbus_mmio_map(sbd, 0, sdhci_addr[i]);
706b630d3d4SPhilippe Mathieu-Daudé sysbus_connect_irq(sbd, 0, gic_spi[sdhci_intr[i]]);
707b630d3d4SPhilippe Mathieu-Daudé
708eb4f566bSPeter Maydell /* Alias controller SD bus to the SoC itself */
70963fef628SPeter Maydell bus_name = g_strdup_printf("sd-bus%d", i);
710d2623129SMarkus Armbruster object_property_add_alias(OBJECT(s), bus_name, sdhci, "sd-bus");
711eb4f566bSPeter Maydell g_free(bus_name);
71233108e9fSSai Pavan Boddu }
71302d07eb4SAlistair Francis
71402d07eb4SAlistair Francis for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) {
71502d07eb4SAlistair Francis gchar *bus_name;
71602d07eb4SAlistair Francis
717668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->spi[i]), errp)) {
718660b4e70SPeter Maydell return;
719660b4e70SPeter Maydell }
72002d07eb4SAlistair Francis
72102d07eb4SAlistair Francis sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0, spi_addr[i]);
72202d07eb4SAlistair Francis sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi[i]), 0,
72302d07eb4SAlistair Francis gic_spi[spi_intr[i]]);
72402d07eb4SAlistair Francis
72502d07eb4SAlistair Francis /* Alias controller SPI bus to the SoC itself */
72602d07eb4SAlistair Francis bus_name = g_strdup_printf("spi%d", i);
72702d07eb4SAlistair Francis object_property_add_alias(OBJECT(s), bus_name,
728d2623129SMarkus Armbruster OBJECT(&s->spi[i]), "spi0");
72902d07eb4SAlistair Francis g_free(bus_name);
73002d07eb4SAlistair Francis }
731b93dbcddSKONRAD Frederic
732668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->dp), errp)) {
733b93dbcddSKONRAD Frederic return;
734b93dbcddSKONRAD Frederic }
735b93dbcddSKONRAD Frederic sysbus_mmio_map(SYS_BUS_DEVICE(&s->dp), 0, DP_ADDR);
736b93dbcddSKONRAD Frederic sysbus_connect_irq(SYS_BUS_DEVICE(&s->dp), 0, gic_spi[DP_IRQ]);
737b93dbcddSKONRAD Frederic
738668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->dpdma), errp)) {
739b93dbcddSKONRAD Frederic return;
740b93dbcddSKONRAD Frederic }
7415325cc34SMarkus Armbruster object_property_set_link(OBJECT(&s->dp), "dpdma", OBJECT(&s->dpdma),
742b93dbcddSKONRAD Frederic &error_abort);
743b93dbcddSKONRAD Frederic sysbus_mmio_map(SYS_BUS_DEVICE(&s->dpdma), 0, DPDMA_ADDR);
744b93dbcddSKONRAD Frederic sysbus_connect_irq(SYS_BUS_DEVICE(&s->dpdma), 0, gic_spi[DPDMA_IRQ]);
7450ab7bbc7SAlistair Francis
746668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->ipi), errp)) {
7470ab7bbc7SAlistair Francis return;
7480ab7bbc7SAlistair Francis }
7490ab7bbc7SAlistair Francis sysbus_mmio_map(SYS_BUS_DEVICE(&s->ipi), 0, IPI_ADDR);
7500ab7bbc7SAlistair Francis sysbus_connect_irq(SYS_BUS_DEVICE(&s->ipi), 0, gic_spi[IPI_IRQ]);
75108b2f15eSAlistair Francis
752668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->rtc), errp)) {
75308b2f15eSAlistair Francis return;
75408b2f15eSAlistair Francis }
75508b2f15eSAlistair Francis sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, RTC_ADDR);
75608b2f15eSAlistair Francis sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0, gic_spi[RTC_IRQ]);
75704965bcaSFrancisco Iglesias
7587e47e15cSTong Ho xlnx_zynqmp_create_bbram(s, gic_spi);
759db1264dfSTong Ho xlnx_zynqmp_create_efuse(s, gic_spi);
760eb7a38baSEdgar E. Iglesias xlnx_zynqmp_create_apu_ctrl(s, gic_spi);
76163320bcaSEdgar E. Iglesias xlnx_zynqmp_create_crf(s, gic_spi);
76251af6231SEdgar E. Iglesias xlnx_zynqmp_create_ttc(s, gic_spi);
763d2e6f370STong Ho xlnx_zynqmp_create_unimp_mmio(s);
764d2e6f370STong Ho
76504965bcaSFrancisco Iglesias for (i = 0; i < XLNX_ZYNQMP_NUM_GDMA_CH; i++) {
766778a2dc5SMarkus Armbruster if (!object_property_set_uint(OBJECT(&s->gdma[i]), "bus-width", 128,
767668f62ecSMarkus Armbruster errp)) {
768660b4e70SPeter Maydell return;
769660b4e70SPeter Maydell }
770783dbab1SPhilippe Mathieu-Daudé if (!object_property_set_link(OBJECT(&s->gdma[i]), "dma",
771783dbab1SPhilippe Mathieu-Daudé OBJECT(system_memory), errp)) {
772783dbab1SPhilippe Mathieu-Daudé return;
773783dbab1SPhilippe Mathieu-Daudé }
774668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->gdma[i]), errp)) {
77504965bcaSFrancisco Iglesias return;
77604965bcaSFrancisco Iglesias }
77704965bcaSFrancisco Iglesias
77804965bcaSFrancisco Iglesias sysbus_mmio_map(SYS_BUS_DEVICE(&s->gdma[i]), 0, gdma_ch_addr[i]);
77904965bcaSFrancisco Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(&s->gdma[i]), 0,
78004965bcaSFrancisco Iglesias gic_spi[gdma_ch_intr[i]]);
78104965bcaSFrancisco Iglesias }
78204965bcaSFrancisco Iglesias
78304965bcaSFrancisco Iglesias for (i = 0; i < XLNX_ZYNQMP_NUM_ADMA_CH; i++) {
784783dbab1SPhilippe Mathieu-Daudé if (!object_property_set_link(OBJECT(&s->adma[i]), "dma",
785783dbab1SPhilippe Mathieu-Daudé OBJECT(system_memory), errp)) {
786783dbab1SPhilippe Mathieu-Daudé return;
787783dbab1SPhilippe Mathieu-Daudé }
788668f62ecSMarkus Armbruster if (!sysbus_realize(SYS_BUS_DEVICE(&s->adma[i]), errp)) {
78904965bcaSFrancisco Iglesias return;
79004965bcaSFrancisco Iglesias }
79104965bcaSFrancisco Iglesias
79204965bcaSFrancisco Iglesias sysbus_mmio_map(SYS_BUS_DEVICE(&s->adma[i]), 0, adma_ch_addr[i]);
79304965bcaSFrancisco Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(&s->adma[i]), 0,
79404965bcaSFrancisco Iglesias gic_spi[adma_ch_intr[i]]);
79504965bcaSFrancisco Iglesias }
796668351a5SXuzhou Cheng
797c74ccb5dSFrancisco Iglesias object_property_set_int(OBJECT(&s->qspi_irq_orgate),
798c74ccb5dSFrancisco Iglesias "num-lines", NUM_QSPI_IRQ_LINES, &error_fatal);
799c74ccb5dSFrancisco Iglesias qdev_realize(DEVICE(&s->qspi_irq_orgate), NULL, &error_fatal);
800c74ccb5dSFrancisco Iglesias qdev_connect_gpio_out(DEVICE(&s->qspi_irq_orgate), 0, gic_spi[QSPI_IRQ]);
801c74ccb5dSFrancisco Iglesias
802c31b7f59SPhilippe Mathieu-Daudé if (!object_property_set_link(OBJECT(&s->qspi_dma), "dma",
803c31b7f59SPhilippe Mathieu-Daudé OBJECT(system_memory), errp)) {
804c31b7f59SPhilippe Mathieu-Daudé return;
805c31b7f59SPhilippe Mathieu-Daudé }
806668351a5SXuzhou Cheng if (!sysbus_realize(SYS_BUS_DEVICE(&s->qspi_dma), errp)) {
807668351a5SXuzhou Cheng return;
808668351a5SXuzhou Cheng }
809668351a5SXuzhou Cheng
810668351a5SXuzhou Cheng sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi_dma), 0, QSPI_DMA_ADDR);
811c74ccb5dSFrancisco Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(&s->qspi_dma), 0,
812c74ccb5dSFrancisco Iglesias qdev_get_gpio_in(DEVICE(&s->qspi_irq_orgate), 0));
81334a3a71dSPhilippe Mathieu-Daudé
81434a3a71dSPhilippe Mathieu-Daudé if (!object_property_set_link(OBJECT(&s->qspi), "stream-connected-dma",
81534a3a71dSPhilippe Mathieu-Daudé OBJECT(&s->qspi_dma), errp)) {
81634a3a71dSPhilippe Mathieu-Daudé return;
81734a3a71dSPhilippe Mathieu-Daudé }
81834a3a71dSPhilippe Mathieu-Daudé if (!sysbus_realize(SYS_BUS_DEVICE(&s->qspi), errp)) {
81934a3a71dSPhilippe Mathieu-Daudé return;
82034a3a71dSPhilippe Mathieu-Daudé }
82134a3a71dSPhilippe Mathieu-Daudé sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi), 0, QSPI_ADDR);
82234a3a71dSPhilippe Mathieu-Daudé sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi), 1, LQSPI_ADDR);
823c74ccb5dSFrancisco Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(&s->qspi), 0,
824c74ccb5dSFrancisco Iglesias qdev_get_gpio_in(DEVICE(&s->qspi_irq_orgate), 1));
82534a3a71dSPhilippe Mathieu-Daudé
82634a3a71dSPhilippe Mathieu-Daudé for (i = 0; i < XLNX_ZYNQMP_NUM_QSPI_BUS; i++) {
82734a3a71dSPhilippe Mathieu-Daudé g_autofree gchar *bus_name = g_strdup_printf("qspi%d", i);
82834a3a71dSPhilippe Mathieu-Daudé g_autofree gchar *target_bus = g_strdup_printf("spi%d", i);
82934a3a71dSPhilippe Mathieu-Daudé
83034a3a71dSPhilippe Mathieu-Daudé /* Alias controller SPI bus to the SoC itself */
83134a3a71dSPhilippe Mathieu-Daudé object_property_add_alias(OBJECT(s), bus_name,
83234a3a71dSPhilippe Mathieu-Daudé OBJECT(&s->qspi), target_bus);
83334a3a71dSPhilippe Mathieu-Daudé }
834acc0b8b0SFrancisco Iglesias
835acc0b8b0SFrancisco Iglesias for (i = 0; i < XLNX_ZYNQMP_NUM_USB; i++) {
836acc0b8b0SFrancisco Iglesias if (!object_property_set_link(OBJECT(&s->usb[i].sysbus_xhci), "dma",
837acc0b8b0SFrancisco Iglesias OBJECT(system_memory), errp)) {
838acc0b8b0SFrancisco Iglesias return;
839acc0b8b0SFrancisco Iglesias }
840acc0b8b0SFrancisco Iglesias
841acc0b8b0SFrancisco Iglesias qdev_prop_set_uint32(DEVICE(&s->usb[i].sysbus_xhci), "intrs", 4);
842acc0b8b0SFrancisco Iglesias qdev_prop_set_uint32(DEVICE(&s->usb[i].sysbus_xhci), "slots", 2);
843acc0b8b0SFrancisco Iglesias
844acc0b8b0SFrancisco Iglesias if (!sysbus_realize(SYS_BUS_DEVICE(&s->usb[i]), errp)) {
845acc0b8b0SFrancisco Iglesias return;
846acc0b8b0SFrancisco Iglesias }
847acc0b8b0SFrancisco Iglesias
848acc0b8b0SFrancisco Iglesias sysbus_mmio_map(SYS_BUS_DEVICE(&s->usb[i]), 0, usb_addr[i]);
849acc0b8b0SFrancisco Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i].sysbus_xhci), 0,
850acc0b8b0SFrancisco Iglesias gic_spi[usb_intr[i]]);
851acc0b8b0SFrancisco Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i].sysbus_xhci), 1,
852acc0b8b0SFrancisco Iglesias gic_spi[usb_intr[i] + 1]);
853acc0b8b0SFrancisco Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i].sysbus_xhci), 2,
854acc0b8b0SFrancisco Iglesias gic_spi[usb_intr[i] + 2]);
855acc0b8b0SFrancisco Iglesias sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i].sysbus_xhci), 3,
856acc0b8b0SFrancisco Iglesias gic_spi[usb_intr[i] + 3]);
857acc0b8b0SFrancisco Iglesias }
858f0a902f7SPeter Crosthwaite }
859f0a902f7SPeter Crosthwaite
8606396a193SPeter Crosthwaite static Property xlnx_zynqmp_props[] = {
8616396a193SPeter Crosthwaite DEFINE_PROP_STRING("boot-cpu", XlnxZynqMPState, boot_cpu),
86237d42473SEdgar E. Iglesias DEFINE_PROP_BOOL("secure", XlnxZynqMPState, secure, false),
8631946809eSAlistair Francis DEFINE_PROP_BOOL("virtualization", XlnxZynqMPState, virt, false),
864c3acfa01SFam Zheng DEFINE_PROP_LINK("ddr-ram", XlnxZynqMPState, ddr_ram, TYPE_MEMORY_REGION,
865c3acfa01SFam Zheng MemoryRegion *),
866840c22cdSVikram Garhwal DEFINE_PROP_LINK("canbus0", XlnxZynqMPState, canbus[0], TYPE_CAN_BUS,
867840c22cdSVikram Garhwal CanBusState *),
868840c22cdSVikram Garhwal DEFINE_PROP_LINK("canbus1", XlnxZynqMPState, canbus[1], TYPE_CAN_BUS,
869840c22cdSVikram Garhwal CanBusState *),
8706396a193SPeter Crosthwaite DEFINE_PROP_END_OF_LIST()
8716396a193SPeter Crosthwaite };
8726396a193SPeter Crosthwaite
xlnx_zynqmp_class_init(ObjectClass * oc,void * data)873f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_class_init(ObjectClass *oc, void *data)
874f0a902f7SPeter Crosthwaite {
875f0a902f7SPeter Crosthwaite DeviceClass *dc = DEVICE_CLASS(oc);
876f0a902f7SPeter Crosthwaite
8774f67d30bSMarc-André Lureau device_class_set_props(dc, xlnx_zynqmp_props);
878f0a902f7SPeter Crosthwaite dc->realize = xlnx_zynqmp_realize;
879d8589144SThomas Huth /* Reason: Uses serial_hds in realize function, thus can't be used twice */
880d8589144SThomas Huth dc->user_creatable = false;
881f0a902f7SPeter Crosthwaite }
882f0a902f7SPeter Crosthwaite
883f0a902f7SPeter Crosthwaite static const TypeInfo xlnx_zynqmp_type_info = {
884f0a902f7SPeter Crosthwaite .name = TYPE_XLNX_ZYNQMP,
885f0a902f7SPeter Crosthwaite .parent = TYPE_DEVICE,
886f0a902f7SPeter Crosthwaite .instance_size = sizeof(XlnxZynqMPState),
887f0a902f7SPeter Crosthwaite .instance_init = xlnx_zynqmp_init,
888f0a902f7SPeter Crosthwaite .class_init = xlnx_zynqmp_class_init,
889f0a902f7SPeter Crosthwaite };
890f0a902f7SPeter Crosthwaite
xlnx_zynqmp_register_types(void)891f0a902f7SPeter Crosthwaite static void xlnx_zynqmp_register_types(void)
892f0a902f7SPeter Crosthwaite {
893f0a902f7SPeter Crosthwaite type_register_static(&xlnx_zynqmp_type_info);
894f0a902f7SPeter Crosthwaite }
895f0a902f7SPeter Crosthwaite
896f0a902f7SPeter Crosthwaite type_init(xlnx_zynqmp_register_types)
897