omap_sx1.c 7.6 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, write to the Free Software Foundation, Inc.,
  26. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  27. */
  28. #include "hw.h"
  29. #include "sysemu.h"
  30. #include "console.h"
  31. #include "omap.h"
  32. #include "boards.h"
  33. #include "arm-misc.h"
  34. #include "flash.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 *static_readfn[] = {
  82. static_readb,
  83. static_readh,
  84. static_readw,
  85. };
  86. static CPUWriteMemoryFunc *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, int vga_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. int io;
  111. static uint32_t cs0val = 0x00213090;
  112. static uint32_t cs1val = 0x00215070;
  113. static uint32_t cs2val = 0x00001139;
  114. static uint32_t cs3val = 0x00001139;
  115. ram_addr_t phys_flash;
  116. int index;
  117. int fl_idx;
  118. uint32_t flash_size = flash0_size;
  119. if (version == 2) {
  120. flash_size = flash2_size;
  121. }
  122. cpu = omap310_mpu_init(sx1_binfo.ram_size, cpu_model);
  123. /* External Flash (EMIFS) */
  124. cpu_register_physical_memory(OMAP_CS0_BASE, flash_size,
  125. (phys_flash = qemu_ram_alloc(flash_size)) | IO_MEM_ROM);
  126. io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs0val);
  127. cpu_register_physical_memory(OMAP_CS0_BASE + flash_size,
  128. OMAP_CS0_SIZE - flash_size, io);
  129. io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs2val);
  130. cpu_register_physical_memory(OMAP_CS2_BASE, OMAP_CS2_SIZE, io);
  131. io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs3val);
  132. cpu_register_physical_memory(OMAP_CS3_BASE, OMAP_CS3_SIZE, io);
  133. fl_idx = 0;
  134. if ((index = drive_get_index(IF_PFLASH, 0, fl_idx)) > -1) {
  135. if (!pflash_cfi01_register(OMAP_CS0_BASE, qemu_ram_alloc(flash_size),
  136. drives_table[index].bdrv, sector_size, flash_size / sector_size,
  137. 4, 0, 0, 0, 0)) {
  138. fprintf(stderr, "qemu: Error registering flash memory %d.\n",
  139. fl_idx);
  140. }
  141. fl_idx++;
  142. }
  143. if ((version == 1) &&
  144. (index = drive_get_index(IF_PFLASH, 0, fl_idx)) > -1) {
  145. cpu_register_physical_memory(OMAP_CS1_BASE, flash1_size,
  146. (phys_flash = qemu_ram_alloc(flash1_size)) |
  147. IO_MEM_ROM);
  148. io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs1val);
  149. cpu_register_physical_memory(OMAP_CS1_BASE + flash1_size,
  150. OMAP_CS1_SIZE - flash1_size, io);
  151. if (!pflash_cfi01_register(OMAP_CS1_BASE, qemu_ram_alloc(flash1_size),
  152. drives_table[index].bdrv, sector_size, flash1_size / sector_size,
  153. 4, 0, 0, 0, 0)) {
  154. fprintf(stderr, "qemu: Error registering flash memory %d.\n",
  155. fl_idx);
  156. }
  157. fl_idx++;
  158. } else {
  159. io = cpu_register_io_memory(0, static_readfn, static_writefn, &cs1val);
  160. cpu_register_physical_memory(OMAP_CS1_BASE, OMAP_CS1_SIZE, io);
  161. }
  162. if (!kernel_filename && !fl_idx) {
  163. fprintf(stderr, "Kernel or Flash image must be specified\n");
  164. exit(1);
  165. }
  166. /* Load the kernel. */
  167. if (kernel_filename) {
  168. /* Start at bootloader. */
  169. cpu->env->regs[15] = sx1_binfo.loader_start;
  170. sx1_binfo.kernel_filename = kernel_filename;
  171. sx1_binfo.kernel_cmdline = kernel_cmdline;
  172. sx1_binfo.initrd_filename = initrd_filename;
  173. arm_load_kernel(cpu->env, &sx1_binfo);
  174. } else {
  175. cpu->env->regs[15] = 0x00000000;
  176. }
  177. /* TODO: fix next line */
  178. //~ qemu_console_resize(ds, 640, 480);
  179. }
  180. static void sx1_init_v1(ram_addr_t ram_size, int vga_ram_size,
  181. const char *boot_device,
  182. const char *kernel_filename, const char *kernel_cmdline,
  183. const char *initrd_filename, const char *cpu_model)
  184. {
  185. sx1_init(ram_size, vga_ram_size, boot_device, kernel_filename,
  186. kernel_cmdline, initrd_filename, cpu_model, 1);
  187. }
  188. static void sx1_init_v2(ram_addr_t ram_size, int vga_ram_size,
  189. const char *boot_device,
  190. const char *kernel_filename, const char *kernel_cmdline,
  191. const char *initrd_filename, const char *cpu_model)
  192. {
  193. sx1_init(ram_size, vga_ram_size, boot_device, kernel_filename,
  194. kernel_cmdline, initrd_filename, cpu_model, 2);
  195. }
  196. QEMUMachine sx1_machine_v2 = {
  197. .name = "sx1",
  198. .desc = "Siemens SX1 (OMAP310) V2",
  199. .init = sx1_init_v2,
  200. .ram_require = total_ram_v2 | RAMSIZE_FIXED,
  201. };
  202. QEMUMachine sx1_machine_v1 = {
  203. .name = "sx1-v1",
  204. .desc = "Siemens SX1 (OMAP310) V1",
  205. .init = sx1_init_v1,
  206. .ram_require = total_ram_v1 | RAMSIZE_FIXED,
  207. };