armsse.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  1. /*
  2. * Arm SSE (Subsystems for Embedded): IoTKit
  3. *
  4. * Copyright (c) 2018 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. #include "qemu/osdep.h"
  12. #include "qemu/log.h"
  13. #include "qemu/module.h"
  14. #include "qemu/bitops.h"
  15. #include "qemu/units.h"
  16. #include "qapi/error.h"
  17. #include "trace.h"
  18. #include "hw/sysbus.h"
  19. #include "migration/vmstate.h"
  20. #include "hw/registerfields.h"
  21. #include "hw/arm/armsse.h"
  22. #include "hw/arm/armsse-version.h"
  23. #include "hw/arm/boot.h"
  24. #include "hw/irq.h"
  25. #include "hw/qdev-clock.h"
  26. /*
  27. * The SSE-300 puts some devices in different places to the
  28. * SSE-200 (and original IoTKit). We use an array of these structs
  29. * to define how each variant lays out these devices. (Parts of the
  30. * SoC that are the same for all variants aren't handled via these
  31. * data structures.)
  32. */
  33. #define NO_IRQ -1
  34. #define NO_PPC -1
  35. /*
  36. * Special values for ARMSSEDeviceInfo::irq to indicate that this
  37. * device uses one of the inputs to the OR gate that feeds into the
  38. * CPU NMI input.
  39. */
  40. #define NMI_0 10000
  41. #define NMI_1 10001
  42. typedef struct ARMSSEDeviceInfo {
  43. const char *name; /* name to use for the QOM object; NULL terminates list */
  44. const char *type; /* QOM type name */
  45. unsigned int index; /* Which of the N devices of this type is this ? */
  46. hwaddr addr;
  47. hwaddr size; /* only needed for TYPE_UNIMPLEMENTED_DEVICE */
  48. int ppc; /* Index of APB PPC this device is wired up to, or NO_PPC */
  49. int ppc_port; /* Port number of this device on the PPC */
  50. int irq; /* NO_IRQ, or 0..NUM_SSE_IRQS-1, or NMI_0 or NMI_1 */
  51. bool slowclk; /* true if device uses the slow 32KHz clock */
  52. } ARMSSEDeviceInfo;
  53. struct ARMSSEInfo {
  54. const char *name;
  55. const char *cpu_type;
  56. uint32_t sse_version;
  57. int sram_banks;
  58. uint32_t sram_bank_base;
  59. int num_cpus;
  60. uint32_t sys_version;
  61. uint32_t iidr;
  62. uint32_t cpuwait_rst;
  63. bool has_mhus;
  64. bool has_cachectrl;
  65. bool has_cpusecctrl;
  66. bool has_cpuid;
  67. bool has_cpu_pwrctrl;
  68. bool has_sse_counter;
  69. bool has_tcms;
  70. Property *props;
  71. const ARMSSEDeviceInfo *devinfo;
  72. const bool *irq_is_common;
  73. };
  74. static Property iotkit_properties[] = {
  75. DEFINE_PROP_LINK("memory", ARMSSE, board_memory, TYPE_MEMORY_REGION,
  76. MemoryRegion *),
  77. DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE, exp_numirq, 64),
  78. DEFINE_PROP_UINT32("SRAM_ADDR_WIDTH", ARMSSE, sram_addr_width, 15),
  79. DEFINE_PROP_UINT32("init-svtor", ARMSSE, init_svtor, 0x10000000),
  80. DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], true),
  81. DEFINE_PROP_BOOL("CPU0_DSP", ARMSSE, cpu_dsp[0], true),
  82. DEFINE_PROP_UINT32("CPU0_MPU_NS", ARMSSE, cpu_mpu_ns[0], 8),
  83. DEFINE_PROP_UINT32("CPU0_MPU_S", ARMSSE, cpu_mpu_s[0], 8),
  84. DEFINE_PROP_END_OF_LIST()
  85. };
  86. static Property sse200_properties[] = {
  87. DEFINE_PROP_LINK("memory", ARMSSE, board_memory, TYPE_MEMORY_REGION,
  88. MemoryRegion *),
  89. DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE, exp_numirq, 64),
  90. DEFINE_PROP_UINT32("SRAM_ADDR_WIDTH", ARMSSE, sram_addr_width, 15),
  91. DEFINE_PROP_UINT32("init-svtor", ARMSSE, init_svtor, 0x10000000),
  92. DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], false),
  93. DEFINE_PROP_BOOL("CPU0_DSP", ARMSSE, cpu_dsp[0], false),
  94. DEFINE_PROP_BOOL("CPU1_FPU", ARMSSE, cpu_fpu[1], true),
  95. DEFINE_PROP_BOOL("CPU1_DSP", ARMSSE, cpu_dsp[1], true),
  96. DEFINE_PROP_UINT32("CPU0_MPU_NS", ARMSSE, cpu_mpu_ns[0], 8),
  97. DEFINE_PROP_UINT32("CPU0_MPU_S", ARMSSE, cpu_mpu_s[0], 8),
  98. DEFINE_PROP_UINT32("CPU1_MPU_NS", ARMSSE, cpu_mpu_ns[1], 8),
  99. DEFINE_PROP_UINT32("CPU1_MPU_S", ARMSSE, cpu_mpu_s[1], 8),
  100. DEFINE_PROP_END_OF_LIST()
  101. };
  102. static Property sse300_properties[] = {
  103. DEFINE_PROP_LINK("memory", ARMSSE, board_memory, TYPE_MEMORY_REGION,
  104. MemoryRegion *),
  105. DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE, exp_numirq, 64),
  106. DEFINE_PROP_UINT32("SRAM_ADDR_WIDTH", ARMSSE, sram_addr_width, 18),
  107. DEFINE_PROP_UINT32("init-svtor", ARMSSE, init_svtor, 0x10000000),
  108. DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], true),
  109. DEFINE_PROP_BOOL("CPU0_DSP", ARMSSE, cpu_dsp[0], true),
  110. DEFINE_PROP_UINT32("CPU0_MPU_NS", ARMSSE, cpu_mpu_ns[0], 8),
  111. DEFINE_PROP_UINT32("CPU0_MPU_S", ARMSSE, cpu_mpu_s[0], 8),
  112. DEFINE_PROP_END_OF_LIST()
  113. };
  114. static const ARMSSEDeviceInfo iotkit_devices[] = {
  115. {
  116. .name = "timer0",
  117. .type = TYPE_CMSDK_APB_TIMER,
  118. .index = 0,
  119. .addr = 0x40000000,
  120. .ppc = 0,
  121. .ppc_port = 0,
  122. .irq = 3,
  123. },
  124. {
  125. .name = "timer1",
  126. .type = TYPE_CMSDK_APB_TIMER,
  127. .index = 1,
  128. .addr = 0x40001000,
  129. .ppc = 0,
  130. .ppc_port = 1,
  131. .irq = 4,
  132. },
  133. {
  134. .name = "s32ktimer",
  135. .type = TYPE_CMSDK_APB_TIMER,
  136. .index = 2,
  137. .addr = 0x4002f000,
  138. .ppc = 1,
  139. .ppc_port = 0,
  140. .irq = 2,
  141. .slowclk = true,
  142. },
  143. {
  144. .name = "dualtimer",
  145. .type = TYPE_CMSDK_APB_DUALTIMER,
  146. .index = 0,
  147. .addr = 0x40002000,
  148. .ppc = 0,
  149. .ppc_port = 2,
  150. .irq = 5,
  151. },
  152. {
  153. .name = "s32kwatchdog",
  154. .type = TYPE_CMSDK_APB_WATCHDOG,
  155. .index = 0,
  156. .addr = 0x5002e000,
  157. .ppc = NO_PPC,
  158. .irq = NMI_0,
  159. .slowclk = true,
  160. },
  161. {
  162. .name = "nswatchdog",
  163. .type = TYPE_CMSDK_APB_WATCHDOG,
  164. .index = 1,
  165. .addr = 0x40081000,
  166. .ppc = NO_PPC,
  167. .irq = 1,
  168. },
  169. {
  170. .name = "swatchdog",
  171. .type = TYPE_CMSDK_APB_WATCHDOG,
  172. .index = 2,
  173. .addr = 0x50081000,
  174. .ppc = NO_PPC,
  175. .irq = NMI_1,
  176. },
  177. {
  178. .name = "armsse-sysinfo",
  179. .type = TYPE_IOTKIT_SYSINFO,
  180. .index = 0,
  181. .addr = 0x40020000,
  182. .ppc = NO_PPC,
  183. .irq = NO_IRQ,
  184. },
  185. {
  186. .name = "armsse-sysctl",
  187. .type = TYPE_IOTKIT_SYSCTL,
  188. .index = 0,
  189. .addr = 0x50021000,
  190. .ppc = NO_PPC,
  191. .irq = NO_IRQ,
  192. },
  193. {
  194. .name = NULL,
  195. }
  196. };
  197. static const ARMSSEDeviceInfo sse200_devices[] = {
  198. {
  199. .name = "timer0",
  200. .type = TYPE_CMSDK_APB_TIMER,
  201. .index = 0,
  202. .addr = 0x40000000,
  203. .ppc = 0,
  204. .ppc_port = 0,
  205. .irq = 3,
  206. },
  207. {
  208. .name = "timer1",
  209. .type = TYPE_CMSDK_APB_TIMER,
  210. .index = 1,
  211. .addr = 0x40001000,
  212. .ppc = 0,
  213. .ppc_port = 1,
  214. .irq = 4,
  215. },
  216. {
  217. .name = "s32ktimer",
  218. .type = TYPE_CMSDK_APB_TIMER,
  219. .index = 2,
  220. .addr = 0x4002f000,
  221. .ppc = 1,
  222. .ppc_port = 0,
  223. .irq = 2,
  224. .slowclk = true,
  225. },
  226. {
  227. .name = "dualtimer",
  228. .type = TYPE_CMSDK_APB_DUALTIMER,
  229. .index = 0,
  230. .addr = 0x40002000,
  231. .ppc = 0,
  232. .ppc_port = 2,
  233. .irq = 5,
  234. },
  235. {
  236. .name = "s32kwatchdog",
  237. .type = TYPE_CMSDK_APB_WATCHDOG,
  238. .index = 0,
  239. .addr = 0x5002e000,
  240. .ppc = NO_PPC,
  241. .irq = NMI_0,
  242. .slowclk = true,
  243. },
  244. {
  245. .name = "nswatchdog",
  246. .type = TYPE_CMSDK_APB_WATCHDOG,
  247. .index = 1,
  248. .addr = 0x40081000,
  249. .ppc = NO_PPC,
  250. .irq = 1,
  251. },
  252. {
  253. .name = "swatchdog",
  254. .type = TYPE_CMSDK_APB_WATCHDOG,
  255. .index = 2,
  256. .addr = 0x50081000,
  257. .ppc = NO_PPC,
  258. .irq = NMI_1,
  259. },
  260. {
  261. .name = "armsse-sysinfo",
  262. .type = TYPE_IOTKIT_SYSINFO,
  263. .index = 0,
  264. .addr = 0x40020000,
  265. .ppc = NO_PPC,
  266. .irq = NO_IRQ,
  267. },
  268. {
  269. .name = "armsse-sysctl",
  270. .type = TYPE_IOTKIT_SYSCTL,
  271. .index = 0,
  272. .addr = 0x50021000,
  273. .ppc = NO_PPC,
  274. .irq = NO_IRQ,
  275. },
  276. {
  277. .name = "CPU0CORE_PPU",
  278. .type = TYPE_UNIMPLEMENTED_DEVICE,
  279. .index = 0,
  280. .addr = 0x50023000,
  281. .size = 0x1000,
  282. .ppc = NO_PPC,
  283. .irq = NO_IRQ,
  284. },
  285. {
  286. .name = "CPU1CORE_PPU",
  287. .type = TYPE_UNIMPLEMENTED_DEVICE,
  288. .index = 1,
  289. .addr = 0x50025000,
  290. .size = 0x1000,
  291. .ppc = NO_PPC,
  292. .irq = NO_IRQ,
  293. },
  294. {
  295. .name = "DBG_PPU",
  296. .type = TYPE_UNIMPLEMENTED_DEVICE,
  297. .index = 2,
  298. .addr = 0x50029000,
  299. .size = 0x1000,
  300. .ppc = NO_PPC,
  301. .irq = NO_IRQ,
  302. },
  303. {
  304. .name = "RAM0_PPU",
  305. .type = TYPE_UNIMPLEMENTED_DEVICE,
  306. .index = 3,
  307. .addr = 0x5002a000,
  308. .size = 0x1000,
  309. .ppc = NO_PPC,
  310. .irq = NO_IRQ,
  311. },
  312. {
  313. .name = "RAM1_PPU",
  314. .type = TYPE_UNIMPLEMENTED_DEVICE,
  315. .index = 4,
  316. .addr = 0x5002b000,
  317. .size = 0x1000,
  318. .ppc = NO_PPC,
  319. .irq = NO_IRQ,
  320. },
  321. {
  322. .name = "RAM2_PPU",
  323. .type = TYPE_UNIMPLEMENTED_DEVICE,
  324. .index = 5,
  325. .addr = 0x5002c000,
  326. .size = 0x1000,
  327. .ppc = NO_PPC,
  328. .irq = NO_IRQ,
  329. },
  330. {
  331. .name = "RAM3_PPU",
  332. .type = TYPE_UNIMPLEMENTED_DEVICE,
  333. .index = 6,
  334. .addr = 0x5002d000,
  335. .size = 0x1000,
  336. .ppc = NO_PPC,
  337. .irq = NO_IRQ,
  338. },
  339. {
  340. .name = "SYS_PPU",
  341. .type = TYPE_UNIMPLEMENTED_DEVICE,
  342. .index = 7,
  343. .addr = 0x50022000,
  344. .size = 0x1000,
  345. .ppc = NO_PPC,
  346. .irq = NO_IRQ,
  347. },
  348. {
  349. .name = NULL,
  350. }
  351. };
  352. static const ARMSSEDeviceInfo sse300_devices[] = {
  353. {
  354. .name = "timer0",
  355. .type = TYPE_SSE_TIMER,
  356. .index = 0,
  357. .addr = 0x48000000,
  358. .ppc = 0,
  359. .ppc_port = 0,
  360. .irq = 3,
  361. },
  362. {
  363. .name = "timer1",
  364. .type = TYPE_SSE_TIMER,
  365. .index = 1,
  366. .addr = 0x48001000,
  367. .ppc = 0,
  368. .ppc_port = 1,
  369. .irq = 4,
  370. },
  371. {
  372. .name = "timer2",
  373. .type = TYPE_SSE_TIMER,
  374. .index = 2,
  375. .addr = 0x48002000,
  376. .ppc = 0,
  377. .ppc_port = 2,
  378. .irq = 5,
  379. },
  380. {
  381. .name = "timer3",
  382. .type = TYPE_SSE_TIMER,
  383. .index = 3,
  384. .addr = 0x48003000,
  385. .ppc = 0,
  386. .ppc_port = 5,
  387. .irq = 27,
  388. },
  389. {
  390. .name = "s32ktimer",
  391. .type = TYPE_CMSDK_APB_TIMER,
  392. .index = 0,
  393. .addr = 0x4802f000,
  394. .ppc = 1,
  395. .ppc_port = 0,
  396. .irq = 2,
  397. .slowclk = true,
  398. },
  399. {
  400. .name = "s32kwatchdog",
  401. .type = TYPE_CMSDK_APB_WATCHDOG,
  402. .index = 0,
  403. .addr = 0x4802e000,
  404. .ppc = NO_PPC,
  405. .irq = NMI_0,
  406. .slowclk = true,
  407. },
  408. {
  409. .name = "watchdog",
  410. .type = TYPE_UNIMPLEMENTED_DEVICE,
  411. .index = 0,
  412. .addr = 0x48040000,
  413. .size = 0x2000,
  414. .ppc = NO_PPC,
  415. .irq = NO_IRQ,
  416. },
  417. {
  418. .name = "armsse-sysinfo",
  419. .type = TYPE_IOTKIT_SYSINFO,
  420. .index = 0,
  421. .addr = 0x48020000,
  422. .ppc = NO_PPC,
  423. .irq = NO_IRQ,
  424. },
  425. {
  426. .name = "armsse-sysctl",
  427. .type = TYPE_IOTKIT_SYSCTL,
  428. .index = 0,
  429. .addr = 0x58021000,
  430. .ppc = NO_PPC,
  431. .irq = NO_IRQ,
  432. },
  433. {
  434. .name = "SYS_PPU",
  435. .type = TYPE_UNIMPLEMENTED_DEVICE,
  436. .index = 1,
  437. .addr = 0x58022000,
  438. .size = 0x1000,
  439. .ppc = NO_PPC,
  440. .irq = NO_IRQ,
  441. },
  442. {
  443. .name = "CPU0CORE_PPU",
  444. .type = TYPE_UNIMPLEMENTED_DEVICE,
  445. .index = 2,
  446. .addr = 0x50023000,
  447. .size = 0x1000,
  448. .ppc = NO_PPC,
  449. .irq = NO_IRQ,
  450. },
  451. {
  452. .name = "MGMT_PPU",
  453. .type = TYPE_UNIMPLEMENTED_DEVICE,
  454. .index = 3,
  455. .addr = 0x50028000,
  456. .size = 0x1000,
  457. .ppc = NO_PPC,
  458. .irq = NO_IRQ,
  459. },
  460. {
  461. .name = "DEBUG_PPU",
  462. .type = TYPE_UNIMPLEMENTED_DEVICE,
  463. .index = 4,
  464. .addr = 0x50029000,
  465. .size = 0x1000,
  466. .ppc = NO_PPC,
  467. .irq = NO_IRQ,
  468. },
  469. {
  470. .name = NULL,
  471. }
  472. };
  473. /* Is internal IRQ n shared between CPUs in a multi-core SSE ? */
  474. static const bool sse200_irq_is_common[32] = {
  475. [0 ... 5] = true,
  476. /* 6, 7: per-CPU MHU interrupts */
  477. [8 ... 12] = true,
  478. /* 13: per-CPU icache interrupt */
  479. /* 14: reserved */
  480. [15 ... 20] = true,
  481. /* 21: reserved */
  482. [22 ... 26] = true,
  483. /* 27: reserved */
  484. /* 28, 29: per-CPU CTI interrupts */
  485. /* 30, 31: reserved */
  486. };
  487. static const bool sse300_irq_is_common[32] = {
  488. [0 ... 5] = true,
  489. /* 6, 7: per-CPU MHU interrupts */
  490. [8 ... 12] = true,
  491. /* 13: reserved */
  492. [14 ... 16] = true,
  493. /* 17-25: reserved */
  494. [26 ... 27] = true,
  495. /* 28, 29: per-CPU CTI interrupts */
  496. /* 30, 31: reserved */
  497. };
  498. static const ARMSSEInfo armsse_variants[] = {
  499. {
  500. .name = TYPE_IOTKIT,
  501. .sse_version = ARMSSE_IOTKIT,
  502. .cpu_type = ARM_CPU_TYPE_NAME("cortex-m33"),
  503. .sram_banks = 1,
  504. .sram_bank_base = 0x20000000,
  505. .num_cpus = 1,
  506. .sys_version = 0x41743,
  507. .iidr = 0,
  508. .cpuwait_rst = 0,
  509. .has_mhus = false,
  510. .has_cachectrl = false,
  511. .has_cpusecctrl = false,
  512. .has_cpuid = false,
  513. .has_cpu_pwrctrl = false,
  514. .has_sse_counter = false,
  515. .has_tcms = false,
  516. .props = iotkit_properties,
  517. .devinfo = iotkit_devices,
  518. .irq_is_common = sse200_irq_is_common,
  519. },
  520. {
  521. .name = TYPE_SSE200,
  522. .sse_version = ARMSSE_SSE200,
  523. .cpu_type = ARM_CPU_TYPE_NAME("cortex-m33"),
  524. .sram_banks = 4,
  525. .sram_bank_base = 0x20000000,
  526. .num_cpus = 2,
  527. .sys_version = 0x22041743,
  528. .iidr = 0,
  529. .cpuwait_rst = 2,
  530. .has_mhus = true,
  531. .has_cachectrl = true,
  532. .has_cpusecctrl = true,
  533. .has_cpuid = true,
  534. .has_cpu_pwrctrl = false,
  535. .has_sse_counter = false,
  536. .has_tcms = false,
  537. .props = sse200_properties,
  538. .devinfo = sse200_devices,
  539. .irq_is_common = sse200_irq_is_common,
  540. },
  541. {
  542. .name = TYPE_SSE300,
  543. .sse_version = ARMSSE_SSE300,
  544. .cpu_type = ARM_CPU_TYPE_NAME("cortex-m55"),
  545. .sram_banks = 2,
  546. .sram_bank_base = 0x21000000,
  547. .num_cpus = 1,
  548. .sys_version = 0x7e00043b,
  549. .iidr = 0x74a0043b,
  550. .cpuwait_rst = 0,
  551. .has_mhus = false,
  552. .has_cachectrl = false,
  553. .has_cpusecctrl = true,
  554. .has_cpuid = true,
  555. .has_cpu_pwrctrl = true,
  556. .has_sse_counter = true,
  557. .has_tcms = true,
  558. .props = sse300_properties,
  559. .devinfo = sse300_devices,
  560. .irq_is_common = sse300_irq_is_common,
  561. },
  562. };
  563. static uint32_t armsse_sys_config_value(ARMSSE *s, const ARMSSEInfo *info)
  564. {
  565. /* Return the SYS_CONFIG value for this SSE */
  566. uint32_t sys_config;
  567. switch (info->sse_version) {
  568. case ARMSSE_IOTKIT:
  569. sys_config = 0;
  570. sys_config = deposit32(sys_config, 0, 4, info->sram_banks);
  571. sys_config = deposit32(sys_config, 4, 4, s->sram_addr_width - 12);
  572. break;
  573. case ARMSSE_SSE200:
  574. sys_config = 0;
  575. sys_config = deposit32(sys_config, 0, 4, info->sram_banks);
  576. sys_config = deposit32(sys_config, 4, 5, s->sram_addr_width);
  577. sys_config = deposit32(sys_config, 24, 4, 2);
  578. if (info->num_cpus > 1) {
  579. sys_config = deposit32(sys_config, 10, 1, 1);
  580. sys_config = deposit32(sys_config, 20, 4, info->sram_banks - 1);
  581. sys_config = deposit32(sys_config, 28, 4, 2);
  582. }
  583. break;
  584. case ARMSSE_SSE300:
  585. sys_config = 0;
  586. sys_config = deposit32(sys_config, 0, 4, info->sram_banks);
  587. sys_config = deposit32(sys_config, 4, 5, s->sram_addr_width);
  588. sys_config = deposit32(sys_config, 16, 3, 3); /* CPU0 = Cortex-M55 */
  589. break;
  590. default:
  591. g_assert_not_reached();
  592. }
  593. return sys_config;
  594. }
  595. /* Clock frequency in HZ of the 32KHz "slow clock" */
  596. #define S32KCLK (32 * 1000)
  597. /*
  598. * Create an alias region in @container of @size bytes starting at @base
  599. * which mirrors the memory starting at @orig.
  600. */
  601. static void make_alias(ARMSSE *s, MemoryRegion *mr, MemoryRegion *container,
  602. const char *name, hwaddr base, hwaddr size, hwaddr orig)
  603. {
  604. memory_region_init_alias(mr, NULL, name, container, orig, size);
  605. /* The alias is even lower priority than unimplemented_device regions */
  606. memory_region_add_subregion_overlap(container, base, mr, -1500);
  607. }
  608. static void irq_status_forwarder(void *opaque, int n, int level)
  609. {
  610. qemu_irq destirq = opaque;
  611. qemu_set_irq(destirq, level);
  612. }
  613. static void nsccfg_handler(void *opaque, int n, int level)
  614. {
  615. ARMSSE *s = ARM_SSE(opaque);
  616. s->nsccfg = level;
  617. }
  618. static void armsse_forward_ppc(ARMSSE *s, const char *ppcname, int ppcnum)
  619. {
  620. /* Each of the 4 AHB and 4 APB PPCs that might be present in a
  621. * system using the ARMSSE has a collection of control lines which
  622. * are provided by the security controller and which we want to
  623. * expose as control lines on the ARMSSE device itself, so the
  624. * code using the ARMSSE can wire them up to the PPCs.
  625. */
  626. SplitIRQ *splitter = &s->ppc_irq_splitter[ppcnum];
  627. DeviceState *armssedev = DEVICE(s);
  628. DeviceState *dev_secctl = DEVICE(&s->secctl);
  629. DeviceState *dev_splitter = DEVICE(splitter);
  630. char *name;
  631. name = g_strdup_printf("%s_nonsec", ppcname);
  632. qdev_pass_gpios(dev_secctl, armssedev, name);
  633. g_free(name);
  634. name = g_strdup_printf("%s_ap", ppcname);
  635. qdev_pass_gpios(dev_secctl, armssedev, name);
  636. g_free(name);
  637. name = g_strdup_printf("%s_irq_enable", ppcname);
  638. qdev_pass_gpios(dev_secctl, armssedev, name);
  639. g_free(name);
  640. name = g_strdup_printf("%s_irq_clear", ppcname);
  641. qdev_pass_gpios(dev_secctl, armssedev, name);
  642. g_free(name);
  643. /* irq_status is a little more tricky, because we need to
  644. * split it so we can send it both to the security controller
  645. * and to our OR gate for the NVIC interrupt line.
  646. * Connect up the splitter's outputs, and create a GPIO input
  647. * which will pass the line state to the input splitter.
  648. */
  649. name = g_strdup_printf("%s_irq_status", ppcname);
  650. qdev_connect_gpio_out(dev_splitter, 0,
  651. qdev_get_gpio_in_named(dev_secctl,
  652. name, 0));
  653. qdev_connect_gpio_out(dev_splitter, 1,
  654. qdev_get_gpio_in(DEVICE(&s->ppc_irq_orgate), ppcnum));
  655. s->irq_status_in[ppcnum] = qdev_get_gpio_in(dev_splitter, 0);
  656. qdev_init_gpio_in_named_with_opaque(armssedev, irq_status_forwarder,
  657. s->irq_status_in[ppcnum], name, 1);
  658. g_free(name);
  659. }
  660. static void armsse_forward_sec_resp_cfg(ARMSSE *s)
  661. {
  662. /* Forward the 3rd output from the splitter device as a
  663. * named GPIO output of the armsse object.
  664. */
  665. DeviceState *dev = DEVICE(s);
  666. DeviceState *dev_splitter = DEVICE(&s->sec_resp_splitter);
  667. qdev_init_gpio_out_named(dev, &s->sec_resp_cfg, "sec_resp_cfg", 1);
  668. s->sec_resp_cfg_in = qemu_allocate_irq(irq_status_forwarder,
  669. s->sec_resp_cfg, 1);
  670. qdev_connect_gpio_out(dev_splitter, 2, s->sec_resp_cfg_in);
  671. }
  672. static void armsse_init(Object *obj)
  673. {
  674. ARMSSE *s = ARM_SSE(obj);
  675. ARMSSEClass *asc = ARM_SSE_GET_CLASS(obj);
  676. const ARMSSEInfo *info = asc->info;
  677. const ARMSSEDeviceInfo *devinfo;
  678. int i;
  679. assert(info->sram_banks <= MAX_SRAM_BANKS);
  680. assert(info->num_cpus <= SSE_MAX_CPUS);
  681. s->mainclk = qdev_init_clock_in(DEVICE(s), "MAINCLK", NULL, NULL, 0);
  682. s->s32kclk = qdev_init_clock_in(DEVICE(s), "S32KCLK", NULL, NULL, 0);
  683. memory_region_init(&s->container, obj, "armsse-container", UINT64_MAX);
  684. for (i = 0; i < info->num_cpus; i++) {
  685. /*
  686. * We put each CPU in its own cluster as they are logically
  687. * distinct and may be configured differently.
  688. */
  689. char *name;
  690. name = g_strdup_printf("cluster%d", i);
  691. object_initialize_child(obj, name, &s->cluster[i], TYPE_CPU_CLUSTER);
  692. qdev_prop_set_uint32(DEVICE(&s->cluster[i]), "cluster-id", i);
  693. g_free(name);
  694. name = g_strdup_printf("armv7m%d", i);
  695. object_initialize_child(OBJECT(&s->cluster[i]), name, &s->armv7m[i],
  696. TYPE_ARMV7M);
  697. qdev_prop_set_string(DEVICE(&s->armv7m[i]), "cpu-type", info->cpu_type);
  698. g_free(name);
  699. name = g_strdup_printf("arm-sse-cpu-container%d", i);
  700. memory_region_init(&s->cpu_container[i], obj, name, UINT64_MAX);
  701. g_free(name);
  702. if (i > 0) {
  703. name = g_strdup_printf("arm-sse-container-alias%d", i);
  704. memory_region_init_alias(&s->container_alias[i - 1], obj,
  705. name, &s->container, 0, UINT64_MAX);
  706. g_free(name);
  707. }
  708. }
  709. for (devinfo = info->devinfo; devinfo->name; devinfo++) {
  710. assert(devinfo->ppc == NO_PPC || devinfo->ppc < ARRAY_SIZE(s->apb_ppc));
  711. if (!strcmp(devinfo->type, TYPE_CMSDK_APB_TIMER)) {
  712. assert(devinfo->index < ARRAY_SIZE(s->timer));
  713. object_initialize_child(obj, devinfo->name,
  714. &s->timer[devinfo->index],
  715. TYPE_CMSDK_APB_TIMER);
  716. } else if (!strcmp(devinfo->type, TYPE_CMSDK_APB_DUALTIMER)) {
  717. assert(devinfo->index == 0);
  718. object_initialize_child(obj, devinfo->name, &s->dualtimer,
  719. TYPE_CMSDK_APB_DUALTIMER);
  720. } else if (!strcmp(devinfo->type, TYPE_SSE_TIMER)) {
  721. assert(devinfo->index < ARRAY_SIZE(s->sse_timer));
  722. object_initialize_child(obj, devinfo->name,
  723. &s->sse_timer[devinfo->index],
  724. TYPE_SSE_TIMER);
  725. } else if (!strcmp(devinfo->type, TYPE_CMSDK_APB_WATCHDOG)) {
  726. assert(devinfo->index < ARRAY_SIZE(s->cmsdk_watchdog));
  727. object_initialize_child(obj, devinfo->name,
  728. &s->cmsdk_watchdog[devinfo->index],
  729. TYPE_CMSDK_APB_WATCHDOG);
  730. } else if (!strcmp(devinfo->type, TYPE_IOTKIT_SYSINFO)) {
  731. assert(devinfo->index == 0);
  732. object_initialize_child(obj, devinfo->name, &s->sysinfo,
  733. TYPE_IOTKIT_SYSINFO);
  734. } else if (!strcmp(devinfo->type, TYPE_IOTKIT_SYSCTL)) {
  735. assert(devinfo->index == 0);
  736. object_initialize_child(obj, devinfo->name, &s->sysctl,
  737. TYPE_IOTKIT_SYSCTL);
  738. } else if (!strcmp(devinfo->type, TYPE_UNIMPLEMENTED_DEVICE)) {
  739. assert(devinfo->index < ARRAY_SIZE(s->unimp));
  740. object_initialize_child(obj, devinfo->name,
  741. &s->unimp[devinfo->index],
  742. TYPE_UNIMPLEMENTED_DEVICE);
  743. } else {
  744. g_assert_not_reached();
  745. }
  746. }
  747. object_initialize_child(obj, "secctl", &s->secctl, TYPE_IOTKIT_SECCTL);
  748. for (i = 0; i < ARRAY_SIZE(s->apb_ppc); i++) {
  749. g_autofree char *name = g_strdup_printf("apb-ppc%d", i);
  750. object_initialize_child(obj, name, &s->apb_ppc[i], TYPE_TZ_PPC);
  751. }
  752. for (i = 0; i < info->sram_banks; i++) {
  753. char *name = g_strdup_printf("mpc%d", i);
  754. object_initialize_child(obj, name, &s->mpc[i], TYPE_TZ_MPC);
  755. g_free(name);
  756. }
  757. object_initialize_child(obj, "mpc-irq-orgate", &s->mpc_irq_orgate,
  758. TYPE_OR_IRQ);
  759. for (i = 0; i < IOTS_NUM_EXP_MPC + info->sram_banks; i++) {
  760. char *name = g_strdup_printf("mpc-irq-splitter-%d", i);
  761. SplitIRQ *splitter = &s->mpc_irq_splitter[i];
  762. object_initialize_child(obj, name, splitter, TYPE_SPLIT_IRQ);
  763. g_free(name);
  764. }
  765. if (info->has_mhus) {
  766. object_initialize_child(obj, "mhu0", &s->mhu[0], TYPE_ARMSSE_MHU);
  767. object_initialize_child(obj, "mhu1", &s->mhu[1], TYPE_ARMSSE_MHU);
  768. }
  769. if (info->has_cachectrl) {
  770. for (i = 0; i < info->num_cpus; i++) {
  771. char *name = g_strdup_printf("cachectrl%d", i);
  772. object_initialize_child(obj, name, &s->cachectrl[i],
  773. TYPE_UNIMPLEMENTED_DEVICE);
  774. g_free(name);
  775. }
  776. }
  777. if (info->has_cpusecctrl) {
  778. for (i = 0; i < info->num_cpus; i++) {
  779. char *name = g_strdup_printf("cpusecctrl%d", i);
  780. object_initialize_child(obj, name, &s->cpusecctrl[i],
  781. TYPE_UNIMPLEMENTED_DEVICE);
  782. g_free(name);
  783. }
  784. }
  785. if (info->has_cpuid) {
  786. for (i = 0; i < info->num_cpus; i++) {
  787. char *name = g_strdup_printf("cpuid%d", i);
  788. object_initialize_child(obj, name, &s->cpuid[i],
  789. TYPE_ARMSSE_CPUID);
  790. g_free(name);
  791. }
  792. }
  793. if (info->has_cpu_pwrctrl) {
  794. for (i = 0; i < info->num_cpus; i++) {
  795. char *name = g_strdup_printf("cpu_pwrctrl%d", i);
  796. object_initialize_child(obj, name, &s->cpu_pwrctrl[i],
  797. TYPE_ARMSSE_CPU_PWRCTRL);
  798. g_free(name);
  799. }
  800. }
  801. if (info->has_sse_counter) {
  802. object_initialize_child(obj, "sse-counter", &s->sse_counter,
  803. TYPE_SSE_COUNTER);
  804. }
  805. object_initialize_child(obj, "nmi-orgate", &s->nmi_orgate, TYPE_OR_IRQ);
  806. object_initialize_child(obj, "ppc-irq-orgate", &s->ppc_irq_orgate,
  807. TYPE_OR_IRQ);
  808. object_initialize_child(obj, "sec-resp-splitter", &s->sec_resp_splitter,
  809. TYPE_SPLIT_IRQ);
  810. for (i = 0; i < ARRAY_SIZE(s->ppc_irq_splitter); i++) {
  811. char *name = g_strdup_printf("ppc-irq-splitter-%d", i);
  812. SplitIRQ *splitter = &s->ppc_irq_splitter[i];
  813. object_initialize_child(obj, name, splitter, TYPE_SPLIT_IRQ);
  814. g_free(name);
  815. }
  816. if (info->num_cpus > 1) {
  817. for (i = 0; i < ARRAY_SIZE(s->cpu_irq_splitter); i++) {
  818. if (info->irq_is_common[i]) {
  819. char *name = g_strdup_printf("cpu-irq-splitter%d", i);
  820. SplitIRQ *splitter = &s->cpu_irq_splitter[i];
  821. object_initialize_child(obj, name, splitter, TYPE_SPLIT_IRQ);
  822. g_free(name);
  823. }
  824. }
  825. }
  826. }
  827. static void armsse_exp_irq(void *opaque, int n, int level)
  828. {
  829. qemu_irq *irqarray = opaque;
  830. qemu_set_irq(irqarray[n], level);
  831. }
  832. static void armsse_mpcexp_status(void *opaque, int n, int level)
  833. {
  834. ARMSSE *s = ARM_SSE(opaque);
  835. qemu_set_irq(s->mpcexp_status_in[n], level);
  836. }
  837. static qemu_irq armsse_get_common_irq_in(ARMSSE *s, int irqno)
  838. {
  839. /*
  840. * Return a qemu_irq which can be used to signal IRQ n to
  841. * all CPUs in the SSE.
  842. */
  843. ARMSSEClass *asc = ARM_SSE_GET_CLASS(s);
  844. const ARMSSEInfo *info = asc->info;
  845. assert(info->irq_is_common[irqno]);
  846. if (info->num_cpus == 1) {
  847. /* Only one CPU -- just connect directly to it */
  848. return qdev_get_gpio_in(DEVICE(&s->armv7m[0]), irqno);
  849. } else {
  850. /* Connect to the splitter which feeds all CPUs */
  851. return qdev_get_gpio_in(DEVICE(&s->cpu_irq_splitter[irqno]), 0);
  852. }
  853. }
  854. static void armsse_realize(DeviceState *dev, Error **errp)
  855. {
  856. ERRP_GUARD();
  857. ARMSSE *s = ARM_SSE(dev);
  858. ARMSSEClass *asc = ARM_SSE_GET_CLASS(dev);
  859. const ARMSSEInfo *info = asc->info;
  860. const ARMSSEDeviceInfo *devinfo;
  861. int i;
  862. MemoryRegion *mr;
  863. SysBusDevice *sbd_apb_ppc0;
  864. SysBusDevice *sbd_secctl;
  865. DeviceState *dev_apb_ppc0;
  866. DeviceState *dev_apb_ppc1;
  867. DeviceState *dev_secctl;
  868. DeviceState *dev_splitter;
  869. uint32_t addr_width_max;
  870. if (!s->board_memory) {
  871. error_setg(errp, "memory property was not set");
  872. return;
  873. }
  874. if (!clock_has_source(s->mainclk)) {
  875. error_setg(errp, "MAINCLK clock was not connected");
  876. }
  877. if (!clock_has_source(s->s32kclk)) {
  878. error_setg(errp, "S32KCLK clock was not connected");
  879. }
  880. assert(info->num_cpus <= SSE_MAX_CPUS);
  881. /* max SRAM_ADDR_WIDTH: 24 - log2(SRAM_NUM_BANK) */
  882. assert(is_power_of_2(info->sram_banks));
  883. addr_width_max = 24 - ctz32(info->sram_banks);
  884. if (s->sram_addr_width < 1 || s->sram_addr_width > addr_width_max) {
  885. error_setg(errp, "SRAM_ADDR_WIDTH must be between 1 and %d",
  886. addr_width_max);
  887. return;
  888. }
  889. /* Handling of which devices should be available only to secure
  890. * code is usually done differently for M profile than for A profile.
  891. * Instead of putting some devices only into the secure address space,
  892. * devices exist in both address spaces but with hard-wired security
  893. * permissions that will cause the CPU to fault for non-secure accesses.
  894. *
  895. * The ARMSSE has an IDAU (Implementation Defined Access Unit),
  896. * which specifies hard-wired security permissions for different
  897. * areas of the physical address space. For the ARMSSE IDAU, the
  898. * top 4 bits of the physical address are the IDAU region ID, and
  899. * if bit 28 (ie the lowest bit of the ID) is 0 then this is an NS
  900. * region, otherwise it is an S region.
  901. *
  902. * The various devices and RAMs are generally all mapped twice,
  903. * once into a region that the IDAU defines as secure and once
  904. * into a non-secure region. They sit behind either a Memory
  905. * Protection Controller (for RAM) or a Peripheral Protection
  906. * Controller (for devices), which allow a more fine grained
  907. * configuration of whether non-secure accesses are permitted.
  908. *
  909. * (The other place that guest software can configure security
  910. * permissions is in the architected SAU (Security Attribution
  911. * Unit), which is entirely inside the CPU. The IDAU can upgrade
  912. * the security attributes for a region to more restrictive than
  913. * the SAU specifies, but cannot downgrade them.)
  914. *
  915. * 0x10000000..0x1fffffff alias of 0x00000000..0x0fffffff
  916. * 0x20000000..0x2007ffff 32KB FPGA block RAM
  917. * 0x30000000..0x3fffffff alias of 0x20000000..0x2fffffff
  918. * 0x40000000..0x4000ffff base peripheral region 1
  919. * 0x40010000..0x4001ffff CPU peripherals (none for ARMSSE)
  920. * 0x40020000..0x4002ffff system control element peripherals
  921. * 0x40080000..0x400fffff base peripheral region 2
  922. * 0x50000000..0x5fffffff alias of 0x40000000..0x4fffffff
  923. */
  924. memory_region_add_subregion_overlap(&s->container, 0, s->board_memory, -2);
  925. for (i = 0; i < info->num_cpus; i++) {
  926. DeviceState *cpudev = DEVICE(&s->armv7m[i]);
  927. Object *cpuobj = OBJECT(&s->armv7m[i]);
  928. int j;
  929. char *gpioname;
  930. qdev_connect_clock_in(cpudev, "cpuclk", s->mainclk);
  931. /* The SSE subsystems do not wire up a systick refclk */
  932. qdev_prop_set_uint32(cpudev, "num-irq", s->exp_numirq + NUM_SSE_IRQS);
  933. /*
  934. * In real hardware the initial Secure VTOR is set from the INITSVTOR*
  935. * registers in the IoT Kit System Control Register block. In QEMU
  936. * we set the initial value here, and also the reset value of the
  937. * sysctl register, from this object's QOM init-svtor property.
  938. * If the guest changes the INITSVTOR* registers at runtime then the
  939. * code in iotkit-sysctl.c will update the CPU init-svtor property
  940. * (which will then take effect on the next CPU warm-reset).
  941. *
  942. * Note that typically a board using the SSE-200 will have a system
  943. * control processor whose boot firmware initializes the INITSVTOR*
  944. * registers before powering up the CPUs. QEMU doesn't emulate
  945. * the control processor, so instead we behave in the way that the
  946. * firmware does: the initial value should be set by the board code
  947. * (using the init-svtor property on the ARMSSE object) to match
  948. * whatever its firmware does.
  949. */
  950. qdev_prop_set_uint32(cpudev, "init-svtor", s->init_svtor);
  951. /*
  952. * CPUs start powered down if the corresponding bit in the CPUWAIT
  953. * register is 1. In real hardware the CPUWAIT register reset value is
  954. * a configurable property of the SSE-200 (via the CPUWAIT0_RST and
  955. * CPUWAIT1_RST parameters), but since all the boards we care about
  956. * start CPU0 and leave CPU1 powered off, we hard-code that in
  957. * info->cpuwait_rst for now. We can add QOM properties for this
  958. * later if necessary.
  959. */
  960. if (extract32(info->cpuwait_rst, i, 1)) {
  961. object_property_set_bool(cpuobj, "start-powered-off", true,
  962. &error_abort);
  963. }
  964. if (!s->cpu_fpu[i]) {
  965. if (!object_property_set_bool(cpuobj, "vfp", false, errp)) {
  966. return;
  967. }
  968. }
  969. if (!s->cpu_dsp[i]) {
  970. if (!object_property_set_bool(cpuobj, "dsp", false, errp)) {
  971. return;
  972. }
  973. }
  974. if (!object_property_set_uint(cpuobj, "mpu-ns-regions",
  975. s->cpu_mpu_ns[i], errp)) {
  976. return;
  977. }
  978. if (!object_property_set_uint(cpuobj, "mpu-s-regions",
  979. s->cpu_mpu_s[i], errp)) {
  980. return;
  981. }
  982. if (i > 0) {
  983. memory_region_add_subregion_overlap(&s->cpu_container[i], 0,
  984. &s->container_alias[i - 1], -1);
  985. } else {
  986. memory_region_add_subregion_overlap(&s->cpu_container[i], 0,
  987. &s->container, -1);
  988. }
  989. object_property_set_link(cpuobj, "memory",
  990. OBJECT(&s->cpu_container[i]), &error_abort);
  991. object_property_set_link(cpuobj, "idau", OBJECT(s), &error_abort);
  992. if (!sysbus_realize(SYS_BUS_DEVICE(cpuobj), errp)) {
  993. return;
  994. }
  995. /*
  996. * The cluster must be realized after the armv7m container, as
  997. * the container's CPU object is only created on realize, and the
  998. * CPU must exist and have been parented into the cluster before
  999. * the cluster is realized.
  1000. */
  1001. if (!qdev_realize(DEVICE(&s->cluster[i]), NULL, errp)) {
  1002. return;
  1003. }
  1004. /* Connect EXP_IRQ/EXP_CPUn_IRQ GPIOs to the NVIC's lines 32 and up */
  1005. s->exp_irqs[i] = g_new(qemu_irq, s->exp_numirq);
  1006. for (j = 0; j < s->exp_numirq; j++) {
  1007. s->exp_irqs[i][j] = qdev_get_gpio_in(cpudev, j + NUM_SSE_IRQS);
  1008. }
  1009. if (i == 0) {
  1010. gpioname = g_strdup("EXP_IRQ");
  1011. } else {
  1012. gpioname = g_strdup_printf("EXP_CPU%d_IRQ", i);
  1013. }
  1014. qdev_init_gpio_in_named_with_opaque(dev, armsse_exp_irq,
  1015. s->exp_irqs[i],
  1016. gpioname, s->exp_numirq);
  1017. g_free(gpioname);
  1018. }
  1019. /* Wire up the splitters that connect common IRQs to all CPUs */
  1020. if (info->num_cpus > 1) {
  1021. for (i = 0; i < ARRAY_SIZE(s->cpu_irq_splitter); i++) {
  1022. if (info->irq_is_common[i]) {
  1023. Object *splitter = OBJECT(&s->cpu_irq_splitter[i]);
  1024. DeviceState *devs = DEVICE(splitter);
  1025. int cpunum;
  1026. if (!object_property_set_int(splitter, "num-lines",
  1027. info->num_cpus, errp)) {
  1028. return;
  1029. }
  1030. if (!qdev_realize(DEVICE(splitter), NULL, errp)) {
  1031. return;
  1032. }
  1033. for (cpunum = 0; cpunum < info->num_cpus; cpunum++) {
  1034. DeviceState *cpudev = DEVICE(&s->armv7m[cpunum]);
  1035. qdev_connect_gpio_out(devs, cpunum,
  1036. qdev_get_gpio_in(cpudev, i));
  1037. }
  1038. }
  1039. }
  1040. }
  1041. /* Set up the big aliases first */
  1042. make_alias(s, &s->alias1, &s->container, "alias 1",
  1043. 0x10000000, 0x10000000, 0x00000000);
  1044. make_alias(s, &s->alias2, &s->container,
  1045. "alias 2", 0x30000000, 0x10000000, 0x20000000);
  1046. /* The 0x50000000..0x5fffffff region is not a pure alias: it has
  1047. * a few extra devices that only appear there (generally the
  1048. * control interfaces for the protection controllers).
  1049. * We implement this by mapping those devices over the top of this
  1050. * alias MR at a higher priority. Some of the devices in this range
  1051. * are per-CPU, so we must put this alias in the per-cpu containers.
  1052. */
  1053. for (i = 0; i < info->num_cpus; i++) {
  1054. make_alias(s, &s->alias3[i], &s->cpu_container[i],
  1055. "alias 3", 0x50000000, 0x10000000, 0x40000000);
  1056. }
  1057. /* Security controller */
  1058. object_property_set_int(OBJECT(&s->secctl), "sse-version",
  1059. info->sse_version, &error_abort);
  1060. if (!sysbus_realize(SYS_BUS_DEVICE(&s->secctl), errp)) {
  1061. return;
  1062. }
  1063. sbd_secctl = SYS_BUS_DEVICE(&s->secctl);
  1064. dev_secctl = DEVICE(&s->secctl);
  1065. sysbus_mmio_map(sbd_secctl, 0, 0x50080000);
  1066. sysbus_mmio_map(sbd_secctl, 1, 0x40080000);
  1067. s->nsc_cfg_in = qemu_allocate_irq(nsccfg_handler, s, 1);
  1068. qdev_connect_gpio_out_named(dev_secctl, "nsc_cfg", 0, s->nsc_cfg_in);
  1069. /* The sec_resp_cfg output from the security controller must be split into
  1070. * multiple lines, one for each of the PPCs within the ARMSSE and one
  1071. * that will be an output from the ARMSSE to the system.
  1072. */
  1073. if (!object_property_set_int(OBJECT(&s->sec_resp_splitter),
  1074. "num-lines", 3, errp)) {
  1075. return;
  1076. }
  1077. if (!qdev_realize(DEVICE(&s->sec_resp_splitter), NULL, errp)) {
  1078. return;
  1079. }
  1080. dev_splitter = DEVICE(&s->sec_resp_splitter);
  1081. qdev_connect_gpio_out_named(dev_secctl, "sec_resp_cfg", 0,
  1082. qdev_get_gpio_in(dev_splitter, 0));
  1083. /* Each SRAM bank lives behind its own Memory Protection Controller */
  1084. for (i = 0; i < info->sram_banks; i++) {
  1085. char *ramname = g_strdup_printf("armsse.sram%d", i);
  1086. SysBusDevice *sbd_mpc;
  1087. uint32_t sram_bank_size = 1 << s->sram_addr_width;
  1088. memory_region_init_ram(&s->sram[i], NULL, ramname,
  1089. sram_bank_size, errp);
  1090. g_free(ramname);
  1091. if (*errp) {
  1092. return;
  1093. }
  1094. object_property_set_link(OBJECT(&s->mpc[i]), "downstream",
  1095. OBJECT(&s->sram[i]), &error_abort);
  1096. if (!sysbus_realize(SYS_BUS_DEVICE(&s->mpc[i]), errp)) {
  1097. return;
  1098. }
  1099. /* Map the upstream end of the MPC into the right place... */
  1100. sbd_mpc = SYS_BUS_DEVICE(&s->mpc[i]);
  1101. memory_region_add_subregion(&s->container,
  1102. info->sram_bank_base + i * sram_bank_size,
  1103. sysbus_mmio_get_region(sbd_mpc, 1));
  1104. /* ...and its register interface */
  1105. memory_region_add_subregion(&s->container, 0x50083000 + i * 0x1000,
  1106. sysbus_mmio_get_region(sbd_mpc, 0));
  1107. }
  1108. /* We must OR together lines from the MPC splitters to go to the NVIC */
  1109. if (!object_property_set_int(OBJECT(&s->mpc_irq_orgate), "num-lines",
  1110. IOTS_NUM_EXP_MPC + info->sram_banks,
  1111. errp)) {
  1112. return;
  1113. }
  1114. if (!qdev_realize(DEVICE(&s->mpc_irq_orgate), NULL, errp)) {
  1115. return;
  1116. }
  1117. qdev_connect_gpio_out(DEVICE(&s->mpc_irq_orgate), 0,
  1118. armsse_get_common_irq_in(s, 9));
  1119. /* This OR gate wires together outputs from the secure watchdogs to NMI */
  1120. if (!object_property_set_int(OBJECT(&s->nmi_orgate), "num-lines", 2,
  1121. errp)) {
  1122. return;
  1123. }
  1124. if (!qdev_realize(DEVICE(&s->nmi_orgate), NULL, errp)) {
  1125. return;
  1126. }
  1127. qdev_connect_gpio_out(DEVICE(&s->nmi_orgate), 0,
  1128. qdev_get_gpio_in_named(DEVICE(&s->armv7m), "NMI", 0));
  1129. /* The SSE-300 has a System Counter / System Timestamp Generator */
  1130. if (info->has_sse_counter) {
  1131. SysBusDevice *sbd = SYS_BUS_DEVICE(&s->sse_counter);
  1132. qdev_connect_clock_in(DEVICE(sbd), "CLK", s->mainclk);
  1133. if (!sysbus_realize(sbd, errp)) {
  1134. return;
  1135. }
  1136. /*
  1137. * The control frame is only in the Secure region;
  1138. * the status frame is in the NS region (and visible in the
  1139. * S region via the alias mapping).
  1140. */
  1141. memory_region_add_subregion(&s->container, 0x58100000,
  1142. sysbus_mmio_get_region(sbd, 0));
  1143. memory_region_add_subregion(&s->container, 0x48101000,
  1144. sysbus_mmio_get_region(sbd, 1));
  1145. }
  1146. if (info->has_tcms) {
  1147. /* The SSE-300 has an ITCM at 0x0000_0000 and a DTCM at 0x2000_0000 */
  1148. memory_region_init_ram(&s->itcm, NULL, "sse300-itcm", 512 * KiB, errp);
  1149. if (*errp) {
  1150. return;
  1151. }
  1152. memory_region_init_ram(&s->dtcm, NULL, "sse300-dtcm", 512 * KiB, errp);
  1153. if (*errp) {
  1154. return;
  1155. }
  1156. memory_region_add_subregion(&s->container, 0x00000000, &s->itcm);
  1157. memory_region_add_subregion(&s->container, 0x20000000, &s->dtcm);
  1158. }
  1159. /* Devices behind APB PPC0:
  1160. * 0x40000000: timer0
  1161. * 0x40001000: timer1
  1162. * 0x40002000: dual timer
  1163. * 0x40003000: MHU0 (SSE-200 only)
  1164. * 0x40004000: MHU1 (SSE-200 only)
  1165. * We must configure and realize each downstream device and connect
  1166. * it to the appropriate PPC port; then we can realize the PPC and
  1167. * map its upstream ends to the right place in the container.
  1168. */
  1169. for (devinfo = info->devinfo; devinfo->name; devinfo++) {
  1170. SysBusDevice *sbd;
  1171. qemu_irq irq;
  1172. if (!strcmp(devinfo->type, TYPE_CMSDK_APB_TIMER)) {
  1173. sbd = SYS_BUS_DEVICE(&s->timer[devinfo->index]);
  1174. qdev_connect_clock_in(DEVICE(sbd), "pclk",
  1175. devinfo->slowclk ? s->s32kclk : s->mainclk);
  1176. if (!sysbus_realize(sbd, errp)) {
  1177. return;
  1178. }
  1179. mr = sysbus_mmio_get_region(sbd, 0);
  1180. } else if (!strcmp(devinfo->type, TYPE_CMSDK_APB_DUALTIMER)) {
  1181. sbd = SYS_BUS_DEVICE(&s->dualtimer);
  1182. qdev_connect_clock_in(DEVICE(sbd), "TIMCLK", s->mainclk);
  1183. if (!sysbus_realize(sbd, errp)) {
  1184. return;
  1185. }
  1186. mr = sysbus_mmio_get_region(sbd, 0);
  1187. } else if (!strcmp(devinfo->type, TYPE_SSE_TIMER)) {
  1188. sbd = SYS_BUS_DEVICE(&s->sse_timer[devinfo->index]);
  1189. assert(info->has_sse_counter);
  1190. object_property_set_link(OBJECT(sbd), "counter",
  1191. OBJECT(&s->sse_counter), &error_abort);
  1192. if (!sysbus_realize(sbd, errp)) {
  1193. return;
  1194. }
  1195. mr = sysbus_mmio_get_region(sbd, 0);
  1196. } else if (!strcmp(devinfo->type, TYPE_CMSDK_APB_WATCHDOG)) {
  1197. sbd = SYS_BUS_DEVICE(&s->cmsdk_watchdog[devinfo->index]);
  1198. qdev_connect_clock_in(DEVICE(sbd), "WDOGCLK",
  1199. devinfo->slowclk ? s->s32kclk : s->mainclk);
  1200. if (!sysbus_realize(sbd, errp)) {
  1201. return;
  1202. }
  1203. mr = sysbus_mmio_get_region(sbd, 0);
  1204. } else if (!strcmp(devinfo->type, TYPE_IOTKIT_SYSINFO)) {
  1205. sbd = SYS_BUS_DEVICE(&s->sysinfo);
  1206. object_property_set_int(OBJECT(&s->sysinfo), "SYS_VERSION",
  1207. info->sys_version, &error_abort);
  1208. object_property_set_int(OBJECT(&s->sysinfo), "SYS_CONFIG",
  1209. armsse_sys_config_value(s, info),
  1210. &error_abort);
  1211. object_property_set_int(OBJECT(&s->sysinfo), "sse-version",
  1212. info->sse_version, &error_abort);
  1213. object_property_set_int(OBJECT(&s->sysinfo), "IIDR",
  1214. info->iidr, &error_abort);
  1215. if (!sysbus_realize(sbd, errp)) {
  1216. return;
  1217. }
  1218. mr = sysbus_mmio_get_region(sbd, 0);
  1219. } else if (!strcmp(devinfo->type, TYPE_IOTKIT_SYSCTL)) {
  1220. /* System control registers */
  1221. sbd = SYS_BUS_DEVICE(&s->sysctl);
  1222. object_property_set_int(OBJECT(&s->sysctl), "sse-version",
  1223. info->sse_version, &error_abort);
  1224. object_property_set_int(OBJECT(&s->sysctl), "CPUWAIT_RST",
  1225. info->cpuwait_rst, &error_abort);
  1226. object_property_set_int(OBJECT(&s->sysctl), "INITSVTOR0_RST",
  1227. s->init_svtor, &error_abort);
  1228. object_property_set_int(OBJECT(&s->sysctl), "INITSVTOR1_RST",
  1229. s->init_svtor, &error_abort);
  1230. if (!sysbus_realize(sbd, errp)) {
  1231. return;
  1232. }
  1233. mr = sysbus_mmio_get_region(sbd, 0);
  1234. } else if (!strcmp(devinfo->type, TYPE_UNIMPLEMENTED_DEVICE)) {
  1235. sbd = SYS_BUS_DEVICE(&s->unimp[devinfo->index]);
  1236. qdev_prop_set_string(DEVICE(sbd), "name", devinfo->name);
  1237. qdev_prop_set_uint64(DEVICE(sbd), "size", devinfo->size);
  1238. if (!sysbus_realize(sbd, errp)) {
  1239. return;
  1240. }
  1241. mr = sysbus_mmio_get_region(sbd, 0);
  1242. } else {
  1243. g_assert_not_reached();
  1244. }
  1245. switch (devinfo->irq) {
  1246. case NO_IRQ:
  1247. irq = NULL;
  1248. break;
  1249. case 0 ... NUM_SSE_IRQS - 1:
  1250. irq = armsse_get_common_irq_in(s, devinfo->irq);
  1251. break;
  1252. case NMI_0:
  1253. case NMI_1:
  1254. irq = qdev_get_gpio_in(DEVICE(&s->nmi_orgate),
  1255. devinfo->irq - NMI_0);
  1256. break;
  1257. default:
  1258. g_assert_not_reached();
  1259. }
  1260. if (irq) {
  1261. sysbus_connect_irq(sbd, 0, irq);
  1262. }
  1263. /*
  1264. * Devices connected to a PPC are connected to the port here;
  1265. * we will map the upstream end of that port to the right address
  1266. * in the container later after the PPC has been realized.
  1267. * Devices not connected to a PPC can be mapped immediately.
  1268. */
  1269. if (devinfo->ppc != NO_PPC) {
  1270. TZPPC *ppc = &s->apb_ppc[devinfo->ppc];
  1271. g_autofree char *portname = g_strdup_printf("port[%d]",
  1272. devinfo->ppc_port);
  1273. object_property_set_link(OBJECT(ppc), portname, OBJECT(mr),
  1274. &error_abort);
  1275. } else {
  1276. memory_region_add_subregion(&s->container, devinfo->addr, mr);
  1277. }
  1278. }
  1279. if (info->has_mhus) {
  1280. /*
  1281. * An SSE-200 with only one CPU should have only one MHU created,
  1282. * with the region where the second MHU usually is being RAZ/WI.
  1283. * We don't implement that SSE-200 config; if we want to support
  1284. * it then this code needs to be enhanced to handle creating the
  1285. * RAZ/WI region instead of the second MHU.
  1286. */
  1287. assert(info->num_cpus == ARRAY_SIZE(s->mhu));
  1288. for (i = 0; i < ARRAY_SIZE(s->mhu); i++) {
  1289. char *port;
  1290. int cpunum;
  1291. SysBusDevice *mhu_sbd = SYS_BUS_DEVICE(&s->mhu[i]);
  1292. if (!sysbus_realize(SYS_BUS_DEVICE(&s->mhu[i]), errp)) {
  1293. return;
  1294. }
  1295. port = g_strdup_printf("port[%d]", i + 3);
  1296. mr = sysbus_mmio_get_region(mhu_sbd, 0);
  1297. object_property_set_link(OBJECT(&s->apb_ppc[0]), port, OBJECT(mr),
  1298. &error_abort);
  1299. g_free(port);
  1300. /*
  1301. * Each MHU has an irq line for each CPU:
  1302. * MHU 0 irq line 0 -> CPU 0 IRQ 6
  1303. * MHU 0 irq line 1 -> CPU 1 IRQ 6
  1304. * MHU 1 irq line 0 -> CPU 0 IRQ 7
  1305. * MHU 1 irq line 1 -> CPU 1 IRQ 7
  1306. */
  1307. for (cpunum = 0; cpunum < info->num_cpus; cpunum++) {
  1308. DeviceState *cpudev = DEVICE(&s->armv7m[cpunum]);
  1309. sysbus_connect_irq(mhu_sbd, cpunum,
  1310. qdev_get_gpio_in(cpudev, 6 + i));
  1311. }
  1312. }
  1313. }
  1314. if (!sysbus_realize(SYS_BUS_DEVICE(&s->apb_ppc[0]), errp)) {
  1315. return;
  1316. }
  1317. sbd_apb_ppc0 = SYS_BUS_DEVICE(&s->apb_ppc[0]);
  1318. dev_apb_ppc0 = DEVICE(&s->apb_ppc[0]);
  1319. if (info->has_mhus) {
  1320. mr = sysbus_mmio_get_region(sbd_apb_ppc0, 3);
  1321. memory_region_add_subregion(&s->container, 0x40003000, mr);
  1322. mr = sysbus_mmio_get_region(sbd_apb_ppc0, 4);
  1323. memory_region_add_subregion(&s->container, 0x40004000, mr);
  1324. }
  1325. for (i = 0; i < IOTS_APB_PPC0_NUM_PORTS; i++) {
  1326. qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_nonsec", i,
  1327. qdev_get_gpio_in_named(dev_apb_ppc0,
  1328. "cfg_nonsec", i));
  1329. qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_ap", i,
  1330. qdev_get_gpio_in_named(dev_apb_ppc0,
  1331. "cfg_ap", i));
  1332. }
  1333. qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_irq_enable", 0,
  1334. qdev_get_gpio_in_named(dev_apb_ppc0,
  1335. "irq_enable", 0));
  1336. qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_irq_clear", 0,
  1337. qdev_get_gpio_in_named(dev_apb_ppc0,
  1338. "irq_clear", 0));
  1339. qdev_connect_gpio_out(dev_splitter, 0,
  1340. qdev_get_gpio_in_named(dev_apb_ppc0,
  1341. "cfg_sec_resp", 0));
  1342. /* All the PPC irq lines (from the 2 internal PPCs and the 8 external
  1343. * ones) are sent individually to the security controller, and also
  1344. * ORed together to give a single combined PPC interrupt to the NVIC.
  1345. */
  1346. if (!object_property_set_int(OBJECT(&s->ppc_irq_orgate),
  1347. "num-lines", NUM_PPCS, errp)) {
  1348. return;
  1349. }
  1350. if (!qdev_realize(DEVICE(&s->ppc_irq_orgate), NULL, errp)) {
  1351. return;
  1352. }
  1353. qdev_connect_gpio_out(DEVICE(&s->ppc_irq_orgate), 0,
  1354. armsse_get_common_irq_in(s, 10));
  1355. /*
  1356. * 0x40010000 .. 0x4001ffff (and the 0x5001000... secure-only alias):
  1357. * private per-CPU region (all these devices are SSE-200 only):
  1358. * 0x50010000: L1 icache control registers
  1359. * 0x50011000: CPUSECCTRL (CPU local security control registers)
  1360. * 0x4001f000 and 0x5001f000: CPU_IDENTITY register block
  1361. * The SSE-300 has an extra:
  1362. * 0x40012000 and 0x50012000: CPU_PWRCTRL register block
  1363. */
  1364. if (info->has_cachectrl) {
  1365. for (i = 0; i < info->num_cpus; i++) {
  1366. char *name = g_strdup_printf("cachectrl%d", i);
  1367. qdev_prop_set_string(DEVICE(&s->cachectrl[i]), "name", name);
  1368. g_free(name);
  1369. qdev_prop_set_uint64(DEVICE(&s->cachectrl[i]), "size", 0x1000);
  1370. if (!sysbus_realize(SYS_BUS_DEVICE(&s->cachectrl[i]), errp)) {
  1371. return;
  1372. }
  1373. mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cachectrl[i]), 0);
  1374. memory_region_add_subregion(&s->cpu_container[i], 0x50010000, mr);
  1375. }
  1376. }
  1377. if (info->has_cpusecctrl) {
  1378. for (i = 0; i < info->num_cpus; i++) {
  1379. char *name = g_strdup_printf("CPUSECCTRL%d", i);
  1380. qdev_prop_set_string(DEVICE(&s->cpusecctrl[i]), "name", name);
  1381. g_free(name);
  1382. qdev_prop_set_uint64(DEVICE(&s->cpusecctrl[i]), "size", 0x1000);
  1383. if (!sysbus_realize(SYS_BUS_DEVICE(&s->cpusecctrl[i]), errp)) {
  1384. return;
  1385. }
  1386. mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpusecctrl[i]), 0);
  1387. memory_region_add_subregion(&s->cpu_container[i], 0x50011000, mr);
  1388. }
  1389. }
  1390. if (info->has_cpuid) {
  1391. for (i = 0; i < info->num_cpus; i++) {
  1392. qdev_prop_set_uint32(DEVICE(&s->cpuid[i]), "CPUID", i);
  1393. if (!sysbus_realize(SYS_BUS_DEVICE(&s->cpuid[i]), errp)) {
  1394. return;
  1395. }
  1396. mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpuid[i]), 0);
  1397. memory_region_add_subregion(&s->cpu_container[i], 0x4001F000, mr);
  1398. }
  1399. }
  1400. if (info->has_cpu_pwrctrl) {
  1401. for (i = 0; i < info->num_cpus; i++) {
  1402. if (!sysbus_realize(SYS_BUS_DEVICE(&s->cpu_pwrctrl[i]), errp)) {
  1403. return;
  1404. }
  1405. mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpu_pwrctrl[i]), 0);
  1406. memory_region_add_subregion(&s->cpu_container[i], 0x40012000, mr);
  1407. }
  1408. }
  1409. if (!sysbus_realize(SYS_BUS_DEVICE(&s->apb_ppc[1]), errp)) {
  1410. return;
  1411. }
  1412. dev_apb_ppc1 = DEVICE(&s->apb_ppc[1]);
  1413. qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_nonsec", 0,
  1414. qdev_get_gpio_in_named(dev_apb_ppc1,
  1415. "cfg_nonsec", 0));
  1416. qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_ap", 0,
  1417. qdev_get_gpio_in_named(dev_apb_ppc1,
  1418. "cfg_ap", 0));
  1419. qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_irq_enable", 0,
  1420. qdev_get_gpio_in_named(dev_apb_ppc1,
  1421. "irq_enable", 0));
  1422. qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_irq_clear", 0,
  1423. qdev_get_gpio_in_named(dev_apb_ppc1,
  1424. "irq_clear", 0));
  1425. qdev_connect_gpio_out(dev_splitter, 1,
  1426. qdev_get_gpio_in_named(dev_apb_ppc1,
  1427. "cfg_sec_resp", 0));
  1428. /*
  1429. * Now both PPCs are realized we can map the upstream ends of
  1430. * ports which correspond to entries in the devinfo array.
  1431. * The ports which are connected to non-devinfo devices have
  1432. * already been mapped.
  1433. */
  1434. for (devinfo = info->devinfo; devinfo->name; devinfo++) {
  1435. SysBusDevice *ppc_sbd;
  1436. if (devinfo->ppc == NO_PPC) {
  1437. continue;
  1438. }
  1439. ppc_sbd = SYS_BUS_DEVICE(&s->apb_ppc[devinfo->ppc]);
  1440. mr = sysbus_mmio_get_region(ppc_sbd, devinfo->ppc_port);
  1441. memory_region_add_subregion(&s->container, devinfo->addr, mr);
  1442. }
  1443. for (i = 0; i < ARRAY_SIZE(s->ppc_irq_splitter); i++) {
  1444. Object *splitter = OBJECT(&s->ppc_irq_splitter[i]);
  1445. if (!object_property_set_int(splitter, "num-lines", 2, errp)) {
  1446. return;
  1447. }
  1448. if (!qdev_realize(DEVICE(splitter), NULL, errp)) {
  1449. return;
  1450. }
  1451. }
  1452. for (i = 0; i < IOTS_NUM_AHB_EXP_PPC; i++) {
  1453. char *ppcname = g_strdup_printf("ahb_ppcexp%d", i);
  1454. armsse_forward_ppc(s, ppcname, i);
  1455. g_free(ppcname);
  1456. }
  1457. for (i = 0; i < IOTS_NUM_APB_EXP_PPC; i++) {
  1458. char *ppcname = g_strdup_printf("apb_ppcexp%d", i);
  1459. armsse_forward_ppc(s, ppcname, i + IOTS_NUM_AHB_EXP_PPC);
  1460. g_free(ppcname);
  1461. }
  1462. for (i = NUM_EXTERNAL_PPCS; i < NUM_PPCS; i++) {
  1463. /* Wire up IRQ splitter for internal PPCs */
  1464. DeviceState *devs = DEVICE(&s->ppc_irq_splitter[i]);
  1465. char *gpioname = g_strdup_printf("apb_ppc%d_irq_status",
  1466. i - NUM_EXTERNAL_PPCS);
  1467. TZPPC *ppc = &s->apb_ppc[i - NUM_EXTERNAL_PPCS];
  1468. qdev_connect_gpio_out(devs, 0,
  1469. qdev_get_gpio_in_named(dev_secctl, gpioname, 0));
  1470. qdev_connect_gpio_out(devs, 1,
  1471. qdev_get_gpio_in(DEVICE(&s->ppc_irq_orgate), i));
  1472. qdev_connect_gpio_out_named(DEVICE(ppc), "irq", 0,
  1473. qdev_get_gpio_in(devs, 0));
  1474. g_free(gpioname);
  1475. }
  1476. /* Wire up the splitters for the MPC IRQs */
  1477. for (i = 0; i < IOTS_NUM_EXP_MPC + info->sram_banks; i++) {
  1478. SplitIRQ *splitter = &s->mpc_irq_splitter[i];
  1479. DeviceState *devs = DEVICE(splitter);
  1480. if (!object_property_set_int(OBJECT(splitter), "num-lines", 2,
  1481. errp)) {
  1482. return;
  1483. }
  1484. if (!qdev_realize(DEVICE(splitter), NULL, errp)) {
  1485. return;
  1486. }
  1487. if (i < IOTS_NUM_EXP_MPC) {
  1488. /* Splitter input is from GPIO input line */
  1489. s->mpcexp_status_in[i] = qdev_get_gpio_in(devs, 0);
  1490. qdev_connect_gpio_out(devs, 0,
  1491. qdev_get_gpio_in_named(dev_secctl,
  1492. "mpcexp_status", i));
  1493. } else {
  1494. /* Splitter input is from our own MPC */
  1495. qdev_connect_gpio_out_named(DEVICE(&s->mpc[i - IOTS_NUM_EXP_MPC]),
  1496. "irq", 0,
  1497. qdev_get_gpio_in(devs, 0));
  1498. qdev_connect_gpio_out(devs, 0,
  1499. qdev_get_gpio_in_named(dev_secctl,
  1500. "mpc_status",
  1501. i - IOTS_NUM_EXP_MPC));
  1502. }
  1503. qdev_connect_gpio_out(devs, 1,
  1504. qdev_get_gpio_in(DEVICE(&s->mpc_irq_orgate), i));
  1505. }
  1506. /* Create GPIO inputs which will pass the line state for our
  1507. * mpcexp_irq inputs to the correct splitter devices.
  1508. */
  1509. qdev_init_gpio_in_named(dev, armsse_mpcexp_status, "mpcexp_status",
  1510. IOTS_NUM_EXP_MPC);
  1511. armsse_forward_sec_resp_cfg(s);
  1512. /* Forward the MSC related signals */
  1513. qdev_pass_gpios(dev_secctl, dev, "mscexp_status");
  1514. qdev_pass_gpios(dev_secctl, dev, "mscexp_clear");
  1515. qdev_pass_gpios(dev_secctl, dev, "mscexp_ns");
  1516. qdev_connect_gpio_out_named(dev_secctl, "msc_irq", 0,
  1517. armsse_get_common_irq_in(s, 11));
  1518. /*
  1519. * Expose our container region to the board model; this corresponds
  1520. * to the AHB Slave Expansion ports which allow bus master devices
  1521. * (eg DMA controllers) in the board model to make transactions into
  1522. * devices in the ARMSSE.
  1523. */
  1524. sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->container);
  1525. }
  1526. static void armsse_idau_check(IDAUInterface *ii, uint32_t address,
  1527. int *iregion, bool *exempt, bool *ns, bool *nsc)
  1528. {
  1529. /*
  1530. * For ARMSSE systems the IDAU responses are simple logical functions
  1531. * of the address bits. The NSC attribute is guest-adjustable via the
  1532. * NSCCFG register in the security controller.
  1533. */
  1534. ARMSSE *s = ARM_SSE(ii);
  1535. int region = extract32(address, 28, 4);
  1536. *ns = !(region & 1);
  1537. *nsc = (region == 1 && (s->nsccfg & 1)) || (region == 3 && (s->nsccfg & 2));
  1538. /* 0xe0000000..0xe00fffff and 0xf0000000..0xf00fffff are exempt */
  1539. *exempt = (address & 0xeff00000) == 0xe0000000;
  1540. *iregion = region;
  1541. }
  1542. static const VMStateDescription armsse_vmstate = {
  1543. .name = "iotkit",
  1544. .version_id = 2,
  1545. .minimum_version_id = 2,
  1546. .fields = (const VMStateField[]) {
  1547. VMSTATE_CLOCK(mainclk, ARMSSE),
  1548. VMSTATE_CLOCK(s32kclk, ARMSSE),
  1549. VMSTATE_UINT32(nsccfg, ARMSSE),
  1550. VMSTATE_END_OF_LIST()
  1551. }
  1552. };
  1553. static void armsse_reset(DeviceState *dev)
  1554. {
  1555. ARMSSE *s = ARM_SSE(dev);
  1556. s->nsccfg = 0;
  1557. }
  1558. static void armsse_class_init(ObjectClass *klass, void *data)
  1559. {
  1560. DeviceClass *dc = DEVICE_CLASS(klass);
  1561. IDAUInterfaceClass *iic = IDAU_INTERFACE_CLASS(klass);
  1562. ARMSSEClass *asc = ARM_SSE_CLASS(klass);
  1563. const ARMSSEInfo *info = data;
  1564. dc->realize = armsse_realize;
  1565. dc->vmsd = &armsse_vmstate;
  1566. device_class_set_props(dc, info->props);
  1567. device_class_set_legacy_reset(dc, armsse_reset);
  1568. iic->check = armsse_idau_check;
  1569. asc->info = info;
  1570. }
  1571. static const TypeInfo armsse_info = {
  1572. .name = TYPE_ARM_SSE,
  1573. .parent = TYPE_SYS_BUS_DEVICE,
  1574. .instance_size = sizeof(ARMSSE),
  1575. .class_size = sizeof(ARMSSEClass),
  1576. .instance_init = armsse_init,
  1577. .abstract = true,
  1578. .interfaces = (InterfaceInfo[]) {
  1579. { TYPE_IDAU_INTERFACE },
  1580. { }
  1581. }
  1582. };
  1583. static void armsse_register_types(void)
  1584. {
  1585. int i;
  1586. type_register_static(&armsse_info);
  1587. for (i = 0; i < ARRAY_SIZE(armsse_variants); i++) {
  1588. TypeInfo ti = {
  1589. .name = armsse_variants[i].name,
  1590. .parent = TYPE_ARM_SSE,
  1591. .class_init = armsse_class_init,
  1592. .class_data = (void *)&armsse_variants[i],
  1593. };
  1594. type_register(&ti);
  1595. }
  1596. }
  1597. type_init(armsse_register_types);