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" 18764ca3ecSGuenter Roeck #include <libfdt.h> 19764ca3ecSGuenter Roeck 20764ca3ecSGuenter Roeck static void imx8mp_evk_modify_dtb(const struct arm_boot_info *info, void *fdt) 21764ca3ecSGuenter Roeck { 22*f978f410SGuenter Roeck int i, offset; 23*f978f410SGuenter Roeck 24*f978f410SGuenter Roeck /* Temporarily disable following nodes until they are implemented */ 25*f978f410SGuenter Roeck const char *nodes_to_remove[] = { 26*f978f410SGuenter Roeck "nxp,imx8mp-fspi", 27*f978f410SGuenter Roeck }; 28*f978f410SGuenter Roeck 29*f978f410SGuenter Roeck for (i = 0; i < ARRAY_SIZE(nodes_to_remove); i++) { 30*f978f410SGuenter Roeck const char *dev_str = nodes_to_remove[i]; 31*f978f410SGuenter Roeck 32*f978f410SGuenter Roeck offset = fdt_node_offset_by_compatible(fdt, -1, dev_str); 33*f978f410SGuenter Roeck while (offset >= 0) { 34*f978f410SGuenter Roeck fdt_nop_node(fdt, offset); 35*f978f410SGuenter Roeck offset = fdt_node_offset_by_compatible(fdt, offset, dev_str); 36*f978f410SGuenter Roeck } 37*f978f410SGuenter Roeck } 38764ca3ecSGuenter Roeck 39764ca3ecSGuenter Roeck /* Remove cpu-idle-states property from CPU nodes */ 40764ca3ecSGuenter Roeck offset = fdt_node_offset_by_compatible(fdt, -1, "arm,cortex-a53"); 41764ca3ecSGuenter Roeck while (offset >= 0) { 42764ca3ecSGuenter Roeck fdt_nop_property(fdt, offset, "cpu-idle-states"); 43764ca3ecSGuenter Roeck offset = fdt_node_offset_by_compatible(fdt, offset, "arm,cortex-a53"); 44764ca3ecSGuenter Roeck } 45764ca3ecSGuenter Roeck } 46a4eefc69SBernhard Beschow 47a4eefc69SBernhard Beschow static void imx8mp_evk_init(MachineState *machine) 48a4eefc69SBernhard Beschow { 49a4eefc69SBernhard Beschow static struct arm_boot_info boot_info; 50a4eefc69SBernhard Beschow FslImx8mpState *s; 51a4eefc69SBernhard Beschow 52a4eefc69SBernhard Beschow if (machine->ram_size > FSL_IMX8MP_RAM_SIZE_MAX) { 53a4eefc69SBernhard Beschow error_report("RAM size " RAM_ADDR_FMT " above max supported (%08" PRIx64 ")", 54a4eefc69SBernhard Beschow machine->ram_size, FSL_IMX8MP_RAM_SIZE_MAX); 55a4eefc69SBernhard Beschow exit(1); 56a4eefc69SBernhard Beschow } 57a4eefc69SBernhard Beschow 58a4eefc69SBernhard Beschow boot_info = (struct arm_boot_info) { 59a4eefc69SBernhard Beschow .loader_start = FSL_IMX8MP_RAM_START, 60a4eefc69SBernhard Beschow .board_id = -1, 61a4eefc69SBernhard Beschow .ram_size = machine->ram_size, 62a4eefc69SBernhard Beschow .psci_conduit = QEMU_PSCI_CONDUIT_SMC, 63764ca3ecSGuenter Roeck .modify_dtb = imx8mp_evk_modify_dtb, 64a4eefc69SBernhard Beschow }; 65a4eefc69SBernhard Beschow 66a4eefc69SBernhard Beschow s = FSL_IMX8MP(object_new(TYPE_FSL_IMX8MP)); 67a4eefc69SBernhard Beschow object_property_add_child(OBJECT(machine), "soc", OBJECT(s)); 680c105b26SBernhard Beschow object_property_set_uint(OBJECT(s), "fec1-phy-num", 1, &error_fatal); 6926c1c41eSBernhard Beschow sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal); 70a4eefc69SBernhard Beschow 71a4eefc69SBernhard Beschow memory_region_add_subregion(get_system_memory(), FSL_IMX8MP_RAM_START, 72a4eefc69SBernhard Beschow machine->ram); 73a4eefc69SBernhard Beschow 74a81193c3SBernhard Beschow for (int i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) { 75a81193c3SBernhard Beschow BusState *bus; 76a81193c3SBernhard Beschow DeviceState *carddev; 77a81193c3SBernhard Beschow BlockBackend *blk; 78a81193c3SBernhard Beschow DriveInfo *di = drive_get(IF_SD, i, 0); 79a81193c3SBernhard Beschow 80a81193c3SBernhard Beschow if (!di) { 81a81193c3SBernhard Beschow continue; 82a81193c3SBernhard Beschow } 83a81193c3SBernhard Beschow 84a81193c3SBernhard Beschow blk = blk_by_legacy_dinfo(di); 85a81193c3SBernhard Beschow bus = qdev_get_child_bus(DEVICE(&s->usdhc[i]), "sd-bus"); 86a81193c3SBernhard Beschow carddev = qdev_new(TYPE_SD_CARD); 87a81193c3SBernhard Beschow qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal); 88a81193c3SBernhard Beschow qdev_realize_and_unref(carddev, bus, &error_fatal); 89a81193c3SBernhard Beschow } 90a81193c3SBernhard Beschow 91a4eefc69SBernhard Beschow if (!qtest_enabled()) { 92a4eefc69SBernhard Beschow arm_load_kernel(&s->cpu[0], machine, &boot_info); 93a4eefc69SBernhard Beschow } 94a4eefc69SBernhard Beschow } 95a4eefc69SBernhard Beschow 96a4eefc69SBernhard Beschow static void imx8mp_evk_machine_init(MachineClass *mc) 97a4eefc69SBernhard Beschow { 98a4eefc69SBernhard Beschow mc->desc = "NXP i.MX 8M Plus EVK Board"; 99a4eefc69SBernhard Beschow mc->init = imx8mp_evk_init; 100a4eefc69SBernhard Beschow mc->max_cpus = FSL_IMX8MP_NUM_CPUS; 101a4eefc69SBernhard Beschow mc->default_ram_id = "imx8mp-evk.ram"; 102a4eefc69SBernhard Beschow } 103a4eefc69SBernhard Beschow DEFINE_MACHINE("imx8mp-evk", imx8mp_evk_machine_init) 104