2
0

omap_sx1.c 7.5 KB

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