omap_sx1.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 "qapi/error.h"
  29. #include "ui/console.h"
  30. #include "hw/arm/omap.h"
  31. #include "hw/boards.h"
  32. #include "hw/arm/boot.h"
  33. #include "hw/block/flash.h"
  34. #include "sysemu/qtest.h"
  35. #include "exec/address-spaces.h"
  36. #include "cpu.h"
  37. /*****************************************************************************/
  38. /* Siemens SX1 Cellphone V1 */
  39. /* - ARM OMAP310 processor
  40. * - SRAM 192 kB
  41. * - SDRAM 32 MB at 0x10000000
  42. * - Boot flash 16 MB at 0x00000000
  43. * - Application flash 8 MB at 0x04000000
  44. * - 3 serial ports
  45. * - 1 SecureDigital
  46. * - 1 LCD display
  47. * - 1 RTC
  48. */
  49. /*****************************************************************************/
  50. /* Siemens SX1 Cellphone V2 */
  51. /* - ARM OMAP310 processor
  52. * - SRAM 192 kB
  53. * - SDRAM 32 MB at 0x10000000
  54. * - Boot flash 32 MB at 0x00000000
  55. * - 3 serial ports
  56. * - 1 SecureDigital
  57. * - 1 LCD display
  58. * - 1 RTC
  59. */
  60. static uint64_t static_read(void *opaque, hwaddr offset,
  61. unsigned size)
  62. {
  63. uint32_t *val = (uint32_t *) opaque;
  64. uint32_t mask = (4 / size) - 1;
  65. return *val >> ((offset & mask) << 3);
  66. }
  67. static void static_write(void *opaque, hwaddr offset,
  68. uint64_t value, unsigned size)
  69. {
  70. #ifdef SPY
  71. printf("%s: value %" PRIx64 " %u bytes written at 0x%x\n",
  72. __func__, value, size, (int)offset);
  73. #endif
  74. }
  75. static const MemoryRegionOps static_ops = {
  76. .read = static_read,
  77. .write = static_write,
  78. .endianness = DEVICE_NATIVE_ENDIAN,
  79. };
  80. #define sdram_size 0x02000000
  81. #define sector_size (128 * 1024)
  82. #define flash0_size (16 * 1024 * 1024)
  83. #define flash1_size ( 8 * 1024 * 1024)
  84. #define flash2_size (32 * 1024 * 1024)
  85. #define total_ram_v1 (sdram_size + flash0_size + flash1_size + OMAP15XX_SRAM_SIZE)
  86. #define total_ram_v2 (sdram_size + flash2_size + OMAP15XX_SRAM_SIZE)
  87. static struct arm_boot_info sx1_binfo = {
  88. .loader_start = OMAP_EMIFF_BASE,
  89. .ram_size = sdram_size,
  90. .board_id = 0x265,
  91. };
  92. static void sx1_init(MachineState *machine, const int version)
  93. {
  94. struct omap_mpu_state_s *mpu;
  95. MemoryRegion *address_space = get_system_memory();
  96. MemoryRegion *dram = g_new(MemoryRegion, 1);
  97. MemoryRegion *flash = g_new(MemoryRegion, 1);
  98. MemoryRegion *cs = g_new(MemoryRegion, 4);
  99. static uint32_t cs0val = 0x00213090;
  100. static uint32_t cs1val = 0x00215070;
  101. static uint32_t cs2val = 0x00001139;
  102. static uint32_t cs3val = 0x00001139;
  103. DriveInfo *dinfo;
  104. int fl_idx;
  105. uint32_t flash_size = flash0_size;
  106. int be;
  107. if (version == 2) {
  108. flash_size = flash2_size;
  109. }
  110. memory_region_allocate_system_memory(dram, NULL, "omap1.dram",
  111. sx1_binfo.ram_size);
  112. memory_region_add_subregion(address_space, OMAP_EMIFF_BASE, dram);
  113. mpu = omap310_mpu_init(dram, machine->cpu_type);
  114. /* External Flash (EMIFS) */
  115. memory_region_init_ram(flash, NULL, "omap_sx1.flash0-0", flash_size,
  116. &error_fatal);
  117. memory_region_set_readonly(flash, true);
  118. memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
  119. memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
  120. "sx1.cs0", OMAP_CS0_SIZE - flash_size);
  121. memory_region_add_subregion(address_space,
  122. OMAP_CS0_BASE + flash_size, &cs[0]);
  123. memory_region_init_io(&cs[2], NULL, &static_ops, &cs2val,
  124. "sx1.cs2", OMAP_CS2_SIZE);
  125. memory_region_add_subregion(address_space,
  126. OMAP_CS2_BASE, &cs[2]);
  127. memory_region_init_io(&cs[3], NULL, &static_ops, &cs3val,
  128. "sx1.cs3", OMAP_CS3_SIZE);
  129. memory_region_add_subregion(address_space,
  130. OMAP_CS2_BASE, &cs[3]);
  131. fl_idx = 0;
  132. #ifdef TARGET_WORDS_BIGENDIAN
  133. be = 1;
  134. #else
  135. be = 0;
  136. #endif
  137. if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
  138. if (!pflash_cfi01_register(OMAP_CS0_BASE,
  139. "omap_sx1.flash0-1", flash_size,
  140. blk_by_legacy_dinfo(dinfo),
  141. sector_size, 4, 0, 0, 0, 0, be)) {
  142. fprintf(stderr, "qemu: Error registering flash memory %d.\n",
  143. fl_idx);
  144. }
  145. fl_idx++;
  146. }
  147. if ((version == 1) &&
  148. (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
  149. MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
  150. memory_region_init_ram(flash_1, NULL, "omap_sx1.flash1-0",
  151. flash1_size, &error_fatal);
  152. memory_region_set_readonly(flash_1, true);
  153. memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
  154. memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
  155. "sx1.cs1", OMAP_CS1_SIZE - flash1_size);
  156. memory_region_add_subregion(address_space,
  157. OMAP_CS1_BASE + flash1_size, &cs[1]);
  158. if (!pflash_cfi01_register(OMAP_CS1_BASE,
  159. "omap_sx1.flash1-1", flash1_size,
  160. blk_by_legacy_dinfo(dinfo),
  161. sector_size, 4, 0, 0, 0, 0, be)) {
  162. fprintf(stderr, "qemu: Error registering flash memory %d.\n",
  163. fl_idx);
  164. }
  165. fl_idx++;
  166. } else {
  167. memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
  168. "sx1.cs1", OMAP_CS1_SIZE);
  169. memory_region_add_subregion(address_space,
  170. OMAP_CS1_BASE, &cs[1]);
  171. }
  172. if (!machine->kernel_filename && !fl_idx && !qtest_enabled()) {
  173. error_report("Kernel or Flash image must be specified");
  174. exit(1);
  175. }
  176. /* Load the kernel. */
  177. arm_load_kernel(mpu->cpu, machine, &sx1_binfo);
  178. /* TODO: fix next line */
  179. //~ qemu_console_resize(ds, 640, 480);
  180. }
  181. static void sx1_init_v1(MachineState *machine)
  182. {
  183. sx1_init(machine, 1);
  184. }
  185. static void sx1_init_v2(MachineState *machine)
  186. {
  187. sx1_init(machine, 2);
  188. }
  189. static void sx1_machine_v2_class_init(ObjectClass *oc, void *data)
  190. {
  191. MachineClass *mc = MACHINE_CLASS(oc);
  192. mc->desc = "Siemens SX1 (OMAP310) V2";
  193. mc->init = sx1_init_v2;
  194. mc->ignore_memory_transaction_failures = true;
  195. mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t");
  196. }
  197. static const TypeInfo sx1_machine_v2_type = {
  198. .name = MACHINE_TYPE_NAME("sx1"),
  199. .parent = TYPE_MACHINE,
  200. .class_init = sx1_machine_v2_class_init,
  201. };
  202. static void sx1_machine_v1_class_init(ObjectClass *oc, void *data)
  203. {
  204. MachineClass *mc = MACHINE_CLASS(oc);
  205. mc->desc = "Siemens SX1 (OMAP310) V1";
  206. mc->init = sx1_init_v1;
  207. mc->ignore_memory_transaction_failures = true;
  208. mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t");
  209. }
  210. static const TypeInfo sx1_machine_v1_type = {
  211. .name = MACHINE_TYPE_NAME("sx1-v1"),
  212. .parent = TYPE_MACHINE,
  213. .class_init = sx1_machine_v1_class_init,
  214. };
  215. static void sx1_machine_init(void)
  216. {
  217. type_register_static(&sx1_machine_v1_type);
  218. type_register_static(&sx1_machine_v2_type);
  219. }
  220. type_init(sx1_machine_init)