mcimx7d-sabre.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2018, Impinj, Inc.
  3. *
  4. * MCIMX7D_SABRE Board System emulation.
  5. *
  6. * Author: Andrey Smirnov <andrew.smirnov@gmail.com>
  7. *
  8. * This code is licensed under the GPL, version 2 or later.
  9. * See the file `COPYING' in the top level directory.
  10. *
  11. * It (partially) emulates a mcimx7d_sabre board, with a Freescale
  12. * i.MX7 SoC
  13. */
  14. #include "qemu/osdep.h"
  15. #include "qapi/error.h"
  16. #include "hw/arm/fsl-imx7.h"
  17. #include "hw/arm/boot.h"
  18. #include "hw/boards.h"
  19. #include "hw/qdev-properties.h"
  20. #include "qemu/error-report.h"
  21. #include "system/qtest.h"
  22. static void mcimx7d_sabre_init(MachineState *machine)
  23. {
  24. static struct arm_boot_info boot_info;
  25. FslIMX7State *s;
  26. int i;
  27. if (machine->ram_size > FSL_IMX7_MMDC_SIZE) {
  28. error_report("RAM size " RAM_ADDR_FMT " above max supported (%08x)",
  29. machine->ram_size, FSL_IMX7_MMDC_SIZE);
  30. exit(1);
  31. }
  32. boot_info = (struct arm_boot_info) {
  33. .loader_start = FSL_IMX7_MMDC_ADDR,
  34. .board_id = -1,
  35. .ram_size = machine->ram_size,
  36. .psci_conduit = QEMU_PSCI_CONDUIT_SMC,
  37. };
  38. s = FSL_IMX7(object_new(TYPE_FSL_IMX7));
  39. object_property_add_child(OBJECT(machine), "soc", OBJECT(s));
  40. object_property_set_bool(OBJECT(s), "fec2-phy-connected", false,
  41. &error_fatal);
  42. qdev_realize(DEVICE(s), NULL, &error_fatal);
  43. memory_region_add_subregion(get_system_memory(), FSL_IMX7_MMDC_ADDR,
  44. machine->ram);
  45. for (i = 0; i < FSL_IMX7_NUM_USDHCS; i++) {
  46. BusState *bus;
  47. DeviceState *carddev;
  48. DriveInfo *di;
  49. BlockBackend *blk;
  50. di = drive_get(IF_SD, 0, i);
  51. blk = di ? blk_by_legacy_dinfo(di) : NULL;
  52. bus = qdev_get_child_bus(DEVICE(&s->usdhc[i]), "sd-bus");
  53. carddev = qdev_new(TYPE_SD_CARD);
  54. qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
  55. qdev_realize_and_unref(carddev, bus, &error_fatal);
  56. }
  57. if (!qtest_enabled()) {
  58. arm_load_kernel(&s->cpu[0], machine, &boot_info);
  59. }
  60. }
  61. static void mcimx7d_sabre_machine_init(MachineClass *mc)
  62. {
  63. mc->desc = "Freescale i.MX7 DUAL SABRE (Cortex-A7)";
  64. mc->init = mcimx7d_sabre_init;
  65. mc->max_cpus = FSL_IMX7_NUM_CPUS;
  66. mc->default_ram_id = "mcimx7d-sabre.ram";
  67. mc->auto_create_sdcard = true;
  68. }
  69. DEFINE_MACHINE("mcimx7d-sabre", mcimx7d_sabre_machine_init)