omap_sx1.c 8.1 KB

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