xref: /openbmc/qemu/hw/arm/omap_sx1.c (revision 7a1dc45af581d2b643cdbf33c01fd96271616fbd)
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"
29d7f1bd19SPhilippe Mathieu-Daudé #include "qemu/units.h"
30da34e65cSMarkus Armbruster #include "qapi/error.h"
3153018216SPaolo Bonzini #include "ui/console.h"
320d09e41aSPaolo Bonzini #include "hw/arm/omap.h"
3353018216SPaolo Bonzini #include "hw/boards.h"
3412ec8bd5SPeter Maydell #include "hw/arm/boot.h"
350d09e41aSPaolo Bonzini #include "hw/block/flash.h"
36db3fd069SAndreas Färber #include "sysemu/qtest.h"
3753018216SPaolo Bonzini #include "exec/address-spaces.h"
38238ea0e3SIgor Mammedov #include "qemu/cutils.h"
39*cc37d98bSRichard Henderson #include "qemu/error-report.h"
40*cc37d98bSRichard Henderson 
4153018216SPaolo Bonzini 
4253018216SPaolo Bonzini /*****************************************************************************/
4353018216SPaolo Bonzini /* Siemens SX1 Cellphone V1 */
4453018216SPaolo Bonzini /* - ARM OMAP310 processor
4553018216SPaolo Bonzini  * - SRAM                192 kB
4653018216SPaolo Bonzini  * - SDRAM                32 MB at 0x10000000
4753018216SPaolo Bonzini  * - Boot flash           16 MB at 0x00000000
4853018216SPaolo Bonzini  * - Application flash     8 MB at 0x04000000
4953018216SPaolo Bonzini  * - 3 serial ports
5053018216SPaolo Bonzini  * - 1 SecureDigital
5153018216SPaolo Bonzini  * - 1 LCD display
5253018216SPaolo Bonzini  * - 1 RTC
5353018216SPaolo Bonzini  */
5453018216SPaolo Bonzini 
5553018216SPaolo Bonzini /*****************************************************************************/
5653018216SPaolo Bonzini /* Siemens SX1 Cellphone V2 */
5753018216SPaolo Bonzini /* - ARM OMAP310 processor
5853018216SPaolo Bonzini  * - SRAM                192 kB
5953018216SPaolo Bonzini  * - SDRAM                32 MB at 0x10000000
6053018216SPaolo Bonzini  * - Boot flash           32 MB at 0x00000000
6153018216SPaolo Bonzini  * - 3 serial ports
6253018216SPaolo Bonzini  * - 1 SecureDigital
6353018216SPaolo Bonzini  * - 1 LCD display
6453018216SPaolo Bonzini  * - 1 RTC
6553018216SPaolo Bonzini  */
6653018216SPaolo Bonzini 
static_read(void * opaque,hwaddr offset,unsigned size)6753018216SPaolo Bonzini static uint64_t static_read(void *opaque, hwaddr offset,
6853018216SPaolo Bonzini                             unsigned size)
6953018216SPaolo Bonzini {
70a75ed3c4SPhilippe Mathieu-Daudé     uint32_t *val = opaque;
7153018216SPaolo Bonzini     uint32_t mask = (4 / size) - 1;
7253018216SPaolo Bonzini 
7353018216SPaolo Bonzini     return *val >> ((offset & mask) << 3);
7453018216SPaolo Bonzini }
7553018216SPaolo Bonzini 
static_write(void * opaque,hwaddr offset,uint64_t value,unsigned size)7653018216SPaolo Bonzini static void static_write(void *opaque, hwaddr offset,
7753018216SPaolo Bonzini                          uint64_t value, unsigned size)
7853018216SPaolo Bonzini {
7953018216SPaolo Bonzini #ifdef SPY
8053018216SPaolo Bonzini     printf("%s: value %" PRIx64 " %u bytes written at 0x%x\n",
8153018216SPaolo Bonzini                     __func__, value, size, (int)offset);
8253018216SPaolo Bonzini #endif
8353018216SPaolo Bonzini }
8453018216SPaolo Bonzini 
8553018216SPaolo Bonzini static const MemoryRegionOps static_ops = {
8653018216SPaolo Bonzini     .read = static_read,
8753018216SPaolo Bonzini     .write = static_write,
8853018216SPaolo Bonzini     .endianness = DEVICE_NATIVE_ENDIAN,
8953018216SPaolo Bonzini };
9053018216SPaolo Bonzini 
91d7f1bd19SPhilippe Mathieu-Daudé #define SDRAM_SIZE      (32 * MiB)
92d7f1bd19SPhilippe Mathieu-Daudé #define SECTOR_SIZE     (128 * KiB)
93d7f1bd19SPhilippe Mathieu-Daudé #define FLASH0_SIZE     (16 * MiB)
94d7f1bd19SPhilippe Mathieu-Daudé #define FLASH1_SIZE     (8 * MiB)
95d7f1bd19SPhilippe Mathieu-Daudé #define FLASH2_SIZE     (32 * MiB)
9653018216SPaolo Bonzini 
9753018216SPaolo Bonzini static struct arm_boot_info sx1_binfo = {
9853018216SPaolo Bonzini     .loader_start = OMAP_EMIFF_BASE,
99d7f1bd19SPhilippe Mathieu-Daudé     .ram_size = SDRAM_SIZE,
10053018216SPaolo Bonzini     .board_id = 0x265,
10153018216SPaolo Bonzini };
10253018216SPaolo Bonzini 
sx1_init(MachineState * machine,const int version)1033ef96221SMarcel Apfelbaum static void sx1_init(MachineState *machine, const int version)
10453018216SPaolo Bonzini {
10553018216SPaolo Bonzini     struct omap_mpu_state_s *mpu;
106238ea0e3SIgor Mammedov     MachineClass *mc = MACHINE_GET_CLASS(machine);
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;
116d7f1bd19SPhilippe Mathieu-Daudé     uint32_t flash_size = FLASH0_SIZE;
11753018216SPaolo Bonzini 
118238ea0e3SIgor Mammedov     if (machine->ram_size != mc->default_ram_size) {
119238ea0e3SIgor Mammedov         char *sz = size_to_str(mc->default_ram_size);
120238ea0e3SIgor Mammedov         error_report("Invalid RAM size, should be %s", sz);
121238ea0e3SIgor Mammedov         g_free(sz);
122238ea0e3SIgor Mammedov         exit(EXIT_FAILURE);
123238ea0e3SIgor Mammedov     }
124238ea0e3SIgor Mammedov 
12553018216SPaolo Bonzini     if (version == 2) {
126d7f1bd19SPhilippe Mathieu-Daudé         flash_size = FLASH2_SIZE;
12753018216SPaolo Bonzini     }
12853018216SPaolo Bonzini 
129238ea0e3SIgor Mammedov     memory_region_add_subregion(address_space, OMAP_EMIFF_BASE, machine->ram);
1304387b253SPhilippe Mathieu-Daudé 
131238ea0e3SIgor Mammedov     mpu = omap310_mpu_init(machine->ram, machine->cpu_type);
13253018216SPaolo Bonzini 
13353018216SPaolo Bonzini     /* External Flash (EMIFS) */
13416260006SPhilippe Mathieu-Daudé     memory_region_init_rom(flash, NULL, "omap_sx1.flash0-0", flash_size,
135f8ed85acSMarkus Armbruster                            &error_fatal);
13653018216SPaolo Bonzini     memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
13753018216SPaolo Bonzini 
1382c9b15caSPaolo Bonzini     memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
13953018216SPaolo Bonzini                           "sx1.cs0", OMAP_CS0_SIZE - flash_size);
14053018216SPaolo Bonzini     memory_region_add_subregion(address_space,
14153018216SPaolo Bonzini                                 OMAP_CS0_BASE + flash_size, &cs[0]);
14253018216SPaolo Bonzini 
14353018216SPaolo Bonzini 
1442c9b15caSPaolo Bonzini     memory_region_init_io(&cs[2], NULL, &static_ops, &cs2val,
14553018216SPaolo Bonzini                           "sx1.cs2", OMAP_CS2_SIZE);
14653018216SPaolo Bonzini     memory_region_add_subregion(address_space,
14753018216SPaolo Bonzini                                 OMAP_CS2_BASE, &cs[2]);
14853018216SPaolo Bonzini 
1492c9b15caSPaolo Bonzini     memory_region_init_io(&cs[3], NULL, &static_ops, &cs3val,
15053018216SPaolo Bonzini                           "sx1.cs3", OMAP_CS3_SIZE);
15153018216SPaolo Bonzini     memory_region_add_subregion(address_space,
15253018216SPaolo Bonzini                                 OMAP_CS2_BASE, &cs[3]);
15353018216SPaolo Bonzini 
15453018216SPaolo Bonzini     fl_idx = 0;
15553018216SPaolo Bonzini     if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
15620f82226SPhilippe Mathieu-Daudé         pflash_cfi01_register(OMAP_CS0_BASE,
15753018216SPaolo Bonzini                               "omap_sx1.flash0-1", flash_size,
1584be74634SMarkus Armbruster                               blk_by_legacy_dinfo(dinfo),
15920f82226SPhilippe Mathieu-Daudé                               SECTOR_SIZE, 4, 0, 0, 0, 0, 0);
16053018216SPaolo Bonzini         fl_idx++;
16153018216SPaolo Bonzini     }
16253018216SPaolo Bonzini 
16353018216SPaolo Bonzini     if ((version == 1) &&
16453018216SPaolo Bonzini             (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
1659f9b026dSShannon Zhao         MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
16616260006SPhilippe Mathieu-Daudé         memory_region_init_rom(flash_1, NULL, "omap_sx1.flash1-0",
167d7f1bd19SPhilippe Mathieu-Daudé                                FLASH1_SIZE, &error_fatal);
16853018216SPaolo Bonzini         memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
16953018216SPaolo Bonzini 
1702c9b15caSPaolo Bonzini         memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
171d7f1bd19SPhilippe Mathieu-Daudé                               "sx1.cs1", OMAP_CS1_SIZE - FLASH1_SIZE);
17253018216SPaolo Bonzini         memory_region_add_subregion(address_space,
173d7f1bd19SPhilippe Mathieu-Daudé                                 OMAP_CS1_BASE + FLASH1_SIZE, &cs[1]);
17453018216SPaolo Bonzini 
17520f82226SPhilippe Mathieu-Daudé         pflash_cfi01_register(OMAP_CS1_BASE,
176d7f1bd19SPhilippe Mathieu-Daudé                               "omap_sx1.flash1-1", FLASH1_SIZE,
1774be74634SMarkus Armbruster                               blk_by_legacy_dinfo(dinfo),
17820f82226SPhilippe Mathieu-Daudé                               SECTOR_SIZE, 4, 0, 0, 0, 0, 0);
17953018216SPaolo Bonzini         fl_idx++;
18053018216SPaolo Bonzini     } else {
1812c9b15caSPaolo Bonzini         memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
18253018216SPaolo Bonzini                               "sx1.cs1", OMAP_CS1_SIZE);
18353018216SPaolo Bonzini         memory_region_add_subregion(address_space,
18453018216SPaolo Bonzini                                 OMAP_CS1_BASE, &cs[1]);
18553018216SPaolo Bonzini     }
18653018216SPaolo Bonzini 
1873ef96221SMarcel Apfelbaum     if (!machine->kernel_filename && !fl_idx && !qtest_enabled()) {
188c0dbca36SAlistair Francis         error_report("Kernel or Flash image must be specified");
18953018216SPaolo Bonzini         exit(1);
19053018216SPaolo Bonzini     }
19153018216SPaolo Bonzini 
19253018216SPaolo Bonzini     /* Load the kernel.  */
1932744ece8STao Xu     arm_load_kernel(mpu->cpu, machine, &sx1_binfo);
19453018216SPaolo Bonzini 
19553018216SPaolo Bonzini     /* TODO: fix next line */
19653018216SPaolo Bonzini     //~ qemu_console_resize(ds, 640, 480);
19753018216SPaolo Bonzini }
19853018216SPaolo Bonzini 
sx1_init_v1(MachineState * machine)1993ef96221SMarcel Apfelbaum static void sx1_init_v1(MachineState *machine)
20053018216SPaolo Bonzini {
2013ef96221SMarcel Apfelbaum     sx1_init(machine, 1);
20253018216SPaolo Bonzini }
20353018216SPaolo Bonzini 
sx1_init_v2(MachineState * machine)2043ef96221SMarcel Apfelbaum static void sx1_init_v2(MachineState *machine)
20553018216SPaolo Bonzini {
2063ef96221SMarcel Apfelbaum     sx1_init(machine, 2);
20753018216SPaolo Bonzini }
20853018216SPaolo Bonzini 
sx1_machine_v2_class_init(ObjectClass * oc,void * data)2098a661aeaSAndreas Färber static void sx1_machine_v2_class_init(ObjectClass *oc, void *data)
21053018216SPaolo Bonzini {
2118a661aeaSAndreas Färber     MachineClass *mc = MACHINE_CLASS(oc);
2128a661aeaSAndreas Färber 
213e264d29dSEduardo Habkost     mc->desc = "Siemens SX1 (OMAP310) V2";
214e264d29dSEduardo Habkost     mc->init = sx1_init_v2;
2154672cbd7SPeter Maydell     mc->ignore_memory_transaction_failures = true;
216ba1ba5ccSIgor Mammedov     mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t");
217d7f1bd19SPhilippe Mathieu-Daudé     mc->default_ram_size = SDRAM_SIZE;
218238ea0e3SIgor Mammedov     mc->default_ram_id = "omap1.dram";
21953018216SPaolo Bonzini }
22053018216SPaolo Bonzini 
2218a661aeaSAndreas Färber static const TypeInfo sx1_machine_v2_type = {
2228a661aeaSAndreas Färber     .name = MACHINE_TYPE_NAME("sx1"),
2238a661aeaSAndreas Färber     .parent = TYPE_MACHINE,
2248a661aeaSAndreas Färber     .class_init = sx1_machine_v2_class_init,
2258a661aeaSAndreas Färber };
226e264d29dSEduardo Habkost 
sx1_machine_v1_class_init(ObjectClass * oc,void * data)2278a661aeaSAndreas Färber static void sx1_machine_v1_class_init(ObjectClass *oc, void *data)
228e264d29dSEduardo Habkost {
2298a661aeaSAndreas Färber     MachineClass *mc = MACHINE_CLASS(oc);
2308a661aeaSAndreas Färber 
231e264d29dSEduardo Habkost     mc->desc = "Siemens SX1 (OMAP310) V1";
232e264d29dSEduardo Habkost     mc->init = sx1_init_v1;
2334672cbd7SPeter Maydell     mc->ignore_memory_transaction_failures = true;
234ba1ba5ccSIgor Mammedov     mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t");
235d7f1bd19SPhilippe Mathieu-Daudé     mc->default_ram_size = SDRAM_SIZE;
236238ea0e3SIgor Mammedov     mc->default_ram_id = "omap1.dram";
237e264d29dSEduardo Habkost }
238e264d29dSEduardo Habkost 
2398a661aeaSAndreas Färber static const TypeInfo sx1_machine_v1_type = {
2408a661aeaSAndreas Färber     .name = MACHINE_TYPE_NAME("sx1-v1"),
2418a661aeaSAndreas Färber     .parent = TYPE_MACHINE,
2428a661aeaSAndreas Färber     .class_init = sx1_machine_v1_class_init,
2438a661aeaSAndreas Färber };
2448a661aeaSAndreas Färber 
sx1_machine_init(void)2458a661aeaSAndreas Färber static void sx1_machine_init(void)
2468a661aeaSAndreas Färber {
2478a661aeaSAndreas Färber     type_register_static(&sx1_machine_v1_type);
2488a661aeaSAndreas Färber     type_register_static(&sx1_machine_v2_type);
2498a661aeaSAndreas Färber }
2508a661aeaSAndreas Färber 
2510e6aac87SEduardo Habkost type_init(sx1_machine_init)
252