jazz.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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 "qemu/osdep.h"
  25. #include "qemu/datadir.h"
  26. #include "hw/clock.h"
  27. #include "hw/mips/mips.h"
  28. #include "hw/intc/i8259.h"
  29. #include "hw/dma/i8257.h"
  30. #include "hw/char/serial-mm.h"
  31. #include "hw/char/parallel.h"
  32. #include "hw/isa/isa.h"
  33. #include "hw/block/fdc.h"
  34. #include "system/system.h"
  35. #include "hw/boards.h"
  36. #include "net/net.h"
  37. #include "hw/scsi/esp.h"
  38. #include "hw/loader.h"
  39. #include "hw/rtc/mc146818rtc.h"
  40. #include "hw/timer/i8254.h"
  41. #include "hw/display/vga.h"
  42. #include "hw/display/bochs-vbe.h"
  43. #include "hw/audio/pcspk.h"
  44. #include "hw/input/i8042.h"
  45. #include "hw/sysbus.h"
  46. #include "system/qtest.h"
  47. #include "system/reset.h"
  48. #include "qapi/error.h"
  49. #include "qemu/error-report.h"
  50. #include "qemu/help_option.h"
  51. #ifdef CONFIG_TCG
  52. #include "hw/core/tcg-cpu-ops.h"
  53. #endif /* CONFIG_TCG */
  54. #include "cpu.h"
  55. enum jazz_model_e {
  56. JAZZ_MAGNUM,
  57. JAZZ_PICA61,
  58. };
  59. #if TARGET_BIG_ENDIAN
  60. #define BIOS_FILENAME "mips_bios.bin"
  61. #else
  62. #define BIOS_FILENAME "mipsel_bios.bin"
  63. #endif
  64. static void main_cpu_reset(void *opaque)
  65. {
  66. MIPSCPU *cpu = opaque;
  67. cpu_reset(CPU(cpu));
  68. }
  69. static uint64_t rtc_read(void *opaque, hwaddr addr, unsigned size)
  70. {
  71. uint8_t val;
  72. address_space_read(&address_space_memory, 0x90000071,
  73. MEMTXATTRS_UNSPECIFIED, &val, 1);
  74. return val;
  75. }
  76. static void rtc_write(void *opaque, hwaddr addr,
  77. uint64_t val, unsigned size)
  78. {
  79. uint8_t buf = val & 0xff;
  80. address_space_write(&address_space_memory, 0x90000071,
  81. MEMTXATTRS_UNSPECIFIED, &buf, 1);
  82. }
  83. static const MemoryRegionOps rtc_ops = {
  84. .read = rtc_read,
  85. .write = rtc_write,
  86. .endianness = DEVICE_NATIVE_ENDIAN,
  87. };
  88. static uint64_t dma_dummy_read(void *opaque, hwaddr addr,
  89. unsigned size)
  90. {
  91. /*
  92. * Nothing to do. That is only to ensure that
  93. * the current DMA acknowledge cycle is completed.
  94. */
  95. return 0xff;
  96. }
  97. static void dma_dummy_write(void *opaque, hwaddr addr,
  98. uint64_t val, unsigned size)
  99. {
  100. /*
  101. * Nothing to do. That is only to ensure that
  102. * the current DMA acknowledge cycle is completed.
  103. */
  104. }
  105. static const MemoryRegionOps dma_dummy_ops = {
  106. .read = dma_dummy_read,
  107. .write = dma_dummy_write,
  108. .endianness = DEVICE_NATIVE_ENDIAN,
  109. };
  110. static void mips_jazz_init_net(IOMMUMemoryRegion *rc4030_dma_mr,
  111. DeviceState *rc4030, MemoryRegion *dp8393x_prom)
  112. {
  113. DeviceState *dev;
  114. SysBusDevice *sysbus;
  115. int checksum, i;
  116. uint8_t *prom;
  117. NICInfo *nd;
  118. nd = qemu_find_nic_info("dp8393x", true, "dp83932");
  119. if (!nd) {
  120. return;
  121. }
  122. dev = qdev_new("dp8393x");
  123. qdev_set_nic_properties(dev, nd);
  124. qdev_prop_set_uint8(dev, "it_shift", 2);
  125. qdev_prop_set_bit(dev, "big_endian", TARGET_BIG_ENDIAN);
  126. object_property_set_link(OBJECT(dev), "dma_mr",
  127. OBJECT(rc4030_dma_mr), &error_abort);
  128. sysbus = SYS_BUS_DEVICE(dev);
  129. sysbus_realize_and_unref(sysbus, &error_fatal);
  130. sysbus_mmio_map(sysbus, 0, 0x80001000);
  131. sysbus_connect_irq(sysbus, 0, qdev_get_gpio_in(rc4030, 4));
  132. /* Add MAC address with valid checksum to PROM */
  133. prom = memory_region_get_ram_ptr(dp8393x_prom);
  134. checksum = 0;
  135. for (i = 0; i < 6; i++) {
  136. prom[i] = nd->macaddr.a[i];
  137. checksum += prom[i];
  138. if (checksum > 0xff) {
  139. checksum = (checksum + 1) & 0xff;
  140. }
  141. }
  142. prom[7] = 0xff - checksum;
  143. }
  144. #define BIOS_SIZE (4 * MiB)
  145. #define MAGNUM_BIOS_SIZE_MAX 0x7e000
  146. #define MAGNUM_BIOS_SIZE \
  147. (BIOS_SIZE < MAGNUM_BIOS_SIZE_MAX ? BIOS_SIZE : MAGNUM_BIOS_SIZE_MAX)
  148. #define SONIC_PROM_SIZE 0x1000
  149. static void mips_jazz_init(MachineState *machine,
  150. enum jazz_model_e jazz_model)
  151. {
  152. MemoryRegion *address_space = get_system_memory();
  153. char *filename;
  154. int bios_size, n;
  155. Clock *cpuclk;
  156. MIPSCPU *cpu;
  157. MIPSCPUClass *mcc;
  158. CPUMIPSState *env;
  159. qemu_irq *i8259;
  160. rc4030_dma *dmas;
  161. IOMMUMemoryRegion *rc4030_dma_mr;
  162. MemoryRegion *isa_mem = g_new(MemoryRegion, 1);
  163. MemoryRegion *isa_io = g_new(MemoryRegion, 1);
  164. MemoryRegion *rtc = g_new(MemoryRegion, 1);
  165. MemoryRegion *dma_dummy = g_new(MemoryRegion, 1);
  166. MemoryRegion *dp8393x_prom = g_new(MemoryRegion, 1);
  167. DeviceState *dev, *rc4030;
  168. MMIOKBDState *i8042;
  169. SysBusDevice *sysbus;
  170. ISABus *isa_bus;
  171. ISADevice *pit;
  172. ISADevice *pcspk;
  173. DriveInfo *fds[MAX_FD];
  174. MemoryRegion *bios = g_new(MemoryRegion, 1);
  175. MemoryRegion *bios2 = g_new(MemoryRegion, 1);
  176. SysBusESPState *sysbus_esp;
  177. ESPState *esp;
  178. static const struct {
  179. unsigned freq_hz;
  180. unsigned pll_mult;
  181. } ext_clk[] = {
  182. [JAZZ_MAGNUM] = {50000000, 2},
  183. [JAZZ_PICA61] = {33333333, 4},
  184. };
  185. if (machine->ram_size > 256 * MiB) {
  186. error_report("RAM size more than 256Mb is not supported");
  187. exit(EXIT_FAILURE);
  188. }
  189. cpuclk = clock_new(OBJECT(machine), "cpu-refclk");
  190. clock_set_hz(cpuclk, ext_clk[jazz_model].freq_hz
  191. * ext_clk[jazz_model].pll_mult);
  192. /* init CPUs */
  193. cpu = mips_cpu_create_with_clock(machine->cpu_type, cpuclk,
  194. TARGET_BIG_ENDIAN);
  195. env = &cpu->env;
  196. qemu_register_reset(main_cpu_reset, cpu);
  197. /*
  198. * Chipset returns 0 in invalid reads and do not raise data exceptions.
  199. * However, we can't simply add a global memory region to catch
  200. * everything, as this would make all accesses including instruction
  201. * accesses be ignored and not raise exceptions.
  202. *
  203. * NOTE: this behaviour of raising exceptions for bad instruction
  204. * fetches but not bad data accesses was added in commit 54e755588cf1e9
  205. * to restore behaviour broken by c658b94f6e8c206, but it is not clear
  206. * whether the real hardware behaves this way. It is possible that
  207. * real hardware ignores bad instruction fetches as well -- if so then
  208. * we could replace this hijacking of CPU methods with a simple global
  209. * memory region that catches all memory accesses, as we do on Malta.
  210. */
  211. mcc = MIPS_CPU_GET_CLASS(cpu);
  212. mcc->no_data_aborts = true;
  213. /* allocate RAM */
  214. memory_region_add_subregion(address_space, 0, machine->ram);
  215. memory_region_init_rom(bios, NULL, "mips_jazz.bios", MAGNUM_BIOS_SIZE,
  216. &error_fatal);
  217. memory_region_init_alias(bios2, NULL, "mips_jazz.bios", bios,
  218. 0, MAGNUM_BIOS_SIZE);
  219. memory_region_add_subregion(address_space, 0x1fc00000LL, bios);
  220. memory_region_add_subregion(address_space, 0xfff00000LL, bios2);
  221. /* load the BIOS image. */
  222. filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, machine->firmware ?: BIOS_FILENAME);
  223. if (filename) {
  224. bios_size = load_image_targphys(filename, 0xfff00000LL,
  225. MAGNUM_BIOS_SIZE);
  226. g_free(filename);
  227. } else {
  228. bios_size = -1;
  229. }
  230. if ((bios_size < 0 || bios_size > MAGNUM_BIOS_SIZE)
  231. && machine->firmware && !qtest_enabled()) {
  232. error_report("Could not load MIPS bios '%s'", machine->firmware);
  233. exit(1);
  234. }
  235. /* Init CPU internal devices */
  236. cpu_mips_irq_init_cpu(cpu);
  237. cpu_mips_clock_init(cpu);
  238. /* Chipset */
  239. rc4030 = rc4030_init(&dmas, &rc4030_dma_mr);
  240. sysbus = SYS_BUS_DEVICE(rc4030);
  241. sysbus_connect_irq(sysbus, 0, env->irq[6]);
  242. sysbus_connect_irq(sysbus, 1, env->irq[3]);
  243. memory_region_add_subregion(address_space, 0x80000000,
  244. sysbus_mmio_get_region(sysbus, 0));
  245. memory_region_add_subregion(address_space, 0xf0000000,
  246. sysbus_mmio_get_region(sysbus, 1));
  247. memory_region_init_io(dma_dummy, NULL, &dma_dummy_ops,
  248. NULL, "dummy_dma", 0x1000);
  249. memory_region_add_subregion(address_space, 0x8000d000, dma_dummy);
  250. memory_region_init_rom(dp8393x_prom, NULL, "dp8393x-jazz.prom",
  251. SONIC_PROM_SIZE, &error_fatal);
  252. memory_region_add_subregion(address_space, 0x8000b000, dp8393x_prom);
  253. /* ISA bus: IO space at 0x90000000, mem space at 0x91000000 */
  254. memory_region_init(isa_io, NULL, "isa-io", 0x00010000);
  255. memory_region_init(isa_mem, NULL, "isa-mem", 0x01000000);
  256. memory_region_add_subregion(address_space, 0x90000000, isa_io);
  257. memory_region_add_subregion(address_space, 0x91000000, isa_mem);
  258. isa_bus = isa_bus_new(NULL, isa_mem, isa_io, &error_abort);
  259. /* ISA devices */
  260. i8259 = i8259_init(isa_bus, env->irq[4]);
  261. isa_bus_register_input_irqs(isa_bus, i8259);
  262. i8257_dma_init(OBJECT(rc4030), isa_bus, 0);
  263. pit = i8254_pit_init(isa_bus, 0x40, 0, NULL);
  264. pcspk = isa_new(TYPE_PC_SPEAKER);
  265. object_property_set_link(OBJECT(pcspk), "pit", OBJECT(pit), &error_fatal);
  266. isa_realize_and_unref(pcspk, isa_bus, &error_fatal);
  267. /* Video card */
  268. switch (jazz_model) {
  269. case JAZZ_MAGNUM:
  270. dev = qdev_new("sysbus-g364");
  271. sysbus = SYS_BUS_DEVICE(dev);
  272. sysbus_realize_and_unref(sysbus, &error_fatal);
  273. sysbus_mmio_map(sysbus, 0, 0x60080000);
  274. sysbus_mmio_map(sysbus, 1, 0x40000000);
  275. sysbus_connect_irq(sysbus, 0, qdev_get_gpio_in(rc4030, 3));
  276. {
  277. /* Simple ROM, so user doesn't have to provide one */
  278. MemoryRegion *rom_mr = g_new(MemoryRegion, 1);
  279. memory_region_init_rom(rom_mr, NULL, "g364fb.rom", 0x80000,
  280. &error_fatal);
  281. uint8_t *rom = memory_region_get_ram_ptr(rom_mr);
  282. memory_region_add_subregion(address_space, 0x60000000, rom_mr);
  283. rom[0] = 0x10; /* Mips G364 */
  284. }
  285. break;
  286. case JAZZ_PICA61:
  287. dev = qdev_new(TYPE_VGA_MMIO);
  288. qdev_prop_set_uint8(dev, "it_shift", 0);
  289. sysbus = SYS_BUS_DEVICE(dev);
  290. sysbus_realize_and_unref(sysbus, &error_fatal);
  291. sysbus_mmio_map(sysbus, 0, 0x60000000);
  292. sysbus_mmio_map(sysbus, 1, 0x400a0000);
  293. sysbus_mmio_map(sysbus, 2, VBE_DISPI_LFB_PHYSICAL_ADDRESS);
  294. break;
  295. default:
  296. break;
  297. }
  298. /* Network controller */
  299. mips_jazz_init_net(rc4030_dma_mr, rc4030, dp8393x_prom);
  300. /* SCSI adapter */
  301. dev = qdev_new(TYPE_SYSBUS_ESP);
  302. sysbus_esp = SYSBUS_ESP(dev);
  303. esp = &sysbus_esp->esp;
  304. esp->dma_memory_read = rc4030_dma_read;
  305. esp->dma_memory_write = rc4030_dma_write;
  306. esp->dma_opaque = dmas[0];
  307. sysbus_esp->it_shift = 0;
  308. /* XXX for now until rc4030 has been changed to use DMA enable signal */
  309. esp->dma_enabled = 1;
  310. sysbus = SYS_BUS_DEVICE(dev);
  311. sysbus_realize_and_unref(sysbus, &error_fatal);
  312. sysbus_connect_irq(sysbus, 0, qdev_get_gpio_in(rc4030, 5));
  313. sysbus_mmio_map(sysbus, 0, 0x80002000);
  314. scsi_bus_legacy_handle_cmdline(&esp->bus);
  315. /* Floppy */
  316. for (n = 0; n < MAX_FD; n++) {
  317. fds[n] = drive_get(IF_FLOPPY, 0, n);
  318. }
  319. /* FIXME: we should enable DMA with a custom IsaDma device */
  320. fdctrl_init_sysbus(qdev_get_gpio_in(rc4030, 1), 0x80003000, fds);
  321. /* Real time clock */
  322. mc146818_rtc_init(isa_bus, 1980, NULL);
  323. memory_region_init_io(rtc, NULL, &rtc_ops, NULL, "rtc", 0x1000);
  324. memory_region_add_subregion(address_space, 0x80004000, rtc);
  325. /* Keyboard (i8042) */
  326. i8042 = I8042_MMIO(qdev_new(TYPE_I8042_MMIO));
  327. qdev_prop_set_uint64(DEVICE(i8042), "mask", 1);
  328. qdev_prop_set_uint32(DEVICE(i8042), "size", 0x1000);
  329. sysbus_realize_and_unref(SYS_BUS_DEVICE(i8042), &error_fatal);
  330. qdev_connect_gpio_out(DEVICE(i8042), I8042_KBD_IRQ,
  331. qdev_get_gpio_in(rc4030, 6));
  332. qdev_connect_gpio_out(DEVICE(i8042), I8042_MOUSE_IRQ,
  333. qdev_get_gpio_in(rc4030, 7));
  334. memory_region_add_subregion(address_space, 0x80005000,
  335. sysbus_mmio_get_region(SYS_BUS_DEVICE(i8042),
  336. 0));
  337. /* Serial ports */
  338. serial_mm_init(address_space, 0x80006000, 0,
  339. qdev_get_gpio_in(rc4030, 8), 8000000 / 16,
  340. serial_hd(0), DEVICE_NATIVE_ENDIAN);
  341. serial_mm_init(address_space, 0x80007000, 0,
  342. qdev_get_gpio_in(rc4030, 9), 8000000 / 16,
  343. serial_hd(1), DEVICE_NATIVE_ENDIAN);
  344. /* Parallel port */
  345. if (parallel_hds[0])
  346. parallel_mm_init(address_space, 0x80008000, 0,
  347. qdev_get_gpio_in(rc4030, 0), parallel_hds[0]);
  348. /* FIXME: missing Jazz sound at 0x8000c000, rc4030[2] */
  349. /* NVRAM */
  350. dev = qdev_new("ds1225y");
  351. sysbus = SYS_BUS_DEVICE(dev);
  352. sysbus_realize_and_unref(sysbus, &error_fatal);
  353. sysbus_mmio_map(sysbus, 0, 0x80009000);
  354. /* LED indicator */
  355. sysbus_create_simple("jazz-led", 0x8000f000, NULL);
  356. g_free(dmas);
  357. }
  358. static
  359. void mips_magnum_init(MachineState *machine)
  360. {
  361. mips_jazz_init(machine, JAZZ_MAGNUM);
  362. }
  363. static
  364. void mips_pica61_init(MachineState *machine)
  365. {
  366. mips_jazz_init(machine, JAZZ_PICA61);
  367. }
  368. static void mips_magnum_class_init(ObjectClass *oc, void *data)
  369. {
  370. MachineClass *mc = MACHINE_CLASS(oc);
  371. mc->desc = "MIPS Magnum";
  372. mc->init = mips_magnum_init;
  373. mc->block_default_type = IF_SCSI;
  374. mc->default_cpu_type = MIPS_CPU_TYPE_NAME("R4000");
  375. mc->default_ram_id = "mips_jazz.ram";
  376. }
  377. static const TypeInfo mips_magnum_type = {
  378. .name = MACHINE_TYPE_NAME("magnum"),
  379. .parent = TYPE_MACHINE,
  380. .class_init = mips_magnum_class_init,
  381. };
  382. static void mips_pica61_class_init(ObjectClass *oc, void *data)
  383. {
  384. MachineClass *mc = MACHINE_CLASS(oc);
  385. mc->desc = "Acer Pica 61";
  386. mc->init = mips_pica61_init;
  387. mc->block_default_type = IF_SCSI;
  388. mc->default_cpu_type = MIPS_CPU_TYPE_NAME("R4000");
  389. mc->default_ram_id = "mips_jazz.ram";
  390. }
  391. static const TypeInfo mips_pica61_type = {
  392. .name = MACHINE_TYPE_NAME("pica61"),
  393. .parent = TYPE_MACHINE,
  394. .class_init = mips_pica61_class_init,
  395. };
  396. static void mips_jazz_machine_init(void)
  397. {
  398. type_register_static(&mips_magnum_type);
  399. type_register_static(&mips_pica61_type);
  400. }
  401. type_init(mips_jazz_machine_init)