mps2.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*
  2. * ARM V2M MPS2 board emulation.
  3. *
  4. * Copyright (c) 2017 Linaro Limited
  5. * Written by Peter Maydell
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 or
  9. * (at your option) any later version.
  10. */
  11. /* The MPS2 and MPS2+ dev boards are FPGA based (the 2+ has a bigger
  12. * FPGA but is otherwise the same as the 2). Since the CPU itself
  13. * and most of the devices are in the FPGA, the details of the board
  14. * as seen by the guest depend significantly on the FPGA image.
  15. * We model the following FPGA images:
  16. * "mps2-an385" -- Cortex-M3 as documented in ARM Application Note AN385
  17. * "mps2-an386" -- Cortex-M4 as documented in ARM Application Note AN386
  18. * "mps2-an500" -- Cortex-M7 as documented in ARM Application Note AN500
  19. * "mps2-an511" -- Cortex-M3 'DesignStart' as documented in AN511
  20. *
  21. * Links to the TRM for the board itself and to the various Application
  22. * Notes which document the FPGA images can be found here:
  23. * https://developer.arm.com/products/system-design/development-boards/cortex-m-prototyping-system
  24. */
  25. #include "qemu/osdep.h"
  26. #include "qemu/units.h"
  27. #include "qemu/cutils.h"
  28. #include "qapi/error.h"
  29. #include "qemu/error-report.h"
  30. #include "hw/arm/boot.h"
  31. #include "hw/arm/armv7m.h"
  32. #include "hw/or-irq.h"
  33. #include "hw/boards.h"
  34. #include "exec/address-spaces.h"
  35. #include "system/system.h"
  36. #include "hw/qdev-properties.h"
  37. #include "hw/misc/unimp.h"
  38. #include "hw/char/cmsdk-apb-uart.h"
  39. #include "hw/timer/cmsdk-apb-timer.h"
  40. #include "hw/timer/cmsdk-apb-dualtimer.h"
  41. #include "hw/misc/mps2-scc.h"
  42. #include "hw/misc/mps2-fpgaio.h"
  43. #include "hw/ssi/pl022.h"
  44. #include "hw/i2c/arm_sbcon_i2c.h"
  45. #include "hw/net/lan9118.h"
  46. #include "net/net.h"
  47. #include "hw/watchdog/cmsdk-apb-watchdog.h"
  48. #include "hw/qdev-clock.h"
  49. #include "qobject/qlist.h"
  50. #include "qom/object.h"
  51. typedef enum MPS2FPGAType {
  52. FPGA_AN385,
  53. FPGA_AN386,
  54. FPGA_AN500,
  55. FPGA_AN511,
  56. } MPS2FPGAType;
  57. struct MPS2MachineClass {
  58. MachineClass parent;
  59. MPS2FPGAType fpga_type;
  60. uint32_t scc_id;
  61. bool has_block_ram;
  62. hwaddr ethernet_base;
  63. hwaddr psram_base;
  64. };
  65. struct MPS2MachineState {
  66. MachineState parent;
  67. ARMv7MState armv7m;
  68. MemoryRegion ssram1;
  69. MemoryRegion ssram1_m;
  70. MemoryRegion ssram23;
  71. MemoryRegion ssram23_m;
  72. MemoryRegion blockram;
  73. MemoryRegion blockram_m1;
  74. MemoryRegion blockram_m2;
  75. MemoryRegion blockram_m3;
  76. MemoryRegion sram;
  77. /* FPGA APB subsystem */
  78. MPS2SCC scc;
  79. MPS2FPGAIO fpgaio;
  80. /* CMSDK APB subsystem */
  81. CMSDKAPBDualTimer dualtimer;
  82. CMSDKAPBWatchdog watchdog;
  83. CMSDKAPBTimer timer[2];
  84. Clock *sysclk;
  85. Clock *refclk;
  86. };
  87. #define TYPE_MPS2_MACHINE "mps2"
  88. #define TYPE_MPS2_AN385_MACHINE MACHINE_TYPE_NAME("mps2-an385")
  89. #define TYPE_MPS2_AN386_MACHINE MACHINE_TYPE_NAME("mps2-an386")
  90. #define TYPE_MPS2_AN500_MACHINE MACHINE_TYPE_NAME("mps2-an500")
  91. #define TYPE_MPS2_AN511_MACHINE MACHINE_TYPE_NAME("mps2-an511")
  92. OBJECT_DECLARE_TYPE(MPS2MachineState, MPS2MachineClass, MPS2_MACHINE)
  93. /* Main SYSCLK frequency in Hz */
  94. #define SYSCLK_FRQ 25000000
  95. /*
  96. * The Application Notes don't say anything about how the
  97. * systick reference clock is configured. (Quite possibly
  98. * they don't have one at all.) This 1MHz clock matches the
  99. * pre-existing behaviour that used to be hardcoded in the
  100. * armv7m_systick implementation.
  101. */
  102. #define REFCLK_FRQ (1 * 1000 * 1000)
  103. /* Initialize the auxiliary RAM region @mr and map it into
  104. * the memory map at @base.
  105. */
  106. static void make_ram(MemoryRegion *mr, const char *name,
  107. hwaddr base, hwaddr size)
  108. {
  109. memory_region_init_ram(mr, NULL, name, size, &error_fatal);
  110. memory_region_add_subregion(get_system_memory(), base, mr);
  111. }
  112. /* Create an alias of an entire original MemoryRegion @orig
  113. * located at @base in the memory map.
  114. */
  115. static void make_ram_alias(MemoryRegion *mr, const char *name,
  116. MemoryRegion *orig, hwaddr base)
  117. {
  118. memory_region_init_alias(mr, NULL, name, orig, 0,
  119. memory_region_size(orig));
  120. memory_region_add_subregion(get_system_memory(), base, mr);
  121. }
  122. static void mps2_common_init(MachineState *machine)
  123. {
  124. MPS2MachineState *mms = MPS2_MACHINE(machine);
  125. MPS2MachineClass *mmc = MPS2_MACHINE_GET_CLASS(machine);
  126. MemoryRegion *system_memory = get_system_memory();
  127. MachineClass *mc = MACHINE_GET_CLASS(machine);
  128. DeviceState *armv7m, *sccdev;
  129. QList *oscclk;
  130. int i;
  131. if (machine->ram_size != mc->default_ram_size) {
  132. char *sz = size_to_str(mc->default_ram_size);
  133. error_report("Invalid RAM size, should be %s", sz);
  134. g_free(sz);
  135. exit(EXIT_FAILURE);
  136. }
  137. /* This clock doesn't need migration because it is fixed-frequency */
  138. mms->sysclk = clock_new(OBJECT(machine), "SYSCLK");
  139. clock_set_hz(mms->sysclk, SYSCLK_FRQ);
  140. mms->refclk = clock_new(OBJECT(machine), "REFCLK");
  141. clock_set_hz(mms->refclk, REFCLK_FRQ);
  142. /* The FPGA images have an odd combination of different RAMs,
  143. * because in hardware they are different implementations and
  144. * connected to different buses, giving varying performance/size
  145. * tradeoffs. For QEMU they're all just RAM, though. We arbitrarily
  146. * call the 16MB our "system memory", as it's the largest lump.
  147. *
  148. * AN385/AN386/AN511:
  149. * 0x21000000 .. 0x21ffffff : PSRAM (16MB)
  150. * AN385/AN386/AN500:
  151. * 0x00000000 .. 0x003fffff : ZBT SSRAM1
  152. * 0x00400000 .. 0x007fffff : mirror of ZBT SSRAM1
  153. * 0x20000000 .. 0x203fffff : ZBT SSRAM 2&3
  154. * 0x20400000 .. 0x207fffff : mirror of ZBT SSRAM 2&3
  155. * AN385/AN386 only:
  156. * 0x01000000 .. 0x01003fff : block RAM (16K)
  157. * 0x01004000 .. 0x01007fff : mirror of above
  158. * 0x01008000 .. 0x0100bfff : mirror of above
  159. * 0x0100c000 .. 0x0100ffff : mirror of above
  160. * AN511 only:
  161. * 0x00000000 .. 0x0003ffff : FPGA block RAM
  162. * 0x00400000 .. 0x007fffff : ZBT SSRAM1
  163. * 0x20000000 .. 0x2001ffff : SRAM
  164. * 0x20400000 .. 0x207fffff : ZBT SSRAM 2&3
  165. * AN500 only:
  166. * 0x60000000 .. 0x60ffffff : PSRAM (16MB)
  167. *
  168. * The AN385/AN386 has a feature where the lowest 16K can be mapped
  169. * either to the bottom of the ZBT SSRAM1 or to the block RAM.
  170. * This is of no use for QEMU so we don't implement it (as if
  171. * zbt_boot_ctrl is always zero).
  172. */
  173. memory_region_add_subregion(system_memory, mmc->psram_base, machine->ram);
  174. if (mmc->has_block_ram) {
  175. make_ram(&mms->blockram, "mps.blockram", 0x01000000, 0x4000);
  176. make_ram_alias(&mms->blockram_m1, "mps.blockram_m1",
  177. &mms->blockram, 0x01004000);
  178. make_ram_alias(&mms->blockram_m2, "mps.blockram_m2",
  179. &mms->blockram, 0x01008000);
  180. make_ram_alias(&mms->blockram_m3, "mps.blockram_m3",
  181. &mms->blockram, 0x0100c000);
  182. }
  183. switch (mmc->fpga_type) {
  184. case FPGA_AN385:
  185. case FPGA_AN386:
  186. case FPGA_AN500:
  187. make_ram(&mms->ssram1, "mps.ssram1", 0x0, 0x400000);
  188. make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", &mms->ssram1, 0x400000);
  189. make_ram(&mms->ssram23, "mps.ssram23", 0x20000000, 0x400000);
  190. make_ram_alias(&mms->ssram23_m, "mps.ssram23_m",
  191. &mms->ssram23, 0x20400000);
  192. break;
  193. case FPGA_AN511:
  194. make_ram(&mms->blockram, "mps.blockram", 0x0, 0x40000);
  195. make_ram(&mms->ssram1, "mps.ssram1", 0x00400000, 0x00800000);
  196. make_ram(&mms->sram, "mps.sram", 0x20000000, 0x20000);
  197. make_ram(&mms->ssram23, "mps.ssram23", 0x20400000, 0x400000);
  198. break;
  199. default:
  200. g_assert_not_reached();
  201. }
  202. object_initialize_child(OBJECT(mms), "armv7m", &mms->armv7m, TYPE_ARMV7M);
  203. armv7m = DEVICE(&mms->armv7m);
  204. switch (mmc->fpga_type) {
  205. case FPGA_AN385:
  206. case FPGA_AN386:
  207. case FPGA_AN500:
  208. qdev_prop_set_uint32(armv7m, "num-irq", 32);
  209. break;
  210. case FPGA_AN511:
  211. qdev_prop_set_uint32(armv7m, "num-irq", 64);
  212. break;
  213. default:
  214. g_assert_not_reached();
  215. }
  216. qdev_connect_clock_in(armv7m, "cpuclk", mms->sysclk);
  217. qdev_connect_clock_in(armv7m, "refclk", mms->refclk);
  218. qdev_prop_set_string(armv7m, "cpu-type", machine->cpu_type);
  219. qdev_prop_set_bit(armv7m, "enable-bitband", true);
  220. object_property_set_link(OBJECT(&mms->armv7m), "memory",
  221. OBJECT(system_memory), &error_abort);
  222. sysbus_realize(SYS_BUS_DEVICE(&mms->armv7m), &error_fatal);
  223. create_unimplemented_device("zbtsmram mirror", 0x00400000, 0x00400000);
  224. create_unimplemented_device("RESERVED 1", 0x00800000, 0x00800000);
  225. create_unimplemented_device("Block RAM", 0x01000000, 0x00010000);
  226. create_unimplemented_device("RESERVED 2", 0x01010000, 0x1EFF0000);
  227. create_unimplemented_device("RESERVED 3", 0x20800000, 0x00800000);
  228. create_unimplemented_device("PSRAM", 0x21000000, 0x01000000);
  229. /* These three ranges all cover multiple devices; we may implement
  230. * some of them below (in which case the real device takes precedence
  231. * over the unimplemented-region mapping).
  232. */
  233. create_unimplemented_device("CMSDK APB peripheral region @0x40000000",
  234. 0x40000000, 0x00010000);
  235. create_unimplemented_device("CMSDK AHB peripheral region @0x40010000",
  236. 0x40010000, 0x00010000);
  237. create_unimplemented_device("Extra peripheral region @0x40020000",
  238. 0x40020000, 0x00010000);
  239. create_unimplemented_device("RESERVED 4", 0x40030000, 0x001D0000);
  240. create_unimplemented_device("VGA", 0x41000000, 0x0200000);
  241. switch (mmc->fpga_type) {
  242. case FPGA_AN385:
  243. case FPGA_AN386:
  244. case FPGA_AN500:
  245. {
  246. /* The overflow IRQs for UARTs 0, 1 and 2 are ORed together.
  247. * Overflow for UARTs 4 and 5 doesn't trigger any interrupt.
  248. */
  249. Object *orgate;
  250. DeviceState *orgate_dev;
  251. orgate = object_new(TYPE_OR_IRQ);
  252. object_property_set_int(orgate, "num-lines", 6, &error_fatal);
  253. qdev_realize(DEVICE(orgate), NULL, &error_fatal);
  254. orgate_dev = DEVICE(orgate);
  255. qdev_connect_gpio_out(orgate_dev, 0, qdev_get_gpio_in(armv7m, 12));
  256. for (i = 0; i < 5; i++) {
  257. DeviceState *dev;
  258. SysBusDevice *s;
  259. static const hwaddr uartbase[] = {0x40004000, 0x40005000,
  260. 0x40006000, 0x40007000,
  261. 0x40009000};
  262. /* RX irq number; TX irq is always one greater */
  263. static const int uartirq[] = {0, 2, 4, 18, 20};
  264. qemu_irq txovrint = NULL, rxovrint = NULL;
  265. if (i < 3) {
  266. txovrint = qdev_get_gpio_in(orgate_dev, i * 2);
  267. rxovrint = qdev_get_gpio_in(orgate_dev, i * 2 + 1);
  268. }
  269. dev = qdev_new(TYPE_CMSDK_APB_UART);
  270. s = SYS_BUS_DEVICE(dev);
  271. qdev_prop_set_chr(dev, "chardev", serial_hd(i));
  272. qdev_prop_set_uint32(dev, "pclk-frq", SYSCLK_FRQ);
  273. sysbus_realize_and_unref(s, &error_fatal);
  274. sysbus_mmio_map(s, 0, uartbase[i]);
  275. sysbus_connect_irq(s, 0, qdev_get_gpio_in(armv7m, uartirq[i] + 1));
  276. sysbus_connect_irq(s, 1, qdev_get_gpio_in(armv7m, uartirq[i]));
  277. sysbus_connect_irq(s, 2, txovrint);
  278. sysbus_connect_irq(s, 3, rxovrint);
  279. }
  280. break;
  281. }
  282. case FPGA_AN511:
  283. {
  284. /* The overflow IRQs for all UARTs are ORed together.
  285. * Tx and Rx IRQs for each UART are ORed together.
  286. */
  287. Object *orgate;
  288. DeviceState *orgate_dev;
  289. orgate = object_new(TYPE_OR_IRQ);
  290. object_property_set_int(orgate, "num-lines", 10, &error_fatal);
  291. qdev_realize(DEVICE(orgate), NULL, &error_fatal);
  292. orgate_dev = DEVICE(orgate);
  293. qdev_connect_gpio_out(orgate_dev, 0, qdev_get_gpio_in(armv7m, 12));
  294. for (i = 0; i < 5; i++) {
  295. /* system irq numbers for the combined tx/rx for each UART */
  296. static const int uart_txrx_irqno[] = {0, 2, 45, 46, 56};
  297. static const hwaddr uartbase[] = {0x40004000, 0x40005000,
  298. 0x4002c000, 0x4002d000,
  299. 0x4002e000};
  300. Object *txrx_orgate;
  301. DeviceState *txrx_orgate_dev, *dev;
  302. SysBusDevice *s;
  303. txrx_orgate = object_new(TYPE_OR_IRQ);
  304. object_property_set_int(txrx_orgate, "num-lines", 2, &error_fatal);
  305. qdev_realize(DEVICE(txrx_orgate), NULL, &error_fatal);
  306. txrx_orgate_dev = DEVICE(txrx_orgate);
  307. qdev_connect_gpio_out(txrx_orgate_dev, 0,
  308. qdev_get_gpio_in(armv7m, uart_txrx_irqno[i]));
  309. dev = qdev_new(TYPE_CMSDK_APB_UART);
  310. s = SYS_BUS_DEVICE(dev);
  311. qdev_prop_set_chr(dev, "chardev", serial_hd(i));
  312. qdev_prop_set_uint32(dev, "pclk-frq", SYSCLK_FRQ);
  313. sysbus_realize_and_unref(s, &error_fatal);
  314. sysbus_mmio_map(s, 0, uartbase[i]);
  315. sysbus_connect_irq(s, 0, qdev_get_gpio_in(txrx_orgate_dev, 0));
  316. sysbus_connect_irq(s, 1, qdev_get_gpio_in(txrx_orgate_dev, 1));
  317. sysbus_connect_irq(s, 2, qdev_get_gpio_in(orgate_dev, i * 2));
  318. sysbus_connect_irq(s, 3, qdev_get_gpio_in(orgate_dev, i * 2 + 1));
  319. }
  320. break;
  321. }
  322. default:
  323. g_assert_not_reached();
  324. }
  325. for (i = 0; i < 4; i++) {
  326. static const hwaddr gpiobase[] = {0x40010000, 0x40011000,
  327. 0x40012000, 0x40013000};
  328. create_unimplemented_device("cmsdk-ahb-gpio", gpiobase[i], 0x1000);
  329. }
  330. /* CMSDK APB subsystem */
  331. for (i = 0; i < ARRAY_SIZE(mms->timer); i++) {
  332. g_autofree char *name = g_strdup_printf("timer%d", i);
  333. hwaddr base = 0x40000000 + i * 0x1000;
  334. int irqno = 8 + i;
  335. SysBusDevice *sbd;
  336. object_initialize_child(OBJECT(mms), name, &mms->timer[i],
  337. TYPE_CMSDK_APB_TIMER);
  338. sbd = SYS_BUS_DEVICE(&mms->timer[i]);
  339. qdev_connect_clock_in(DEVICE(&mms->timer[i]), "pclk", mms->sysclk);
  340. sysbus_realize_and_unref(sbd, &error_fatal);
  341. sysbus_mmio_map(sbd, 0, base);
  342. sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(armv7m, irqno));
  343. }
  344. object_initialize_child(OBJECT(mms), "dualtimer", &mms->dualtimer,
  345. TYPE_CMSDK_APB_DUALTIMER);
  346. qdev_connect_clock_in(DEVICE(&mms->dualtimer), "TIMCLK", mms->sysclk);
  347. sysbus_realize(SYS_BUS_DEVICE(&mms->dualtimer), &error_fatal);
  348. sysbus_connect_irq(SYS_BUS_DEVICE(&mms->dualtimer), 0,
  349. qdev_get_gpio_in(armv7m, 10));
  350. sysbus_mmio_map(SYS_BUS_DEVICE(&mms->dualtimer), 0, 0x40002000);
  351. object_initialize_child(OBJECT(mms), "watchdog", &mms->watchdog,
  352. TYPE_CMSDK_APB_WATCHDOG);
  353. qdev_connect_clock_in(DEVICE(&mms->watchdog), "WDOGCLK", mms->sysclk);
  354. sysbus_realize(SYS_BUS_DEVICE(&mms->watchdog), &error_fatal);
  355. sysbus_connect_irq(SYS_BUS_DEVICE(&mms->watchdog), 0,
  356. qdev_get_gpio_in_named(armv7m, "NMI", 0));
  357. sysbus_mmio_map(SYS_BUS_DEVICE(&mms->watchdog), 0, 0x40008000);
  358. /* FPGA APB subsystem */
  359. object_initialize_child(OBJECT(mms), "scc", &mms->scc, TYPE_MPS2_SCC);
  360. sccdev = DEVICE(&mms->scc);
  361. qdev_prop_set_uint32(sccdev, "scc-cfg4", 0x2);
  362. qdev_prop_set_uint32(sccdev, "scc-aid", 0x00200008);
  363. qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id);
  364. /* All these FPGA images have the same OSCCLK configuration */
  365. oscclk = qlist_new();
  366. qlist_append_int(oscclk, 50000000);
  367. qlist_append_int(oscclk, 24576000);
  368. qlist_append_int(oscclk, 25000000);
  369. qdev_prop_set_array(sccdev, "oscclk", oscclk);
  370. sysbus_realize(SYS_BUS_DEVICE(&mms->scc), &error_fatal);
  371. sysbus_mmio_map(SYS_BUS_DEVICE(sccdev), 0, 0x4002f000);
  372. object_initialize_child(OBJECT(mms), "fpgaio",
  373. &mms->fpgaio, TYPE_MPS2_FPGAIO);
  374. qdev_prop_set_uint32(DEVICE(&mms->fpgaio), "prescale-clk", 25000000);
  375. sysbus_realize(SYS_BUS_DEVICE(&mms->fpgaio), &error_fatal);
  376. sysbus_mmio_map(SYS_BUS_DEVICE(&mms->fpgaio), 0, 0x40028000);
  377. sysbus_create_simple(TYPE_PL022, 0x40025000, /* External ADC */
  378. qdev_get_gpio_in(armv7m, 22));
  379. for (i = 0; i < 2; i++) {
  380. static const int spi_irqno[] = {11, 24};
  381. static const hwaddr spibase[] = {0x40020000, /* APB */
  382. 0x40021000, /* LCD */
  383. 0x40026000, /* Shield0 */
  384. 0x40027000}; /* Shield1 */
  385. DeviceState *orgate_dev;
  386. Object *orgate;
  387. int j;
  388. orgate = object_new(TYPE_OR_IRQ);
  389. object_property_set_int(orgate, "num-lines", 2, &error_fatal);
  390. orgate_dev = DEVICE(orgate);
  391. qdev_realize(orgate_dev, NULL, &error_fatal);
  392. qdev_connect_gpio_out(orgate_dev, 0,
  393. qdev_get_gpio_in(armv7m, spi_irqno[i]));
  394. for (j = 0; j < 2; j++) {
  395. sysbus_create_simple(TYPE_PL022, spibase[2 * i + j],
  396. qdev_get_gpio_in(orgate_dev, j));
  397. }
  398. }
  399. for (i = 0; i < 4; i++) {
  400. static const hwaddr i2cbase[] = {0x40022000, /* Touch */
  401. 0x40023000, /* Audio */
  402. 0x40029000, /* Shield0 */
  403. 0x4002a000}; /* Shield1 */
  404. DeviceState *dev;
  405. dev = sysbus_create_simple(TYPE_ARM_SBCON_I2C, i2cbase[i], NULL);
  406. if (i < 2) {
  407. /*
  408. * internal-only bus: mark it full to avoid user-created
  409. * i2c devices being plugged into it.
  410. */
  411. BusState *qbus = qdev_get_child_bus(dev, "i2c");
  412. qbus_mark_full(qbus);
  413. }
  414. }
  415. create_unimplemented_device("i2s", 0x40024000, 0x400);
  416. /* In hardware this is a LAN9220; the LAN9118 is software compatible
  417. * except that it doesn't support the checksum-offload feature.
  418. */
  419. lan9118_init(mmc->ethernet_base,
  420. qdev_get_gpio_in(armv7m,
  421. mmc->fpga_type == FPGA_AN511 ? 47 : 13));
  422. armv7m_load_kernel(mms->armv7m.cpu, machine->kernel_filename,
  423. 0, 0x400000);
  424. }
  425. static void mps2_class_init(ObjectClass *oc, void *data)
  426. {
  427. MachineClass *mc = MACHINE_CLASS(oc);
  428. mc->init = mps2_common_init;
  429. mc->max_cpus = 1;
  430. mc->default_ram_size = 16 * MiB;
  431. mc->default_ram_id = "mps.ram";
  432. }
  433. static void mps2_an385_class_init(ObjectClass *oc, void *data)
  434. {
  435. MachineClass *mc = MACHINE_CLASS(oc);
  436. MPS2MachineClass *mmc = MPS2_MACHINE_CLASS(oc);
  437. static const char * const valid_cpu_types[] = {
  438. ARM_CPU_TYPE_NAME("cortex-m3"),
  439. NULL
  440. };
  441. mc->desc = "ARM MPS2 with AN385 FPGA image for Cortex-M3";
  442. mmc->fpga_type = FPGA_AN385;
  443. mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3");
  444. mc->valid_cpu_types = valid_cpu_types;
  445. mmc->scc_id = 0x41043850;
  446. mmc->psram_base = 0x21000000;
  447. mmc->ethernet_base = 0x40200000;
  448. mmc->has_block_ram = true;
  449. }
  450. static void mps2_an386_class_init(ObjectClass *oc, void *data)
  451. {
  452. MachineClass *mc = MACHINE_CLASS(oc);
  453. MPS2MachineClass *mmc = MPS2_MACHINE_CLASS(oc);
  454. static const char * const valid_cpu_types[] = {
  455. ARM_CPU_TYPE_NAME("cortex-m4"),
  456. NULL
  457. };
  458. mc->desc = "ARM MPS2 with AN386 FPGA image for Cortex-M4";
  459. mmc->fpga_type = FPGA_AN386;
  460. mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m4");
  461. mc->valid_cpu_types = valid_cpu_types;
  462. mmc->scc_id = 0x41043860;
  463. mmc->psram_base = 0x21000000;
  464. mmc->ethernet_base = 0x40200000;
  465. mmc->has_block_ram = true;
  466. }
  467. static void mps2_an500_class_init(ObjectClass *oc, void *data)
  468. {
  469. MachineClass *mc = MACHINE_CLASS(oc);
  470. MPS2MachineClass *mmc = MPS2_MACHINE_CLASS(oc);
  471. static const char * const valid_cpu_types[] = {
  472. ARM_CPU_TYPE_NAME("cortex-m7"),
  473. NULL
  474. };
  475. mc->desc = "ARM MPS2 with AN500 FPGA image for Cortex-M7";
  476. mmc->fpga_type = FPGA_AN500;
  477. mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m7");
  478. mc->valid_cpu_types = valid_cpu_types;
  479. mmc->scc_id = 0x41045000;
  480. mmc->psram_base = 0x60000000;
  481. mmc->ethernet_base = 0xa0000000;
  482. mmc->has_block_ram = false;
  483. }
  484. static void mps2_an511_class_init(ObjectClass *oc, void *data)
  485. {
  486. MachineClass *mc = MACHINE_CLASS(oc);
  487. MPS2MachineClass *mmc = MPS2_MACHINE_CLASS(oc);
  488. static const char * const valid_cpu_types[] = {
  489. ARM_CPU_TYPE_NAME("cortex-m3"),
  490. NULL
  491. };
  492. mc->desc = "ARM MPS2 with AN511 DesignStart FPGA image for Cortex-M3";
  493. mmc->fpga_type = FPGA_AN511;
  494. mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3");
  495. mc->valid_cpu_types = valid_cpu_types;
  496. mmc->scc_id = 0x41045110;
  497. mmc->psram_base = 0x21000000;
  498. mmc->ethernet_base = 0x40200000;
  499. mmc->has_block_ram = false;
  500. }
  501. static const TypeInfo mps2_info = {
  502. .name = TYPE_MPS2_MACHINE,
  503. .parent = TYPE_MACHINE,
  504. .abstract = true,
  505. .instance_size = sizeof(MPS2MachineState),
  506. .class_size = sizeof(MPS2MachineClass),
  507. .class_init = mps2_class_init,
  508. };
  509. static const TypeInfo mps2_an385_info = {
  510. .name = TYPE_MPS2_AN385_MACHINE,
  511. .parent = TYPE_MPS2_MACHINE,
  512. .class_init = mps2_an385_class_init,
  513. };
  514. static const TypeInfo mps2_an386_info = {
  515. .name = TYPE_MPS2_AN386_MACHINE,
  516. .parent = TYPE_MPS2_MACHINE,
  517. .class_init = mps2_an386_class_init,
  518. };
  519. static const TypeInfo mps2_an500_info = {
  520. .name = TYPE_MPS2_AN500_MACHINE,
  521. .parent = TYPE_MPS2_MACHINE,
  522. .class_init = mps2_an500_class_init,
  523. };
  524. static const TypeInfo mps2_an511_info = {
  525. .name = TYPE_MPS2_AN511_MACHINE,
  526. .parent = TYPE_MPS2_MACHINE,
  527. .class_init = mps2_an511_class_init,
  528. };
  529. static void mps2_machine_init(void)
  530. {
  531. type_register_static(&mps2_info);
  532. type_register_static(&mps2_an385_info);
  533. type_register_static(&mps2_an386_info);
  534. type_register_static(&mps2_an500_info);
  535. type_register_static(&mps2_an511_info);
  536. }
  537. type_init(mps2_machine_init);