1a4eefc69SBernhard Beschow /* 2a4eefc69SBernhard Beschow * NXP i.MX 8M Plus Evaluation Kit System Emulation 3a4eefc69SBernhard Beschow * 4a4eefc69SBernhard Beschow * Copyright (c) 2024, Bernhard Beschow <shentey@gmail.com> 5a4eefc69SBernhard Beschow * 6a4eefc69SBernhard Beschow * SPDX-License-Identifier: GPL-2.0-or-later 7a4eefc69SBernhard Beschow */ 8a4eefc69SBernhard Beschow 9a4eefc69SBernhard Beschow #include "qemu/osdep.h" 10a4eefc69SBernhard Beschow #include "exec/address-spaces.h" 11a4eefc69SBernhard Beschow #include "hw/arm/boot.h" 12a4eefc69SBernhard Beschow #include "hw/arm/fsl-imx8mp.h" 13a4eefc69SBernhard Beschow #include "hw/boards.h" 14a81193c3SBernhard Beschow #include "hw/qdev-properties.h" 15a4eefc69SBernhard Beschow #include "system/qtest.h" 16a4eefc69SBernhard Beschow #include "qemu/error-report.h" 17a4eefc69SBernhard Beschow #include "qapi/error.h" 18a4eefc69SBernhard Beschow 19a4eefc69SBernhard Beschow static void imx8mp_evk_init(MachineState *machine) 20a4eefc69SBernhard Beschow { 21a4eefc69SBernhard Beschow static struct arm_boot_info boot_info; 22a4eefc69SBernhard Beschow FslImx8mpState *s; 23a4eefc69SBernhard Beschow 24a4eefc69SBernhard Beschow if (machine->ram_size > FSL_IMX8MP_RAM_SIZE_MAX) { 25a4eefc69SBernhard Beschow error_report("RAM size " RAM_ADDR_FMT " above max supported (%08" PRIx64 ")", 26a4eefc69SBernhard Beschow machine->ram_size, FSL_IMX8MP_RAM_SIZE_MAX); 27a4eefc69SBernhard Beschow exit(1); 28a4eefc69SBernhard Beschow } 29a4eefc69SBernhard Beschow 30a4eefc69SBernhard Beschow boot_info = (struct arm_boot_info) { 31a4eefc69SBernhard Beschow .loader_start = FSL_IMX8MP_RAM_START, 32a4eefc69SBernhard Beschow .board_id = -1, 33a4eefc69SBernhard Beschow .ram_size = machine->ram_size, 34a4eefc69SBernhard Beschow .psci_conduit = QEMU_PSCI_CONDUIT_SMC, 35a4eefc69SBernhard Beschow }; 36a4eefc69SBernhard Beschow 37a4eefc69SBernhard Beschow s = FSL_IMX8MP(object_new(TYPE_FSL_IMX8MP)); 38a4eefc69SBernhard Beschow object_property_add_child(OBJECT(machine), "soc", OBJECT(s)); 39*0c105b26SBernhard Beschow object_property_set_uint(OBJECT(s), "fec1-phy-num", 1, &error_fatal); 40a4eefc69SBernhard Beschow qdev_realize(DEVICE(s), NULL, &error_fatal); 41a4eefc69SBernhard Beschow 42a4eefc69SBernhard Beschow memory_region_add_subregion(get_system_memory(), FSL_IMX8MP_RAM_START, 43a4eefc69SBernhard Beschow machine->ram); 44a4eefc69SBernhard Beschow 45a81193c3SBernhard Beschow for (int i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) { 46a81193c3SBernhard Beschow BusState *bus; 47a81193c3SBernhard Beschow DeviceState *carddev; 48a81193c3SBernhard Beschow BlockBackend *blk; 49a81193c3SBernhard Beschow DriveInfo *di = drive_get(IF_SD, i, 0); 50a81193c3SBernhard Beschow 51a81193c3SBernhard Beschow if (!di) { 52a81193c3SBernhard Beschow continue; 53a81193c3SBernhard Beschow } 54a81193c3SBernhard Beschow 55a81193c3SBernhard Beschow blk = blk_by_legacy_dinfo(di); 56a81193c3SBernhard Beschow bus = qdev_get_child_bus(DEVICE(&s->usdhc[i]), "sd-bus"); 57a81193c3SBernhard Beschow carddev = qdev_new(TYPE_SD_CARD); 58a81193c3SBernhard Beschow qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal); 59a81193c3SBernhard Beschow qdev_realize_and_unref(carddev, bus, &error_fatal); 60a81193c3SBernhard Beschow } 61a81193c3SBernhard Beschow 62a4eefc69SBernhard Beschow if (!qtest_enabled()) { 63a4eefc69SBernhard Beschow arm_load_kernel(&s->cpu[0], machine, &boot_info); 64a4eefc69SBernhard Beschow } 65a4eefc69SBernhard Beschow } 66a4eefc69SBernhard Beschow 67a4eefc69SBernhard Beschow static void imx8mp_evk_machine_init(MachineClass *mc) 68a4eefc69SBernhard Beschow { 69a4eefc69SBernhard Beschow mc->desc = "NXP i.MX 8M Plus EVK Board"; 70a4eefc69SBernhard Beschow mc->init = imx8mp_evk_init; 71a4eefc69SBernhard Beschow mc->max_cpus = FSL_IMX8MP_NUM_CPUS; 72a4eefc69SBernhard Beschow mc->default_ram_id = "imx8mp-evk.ram"; 73a4eefc69SBernhard Beschow } 74a4eefc69SBernhard Beschow DEFINE_MACHINE("imx8mp-evk", imx8mp_evk_machine_init) 75