xref: /openbmc/qemu/hw/arm/omap_sx1.c (revision ba1ba5cca3962a9cc400c713c736b4fb8db1f38e)
153018216SPaolo Bonzini /* omap_sx1.c Support for the Siemens SX1 smartphone emulation.
253018216SPaolo Bonzini  *
353018216SPaolo Bonzini  *   Copyright (C) 2008
453018216SPaolo Bonzini  * 	Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
553018216SPaolo Bonzini  *   Copyright (C) 2007 Vladimir Ananiev <vovan888@gmail.com>
653018216SPaolo Bonzini  *
753018216SPaolo Bonzini  *   based on PalmOne's (TM) PDAs support (palm.c)
853018216SPaolo Bonzini  */
953018216SPaolo Bonzini 
1053018216SPaolo Bonzini /*
1153018216SPaolo Bonzini  * PalmOne's (TM) PDAs.
1253018216SPaolo Bonzini  *
1353018216SPaolo Bonzini  * Copyright (C) 2006-2007 Andrzej Zaborowski <balrog@zabor.org>
1453018216SPaolo Bonzini  *
1553018216SPaolo Bonzini  * This program is free software; you can redistribute it and/or
1653018216SPaolo Bonzini  * modify it under the terms of the GNU General Public License as
1753018216SPaolo Bonzini  * published by the Free Software Foundation; either version 2 of
1853018216SPaolo Bonzini  * the License, or (at your option) any later version.
1953018216SPaolo Bonzini  *
2053018216SPaolo Bonzini  * This program is distributed in the hope that it will be useful,
2153018216SPaolo Bonzini  * but WITHOUT ANY WARRANTY; without even the implied warranty of
2253018216SPaolo Bonzini  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2353018216SPaolo Bonzini  * GNU General Public License for more details.
2453018216SPaolo Bonzini  *
2553018216SPaolo Bonzini  * You should have received a copy of the GNU General Public License along
2653018216SPaolo Bonzini  * with this program; if not, see <http://www.gnu.org/licenses/>.
2753018216SPaolo Bonzini  */
2812b16722SPeter Maydell #include "qemu/osdep.h"
29da34e65cSMarkus Armbruster #include "qapi/error.h"
3053018216SPaolo Bonzini #include "hw/hw.h"
3153018216SPaolo Bonzini #include "ui/console.h"
320d09e41aSPaolo Bonzini #include "hw/arm/omap.h"
3353018216SPaolo Bonzini #include "hw/boards.h"
34bd2be150SPeter Maydell #include "hw/arm/arm.h"
350d09e41aSPaolo Bonzini #include "hw/block/flash.h"
36fa1d36dfSMarkus Armbruster #include "sysemu/block-backend.h"
37db3fd069SAndreas Färber #include "sysemu/qtest.h"
3853018216SPaolo Bonzini #include "exec/address-spaces.h"
39*ba1ba5ccSIgor Mammedov #include "cpu.h"
4053018216SPaolo Bonzini 
4153018216SPaolo Bonzini /*****************************************************************************/
4253018216SPaolo Bonzini /* Siemens SX1 Cellphone V1 */
4353018216SPaolo Bonzini /* - ARM OMAP310 processor
4453018216SPaolo Bonzini  * - SRAM                192 kB
4553018216SPaolo Bonzini  * - SDRAM                32 MB at 0x10000000
4653018216SPaolo Bonzini  * - Boot flash           16 MB at 0x00000000
4753018216SPaolo Bonzini  * - Application flash     8 MB at 0x04000000
4853018216SPaolo Bonzini  * - 3 serial ports
4953018216SPaolo Bonzini  * - 1 SecureDigital
5053018216SPaolo Bonzini  * - 1 LCD display
5153018216SPaolo Bonzini  * - 1 RTC
5253018216SPaolo Bonzini  */
5353018216SPaolo Bonzini 
5453018216SPaolo Bonzini /*****************************************************************************/
5553018216SPaolo Bonzini /* Siemens SX1 Cellphone V2 */
5653018216SPaolo Bonzini /* - ARM OMAP310 processor
5753018216SPaolo Bonzini  * - SRAM                192 kB
5853018216SPaolo Bonzini  * - SDRAM                32 MB at 0x10000000
5953018216SPaolo Bonzini  * - Boot flash           32 MB at 0x00000000
6053018216SPaolo Bonzini  * - 3 serial ports
6153018216SPaolo Bonzini  * - 1 SecureDigital
6253018216SPaolo Bonzini  * - 1 LCD display
6353018216SPaolo Bonzini  * - 1 RTC
6453018216SPaolo Bonzini  */
6553018216SPaolo Bonzini 
6653018216SPaolo Bonzini static uint64_t static_read(void *opaque, hwaddr offset,
6753018216SPaolo Bonzini                             unsigned size)
6853018216SPaolo Bonzini {
6953018216SPaolo Bonzini     uint32_t *val = (uint32_t *) opaque;
7053018216SPaolo Bonzini     uint32_t mask = (4 / size) - 1;
7153018216SPaolo Bonzini 
7253018216SPaolo Bonzini     return *val >> ((offset & mask) << 3);
7353018216SPaolo Bonzini }
7453018216SPaolo Bonzini 
7553018216SPaolo Bonzini static void static_write(void *opaque, hwaddr offset,
7653018216SPaolo Bonzini                          uint64_t value, unsigned size)
7753018216SPaolo Bonzini {
7853018216SPaolo Bonzini #ifdef SPY
7953018216SPaolo Bonzini     printf("%s: value %" PRIx64 " %u bytes written at 0x%x\n",
8053018216SPaolo Bonzini                     __func__, value, size, (int)offset);
8153018216SPaolo Bonzini #endif
8253018216SPaolo Bonzini }
8353018216SPaolo Bonzini 
8453018216SPaolo Bonzini static const MemoryRegionOps static_ops = {
8553018216SPaolo Bonzini     .read = static_read,
8653018216SPaolo Bonzini     .write = static_write,
8753018216SPaolo Bonzini     .endianness = DEVICE_NATIVE_ENDIAN,
8853018216SPaolo Bonzini };
8953018216SPaolo Bonzini 
9053018216SPaolo Bonzini #define sdram_size	0x02000000
9153018216SPaolo Bonzini #define sector_size	(128 * 1024)
9253018216SPaolo Bonzini #define flash0_size	(16 * 1024 * 1024)
9353018216SPaolo Bonzini #define flash1_size	( 8 * 1024 * 1024)
9453018216SPaolo Bonzini #define flash2_size	(32 * 1024 * 1024)
9553018216SPaolo Bonzini #define total_ram_v1	(sdram_size + flash0_size + flash1_size + OMAP15XX_SRAM_SIZE)
9653018216SPaolo Bonzini #define total_ram_v2	(sdram_size + flash2_size + OMAP15XX_SRAM_SIZE)
9753018216SPaolo Bonzini 
9853018216SPaolo Bonzini static struct arm_boot_info sx1_binfo = {
9953018216SPaolo Bonzini     .loader_start = OMAP_EMIFF_BASE,
10053018216SPaolo Bonzini     .ram_size = sdram_size,
10153018216SPaolo Bonzini     .board_id = 0x265,
10253018216SPaolo Bonzini };
10353018216SPaolo Bonzini 
1043ef96221SMarcel Apfelbaum static void sx1_init(MachineState *machine, const int version)
10553018216SPaolo Bonzini {
10653018216SPaolo Bonzini     struct omap_mpu_state_s *mpu;
10753018216SPaolo Bonzini     MemoryRegion *address_space = get_system_memory();
10853018216SPaolo Bonzini     MemoryRegion *flash = g_new(MemoryRegion, 1);
10953018216SPaolo Bonzini     MemoryRegion *cs = g_new(MemoryRegion, 4);
11053018216SPaolo Bonzini     static uint32_t cs0val = 0x00213090;
11153018216SPaolo Bonzini     static uint32_t cs1val = 0x00215070;
11253018216SPaolo Bonzini     static uint32_t cs2val = 0x00001139;
11353018216SPaolo Bonzini     static uint32_t cs3val = 0x00001139;
11453018216SPaolo Bonzini     DriveInfo *dinfo;
11553018216SPaolo Bonzini     int fl_idx;
11653018216SPaolo Bonzini     uint32_t flash_size = flash0_size;
11753018216SPaolo Bonzini     int be;
11853018216SPaolo Bonzini 
11953018216SPaolo Bonzini     if (version == 2) {
12053018216SPaolo Bonzini         flash_size = flash2_size;
12153018216SPaolo Bonzini     }
12253018216SPaolo Bonzini 
1233ef96221SMarcel Apfelbaum     mpu = omap310_mpu_init(address_space, sx1_binfo.ram_size,
124*ba1ba5ccSIgor Mammedov                            machine->cpu_type);
12553018216SPaolo Bonzini 
12653018216SPaolo Bonzini     /* External Flash (EMIFS) */
12798a99ce0SPeter Maydell     memory_region_init_ram(flash, NULL, "omap_sx1.flash0-0", flash_size,
128f8ed85acSMarkus Armbruster                            &error_fatal);
12953018216SPaolo Bonzini     memory_region_set_readonly(flash, true);
13053018216SPaolo Bonzini     memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
13153018216SPaolo Bonzini 
1322c9b15caSPaolo Bonzini     memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
13353018216SPaolo Bonzini                           "sx1.cs0", OMAP_CS0_SIZE - flash_size);
13453018216SPaolo Bonzini     memory_region_add_subregion(address_space,
13553018216SPaolo Bonzini                                 OMAP_CS0_BASE + flash_size, &cs[0]);
13653018216SPaolo Bonzini 
13753018216SPaolo Bonzini 
1382c9b15caSPaolo Bonzini     memory_region_init_io(&cs[2], NULL, &static_ops, &cs2val,
13953018216SPaolo Bonzini                           "sx1.cs2", OMAP_CS2_SIZE);
14053018216SPaolo Bonzini     memory_region_add_subregion(address_space,
14153018216SPaolo Bonzini                                 OMAP_CS2_BASE, &cs[2]);
14253018216SPaolo Bonzini 
1432c9b15caSPaolo Bonzini     memory_region_init_io(&cs[3], NULL, &static_ops, &cs3val,
14453018216SPaolo Bonzini                           "sx1.cs3", OMAP_CS3_SIZE);
14553018216SPaolo Bonzini     memory_region_add_subregion(address_space,
14653018216SPaolo Bonzini                                 OMAP_CS2_BASE, &cs[3]);
14753018216SPaolo Bonzini 
14853018216SPaolo Bonzini     fl_idx = 0;
14953018216SPaolo Bonzini #ifdef TARGET_WORDS_BIGENDIAN
15053018216SPaolo Bonzini     be = 1;
15153018216SPaolo Bonzini #else
15253018216SPaolo Bonzini     be = 0;
15353018216SPaolo Bonzini #endif
15453018216SPaolo Bonzini 
15553018216SPaolo Bonzini     if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
15653018216SPaolo Bonzini         if (!pflash_cfi01_register(OMAP_CS0_BASE, NULL,
15753018216SPaolo Bonzini                                    "omap_sx1.flash0-1", flash_size,
1584be74634SMarkus Armbruster                                    blk_by_legacy_dinfo(dinfo),
159fa1d36dfSMarkus Armbruster                                    sector_size, flash_size / sector_size,
16053018216SPaolo Bonzini                                    4, 0, 0, 0, 0, be)) {
16153018216SPaolo Bonzini             fprintf(stderr, "qemu: Error registering flash memory %d.\n",
16253018216SPaolo Bonzini                            fl_idx);
16353018216SPaolo Bonzini         }
16453018216SPaolo Bonzini         fl_idx++;
16553018216SPaolo Bonzini     }
16653018216SPaolo Bonzini 
16753018216SPaolo Bonzini     if ((version == 1) &&
16853018216SPaolo Bonzini             (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
1699f9b026dSShannon Zhao         MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
17098a99ce0SPeter Maydell         memory_region_init_ram(flash_1, NULL, "omap_sx1.flash1-0",
17198a99ce0SPeter Maydell                                flash1_size, &error_fatal);
17253018216SPaolo Bonzini         memory_region_set_readonly(flash_1, true);
17353018216SPaolo Bonzini         memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
17453018216SPaolo Bonzini 
1752c9b15caSPaolo Bonzini         memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
17653018216SPaolo Bonzini                               "sx1.cs1", OMAP_CS1_SIZE - flash1_size);
17753018216SPaolo Bonzini         memory_region_add_subregion(address_space,
17853018216SPaolo Bonzini                                 OMAP_CS1_BASE + flash1_size, &cs[1]);
17953018216SPaolo Bonzini 
18053018216SPaolo Bonzini         if (!pflash_cfi01_register(OMAP_CS1_BASE, NULL,
18153018216SPaolo Bonzini                                    "omap_sx1.flash1-1", flash1_size,
1824be74634SMarkus Armbruster                                    blk_by_legacy_dinfo(dinfo),
183fa1d36dfSMarkus Armbruster                                    sector_size, flash1_size / sector_size,
18453018216SPaolo Bonzini                                    4, 0, 0, 0, 0, be)) {
18553018216SPaolo Bonzini             fprintf(stderr, "qemu: Error registering flash memory %d.\n",
18653018216SPaolo Bonzini                            fl_idx);
18753018216SPaolo Bonzini         }
18853018216SPaolo Bonzini         fl_idx++;
18953018216SPaolo Bonzini     } else {
1902c9b15caSPaolo Bonzini         memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
19153018216SPaolo Bonzini                               "sx1.cs1", OMAP_CS1_SIZE);
19253018216SPaolo Bonzini         memory_region_add_subregion(address_space,
19353018216SPaolo Bonzini                                 OMAP_CS1_BASE, &cs[1]);
19453018216SPaolo Bonzini     }
19553018216SPaolo Bonzini 
1963ef96221SMarcel Apfelbaum     if (!machine->kernel_filename && !fl_idx && !qtest_enabled()) {
19753018216SPaolo Bonzini         fprintf(stderr, "Kernel or Flash image must be specified\n");
19853018216SPaolo Bonzini         exit(1);
19953018216SPaolo Bonzini     }
20053018216SPaolo Bonzini 
20153018216SPaolo Bonzini     /* Load the kernel.  */
2023ef96221SMarcel Apfelbaum     sx1_binfo.kernel_filename = machine->kernel_filename;
2033ef96221SMarcel Apfelbaum     sx1_binfo.kernel_cmdline = machine->kernel_cmdline;
2043ef96221SMarcel Apfelbaum     sx1_binfo.initrd_filename = machine->initrd_filename;
20553018216SPaolo Bonzini     arm_load_kernel(mpu->cpu, &sx1_binfo);
20653018216SPaolo Bonzini 
20753018216SPaolo Bonzini     /* TODO: fix next line */
20853018216SPaolo Bonzini     //~ qemu_console_resize(ds, 640, 480);
20953018216SPaolo Bonzini }
21053018216SPaolo Bonzini 
2113ef96221SMarcel Apfelbaum static void sx1_init_v1(MachineState *machine)
21253018216SPaolo Bonzini {
2133ef96221SMarcel Apfelbaum     sx1_init(machine, 1);
21453018216SPaolo Bonzini }
21553018216SPaolo Bonzini 
2163ef96221SMarcel Apfelbaum static void sx1_init_v2(MachineState *machine)
21753018216SPaolo Bonzini {
2183ef96221SMarcel Apfelbaum     sx1_init(machine, 2);
21953018216SPaolo Bonzini }
22053018216SPaolo Bonzini 
2218a661aeaSAndreas Färber static void sx1_machine_v2_class_init(ObjectClass *oc, void *data)
22253018216SPaolo Bonzini {
2238a661aeaSAndreas Färber     MachineClass *mc = MACHINE_CLASS(oc);
2248a661aeaSAndreas Färber 
225e264d29dSEduardo Habkost     mc->desc = "Siemens SX1 (OMAP310) V2";
226e264d29dSEduardo Habkost     mc->init = sx1_init_v2;
2274672cbd7SPeter Maydell     mc->ignore_memory_transaction_failures = true;
228*ba1ba5ccSIgor Mammedov     mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t");
22953018216SPaolo Bonzini }
23053018216SPaolo Bonzini 
2318a661aeaSAndreas Färber static const TypeInfo sx1_machine_v2_type = {
2328a661aeaSAndreas Färber     .name = MACHINE_TYPE_NAME("sx1"),
2338a661aeaSAndreas Färber     .parent = TYPE_MACHINE,
2348a661aeaSAndreas Färber     .class_init = sx1_machine_v2_class_init,
2358a661aeaSAndreas Färber };
236e264d29dSEduardo Habkost 
2378a661aeaSAndreas Färber static void sx1_machine_v1_class_init(ObjectClass *oc, void *data)
238e264d29dSEduardo Habkost {
2398a661aeaSAndreas Färber     MachineClass *mc = MACHINE_CLASS(oc);
2408a661aeaSAndreas Färber 
241e264d29dSEduardo Habkost     mc->desc = "Siemens SX1 (OMAP310) V1";
242e264d29dSEduardo Habkost     mc->init = sx1_init_v1;
2434672cbd7SPeter Maydell     mc->ignore_memory_transaction_failures = true;
244*ba1ba5ccSIgor Mammedov     mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t");
245e264d29dSEduardo Habkost }
246e264d29dSEduardo Habkost 
2478a661aeaSAndreas Färber static const TypeInfo sx1_machine_v1_type = {
2488a661aeaSAndreas Färber     .name = MACHINE_TYPE_NAME("sx1-v1"),
2498a661aeaSAndreas Färber     .parent = TYPE_MACHINE,
2508a661aeaSAndreas Färber     .class_init = sx1_machine_v1_class_init,
2518a661aeaSAndreas Färber };
2528a661aeaSAndreas Färber 
2538a661aeaSAndreas Färber static void sx1_machine_init(void)
2548a661aeaSAndreas Färber {
2558a661aeaSAndreas Färber     type_register_static(&sx1_machine_v1_type);
2568a661aeaSAndreas Färber     type_register_static(&sx1_machine_v2_type);
2578a661aeaSAndreas Färber }
2588a661aeaSAndreas Färber 
2590e6aac87SEduardo Habkost type_init(sx1_machine_init)
260