xref: /openbmc/qemu/hw/arm/imx25_pdk.c (revision cc17f3b2ad036a315a943f1085fd29b9531f0cba)
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"
28bfae1772SGuenter Roeck #include "hw/qdev-properties.h"
2965f57c43SJean-Christophe Dubois #include "hw/arm/fsl-imx25.h"
306fda3b91SPhilippe Mathieu-Daudé #include "hw/arm/boot.h"
3165f57c43SJean-Christophe Dubois #include "hw/boards.h"
3265f57c43SJean-Christophe Dubois #include "qemu/error-report.h"
3365f57c43SJean-Christophe Dubois #include "sysemu/qtest.h"
3465f57c43SJean-Christophe Dubois #include "hw/i2c/i2c.h"
35bf350daaSIgor Mammedov #include "qemu/cutils.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_alias;
6365f57c43SJean-Christophe Dubois } IMX25PDK;
6465f57c43SJean-Christophe Dubois 
6565f57c43SJean-Christophe Dubois static struct arm_boot_info imx25_pdk_binfo;
6665f57c43SJean-Christophe Dubois 
imx25_pdk_init(MachineState * machine)6765f57c43SJean-Christophe Dubois static void imx25_pdk_init(MachineState *machine)
6865f57c43SJean-Christophe Dubois {
6965f57c43SJean-Christophe Dubois     IMX25PDK *s = g_new0(IMX25PDK, 1);
7065f57c43SJean-Christophe Dubois     unsigned int ram_size;
7165f57c43SJean-Christophe Dubois     unsigned int alias_offset;
7265f57c43SJean-Christophe Dubois     int i;
7365f57c43SJean-Christophe Dubois 
749fc7fc4dSMarkus Armbruster     object_initialize_child(OBJECT(machine), "soc", &s->soc, TYPE_FSL_IMX25);
7565f57c43SJean-Christophe Dubois 
76ce189ab2SMarkus Armbruster     qdev_realize(DEVICE(&s->soc), NULL, &error_fatal);
7765f57c43SJean-Christophe Dubois 
7865f57c43SJean-Christophe Dubois     /* We need to initialize our memory */
7965f57c43SJean-Christophe Dubois     if (machine->ram_size > (FSL_IMX25_SDRAM0_SIZE + FSL_IMX25_SDRAM1_SIZE)) {
80f463684fSPhilippe Mathieu-Daudé         char *sz = size_to_str(FSL_IMX25_SDRAM0_SIZE + FSL_IMX25_SDRAM1_SIZE);
81f463684fSPhilippe Mathieu-Daudé         error_report("RAM size more than %s is not supported", sz);
82bf350daaSIgor Mammedov         g_free(sz);
83bf350daaSIgor Mammedov         exit(EXIT_FAILURE);
8465f57c43SJean-Christophe Dubois     }
8565f57c43SJean-Christophe Dubois 
8665f57c43SJean-Christophe Dubois     memory_region_add_subregion(get_system_memory(), FSL_IMX25_SDRAM0_ADDR,
87eebd06abSIgor Mammedov                                 machine->ram);
8865f57c43SJean-Christophe Dubois 
8965f57c43SJean-Christophe Dubois     /* initialize the alias memory if any */
9065f57c43SJean-Christophe Dubois     for (i = 0, ram_size = machine->ram_size, alias_offset = 0;
9165f57c43SJean-Christophe Dubois          (i < 2) && ram_size; i++) {
9265f57c43SJean-Christophe Dubois         unsigned int size;
9365f57c43SJean-Christophe Dubois         static const struct {
9465f57c43SJean-Christophe Dubois             hwaddr addr;
9565f57c43SJean-Christophe Dubois             unsigned int size;
9665f57c43SJean-Christophe Dubois         } ram[2] = {
9765f57c43SJean-Christophe Dubois             { FSL_IMX25_SDRAM0_ADDR, FSL_IMX25_SDRAM0_SIZE },
9865f57c43SJean-Christophe Dubois             { FSL_IMX25_SDRAM1_ADDR, FSL_IMX25_SDRAM1_SIZE },
9965f57c43SJean-Christophe Dubois         };
10065f57c43SJean-Christophe Dubois 
10165f57c43SJean-Christophe Dubois         size = MIN(ram_size, ram[i].size);
10265f57c43SJean-Christophe Dubois 
10365f57c43SJean-Christophe Dubois         ram_size -= size;
10465f57c43SJean-Christophe Dubois 
10565f57c43SJean-Christophe Dubois         if (size < ram[i].size) {
10665f57c43SJean-Christophe Dubois             memory_region_init_alias(&s->ram_alias, NULL, "ram.alias",
107eebd06abSIgor Mammedov                                      machine->ram,
108eebd06abSIgor Mammedov                                      alias_offset, ram[i].size - size);
10965f57c43SJean-Christophe Dubois             memory_region_add_subregion(get_system_memory(),
11065f57c43SJean-Christophe Dubois                                         ram[i].addr + size, &s->ram_alias);
11165f57c43SJean-Christophe Dubois         }
11265f57c43SJean-Christophe Dubois 
11365f57c43SJean-Christophe Dubois         alias_offset += ram[i].size;
11465f57c43SJean-Christophe Dubois     }
11565f57c43SJean-Christophe Dubois 
11665f57c43SJean-Christophe Dubois     imx25_pdk_binfo.ram_size = machine->ram_size;
11765f57c43SJean-Christophe Dubois     imx25_pdk_binfo.loader_start = FSL_IMX25_SDRAM0_ADDR;
118d6dc926eSPeter Maydell     imx25_pdk_binfo.board_id = 1771;
11965f57c43SJean-Christophe Dubois 
120bfae1772SGuenter Roeck     for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) {
121bfae1772SGuenter Roeck         BusState *bus;
122bfae1772SGuenter Roeck         DeviceState *carddev;
123bfae1772SGuenter Roeck         DriveInfo *di;
124bfae1772SGuenter Roeck         BlockBackend *blk;
125bfae1772SGuenter Roeck 
1266b87668bSMarkus Armbruster         di = drive_get(IF_SD, 0, i);
127bfae1772SGuenter Roeck         blk = di ? blk_by_legacy_dinfo(di) : NULL;
128*cc17f3b2SCédric Le Goater         bus = BUS(&s->soc.esdhc[i].sdbus);
1293e80f690SMarkus Armbruster         carddev = qdev_new(TYPE_SD_CARD);
130934df912SMarkus Armbruster         qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
1313e80f690SMarkus Armbruster         qdev_realize_and_unref(carddev, bus, &error_fatal);
132bfae1772SGuenter Roeck     }
133bfae1772SGuenter Roeck 
13465f57c43SJean-Christophe Dubois     /*
13565f57c43SJean-Christophe Dubois      * We test explicitly for qtest here as it is not done (yet?) in
13665f57c43SJean-Christophe Dubois      * arm_load_kernel(). Without this the "make check" command would
13765f57c43SJean-Christophe Dubois      * fail.
13865f57c43SJean-Christophe Dubois      */
13965f57c43SJean-Christophe Dubois     if (!qtest_enabled()) {
1402744ece8STao Xu         arm_load_kernel(&s->soc.cpu, machine, &imx25_pdk_binfo);
14165f57c43SJean-Christophe Dubois     }
14265f57c43SJean-Christophe Dubois }
14365f57c43SJean-Christophe Dubois 
imx25_pdk_machine_init(MachineClass * mc)144e264d29dSEduardo Habkost static void imx25_pdk_machine_init(MachineClass *mc)
14565f57c43SJean-Christophe Dubois {
146e264d29dSEduardo Habkost     mc->desc = "ARM i.MX25 PDK board (ARM926)";
147e264d29dSEduardo Habkost     mc->init = imx25_pdk_init;
1484672cbd7SPeter Maydell     mc->ignore_memory_transaction_failures = true;
149eebd06abSIgor Mammedov     mc->default_ram_id = "imx25.ram";
15065f57c43SJean-Christophe Dubois }
15165f57c43SJean-Christophe Dubois 
152b64d64deSPeter Crosthwaite DEFINE_MACHINE("imx25-pdk", imx25_pdk_machine_init)
153