xref: /openbmc/qemu/hw/arm/mcimx6ul-evk.c (revision 784155cd)
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 "qemu/error-report.h"
19 #include "sysemu/qtest.h"
20 
21 static void mcimx6ul_evk_init(MachineState *machine)
22 {
23     static struct arm_boot_info boot_info;
24     FslIMX6ULState *s;
25     int i;
26 
27     if (machine->ram_size > FSL_IMX6UL_MMDC_SIZE) {
28         error_report("RAM size " RAM_ADDR_FMT " above max supported (%08x)",
29                      machine->ram_size, FSL_IMX6UL_MMDC_SIZE);
30         exit(1);
31     }
32 
33     boot_info = (struct arm_boot_info) {
34         .loader_start = FSL_IMX6UL_MMDC_ADDR,
35         .board_id = -1,
36         .ram_size = machine->ram_size,
37         .psci_conduit = QEMU_PSCI_CONDUIT_SMC,
38     };
39 
40     s = FSL_IMX6UL(object_new(TYPE_FSL_IMX6UL));
41     object_property_add_child(OBJECT(machine), "soc", OBJECT(s));
42     object_property_set_uint(OBJECT(s), "fec1-phy-num", 2, &error_fatal);
43     object_property_set_uint(OBJECT(s), "fec2-phy-num", 1, &error_fatal);
44     object_property_set_bool(OBJECT(s), "fec1-phy-connected", false,
45                              &error_fatal);
46     qdev_realize(DEVICE(s), NULL, &error_fatal);
47 
48     memory_region_add_subregion(get_system_memory(), FSL_IMX6UL_MMDC_ADDR,
49                                 machine->ram);
50 
51     for (i = 0; i < FSL_IMX6UL_NUM_USDHCS; i++) {
52         BusState *bus;
53         DeviceState *carddev;
54         DriveInfo *di;
55         BlockBackend *blk;
56 
57         di = drive_get(IF_SD, 0, i);
58         blk = di ? blk_by_legacy_dinfo(di) : NULL;
59         bus = qdev_get_child_bus(DEVICE(&s->usdhc[i]), "sd-bus");
60         carddev = qdev_new(TYPE_SD_CARD);
61         qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
62         qdev_realize_and_unref(carddev, bus, &error_fatal);
63     }
64 
65     if (!qtest_enabled()) {
66         arm_load_kernel(&s->cpu, machine, &boot_info);
67     }
68 }
69 
70 static void mcimx6ul_evk_machine_init(MachineClass *mc)
71 {
72     mc->desc = "Freescale i.MX6UL Evaluation Kit (Cortex-A7)";
73     mc->init = mcimx6ul_evk_init;
74     mc->max_cpus = FSL_IMX6UL_NUM_CPUS;
75     mc->default_ram_id = "mcimx6ul-evk.ram";
76 }
77 DEFINE_MACHINE("mcimx6ul-evk", mcimx6ul_evk_machine_init)
78