omap_sx1.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. #ifdef SPY
  73. printf("%s: value %" PRIx64 " %u bytes written at 0x%x\n",
  74. __func__, value, size, (int)offset);
  75. #endif
  76. }
  77. static const MemoryRegionOps static_ops = {
  78. .read = static_read,
  79. .write = static_write,
  80. .endianness = DEVICE_NATIVE_ENDIAN,
  81. };
  82. #define SDRAM_SIZE (32 * MiB)
  83. #define SECTOR_SIZE (128 * KiB)
  84. #define FLASH0_SIZE (16 * MiB)
  85. #define FLASH1_SIZE (8 * MiB)
  86. #define FLASH2_SIZE (32 * MiB)
  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. MachineClass *mc = MACHINE_GET_CLASS(machine);
  96. MemoryRegion *address_space = get_system_memory();
  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. if (machine->ram_size != mc->default_ram_size) {
  107. char *sz = size_to_str(mc->default_ram_size);
  108. error_report("Invalid RAM size, should be %s", sz);
  109. g_free(sz);
  110. exit(EXIT_FAILURE);
  111. }
  112. if (version == 2) {
  113. flash_size = FLASH2_SIZE;
  114. }
  115. memory_region_add_subregion(address_space, OMAP_EMIFF_BASE, machine->ram);
  116. mpu = omap310_mpu_init(machine->ram, machine->cpu_type);
  117. /* External Flash (EMIFS) */
  118. memory_region_init_rom(flash, NULL, "omap_sx1.flash0-0", flash_size,
  119. &error_fatal);
  120. memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
  121. memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
  122. "sx1.cs0", OMAP_CS0_SIZE - flash_size);
  123. memory_region_add_subregion(address_space,
  124. OMAP_CS0_BASE + flash_size, &cs[0]);
  125. memory_region_init_io(&cs[2], NULL, &static_ops, &cs2val,
  126. "sx1.cs2", OMAP_CS2_SIZE);
  127. memory_region_add_subregion(address_space,
  128. OMAP_CS2_BASE, &cs[2]);
  129. memory_region_init_io(&cs[3], NULL, &static_ops, &cs3val,
  130. "sx1.cs3", OMAP_CS3_SIZE);
  131. memory_region_add_subregion(address_space,
  132. OMAP_CS2_BASE, &cs[3]);
  133. fl_idx = 0;
  134. if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
  135. pflash_cfi01_register(OMAP_CS0_BASE,
  136. "omap_sx1.flash0-1", flash_size,
  137. blk_by_legacy_dinfo(dinfo),
  138. SECTOR_SIZE, 4, 0, 0, 0, 0, 0);
  139. fl_idx++;
  140. }
  141. if ((version == 1) &&
  142. (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
  143. MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
  144. memory_region_init_rom(flash_1, NULL, "omap_sx1.flash1-0",
  145. FLASH1_SIZE, &error_fatal);
  146. memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
  147. memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
  148. "sx1.cs1", OMAP_CS1_SIZE - FLASH1_SIZE);
  149. memory_region_add_subregion(address_space,
  150. OMAP_CS1_BASE + FLASH1_SIZE, &cs[1]);
  151. pflash_cfi01_register(OMAP_CS1_BASE,
  152. "omap_sx1.flash1-1", FLASH1_SIZE,
  153. blk_by_legacy_dinfo(dinfo),
  154. SECTOR_SIZE, 4, 0, 0, 0, 0, 0);
  155. fl_idx++;
  156. } else {
  157. memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
  158. "sx1.cs1", OMAP_CS1_SIZE);
  159. memory_region_add_subregion(address_space,
  160. OMAP_CS1_BASE, &cs[1]);
  161. }
  162. if (!machine->kernel_filename && !fl_idx && !qtest_enabled()) {
  163. error_report("Kernel or Flash image must be specified");
  164. exit(1);
  165. }
  166. /* Load the kernel. */
  167. arm_load_kernel(mpu->cpu, machine, &sx1_binfo);
  168. /* TODO: fix next line */
  169. //~ qemu_console_resize(ds, 640, 480);
  170. }
  171. static void sx1_init_v1(MachineState *machine)
  172. {
  173. sx1_init(machine, 1);
  174. }
  175. static void sx1_init_v2(MachineState *machine)
  176. {
  177. sx1_init(machine, 2);
  178. }
  179. static void sx1_machine_v2_class_init(ObjectClass *oc, void *data)
  180. {
  181. MachineClass *mc = MACHINE_CLASS(oc);
  182. mc->desc = "Siemens SX1 (OMAP310) V2";
  183. mc->init = sx1_init_v2;
  184. mc->ignore_memory_transaction_failures = true;
  185. mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t");
  186. mc->default_ram_size = SDRAM_SIZE;
  187. mc->default_ram_id = "omap1.dram";
  188. }
  189. static const TypeInfo sx1_machine_v2_type = {
  190. .name = MACHINE_TYPE_NAME("sx1"),
  191. .parent = TYPE_MACHINE,
  192. .class_init = sx1_machine_v2_class_init,
  193. };
  194. static void sx1_machine_v1_class_init(ObjectClass *oc, void *data)
  195. {
  196. MachineClass *mc = MACHINE_CLASS(oc);
  197. mc->desc = "Siemens SX1 (OMAP310) V1";
  198. mc->init = sx1_init_v1;
  199. mc->ignore_memory_transaction_failures = true;
  200. mc->default_cpu_type = ARM_CPU_TYPE_NAME("ti925t");
  201. mc->default_ram_size = SDRAM_SIZE;
  202. mc->default_ram_id = "omap1.dram";
  203. }
  204. static const TypeInfo sx1_machine_v1_type = {
  205. .name = MACHINE_TYPE_NAME("sx1-v1"),
  206. .parent = TYPE_MACHINE,
  207. .class_init = sx1_machine_v1_class_init,
  208. };
  209. static void sx1_machine_init(void)
  210. {
  211. type_register_static(&sx1_machine_v1_type);
  212. type_register_static(&sx1_machine_v2_type);
  213. }
  214. type_init(sx1_machine_init)