1 /* 2 * Copyright (c) 2018 Jean-Christophe Dubois <jcd@tribudubois.net> 3 * 4 * MCIMX6UL_EVK Board System emulation. 5 * 6 * This code is licensed under the GPL, version 2 or later. 7 * See the file `COPYING' in the top level directory. 8 * 9 * It (partially) emulates a mcimx6ul_evk board, with a Freescale 10 * i.MX6ul SoC 11 */ 12 13 #include "qemu/osdep.h" 14 #include "qapi/error.h" 15 #include "hw/arm/fsl-imx6ul.h" 16 #include "hw/boards.h" 17 #include "hw/qdev-properties.h" 18 #include "sysemu/sysemu.h" 19 #include "qemu/error-report.h" 20 #include "sysemu/qtest.h" 21 22 typedef struct { 23 FslIMX6ULState soc; 24 MemoryRegion ram; 25 } MCIMX6ULEVK; 26 27 static void mcimx6ul_evk_init(MachineState *machine) 28 { 29 static struct arm_boot_info boot_info; 30 MCIMX6ULEVK *s = g_new0(MCIMX6ULEVK, 1); 31 int i; 32 33 if (machine->ram_size > FSL_IMX6UL_MMDC_SIZE) { 34 error_report("RAM size " RAM_ADDR_FMT " above max supported (%08x)", 35 machine->ram_size, FSL_IMX6UL_MMDC_SIZE); 36 exit(1); 37 } 38 39 boot_info = (struct arm_boot_info) { 40 .loader_start = FSL_IMX6UL_MMDC_ADDR, 41 .board_id = -1, 42 .ram_size = machine->ram_size, 43 .nb_cpus = machine->smp.cpus, 44 }; 45 46 object_initialize_child(OBJECT(machine), "soc", &s->soc, sizeof(s->soc), 47 TYPE_FSL_IMX6UL, &error_fatal, NULL); 48 49 object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_fatal); 50 51 memory_region_allocate_system_memory(&s->ram, NULL, "mcimx6ul-evk.ram", 52 machine->ram_size); 53 memory_region_add_subregion(get_system_memory(), 54 FSL_IMX6UL_MMDC_ADDR, &s->ram); 55 56 for (i = 0; i < FSL_IMX6UL_NUM_USDHCS; i++) { 57 BusState *bus; 58 DeviceState *carddev; 59 DriveInfo *di; 60 BlockBackend *blk; 61 62 di = drive_get_next(IF_SD); 63 blk = di ? blk_by_legacy_dinfo(di) : NULL; 64 bus = qdev_get_child_bus(DEVICE(&s->soc.usdhc[i]), "sd-bus"); 65 carddev = qdev_create(bus, TYPE_SD_CARD); 66 qdev_prop_set_drive(carddev, "drive", blk, &error_fatal); 67 object_property_set_bool(OBJECT(carddev), true, 68 "realized", &error_fatal); 69 } 70 71 if (!qtest_enabled()) { 72 arm_load_kernel(&s->soc.cpu, machine, &boot_info); 73 } 74 } 75 76 static void mcimx6ul_evk_machine_init(MachineClass *mc) 77 { 78 mc->desc = "Freescale i.MX6UL Evaluation Kit (Cortex A7)"; 79 mc->init = mcimx6ul_evk_init; 80 mc->max_cpus = FSL_IMX6UL_NUM_CPUS; 81 } 82 DEFINE_MACHINE("mcimx6ul-evk", mcimx6ul_evk_machine_init) 83