1997641a8Sbalrog /* omap_sx1.c Support for the Siemens SX1 smartphone emulation. 2997641a8Sbalrog * 3997641a8Sbalrog * Copyright (C) 2008 4997641a8Sbalrog * Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> 5997641a8Sbalrog * Copyright (C) 2007 Vladimir Ananiev <vovan888@gmail.com> 6997641a8Sbalrog * 7997641a8Sbalrog * based on PalmOne's (TM) PDAs support (palm.c) 8997641a8Sbalrog */ 9997641a8Sbalrog 10997641a8Sbalrog /* 11997641a8Sbalrog * PalmOne's (TM) PDAs. 12997641a8Sbalrog * 13997641a8Sbalrog * Copyright (C) 2006-2007 Andrzej Zaborowski <balrog@zabor.org> 14997641a8Sbalrog * 15997641a8Sbalrog * This program is free software; you can redistribute it and/or 16997641a8Sbalrog * modify it under the terms of the GNU General Public License as 17997641a8Sbalrog * published by the Free Software Foundation; either version 2 of 18997641a8Sbalrog * the License, or (at your option) any later version. 19997641a8Sbalrog * 20997641a8Sbalrog * This program is distributed in the hope that it will be useful, 21997641a8Sbalrog * but WITHOUT ANY WARRANTY; without even the implied warranty of 22997641a8Sbalrog * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23997641a8Sbalrog * GNU General Public License for more details. 24997641a8Sbalrog * 25fad6cb1aSaurel32 * You should have received a copy of the GNU General Public License along 268167ee88SBlue Swirl * with this program; if not, see <http://www.gnu.org/licenses/>. 27997641a8Sbalrog */ 2812b16722SPeter Maydell #include "qemu/osdep.h" 29*d7f1bd19SPhilippe Mathieu-Daudé #include "qemu/units.h" 30da34e65cSMarkus Armbruster #include "qapi/error.h" 3128ecbaeeSPaolo Bonzini #include "ui/console.h" 320d09e41aSPaolo Bonzini #include "hw/arm/omap.h" 3383c9f4caSPaolo 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" 37022c62cbSPaolo Bonzini #include "exec/address-spaces.h" 38ba1ba5ccSIgor Mammedov #include "cpu.h" 39238ea0e3SIgor Mammedov #include "qemu/cutils.h" 40997641a8Sbalrog 41997641a8Sbalrog /*****************************************************************************/ 42997641a8Sbalrog /* Siemens SX1 Cellphone V1 */ 43997641a8Sbalrog /* - ARM OMAP310 processor 44997641a8Sbalrog * - SRAM 192 kB 45997641a8Sbalrog * - SDRAM 32 MB at 0x10000000 46997641a8Sbalrog * - Boot flash 16 MB at 0x00000000 47997641a8Sbalrog * - Application flash 8 MB at 0x04000000 48997641a8Sbalrog * - 3 serial ports 49997641a8Sbalrog * - 1 SecureDigital 50997641a8Sbalrog * - 1 LCD display 51997641a8Sbalrog * - 1 RTC 52997641a8Sbalrog */ 53997641a8Sbalrog 54997641a8Sbalrog /*****************************************************************************/ 55997641a8Sbalrog /* Siemens SX1 Cellphone V2 */ 56997641a8Sbalrog /* - ARM OMAP310 processor 57997641a8Sbalrog * - SRAM 192 kB 58997641a8Sbalrog * - SDRAM 32 MB at 0x10000000 59997641a8Sbalrog * - Boot flash 32 MB at 0x00000000 60997641a8Sbalrog * - 3 serial ports 61997641a8Sbalrog * - 1 SecureDigital 62997641a8Sbalrog * - 1 LCD display 63997641a8Sbalrog * - 1 RTC 64997641a8Sbalrog */ 65997641a8Sbalrog 66a8170e5eSAvi Kivity static uint64_t static_read(void *opaque, hwaddr offset, 67ba158029SBenoît Canet unsigned size) 68997641a8Sbalrog { 69997641a8Sbalrog uint32_t *val = (uint32_t *) opaque; 70ba158029SBenoît Canet uint32_t mask = (4 / size) - 1; 71997641a8Sbalrog 72ba158029SBenoît Canet return *val >> ((offset & mask) << 3); 73997641a8Sbalrog } 74997641a8Sbalrog 75a8170e5eSAvi Kivity static void static_write(void *opaque, hwaddr offset, 76ba158029SBenoît Canet uint64_t value, unsigned size) 77997641a8Sbalrog { 78997641a8Sbalrog #ifdef SPY 79ba158029SBenoît Canet printf("%s: value %" PRIx64 " %u bytes written at 0x%x\n", 80ba158029SBenoît Canet __func__, value, size, (int)offset); 81997641a8Sbalrog #endif 82997641a8Sbalrog } 83997641a8Sbalrog 84ba158029SBenoît Canet static const MemoryRegionOps static_ops = { 85ba158029SBenoît Canet .read = static_read, 86ba158029SBenoît Canet .write = static_write, 87ba158029SBenoît Canet .endianness = DEVICE_NATIVE_ENDIAN, 88997641a8Sbalrog }; 89997641a8Sbalrog 90*d7f1bd19SPhilippe Mathieu-Daudé #define SDRAM_SIZE (32 * MiB) 91*d7f1bd19SPhilippe Mathieu-Daudé #define SECTOR_SIZE (128 * KiB) 92*d7f1bd19SPhilippe Mathieu-Daudé #define FLASH0_SIZE (16 * MiB) 93*d7f1bd19SPhilippe Mathieu-Daudé #define FLASH1_SIZE (8 * MiB) 94*d7f1bd19SPhilippe Mathieu-Daudé #define FLASH2_SIZE (32 * MiB) 95997641a8Sbalrog 96997641a8Sbalrog static struct arm_boot_info sx1_binfo = { 97997641a8Sbalrog .loader_start = OMAP_EMIFF_BASE, 98*d7f1bd19SPhilippe Mathieu-Daudé .ram_size = SDRAM_SIZE, 99997641a8Sbalrog .board_id = 0x265, 100997641a8Sbalrog }; 101997641a8Sbalrog 1023ef96221SMarcel Apfelbaum static void sx1_init(MachineState *machine, const int version) 103997641a8Sbalrog { 10459b91996SAndreas Färber struct omap_mpu_state_s *mpu; 105238ea0e3SIgor Mammedov MachineClass *mc = MACHINE_GET_CLASS(machine); 1064b3fedf3SAvi Kivity MemoryRegion *address_space = get_system_memory(); 107ba158029SBenoît Canet MemoryRegion *flash = g_new(MemoryRegion, 1); 108ba158029SBenoît Canet MemoryRegion *cs = g_new(MemoryRegion, 4); 109997641a8Sbalrog static uint32_t cs0val = 0x00213090; 110997641a8Sbalrog static uint32_t cs1val = 0x00215070; 111997641a8Sbalrog static uint32_t cs2val = 0x00001139; 112997641a8Sbalrog static uint32_t cs3val = 0x00001139; 113751c6a17SGerd Hoffmann DriveInfo *dinfo; 114997641a8Sbalrog int fl_idx; 115*d7f1bd19SPhilippe Mathieu-Daudé uint32_t flash_size = FLASH0_SIZE; 116997641a8Sbalrog 117238ea0e3SIgor Mammedov if (machine->ram_size != mc->default_ram_size) { 118238ea0e3SIgor Mammedov char *sz = size_to_str(mc->default_ram_size); 119238ea0e3SIgor Mammedov error_report("Invalid RAM size, should be %s", sz); 120238ea0e3SIgor Mammedov g_free(sz); 121238ea0e3SIgor Mammedov exit(EXIT_FAILURE); 122238ea0e3SIgor Mammedov } 123238ea0e3SIgor Mammedov 124997641a8Sbalrog if (version == 2) { 125*d7f1bd19SPhilippe Mathieu-Daudé flash_size = FLASH2_SIZE; 126997641a8Sbalrog } 127997641a8Sbalrog 128238ea0e3SIgor Mammedov memory_region_add_subregion(address_space, OMAP_EMIFF_BASE, machine->ram); 1294387b253SPhilippe Mathieu-Daudé 130238ea0e3SIgor Mammedov mpu = omap310_mpu_init(machine->ram, machine->cpu_type); 131997641a8Sbalrog 132997641a8Sbalrog /* External Flash (EMIFS) */ 13316260006SPhilippe Mathieu-Daudé memory_region_init_rom(flash, NULL, "omap_sx1.flash0-0", flash_size, 134f8ed85acSMarkus Armbruster &error_fatal); 135ba158029SBenoît Canet memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash); 136997641a8Sbalrog 1372c9b15caSPaolo Bonzini memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val, 138ba158029SBenoît Canet "sx1.cs0", OMAP_CS0_SIZE - flash_size); 139ba158029SBenoît Canet memory_region_add_subregion(address_space, 140ba158029SBenoît Canet OMAP_CS0_BASE + flash_size, &cs[0]); 141ba158029SBenoît Canet 142ba158029SBenoît Canet 1432c9b15caSPaolo Bonzini memory_region_init_io(&cs[2], NULL, &static_ops, &cs2val, 144ba158029SBenoît Canet "sx1.cs2", OMAP_CS2_SIZE); 145ba158029SBenoît Canet memory_region_add_subregion(address_space, 146ba158029SBenoît Canet OMAP_CS2_BASE, &cs[2]); 147ba158029SBenoît Canet 1482c9b15caSPaolo Bonzini memory_region_init_io(&cs[3], NULL, &static_ops, &cs3val, 149ba158029SBenoît Canet "sx1.cs3", OMAP_CS3_SIZE); 150ba158029SBenoît Canet memory_region_add_subregion(address_space, 151ba158029SBenoît Canet OMAP_CS2_BASE, &cs[3]); 152997641a8Sbalrog 153997641a8Sbalrog fl_idx = 0; 154751c6a17SGerd Hoffmann if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) { 155940d5b13SMarkus Armbruster if (!pflash_cfi01_register(OMAP_CS0_BASE, 156cfe5f011SAvi Kivity "omap_sx1.flash0-1", flash_size, 1574be74634SMarkus Armbruster blk_by_legacy_dinfo(dinfo), 158*d7f1bd19SPhilippe Mathieu-Daudé SECTOR_SIZE, 4, 0, 0, 0, 0, 0)) { 159997641a8Sbalrog fprintf(stderr, "qemu: Error registering flash memory %d.\n", 160997641a8Sbalrog fl_idx); 161997641a8Sbalrog } 162997641a8Sbalrog fl_idx++; 163997641a8Sbalrog } 164997641a8Sbalrog 165997641a8Sbalrog if ((version == 1) && 166751c6a17SGerd Hoffmann (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) { 1679f9b026dSShannon Zhao MemoryRegion *flash_1 = g_new(MemoryRegion, 1); 16816260006SPhilippe Mathieu-Daudé memory_region_init_rom(flash_1, NULL, "omap_sx1.flash1-0", 169*d7f1bd19SPhilippe Mathieu-Daudé FLASH1_SIZE, &error_fatal); 170ba158029SBenoît Canet memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1); 171ba158029SBenoît Canet 1722c9b15caSPaolo Bonzini memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val, 173*d7f1bd19SPhilippe Mathieu-Daudé "sx1.cs1", OMAP_CS1_SIZE - FLASH1_SIZE); 174ba158029SBenoît Canet memory_region_add_subregion(address_space, 175*d7f1bd19SPhilippe Mathieu-Daudé OMAP_CS1_BASE + FLASH1_SIZE, &cs[1]); 176997641a8Sbalrog 177940d5b13SMarkus Armbruster if (!pflash_cfi01_register(OMAP_CS1_BASE, 178*d7f1bd19SPhilippe Mathieu-Daudé "omap_sx1.flash1-1", FLASH1_SIZE, 1794be74634SMarkus Armbruster blk_by_legacy_dinfo(dinfo), 180*d7f1bd19SPhilippe Mathieu-Daudé SECTOR_SIZE, 4, 0, 0, 0, 0, 0)) { 181997641a8Sbalrog fprintf(stderr, "qemu: Error registering flash memory %d.\n", 182997641a8Sbalrog fl_idx); 183997641a8Sbalrog } 184997641a8Sbalrog fl_idx++; 185997641a8Sbalrog } else { 1862c9b15caSPaolo Bonzini memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val, 187ba158029SBenoît Canet "sx1.cs1", OMAP_CS1_SIZE); 188ba158029SBenoît Canet memory_region_add_subregion(address_space, 189ba158029SBenoît Canet OMAP_CS1_BASE, &cs[1]); 190997641a8Sbalrog } 191997641a8Sbalrog 1923ef96221SMarcel Apfelbaum if (!machine->kernel_filename && !fl_idx && !qtest_enabled()) { 193c0dbca36SAlistair Francis error_report("Kernel or Flash image must be specified"); 194997641a8Sbalrog exit(1); 195997641a8Sbalrog } 196997641a8Sbalrog 197997641a8Sbalrog /* Load the kernel. */ 1982744ece8STao Xu arm_load_kernel(mpu->cpu, machine, &sx1_binfo); 199997641a8Sbalrog 2005f70aab1Saurel32 /* TODO: fix next line */ 2015f70aab1Saurel32 //~ qemu_console_resize(ds, 640, 480); 202997641a8Sbalrog } 203997641a8Sbalrog 2043ef96221SMarcel Apfelbaum static void sx1_init_v1(MachineState *machine) 205997641a8Sbalrog { 2063ef96221SMarcel Apfelbaum sx1_init(machine, 1); 207997641a8Sbalrog } 208997641a8Sbalrog 2093ef96221SMarcel Apfelbaum static void sx1_init_v2(MachineState *machine) 210997641a8Sbalrog { 2113ef96221SMarcel Apfelbaum sx1_init(machine, 2); 212997641a8Sbalrog } 213997641a8Sbalrog 2148a661aeaSAndreas Färber static void sx1_machine_v2_class_init(ObjectClass *oc, void *data) 215f80f9ec9SAnthony Liguori { 2168a661aeaSAndreas Färber MachineClass *mc = MACHINE_CLASS(oc); 2178a661aeaSAndreas Färber 218e264d29dSEduardo Habkost mc->desc = "Siemens SX1 (OMAP310) V2"; 219e264d29dSEduardo Habkost mc->init = sx1_init_v2; 2204672cbd7SPeter Maydell mc->ignore_memory_transaction_failures = true; 221ba1ba5ccSIgor Mammedov mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t"); 222*d7f1bd19SPhilippe Mathieu-Daudé mc->default_ram_size = SDRAM_SIZE; 223238ea0e3SIgor Mammedov mc->default_ram_id = "omap1.dram"; 224f80f9ec9SAnthony Liguori } 225f80f9ec9SAnthony Liguori 2268a661aeaSAndreas Färber static const TypeInfo sx1_machine_v2_type = { 2278a661aeaSAndreas Färber .name = MACHINE_TYPE_NAME("sx1"), 2288a661aeaSAndreas Färber .parent = TYPE_MACHINE, 2298a661aeaSAndreas Färber .class_init = sx1_machine_v2_class_init, 2308a661aeaSAndreas Färber }; 231e264d29dSEduardo Habkost 2328a661aeaSAndreas Färber static void sx1_machine_v1_class_init(ObjectClass *oc, void *data) 233e264d29dSEduardo Habkost { 2348a661aeaSAndreas Färber MachineClass *mc = MACHINE_CLASS(oc); 2358a661aeaSAndreas Färber 236e264d29dSEduardo Habkost mc->desc = "Siemens SX1 (OMAP310) V1"; 237e264d29dSEduardo Habkost mc->init = sx1_init_v1; 2384672cbd7SPeter Maydell mc->ignore_memory_transaction_failures = true; 239ba1ba5ccSIgor Mammedov mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t"); 240*d7f1bd19SPhilippe Mathieu-Daudé mc->default_ram_size = SDRAM_SIZE; 241238ea0e3SIgor Mammedov mc->default_ram_id = "omap1.dram"; 242e264d29dSEduardo Habkost } 243e264d29dSEduardo Habkost 2448a661aeaSAndreas Färber static const TypeInfo sx1_machine_v1_type = { 2458a661aeaSAndreas Färber .name = MACHINE_TYPE_NAME("sx1-v1"), 2468a661aeaSAndreas Färber .parent = TYPE_MACHINE, 2478a661aeaSAndreas Färber .class_init = sx1_machine_v1_class_init, 2488a661aeaSAndreas Färber }; 2498a661aeaSAndreas Färber 2508a661aeaSAndreas Färber static void sx1_machine_init(void) 2518a661aeaSAndreas Färber { 2528a661aeaSAndreas Färber type_register_static(&sx1_machine_v1_type); 2538a661aeaSAndreas Färber type_register_static(&sx1_machine_v2_type); 2548a661aeaSAndreas Färber } 2558a661aeaSAndreas Färber 2560e6aac87SEduardo Habkost type_init(sx1_machine_init) 257