mps2-tz.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  1. /*
  2. * ARM V2M MPS2 board emulation, trustzone aware FPGA images
  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. * This source file covers the following FPGA images, for TrustZone cores:
  16. * "mps2-an505" -- Cortex-M33 as documented in ARM Application Note AN505
  17. * "mps2-an521" -- Dual Cortex-M33 as documented in Application Note AN521
  18. * "mps2-an524" -- Dual Cortex-M33 as documented in Application Note AN524
  19. * "mps2-an547" -- Single Cortex-M55 as documented in Application Note AN547
  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/fpga-prototyping-boards/mps2
  24. *
  25. * Board TRM:
  26. * https://developer.arm.com/documentation/100112/latest/
  27. * Application Note AN505:
  28. * https://developer.arm.com/documentation/dai0505/latest/
  29. * Application Note AN521:
  30. * https://developer.arm.com/documentation/dai0521/latest/
  31. * Application Note AN524:
  32. * https://developer.arm.com/documentation/dai0524/latest/
  33. * Application Note AN547:
  34. * https://developer.arm.com/documentation/dai0547/latest/
  35. *
  36. * The AN505 defers to the Cortex-M33 processor ARMv8M IoT Kit FVP User Guide
  37. * (ARM ECM0601256) for the details of some of the device layout:
  38. * https://developer.arm.com/documentation/ecm0601256/latest
  39. * Similarly, the AN521 and AN524 use the SSE-200, and the SSE-200 TRM defines
  40. * most of the device layout:
  41. * https://developer.arm.com/documentation/101104/latest/
  42. * and the AN547 uses the SSE-300, whose layout is in the SSE-300 TRM:
  43. * https://developer.arm.com/documentation/101773/latest/
  44. */
  45. #include "qemu/osdep.h"
  46. #include "qemu/units.h"
  47. #include "qemu/cutils.h"
  48. #include "qapi/error.h"
  49. #include "qobject/qlist.h"
  50. #include "qemu/error-report.h"
  51. #include "hw/arm/boot.h"
  52. #include "hw/arm/armv7m.h"
  53. #include "hw/or-irq.h"
  54. #include "hw/boards.h"
  55. #include "exec/address-spaces.h"
  56. #include "system/system.h"
  57. #include "system/reset.h"
  58. #include "hw/misc/unimp.h"
  59. #include "hw/char/cmsdk-apb-uart.h"
  60. #include "hw/timer/cmsdk-apb-timer.h"
  61. #include "hw/misc/mps2-scc.h"
  62. #include "hw/misc/mps2-fpgaio.h"
  63. #include "hw/misc/tz-mpc.h"
  64. #include "hw/misc/tz-msc.h"
  65. #include "hw/arm/armsse.h"
  66. #include "hw/dma/pl080.h"
  67. #include "hw/rtc/pl031.h"
  68. #include "hw/ssi/pl022.h"
  69. #include "hw/i2c/arm_sbcon_i2c.h"
  70. #include "hw/net/lan9118.h"
  71. #include "net/net.h"
  72. #include "hw/core/split-irq.h"
  73. #include "hw/qdev-clock.h"
  74. #include "qom/object.h"
  75. #include "hw/irq.h"
  76. #define MPS2TZ_NUMIRQ_MAX 96
  77. #define MPS2TZ_RAM_MAX 5
  78. typedef enum MPS2TZFPGAType {
  79. FPGA_AN505,
  80. FPGA_AN521,
  81. FPGA_AN524,
  82. FPGA_AN547,
  83. } MPS2TZFPGAType;
  84. /*
  85. * Define the layout of RAM in a board, including which parts are
  86. * behind which MPCs.
  87. * mrindex specifies the index into mms->ram[] to use for the backing RAM;
  88. * -1 means "use the system RAM".
  89. */
  90. typedef struct RAMInfo {
  91. const char *name;
  92. uint32_t base;
  93. uint32_t size;
  94. int mpc; /* MPC number, -1 for "not behind an MPC" */
  95. int mrindex;
  96. int flags;
  97. } RAMInfo;
  98. /*
  99. * Flag values:
  100. * IS_ALIAS: this RAM area is an alias to the upstream end of the
  101. * MPC specified by its .mpc value
  102. * IS_ROM: this RAM area is read-only
  103. */
  104. #define IS_ALIAS 1
  105. #define IS_ROM 2
  106. struct MPS2TZMachineClass {
  107. MachineClass parent;
  108. MPS2TZFPGAType fpga_type;
  109. uint32_t scc_id;
  110. uint32_t sysclk_frq; /* Main SYSCLK frequency in Hz */
  111. uint32_t apb_periph_frq; /* APB peripheral frequency in Hz */
  112. uint32_t len_oscclk;
  113. const uint32_t *oscclk;
  114. uint32_t fpgaio_num_leds; /* Number of LEDs in FPGAIO LED0 register */
  115. bool fpgaio_has_switches; /* Does FPGAIO have SWITCH register? */
  116. bool fpgaio_has_dbgctrl; /* Does FPGAIO have DBGCTRL register? */
  117. int numirq; /* Number of external interrupts */
  118. int uart_overflow_irq; /* number of the combined UART overflow IRQ */
  119. uint32_t init_svtor; /* init-svtor setting for SSE */
  120. uint32_t sram_addr_width; /* SRAM_ADDR_WIDTH setting for SSE */
  121. uint32_t cpu0_mpu_ns; /* CPU0_MPU_NS setting for SSE */
  122. uint32_t cpu0_mpu_s; /* CPU0_MPU_S setting for SSE */
  123. uint32_t cpu1_mpu_ns; /* CPU1_MPU_NS setting for SSE */
  124. uint32_t cpu1_mpu_s; /* CPU1_MPU_S setting for SSE */
  125. const RAMInfo *raminfo;
  126. const char *armsse_type;
  127. uint32_t boot_ram_size; /* size of ram at address 0; 0 == find in raminfo */
  128. };
  129. struct MPS2TZMachineState {
  130. MachineState parent;
  131. ARMSSE iotkit;
  132. MemoryRegion ram[MPS2TZ_RAM_MAX];
  133. MemoryRegion eth_usb_container;
  134. MPS2SCC scc;
  135. MPS2FPGAIO fpgaio;
  136. TZPPC ppc[5];
  137. TZMPC mpc[3];
  138. PL022State spi[5];
  139. ArmSbconI2CState i2c[5];
  140. UnimplementedDeviceState i2s_audio;
  141. UnimplementedDeviceState gpio[4];
  142. UnimplementedDeviceState gfx;
  143. UnimplementedDeviceState cldc;
  144. UnimplementedDeviceState usb;
  145. PL031State rtc;
  146. PL080State dma[4];
  147. TZMSC msc[4];
  148. CMSDKAPBUART uart[6];
  149. SplitIRQ sec_resp_splitter;
  150. OrIRQState uart_irq_orgate;
  151. DeviceState *lan9118;
  152. SplitIRQ cpu_irq_splitter[MPS2TZ_NUMIRQ_MAX];
  153. Clock *sysclk;
  154. Clock *s32kclk;
  155. bool remap;
  156. qemu_irq remap_irq;
  157. };
  158. #define TYPE_MPS2TZ_MACHINE "mps2tz"
  159. #define TYPE_MPS2TZ_AN505_MACHINE MACHINE_TYPE_NAME("mps2-an505")
  160. #define TYPE_MPS2TZ_AN521_MACHINE MACHINE_TYPE_NAME("mps2-an521")
  161. #define TYPE_MPS3TZ_AN524_MACHINE MACHINE_TYPE_NAME("mps3-an524")
  162. #define TYPE_MPS3TZ_AN547_MACHINE MACHINE_TYPE_NAME("mps3-an547")
  163. OBJECT_DECLARE_TYPE(MPS2TZMachineState, MPS2TZMachineClass, MPS2TZ_MACHINE)
  164. /* Slow 32Khz S32KCLK frequency in Hz */
  165. #define S32KCLK_FRQ (32 * 1000)
  166. /*
  167. * The MPS3 DDR is 2GiB, but on a 32-bit host QEMU doesn't permit
  168. * emulation of that much guest RAM, so artificially make it smaller.
  169. */
  170. #if HOST_LONG_BITS == 32
  171. #define MPS3_DDR_SIZE (1 * GiB)
  172. #else
  173. #define MPS3_DDR_SIZE (2 * GiB)
  174. #endif
  175. /* For cpu{0,1}_mpu_{ns,s}, means "leave at SSE's default value" */
  176. #define MPU_REGION_DEFAULT UINT32_MAX
  177. static const uint32_t an505_oscclk[] = {
  178. 40000000,
  179. 24580000,
  180. 25000000,
  181. };
  182. static const uint32_t an524_oscclk[] = {
  183. 24000000,
  184. 32000000,
  185. 50000000,
  186. 50000000,
  187. 24576000,
  188. 23750000,
  189. };
  190. static const RAMInfo an505_raminfo[] = { {
  191. .name = "ssram-0",
  192. .base = 0x00000000,
  193. .size = 0x00400000,
  194. .mpc = 0,
  195. .mrindex = 0,
  196. }, {
  197. .name = "ssram-1",
  198. .base = 0x28000000,
  199. .size = 0x00200000,
  200. .mpc = 1,
  201. .mrindex = 1,
  202. }, {
  203. .name = "ssram-2",
  204. .base = 0x28200000,
  205. .size = 0x00200000,
  206. .mpc = 2,
  207. .mrindex = 2,
  208. }, {
  209. .name = "ssram-0-alias",
  210. .base = 0x00400000,
  211. .size = 0x00400000,
  212. .mpc = 0,
  213. .mrindex = 3,
  214. .flags = IS_ALIAS,
  215. }, {
  216. /* Use the largest bit of contiguous RAM as our "system memory" */
  217. .name = "mps.ram",
  218. .base = 0x80000000,
  219. .size = 16 * MiB,
  220. .mpc = -1,
  221. .mrindex = -1,
  222. }, {
  223. .name = NULL,
  224. },
  225. };
  226. /*
  227. * Note that the addresses and MPC numbering here should match up
  228. * with those used in remap_memory(), which can swap the BRAM and QSPI.
  229. */
  230. static const RAMInfo an524_raminfo[] = { {
  231. .name = "bram",
  232. .base = 0x00000000,
  233. .size = 512 * KiB,
  234. .mpc = 0,
  235. .mrindex = 0,
  236. }, {
  237. /* We don't model QSPI flash yet; for now expose it as simple ROM */
  238. .name = "QSPI",
  239. .base = 0x28000000,
  240. .size = 8 * MiB,
  241. .mpc = 1,
  242. .mrindex = 1,
  243. .flags = IS_ROM,
  244. }, {
  245. .name = "DDR",
  246. .base = 0x60000000,
  247. .size = MPS3_DDR_SIZE,
  248. .mpc = 2,
  249. .mrindex = -1,
  250. }, {
  251. .name = NULL,
  252. },
  253. };
  254. static const RAMInfo an547_raminfo[] = { {
  255. .name = "sram",
  256. .base = 0x01000000,
  257. .size = 2 * MiB,
  258. .mpc = 0,
  259. .mrindex = 1,
  260. }, {
  261. .name = "sram 2",
  262. .base = 0x21000000,
  263. .size = 4 * MiB,
  264. .mpc = -1,
  265. .mrindex = 3,
  266. }, {
  267. /* We don't model QSPI flash yet; for now expose it as simple ROM */
  268. .name = "QSPI",
  269. .base = 0x28000000,
  270. .size = 8 * MiB,
  271. .mpc = 1,
  272. .mrindex = 4,
  273. .flags = IS_ROM,
  274. }, {
  275. .name = "DDR",
  276. .base = 0x60000000,
  277. .size = MPS3_DDR_SIZE,
  278. .mpc = 2,
  279. .mrindex = -1,
  280. }, {
  281. .name = NULL,
  282. },
  283. };
  284. static const RAMInfo *find_raminfo_for_mpc(MPS2TZMachineState *mms, int mpc)
  285. {
  286. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
  287. const RAMInfo *p;
  288. const RAMInfo *found = NULL;
  289. for (p = mmc->raminfo; p->name; p++) {
  290. if (p->mpc == mpc && !(p->flags & IS_ALIAS)) {
  291. /* There should only be one entry in the array for this MPC */
  292. g_assert(!found);
  293. found = p;
  294. }
  295. }
  296. /* if raminfo array doesn't have an entry for each MPC this is a bug */
  297. assert(found);
  298. return found;
  299. }
  300. static MemoryRegion *mr_for_raminfo(MPS2TZMachineState *mms,
  301. const RAMInfo *raminfo)
  302. {
  303. /* Return an initialized MemoryRegion for the RAMInfo. */
  304. MemoryRegion *ram;
  305. if (raminfo->mrindex < 0) {
  306. /* Means this RAMInfo is for QEMU's "system memory" */
  307. MachineState *machine = MACHINE(mms);
  308. assert(!(raminfo->flags & IS_ROM));
  309. return machine->ram;
  310. }
  311. assert(raminfo->mrindex < MPS2TZ_RAM_MAX);
  312. ram = &mms->ram[raminfo->mrindex];
  313. memory_region_init_ram(ram, NULL, raminfo->name,
  314. raminfo->size, &error_fatal);
  315. if (raminfo->flags & IS_ROM) {
  316. memory_region_set_readonly(ram, true);
  317. }
  318. return ram;
  319. }
  320. /* Create an alias of an entire original MemoryRegion @orig
  321. * located at @base in the memory map.
  322. */
  323. static void make_ram_alias(MemoryRegion *mr, const char *name,
  324. MemoryRegion *orig, hwaddr base)
  325. {
  326. memory_region_init_alias(mr, NULL, name, orig, 0,
  327. memory_region_size(orig));
  328. memory_region_add_subregion(get_system_memory(), base, mr);
  329. }
  330. static qemu_irq get_sse_irq_in(MPS2TZMachineState *mms, int irqno)
  331. {
  332. /*
  333. * Return a qemu_irq which will signal IRQ n to all CPUs in the
  334. * SSE. The irqno should be as the CPU sees it, so the first
  335. * external-to-the-SSE interrupt is 32.
  336. */
  337. MachineClass *mc = MACHINE_GET_CLASS(mms);
  338. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
  339. assert(irqno >= 32 && irqno < (mmc->numirq + 32));
  340. /*
  341. * Convert from "CPU irq number" (as listed in the FPGA image
  342. * documentation) to the SSE external-interrupt number.
  343. */
  344. irqno -= 32;
  345. if (mc->max_cpus > 1) {
  346. return qdev_get_gpio_in(DEVICE(&mms->cpu_irq_splitter[irqno]), 0);
  347. } else {
  348. return qdev_get_gpio_in_named(DEVICE(&mms->iotkit), "EXP_IRQ", irqno);
  349. }
  350. }
  351. /* Union describing the device-specific extra data we pass to the devfn. */
  352. typedef union PPCExtraData {
  353. bool i2c_internal;
  354. } PPCExtraData;
  355. /* Most of the devices in the AN505 FPGA image sit behind
  356. * Peripheral Protection Controllers. These data structures
  357. * define the layout of which devices sit behind which PPCs.
  358. * The devfn for each port is a function which creates, configures
  359. * and initializes the device, returning the MemoryRegion which
  360. * needs to be plugged into the downstream end of the PPC port.
  361. */
  362. typedef MemoryRegion *MakeDevFn(MPS2TZMachineState *mms, void *opaque,
  363. const char *name, hwaddr size,
  364. const int *irqs,
  365. const PPCExtraData *extradata);
  366. typedef struct PPCPortInfo {
  367. const char *name;
  368. MakeDevFn *devfn;
  369. void *opaque;
  370. hwaddr addr;
  371. hwaddr size;
  372. int irqs[3]; /* currently no device needs more IRQ lines than this */
  373. PPCExtraData extradata; /* to pass device-specific info to the devfn */
  374. } PPCPortInfo;
  375. typedef struct PPCInfo {
  376. const char *name;
  377. PPCPortInfo ports[TZ_NUM_PORTS];
  378. } PPCInfo;
  379. static MemoryRegion *make_unimp_dev(MPS2TZMachineState *mms,
  380. void *opaque,
  381. const char *name, hwaddr size,
  382. const int *irqs,
  383. const PPCExtraData *extradata)
  384. {
  385. /* Initialize, configure and realize a TYPE_UNIMPLEMENTED_DEVICE,
  386. * and return a pointer to its MemoryRegion.
  387. */
  388. UnimplementedDeviceState *uds = opaque;
  389. object_initialize_child(OBJECT(mms), name, uds, TYPE_UNIMPLEMENTED_DEVICE);
  390. qdev_prop_set_string(DEVICE(uds), "name", name);
  391. qdev_prop_set_uint64(DEVICE(uds), "size", size);
  392. sysbus_realize(SYS_BUS_DEVICE(uds), &error_fatal);
  393. return sysbus_mmio_get_region(SYS_BUS_DEVICE(uds), 0);
  394. }
  395. static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
  396. const char *name, hwaddr size,
  397. const int *irqs, const PPCExtraData *extradata)
  398. {
  399. /* The irq[] array is rx, tx, combined, in that order */
  400. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
  401. CMSDKAPBUART *uart = opaque;
  402. int i = uart - &mms->uart[0];
  403. SysBusDevice *s;
  404. DeviceState *orgate_dev = DEVICE(&mms->uart_irq_orgate);
  405. object_initialize_child(OBJECT(mms), name, uart, TYPE_CMSDK_APB_UART);
  406. qdev_prop_set_chr(DEVICE(uart), "chardev", serial_hd(i));
  407. qdev_prop_set_uint32(DEVICE(uart), "pclk-frq", mmc->apb_periph_frq);
  408. sysbus_realize(SYS_BUS_DEVICE(uart), &error_fatal);
  409. s = SYS_BUS_DEVICE(uart);
  410. sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[1]));
  411. sysbus_connect_irq(s, 1, get_sse_irq_in(mms, irqs[0]));
  412. sysbus_connect_irq(s, 2, qdev_get_gpio_in(orgate_dev, i * 2));
  413. sysbus_connect_irq(s, 3, qdev_get_gpio_in(orgate_dev, i * 2 + 1));
  414. sysbus_connect_irq(s, 4, get_sse_irq_in(mms, irqs[2]));
  415. return sysbus_mmio_get_region(SYS_BUS_DEVICE(uart), 0);
  416. }
  417. static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
  418. const char *name, hwaddr size,
  419. const int *irqs, const PPCExtraData *extradata)
  420. {
  421. MPS2SCC *scc = opaque;
  422. DeviceState *sccdev;
  423. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
  424. QList *oscclk;
  425. uint32_t i;
  426. object_initialize_child(OBJECT(mms), "scc", scc, TYPE_MPS2_SCC);
  427. sccdev = DEVICE(scc);
  428. qdev_prop_set_uint32(sccdev, "scc-cfg0", mms->remap ? 1 : 0);
  429. qdev_prop_set_uint32(sccdev, "scc-cfg4", 0x2);
  430. qdev_prop_set_uint32(sccdev, "scc-aid", 0x00200008);
  431. qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id);
  432. oscclk = qlist_new();
  433. for (i = 0; i < mmc->len_oscclk; i++) {
  434. qlist_append_int(oscclk, mmc->oscclk[i]);
  435. }
  436. qdev_prop_set_array(sccdev, "oscclk", oscclk);
  437. sysbus_realize(SYS_BUS_DEVICE(scc), &error_fatal);
  438. return sysbus_mmio_get_region(SYS_BUS_DEVICE(sccdev), 0);
  439. }
  440. static MemoryRegion *make_fpgaio(MPS2TZMachineState *mms, void *opaque,
  441. const char *name, hwaddr size,
  442. const int *irqs, const PPCExtraData *extradata)
  443. {
  444. MPS2FPGAIO *fpgaio = opaque;
  445. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
  446. object_initialize_child(OBJECT(mms), "fpgaio", fpgaio, TYPE_MPS2_FPGAIO);
  447. qdev_prop_set_uint32(DEVICE(fpgaio), "num-leds", mmc->fpgaio_num_leds);
  448. qdev_prop_set_bit(DEVICE(fpgaio), "has-switches", mmc->fpgaio_has_switches);
  449. qdev_prop_set_bit(DEVICE(fpgaio), "has-dbgctrl", mmc->fpgaio_has_dbgctrl);
  450. sysbus_realize(SYS_BUS_DEVICE(fpgaio), &error_fatal);
  451. return sysbus_mmio_get_region(SYS_BUS_DEVICE(fpgaio), 0);
  452. }
  453. static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
  454. const char *name, hwaddr size,
  455. const int *irqs,
  456. const PPCExtraData *extradata)
  457. {
  458. SysBusDevice *s;
  459. /* In hardware this is a LAN9220; the LAN9118 is software compatible
  460. * except that it doesn't support the checksum-offload feature.
  461. */
  462. mms->lan9118 = qdev_new(TYPE_LAN9118);
  463. qemu_configure_nic_device(mms->lan9118, true, NULL);
  464. s = SYS_BUS_DEVICE(mms->lan9118);
  465. sysbus_realize_and_unref(s, &error_fatal);
  466. sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
  467. return sysbus_mmio_get_region(s, 0);
  468. }
  469. static MemoryRegion *make_eth_usb(MPS2TZMachineState *mms, void *opaque,
  470. const char *name, hwaddr size,
  471. const int *irqs,
  472. const PPCExtraData *extradata)
  473. {
  474. /*
  475. * The AN524 makes the ethernet and USB share a PPC port.
  476. * irqs[] is the ethernet IRQ.
  477. */
  478. SysBusDevice *s;
  479. memory_region_init(&mms->eth_usb_container, OBJECT(mms),
  480. "mps2-tz-eth-usb-container", 0x200000);
  481. /*
  482. * In hardware this is a LAN9220; the LAN9118 is software compatible
  483. * except that it doesn't support the checksum-offload feature.
  484. */
  485. mms->lan9118 = qdev_new(TYPE_LAN9118);
  486. qemu_configure_nic_device(mms->lan9118, true, NULL);
  487. s = SYS_BUS_DEVICE(mms->lan9118);
  488. sysbus_realize_and_unref(s, &error_fatal);
  489. sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
  490. memory_region_add_subregion(&mms->eth_usb_container,
  491. 0, sysbus_mmio_get_region(s, 0));
  492. /* The USB OTG controller is an ISP1763; we don't have a model of it. */
  493. object_initialize_child(OBJECT(mms), "usb-otg",
  494. &mms->usb, TYPE_UNIMPLEMENTED_DEVICE);
  495. qdev_prop_set_string(DEVICE(&mms->usb), "name", "usb-otg");
  496. qdev_prop_set_uint64(DEVICE(&mms->usb), "size", 0x100000);
  497. s = SYS_BUS_DEVICE(&mms->usb);
  498. sysbus_realize(s, &error_fatal);
  499. memory_region_add_subregion(&mms->eth_usb_container,
  500. 0x100000, sysbus_mmio_get_region(s, 0));
  501. return &mms->eth_usb_container;
  502. }
  503. static MemoryRegion *make_mpc(MPS2TZMachineState *mms, void *opaque,
  504. const char *name, hwaddr size,
  505. const int *irqs, const PPCExtraData *extradata)
  506. {
  507. TZMPC *mpc = opaque;
  508. int i = mpc - &mms->mpc[0];
  509. MemoryRegion *upstream;
  510. const RAMInfo *raminfo = find_raminfo_for_mpc(mms, i);
  511. MemoryRegion *ram = mr_for_raminfo(mms, raminfo);
  512. object_initialize_child(OBJECT(mms), name, mpc, TYPE_TZ_MPC);
  513. object_property_set_link(OBJECT(mpc), "downstream", OBJECT(ram),
  514. &error_fatal);
  515. sysbus_realize(SYS_BUS_DEVICE(mpc), &error_fatal);
  516. /* Map the upstream end of the MPC into system memory */
  517. upstream = sysbus_mmio_get_region(SYS_BUS_DEVICE(mpc), 1);
  518. memory_region_add_subregion(get_system_memory(), raminfo->base, upstream);
  519. /* and connect its interrupt to the IoTKit */
  520. qdev_connect_gpio_out_named(DEVICE(mpc), "irq", 0,
  521. qdev_get_gpio_in_named(DEVICE(&mms->iotkit),
  522. "mpcexp_status", i));
  523. /* Return the register interface MR for our caller to map behind the PPC */
  524. return sysbus_mmio_get_region(SYS_BUS_DEVICE(mpc), 0);
  525. }
  526. static hwaddr boot_mem_base(MPS2TZMachineState *mms)
  527. {
  528. /*
  529. * Return the canonical address of the block which will be mapped
  530. * at address 0x0 (i.e. where the vector table is).
  531. * This is usually 0, but if the AN524 alternate memory map is
  532. * enabled it will be the base address of the QSPI block.
  533. */
  534. return mms->remap ? 0x28000000 : 0;
  535. }
  536. static void remap_memory(MPS2TZMachineState *mms, int map)
  537. {
  538. /*
  539. * Remap the memory for the AN524. 'map' is the value of
  540. * SCC CFG_REG0 bit 0, i.e. 0 for the default map and 1
  541. * for the "option 1" mapping where QSPI is at address 0.
  542. *
  543. * Effectively we need to swap around the "upstream" ends of
  544. * MPC 0 and MPC 1.
  545. */
  546. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
  547. int i;
  548. if (mmc->fpga_type != FPGA_AN524) {
  549. return;
  550. }
  551. memory_region_transaction_begin();
  552. for (i = 0; i < 2; i++) {
  553. TZMPC *mpc = &mms->mpc[i];
  554. MemoryRegion *upstream = sysbus_mmio_get_region(SYS_BUS_DEVICE(mpc), 1);
  555. hwaddr addr = (i ^ map) ? 0x28000000 : 0;
  556. memory_region_set_address(upstream, addr);
  557. }
  558. memory_region_transaction_commit();
  559. }
  560. static void remap_irq_fn(void *opaque, int n, int level)
  561. {
  562. MPS2TZMachineState *mms = opaque;
  563. remap_memory(mms, level);
  564. }
  565. static MemoryRegion *make_dma(MPS2TZMachineState *mms, void *opaque,
  566. const char *name, hwaddr size,
  567. const int *irqs, const PPCExtraData *extradata)
  568. {
  569. /* The irq[] array is DMACINTR, DMACINTERR, DMACINTTC, in that order */
  570. PL080State *dma = opaque;
  571. int i = dma - &mms->dma[0];
  572. SysBusDevice *s;
  573. char *mscname = g_strdup_printf("%s-msc", name);
  574. TZMSC *msc = &mms->msc[i];
  575. DeviceState *iotkitdev = DEVICE(&mms->iotkit);
  576. MemoryRegion *msc_upstream;
  577. MemoryRegion *msc_downstream;
  578. /*
  579. * Each DMA device is a PL081 whose transaction master interface
  580. * is guarded by a Master Security Controller. The downstream end of
  581. * the MSC connects to the IoTKit AHB Slave Expansion port, so the
  582. * DMA devices can see all devices and memory that the CPU does.
  583. */
  584. object_initialize_child(OBJECT(mms), mscname, msc, TYPE_TZ_MSC);
  585. msc_downstream = sysbus_mmio_get_region(SYS_BUS_DEVICE(&mms->iotkit), 0);
  586. object_property_set_link(OBJECT(msc), "downstream",
  587. OBJECT(msc_downstream), &error_fatal);
  588. object_property_set_link(OBJECT(msc), "idau", OBJECT(mms), &error_fatal);
  589. sysbus_realize(SYS_BUS_DEVICE(msc), &error_fatal);
  590. qdev_connect_gpio_out_named(DEVICE(msc), "irq", 0,
  591. qdev_get_gpio_in_named(iotkitdev,
  592. "mscexp_status", i));
  593. qdev_connect_gpio_out_named(iotkitdev, "mscexp_clear", i,
  594. qdev_get_gpio_in_named(DEVICE(msc),
  595. "irq_clear", 0));
  596. qdev_connect_gpio_out_named(iotkitdev, "mscexp_ns", i,
  597. qdev_get_gpio_in_named(DEVICE(msc),
  598. "cfg_nonsec", 0));
  599. qdev_connect_gpio_out(DEVICE(&mms->sec_resp_splitter),
  600. ARRAY_SIZE(mms->ppc) + i,
  601. qdev_get_gpio_in_named(DEVICE(msc),
  602. "cfg_sec_resp", 0));
  603. msc_upstream = sysbus_mmio_get_region(SYS_BUS_DEVICE(msc), 0);
  604. object_initialize_child(OBJECT(mms), name, dma, TYPE_PL081);
  605. object_property_set_link(OBJECT(dma), "downstream", OBJECT(msc_upstream),
  606. &error_fatal);
  607. sysbus_realize(SYS_BUS_DEVICE(dma), &error_fatal);
  608. s = SYS_BUS_DEVICE(dma);
  609. /* Wire up DMACINTR, DMACINTERR, DMACINTTC */
  610. sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
  611. sysbus_connect_irq(s, 1, get_sse_irq_in(mms, irqs[1]));
  612. sysbus_connect_irq(s, 2, get_sse_irq_in(mms, irqs[2]));
  613. g_free(mscname);
  614. return sysbus_mmio_get_region(s, 0);
  615. }
  616. static MemoryRegion *make_spi(MPS2TZMachineState *mms, void *opaque,
  617. const char *name, hwaddr size,
  618. const int *irqs, const PPCExtraData *extradata)
  619. {
  620. /*
  621. * The AN505 has five PL022 SPI controllers.
  622. * One of these should have the LCD controller behind it; the others
  623. * are connected only to the FPGA's "general purpose SPI connector"
  624. * or "shield" expansion connectors.
  625. * Note that if we do implement devices behind SPI, the chip select
  626. * lines are set via the "MISC" register in the MPS2 FPGAIO device.
  627. */
  628. PL022State *spi = opaque;
  629. SysBusDevice *s;
  630. object_initialize_child(OBJECT(mms), name, spi, TYPE_PL022);
  631. sysbus_realize(SYS_BUS_DEVICE(spi), &error_fatal);
  632. s = SYS_BUS_DEVICE(spi);
  633. sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
  634. return sysbus_mmio_get_region(s, 0);
  635. }
  636. static MemoryRegion *make_i2c(MPS2TZMachineState *mms, void *opaque,
  637. const char *name, hwaddr size,
  638. const int *irqs, const PPCExtraData *extradata)
  639. {
  640. ArmSbconI2CState *i2c = opaque;
  641. SysBusDevice *s;
  642. object_initialize_child(OBJECT(mms), name, i2c, TYPE_ARM_SBCON_I2C);
  643. s = SYS_BUS_DEVICE(i2c);
  644. sysbus_realize(s, &error_fatal);
  645. /*
  646. * If this is an internal-use-only i2c bus, mark it full
  647. * so that user-created i2c devices are not plugged into it.
  648. * If we implement models of any on-board i2c devices that
  649. * plug in to one of the internal-use-only buses, then we will
  650. * need to create and plugging those in here before we mark the
  651. * bus as full.
  652. */
  653. if (extradata->i2c_internal) {
  654. BusState *qbus = qdev_get_child_bus(DEVICE(i2c), "i2c");
  655. qbus_mark_full(qbus);
  656. }
  657. return sysbus_mmio_get_region(s, 0);
  658. }
  659. static MemoryRegion *make_rtc(MPS2TZMachineState *mms, void *opaque,
  660. const char *name, hwaddr size,
  661. const int *irqs, const PPCExtraData *extradata)
  662. {
  663. PL031State *pl031 = opaque;
  664. SysBusDevice *s;
  665. object_initialize_child(OBJECT(mms), name, pl031, TYPE_PL031);
  666. s = SYS_BUS_DEVICE(pl031);
  667. sysbus_realize(s, &error_fatal);
  668. /*
  669. * The board docs don't give an IRQ number for the PL031, so
  670. * presumably it is not connected.
  671. */
  672. return sysbus_mmio_get_region(s, 0);
  673. }
  674. static void create_non_mpc_ram(MPS2TZMachineState *mms)
  675. {
  676. /*
  677. * Handle the RAMs which are either not behind MPCs or which are
  678. * aliases to another MPC.
  679. */
  680. const RAMInfo *p;
  681. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
  682. for (p = mmc->raminfo; p->name; p++) {
  683. if (p->flags & IS_ALIAS) {
  684. SysBusDevice *mpc_sbd = SYS_BUS_DEVICE(&mms->mpc[p->mpc]);
  685. MemoryRegion *upstream = sysbus_mmio_get_region(mpc_sbd, 1);
  686. make_ram_alias(&mms->ram[p->mrindex], p->name, upstream, p->base);
  687. } else if (p->mpc == -1) {
  688. /* RAM not behind an MPC */
  689. MemoryRegion *mr = mr_for_raminfo(mms, p);
  690. memory_region_add_subregion(get_system_memory(), p->base, mr);
  691. }
  692. }
  693. }
  694. static uint32_t boot_ram_size(MPS2TZMachineState *mms)
  695. {
  696. /* Return the size of the RAM block at guest address zero */
  697. const RAMInfo *p;
  698. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
  699. /*
  700. * Use a per-board specification (for when the boot RAM is in
  701. * the SSE and so doesn't have a RAMInfo list entry)
  702. */
  703. if (mmc->boot_ram_size) {
  704. return mmc->boot_ram_size;
  705. }
  706. for (p = mmc->raminfo; p->name; p++) {
  707. if (p->base == boot_mem_base(mms)) {
  708. return p->size;
  709. }
  710. }
  711. g_assert_not_reached();
  712. }
  713. static void mps2tz_common_init(MachineState *machine)
  714. {
  715. MPS2TZMachineState *mms = MPS2TZ_MACHINE(machine);
  716. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
  717. MachineClass *mc = MACHINE_GET_CLASS(machine);
  718. MemoryRegion *system_memory = get_system_memory();
  719. DeviceState *iotkitdev;
  720. DeviceState *dev_splitter;
  721. const PPCInfo *ppcs;
  722. int num_ppcs;
  723. int i;
  724. if (machine->ram_size != mc->default_ram_size) {
  725. char *sz = size_to_str(mc->default_ram_size);
  726. error_report("Invalid RAM size, should be %s", sz);
  727. g_free(sz);
  728. exit(EXIT_FAILURE);
  729. }
  730. /* These clocks don't need migration because they are fixed-frequency */
  731. mms->sysclk = clock_new(OBJECT(machine), "SYSCLK");
  732. clock_set_hz(mms->sysclk, mmc->sysclk_frq);
  733. mms->s32kclk = clock_new(OBJECT(machine), "S32KCLK");
  734. clock_set_hz(mms->s32kclk, S32KCLK_FRQ);
  735. object_initialize_child(OBJECT(machine), TYPE_IOTKIT, &mms->iotkit,
  736. mmc->armsse_type);
  737. iotkitdev = DEVICE(&mms->iotkit);
  738. object_property_set_link(OBJECT(&mms->iotkit), "memory",
  739. OBJECT(system_memory), &error_abort);
  740. qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", mmc->numirq);
  741. qdev_prop_set_uint32(iotkitdev, "init-svtor", mmc->init_svtor);
  742. if (mmc->cpu0_mpu_ns != MPU_REGION_DEFAULT) {
  743. qdev_prop_set_uint32(iotkitdev, "CPU0_MPU_NS", mmc->cpu0_mpu_ns);
  744. }
  745. if (mmc->cpu0_mpu_s != MPU_REGION_DEFAULT) {
  746. qdev_prop_set_uint32(iotkitdev, "CPU0_MPU_S", mmc->cpu0_mpu_s);
  747. }
  748. if (object_property_find(OBJECT(iotkitdev), "CPU1_MPU_NS")) {
  749. if (mmc->cpu1_mpu_ns != MPU_REGION_DEFAULT) {
  750. qdev_prop_set_uint32(iotkitdev, "CPU1_MPU_NS", mmc->cpu1_mpu_ns);
  751. }
  752. if (mmc->cpu1_mpu_s != MPU_REGION_DEFAULT) {
  753. qdev_prop_set_uint32(iotkitdev, "CPU1_MPU_S", mmc->cpu1_mpu_s);
  754. }
  755. }
  756. qdev_prop_set_uint32(iotkitdev, "SRAM_ADDR_WIDTH", mmc->sram_addr_width);
  757. qdev_connect_clock_in(iotkitdev, "MAINCLK", mms->sysclk);
  758. qdev_connect_clock_in(iotkitdev, "S32KCLK", mms->s32kclk);
  759. sysbus_realize(SYS_BUS_DEVICE(&mms->iotkit), &error_fatal);
  760. /*
  761. * If this board has more than one CPU, then we need to create splitters
  762. * to feed the IRQ inputs for each CPU in the SSE from each device in the
  763. * board. If there is only one CPU, we can just wire the device IRQ
  764. * directly to the SSE's IRQ input.
  765. */
  766. assert(mmc->numirq <= MPS2TZ_NUMIRQ_MAX);
  767. if (mc->max_cpus > 1) {
  768. for (i = 0; i < mmc->numirq; i++) {
  769. char *name = g_strdup_printf("mps2-irq-splitter%d", i);
  770. SplitIRQ *splitter = &mms->cpu_irq_splitter[i];
  771. object_initialize_child_with_props(OBJECT(machine), name,
  772. splitter, sizeof(*splitter),
  773. TYPE_SPLIT_IRQ, &error_fatal,
  774. NULL);
  775. g_free(name);
  776. object_property_set_int(OBJECT(splitter), "num-lines", 2,
  777. &error_fatal);
  778. qdev_realize(DEVICE(splitter), NULL, &error_fatal);
  779. qdev_connect_gpio_out(DEVICE(splitter), 0,
  780. qdev_get_gpio_in_named(DEVICE(&mms->iotkit),
  781. "EXP_IRQ", i));
  782. qdev_connect_gpio_out(DEVICE(splitter), 1,
  783. qdev_get_gpio_in_named(DEVICE(&mms->iotkit),
  784. "EXP_CPU1_IRQ", i));
  785. }
  786. }
  787. /* The sec_resp_cfg output from the IoTKit must be split into multiple
  788. * lines, one for each of the PPCs we create here, plus one per MSC.
  789. */
  790. object_initialize_child(OBJECT(machine), "sec-resp-splitter",
  791. &mms->sec_resp_splitter, TYPE_SPLIT_IRQ);
  792. object_property_set_int(OBJECT(&mms->sec_resp_splitter), "num-lines",
  793. ARRAY_SIZE(mms->ppc) + ARRAY_SIZE(mms->msc),
  794. &error_fatal);
  795. qdev_realize(DEVICE(&mms->sec_resp_splitter), NULL, &error_fatal);
  796. dev_splitter = DEVICE(&mms->sec_resp_splitter);
  797. qdev_connect_gpio_out_named(iotkitdev, "sec_resp_cfg", 0,
  798. qdev_get_gpio_in(dev_splitter, 0));
  799. /*
  800. * The IoTKit sets up much of the memory layout, including
  801. * the aliases between secure and non-secure regions in the
  802. * address space, and also most of the devices in the system.
  803. * The FPGA itself contains various RAMs and some additional devices.
  804. * The FPGA images have an odd combination of different RAMs,
  805. * because in hardware they are different implementations and
  806. * connected to different buses, giving varying performance/size
  807. * tradeoffs. For QEMU they're all just RAM, though. We arbitrarily
  808. * call the largest lump our "system memory".
  809. */
  810. /*
  811. * The overflow IRQs for all UARTs are ORed together.
  812. * Tx, Rx and "combined" IRQs are sent to the NVIC separately.
  813. * Create the OR gate for this: it has one input for the TX overflow
  814. * and one for the RX overflow for each UART we might have.
  815. * (If the board has fewer than the maximum possible number of UARTs
  816. * those inputs are never wired up and are treated as always-zero.)
  817. */
  818. object_initialize_child(OBJECT(mms), "uart-irq-orgate",
  819. &mms->uart_irq_orgate, TYPE_OR_IRQ);
  820. object_property_set_int(OBJECT(&mms->uart_irq_orgate), "num-lines",
  821. 2 * ARRAY_SIZE(mms->uart),
  822. &error_fatal);
  823. qdev_realize(DEVICE(&mms->uart_irq_orgate), NULL, &error_fatal);
  824. qdev_connect_gpio_out(DEVICE(&mms->uart_irq_orgate), 0,
  825. get_sse_irq_in(mms, mmc->uart_overflow_irq));
  826. /* Most of the devices in the FPGA are behind Peripheral Protection
  827. * Controllers. The required order for initializing things is:
  828. * + initialize the PPC
  829. * + initialize, configure and realize downstream devices
  830. * + connect downstream device MemoryRegions to the PPC
  831. * + realize the PPC
  832. * + map the PPC's MemoryRegions to the places in the address map
  833. * where the downstream devices should appear
  834. * + wire up the PPC's control lines to the IoTKit object
  835. */
  836. const PPCInfo an505_ppcs[] = { {
  837. .name = "apb_ppcexp0",
  838. .ports = {
  839. { "ssram-0-mpc", make_mpc, &mms->mpc[0], 0x58007000, 0x1000 },
  840. { "ssram-1-mpc", make_mpc, &mms->mpc[1], 0x58008000, 0x1000 },
  841. { "ssram-2-mpc", make_mpc, &mms->mpc[2], 0x58009000, 0x1000 },
  842. },
  843. }, {
  844. .name = "apb_ppcexp1",
  845. .ports = {
  846. { "spi0", make_spi, &mms->spi[0], 0x40205000, 0x1000, { 51 } },
  847. { "spi1", make_spi, &mms->spi[1], 0x40206000, 0x1000, { 52 } },
  848. { "spi2", make_spi, &mms->spi[2], 0x40209000, 0x1000, { 53 } },
  849. { "spi3", make_spi, &mms->spi[3], 0x4020a000, 0x1000, { 54 } },
  850. { "spi4", make_spi, &mms->spi[4], 0x4020b000, 0x1000, { 55 } },
  851. { "uart0", make_uart, &mms->uart[0], 0x40200000, 0x1000, { 32, 33, 42 } },
  852. { "uart1", make_uart, &mms->uart[1], 0x40201000, 0x1000, { 34, 35, 43 } },
  853. { "uart2", make_uart, &mms->uart[2], 0x40202000, 0x1000, { 36, 37, 44 } },
  854. { "uart3", make_uart, &mms->uart[3], 0x40203000, 0x1000, { 38, 39, 45 } },
  855. { "uart4", make_uart, &mms->uart[4], 0x40204000, 0x1000, { 40, 41, 46 } },
  856. { "i2c0", make_i2c, &mms->i2c[0], 0x40207000, 0x1000, {},
  857. { .i2c_internal = true /* touchscreen */ } },
  858. { "i2c1", make_i2c, &mms->i2c[1], 0x40208000, 0x1000, {},
  859. { .i2c_internal = true /* audio conf */ } },
  860. { "i2c2", make_i2c, &mms->i2c[2], 0x4020c000, 0x1000, {},
  861. { .i2c_internal = false /* shield 0 */ } },
  862. { "i2c3", make_i2c, &mms->i2c[3], 0x4020d000, 0x1000, {},
  863. { .i2c_internal = false /* shield 1 */ } },
  864. },
  865. }, {
  866. .name = "apb_ppcexp2",
  867. .ports = {
  868. { "scc", make_scc, &mms->scc, 0x40300000, 0x1000 },
  869. { "i2s-audio", make_unimp_dev, &mms->i2s_audio,
  870. 0x40301000, 0x1000 },
  871. { "fpgaio", make_fpgaio, &mms->fpgaio, 0x40302000, 0x1000 },
  872. },
  873. }, {
  874. .name = "ahb_ppcexp0",
  875. .ports = {
  876. { "gfx", make_unimp_dev, &mms->gfx, 0x41000000, 0x140000 },
  877. { "gpio0", make_unimp_dev, &mms->gpio[0], 0x40100000, 0x1000 },
  878. { "gpio1", make_unimp_dev, &mms->gpio[1], 0x40101000, 0x1000 },
  879. { "gpio2", make_unimp_dev, &mms->gpio[2], 0x40102000, 0x1000 },
  880. { "gpio3", make_unimp_dev, &mms->gpio[3], 0x40103000, 0x1000 },
  881. { "eth", make_eth_dev, NULL, 0x42000000, 0x100000, { 48 } },
  882. },
  883. }, {
  884. .name = "ahb_ppcexp1",
  885. .ports = {
  886. { "dma0", make_dma, &mms->dma[0], 0x40110000, 0x1000, { 58, 56, 57 } },
  887. { "dma1", make_dma, &mms->dma[1], 0x40111000, 0x1000, { 61, 59, 60 } },
  888. { "dma2", make_dma, &mms->dma[2], 0x40112000, 0x1000, { 64, 62, 63 } },
  889. { "dma3", make_dma, &mms->dma[3], 0x40113000, 0x1000, { 67, 65, 66 } },
  890. },
  891. },
  892. };
  893. const PPCInfo an524_ppcs[] = { {
  894. .name = "apb_ppcexp0",
  895. .ports = {
  896. { "bram-mpc", make_mpc, &mms->mpc[0], 0x58007000, 0x1000 },
  897. { "qspi-mpc", make_mpc, &mms->mpc[1], 0x58008000, 0x1000 },
  898. { "ddr-mpc", make_mpc, &mms->mpc[2], 0x58009000, 0x1000 },
  899. },
  900. }, {
  901. .name = "apb_ppcexp1",
  902. .ports = {
  903. { "i2c0", make_i2c, &mms->i2c[0], 0x41200000, 0x1000, {},
  904. { .i2c_internal = true /* touchscreen */ } },
  905. { "i2c1", make_i2c, &mms->i2c[1], 0x41201000, 0x1000, {},
  906. { .i2c_internal = true /* audio conf */ } },
  907. { "spi0", make_spi, &mms->spi[0], 0x41202000, 0x1000, { 52 } },
  908. { "spi1", make_spi, &mms->spi[1], 0x41203000, 0x1000, { 53 } },
  909. { "spi2", make_spi, &mms->spi[2], 0x41204000, 0x1000, { 54 } },
  910. { "i2c2", make_i2c, &mms->i2c[2], 0x41205000, 0x1000, {},
  911. { .i2c_internal = false /* shield 0 */ } },
  912. { "i2c3", make_i2c, &mms->i2c[3], 0x41206000, 0x1000, {},
  913. { .i2c_internal = false /* shield 1 */ } },
  914. { /* port 7 reserved */ },
  915. { "i2c4", make_i2c, &mms->i2c[4], 0x41208000, 0x1000, {},
  916. { .i2c_internal = true /* DDR4 EEPROM */ } },
  917. },
  918. }, {
  919. .name = "apb_ppcexp2",
  920. .ports = {
  921. { "scc", make_scc, &mms->scc, 0x41300000, 0x1000 },
  922. { "i2s-audio", make_unimp_dev, &mms->i2s_audio,
  923. 0x41301000, 0x1000 },
  924. { "fpgaio", make_fpgaio, &mms->fpgaio, 0x41302000, 0x1000 },
  925. { "uart0", make_uart, &mms->uart[0], 0x41303000, 0x1000, { 32, 33, 42 } },
  926. { "uart1", make_uart, &mms->uart[1], 0x41304000, 0x1000, { 34, 35, 43 } },
  927. { "uart2", make_uart, &mms->uart[2], 0x41305000, 0x1000, { 36, 37, 44 } },
  928. { "uart3", make_uart, &mms->uart[3], 0x41306000, 0x1000, { 38, 39, 45 } },
  929. { "uart4", make_uart, &mms->uart[4], 0x41307000, 0x1000, { 40, 41, 46 } },
  930. { "uart5", make_uart, &mms->uart[5], 0x41308000, 0x1000, { 124, 125, 126 } },
  931. { /* port 9 reserved */ },
  932. { "clcd", make_unimp_dev, &mms->cldc, 0x4130a000, 0x1000 },
  933. { "rtc", make_rtc, &mms->rtc, 0x4130b000, 0x1000 },
  934. },
  935. }, {
  936. .name = "ahb_ppcexp0",
  937. .ports = {
  938. { "gpio0", make_unimp_dev, &mms->gpio[0], 0x41100000, 0x1000 },
  939. { "gpio1", make_unimp_dev, &mms->gpio[1], 0x41101000, 0x1000 },
  940. { "gpio2", make_unimp_dev, &mms->gpio[2], 0x41102000, 0x1000 },
  941. { "gpio3", make_unimp_dev, &mms->gpio[3], 0x41103000, 0x1000 },
  942. { "eth-usb", make_eth_usb, NULL, 0x41400000, 0x200000, { 48 } },
  943. },
  944. },
  945. };
  946. const PPCInfo an547_ppcs[] = { {
  947. .name = "apb_ppcexp0",
  948. .ports = {
  949. { "ssram-mpc", make_mpc, &mms->mpc[0], 0x57000000, 0x1000 },
  950. { "qspi-mpc", make_mpc, &mms->mpc[1], 0x57001000, 0x1000 },
  951. { "ddr-mpc", make_mpc, &mms->mpc[2], 0x57002000, 0x1000 },
  952. },
  953. }, {
  954. .name = "apb_ppcexp1",
  955. .ports = {
  956. { "i2c0", make_i2c, &mms->i2c[0], 0x49200000, 0x1000, {},
  957. { .i2c_internal = true /* touchscreen */ } },
  958. { "i2c1", make_i2c, &mms->i2c[1], 0x49201000, 0x1000, {},
  959. { .i2c_internal = true /* audio conf */ } },
  960. { "spi0", make_spi, &mms->spi[0], 0x49202000, 0x1000, { 53 } },
  961. { "spi1", make_spi, &mms->spi[1], 0x49203000, 0x1000, { 54 } },
  962. { "spi2", make_spi, &mms->spi[2], 0x49204000, 0x1000, { 55 } },
  963. { "i2c2", make_i2c, &mms->i2c[2], 0x49205000, 0x1000, {},
  964. { .i2c_internal = false /* shield 0 */ } },
  965. { "i2c3", make_i2c, &mms->i2c[3], 0x49206000, 0x1000, {},
  966. { .i2c_internal = false /* shield 1 */ } },
  967. { /* port 7 reserved */ },
  968. { "i2c4", make_i2c, &mms->i2c[4], 0x49208000, 0x1000, {},
  969. { .i2c_internal = true /* DDR4 EEPROM */ } },
  970. },
  971. }, {
  972. .name = "apb_ppcexp2",
  973. .ports = {
  974. { "scc", make_scc, &mms->scc, 0x49300000, 0x1000 },
  975. { "i2s-audio", make_unimp_dev, &mms->i2s_audio, 0x49301000, 0x1000 },
  976. { "fpgaio", make_fpgaio, &mms->fpgaio, 0x49302000, 0x1000 },
  977. { "uart0", make_uart, &mms->uart[0], 0x49303000, 0x1000, { 33, 34, 43 } },
  978. { "uart1", make_uart, &mms->uart[1], 0x49304000, 0x1000, { 35, 36, 44 } },
  979. { "uart2", make_uart, &mms->uart[2], 0x49305000, 0x1000, { 37, 38, 45 } },
  980. { "uart3", make_uart, &mms->uart[3], 0x49306000, 0x1000, { 39, 40, 46 } },
  981. { "uart4", make_uart, &mms->uart[4], 0x49307000, 0x1000, { 41, 42, 47 } },
  982. { "uart5", make_uart, &mms->uart[5], 0x49308000, 0x1000, { 125, 126, 127 } },
  983. { /* port 9 reserved */ },
  984. { "clcd", make_unimp_dev, &mms->cldc, 0x4930a000, 0x1000 },
  985. { "rtc", make_rtc, &mms->rtc, 0x4930b000, 0x1000 },
  986. },
  987. }, {
  988. .name = "ahb_ppcexp0",
  989. .ports = {
  990. { "gpio0", make_unimp_dev, &mms->gpio[0], 0x41100000, 0x1000 },
  991. { "gpio1", make_unimp_dev, &mms->gpio[1], 0x41101000, 0x1000 },
  992. { "gpio2", make_unimp_dev, &mms->gpio[2], 0x41102000, 0x1000 },
  993. { "gpio3", make_unimp_dev, &mms->gpio[3], 0x41103000, 0x1000 },
  994. { /* port 4 USER AHB interface 0 */ },
  995. { /* port 5 USER AHB interface 1 */ },
  996. { /* port 6 USER AHB interface 2 */ },
  997. { /* port 7 USER AHB interface 3 */ },
  998. { "eth-usb", make_eth_usb, NULL, 0x41400000, 0x200000, { 49 } },
  999. },
  1000. },
  1001. };
  1002. switch (mmc->fpga_type) {
  1003. case FPGA_AN505:
  1004. case FPGA_AN521:
  1005. ppcs = an505_ppcs;
  1006. num_ppcs = ARRAY_SIZE(an505_ppcs);
  1007. break;
  1008. case FPGA_AN524:
  1009. ppcs = an524_ppcs;
  1010. num_ppcs = ARRAY_SIZE(an524_ppcs);
  1011. break;
  1012. case FPGA_AN547:
  1013. ppcs = an547_ppcs;
  1014. num_ppcs = ARRAY_SIZE(an547_ppcs);
  1015. break;
  1016. default:
  1017. g_assert_not_reached();
  1018. }
  1019. for (i = 0; i < num_ppcs; i++) {
  1020. const PPCInfo *ppcinfo = &ppcs[i];
  1021. TZPPC *ppc = &mms->ppc[i];
  1022. DeviceState *ppcdev;
  1023. int port;
  1024. char *gpioname;
  1025. object_initialize_child(OBJECT(machine), ppcinfo->name, ppc,
  1026. TYPE_TZ_PPC);
  1027. ppcdev = DEVICE(ppc);
  1028. for (port = 0; port < TZ_NUM_PORTS; port++) {
  1029. const PPCPortInfo *pinfo = &ppcinfo->ports[port];
  1030. MemoryRegion *mr;
  1031. char *portname;
  1032. if (!pinfo->devfn) {
  1033. continue;
  1034. }
  1035. mr = pinfo->devfn(mms, pinfo->opaque, pinfo->name, pinfo->size,
  1036. pinfo->irqs, &pinfo->extradata);
  1037. portname = g_strdup_printf("port[%d]", port);
  1038. object_property_set_link(OBJECT(ppc), portname, OBJECT(mr),
  1039. &error_fatal);
  1040. g_free(portname);
  1041. }
  1042. sysbus_realize(SYS_BUS_DEVICE(ppc), &error_fatal);
  1043. for (port = 0; port < TZ_NUM_PORTS; port++) {
  1044. const PPCPortInfo *pinfo = &ppcinfo->ports[port];
  1045. if (!pinfo->devfn) {
  1046. continue;
  1047. }
  1048. sysbus_mmio_map(SYS_BUS_DEVICE(ppc), port, pinfo->addr);
  1049. gpioname = g_strdup_printf("%s_nonsec", ppcinfo->name);
  1050. qdev_connect_gpio_out_named(iotkitdev, gpioname, port,
  1051. qdev_get_gpio_in_named(ppcdev,
  1052. "cfg_nonsec",
  1053. port));
  1054. g_free(gpioname);
  1055. gpioname = g_strdup_printf("%s_ap", ppcinfo->name);
  1056. qdev_connect_gpio_out_named(iotkitdev, gpioname, port,
  1057. qdev_get_gpio_in_named(ppcdev,
  1058. "cfg_ap", port));
  1059. g_free(gpioname);
  1060. }
  1061. gpioname = g_strdup_printf("%s_irq_enable", ppcinfo->name);
  1062. qdev_connect_gpio_out_named(iotkitdev, gpioname, 0,
  1063. qdev_get_gpio_in_named(ppcdev,
  1064. "irq_enable", 0));
  1065. g_free(gpioname);
  1066. gpioname = g_strdup_printf("%s_irq_clear", ppcinfo->name);
  1067. qdev_connect_gpio_out_named(iotkitdev, gpioname, 0,
  1068. qdev_get_gpio_in_named(ppcdev,
  1069. "irq_clear", 0));
  1070. g_free(gpioname);
  1071. gpioname = g_strdup_printf("%s_irq_status", ppcinfo->name);
  1072. qdev_connect_gpio_out_named(ppcdev, "irq", 0,
  1073. qdev_get_gpio_in_named(iotkitdev,
  1074. gpioname, 0));
  1075. g_free(gpioname);
  1076. qdev_connect_gpio_out(dev_splitter, i,
  1077. qdev_get_gpio_in_named(ppcdev,
  1078. "cfg_sec_resp", 0));
  1079. }
  1080. create_unimplemented_device("FPGA NS PC", 0x48007000, 0x1000);
  1081. if (mmc->fpga_type == FPGA_AN547) {
  1082. create_unimplemented_device("U55 timing adapter 0", 0x48102000, 0x1000);
  1083. create_unimplemented_device("U55 timing adapter 1", 0x48103000, 0x1000);
  1084. }
  1085. create_non_mpc_ram(mms);
  1086. if (mmc->fpga_type == FPGA_AN524) {
  1087. /*
  1088. * Connect the line from the SCC so that we can remap when the
  1089. * guest updates that register.
  1090. */
  1091. mms->remap_irq = qemu_allocate_irq(remap_irq_fn, mms, 0);
  1092. qdev_connect_gpio_out_named(DEVICE(&mms->scc), "remap", 0,
  1093. mms->remap_irq);
  1094. }
  1095. armv7m_load_kernel(mms->iotkit.armv7m[0].cpu, machine->kernel_filename,
  1096. 0, boot_ram_size(mms));
  1097. }
  1098. static void mps2_tz_idau_check(IDAUInterface *ii, uint32_t address,
  1099. int *iregion, bool *exempt, bool *ns, bool *nsc)
  1100. {
  1101. /*
  1102. * The MPS2 TZ FPGA images have IDAUs in them which are connected to
  1103. * the Master Security Controllers. These have the same logic as
  1104. * is used by the IoTKit for the IDAU connected to the CPU, except
  1105. * that MSCs don't care about the NSC attribute.
  1106. */
  1107. int region = extract32(address, 28, 4);
  1108. *ns = !(region & 1);
  1109. *nsc = false;
  1110. /* 0xe0000000..0xe00fffff and 0xf0000000..0xf00fffff are exempt */
  1111. *exempt = (address & 0xeff00000) == 0xe0000000;
  1112. *iregion = region;
  1113. }
  1114. static char *mps2_get_remap(Object *obj, Error **errp)
  1115. {
  1116. MPS2TZMachineState *mms = MPS2TZ_MACHINE(obj);
  1117. const char *val = mms->remap ? "QSPI" : "BRAM";
  1118. return g_strdup(val);
  1119. }
  1120. static void mps2_set_remap(Object *obj, const char *value, Error **errp)
  1121. {
  1122. MPS2TZMachineState *mms = MPS2TZ_MACHINE(obj);
  1123. if (!strcmp(value, "BRAM")) {
  1124. mms->remap = false;
  1125. } else if (!strcmp(value, "QSPI")) {
  1126. mms->remap = true;
  1127. } else {
  1128. error_setg(errp, "Invalid remap value");
  1129. error_append_hint(errp, "Valid values are BRAM and QSPI.\n");
  1130. }
  1131. }
  1132. static void mps2_machine_reset(MachineState *machine, ResetType type)
  1133. {
  1134. MPS2TZMachineState *mms = MPS2TZ_MACHINE(machine);
  1135. /*
  1136. * Set the initial memory mapping before triggering the reset of
  1137. * the rest of the system, so that the guest image loader and CPU
  1138. * reset see the correct mapping.
  1139. */
  1140. remap_memory(mms, mms->remap);
  1141. qemu_devices_reset(type);
  1142. }
  1143. static void mps2tz_class_init(ObjectClass *oc, void *data)
  1144. {
  1145. MachineClass *mc = MACHINE_CLASS(oc);
  1146. IDAUInterfaceClass *iic = IDAU_INTERFACE_CLASS(oc);
  1147. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_CLASS(oc);
  1148. mc->init = mps2tz_common_init;
  1149. mc->reset = mps2_machine_reset;
  1150. iic->check = mps2_tz_idau_check;
  1151. /* Most machines leave these at the SSE defaults */
  1152. mmc->cpu0_mpu_ns = MPU_REGION_DEFAULT;
  1153. mmc->cpu0_mpu_s = MPU_REGION_DEFAULT;
  1154. mmc->cpu1_mpu_ns = MPU_REGION_DEFAULT;
  1155. mmc->cpu1_mpu_s = MPU_REGION_DEFAULT;
  1156. }
  1157. static void mps2tz_set_default_ram_info(MPS2TZMachineClass *mmc)
  1158. {
  1159. /*
  1160. * Set mc->default_ram_size and default_ram_id from the
  1161. * information in mmc->raminfo.
  1162. */
  1163. MachineClass *mc = MACHINE_CLASS(mmc);
  1164. const RAMInfo *p;
  1165. for (p = mmc->raminfo; p->name; p++) {
  1166. if (p->mrindex < 0) {
  1167. /* Found the entry for "system memory" */
  1168. mc->default_ram_size = p->size;
  1169. mc->default_ram_id = p->name;
  1170. return;
  1171. }
  1172. }
  1173. g_assert_not_reached();
  1174. }
  1175. static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
  1176. {
  1177. MachineClass *mc = MACHINE_CLASS(oc);
  1178. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_CLASS(oc);
  1179. static const char * const valid_cpu_types[] = {
  1180. ARM_CPU_TYPE_NAME("cortex-m33"),
  1181. NULL
  1182. };
  1183. mc->desc = "ARM MPS2 with AN505 FPGA image for Cortex-M33";
  1184. mc->default_cpus = 1;
  1185. mc->min_cpus = mc->default_cpus;
  1186. mc->max_cpus = mc->default_cpus;
  1187. mmc->fpga_type = FPGA_AN505;
  1188. mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
  1189. mc->valid_cpu_types = valid_cpu_types;
  1190. mmc->scc_id = 0x41045050;
  1191. mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
  1192. mmc->apb_periph_frq = mmc->sysclk_frq;
  1193. mmc->oscclk = an505_oscclk;
  1194. mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
  1195. mmc->fpgaio_num_leds = 2;
  1196. mmc->fpgaio_has_switches = false;
  1197. mmc->fpgaio_has_dbgctrl = false;
  1198. mmc->numirq = 92;
  1199. mmc->uart_overflow_irq = 47;
  1200. mmc->init_svtor = 0x10000000;
  1201. mmc->sram_addr_width = 15;
  1202. mmc->raminfo = an505_raminfo;
  1203. mmc->armsse_type = TYPE_IOTKIT;
  1204. mmc->boot_ram_size = 0;
  1205. mps2tz_set_default_ram_info(mmc);
  1206. }
  1207. static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
  1208. {
  1209. MachineClass *mc = MACHINE_CLASS(oc);
  1210. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_CLASS(oc);
  1211. static const char * const valid_cpu_types[] = {
  1212. ARM_CPU_TYPE_NAME("cortex-m33"),
  1213. NULL
  1214. };
  1215. mc->desc = "ARM MPS2 with AN521 FPGA image for dual Cortex-M33";
  1216. mc->default_cpus = 2;
  1217. mc->min_cpus = mc->default_cpus;
  1218. mc->max_cpus = mc->default_cpus;
  1219. mmc->fpga_type = FPGA_AN521;
  1220. mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
  1221. mc->valid_cpu_types = valid_cpu_types;
  1222. mmc->scc_id = 0x41045210;
  1223. mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
  1224. mmc->apb_periph_frq = mmc->sysclk_frq;
  1225. mmc->oscclk = an505_oscclk; /* AN521 is the same as AN505 here */
  1226. mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
  1227. mmc->fpgaio_num_leds = 2;
  1228. mmc->fpgaio_has_switches = false;
  1229. mmc->fpgaio_has_dbgctrl = false;
  1230. mmc->numirq = 92;
  1231. mmc->uart_overflow_irq = 47;
  1232. mmc->init_svtor = 0x10000000;
  1233. mmc->sram_addr_width = 15;
  1234. mmc->raminfo = an505_raminfo; /* AN521 is the same as AN505 here */
  1235. mmc->armsse_type = TYPE_SSE200;
  1236. mmc->boot_ram_size = 0;
  1237. mps2tz_set_default_ram_info(mmc);
  1238. }
  1239. static void mps3tz_an524_class_init(ObjectClass *oc, void *data)
  1240. {
  1241. MachineClass *mc = MACHINE_CLASS(oc);
  1242. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_CLASS(oc);
  1243. static const char * const valid_cpu_types[] = {
  1244. ARM_CPU_TYPE_NAME("cortex-m33"),
  1245. NULL
  1246. };
  1247. mc->desc = "ARM MPS3 with AN524 FPGA image for dual Cortex-M33";
  1248. mc->default_cpus = 2;
  1249. mc->min_cpus = mc->default_cpus;
  1250. mc->max_cpus = mc->default_cpus;
  1251. mmc->fpga_type = FPGA_AN524;
  1252. mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
  1253. mc->valid_cpu_types = valid_cpu_types;
  1254. mmc->scc_id = 0x41045240;
  1255. mmc->sysclk_frq = 32 * 1000 * 1000; /* 32MHz */
  1256. mmc->apb_periph_frq = mmc->sysclk_frq;
  1257. mmc->oscclk = an524_oscclk;
  1258. mmc->len_oscclk = ARRAY_SIZE(an524_oscclk);
  1259. mmc->fpgaio_num_leds = 10;
  1260. mmc->fpgaio_has_switches = true;
  1261. mmc->fpgaio_has_dbgctrl = false;
  1262. mmc->numirq = 95;
  1263. mmc->uart_overflow_irq = 47;
  1264. mmc->init_svtor = 0x10000000;
  1265. mmc->sram_addr_width = 15;
  1266. mmc->raminfo = an524_raminfo;
  1267. mmc->armsse_type = TYPE_SSE200;
  1268. mmc->boot_ram_size = 0;
  1269. mps2tz_set_default_ram_info(mmc);
  1270. object_class_property_add_str(oc, "remap", mps2_get_remap, mps2_set_remap);
  1271. object_class_property_set_description(oc, "remap",
  1272. "Set memory mapping. Valid values "
  1273. "are BRAM (default) and QSPI.");
  1274. }
  1275. static void mps3tz_an547_class_init(ObjectClass *oc, void *data)
  1276. {
  1277. MachineClass *mc = MACHINE_CLASS(oc);
  1278. MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_CLASS(oc);
  1279. static const char * const valid_cpu_types[] = {
  1280. ARM_CPU_TYPE_NAME("cortex-m55"),
  1281. NULL
  1282. };
  1283. mc->desc = "ARM MPS3 with AN547 FPGA image for Cortex-M55";
  1284. mc->default_cpus = 1;
  1285. mc->min_cpus = mc->default_cpus;
  1286. mc->max_cpus = mc->default_cpus;
  1287. mmc->fpga_type = FPGA_AN547;
  1288. mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m55");
  1289. mc->valid_cpu_types = valid_cpu_types;
  1290. mmc->scc_id = 0x41055470;
  1291. mmc->sysclk_frq = 32 * 1000 * 1000; /* 32MHz */
  1292. mmc->apb_periph_frq = 25 * 1000 * 1000; /* 25MHz */
  1293. mmc->oscclk = an524_oscclk; /* same as AN524 */
  1294. mmc->len_oscclk = ARRAY_SIZE(an524_oscclk);
  1295. mmc->fpgaio_num_leds = 10;
  1296. mmc->fpgaio_has_switches = true;
  1297. mmc->fpgaio_has_dbgctrl = true;
  1298. mmc->numirq = 96;
  1299. mmc->uart_overflow_irq = 48;
  1300. mmc->init_svtor = 0x00000000;
  1301. mmc->cpu0_mpu_s = mmc->cpu0_mpu_ns = 16;
  1302. mmc->sram_addr_width = 21;
  1303. mmc->raminfo = an547_raminfo;
  1304. mmc->armsse_type = TYPE_SSE300;
  1305. mmc->boot_ram_size = 512 * KiB;
  1306. mps2tz_set_default_ram_info(mmc);
  1307. }
  1308. static const TypeInfo mps2tz_info = {
  1309. .name = TYPE_MPS2TZ_MACHINE,
  1310. .parent = TYPE_MACHINE,
  1311. .abstract = true,
  1312. .instance_size = sizeof(MPS2TZMachineState),
  1313. .class_size = sizeof(MPS2TZMachineClass),
  1314. .class_init = mps2tz_class_init,
  1315. .interfaces = (InterfaceInfo[]) {
  1316. { TYPE_IDAU_INTERFACE },
  1317. { }
  1318. },
  1319. };
  1320. static const TypeInfo mps2tz_an505_info = {
  1321. .name = TYPE_MPS2TZ_AN505_MACHINE,
  1322. .parent = TYPE_MPS2TZ_MACHINE,
  1323. .class_init = mps2tz_an505_class_init,
  1324. };
  1325. static const TypeInfo mps2tz_an521_info = {
  1326. .name = TYPE_MPS2TZ_AN521_MACHINE,
  1327. .parent = TYPE_MPS2TZ_MACHINE,
  1328. .class_init = mps2tz_an521_class_init,
  1329. };
  1330. static const TypeInfo mps3tz_an524_info = {
  1331. .name = TYPE_MPS3TZ_AN524_MACHINE,
  1332. .parent = TYPE_MPS2TZ_MACHINE,
  1333. .class_init = mps3tz_an524_class_init,
  1334. };
  1335. static const TypeInfo mps3tz_an547_info = {
  1336. .name = TYPE_MPS3TZ_AN547_MACHINE,
  1337. .parent = TYPE_MPS2TZ_MACHINE,
  1338. .class_init = mps3tz_an547_class_init,
  1339. };
  1340. static void mps2tz_machine_init(void)
  1341. {
  1342. type_register_static(&mps2tz_info);
  1343. type_register_static(&mps2tz_an505_info);
  1344. type_register_static(&mps2tz_an521_info);
  1345. type_register_static(&mps3tz_an524_info);
  1346. type_register_static(&mps3tz_an547_info);
  1347. }
  1348. type_init(mps2tz_machine_init);