xref: /openbmc/qemu/hw/arm/sabrelite.c (revision 5964ed56)
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 
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "hw/arm/fsl-imx6.h"
16 #include "hw/boards.h"
17 #include "hw/qdev-properties.h"
18 #include "sysemu/sysemu.h"
19 #include "qemu/error-report.h"
20 #include "sysemu/qtest.h"
21 
22 static struct arm_boot_info sabrelite_binfo = {
23     /* DDR memory start */
24     .loader_start = FSL_IMX6_MMDC_ADDR,
25     /* No board ID, we boot from DT tree */
26     .board_id = -1,
27 };
28 
29 /* No need to do any particular setup for secondary boot */
30 static void sabrelite_write_secondary(ARMCPU *cpu,
31                                       const struct arm_boot_info *info)
32 {
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 
41 static void sabrelite_init(MachineState *machine)
42 {
43     FslIMX6State *s;
44     Error *err = NULL;
45 
46     /* Check the amount of memory is compatible with the SOC */
47     if (machine->ram_size > FSL_IMX6_MMDC_SIZE) {
48         error_report("RAM size " RAM_ADDR_FMT " above max supported (%08x)",
49                      machine->ram_size, FSL_IMX6_MMDC_SIZE);
50         exit(1);
51     }
52 
53     s = FSL_IMX6(object_new(TYPE_FSL_IMX6));
54     object_property_add_child(OBJECT(machine), "soc", OBJECT(s), &error_fatal);
55     object_property_set_bool(OBJECT(s), true, "realized", &err);
56     if (err != NULL) {
57         error_report("%s", error_get_pretty(err));
58         exit(1);
59     }
60 
61     memory_region_add_subregion(get_system_memory(), FSL_IMX6_MMDC_ADDR,
62                                 machine->ram);
63 
64     {
65         /*
66          * TODO: Ideally we would expose the chip select and spi bus on the
67          * SoC object using alias properties; then we would not need to
68          * directly access the underlying spi device object.
69          */
70         /* Add the sst25vf016b NOR FLASH memory to first SPI */
71         Object *spi_dev;
72 
73         spi_dev = object_resolve_path_component(OBJECT(s), "spi1");
74         if (spi_dev) {
75             SSIBus *spi_bus;
76 
77             spi_bus = (SSIBus *)qdev_get_child_bus(DEVICE(spi_dev), "spi");
78             if (spi_bus) {
79                 DeviceState *flash_dev;
80                 qemu_irq cs_line;
81                 DriveInfo *dinfo = drive_get_next(IF_MTD);
82 
83                 flash_dev = ssi_create_slave_no_init(spi_bus, "sst25vf016b");
84                 if (dinfo) {
85                     qdev_prop_set_drive(flash_dev, "drive",
86                                         blk_by_legacy_dinfo(dinfo),
87                                         &error_fatal);
88                 }
89                 qdev_init_nofail(flash_dev);
90 
91                 cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
92                 sysbus_connect_irq(SYS_BUS_DEVICE(spi_dev), 1, cs_line);
93             }
94         }
95     }
96 
97     sabrelite_binfo.ram_size = machine->ram_size;
98     sabrelite_binfo.nb_cpus = machine->smp.cpus;
99     sabrelite_binfo.secure_boot = true;
100     sabrelite_binfo.write_secondary_boot = sabrelite_write_secondary;
101     sabrelite_binfo.secondary_cpu_reset_hook = sabrelite_reset_secondary;
102 
103     if (!qtest_enabled()) {
104         arm_load_kernel(&s->cpu[0], machine, &sabrelite_binfo);
105     }
106 }
107 
108 static void sabrelite_machine_init(MachineClass *mc)
109 {
110     mc->desc = "Freescale i.MX6 Quad SABRE Lite Board (Cortex A9)";
111     mc->init = sabrelite_init;
112     mc->max_cpus = FSL_IMX6_NUM_CPUS;
113     mc->ignore_memory_transaction_failures = true;
114     mc->default_ram_id = "sabrelite.ram";
115 }
116 
117 DEFINE_MACHINE("sabrelite", sabrelite_machine_init)
118