omap_sx1.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /* omap_sx1.c Support for the Siemens SX1 smartphone emulation.
  2. *
  3. * Copyright (C) 2008
  4. * Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  5. * Copyright (C) 2007 Vladimir Ananiev <vovan888@gmail.com>
  6. *
  7. * based on PalmOne's (TM) PDAs support (palm.c)
  8. */
  9. /*
  10. * PalmOne's (TM) PDAs.
  11. *
  12. * Copyright (C) 2006-2007 Andrzej Zaborowski <balrog@zabor.org>
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License along
  25. * with this program; if not, see <http://www.gnu.org/licenses/>.
  26. */
  27. #include "qemu/osdep.h"
  28. #include "qemu/units.h"
  29. #include "qapi/error.h"
  30. #include "ui/console.h"
  31. #include "hw/arm/omap.h"
  32. #include "hw/boards.h"
  33. #include "hw/arm/boot.h"
  34. #include "hw/block/flash.h"
  35. #include "system/qtest.h"
  36. #include "exec/address-spaces.h"
  37. #include "qemu/cutils.h"
  38. #include "qemu/error-report.h"
  39. /*****************************************************************************/
  40. /* Siemens SX1 Cellphone V1 */
  41. /* - ARM OMAP310 processor
  42. * - SRAM 192 kB
  43. * - SDRAM 32 MB at 0x10000000
  44. * - Boot flash 16 MB at 0x00000000
  45. * - Application flash 8 MB at 0x04000000
  46. * - 3 serial ports
  47. * - 1 SecureDigital
  48. * - 1 LCD display
  49. * - 1 RTC
  50. */
  51. /*****************************************************************************/
  52. /* Siemens SX1 Cellphone V2 */
  53. /* - ARM OMAP310 processor
  54. * - SRAM 192 kB
  55. * - SDRAM 32 MB at 0x10000000
  56. * - Boot flash 32 MB at 0x00000000
  57. * - 3 serial ports
  58. * - 1 SecureDigital
  59. * - 1 LCD display
  60. * - 1 RTC
  61. */
  62. static uint64_t static_read(void *opaque, hwaddr offset,
  63. unsigned size)
  64. {
  65. uint32_t *val = opaque;
  66. uint32_t mask = (4 / size) - 1;
  67. return *val >> ((offset & mask) << 3);
  68. }
  69. static void static_write(void *opaque, hwaddr offset,
  70. uint64_t value, unsigned size)
  71. {
  72. }
  73. static const MemoryRegionOps static_ops = {
  74. .read = static_read,
  75. .write = static_write,
  76. .endianness = DEVICE_NATIVE_ENDIAN,
  77. };
  78. #define SDRAM_SIZE (32 * MiB)
  79. #define SECTOR_SIZE (128 * KiB)
  80. #define FLASH0_SIZE (16 * MiB)
  81. #define FLASH1_SIZE (8 * MiB)
  82. #define FLASH2_SIZE (32 * MiB)
  83. static struct arm_boot_info sx1_binfo = {
  84. .loader_start = OMAP_EMIFF_BASE,
  85. .ram_size = SDRAM_SIZE,
  86. .board_id = 0x265,
  87. };
  88. static void sx1_init(MachineState *machine, const int version)
  89. {
  90. struct omap_mpu_state_s *mpu;
  91. MachineClass *mc = MACHINE_GET_CLASS(machine);
  92. MemoryRegion *address_space = get_system_memory();
  93. MemoryRegion *flash = g_new(MemoryRegion, 1);
  94. MemoryRegion *cs = g_new(MemoryRegion, 4);
  95. static uint32_t cs0val = 0x00213090;
  96. static uint32_t cs1val = 0x00215070;
  97. static uint32_t cs2val = 0x00001139;
  98. static uint32_t cs3val = 0x00001139;
  99. DriveInfo *dinfo;
  100. int fl_idx;
  101. uint32_t flash_size = FLASH0_SIZE;
  102. if (machine->ram_size != mc->default_ram_size) {
  103. char *sz = size_to_str(mc->default_ram_size);
  104. error_report("Invalid RAM size, should be %s", sz);
  105. g_free(sz);
  106. exit(EXIT_FAILURE);
  107. }
  108. if (version == 2) {
  109. flash_size = FLASH2_SIZE;
  110. }
  111. memory_region_add_subregion(address_space, OMAP_EMIFF_BASE, machine->ram);
  112. mpu = omap310_mpu_init(machine->ram, machine->cpu_type);
  113. /* External Flash (EMIFS) */
  114. memory_region_init_rom(flash, NULL, "omap_sx1.flash0-0", flash_size,
  115. &error_fatal);
  116. memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
  117. memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
  118. "sx1.cs0", OMAP_CS0_SIZE - flash_size);
  119. memory_region_add_subregion(address_space,
  120. OMAP_CS0_BASE + flash_size, &cs[0]);
  121. memory_region_init_io(&cs[2], NULL, &static_ops, &cs2val,
  122. "sx1.cs2", OMAP_CS2_SIZE);
  123. memory_region_add_subregion(address_space,
  124. OMAP_CS2_BASE, &cs[2]);
  125. memory_region_init_io(&cs[3], NULL, &static_ops, &cs3val,
  126. "sx1.cs3", OMAP_CS3_SIZE);
  127. memory_region_add_subregion(address_space,
  128. OMAP_CS2_BASE, &cs[3]);
  129. fl_idx = 0;
  130. if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
  131. pflash_cfi01_register(OMAP_CS0_BASE,
  132. "omap_sx1.flash0-1", flash_size,
  133. blk_by_legacy_dinfo(dinfo),
  134. SECTOR_SIZE, 4, 0, 0, 0, 0, 0);
  135. fl_idx++;
  136. }
  137. if ((version == 1) &&
  138. (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
  139. MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
  140. memory_region_init_rom(flash_1, NULL, "omap_sx1.flash1-0",
  141. FLASH1_SIZE, &error_fatal);
  142. memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
  143. memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
  144. "sx1.cs1", OMAP_CS1_SIZE - FLASH1_SIZE);
  145. memory_region_add_subregion(address_space,
  146. OMAP_CS1_BASE + FLASH1_SIZE, &cs[1]);
  147. pflash_cfi01_register(OMAP_CS1_BASE,
  148. "omap_sx1.flash1-1", FLASH1_SIZE,
  149. blk_by_legacy_dinfo(dinfo),
  150. SECTOR_SIZE, 4, 0, 0, 0, 0, 0);
  151. fl_idx++;
  152. } else {
  153. memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
  154. "sx1.cs1", OMAP_CS1_SIZE);
  155. memory_region_add_subregion(address_space,
  156. OMAP_CS1_BASE, &cs[1]);
  157. }
  158. if (!machine->kernel_filename && !fl_idx && !qtest_enabled()) {
  159. error_report("Kernel or Flash image must be specified");
  160. exit(1);
  161. }
  162. /* Load the kernel. */
  163. arm_load_kernel(mpu->cpu, machine, &sx1_binfo);
  164. /* TODO: fix next line */
  165. //~ qemu_console_resize(ds, 640, 480);
  166. }
  167. static void sx1_init_v1(MachineState *machine)
  168. {
  169. sx1_init(machine, 1);
  170. }
  171. static void sx1_init_v2(MachineState *machine)
  172. {
  173. sx1_init(machine, 2);
  174. }
  175. static void sx1_machine_v2_class_init(ObjectClass *oc, void *data)
  176. {
  177. MachineClass *mc = MACHINE_CLASS(oc);
  178. mc->desc = "Siemens SX1 (OMAP310) V2";
  179. mc->init = sx1_init_v2;
  180. mc->ignore_memory_transaction_failures = true;
  181. mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t");
  182. mc->default_ram_size = SDRAM_SIZE;
  183. mc->default_ram_id = "omap1.dram";
  184. mc->auto_create_sdcard = true;
  185. }
  186. static const TypeInfo sx1_machine_v2_type = {
  187. .name = MACHINE_TYPE_NAME("sx1"),
  188. .parent = TYPE_MACHINE,
  189. .class_init = sx1_machine_v2_class_init,
  190. };
  191. static void sx1_machine_v1_class_init(ObjectClass *oc, void *data)
  192. {
  193. MachineClass *mc = MACHINE_CLASS(oc);
  194. mc->desc = "Siemens SX1 (OMAP310) V1";
  195. mc->init = sx1_init_v1;
  196. mc->ignore_memory_transaction_failures = true;
  197. mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t");
  198. mc->default_ram_size = SDRAM_SIZE;
  199. mc->default_ram_id = "omap1.dram";
  200. mc->auto_create_sdcard = true;
  201. }
  202. static const TypeInfo sx1_machine_v1_type = {
  203. .name = MACHINE_TYPE_NAME("sx1-v1"),
  204. .parent = TYPE_MACHINE,
  205. .class_init = sx1_machine_v1_class_init,
  206. };
  207. static void sx1_machine_init(void)
  208. {
  209. type_register_static(&sx1_machine_v1_type);
  210. type_register_static(&sx1_machine_v2_type);
  211. }
  212. type_init(sx1_machine_init)