xref: /qemu/hw/arm/sabrelite.c (revision 64eaa820)
13a0f31bcSJean-Christophe DUBOIS /*
23a0f31bcSJean-Christophe DUBOIS  * SABRELITE Board System emulation.
33a0f31bcSJean-Christophe DUBOIS  *
43a0f31bcSJean-Christophe DUBOIS  * Copyright (c) 2015 Jean-Christophe Dubois <jcd@tribudubois.net>
53a0f31bcSJean-Christophe DUBOIS  *
63a0f31bcSJean-Christophe DUBOIS  * This code is licensed under the GPL, version 2 or later.
73a0f31bcSJean-Christophe DUBOIS  * See the file `COPYING' in the top level directory.
83a0f31bcSJean-Christophe DUBOIS  *
93a0f31bcSJean-Christophe DUBOIS  * It (partially) emulates a sabrelite board, with a Freescale
103a0f31bcSJean-Christophe DUBOIS  * i.MX6 SoC
113a0f31bcSJean-Christophe DUBOIS  */
123a0f31bcSJean-Christophe DUBOIS 
133a0f31bcSJean-Christophe DUBOIS #include "qemu/osdep.h"
143a0f31bcSJean-Christophe DUBOIS #include "qapi/error.h"
153a0f31bcSJean-Christophe DUBOIS #include "hw/arm/fsl-imx6.h"
163a0f31bcSJean-Christophe DUBOIS #include "hw/boards.h"
17a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
183a0f31bcSJean-Christophe DUBOIS #include "qemu/error-report.h"
193a0f31bcSJean-Christophe DUBOIS #include "sysemu/qtest.h"
203a0f31bcSJean-Christophe DUBOIS 
213a0f31bcSJean-Christophe DUBOIS static struct arm_boot_info sabrelite_binfo = {
223a0f31bcSJean-Christophe DUBOIS     /* DDR memory start */
233a0f31bcSJean-Christophe DUBOIS     .loader_start = FSL_IMX6_MMDC_ADDR,
243a0f31bcSJean-Christophe DUBOIS     /* No board ID, we boot from DT tree */
253a0f31bcSJean-Christophe DUBOIS     .board_id = -1,
263a0f31bcSJean-Christophe DUBOIS };
273a0f31bcSJean-Christophe DUBOIS 
283a0f31bcSJean-Christophe DUBOIS /* No need to do any particular setup for secondary boot */
293a0f31bcSJean-Christophe DUBOIS static void sabrelite_write_secondary(ARMCPU *cpu,
303a0f31bcSJean-Christophe DUBOIS                                       const struct arm_boot_info *info)
313a0f31bcSJean-Christophe DUBOIS {
323a0f31bcSJean-Christophe DUBOIS }
333a0f31bcSJean-Christophe DUBOIS 
343a0f31bcSJean-Christophe DUBOIS /* Secondary cores are reset through SRC device */
353a0f31bcSJean-Christophe DUBOIS static void sabrelite_reset_secondary(ARMCPU *cpu,
363a0f31bcSJean-Christophe DUBOIS                                       const struct arm_boot_info *info)
373a0f31bcSJean-Christophe DUBOIS {
383a0f31bcSJean-Christophe DUBOIS }
393a0f31bcSJean-Christophe DUBOIS 
403a0f31bcSJean-Christophe DUBOIS static void sabrelite_init(MachineState *machine)
413a0f31bcSJean-Christophe DUBOIS {
42778f4326SIgor Mammedov     FslIMX6State *s;
433a0f31bcSJean-Christophe DUBOIS 
443a0f31bcSJean-Christophe DUBOIS     /* Check the amount of memory is compatible with the SOC */
453a0f31bcSJean-Christophe DUBOIS     if (machine->ram_size > FSL_IMX6_MMDC_SIZE) {
463a0f31bcSJean-Christophe DUBOIS         error_report("RAM size " RAM_ADDR_FMT " above max supported (%08x)",
473a0f31bcSJean-Christophe DUBOIS                      machine->ram_size, FSL_IMX6_MMDC_SIZE);
483a0f31bcSJean-Christophe DUBOIS         exit(1);
493a0f31bcSJean-Christophe DUBOIS     }
503a0f31bcSJean-Christophe DUBOIS 
51778f4326SIgor Mammedov     s = FSL_IMX6(object_new(TYPE_FSL_IMX6));
52d2623129SMarkus Armbruster     object_property_add_child(OBJECT(machine), "soc", OBJECT(s));
5337e33be7SBin Meng 
5437e33be7SBin Meng     /* Ethernet PHY address is 6 */
5537e33be7SBin Meng     object_property_set_int(OBJECT(s), "fec-phy-num", 6, &error_fatal);
5637e33be7SBin Meng 
57ce189ab2SMarkus Armbruster     qdev_realize(DEVICE(s), NULL, &error_fatal);
583a0f31bcSJean-Christophe DUBOIS 
593a0f31bcSJean-Christophe DUBOIS     memory_region_add_subregion(get_system_memory(), FSL_IMX6_MMDC_ADDR,
60778f4326SIgor Mammedov                                 machine->ram);
613a0f31bcSJean-Christophe DUBOIS 
623a0f31bcSJean-Christophe DUBOIS     {
633a0f31bcSJean-Christophe DUBOIS         /*
643a0f31bcSJean-Christophe DUBOIS          * TODO: Ideally we would expose the chip select and spi bus on the
653a0f31bcSJean-Christophe DUBOIS          * SoC object using alias properties; then we would not need to
663a0f31bcSJean-Christophe DUBOIS          * directly access the underlying spi device object.
673a0f31bcSJean-Christophe DUBOIS          */
683a0f31bcSJean-Christophe DUBOIS         /* Add the sst25vf016b NOR FLASH memory to first SPI */
693a0f31bcSJean-Christophe DUBOIS         Object *spi_dev;
703a0f31bcSJean-Christophe DUBOIS 
71778f4326SIgor Mammedov         spi_dev = object_resolve_path_component(OBJECT(s), "spi1");
723a0f31bcSJean-Christophe DUBOIS         if (spi_dev) {
733a0f31bcSJean-Christophe DUBOIS             SSIBus *spi_bus;
743a0f31bcSJean-Christophe DUBOIS 
753a0f31bcSJean-Christophe DUBOIS             spi_bus = (SSIBus *)qdev_get_child_bus(DEVICE(spi_dev), "spi");
763a0f31bcSJean-Christophe DUBOIS             if (spi_bus) {
773a0f31bcSJean-Christophe DUBOIS                 DeviceState *flash_dev;
7873bce518SPaolo Bonzini                 qemu_irq cs_line;
79*64eaa820SMarkus Armbruster                 DriveInfo *dinfo = drive_get(IF_MTD, 0, 0);
803a0f31bcSJean-Christophe DUBOIS 
8157d479c9SMarkus Armbruster                 flash_dev = qdev_new("sst25vf016b");
8273bce518SPaolo Bonzini                 if (dinfo) {
83934df912SMarkus Armbruster                     qdev_prop_set_drive_err(flash_dev, "drive",
8473bce518SPaolo Bonzini                                             blk_by_legacy_dinfo(dinfo),
8573bce518SPaolo Bonzini                                             &error_fatal);
863a0f31bcSJean-Christophe DUBOIS                 }
8757d479c9SMarkus Armbruster                 qdev_realize_and_unref(flash_dev, BUS(spi_bus), &error_fatal);
8873bce518SPaolo Bonzini 
8973bce518SPaolo Bonzini                 cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
901f4b2ec7SXuzhou Cheng                 qdev_connect_gpio_out(DEVICE(&s->gpio[2]), 19, cs_line);
913a0f31bcSJean-Christophe DUBOIS             }
923a0f31bcSJean-Christophe DUBOIS         }
933a0f31bcSJean-Christophe DUBOIS     }
943a0f31bcSJean-Christophe DUBOIS 
953a0f31bcSJean-Christophe DUBOIS     sabrelite_binfo.ram_size = machine->ram_size;
96cc7d44c2SLike Xu     sabrelite_binfo.nb_cpus = machine->smp.cpus;
973a0f31bcSJean-Christophe DUBOIS     sabrelite_binfo.secure_boot = true;
983a0f31bcSJean-Christophe DUBOIS     sabrelite_binfo.write_secondary_boot = sabrelite_write_secondary;
993a0f31bcSJean-Christophe DUBOIS     sabrelite_binfo.secondary_cpu_reset_hook = sabrelite_reset_secondary;
1003a0f31bcSJean-Christophe DUBOIS 
1013a0f31bcSJean-Christophe DUBOIS     if (!qtest_enabled()) {
102778f4326SIgor Mammedov         arm_load_kernel(&s->cpu[0], machine, &sabrelite_binfo);
1033a0f31bcSJean-Christophe DUBOIS     }
1043a0f31bcSJean-Christophe DUBOIS }
1053a0f31bcSJean-Christophe DUBOIS 
1063a0f31bcSJean-Christophe DUBOIS static void sabrelite_machine_init(MachineClass *mc)
1073a0f31bcSJean-Christophe DUBOIS {
108f548f201SPeter Maydell     mc->desc = "Freescale i.MX6 Quad SABRE Lite Board (Cortex-A9)";
1093a0f31bcSJean-Christophe DUBOIS     mc->init = sabrelite_init;
1103a0f31bcSJean-Christophe DUBOIS     mc->max_cpus = FSL_IMX6_NUM_CPUS;
1114672cbd7SPeter Maydell     mc->ignore_memory_transaction_failures = true;
112778f4326SIgor Mammedov     mc->default_ram_id = "sabrelite.ram";
1133a0f31bcSJean-Christophe DUBOIS }
1143a0f31bcSJean-Christophe DUBOIS 
1153a0f31bcSJean-Christophe DUBOIS DEFINE_MACHINE("sabrelite", sabrelite_machine_init)
116