mips_jazz.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * QEMU MIPS Jazz support
  3. *
  4. * Copyright (c) 2007-2008 Hervé Poussineau
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #include "hw.h"
  25. #include "mips.h"
  26. #include "pc.h"
  27. #include "isa.h"
  28. #include "fdc.h"
  29. #include "sysemu.h"
  30. #include "audio/audio.h"
  31. #include "boards.h"
  32. #include "net.h"
  33. #include "scsi.h"
  34. #ifdef TARGET_WORDS_BIGENDIAN
  35. #define BIOS_FILENAME "mips_bios.bin"
  36. #else
  37. #define BIOS_FILENAME "mipsel_bios.bin"
  38. #endif
  39. enum jazz_model_e
  40. {
  41. JAZZ_MAGNUM,
  42. JAZZ_PICA61,
  43. };
  44. static void main_cpu_reset(void *opaque)
  45. {
  46. CPUState *env = opaque;
  47. cpu_reset(env);
  48. }
  49. static uint32_t rtc_readb(void *opaque, target_phys_addr_t addr)
  50. {
  51. CPUState *env = opaque;
  52. return cpu_inw(env, 0x71);
  53. }
  54. static void rtc_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
  55. {
  56. CPUState *env = opaque;
  57. cpu_outw(env, 0x71, val & 0xff);
  58. }
  59. static CPUReadMemoryFunc *rtc_read[3] = {
  60. rtc_readb,
  61. rtc_readb,
  62. rtc_readb,
  63. };
  64. static CPUWriteMemoryFunc *rtc_write[3] = {
  65. rtc_writeb,
  66. rtc_writeb,
  67. rtc_writeb,
  68. };
  69. static void dma_dummy_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
  70. {
  71. /* Nothing to do. That is only to ensure that
  72. * the current DMA acknowledge cycle is completed. */
  73. }
  74. static CPUReadMemoryFunc *dma_dummy_read[3] = {
  75. NULL,
  76. NULL,
  77. NULL,
  78. };
  79. static CPUWriteMemoryFunc *dma_dummy_write[3] = {
  80. dma_dummy_writeb,
  81. dma_dummy_writeb,
  82. dma_dummy_writeb,
  83. };
  84. #ifdef HAS_AUDIO
  85. static void audio_init(qemu_irq *pic)
  86. {
  87. struct soundhw *c;
  88. int audio_enabled = 0;
  89. for (c = soundhw; !audio_enabled && c->name; ++c) {
  90. audio_enabled = c->enabled;
  91. }
  92. if (audio_enabled) {
  93. AudioState *s;
  94. s = AUD_init();
  95. if (s) {
  96. for (c = soundhw; c->name; ++c) {
  97. if (c->enabled) {
  98. if (c->isa) {
  99. c->init.init_isa(s, pic);
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. #endif
  107. #define MAGNUM_BIOS_SIZE_MAX 0x7e000
  108. #define MAGNUM_BIOS_SIZE (BIOS_SIZE < MAGNUM_BIOS_SIZE_MAX ? BIOS_SIZE : MAGNUM_BIOS_SIZE_MAX)
  109. static
  110. void mips_jazz_init (ram_addr_t ram_size, int vga_ram_size,
  111. const char *cpu_model,
  112. enum jazz_model_e jazz_model)
  113. {
  114. char buf[1024];
  115. unsigned long bios_offset;
  116. int bios_size, n;
  117. CPUState *env;
  118. qemu_irq *rc4030, *i8259;
  119. rc4030_dma *dmas;
  120. rc4030_dma_function dma_read, dma_write;
  121. void *scsi_hba;
  122. int hd;
  123. int s_rtc, s_dma_dummy;
  124. PITState *pit;
  125. BlockDriverState *fds[MAX_FD];
  126. qemu_irq esp_reset;
  127. /* init CPUs */
  128. if (cpu_model == NULL) {
  129. #ifdef TARGET_MIPS64
  130. cpu_model = "R4000";
  131. #else
  132. /* FIXME: All wrong, this maybe should be R3000 for the older JAZZs. */
  133. cpu_model = "24Kf";
  134. #endif
  135. }
  136. env = cpu_init(cpu_model);
  137. if (!env) {
  138. fprintf(stderr, "Unable to find CPU definition\n");
  139. exit(1);
  140. }
  141. qemu_register_reset(main_cpu_reset, env);
  142. /* allocate RAM */
  143. cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
  144. /* load the BIOS image. */
  145. bios_offset = ram_size + vga_ram_size;
  146. if (bios_name == NULL)
  147. bios_name = BIOS_FILENAME;
  148. snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
  149. bios_size = load_image(buf, phys_ram_base + bios_offset);
  150. if (bios_size < 0 || bios_size > MAGNUM_BIOS_SIZE) {
  151. fprintf(stderr, "qemu: Could not load MIPS bios '%s'\n",
  152. buf);
  153. exit(1);
  154. }
  155. cpu_register_physical_memory(0x1fc00000LL,
  156. MAGNUM_BIOS_SIZE, bios_offset | IO_MEM_ROM);
  157. cpu_register_physical_memory(0xfff00000LL,
  158. MAGNUM_BIOS_SIZE, bios_offset | IO_MEM_ROM);
  159. /* Init CPU internal devices */
  160. cpu_mips_irq_init_cpu(env);
  161. cpu_mips_clock_init(env);
  162. /* Chipset */
  163. rc4030 = rc4030_init(env->irq[6], env->irq[3],
  164. &dmas, &dma_read, &dma_write);
  165. s_dma_dummy = cpu_register_io_memory(0, dma_dummy_read, dma_dummy_write, NULL);
  166. cpu_register_physical_memory(0x8000d000, 0x00001000, s_dma_dummy);
  167. /* ISA devices */
  168. i8259 = i8259_init(env->irq[4]);
  169. DMA_init(0);
  170. pit = pit_init(0x40, i8259[0]);
  171. pcspk_init(pit);
  172. /* ISA IO space at 0x90000000 */
  173. isa_mmio_init(0x90000000, 0x01000000);
  174. isa_mem_base = 0x11000000;
  175. /* Video card */
  176. switch (jazz_model) {
  177. case JAZZ_MAGNUM:
  178. g364fb_mm_init(phys_ram_base + ram_size, ram_size, vga_ram_size,
  179. 0x40000000, 0x60000000, 0, rc4030[3]);
  180. break;
  181. case JAZZ_PICA61:
  182. isa_vga_mm_init(phys_ram_base + ram_size, ram_size, vga_ram_size,
  183. 0x40000000, 0x60000000, 0);
  184. break;
  185. default:
  186. break;
  187. }
  188. /* Network controller */
  189. /* FIXME: missing NS SONIC DP83932 */
  190. /* SCSI adapter */
  191. scsi_hba = esp_init(0x80002000, 0,
  192. dma_read, dma_write, dmas[0],
  193. rc4030[5], &esp_reset);
  194. for (n = 0; n < ESP_MAX_DEVS; n++) {
  195. hd = drive_get_index(IF_SCSI, 0, n);
  196. if (hd != -1) {
  197. esp_scsi_attach(scsi_hba, drives_table[hd].bdrv, n);
  198. }
  199. }
  200. /* Floppy */
  201. if (drive_get_max_bus(IF_FLOPPY) >= MAX_FD) {
  202. fprintf(stderr, "qemu: too many floppy drives\n");
  203. exit(1);
  204. }
  205. for (n = 0; n < MAX_FD; n++) {
  206. int fd = drive_get_index(IF_FLOPPY, 0, n);
  207. if (fd != -1)
  208. fds[n] = drives_table[fd].bdrv;
  209. else
  210. fds[n] = NULL;
  211. }
  212. fdctrl_init(rc4030[1], 0, 1, 0x80003000, fds);
  213. /* Real time clock */
  214. rtc_init(0x70, i8259[8], 1980);
  215. s_rtc = cpu_register_io_memory(0, rtc_read, rtc_write, env);
  216. cpu_register_physical_memory(0x80004000, 0x00001000, s_rtc);
  217. /* Keyboard (i8042) */
  218. i8042_mm_init(rc4030[6], rc4030[7], 0x80005000, 0x1000, 0x1);
  219. /* Serial ports */
  220. if (serial_hds[0])
  221. serial_mm_init(0x80006000, 0, rc4030[8], 8000000/16, serial_hds[0], 1);
  222. if (serial_hds[1])
  223. serial_mm_init(0x80007000, 0, rc4030[9], 8000000/16, serial_hds[1], 1);
  224. /* Parallel port */
  225. if (parallel_hds[0])
  226. parallel_mm_init(0x80008000, 0, rc4030[0], parallel_hds[0]);
  227. /* Sound card */
  228. /* FIXME: missing Jazz sound at 0x8000c000, rc4030[2] */
  229. #ifdef HAS_AUDIO
  230. audio_init(i8259);
  231. #endif
  232. /* NVRAM: Unprotected at 0x9000, Protected at 0xa000, Read only at 0xb000 */
  233. ds1225y_init(0x80009000, "nvram");
  234. /* LED indicator */
  235. jazz_led_init(0x8000f000);
  236. }
  237. static
  238. void mips_magnum_init (ram_addr_t ram_size, int vga_ram_size,
  239. const char *boot_device,
  240. const char *kernel_filename, const char *kernel_cmdline,
  241. const char *initrd_filename, const char *cpu_model)
  242. {
  243. mips_jazz_init(ram_size, vga_ram_size, cpu_model, JAZZ_MAGNUM);
  244. }
  245. static
  246. void mips_pica61_init (ram_addr_t ram_size, int vga_ram_size,
  247. const char *boot_device,
  248. const char *kernel_filename, const char *kernel_cmdline,
  249. const char *initrd_filename, const char *cpu_model)
  250. {
  251. mips_jazz_init(ram_size, vga_ram_size, cpu_model, JAZZ_PICA61);
  252. }
  253. QEMUMachine mips_magnum_machine = {
  254. .name = "magnum",
  255. .desc = "MIPS Magnum",
  256. .init = mips_magnum_init,
  257. .ram_require = MAGNUM_BIOS_SIZE + VGA_RAM_SIZE,
  258. .nodisk_ok = 1,
  259. .use_scsi = 1,
  260. };
  261. QEMUMachine mips_pica61_machine = {
  262. .name = "pica61",
  263. .desc = "Acer Pica 61",
  264. .init = mips_pica61_init,
  265. .ram_require = MAGNUM_BIOS_SIZE + VGA_RAM_SIZE,
  266. .nodisk_ok = 1,
  267. .use_scsi = 1,
  268. };