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"
168727076bSPhilippe Mathieu-Daudé #include "hw/arm/boot.h"
170550e3bfSJean-Christophe Dubois #include "hw/boards.h"
18a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
190550e3bfSJean-Christophe Dubois #include "qemu/error-report.h"
200550e3bfSJean-Christophe Dubois #include "sysemu/qtest.h"
210550e3bfSJean-Christophe Dubois
mcimx6ul_evk_init(MachineState * machine)220550e3bfSJean-Christophe Dubois static void mcimx6ul_evk_init(MachineState *machine)
230550e3bfSJean-Christophe Dubois {
240550e3bfSJean-Christophe Dubois static struct arm_boot_info boot_info;
2514dbfa55SIgor Mammedov FslIMX6ULState *s;
260550e3bfSJean-Christophe Dubois int i;
270550e3bfSJean-Christophe Dubois
280550e3bfSJean-Christophe Dubois if (machine->ram_size > FSL_IMX6UL_MMDC_SIZE) {
290550e3bfSJean-Christophe Dubois error_report("RAM size " RAM_ADDR_FMT " above max supported (%08x)",
300550e3bfSJean-Christophe Dubois machine->ram_size, FSL_IMX6UL_MMDC_SIZE);
310550e3bfSJean-Christophe Dubois exit(1);
320550e3bfSJean-Christophe Dubois }
330550e3bfSJean-Christophe Dubois
340550e3bfSJean-Christophe Dubois boot_info = (struct arm_boot_info) {
350550e3bfSJean-Christophe Dubois .loader_start = FSL_IMX6UL_MMDC_ADDR,
360550e3bfSJean-Christophe Dubois .board_id = -1,
370550e3bfSJean-Christophe Dubois .ram_size = machine->ram_size,
38ae2474f1SPeter Maydell .psci_conduit = QEMU_PSCI_CONDUIT_SMC,
390550e3bfSJean-Christophe Dubois };
400550e3bfSJean-Christophe Dubois
4114dbfa55SIgor Mammedov s = FSL_IMX6UL(object_new(TYPE_FSL_IMX6UL));
42d2623129SMarkus Armbruster object_property_add_child(OBJECT(machine), "soc", OBJECT(s));
435325cc34SMarkus Armbruster object_property_set_uint(OBJECT(s), "fec1-phy-num", 2, &error_fatal);
445325cc34SMarkus Armbruster object_property_set_uint(OBJECT(s), "fec2-phy-num", 1, &error_fatal);
45bebcddbbSGuenter Roeck object_property_set_bool(OBJECT(s), "fec1-phy-connected", false,
46bebcddbbSGuenter Roeck &error_fatal);
47ce189ab2SMarkus Armbruster qdev_realize(DEVICE(s), NULL, &error_fatal);
480550e3bfSJean-Christophe Dubois
4914dbfa55SIgor Mammedov memory_region_add_subregion(get_system_memory(), FSL_IMX6UL_MMDC_ADDR,
5014dbfa55SIgor Mammedov machine->ram);
510550e3bfSJean-Christophe Dubois
520550e3bfSJean-Christophe Dubois for (i = 0; i < FSL_IMX6UL_NUM_USDHCS; i++) {
530550e3bfSJean-Christophe Dubois BusState *bus;
540550e3bfSJean-Christophe Dubois DeviceState *carddev;
550550e3bfSJean-Christophe Dubois DriveInfo *di;
560550e3bfSJean-Christophe Dubois BlockBackend *blk;
570550e3bfSJean-Christophe Dubois
588acf052fSMarkus Armbruster di = drive_get(IF_SD, 0, i);
590550e3bfSJean-Christophe Dubois blk = di ? blk_by_legacy_dinfo(di) : NULL;
60*cc17f3b2SCédric Le Goater bus = BUS(&s->usdhc[i].sdbus);
613e80f690SMarkus Armbruster carddev = qdev_new(TYPE_SD_CARD);
62934df912SMarkus Armbruster qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
633e80f690SMarkus Armbruster qdev_realize_and_unref(carddev, bus, &error_fatal);
640550e3bfSJean-Christophe Dubois }
650550e3bfSJean-Christophe Dubois
660550e3bfSJean-Christophe Dubois if (!qtest_enabled()) {
6714dbfa55SIgor Mammedov arm_load_kernel(&s->cpu, machine, &boot_info);
680550e3bfSJean-Christophe Dubois }
690550e3bfSJean-Christophe Dubois }
700550e3bfSJean-Christophe Dubois
mcimx6ul_evk_machine_init(MachineClass * mc)710550e3bfSJean-Christophe Dubois static void mcimx6ul_evk_machine_init(MachineClass *mc)
720550e3bfSJean-Christophe Dubois {
73f548f201SPeter Maydell mc->desc = "Freescale i.MX6UL Evaluation Kit (Cortex-A7)";
740550e3bfSJean-Christophe Dubois mc->init = mcimx6ul_evk_init;
750550e3bfSJean-Christophe Dubois mc->max_cpus = FSL_IMX6UL_NUM_CPUS;
7614dbfa55SIgor Mammedov mc->default_ram_id = "mcimx6ul-evk.ram";
770550e3bfSJean-Christophe Dubois }
780550e3bfSJean-Christophe Dubois DEFINE_MACHINE("mcimx6ul-evk", mcimx6ul_evk_machine_init)
79