cortex_a78.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. /*
  2. * Copyright (c) 2019-2022, ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <asm_macros.S>
  8. #include <common/bl_common.h>
  9. #include <cortex_a78.h>
  10. #include <cpu_macros.S>
  11. #include <plat_macros.S>
  12. #include "wa_cve_2022_23960_bhb_vector.S"
  13. /* Hardware handled coherency */
  14. #if HW_ASSISTED_COHERENCY == 0
  15. #error "cortex_a78 must be compiled with HW_ASSISTED_COHERENCY enabled"
  16. #endif
  17. .globl cortex_a78_reset_func
  18. .globl cortex_a78_core_pwr_dwn
  19. #if WORKAROUND_CVE_2022_23960
  20. wa_cve_2022_23960_bhb_vector_table CORTEX_A78_BHB_LOOP_COUNT, cortex_a78
  21. #endif /* WORKAROUND_CVE_2022_23960 */
  22. /* --------------------------------------------------
  23. * Errata Workaround for A78 Erratum 1688305.
  24. * This applies to revision r0p0 and r1p0 of A78.
  25. * Inputs:
  26. * x0: variant[4:7] and revision[0:3] of current cpu.
  27. * Shall clobber: x0-x17
  28. * --------------------------------------------------
  29. */
  30. func errata_a78_1688305_wa
  31. /* Compare x0 against revision r1p0 */
  32. mov x17, x30
  33. bl check_errata_1688305
  34. cbz x0, 1f
  35. mrs x1, CORTEX_A78_ACTLR2_EL1
  36. orr x1, x1, #CORTEX_A78_ACTLR2_EL1_BIT_1
  37. msr CORTEX_A78_ACTLR2_EL1, x1
  38. isb
  39. 1:
  40. ret x17
  41. endfunc errata_a78_1688305_wa
  42. func check_errata_1688305
  43. /* Applies to r0p0 and r1p0 */
  44. mov x1, #0x10
  45. b cpu_rev_var_ls
  46. endfunc check_errata_1688305
  47. /* --------------------------------------------------
  48. * Errata Workaround for Cortex A78 Errata #1941498.
  49. * This applies to revisions r0p0, r1p0, and r1p1.
  50. * x0: variant[4:7] and revision[0:3] of current cpu.
  51. * Shall clobber: x0-x17
  52. * --------------------------------------------------
  53. */
  54. func errata_a78_1941498_wa
  55. /* Compare x0 against revision <= r1p1 */
  56. mov x17, x30
  57. bl check_errata_1941498
  58. cbz x0, 1f
  59. /* Set bit 8 in ECTLR_EL1 */
  60. mrs x1, CORTEX_A78_CPUECTLR_EL1
  61. orr x1, x1, #CORTEX_A78_CPUECTLR_EL1_BIT_8
  62. msr CORTEX_A78_CPUECTLR_EL1, x1
  63. isb
  64. 1:
  65. ret x17
  66. endfunc errata_a78_1941498_wa
  67. func check_errata_1941498
  68. /* Check for revision <= r1p1, might need to be updated later. */
  69. mov x1, #0x11
  70. b cpu_rev_var_ls
  71. endfunc check_errata_1941498
  72. /* --------------------------------------------------
  73. * Errata Workaround for A78 Erratum 1951500.
  74. * This applies to revisions r1p0 and r1p1 of A78.
  75. * The issue also exists in r0p0 but there is no fix
  76. * in that revision.
  77. * Inputs:
  78. * x0: variant[4:7] and revision[0:3] of current cpu.
  79. * Shall clobber: x0-x17
  80. * --------------------------------------------------
  81. */
  82. func errata_a78_1951500_wa
  83. /* Compare x0 against revisions r1p0 - r1p1 */
  84. mov x17, x30
  85. bl check_errata_1951500
  86. cbz x0, 1f
  87. msr S3_6_c15_c8_0, xzr
  88. ldr x0, =0x10E3900002
  89. msr S3_6_c15_c8_2, x0
  90. ldr x0, =0x10FFF00083
  91. msr S3_6_c15_c8_3, x0
  92. ldr x0, =0x2001003FF
  93. msr S3_6_c15_c8_1, x0
  94. mov x0, #1
  95. msr S3_6_c15_c8_0, x0
  96. ldr x0, =0x10E3800082
  97. msr S3_6_c15_c8_2, x0
  98. ldr x0, =0x10FFF00083
  99. msr S3_6_c15_c8_3, x0
  100. ldr x0, =0x2001003FF
  101. msr S3_6_c15_c8_1, x0
  102. mov x0, #2
  103. msr S3_6_c15_c8_0, x0
  104. ldr x0, =0x10E3800200
  105. msr S3_6_c15_c8_2, x0
  106. ldr x0, =0x10FFF003E0
  107. msr S3_6_c15_c8_3, x0
  108. ldr x0, =0x2001003FF
  109. msr S3_6_c15_c8_1, x0
  110. isb
  111. 1:
  112. ret x17
  113. endfunc errata_a78_1951500_wa
  114. func check_errata_1951500
  115. /* Applies to revisions r1p0 and r1p1. */
  116. mov x1, #CPU_REV(1, 0)
  117. mov x2, #CPU_REV(1, 1)
  118. b cpu_rev_var_range
  119. endfunc check_errata_1951500
  120. /* --------------------------------------------------
  121. * Errata Workaround for Cortex A78 Errata #1821534.
  122. * This applies to revisions r0p0 and r1p0.
  123. * x0: variant[4:7] and revision[0:3] of current cpu.
  124. * Shall clobber: x0-x17
  125. * --------------------------------------------------
  126. */
  127. func errata_a78_1821534_wa
  128. /* Check revision. */
  129. mov x17, x30
  130. bl check_errata_1821534
  131. cbz x0, 1f
  132. /* Set bit 2 in ACTLR2_EL1 */
  133. mrs x1, CORTEX_A78_ACTLR2_EL1
  134. orr x1, x1, #CORTEX_A78_ACTLR2_EL1_BIT_2
  135. msr CORTEX_A78_ACTLR2_EL1, x1
  136. isb
  137. 1:
  138. ret x17
  139. endfunc errata_a78_1821534_wa
  140. func check_errata_1821534
  141. /* Applies to r0p0 and r1p0 */
  142. mov x1, #0x10
  143. b cpu_rev_var_ls
  144. endfunc check_errata_1821534
  145. /* --------------------------------------------------
  146. * Errata Workaround for Cortex A78 Errata 1952683.
  147. * This applies to revision r0p0.
  148. * x0: variant[4:7] and revision[0:3] of current cpu.
  149. * Shall clobber: x0-x17
  150. * --------------------------------------------------
  151. */
  152. func errata_a78_1952683_wa
  153. /* Check revision. */
  154. mov x17, x30
  155. bl check_errata_1952683
  156. cbz x0, 1f
  157. ldr x0,=0x5
  158. msr S3_6_c15_c8_0,x0
  159. ldr x0,=0xEEE10A10
  160. msr S3_6_c15_c8_2,x0
  161. ldr x0,=0xFFEF0FFF
  162. msr S3_6_c15_c8_3,x0
  163. ldr x0,=0x0010F000
  164. msr S3_6_c15_c8_4,x0
  165. ldr x0,=0x0010F000
  166. msr S3_6_c15_c8_5,x0
  167. ldr x0,=0x40000080023ff
  168. msr S3_6_c15_c8_1,x0
  169. ldr x0,=0x6
  170. msr S3_6_c15_c8_0,x0
  171. ldr x0,=0xEE640F34
  172. msr S3_6_c15_c8_2,x0
  173. ldr x0,=0xFFEF0FFF
  174. msr S3_6_c15_c8_3,x0
  175. ldr x0,=0x40000080023ff
  176. msr S3_6_c15_c8_1,x0
  177. isb
  178. 1:
  179. ret x17
  180. endfunc errata_a78_1952683_wa
  181. func check_errata_1952683
  182. /* Applies to r0p0 only */
  183. mov x1, #0x00
  184. b cpu_rev_var_ls
  185. endfunc check_errata_1952683
  186. /* --------------------------------------------------
  187. * Errata Workaround for Cortex A78 Errata 2132060.
  188. * This applies to revisions r0p0, r1p0, r1p1, and r1p2.
  189. * It is still open.
  190. * x0: variant[4:7] and revision[0:3] of current cpu.
  191. * Shall clobber: x0-x1, x17
  192. * --------------------------------------------------
  193. */
  194. func errata_a78_2132060_wa
  195. /* Check revision. */
  196. mov x17, x30
  197. bl check_errata_2132060
  198. cbz x0, 1f
  199. /* Apply the workaround. */
  200. mrs x1, CORTEX_A78_CPUECTLR_EL1
  201. mov x0, #CORTEX_A78_CPUECTLR_EL1_PF_MODE_CNSRV
  202. bfi x1, x0, #CPUECTLR_EL1_PF_MODE_LSB, #CPUECTLR_EL1_PF_MODE_WIDTH
  203. msr CORTEX_A78_CPUECTLR_EL1, x1
  204. 1:
  205. ret x17
  206. endfunc errata_a78_2132060_wa
  207. func check_errata_2132060
  208. /* Applies to r0p0, r0p1, r1p1, and r1p2 */
  209. mov x1, #0x12
  210. b cpu_rev_var_ls
  211. endfunc check_errata_2132060
  212. /* --------------------------------------------------------------------
  213. * Errata Workaround for A78 Erratum 2242635.
  214. * This applies to revisions r1p0, r1p1, and r1p2 of the Cortex A78
  215. * processor and is still open.
  216. * The issue also exists in r0p0 but there is no fix in that revision.
  217. * x0: variant[4:7] and revision[0:3] of current cpu.
  218. * Shall clobber: x0-x17
  219. * --------------------------------------------------------------------
  220. */
  221. func errata_a78_2242635_wa
  222. /* Compare x0 against revisions r1p0 - r1p2 */
  223. mov x17, x30
  224. bl check_errata_2242635
  225. cbz x0, 1f
  226. ldr x0, =0x5
  227. msr S3_6_c15_c8_0, x0 /* CPUPSELR_EL3 */
  228. ldr x0, =0x10F600E000
  229. msr S3_6_c15_c8_2, x0 /* CPUPOR_EL3 */
  230. ldr x0, =0x10FF80E000
  231. msr S3_6_c15_c8_3, x0 /* CPUPMR_EL3 */
  232. ldr x0, =0x80000000003FF
  233. msr S3_6_c15_c8_1, x0 /* CPUPCR_EL3 */
  234. isb
  235. 1:
  236. ret x17
  237. endfunc errata_a78_2242635_wa
  238. func check_errata_2242635
  239. /* Applies to revisions r1p0 through r1p2. */
  240. mov x1, #CPU_REV(1, 0)
  241. mov x2, #CPU_REV(1, 2)
  242. b cpu_rev_var_range
  243. endfunc check_errata_2242635
  244. /* --------------------------------------------------
  245. * Errata Workaround for Cortex A78 Errata 2376745.
  246. * This applies to revisions r0p0, r1p0, r1p1, and r1p2.
  247. * It is still open.
  248. * x0: variant[4:7] and revision[0:3] of current cpu.
  249. * Shall clobber: x0-x1, x17
  250. * --------------------------------------------------
  251. */
  252. func errata_a78_2376745_wa
  253. /* Check revision. */
  254. mov x17, x30
  255. bl check_errata_2376745
  256. cbz x0, 1f
  257. /* Apply the workaround. */
  258. mrs x1, CORTEX_A78_ACTLR2_EL1
  259. orr x1, x1, #BIT(0)
  260. msr CORTEX_A78_ACTLR2_EL1, x1
  261. 1:
  262. ret x17
  263. endfunc errata_a78_2376745_wa
  264. func check_errata_2376745
  265. /* Applies to r0p0, r0p1, r1p1, and r1p2 */
  266. mov x1, #CPU_REV(1, 2)
  267. b cpu_rev_var_ls
  268. endfunc check_errata_2376745
  269. /* --------------------------------------------------
  270. * Errata Workaround for Cortex A78 Errata 2395406.
  271. * This applies to revisions r0p0, r1p0, r1p1, and r1p2.
  272. * It is still open.
  273. * x0: variant[4:7] and revision[0:3] of current cpu.
  274. * Shall clobber: x0-x1, x17
  275. * --------------------------------------------------
  276. */
  277. func errata_a78_2395406_wa
  278. /* Check revision. */
  279. mov x17, x30
  280. bl check_errata_2395406
  281. cbz x0, 1f
  282. /* Apply the workaround. */
  283. mrs x1, CORTEX_A78_ACTLR2_EL1
  284. orr x1, x1, #BIT(40)
  285. msr CORTEX_A78_ACTLR2_EL1, x1
  286. 1:
  287. ret x17
  288. endfunc errata_a78_2395406_wa
  289. func check_errata_2395406
  290. /* Applies to r0p0, r0p1, r1p1, and r1p2 */
  291. mov x1, #CPU_REV(1, 2)
  292. b cpu_rev_var_ls
  293. endfunc check_errata_2395406
  294. func check_errata_cve_2022_23960
  295. #if WORKAROUND_CVE_2022_23960
  296. mov x0, #ERRATA_APPLIES
  297. #else
  298. mov x0, #ERRATA_MISSING
  299. #endif
  300. ret
  301. endfunc check_errata_cve_2022_23960
  302. /* -------------------------------------------------
  303. * The CPU Ops reset function for Cortex-A78
  304. * -------------------------------------------------
  305. */
  306. func cortex_a78_reset_func
  307. mov x19, x30
  308. bl cpu_get_rev_var
  309. mov x18, x0
  310. #if ERRATA_A78_1688305
  311. mov x0, x18
  312. bl errata_a78_1688305_wa
  313. #endif
  314. #if ERRATA_A78_1941498
  315. mov x0, x18
  316. bl errata_a78_1941498_wa
  317. #endif
  318. #if ERRATA_A78_1951500
  319. mov x0, x18
  320. bl errata_a78_1951500_wa
  321. #endif
  322. #if ERRATA_A78_1821534
  323. mov x0, x18
  324. bl errata_a78_1821534_wa
  325. #endif
  326. #if ERRATA_A78_1952683
  327. mov x0, x18
  328. bl errata_a78_1952683_wa
  329. #endif
  330. #if ERRATA_A78_2132060
  331. mov x0, x18
  332. bl errata_a78_2132060_wa
  333. #endif
  334. #if ERRATA_A78_2242635
  335. mov x0, x18
  336. bl errata_a78_2242635_wa
  337. #endif
  338. #if ERRATA_A78_2376745
  339. mov x0, x18
  340. bl errata_a78_2376745_wa
  341. #endif
  342. #if ERRATA_A78_2395406
  343. mov x0, x18
  344. bl errata_a78_2395406_wa
  345. #endif
  346. #if ENABLE_AMU
  347. /* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */
  348. mrs x0, actlr_el3
  349. bic x0, x0, #CORTEX_A78_ACTLR_TAM_BIT
  350. msr actlr_el3, x0
  351. /* Make sure accesses from non-secure EL0/EL1 are not trapped to EL2 */
  352. mrs x0, actlr_el2
  353. bic x0, x0, #CORTEX_A78_ACTLR_TAM_BIT
  354. msr actlr_el2, x0
  355. /* Enable group0 counters */
  356. mov x0, #CORTEX_A78_AMU_GROUP0_MASK
  357. msr CPUAMCNTENSET0_EL0, x0
  358. /* Enable group1 counters */
  359. mov x0, #CORTEX_A78_AMU_GROUP1_MASK
  360. msr CPUAMCNTENSET1_EL0, x0
  361. #endif
  362. #if IMAGE_BL31 && WORKAROUND_CVE_2022_23960
  363. /*
  364. * The Cortex-A78 generic vectors are overridden to apply errata
  365. * mitigation on exception entry from lower ELs.
  366. */
  367. adr x0, wa_cve_vbar_cortex_a78
  368. msr vbar_el3, x0
  369. #endif /* IMAGE_BL31 && WORKAROUND_CVE_2022_23960 */
  370. isb
  371. ret x19
  372. endfunc cortex_a78_reset_func
  373. /* ---------------------------------------------
  374. * HW will do the cache maintenance while powering down
  375. * ---------------------------------------------
  376. */
  377. func cortex_a78_core_pwr_dwn
  378. /* ---------------------------------------------
  379. * Enable CPU power down bit in power control register
  380. * ---------------------------------------------
  381. */
  382. mrs x0, CORTEX_A78_CPUPWRCTLR_EL1
  383. orr x0, x0, #CORTEX_A78_CPUPWRCTLR_EL1_CORE_PWRDN_EN_BIT
  384. msr CORTEX_A78_CPUPWRCTLR_EL1, x0
  385. isb
  386. ret
  387. endfunc cortex_a78_core_pwr_dwn
  388. /*
  389. * Errata printing function for cortex_a78. Must follow AAPCS.
  390. */
  391. #if REPORT_ERRATA
  392. func cortex_a78_errata_report
  393. stp x8, x30, [sp, #-16]!
  394. bl cpu_get_rev_var
  395. mov x8, x0
  396. /*
  397. * Report all errata. The revision-variant information is passed to
  398. * checking functions of each errata.
  399. */
  400. report_errata ERRATA_A78_1688305, cortex_a78, 1688305
  401. report_errata ERRATA_A78_1941498, cortex_a78, 1941498
  402. report_errata ERRATA_A78_1951500, cortex_a78, 1951500
  403. report_errata ERRATA_A78_1821534, cortex_a78, 1821534
  404. report_errata ERRATA_A78_1952683, cortex_a78, 1952683
  405. report_errata ERRATA_A78_2132060, cortex_a78, 2132060
  406. report_errata ERRATA_A78_2242635, cortex_a78, 2242635
  407. report_errata ERRATA_A78_2376745, cortex_a78, 2376745
  408. report_errata ERRATA_A78_2395406, cortex_a78, 2395406
  409. report_errata WORKAROUND_CVE_2022_23960, cortex_a78, cve_2022_23960
  410. ldp x8, x30, [sp], #16
  411. ret
  412. endfunc cortex_a78_errata_report
  413. #endif
  414. /* ---------------------------------------------
  415. * This function provides cortex_a78 specific
  416. * register information for crash reporting.
  417. * It needs to return with x6 pointing to
  418. * a list of register names in ascii and
  419. * x8 - x15 having values of registers to be
  420. * reported.
  421. * ---------------------------------------------
  422. */
  423. .section .rodata.cortex_a78_regs, "aS"
  424. cortex_a78_regs: /* The ascii list of register names to be reported */
  425. .asciz "cpuectlr_el1", ""
  426. func cortex_a78_cpu_reg_dump
  427. adr x6, cortex_a78_regs
  428. mrs x8, CORTEX_A78_CPUECTLR_EL1
  429. ret
  430. endfunc cortex_a78_cpu_reg_dump
  431. declare_cpu_ops cortex_a78, CORTEX_A78_MIDR, \
  432. cortex_a78_reset_func, \
  433. cortex_a78_core_pwr_dwn