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