xref: /qemu/hw/arm/sabrelite.c (revision 778f4326)
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 "sysemu/sysemu.h"
193a0f31bcSJean-Christophe DUBOIS #include "qemu/error-report.h"
203a0f31bcSJean-Christophe DUBOIS #include "sysemu/qtest.h"
213a0f31bcSJean-Christophe DUBOIS 
223a0f31bcSJean-Christophe DUBOIS static struct arm_boot_info sabrelite_binfo = {
233a0f31bcSJean-Christophe DUBOIS     /* DDR memory start */
243a0f31bcSJean-Christophe DUBOIS     .loader_start = FSL_IMX6_MMDC_ADDR,
253a0f31bcSJean-Christophe DUBOIS     /* No board ID, we boot from DT tree */
263a0f31bcSJean-Christophe DUBOIS     .board_id = -1,
273a0f31bcSJean-Christophe DUBOIS };
283a0f31bcSJean-Christophe DUBOIS 
293a0f31bcSJean-Christophe DUBOIS /* No need to do any particular setup for secondary boot */
303a0f31bcSJean-Christophe DUBOIS static void sabrelite_write_secondary(ARMCPU *cpu,
313a0f31bcSJean-Christophe DUBOIS                                       const struct arm_boot_info *info)
323a0f31bcSJean-Christophe DUBOIS {
333a0f31bcSJean-Christophe DUBOIS }
343a0f31bcSJean-Christophe DUBOIS 
353a0f31bcSJean-Christophe DUBOIS /* Secondary cores are reset through SRC device */
363a0f31bcSJean-Christophe DUBOIS static void sabrelite_reset_secondary(ARMCPU *cpu,
373a0f31bcSJean-Christophe DUBOIS                                       const struct arm_boot_info *info)
383a0f31bcSJean-Christophe DUBOIS {
393a0f31bcSJean-Christophe DUBOIS }
403a0f31bcSJean-Christophe DUBOIS 
413a0f31bcSJean-Christophe DUBOIS static void sabrelite_init(MachineState *machine)
423a0f31bcSJean-Christophe DUBOIS {
43*778f4326SIgor Mammedov     FslIMX6State *s;
443a0f31bcSJean-Christophe DUBOIS     Error *err = NULL;
453a0f31bcSJean-Christophe DUBOIS 
463a0f31bcSJean-Christophe DUBOIS     /* Check the amount of memory is compatible with the SOC */
473a0f31bcSJean-Christophe DUBOIS     if (machine->ram_size > FSL_IMX6_MMDC_SIZE) {
483a0f31bcSJean-Christophe DUBOIS         error_report("RAM size " RAM_ADDR_FMT " above max supported (%08x)",
493a0f31bcSJean-Christophe DUBOIS                      machine->ram_size, FSL_IMX6_MMDC_SIZE);
503a0f31bcSJean-Christophe DUBOIS         exit(1);
513a0f31bcSJean-Christophe DUBOIS     }
523a0f31bcSJean-Christophe DUBOIS 
53*778f4326SIgor Mammedov     s = FSL_IMX6(object_new(TYPE_FSL_IMX6));
54*778f4326SIgor Mammedov     object_property_add_child(OBJECT(machine), "soc", OBJECT(s), &error_fatal);
55*778f4326SIgor Mammedov     object_property_set_bool(OBJECT(s), true, "realized", &err);
563a0f31bcSJean-Christophe DUBOIS     if (err != NULL) {
573a0f31bcSJean-Christophe DUBOIS         error_report("%s", error_get_pretty(err));
583a0f31bcSJean-Christophe DUBOIS         exit(1);
593a0f31bcSJean-Christophe DUBOIS     }
603a0f31bcSJean-Christophe DUBOIS 
613a0f31bcSJean-Christophe DUBOIS     memory_region_add_subregion(get_system_memory(), FSL_IMX6_MMDC_ADDR,
62*778f4326SIgor Mammedov                                 machine->ram);
633a0f31bcSJean-Christophe DUBOIS 
643a0f31bcSJean-Christophe DUBOIS     {
653a0f31bcSJean-Christophe DUBOIS         /*
663a0f31bcSJean-Christophe DUBOIS          * TODO: Ideally we would expose the chip select and spi bus on the
673a0f31bcSJean-Christophe DUBOIS          * SoC object using alias properties; then we would not need to
683a0f31bcSJean-Christophe DUBOIS          * directly access the underlying spi device object.
693a0f31bcSJean-Christophe DUBOIS          */
703a0f31bcSJean-Christophe DUBOIS         /* Add the sst25vf016b NOR FLASH memory to first SPI */
713a0f31bcSJean-Christophe DUBOIS         Object *spi_dev;
723a0f31bcSJean-Christophe DUBOIS 
73*778f4326SIgor Mammedov         spi_dev = object_resolve_path_component(OBJECT(s), "spi1");
743a0f31bcSJean-Christophe DUBOIS         if (spi_dev) {
753a0f31bcSJean-Christophe DUBOIS             SSIBus *spi_bus;
763a0f31bcSJean-Christophe DUBOIS 
773a0f31bcSJean-Christophe DUBOIS             spi_bus = (SSIBus *)qdev_get_child_bus(DEVICE(spi_dev), "spi");
783a0f31bcSJean-Christophe DUBOIS             if (spi_bus) {
793a0f31bcSJean-Christophe DUBOIS                 DeviceState *flash_dev;
8073bce518SPaolo Bonzini                 qemu_irq cs_line;
8173bce518SPaolo Bonzini                 DriveInfo *dinfo = drive_get_next(IF_MTD);
823a0f31bcSJean-Christophe DUBOIS 
8373bce518SPaolo Bonzini                 flash_dev = ssi_create_slave_no_init(spi_bus, "sst25vf016b");
8473bce518SPaolo Bonzini                 if (dinfo) {
8573bce518SPaolo Bonzini                     qdev_prop_set_drive(flash_dev, "drive",
8673bce518SPaolo Bonzini                                         blk_by_legacy_dinfo(dinfo),
8773bce518SPaolo Bonzini                                         &error_fatal);
883a0f31bcSJean-Christophe DUBOIS                 }
8973bce518SPaolo Bonzini                 qdev_init_nofail(flash_dev);
9073bce518SPaolo Bonzini 
9173bce518SPaolo Bonzini                 cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
9273bce518SPaolo Bonzini                 sysbus_connect_irq(SYS_BUS_DEVICE(spi_dev), 1, cs_line);
933a0f31bcSJean-Christophe DUBOIS             }
943a0f31bcSJean-Christophe DUBOIS         }
953a0f31bcSJean-Christophe DUBOIS     }
963a0f31bcSJean-Christophe DUBOIS 
973a0f31bcSJean-Christophe DUBOIS     sabrelite_binfo.ram_size = machine->ram_size;
98cc7d44c2SLike Xu     sabrelite_binfo.nb_cpus = machine->smp.cpus;
993a0f31bcSJean-Christophe DUBOIS     sabrelite_binfo.secure_boot = true;
1003a0f31bcSJean-Christophe DUBOIS     sabrelite_binfo.write_secondary_boot = sabrelite_write_secondary;
1013a0f31bcSJean-Christophe DUBOIS     sabrelite_binfo.secondary_cpu_reset_hook = sabrelite_reset_secondary;
1023a0f31bcSJean-Christophe DUBOIS 
1033a0f31bcSJean-Christophe DUBOIS     if (!qtest_enabled()) {
104*778f4326SIgor Mammedov         arm_load_kernel(&s->cpu[0], machine, &sabrelite_binfo);
1053a0f31bcSJean-Christophe DUBOIS     }
1063a0f31bcSJean-Christophe DUBOIS }
1073a0f31bcSJean-Christophe DUBOIS 
1083a0f31bcSJean-Christophe DUBOIS static void sabrelite_machine_init(MachineClass *mc)
1093a0f31bcSJean-Christophe DUBOIS {
1103a0f31bcSJean-Christophe DUBOIS     mc->desc = "Freescale i.MX6 Quad SABRE Lite Board (Cortex A9)";
1113a0f31bcSJean-Christophe DUBOIS     mc->init = sabrelite_init;
1123a0f31bcSJean-Christophe DUBOIS     mc->max_cpus = FSL_IMX6_NUM_CPUS;
1134672cbd7SPeter Maydell     mc->ignore_memory_transaction_failures = true;
114*778f4326SIgor Mammedov     mc->default_ram_id = "sabrelite.ram";
1153a0f31bcSJean-Christophe DUBOIS }
1163a0f31bcSJean-Christophe DUBOIS 
1173a0f31bcSJean-Christophe DUBOIS DEFINE_MACHINE("sabrelite", sabrelite_machine_init)
118