1 /* 2 * Xilinx ZynqMP ZCU102 board 3 * 4 * Copyright (C) 2015 Xilinx Inc 5 * Written by Peter Crosthwaite <peter.crosthwaite@xilinx.com> 6 * 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. 11 * 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 15 * for more details. 16 */ 17 18 #include "qemu/osdep.h" 19 #include "qapi/error.h" 20 #include "qemu-common.h" 21 #include "cpu.h" 22 #include "hw/arm/xlnx-zynqmp.h" 23 #include "hw/boards.h" 24 #include "qemu/error-report.h" 25 #include "exec/address-spaces.h" 26 #include "qemu/log.h" 27 28 typedef struct XlnxZCU102 { 29 MachineState parent_obj; 30 31 XlnxZynqMPState soc; 32 MemoryRegion ddr_ram; 33 34 bool secure; 35 bool virt; 36 } XlnxZCU102; 37 38 #define TYPE_ZCU102_MACHINE MACHINE_TYPE_NAME("xlnx-zcu102") 39 #define ZCU102_MACHINE(obj) \ 40 OBJECT_CHECK(XlnxZCU102, (obj), TYPE_ZCU102_MACHINE) 41 42 #define TYPE_EP108_MACHINE MACHINE_TYPE_NAME("xlnx-ep108") 43 #define EP108_MACHINE(obj) \ 44 OBJECT_CHECK(XlnxZCU102, (obj), TYPE_EP108_MACHINE) 45 46 static struct arm_boot_info xlnx_zcu102_binfo; 47 48 static bool zcu102_get_secure(Object *obj, Error **errp) 49 { 50 XlnxZCU102 *s = ZCU102_MACHINE(obj); 51 52 return s->secure; 53 } 54 55 static void zcu102_set_secure(Object *obj, bool value, Error **errp) 56 { 57 XlnxZCU102 *s = ZCU102_MACHINE(obj); 58 59 s->secure = value; 60 } 61 62 static bool zcu102_get_virt(Object *obj, Error **errp) 63 { 64 XlnxZCU102 *s = ZCU102_MACHINE(obj); 65 66 return s->virt; 67 } 68 69 static void zcu102_set_virt(Object *obj, bool value, Error **errp) 70 { 71 XlnxZCU102 *s = ZCU102_MACHINE(obj); 72 73 s->virt = value; 74 } 75 76 static void xlnx_zynqmp_init(XlnxZCU102 *s, MachineState *machine) 77 { 78 int i; 79 uint64_t ram_size = machine->ram_size; 80 81 /* Create the memory region to pass to the SoC */ 82 if (ram_size > XLNX_ZYNQMP_MAX_RAM_SIZE) { 83 error_report("ERROR: RAM size 0x%" PRIx64 " above max supported of " 84 "0x%llx", ram_size, 85 XLNX_ZYNQMP_MAX_RAM_SIZE); 86 exit(1); 87 } 88 89 if (ram_size < 0x08000000) { 90 qemu_log("WARNING: RAM size 0x%" PRIx64 " is small for ZCU102", 91 ram_size); 92 } 93 94 memory_region_allocate_system_memory(&s->ddr_ram, NULL, "ddr-ram", 95 ram_size); 96 97 object_initialize(&s->soc, sizeof(s->soc), TYPE_XLNX_ZYNQMP); 98 object_property_add_child(OBJECT(machine), "soc", OBJECT(&s->soc), 99 &error_abort); 100 101 object_property_set_link(OBJECT(&s->soc), OBJECT(&s->ddr_ram), 102 "ddr-ram", &error_abort); 103 object_property_set_bool(OBJECT(&s->soc), s->secure, "secure", 104 &error_fatal); 105 object_property_set_bool(OBJECT(&s->soc), s->virt, "virtualization", 106 &error_fatal); 107 108 object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_fatal); 109 110 /* Create and plug in the SD cards */ 111 for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) { 112 BusState *bus; 113 DriveInfo *di = drive_get_next(IF_SD); 114 BlockBackend *blk = di ? blk_by_legacy_dinfo(di) : NULL; 115 DeviceState *carddev; 116 char *bus_name; 117 118 bus_name = g_strdup_printf("sd-bus%d", i); 119 bus = qdev_get_child_bus(DEVICE(&s->soc), bus_name); 120 g_free(bus_name); 121 if (!bus) { 122 error_report("No SD bus found for SD card %d", i); 123 exit(1); 124 } 125 carddev = qdev_create(bus, TYPE_SD_CARD); 126 qdev_prop_set_drive(carddev, "drive", blk, &error_fatal); 127 object_property_set_bool(OBJECT(carddev), true, "realized", 128 &error_fatal); 129 } 130 131 for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) { 132 SSIBus *spi_bus; 133 DeviceState *flash_dev; 134 qemu_irq cs_line; 135 DriveInfo *dinfo = drive_get_next(IF_MTD); 136 gchar *bus_name = g_strdup_printf("spi%d", i); 137 138 spi_bus = (SSIBus *)qdev_get_child_bus(DEVICE(&s->soc), bus_name); 139 g_free(bus_name); 140 141 flash_dev = ssi_create_slave_no_init(spi_bus, "sst25wf080"); 142 if (dinfo) { 143 qdev_prop_set_drive(flash_dev, "drive", blk_by_legacy_dinfo(dinfo), 144 &error_fatal); 145 } 146 qdev_init_nofail(flash_dev); 147 148 cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0); 149 150 sysbus_connect_irq(SYS_BUS_DEVICE(&s->soc.spi[i]), 1, cs_line); 151 } 152 153 /* TODO create and connect IDE devices for ide_drive_get() */ 154 155 xlnx_zcu102_binfo.ram_size = ram_size; 156 xlnx_zcu102_binfo.kernel_filename = machine->kernel_filename; 157 xlnx_zcu102_binfo.kernel_cmdline = machine->kernel_cmdline; 158 xlnx_zcu102_binfo.initrd_filename = machine->initrd_filename; 159 xlnx_zcu102_binfo.loader_start = 0; 160 arm_load_kernel(s->soc.boot_cpu_ptr, &xlnx_zcu102_binfo); 161 } 162 163 static void xlnx_ep108_init(MachineState *machine) 164 { 165 XlnxZCU102 *s = EP108_MACHINE(machine); 166 167 info_report("The Xilinx EP108 machine is deprecated, please use the " 168 "ZCU102 machine instead. It has the same features supported."); 169 170 xlnx_zynqmp_init(s, machine); 171 } 172 173 static void xlnx_ep108_machine_instance_init(Object *obj) 174 { 175 XlnxZCU102 *s = EP108_MACHINE(obj); 176 177 /* EP108, we don't support setting secure or virt */ 178 s->secure = false; 179 s->virt = false; 180 } 181 182 static void xlnx_ep108_machine_class_init(ObjectClass *oc, void *data) 183 { 184 MachineClass *mc = MACHINE_CLASS(oc); 185 186 mc->desc = "Xilinx ZynqMP EP108 board (Deprecated, please use xlnx-zcu102)"; 187 mc->init = xlnx_ep108_init; 188 mc->block_default_type = IF_IDE; 189 mc->units_per_default_bus = 1; 190 mc->ignore_memory_transaction_failures = true; 191 mc->max_cpus = XLNX_ZYNQMP_NUM_APU_CPUS + XLNX_ZYNQMP_NUM_RPU_CPUS; 192 mc->default_cpus = XLNX_ZYNQMP_NUM_APU_CPUS; 193 } 194 195 static const TypeInfo xlnx_ep108_machine_init_typeinfo = { 196 .name = MACHINE_TYPE_NAME("xlnx-ep108"), 197 .parent = TYPE_MACHINE, 198 .class_init = xlnx_ep108_machine_class_init, 199 .instance_init = xlnx_ep108_machine_instance_init, 200 .instance_size = sizeof(XlnxZCU102), 201 }; 202 203 static void xlnx_ep108_machine_init_register_types(void) 204 { 205 type_register_static(&xlnx_ep108_machine_init_typeinfo); 206 } 207 208 static void xlnx_zcu102_init(MachineState *machine) 209 { 210 XlnxZCU102 *s = ZCU102_MACHINE(machine); 211 212 xlnx_zynqmp_init(s, machine); 213 } 214 215 static void xlnx_zcu102_machine_instance_init(Object *obj) 216 { 217 XlnxZCU102 *s = ZCU102_MACHINE(obj); 218 219 /* Default to secure mode being disabled */ 220 s->secure = false; 221 object_property_add_bool(obj, "secure", zcu102_get_secure, 222 zcu102_set_secure, NULL); 223 object_property_set_description(obj, "secure", 224 "Set on/off to enable/disable the ARM " 225 "Security Extensions (TrustZone)", 226 NULL); 227 228 /* Default to virt (EL2) being disabled */ 229 s->virt = false; 230 object_property_add_bool(obj, "virtualization", zcu102_get_virt, 231 zcu102_set_virt, NULL); 232 object_property_set_description(obj, "virtualization", 233 "Set on/off to enable/disable emulating a " 234 "guest CPU which implements the ARM " 235 "Virtualization Extensions", 236 NULL); 237 } 238 239 static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data) 240 { 241 MachineClass *mc = MACHINE_CLASS(oc); 242 243 mc->desc = "Xilinx ZynqMP ZCU102 board with 4xA53s and 2xR5s based on " \ 244 "the value of smp"; 245 mc->init = xlnx_zcu102_init; 246 mc->block_default_type = IF_IDE; 247 mc->units_per_default_bus = 1; 248 mc->ignore_memory_transaction_failures = true; 249 mc->max_cpus = XLNX_ZYNQMP_NUM_APU_CPUS + XLNX_ZYNQMP_NUM_RPU_CPUS; 250 mc->default_cpus = XLNX_ZYNQMP_NUM_APU_CPUS; 251 } 252 253 static const TypeInfo xlnx_zcu102_machine_init_typeinfo = { 254 .name = MACHINE_TYPE_NAME("xlnx-zcu102"), 255 .parent = TYPE_MACHINE, 256 .class_init = xlnx_zcu102_machine_class_init, 257 .instance_init = xlnx_zcu102_machine_instance_init, 258 .instance_size = sizeof(XlnxZCU102), 259 }; 260 261 static void xlnx_zcu102_machine_init_register_types(void) 262 { 263 type_register_static(&xlnx_zcu102_machine_init_typeinfo); 264 } 265 266 type_init(xlnx_zcu102_machine_init_register_types) 267 type_init(xlnx_ep108_machine_init_register_types) 268