xref: /qemu/hw/arm/imx25_pdk.c (revision 12b167226f2804063cf8d72fe4fdc01764c99e96)
165f57c43SJean-Christophe Dubois /*
265f57c43SJean-Christophe Dubois  * Copyright (c) 2013 Jean-Christophe Dubois <jcd@tribudubois.net>
365f57c43SJean-Christophe Dubois  *
465f57c43SJean-Christophe Dubois  * PDK Board System emulation.
565f57c43SJean-Christophe Dubois  *
665f57c43SJean-Christophe Dubois  * Based on hw/arm/kzm.c
765f57c43SJean-Christophe Dubois  *
865f57c43SJean-Christophe Dubois  * Copyright (c) 2008 OKL and 2011 NICTA
965f57c43SJean-Christophe Dubois  * Written by Hans at OK-Labs
1065f57c43SJean-Christophe Dubois  * Updated by Peter Chubb.
1165f57c43SJean-Christophe Dubois  *
1265f57c43SJean-Christophe Dubois  *  This program is free software; you can redistribute it and/or modify it
1365f57c43SJean-Christophe Dubois  *  under the terms of the GNU General Public License as published by the
1465f57c43SJean-Christophe Dubois  *  Free Software Foundation; either version 2 of the License, or
1565f57c43SJean-Christophe Dubois  *  (at your option) any later version.
1665f57c43SJean-Christophe Dubois  *
1765f57c43SJean-Christophe Dubois  *  This program is distributed in the hope that it will be useful, but WITHOUT
1865f57c43SJean-Christophe Dubois  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1965f57c43SJean-Christophe Dubois  *  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2065f57c43SJean-Christophe Dubois  *  for more details.
2165f57c43SJean-Christophe Dubois  *
2265f57c43SJean-Christophe Dubois  *  You should have received a copy of the GNU General Public License along
2365f57c43SJean-Christophe Dubois  *  with this program; if not, see <http://www.gnu.org/licenses/>.
2465f57c43SJean-Christophe Dubois  */
2565f57c43SJean-Christophe Dubois 
26*12b16722SPeter Maydell #include "qemu/osdep.h"
2765f57c43SJean-Christophe Dubois #include "hw/arm/fsl-imx25.h"
2865f57c43SJean-Christophe Dubois #include "hw/boards.h"
2965f57c43SJean-Christophe Dubois #include "qemu/error-report.h"
3065f57c43SJean-Christophe Dubois #include "exec/address-spaces.h"
3165f57c43SJean-Christophe Dubois #include "sysemu/qtest.h"
3265f57c43SJean-Christophe Dubois #include "hw/i2c/i2c.h"
3365f57c43SJean-Christophe Dubois 
3465f57c43SJean-Christophe Dubois /* Memory map for PDK Emulation Baseboard:
3565f57c43SJean-Christophe Dubois  * 0x00000000-0x7fffffff See i.MX25 SOC fr support
3665f57c43SJean-Christophe Dubois  * 0x80000000-0x87ffffff RAM + Alias          EMULATED
3765f57c43SJean-Christophe Dubois  * 0x90000000-0x9fffffff RAM + Alias          EMULATED
3865f57c43SJean-Christophe Dubois  * 0xa0000000-0xa7ffffff Flash                IGNORED
3965f57c43SJean-Christophe Dubois  * 0xa8000000-0xafffffff Flash                IGNORED
4065f57c43SJean-Christophe Dubois  * 0xb0000000-0xb1ffffff SRAM                 IGNORED
4165f57c43SJean-Christophe Dubois  * 0xb2000000-0xb3ffffff SRAM                 IGNORED
4265f57c43SJean-Christophe Dubois  * 0xb4000000-0xb5ffffff CS4                  IGNORED
4365f57c43SJean-Christophe Dubois  * 0xb6000000-0xb8000fff Reserved             IGNORED
4465f57c43SJean-Christophe Dubois  * 0xb8001000-0xb8001fff SDRAM CTRL reg       IGNORED
4565f57c43SJean-Christophe Dubois  * 0xb8002000-0xb8002fff WEIM CTRL reg        IGNORED
4665f57c43SJean-Christophe Dubois  * 0xb8003000-0xb8003fff M3IF CTRL reg        IGNORED
4765f57c43SJean-Christophe Dubois  * 0xb8004000-0xb8004fff EMI CTRL reg         IGNORED
4865f57c43SJean-Christophe Dubois  * 0xb8005000-0xbaffffff Reserved             IGNORED
4965f57c43SJean-Christophe Dubois  * 0xbb000000-0xbb000fff NAND flash area buf  IGNORED
5065f57c43SJean-Christophe Dubois  * 0xbb001000-0xbb0011ff NAND flash reserved  IGNORED
5165f57c43SJean-Christophe Dubois  * 0xbb001200-0xbb001dff Reserved             IGNORED
5265f57c43SJean-Christophe Dubois  * 0xbb001e00-0xbb001fff NAN flash CTRL reg   IGNORED
5365f57c43SJean-Christophe Dubois  * 0xbb012000-0xbfffffff Reserved             IGNORED
5465f57c43SJean-Christophe Dubois  * 0xc0000000-0xffffffff Reserved             IGNORED
5565f57c43SJean-Christophe Dubois  */
5665f57c43SJean-Christophe Dubois 
5765f57c43SJean-Christophe Dubois typedef struct IMX25PDK {
5865f57c43SJean-Christophe Dubois     FslIMX25State soc;
5965f57c43SJean-Christophe Dubois     MemoryRegion ram;
6065f57c43SJean-Christophe Dubois     MemoryRegion ram_alias;
6165f57c43SJean-Christophe Dubois } IMX25PDK;
6265f57c43SJean-Christophe Dubois 
6365f57c43SJean-Christophe Dubois static struct arm_boot_info imx25_pdk_binfo;
6465f57c43SJean-Christophe Dubois 
6565f57c43SJean-Christophe Dubois static void imx25_pdk_init(MachineState *machine)
6665f57c43SJean-Christophe Dubois {
6765f57c43SJean-Christophe Dubois     IMX25PDK *s = g_new0(IMX25PDK, 1);
6865f57c43SJean-Christophe Dubois     Error *err = NULL;
6965f57c43SJean-Christophe Dubois     unsigned int ram_size;
7065f57c43SJean-Christophe Dubois     unsigned int alias_offset;
7165f57c43SJean-Christophe Dubois     int i;
7265f57c43SJean-Christophe Dubois 
7365f57c43SJean-Christophe Dubois     object_initialize(&s->soc, sizeof(s->soc), TYPE_FSL_IMX25);
7465f57c43SJean-Christophe Dubois     object_property_add_child(OBJECT(machine), "soc", OBJECT(&s->soc),
7565f57c43SJean-Christophe Dubois                               &error_abort);
7665f57c43SJean-Christophe Dubois 
7765f57c43SJean-Christophe Dubois     object_property_set_bool(OBJECT(&s->soc), true, "realized", &err);
7865f57c43SJean-Christophe Dubois     if (err != NULL) {
794fffeb5eSMarkus Armbruster         error_report_err(err);
8065f57c43SJean-Christophe Dubois         exit(1);
8165f57c43SJean-Christophe Dubois     }
8265f57c43SJean-Christophe Dubois 
8365f57c43SJean-Christophe Dubois     /* We need to initialize our memory */
8465f57c43SJean-Christophe Dubois     if (machine->ram_size > (FSL_IMX25_SDRAM0_SIZE + FSL_IMX25_SDRAM1_SIZE)) {
8565f57c43SJean-Christophe Dubois         error_report("WARNING: RAM size " RAM_ADDR_FMT " above max supported, "
8665f57c43SJean-Christophe Dubois                      "reduced to %x", machine->ram_size,
8765f57c43SJean-Christophe Dubois                      FSL_IMX25_SDRAM0_SIZE + FSL_IMX25_SDRAM1_SIZE);
8865f57c43SJean-Christophe Dubois         machine->ram_size = FSL_IMX25_SDRAM0_SIZE + FSL_IMX25_SDRAM1_SIZE;
8965f57c43SJean-Christophe Dubois     }
9065f57c43SJean-Christophe Dubois 
9165f57c43SJean-Christophe Dubois     memory_region_allocate_system_memory(&s->ram, NULL, "imx25.ram",
9265f57c43SJean-Christophe Dubois                                          machine->ram_size);
9365f57c43SJean-Christophe Dubois     memory_region_add_subregion(get_system_memory(), FSL_IMX25_SDRAM0_ADDR,
9465f57c43SJean-Christophe Dubois                                 &s->ram);
9565f57c43SJean-Christophe Dubois 
9665f57c43SJean-Christophe Dubois     /* initialize the alias memory if any */
9765f57c43SJean-Christophe Dubois     for (i = 0, ram_size = machine->ram_size, alias_offset = 0;
9865f57c43SJean-Christophe Dubois          (i < 2) && ram_size; i++) {
9965f57c43SJean-Christophe Dubois         unsigned int size;
10065f57c43SJean-Christophe Dubois         static const struct {
10165f57c43SJean-Christophe Dubois             hwaddr addr;
10265f57c43SJean-Christophe Dubois             unsigned int size;
10365f57c43SJean-Christophe Dubois         } ram[2] = {
10465f57c43SJean-Christophe Dubois             { FSL_IMX25_SDRAM0_ADDR, FSL_IMX25_SDRAM0_SIZE },
10565f57c43SJean-Christophe Dubois             { FSL_IMX25_SDRAM1_ADDR, FSL_IMX25_SDRAM1_SIZE },
10665f57c43SJean-Christophe Dubois         };
10765f57c43SJean-Christophe Dubois 
10865f57c43SJean-Christophe Dubois         size = MIN(ram_size, ram[i].size);
10965f57c43SJean-Christophe Dubois 
11065f57c43SJean-Christophe Dubois         ram_size -= size;
11165f57c43SJean-Christophe Dubois 
11265f57c43SJean-Christophe Dubois         if (size < ram[i].size) {
11365f57c43SJean-Christophe Dubois             memory_region_init_alias(&s->ram_alias, NULL, "ram.alias",
11465f57c43SJean-Christophe Dubois                                      &s->ram, alias_offset, ram[i].size - size);
11565f57c43SJean-Christophe Dubois             memory_region_add_subregion(get_system_memory(),
11665f57c43SJean-Christophe Dubois                                         ram[i].addr + size, &s->ram_alias);
11765f57c43SJean-Christophe Dubois         }
11865f57c43SJean-Christophe Dubois 
11965f57c43SJean-Christophe Dubois         alias_offset += ram[i].size;
12065f57c43SJean-Christophe Dubois     }
12165f57c43SJean-Christophe Dubois 
12265f57c43SJean-Christophe Dubois     imx25_pdk_binfo.ram_size = machine->ram_size;
12365f57c43SJean-Christophe Dubois     imx25_pdk_binfo.kernel_filename = machine->kernel_filename;
12465f57c43SJean-Christophe Dubois     imx25_pdk_binfo.kernel_cmdline = machine->kernel_cmdline;
12565f57c43SJean-Christophe Dubois     imx25_pdk_binfo.initrd_filename = machine->initrd_filename;
12665f57c43SJean-Christophe Dubois     imx25_pdk_binfo.loader_start = FSL_IMX25_SDRAM0_ADDR;
12765f57c43SJean-Christophe Dubois     imx25_pdk_binfo.board_id = 1771,
12865f57c43SJean-Christophe Dubois     imx25_pdk_binfo.nb_cpus = 1;
12965f57c43SJean-Christophe Dubois 
13065f57c43SJean-Christophe Dubois     /*
13165f57c43SJean-Christophe Dubois      * We test explicitly for qtest here as it is not done (yet?) in
13265f57c43SJean-Christophe Dubois      * arm_load_kernel(). Without this the "make check" command would
13365f57c43SJean-Christophe Dubois      * fail.
13465f57c43SJean-Christophe Dubois      */
13565f57c43SJean-Christophe Dubois     if (!qtest_enabled()) {
13665f57c43SJean-Christophe Dubois         arm_load_kernel(&s->soc.cpu, &imx25_pdk_binfo);
13765f57c43SJean-Christophe Dubois     } else {
13865f57c43SJean-Christophe Dubois         /*
13965f57c43SJean-Christophe Dubois          * This I2C device doesn't exist on the real board.
14065f57c43SJean-Christophe Dubois          * We add it here (only on qtest usage) to be able to do a bit
14165f57c43SJean-Christophe Dubois          * of simple qtest. See "make check" for details.
14265f57c43SJean-Christophe Dubois          */
14365f57c43SJean-Christophe Dubois         i2c_create_slave((I2CBus *)qdev_get_child_bus(DEVICE(&s->soc.i2c[0]),
14465f57c43SJean-Christophe Dubois                                                       "i2c"),
14565f57c43SJean-Christophe Dubois                          "ds1338", 0x68);
14665f57c43SJean-Christophe Dubois     }
14765f57c43SJean-Christophe Dubois }
14865f57c43SJean-Christophe Dubois 
149e264d29dSEduardo Habkost static void imx25_pdk_machine_init(MachineClass *mc)
15065f57c43SJean-Christophe Dubois {
151e264d29dSEduardo Habkost     mc->desc = "ARM i.MX25 PDK board (ARM926)";
152e264d29dSEduardo Habkost     mc->init = imx25_pdk_init;
15365f57c43SJean-Christophe Dubois }
15465f57c43SJean-Christophe Dubois 
155b64d64deSPeter Crosthwaite DEFINE_MACHINE("imx25-pdk", imx25_pdk_machine_init)
156