xref: /qemu/hw/arm/mcimx6ul-evk.c (revision cc7d44c2e0fc9dff1b9eef857f14a7fd31d71f46)
10550e3bfSJean-Christophe Dubois /*
20550e3bfSJean-Christophe Dubois  * Copyright (c) 2018 Jean-Christophe Dubois <jcd@tribudubois.net>
30550e3bfSJean-Christophe Dubois  *
40550e3bfSJean-Christophe Dubois  * MCIMX6UL_EVK Board System emulation.
50550e3bfSJean-Christophe Dubois  *
60550e3bfSJean-Christophe Dubois  * This code is licensed under the GPL, version 2 or later.
70550e3bfSJean-Christophe Dubois  * See the file `COPYING' in the top level directory.
80550e3bfSJean-Christophe Dubois  *
90550e3bfSJean-Christophe Dubois  * It (partially) emulates a mcimx6ul_evk board, with a Freescale
100550e3bfSJean-Christophe Dubois  * i.MX6ul SoC
110550e3bfSJean-Christophe Dubois  */
120550e3bfSJean-Christophe Dubois 
130550e3bfSJean-Christophe Dubois #include "qemu/osdep.h"
140550e3bfSJean-Christophe Dubois #include "qapi/error.h"
150550e3bfSJean-Christophe Dubois #include "hw/arm/fsl-imx6ul.h"
160550e3bfSJean-Christophe Dubois #include "hw/boards.h"
170550e3bfSJean-Christophe Dubois #include "sysemu/sysemu.h"
180550e3bfSJean-Christophe Dubois #include "qemu/error-report.h"
190550e3bfSJean-Christophe Dubois #include "sysemu/qtest.h"
200550e3bfSJean-Christophe Dubois 
210550e3bfSJean-Christophe Dubois typedef struct {
220550e3bfSJean-Christophe Dubois     FslIMX6ULState soc;
230550e3bfSJean-Christophe Dubois     MemoryRegion ram;
240550e3bfSJean-Christophe Dubois } MCIMX6ULEVK;
250550e3bfSJean-Christophe Dubois 
260550e3bfSJean-Christophe Dubois static void mcimx6ul_evk_init(MachineState *machine)
270550e3bfSJean-Christophe Dubois {
280550e3bfSJean-Christophe Dubois     static struct arm_boot_info boot_info;
290550e3bfSJean-Christophe Dubois     MCIMX6ULEVK *s = g_new0(MCIMX6ULEVK, 1);
300550e3bfSJean-Christophe Dubois     int i;
310550e3bfSJean-Christophe Dubois 
320550e3bfSJean-Christophe Dubois     if (machine->ram_size > FSL_IMX6UL_MMDC_SIZE) {
330550e3bfSJean-Christophe Dubois         error_report("RAM size " RAM_ADDR_FMT " above max supported (%08x)",
340550e3bfSJean-Christophe Dubois                      machine->ram_size, FSL_IMX6UL_MMDC_SIZE);
350550e3bfSJean-Christophe Dubois         exit(1);
360550e3bfSJean-Christophe Dubois     }
370550e3bfSJean-Christophe Dubois 
380550e3bfSJean-Christophe Dubois     boot_info = (struct arm_boot_info) {
390550e3bfSJean-Christophe Dubois         .loader_start = FSL_IMX6UL_MMDC_ADDR,
400550e3bfSJean-Christophe Dubois         .board_id = -1,
410550e3bfSJean-Christophe Dubois         .ram_size = machine->ram_size,
420550e3bfSJean-Christophe Dubois         .kernel_filename = machine->kernel_filename,
430550e3bfSJean-Christophe Dubois         .kernel_cmdline = machine->kernel_cmdline,
440550e3bfSJean-Christophe Dubois         .initrd_filename = machine->initrd_filename,
45*cc7d44c2SLike Xu         .nb_cpus = machine->smp.cpus,
460550e3bfSJean-Christophe Dubois     };
470550e3bfSJean-Christophe Dubois 
480550e3bfSJean-Christophe Dubois     object_initialize_child(OBJECT(machine), "soc", &s->soc,  sizeof(s->soc),
490550e3bfSJean-Christophe Dubois                             TYPE_FSL_IMX6UL, &error_fatal, NULL);
500550e3bfSJean-Christophe Dubois 
510550e3bfSJean-Christophe Dubois     object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_fatal);
520550e3bfSJean-Christophe Dubois 
530550e3bfSJean-Christophe Dubois     memory_region_allocate_system_memory(&s->ram, NULL, "mcimx6ul-evk.ram",
540550e3bfSJean-Christophe Dubois                                          machine->ram_size);
550550e3bfSJean-Christophe Dubois     memory_region_add_subregion(get_system_memory(),
560550e3bfSJean-Christophe Dubois                                 FSL_IMX6UL_MMDC_ADDR, &s->ram);
570550e3bfSJean-Christophe Dubois 
580550e3bfSJean-Christophe Dubois     for (i = 0; i < FSL_IMX6UL_NUM_USDHCS; i++) {
590550e3bfSJean-Christophe Dubois         BusState *bus;
600550e3bfSJean-Christophe Dubois         DeviceState *carddev;
610550e3bfSJean-Christophe Dubois         DriveInfo *di;
620550e3bfSJean-Christophe Dubois         BlockBackend *blk;
630550e3bfSJean-Christophe Dubois 
640550e3bfSJean-Christophe Dubois         di = drive_get_next(IF_SD);
650550e3bfSJean-Christophe Dubois         blk = di ? blk_by_legacy_dinfo(di) : NULL;
660550e3bfSJean-Christophe Dubois         bus = qdev_get_child_bus(DEVICE(&s->soc.usdhc[i]), "sd-bus");
670550e3bfSJean-Christophe Dubois         carddev = qdev_create(bus, TYPE_SD_CARD);
680550e3bfSJean-Christophe Dubois         qdev_prop_set_drive(carddev, "drive", blk, &error_fatal);
690550e3bfSJean-Christophe Dubois         object_property_set_bool(OBJECT(carddev), true,
700550e3bfSJean-Christophe Dubois                                  "realized", &error_fatal);
710550e3bfSJean-Christophe Dubois     }
720550e3bfSJean-Christophe Dubois 
730550e3bfSJean-Christophe Dubois     if (!qtest_enabled()) {
740550e3bfSJean-Christophe Dubois         arm_load_kernel(&s->soc.cpu[0], &boot_info);
750550e3bfSJean-Christophe Dubois     }
760550e3bfSJean-Christophe Dubois }
770550e3bfSJean-Christophe Dubois 
780550e3bfSJean-Christophe Dubois static void mcimx6ul_evk_machine_init(MachineClass *mc)
790550e3bfSJean-Christophe Dubois {
800550e3bfSJean-Christophe Dubois     mc->desc = "Freescale i.MX6UL Evaluation Kit (Cortex A7)";
810550e3bfSJean-Christophe Dubois     mc->init = mcimx6ul_evk_init;
820550e3bfSJean-Christophe Dubois     mc->max_cpus = FSL_IMX6UL_NUM_CPUS;
830550e3bfSJean-Christophe Dubois }
840550e3bfSJean-Christophe Dubois DEFINE_MACHINE("mcimx6ul-evk", mcimx6ul_evk_machine_init)
85