sabrelite.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * SABRELITE Board System emulation.
  3. *
  4. * Copyright (c) 2015 Jean-Christophe Dubois <jcd@tribudubois.net>
  5. *
  6. * This code is licensed under the GPL, version 2 or later.
  7. * See the file `COPYING' in the top level directory.
  8. *
  9. * It (partially) emulates a sabrelite board, with a Freescale
  10. * i.MX6 SoC
  11. */
  12. #include "qemu/osdep.h"
  13. #include "qapi/error.h"
  14. #include "hw/arm/fsl-imx6.h"
  15. #include "hw/boards.h"
  16. #include "hw/qdev-properties.h"
  17. #include "sysemu/sysemu.h"
  18. #include "qemu/error-report.h"
  19. #include "sysemu/qtest.h"
  20. typedef struct IMX6Sabrelite {
  21. FslIMX6State soc;
  22. MemoryRegion ram;
  23. } IMX6Sabrelite;
  24. static struct arm_boot_info sabrelite_binfo = {
  25. /* DDR memory start */
  26. .loader_start = FSL_IMX6_MMDC_ADDR,
  27. /* No board ID, we boot from DT tree */
  28. .board_id = -1,
  29. };
  30. /* No need to do any particular setup for secondary boot */
  31. static void sabrelite_write_secondary(ARMCPU *cpu,
  32. const struct arm_boot_info *info)
  33. {
  34. }
  35. /* Secondary cores are reset through SRC device */
  36. static void sabrelite_reset_secondary(ARMCPU *cpu,
  37. const struct arm_boot_info *info)
  38. {
  39. }
  40. static void sabrelite_init(MachineState *machine)
  41. {
  42. IMX6Sabrelite *s = g_new0(IMX6Sabrelite, 1);
  43. Error *err = NULL;
  44. /* Check the amount of memory is compatible with the SOC */
  45. if (machine->ram_size > FSL_IMX6_MMDC_SIZE) {
  46. error_report("RAM size " RAM_ADDR_FMT " above max supported (%08x)",
  47. machine->ram_size, FSL_IMX6_MMDC_SIZE);
  48. exit(1);
  49. }
  50. object_initialize_child(OBJECT(machine), "soc", &s->soc, sizeof(s->soc),
  51. TYPE_FSL_IMX6, &error_abort, NULL);
  52. object_property_set_bool(OBJECT(&s->soc), true, "realized", &err);
  53. if (err != NULL) {
  54. error_report("%s", error_get_pretty(err));
  55. exit(1);
  56. }
  57. memory_region_allocate_system_memory(&s->ram, NULL, "sabrelite.ram",
  58. machine->ram_size);
  59. memory_region_add_subregion(get_system_memory(), FSL_IMX6_MMDC_ADDR,
  60. &s->ram);
  61. {
  62. /*
  63. * TODO: Ideally we would expose the chip select and spi bus on the
  64. * SoC object using alias properties; then we would not need to
  65. * directly access the underlying spi device object.
  66. */
  67. /* Add the sst25vf016b NOR FLASH memory to first SPI */
  68. Object *spi_dev;
  69. spi_dev = object_resolve_path_component(OBJECT(&s->soc), "spi1");
  70. if (spi_dev) {
  71. SSIBus *spi_bus;
  72. spi_bus = (SSIBus *)qdev_get_child_bus(DEVICE(spi_dev), "spi");
  73. if (spi_bus) {
  74. DeviceState *flash_dev;
  75. qemu_irq cs_line;
  76. DriveInfo *dinfo = drive_get_next(IF_MTD);
  77. flash_dev = ssi_create_slave_no_init(spi_bus, "sst25vf016b");
  78. if (dinfo) {
  79. qdev_prop_set_drive(flash_dev, "drive",
  80. blk_by_legacy_dinfo(dinfo),
  81. &error_fatal);
  82. }
  83. qdev_init_nofail(flash_dev);
  84. cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
  85. sysbus_connect_irq(SYS_BUS_DEVICE(spi_dev), 1, cs_line);
  86. }
  87. }
  88. }
  89. sabrelite_binfo.ram_size = machine->ram_size;
  90. sabrelite_binfo.nb_cpus = machine->smp.cpus;
  91. sabrelite_binfo.secure_boot = true;
  92. sabrelite_binfo.write_secondary_boot = sabrelite_write_secondary;
  93. sabrelite_binfo.secondary_cpu_reset_hook = sabrelite_reset_secondary;
  94. if (!qtest_enabled()) {
  95. arm_load_kernel(&s->soc.cpu[0], machine, &sabrelite_binfo);
  96. }
  97. }
  98. static void sabrelite_machine_init(MachineClass *mc)
  99. {
  100. mc->desc = "Freescale i.MX6 Quad SABRE Lite Board (Cortex A9)";
  101. mc->init = sabrelite_init;
  102. mc->max_cpus = FSL_IMX6_NUM_CPUS;
  103. mc->ignore_memory_transaction_failures = true;
  104. }
  105. DEFINE_MACHINE("sabrelite", sabrelite_machine_init)