xref: /openbmc/qemu/hw/arm/mcimx6ul-evk.c (revision 6a0acfff)
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 "sysemu/sysemu.h"
18 #include "qemu/error-report.h"
19 #include "sysemu/qtest.h"
20 
21 typedef struct {
22     FslIMX6ULState soc;
23     MemoryRegion ram;
24 } MCIMX6ULEVK;
25 
26 static void mcimx6ul_evk_init(MachineState *machine)
27 {
28     static struct arm_boot_info boot_info;
29     MCIMX6ULEVK *s = g_new0(MCIMX6ULEVK, 1);
30     int i;
31 
32     if (machine->ram_size > FSL_IMX6UL_MMDC_SIZE) {
33         error_report("RAM size " RAM_ADDR_FMT " above max supported (%08x)",
34                      machine->ram_size, FSL_IMX6UL_MMDC_SIZE);
35         exit(1);
36     }
37 
38     boot_info = (struct arm_boot_info) {
39         .loader_start = FSL_IMX6UL_MMDC_ADDR,
40         .board_id = -1,
41         .ram_size = machine->ram_size,
42         .kernel_filename = machine->kernel_filename,
43         .kernel_cmdline = machine->kernel_cmdline,
44         .initrd_filename = machine->initrd_filename,
45         .nb_cpus = machine->smp.cpus,
46     };
47 
48     object_initialize_child(OBJECT(machine), "soc", &s->soc,  sizeof(s->soc),
49                             TYPE_FSL_IMX6UL, &error_fatal, NULL);
50 
51     object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_fatal);
52 
53     memory_region_allocate_system_memory(&s->ram, NULL, "mcimx6ul-evk.ram",
54                                          machine->ram_size);
55     memory_region_add_subregion(get_system_memory(),
56                                 FSL_IMX6UL_MMDC_ADDR, &s->ram);
57 
58     for (i = 0; i < FSL_IMX6UL_NUM_USDHCS; i++) {
59         BusState *bus;
60         DeviceState *carddev;
61         DriveInfo *di;
62         BlockBackend *blk;
63 
64         di = drive_get_next(IF_SD);
65         blk = di ? blk_by_legacy_dinfo(di) : NULL;
66         bus = qdev_get_child_bus(DEVICE(&s->soc.usdhc[i]), "sd-bus");
67         carddev = qdev_create(bus, TYPE_SD_CARD);
68         qdev_prop_set_drive(carddev, "drive", blk, &error_fatal);
69         object_property_set_bool(OBJECT(carddev), true,
70                                  "realized", &error_fatal);
71     }
72 
73     if (!qtest_enabled()) {
74         arm_load_kernel(&s->soc.cpu, &boot_info);
75     }
76 }
77 
78 static void mcimx6ul_evk_machine_init(MachineClass *mc)
79 {
80     mc->desc = "Freescale i.MX6UL Evaluation Kit (Cortex A7)";
81     mc->init = mcimx6ul_evk_init;
82     mc->max_cpus = FSL_IMX6UL_NUM_CPUS;
83 }
84 DEFINE_MACHINE("mcimx6ul-evk", mcimx6ul_evk_machine_init)
85