mcimx7d-sabre.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/boards.h"
  18. #include "hw/qdev-properties.h"
  19. #include "sysemu/sysemu.h"
  20. #include "qemu/error-report.h"
  21. #include "sysemu/qtest.h"
  22. typedef struct {
  23. FslIMX7State soc;
  24. MemoryRegion ram;
  25. } MCIMX7Sabre;
  26. static void mcimx7d_sabre_init(MachineState *machine)
  27. {
  28. static struct arm_boot_info boot_info;
  29. MCIMX7Sabre *s = g_new0(MCIMX7Sabre, 1);
  30. int i;
  31. if (machine->ram_size > FSL_IMX7_MMDC_SIZE) {
  32. error_report("RAM size " RAM_ADDR_FMT " above max supported (%08x)",
  33. machine->ram_size, FSL_IMX7_MMDC_SIZE);
  34. exit(1);
  35. }
  36. boot_info = (struct arm_boot_info) {
  37. .loader_start = FSL_IMX7_MMDC_ADDR,
  38. .board_id = -1,
  39. .ram_size = machine->ram_size,
  40. .nb_cpus = machine->smp.cpus,
  41. };
  42. object_initialize_child(OBJECT(machine), "soc",
  43. &s->soc, sizeof(s->soc),
  44. TYPE_FSL_IMX7, &error_fatal, NULL);
  45. object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_fatal);
  46. memory_region_allocate_system_memory(&s->ram, NULL, "mcimx7d-sabre.ram",
  47. machine->ram_size);
  48. memory_region_add_subregion(get_system_memory(),
  49. FSL_IMX7_MMDC_ADDR, &s->ram);
  50. for (i = 0; i < FSL_IMX7_NUM_USDHCS; i++) {
  51. BusState *bus;
  52. DeviceState *carddev;
  53. DriveInfo *di;
  54. BlockBackend *blk;
  55. di = drive_get_next(IF_SD);
  56. blk = di ? blk_by_legacy_dinfo(di) : NULL;
  57. bus = qdev_get_child_bus(DEVICE(&s->soc.usdhc[i]), "sd-bus");
  58. carddev = qdev_create(bus, TYPE_SD_CARD);
  59. qdev_prop_set_drive(carddev, "drive", blk, &error_fatal);
  60. object_property_set_bool(OBJECT(carddev), true,
  61. "realized", &error_fatal);
  62. }
  63. if (!qtest_enabled()) {
  64. arm_load_kernel(&s->soc.cpu[0], machine, &boot_info);
  65. }
  66. }
  67. static void mcimx7d_sabre_machine_init(MachineClass *mc)
  68. {
  69. mc->desc = "Freescale i.MX7 DUAL SABRE (Cortex A7)";
  70. mc->init = mcimx7d_sabre_init;
  71. mc->max_cpus = FSL_IMX7_NUM_CPUS;
  72. }
  73. DEFINE_MACHINE("mcimx7d-sabre", mcimx7d_sabre_machine_init)