2
0

omap_sx1.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 "console.h"
  29. #include "omap.h"
  30. #include "boards.h"
  31. #include "arm-misc.h"
  32. #include "flash.h"
  33. #include "blockdev.h"
  34. #include "exec-memory.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 uint32_t static_readb(void *opaque, target_phys_addr_t offset)
  59. {
  60. uint32_t *val = (uint32_t *) opaque;
  61. return *val >> ((offset & 3) << 3);
  62. }
  63. static uint32_t static_readh(void *opaque, target_phys_addr_t offset)
  64. {
  65. uint32_t *val = (uint32_t *) opaque;
  66. return *val >> ((offset & 1) << 3);
  67. }
  68. static uint32_t static_readw(void *opaque, target_phys_addr_t offset)
  69. {
  70. uint32_t *val = (uint32_t *) opaque;
  71. return *val >> ((offset & 0) << 3);
  72. }
  73. static void static_write(void *opaque, target_phys_addr_t offset,
  74. uint32_t value)
  75. {
  76. #ifdef SPY
  77. printf("%s: value %08lx written at " PA_FMT "\n",
  78. __FUNCTION__, value, offset);
  79. #endif
  80. }
  81. static CPUReadMemoryFunc * const static_readfn[] = {
  82. static_readb,
  83. static_readh,
  84. static_readw,
  85. };
  86. static CPUWriteMemoryFunc * const static_writefn[] = {
  87. static_write,
  88. static_write,
  89. static_write,
  90. };
  91. #define sdram_size 0x02000000
  92. #define sector_size (128 * 1024)
  93. #define flash0_size (16 * 1024 * 1024)
  94. #define flash1_size ( 8 * 1024 * 1024)
  95. #define flash2_size (32 * 1024 * 1024)
  96. #define total_ram_v1 (sdram_size + flash0_size + flash1_size + OMAP15XX_SRAM_SIZE)
  97. #define total_ram_v2 (sdram_size + flash2_size + OMAP15XX_SRAM_SIZE)
  98. static struct arm_boot_info sx1_binfo = {
  99. .loader_start = OMAP_EMIFF_BASE,
  100. .ram_size = sdram_size,
  101. .board_id = 0x265,
  102. };
  103. static void sx1_init(ram_addr_t ram_size,
  104. const char *boot_device,
  105. const char *kernel_filename, const char *kernel_cmdline,
  106. const char *initrd_filename, const char *cpu_model,
  107. const int version)
  108. {
  109. struct omap_mpu_state_s *cpu;
  110. MemoryRegion *address_space = get_system_memory();
  111. int io;
  112. static uint32_t cs0val = 0x00213090;
  113. static uint32_t cs1val = 0x00215070;
  114. static uint32_t cs2val = 0x00001139;
  115. static uint32_t cs3val = 0x00001139;
  116. DriveInfo *dinfo;
  117. int fl_idx;
  118. uint32_t flash_size = flash0_size;
  119. int be;
  120. if (version == 2) {
  121. flash_size = flash2_size;
  122. }
  123. cpu = omap310_mpu_init(address_space, sx1_binfo.ram_size, cpu_model);
  124. /* External Flash (EMIFS) */
  125. cpu_register_physical_memory(OMAP_CS0_BASE, flash_size,
  126. qemu_ram_alloc(NULL, "omap_sx1.flash0-0",
  127. flash_size) | IO_MEM_ROM);
  128. io = cpu_register_io_memory(static_readfn, static_writefn, &cs0val,
  129. DEVICE_NATIVE_ENDIAN);
  130. cpu_register_physical_memory(OMAP_CS0_BASE + flash_size,
  131. OMAP_CS0_SIZE - flash_size, io);
  132. io = cpu_register_io_memory(static_readfn, static_writefn, &cs2val,
  133. DEVICE_NATIVE_ENDIAN);
  134. cpu_register_physical_memory(OMAP_CS2_BASE, OMAP_CS2_SIZE, io);
  135. io = cpu_register_io_memory(static_readfn, static_writefn, &cs3val,
  136. DEVICE_NATIVE_ENDIAN);
  137. cpu_register_physical_memory(OMAP_CS3_BASE, OMAP_CS3_SIZE, io);
  138. fl_idx = 0;
  139. #ifdef TARGET_WORDS_BIGENDIAN
  140. be = 1;
  141. #else
  142. be = 0;
  143. #endif
  144. if ((dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
  145. if (!pflash_cfi01_register(OMAP_CS0_BASE, NULL,
  146. "omap_sx1.flash0-1", flash_size,
  147. dinfo->bdrv, sector_size,
  148. flash_size / sector_size,
  149. 4, 0, 0, 0, 0, be)) {
  150. fprintf(stderr, "qemu: Error registering flash memory %d.\n",
  151. fl_idx);
  152. }
  153. fl_idx++;
  154. }
  155. if ((version == 1) &&
  156. (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
  157. cpu_register_physical_memory(OMAP_CS1_BASE, flash1_size,
  158. qemu_ram_alloc(NULL, "omap_sx1.flash1-0",
  159. flash1_size) | IO_MEM_ROM);
  160. io = cpu_register_io_memory(static_readfn, static_writefn, &cs1val,
  161. DEVICE_NATIVE_ENDIAN);
  162. cpu_register_physical_memory(OMAP_CS1_BASE + flash1_size,
  163. OMAP_CS1_SIZE - flash1_size, io);
  164. if (!pflash_cfi01_register(OMAP_CS1_BASE, NULL,
  165. "omap_sx1.flash1-1", flash1_size,
  166. dinfo->bdrv, sector_size,
  167. flash1_size / sector_size,
  168. 4, 0, 0, 0, 0, be)) {
  169. fprintf(stderr, "qemu: Error registering flash memory %d.\n",
  170. fl_idx);
  171. }
  172. fl_idx++;
  173. } else {
  174. io = cpu_register_io_memory(static_readfn, static_writefn, &cs1val,
  175. DEVICE_NATIVE_ENDIAN);
  176. cpu_register_physical_memory(OMAP_CS1_BASE, OMAP_CS1_SIZE, io);
  177. }
  178. if (!kernel_filename && !fl_idx) {
  179. fprintf(stderr, "Kernel or Flash image must be specified\n");
  180. exit(1);
  181. }
  182. /* Load the kernel. */
  183. if (kernel_filename) {
  184. sx1_binfo.kernel_filename = kernel_filename;
  185. sx1_binfo.kernel_cmdline = kernel_cmdline;
  186. sx1_binfo.initrd_filename = initrd_filename;
  187. arm_load_kernel(cpu->env, &sx1_binfo);
  188. }
  189. /* TODO: fix next line */
  190. //~ qemu_console_resize(ds, 640, 480);
  191. }
  192. static void sx1_init_v1(ram_addr_t ram_size,
  193. const char *boot_device,
  194. const char *kernel_filename, const char *kernel_cmdline,
  195. const char *initrd_filename, const char *cpu_model)
  196. {
  197. sx1_init(ram_size, boot_device, kernel_filename,
  198. kernel_cmdline, initrd_filename, cpu_model, 1);
  199. }
  200. static void sx1_init_v2(ram_addr_t ram_size,
  201. const char *boot_device,
  202. const char *kernel_filename, const char *kernel_cmdline,
  203. const char *initrd_filename, const char *cpu_model)
  204. {
  205. sx1_init(ram_size, boot_device, kernel_filename,
  206. kernel_cmdline, initrd_filename, cpu_model, 2);
  207. }
  208. static QEMUMachine sx1_machine_v2 = {
  209. .name = "sx1",
  210. .desc = "Siemens SX1 (OMAP310) V2",
  211. .init = sx1_init_v2,
  212. };
  213. static QEMUMachine sx1_machine_v1 = {
  214. .name = "sx1-v1",
  215. .desc = "Siemens SX1 (OMAP310) V1",
  216. .init = sx1_init_v1,
  217. };
  218. static void sx1_machine_init(void)
  219. {
  220. qemu_register_machine(&sx1_machine_v2);
  221. qemu_register_machine(&sx1_machine_v1);
  222. }
  223. machine_init(sx1_machine_init);