xref: /qemu/hw/arm/imx25_pdk.c (revision 4771d756f46219762477aaeaaef9bd215e3d5c60)
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 
2612b16722SPeter Maydell #include "qemu/osdep.h"
27da34e65cSMarkus Armbruster #include "qapi/error.h"
28*4771d756SPaolo Bonzini #include "qemu-common.h"
29*4771d756SPaolo Bonzini #include "cpu.h"
3065f57c43SJean-Christophe Dubois #include "hw/arm/fsl-imx25.h"
3165f57c43SJean-Christophe Dubois #include "hw/boards.h"
3265f57c43SJean-Christophe Dubois #include "qemu/error-report.h"
3365f57c43SJean-Christophe Dubois #include "exec/address-spaces.h"
3465f57c43SJean-Christophe Dubois #include "sysemu/qtest.h"
3565f57c43SJean-Christophe Dubois #include "hw/i2c/i2c.h"
3665f57c43SJean-Christophe Dubois 
3765f57c43SJean-Christophe Dubois /* Memory map for PDK Emulation Baseboard:
3865f57c43SJean-Christophe Dubois  * 0x00000000-0x7fffffff See i.MX25 SOC fr support
3965f57c43SJean-Christophe Dubois  * 0x80000000-0x87ffffff RAM + Alias          EMULATED
4065f57c43SJean-Christophe Dubois  * 0x90000000-0x9fffffff RAM + Alias          EMULATED
4165f57c43SJean-Christophe Dubois  * 0xa0000000-0xa7ffffff Flash                IGNORED
4265f57c43SJean-Christophe Dubois  * 0xa8000000-0xafffffff Flash                IGNORED
4365f57c43SJean-Christophe Dubois  * 0xb0000000-0xb1ffffff SRAM                 IGNORED
4465f57c43SJean-Christophe Dubois  * 0xb2000000-0xb3ffffff SRAM                 IGNORED
4565f57c43SJean-Christophe Dubois  * 0xb4000000-0xb5ffffff CS4                  IGNORED
4665f57c43SJean-Christophe Dubois  * 0xb6000000-0xb8000fff Reserved             IGNORED
4765f57c43SJean-Christophe Dubois  * 0xb8001000-0xb8001fff SDRAM CTRL reg       IGNORED
4865f57c43SJean-Christophe Dubois  * 0xb8002000-0xb8002fff WEIM CTRL reg        IGNORED
4965f57c43SJean-Christophe Dubois  * 0xb8003000-0xb8003fff M3IF CTRL reg        IGNORED
5065f57c43SJean-Christophe Dubois  * 0xb8004000-0xb8004fff EMI CTRL reg         IGNORED
5165f57c43SJean-Christophe Dubois  * 0xb8005000-0xbaffffff Reserved             IGNORED
5265f57c43SJean-Christophe Dubois  * 0xbb000000-0xbb000fff NAND flash area buf  IGNORED
5365f57c43SJean-Christophe Dubois  * 0xbb001000-0xbb0011ff NAND flash reserved  IGNORED
5465f57c43SJean-Christophe Dubois  * 0xbb001200-0xbb001dff Reserved             IGNORED
5565f57c43SJean-Christophe Dubois  * 0xbb001e00-0xbb001fff NAN flash CTRL reg   IGNORED
5665f57c43SJean-Christophe Dubois  * 0xbb012000-0xbfffffff Reserved             IGNORED
5765f57c43SJean-Christophe Dubois  * 0xc0000000-0xffffffff Reserved             IGNORED
5865f57c43SJean-Christophe Dubois  */
5965f57c43SJean-Christophe Dubois 
6065f57c43SJean-Christophe Dubois typedef struct IMX25PDK {
6165f57c43SJean-Christophe Dubois     FslIMX25State soc;
6265f57c43SJean-Christophe Dubois     MemoryRegion ram;
6365f57c43SJean-Christophe Dubois     MemoryRegion ram_alias;
6465f57c43SJean-Christophe Dubois } IMX25PDK;
6565f57c43SJean-Christophe Dubois 
6665f57c43SJean-Christophe Dubois static struct arm_boot_info imx25_pdk_binfo;
6765f57c43SJean-Christophe Dubois 
6865f57c43SJean-Christophe Dubois static void imx25_pdk_init(MachineState *machine)
6965f57c43SJean-Christophe Dubois {
7065f57c43SJean-Christophe Dubois     IMX25PDK *s = g_new0(IMX25PDK, 1);
7165f57c43SJean-Christophe Dubois     unsigned int ram_size;
7265f57c43SJean-Christophe Dubois     unsigned int alias_offset;
7365f57c43SJean-Christophe Dubois     int i;
7465f57c43SJean-Christophe Dubois 
7565f57c43SJean-Christophe Dubois     object_initialize(&s->soc, sizeof(s->soc), TYPE_FSL_IMX25);
7665f57c43SJean-Christophe Dubois     object_property_add_child(OBJECT(machine), "soc", OBJECT(&s->soc),
7765f57c43SJean-Christophe Dubois                               &error_abort);
7865f57c43SJean-Christophe Dubois 
7907d04a02SMarkus Armbruster     object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_fatal);
8065f57c43SJean-Christophe Dubois 
8165f57c43SJean-Christophe Dubois     /* We need to initialize our memory */
8265f57c43SJean-Christophe Dubois     if (machine->ram_size > (FSL_IMX25_SDRAM0_SIZE + FSL_IMX25_SDRAM1_SIZE)) {
8365f57c43SJean-Christophe Dubois         error_report("WARNING: RAM size " RAM_ADDR_FMT " above max supported, "
8465f57c43SJean-Christophe Dubois                      "reduced to %x", machine->ram_size,
8565f57c43SJean-Christophe Dubois                      FSL_IMX25_SDRAM0_SIZE + FSL_IMX25_SDRAM1_SIZE);
8665f57c43SJean-Christophe Dubois         machine->ram_size = FSL_IMX25_SDRAM0_SIZE + FSL_IMX25_SDRAM1_SIZE;
8765f57c43SJean-Christophe Dubois     }
8865f57c43SJean-Christophe Dubois 
8965f57c43SJean-Christophe Dubois     memory_region_allocate_system_memory(&s->ram, NULL, "imx25.ram",
9065f57c43SJean-Christophe Dubois                                          machine->ram_size);
9165f57c43SJean-Christophe Dubois     memory_region_add_subregion(get_system_memory(), FSL_IMX25_SDRAM0_ADDR,
9265f57c43SJean-Christophe Dubois                                 &s->ram);
9365f57c43SJean-Christophe Dubois 
9465f57c43SJean-Christophe Dubois     /* initialize the alias memory if any */
9565f57c43SJean-Christophe Dubois     for (i = 0, ram_size = machine->ram_size, alias_offset = 0;
9665f57c43SJean-Christophe Dubois          (i < 2) && ram_size; i++) {
9765f57c43SJean-Christophe Dubois         unsigned int size;
9865f57c43SJean-Christophe Dubois         static const struct {
9965f57c43SJean-Christophe Dubois             hwaddr addr;
10065f57c43SJean-Christophe Dubois             unsigned int size;
10165f57c43SJean-Christophe Dubois         } ram[2] = {
10265f57c43SJean-Christophe Dubois             { FSL_IMX25_SDRAM0_ADDR, FSL_IMX25_SDRAM0_SIZE },
10365f57c43SJean-Christophe Dubois             { FSL_IMX25_SDRAM1_ADDR, FSL_IMX25_SDRAM1_SIZE },
10465f57c43SJean-Christophe Dubois         };
10565f57c43SJean-Christophe Dubois 
10665f57c43SJean-Christophe Dubois         size = MIN(ram_size, ram[i].size);
10765f57c43SJean-Christophe Dubois 
10865f57c43SJean-Christophe Dubois         ram_size -= size;
10965f57c43SJean-Christophe Dubois 
11065f57c43SJean-Christophe Dubois         if (size < ram[i].size) {
11165f57c43SJean-Christophe Dubois             memory_region_init_alias(&s->ram_alias, NULL, "ram.alias",
11265f57c43SJean-Christophe Dubois                                      &s->ram, alias_offset, ram[i].size - size);
11365f57c43SJean-Christophe Dubois             memory_region_add_subregion(get_system_memory(),
11465f57c43SJean-Christophe Dubois                                         ram[i].addr + size, &s->ram_alias);
11565f57c43SJean-Christophe Dubois         }
11665f57c43SJean-Christophe Dubois 
11765f57c43SJean-Christophe Dubois         alias_offset += ram[i].size;
11865f57c43SJean-Christophe Dubois     }
11965f57c43SJean-Christophe Dubois 
12065f57c43SJean-Christophe Dubois     imx25_pdk_binfo.ram_size = machine->ram_size;
12165f57c43SJean-Christophe Dubois     imx25_pdk_binfo.kernel_filename = machine->kernel_filename;
12265f57c43SJean-Christophe Dubois     imx25_pdk_binfo.kernel_cmdline = machine->kernel_cmdline;
12365f57c43SJean-Christophe Dubois     imx25_pdk_binfo.initrd_filename = machine->initrd_filename;
12465f57c43SJean-Christophe Dubois     imx25_pdk_binfo.loader_start = FSL_IMX25_SDRAM0_ADDR;
12565f57c43SJean-Christophe Dubois     imx25_pdk_binfo.board_id = 1771,
12665f57c43SJean-Christophe Dubois     imx25_pdk_binfo.nb_cpus = 1;
12765f57c43SJean-Christophe Dubois 
12865f57c43SJean-Christophe Dubois     /*
12965f57c43SJean-Christophe Dubois      * We test explicitly for qtest here as it is not done (yet?) in
13065f57c43SJean-Christophe Dubois      * arm_load_kernel(). Without this the "make check" command would
13165f57c43SJean-Christophe Dubois      * fail.
13265f57c43SJean-Christophe Dubois      */
13365f57c43SJean-Christophe Dubois     if (!qtest_enabled()) {
13465f57c43SJean-Christophe Dubois         arm_load_kernel(&s->soc.cpu, &imx25_pdk_binfo);
13565f57c43SJean-Christophe Dubois     } else {
13665f57c43SJean-Christophe Dubois         /*
13765f57c43SJean-Christophe Dubois          * This I2C device doesn't exist on the real board.
13865f57c43SJean-Christophe Dubois          * We add it here (only on qtest usage) to be able to do a bit
13965f57c43SJean-Christophe Dubois          * of simple qtest. See "make check" for details.
14065f57c43SJean-Christophe Dubois          */
14165f57c43SJean-Christophe Dubois         i2c_create_slave((I2CBus *)qdev_get_child_bus(DEVICE(&s->soc.i2c[0]),
14265f57c43SJean-Christophe Dubois                                                       "i2c"),
14365f57c43SJean-Christophe Dubois                          "ds1338", 0x68);
14465f57c43SJean-Christophe Dubois     }
14565f57c43SJean-Christophe Dubois }
14665f57c43SJean-Christophe Dubois 
147e264d29dSEduardo Habkost static void imx25_pdk_machine_init(MachineClass *mc)
14865f57c43SJean-Christophe Dubois {
149e264d29dSEduardo Habkost     mc->desc = "ARM i.MX25 PDK board (ARM926)";
150e264d29dSEduardo Habkost     mc->init = imx25_pdk_init;
15165f57c43SJean-Christophe Dubois }
15265f57c43SJean-Christophe Dubois 
153b64d64deSPeter Crosthwaite DEFINE_MACHINE("imx25-pdk", imx25_pdk_machine_init)
154