2 * Xilinx ZynqMP ZCU102 board
4 * Copyright (C) 2015 Xilinx Inc
5 * Written by Peter Crosthwaite <peter.crosthwaite@xilinx.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 #include "qemu/osdep.h"
19 #include "qapi/error.h"
21 #include "hw/arm/xlnx-zynqmp.h"
22 #include "hw/boards.h"
23 #include "qemu/error-report.h"
25 #include "sysemu/qtest.h"
26 #include "sysemu/device_tree.h"
27 #include "qom/object.h"
30 MachineState parent_obj
;
37 struct arm_boot_info binfo
;
40 #define TYPE_ZCU102_MACHINE MACHINE_TYPE_NAME("xlnx-zcu102")
41 OBJECT_DECLARE_SIMPLE_TYPE(XlnxZCU102
, ZCU102_MACHINE
)
44 static bool zcu102_get_secure(Object
*obj
, Error
**errp
)
46 XlnxZCU102
*s
= ZCU102_MACHINE(obj
);
51 static void zcu102_set_secure(Object
*obj
, bool value
, Error
**errp
)
53 XlnxZCU102
*s
= ZCU102_MACHINE(obj
);
58 static bool zcu102_get_virt(Object
*obj
, Error
**errp
)
60 XlnxZCU102
*s
= ZCU102_MACHINE(obj
);
65 static void zcu102_set_virt(Object
*obj
, bool value
, Error
**errp
)
67 XlnxZCU102
*s
= ZCU102_MACHINE(obj
);
72 static void zcu102_modify_dtb(const struct arm_boot_info
*binfo
, void *fdt
)
74 XlnxZCU102
*s
= container_of(binfo
, XlnxZCU102
, binfo
);
81 /* If EL3 is enabled, we keep all firmware nodes active. */
83 node_path
= qemu_fdt_node_path(fdt
, NULL
, "xlnx,zynqmp-firmware",
86 for (i
= 0; node_path
&& node_path
[i
]; i
++) {
87 r
= qemu_fdt_getprop(fdt
, node_path
[i
], "method", &prop_len
, NULL
);
88 method_is_hvc
= r
&& !strcmp("hvc", r
);
90 /* Allow HVC based firmware if EL2 is enabled. */
91 if (method_is_hvc
&& s
->virt
) {
94 qemu_fdt_setprop_string(fdt
, node_path
[i
], "status", "disabled");
96 g_strfreev(node_path
);
100 static void xlnx_zcu102_init(MachineState
*machine
)
102 XlnxZCU102
*s
= ZCU102_MACHINE(machine
);
104 uint64_t ram_size
= machine
->ram_size
;
106 /* Create the memory region to pass to the SoC */
107 if (ram_size
> XLNX_ZYNQMP_MAX_RAM_SIZE
) {
108 error_report("ERROR: RAM size 0x%" PRIx64
" above max supported of "
110 XLNX_ZYNQMP_MAX_RAM_SIZE
);
114 if (ram_size
< 0x08000000) {
115 qemu_log("WARNING: RAM size 0x%" PRIx64
" is small for ZCU102",
119 object_initialize_child(OBJECT(machine
), "soc", &s
->soc
, TYPE_XLNX_ZYNQMP
);
121 object_property_set_link(OBJECT(&s
->soc
), "ddr-ram", OBJECT(machine
->ram
),
123 object_property_set_bool(OBJECT(&s
->soc
), "secure", s
->secure
,
125 object_property_set_bool(OBJECT(&s
->soc
), "virtualization", s
->virt
,
128 qdev_realize(DEVICE(&s
->soc
), NULL
, &error_fatal
);
130 /* Create and plug in the SD cards */
131 for (i
= 0; i
< XLNX_ZYNQMP_NUM_SDHCI
; i
++) {
133 DriveInfo
*di
= drive_get_next(IF_SD
);
134 BlockBackend
*blk
= di
? blk_by_legacy_dinfo(di
) : NULL
;
135 DeviceState
*carddev
;
138 bus_name
= g_strdup_printf("sd-bus%d", i
);
139 bus
= qdev_get_child_bus(DEVICE(&s
->soc
), bus_name
);
142 error_report("No SD bus found for SD card %d", i
);
145 carddev
= qdev_new(TYPE_SD_CARD
);
146 qdev_prop_set_drive_err(carddev
, "drive", blk
, &error_fatal
);
147 qdev_realize_and_unref(carddev
, bus
, &error_fatal
);
150 for (i
= 0; i
< XLNX_ZYNQMP_NUM_SPIS
; i
++) {
152 DeviceState
*flash_dev
;
154 DriveInfo
*dinfo
= drive_get_next(IF_MTD
);
155 gchar
*bus_name
= g_strdup_printf("spi%d", i
);
157 spi_bus
= qdev_get_child_bus(DEVICE(&s
->soc
), bus_name
);
160 flash_dev
= qdev_new("sst25wf080");
162 qdev_prop_set_drive_err(flash_dev
, "drive",
163 blk_by_legacy_dinfo(dinfo
), &error_fatal
);
165 qdev_realize_and_unref(flash_dev
, spi_bus
, &error_fatal
);
167 cs_line
= qdev_get_gpio_in_named(flash_dev
, SSI_GPIO_CS
, 0);
169 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->soc
.spi
[i
]), 1, cs_line
);
172 for (i
= 0; i
< XLNX_ZYNQMP_NUM_QSPI_FLASH
; i
++) {
174 DeviceState
*flash_dev
;
176 DriveInfo
*dinfo
= drive_get_next(IF_MTD
);
177 int bus
= i
/ XLNX_ZYNQMP_NUM_QSPI_BUS_CS
;
178 gchar
*bus_name
= g_strdup_printf("qspi%d", bus
);
180 spi_bus
= qdev_get_child_bus(DEVICE(&s
->soc
), bus_name
);
183 flash_dev
= qdev_new("n25q512a11");
185 qdev_prop_set_drive_err(flash_dev
, "drive",
186 blk_by_legacy_dinfo(dinfo
), &error_fatal
);
188 qdev_realize_and_unref(flash_dev
, spi_bus
, &error_fatal
);
190 cs_line
= qdev_get_gpio_in_named(flash_dev
, SSI_GPIO_CS
, 0);
192 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->soc
.qspi
), i
+ 1, cs_line
);
195 /* TODO create and connect IDE devices for ide_drive_get() */
197 s
->binfo
.ram_size
= ram_size
;
198 s
->binfo
.loader_start
= 0;
199 s
->binfo
.modify_dtb
= zcu102_modify_dtb
;
200 arm_load_kernel(s
->soc
.boot_cpu_ptr
, machine
, &s
->binfo
);
203 static void xlnx_zcu102_machine_instance_init(Object
*obj
)
205 XlnxZCU102
*s
= ZCU102_MACHINE(obj
);
207 /* Default to secure mode being disabled */
209 /* Default to virt (EL2) being disabled */
213 static void xlnx_zcu102_machine_class_init(ObjectClass
*oc
, void *data
)
215 MachineClass
*mc
= MACHINE_CLASS(oc
);
217 mc
->desc
= "Xilinx ZynqMP ZCU102 board with 4xA53s and 2xR5Fs based on " \
219 mc
->init
= xlnx_zcu102_init
;
220 mc
->block_default_type
= IF_IDE
;
221 mc
->units_per_default_bus
= 1;
222 mc
->ignore_memory_transaction_failures
= true;
223 mc
->max_cpus
= XLNX_ZYNQMP_NUM_APU_CPUS
+ XLNX_ZYNQMP_NUM_RPU_CPUS
;
224 mc
->default_cpus
= XLNX_ZYNQMP_NUM_APU_CPUS
;
225 mc
->default_ram_id
= "ddr-ram";
227 object_class_property_add_bool(oc
, "secure", zcu102_get_secure
,
229 object_class_property_set_description(oc
, "secure",
230 "Set on/off to enable/disable the ARM "
231 "Security Extensions (TrustZone)");
233 object_class_property_add_bool(oc
, "virtualization", zcu102_get_virt
,
235 object_class_property_set_description(oc
, "virtualization",
236 "Set on/off to enable/disable emulating a "
237 "guest CPU which implements the ARM "
238 "Virtualization Extensions");
241 static const TypeInfo xlnx_zcu102_machine_init_typeinfo
= {
242 .name
= TYPE_ZCU102_MACHINE
,
243 .parent
= TYPE_MACHINE
,
244 .class_init
= xlnx_zcu102_machine_class_init
,
245 .instance_init
= xlnx_zcu102_machine_instance_init
,
246 .instance_size
= sizeof(XlnxZCU102
),
249 static void xlnx_zcu102_machine_init_register_types(void)
251 type_register_static(&xlnx_zcu102_machine_init_typeinfo
);
254 type_init(xlnx_zcu102_machine_init_register_types
)