cortex_a57.S 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /*
  2. * Copyright (c) 2017-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <asm_macros.S>
  8. #include <assert_macros.S>
  9. #include <common/debug.h>
  10. #include <cortex_a57.h>
  11. #include <cpu_macros.S>
  12. /* ---------------------------------------------
  13. * Disable intra-cluster coherency
  14. * Clobbers: r0-r1
  15. * ---------------------------------------------
  16. */
  17. func cortex_a57_disable_smp
  18. ldcopr16 r0, r1, CORTEX_A57_ECTLR
  19. bic64_imm r0, r1, CORTEX_A57_ECTLR_SMP_BIT
  20. stcopr16 r0, r1, CORTEX_A57_ECTLR
  21. bx lr
  22. endfunc cortex_a57_disable_smp
  23. /* ---------------------------------------------
  24. * Disable all types of L2 prefetches.
  25. * Clobbers: r0-r2
  26. * ---------------------------------------------
  27. */
  28. func cortex_a57_disable_l2_prefetch
  29. ldcopr16 r0, r1, CORTEX_A57_ECTLR
  30. orr64_imm r0, r1, CORTEX_A57_ECTLR_DIS_TWD_ACC_PFTCH_BIT
  31. bic64_imm r0, r1, (CORTEX_A57_ECTLR_L2_IPFTCH_DIST_MASK | \
  32. CORTEX_A57_ECTLR_L2_DPFTCH_DIST_MASK)
  33. stcopr16 r0, r1, CORTEX_A57_ECTLR
  34. isb
  35. dsb ish
  36. bx lr
  37. endfunc cortex_a57_disable_l2_prefetch
  38. /* ---------------------------------------------
  39. * Disable debug interfaces
  40. * ---------------------------------------------
  41. */
  42. func cortex_a57_disable_ext_debug
  43. mov r0, #1
  44. stcopr r0, DBGOSDLR
  45. isb
  46. #if ERRATA_A57_817169
  47. /*
  48. * Invalidate any TLB address
  49. */
  50. mov r0, #0
  51. stcopr r0, TLBIMVA
  52. #endif
  53. dsb sy
  54. bx lr
  55. endfunc cortex_a57_disable_ext_debug
  56. /* --------------------------------------------------
  57. * Errata Workaround for Cortex A57 Errata #806969.
  58. * This applies only to revision r0p0 of Cortex A57.
  59. * Inputs:
  60. * r0: variant[4:7] and revision[0:3] of current cpu.
  61. * Shall clobber: r0-r3
  62. * --------------------------------------------------
  63. */
  64. func errata_a57_806969_wa
  65. /*
  66. * Compare r0 against revision r0p0
  67. */
  68. mov r2, lr
  69. bl check_errata_806969
  70. mov lr, r2
  71. cmp r0, #ERRATA_NOT_APPLIES
  72. beq 1f
  73. ldcopr16 r0, r1, CORTEX_A57_CPUACTLR
  74. orr64_imm r0, r1, CORTEX_A57_CPUACTLR_NO_ALLOC_WBWA
  75. stcopr16 r0, r1, CORTEX_A57_CPUACTLR
  76. 1:
  77. bx lr
  78. endfunc errata_a57_806969_wa
  79. func check_errata_806969
  80. mov r1, #0x00
  81. b cpu_rev_var_ls
  82. endfunc check_errata_806969
  83. add_erratum_entry cortex_a57, ERRATUM(806969), ERRATA_A57_806969
  84. /* ---------------------------------------------------
  85. * Errata Workaround for Cortex A57 Errata #813419.
  86. * This applies only to revision r0p0 of Cortex A57.
  87. * ---------------------------------------------------
  88. */
  89. func check_errata_813419
  90. /*
  91. * Even though this is only needed for revision r0p0, it
  92. * is always applied due to limitations of the current
  93. * errata framework.
  94. */
  95. mov r0, #ERRATA_APPLIES
  96. bx lr
  97. endfunc check_errata_813419
  98. add_erratum_entry cortex_a57, ERRATUM(813419), ERRATA_A57_813419
  99. /* ---------------------------------------------------
  100. * Errata Workaround for Cortex A57 Errata #813420.
  101. * This applies only to revision r0p0 of Cortex A57.
  102. * Inputs:
  103. * r0: variant[4:7] and revision[0:3] of current cpu.
  104. * Shall clobber: r0-r3
  105. * ---------------------------------------------------
  106. */
  107. func errata_a57_813420_wa
  108. /*
  109. * Compare r0 against revision r0p0
  110. */
  111. mov r2, lr
  112. bl check_errata_813420
  113. mov lr, r2
  114. cmp r0, #ERRATA_NOT_APPLIES
  115. beq 1f
  116. ldcopr16 r0, r1, CORTEX_A57_CPUACTLR
  117. orr64_imm r0, r1, CORTEX_A57_CPUACTLR_DCC_AS_DCCI
  118. stcopr16 r0, r1, CORTEX_A57_CPUACTLR
  119. 1:
  120. bx lr
  121. endfunc errata_a57_813420_wa
  122. func check_errata_813420
  123. mov r1, #0x00
  124. b cpu_rev_var_ls
  125. endfunc check_errata_813420
  126. add_erratum_entry cortex_a57, ERRATUM(813420), ERRATA_A57_813420
  127. /* ---------------------------------------------------
  128. * Errata Workaround for Cortex A57 Errata #814670.
  129. * This applies only to revision r0p0 of Cortex A57.
  130. * Inputs:
  131. * r0: variant[4:7] and revision[0:3] of current cpu.
  132. * Shall clobber: r0-r3
  133. * ---------------------------------------------------
  134. */
  135. func errata_a57_814670_wa
  136. /*
  137. * Compare r0 against revision r0p0
  138. */
  139. mov r2, lr
  140. bl check_errata_814670
  141. cmp r0, #ERRATA_NOT_APPLIES
  142. beq 1f
  143. ldcopr16 r0, r1, CORTEX_A57_CPUACTLR
  144. orr64_imm r0, r1, CORTEX_A57_CPUACTLR_DIS_DMB_NULLIFICATION
  145. stcopr16 r0, r1, CORTEX_A57_CPUACTLR
  146. isb
  147. 1:
  148. bx r2
  149. endfunc errata_a57_814670_wa
  150. func check_errata_814670
  151. mov r1, #0x00
  152. b cpu_rev_var_ls
  153. endfunc check_errata_814670
  154. add_erratum_entry cortex_a57, ERRATUM(814670), ERRATA_A57_814670
  155. /* ----------------------------------------------------
  156. * Errata Workaround for Cortex A57 Errata #817169.
  157. * This applies only to revision <= r0p1 of Cortex A57.
  158. * ----------------------------------------------------
  159. */
  160. func check_errata_817169
  161. /*
  162. * Even though this is only needed for revision <= r0p1, it
  163. * is always applied because of the low cost of the workaround.
  164. */
  165. mov r0, #ERRATA_APPLIES
  166. bx lr
  167. endfunc check_errata_817169
  168. add_erratum_entry cortex_a57, ERRATUM(817169), ERRATA_A57_817169
  169. /* --------------------------------------------------------------------
  170. * Disable the over-read from the LDNP instruction.
  171. *
  172. * This applies to all revisions <= r1p2. The performance degradation
  173. * observed with LDNP/STNP has been fixed on r1p3 and onwards.
  174. *
  175. * Inputs:
  176. * r0: variant[4:7] and revision[0:3] of current cpu.
  177. * Shall clobber: r0-r3
  178. * ---------------------------------------------------------------------
  179. */
  180. func a57_disable_ldnp_overread
  181. /*
  182. * Compare r0 against revision r1p2
  183. */
  184. mov r2, lr
  185. bl check_errata_disable_ldnp_overread
  186. mov lr, r2
  187. cmp r0, #ERRATA_NOT_APPLIES
  188. beq 1f
  189. ldcopr16 r0, r1, CORTEX_A57_CPUACTLR
  190. orr64_imm r0, r1, CORTEX_A57_CPUACTLR_DIS_OVERREAD
  191. stcopr16 r0, r1, CORTEX_A57_CPUACTLR
  192. 1:
  193. bx lr
  194. endfunc a57_disable_ldnp_overread
  195. func check_errata_disable_ldnp_overread
  196. mov r1, #0x12
  197. b cpu_rev_var_ls
  198. endfunc check_errata_disable_ldnp_overread
  199. add_erratum_entry cortex_a57, ERRATUM(1), A57_DISABLE_NON_TEMPORAL_HINT, disable_ldnp_overread
  200. /* ---------------------------------------------------
  201. * Errata Workaround for Cortex A57 Errata #826974.
  202. * This applies only to revision <= r1p1 of Cortex A57.
  203. * Inputs:
  204. * r0: variant[4:7] and revision[0:3] of current cpu.
  205. * Shall clobber: r0-r3
  206. * ---------------------------------------------------
  207. */
  208. func errata_a57_826974_wa
  209. /*
  210. * Compare r0 against revision r1p1
  211. */
  212. mov r2, lr
  213. bl check_errata_826974
  214. mov lr, r2
  215. cmp r0, #ERRATA_NOT_APPLIES
  216. beq 1f
  217. ldcopr16 r0, r1, CORTEX_A57_CPUACTLR
  218. orr64_imm r0, r1, CORTEX_A57_CPUACTLR_DIS_LOAD_PASS_DMB
  219. stcopr16 r0, r1, CORTEX_A57_CPUACTLR
  220. 1:
  221. bx lr
  222. endfunc errata_a57_826974_wa
  223. func check_errata_826974
  224. mov r1, #0x11
  225. b cpu_rev_var_ls
  226. endfunc check_errata_826974
  227. add_erratum_entry cortex_a57, ERRATUM(826974), ERRATA_A57_826974
  228. /* ---------------------------------------------------
  229. * Errata Workaround for Cortex A57 Errata #826977.
  230. * This applies only to revision <= r1p1 of Cortex A57.
  231. * Inputs:
  232. * r0: variant[4:7] and revision[0:3] of current cpu.
  233. * Shall clobber: r0-r3
  234. * ---------------------------------------------------
  235. */
  236. func errata_a57_826977_wa
  237. /*
  238. * Compare r0 against revision r1p1
  239. */
  240. mov r2, lr
  241. bl check_errata_826977
  242. mov lr, r2
  243. cmp r0, #ERRATA_NOT_APPLIES
  244. beq 1f
  245. ldcopr16 r0, r1, CORTEX_A57_CPUACTLR
  246. orr64_imm r0, r1, CORTEX_A57_CPUACTLR_GRE_NGRE_AS_NGNRE
  247. stcopr16 r0, r1, CORTEX_A57_CPUACTLR
  248. 1:
  249. bx lr
  250. endfunc errata_a57_826977_wa
  251. func check_errata_826977
  252. mov r1, #0x11
  253. b cpu_rev_var_ls
  254. endfunc check_errata_826977
  255. add_erratum_entry cortex_a57, ERRATUM(826977), ERRATA_A57_826977
  256. /* ---------------------------------------------------
  257. * Errata Workaround for Cortex A57 Errata #828024.
  258. * This applies only to revision <= r1p1 of Cortex A57.
  259. * Inputs:
  260. * r0: variant[4:7] and revision[0:3] of current cpu.
  261. * Shall clobber: r0-r3
  262. * ---------------------------------------------------
  263. */
  264. func errata_a57_828024_wa
  265. /*
  266. * Compare r0 against revision r1p1
  267. */
  268. mov r2, lr
  269. bl check_errata_828024
  270. mov lr, r2
  271. cmp r0, #ERRATA_NOT_APPLIES
  272. beq 1f
  273. ldcopr16 r0, r1, CORTEX_A57_CPUACTLR
  274. /*
  275. * Setting the relevant bits in CORTEX_A57_CPUACTLR has to be done in 2
  276. * instructions here because the resulting bitmask doesn't fit in a
  277. * 16-bit value so it cannot be encoded in a single instruction.
  278. */
  279. orr64_imm r0, r1, CORTEX_A57_CPUACTLR_NO_ALLOC_WBWA
  280. orr64_imm r0, r1, (CORTEX_A57_CPUACTLR_DIS_L1_STREAMING | CORTEX_A57_CPUACTLR_DIS_STREAMING)
  281. stcopr16 r0, r1, CORTEX_A57_CPUACTLR
  282. 1:
  283. bx lr
  284. endfunc errata_a57_828024_wa
  285. func check_errata_828024
  286. mov r1, #0x11
  287. b cpu_rev_var_ls
  288. endfunc check_errata_828024
  289. add_erratum_entry cortex_a57, ERRATUM(828024), ERRATA_A57_828024
  290. /* ---------------------------------------------------
  291. * Errata Workaround for Cortex A57 Errata #829520.
  292. * This applies only to revision <= r1p2 of Cortex A57.
  293. * Inputs:
  294. * r0: variant[4:7] and revision[0:3] of current cpu.
  295. * Shall clobber: r0-r3
  296. * ---------------------------------------------------
  297. */
  298. func errata_a57_829520_wa
  299. /*
  300. * Compare r0 against revision r1p2
  301. */
  302. mov r2, lr
  303. bl check_errata_829520
  304. mov lr, r2
  305. cmp r0, #ERRATA_NOT_APPLIES
  306. beq 1f
  307. ldcopr16 r0, r1, CORTEX_A57_CPUACTLR
  308. orr64_imm r0, r1, CORTEX_A57_CPUACTLR_DIS_INDIRECT_PREDICTOR
  309. stcopr16 r0, r1, CORTEX_A57_CPUACTLR
  310. 1:
  311. bx lr
  312. endfunc errata_a57_829520_wa
  313. func check_errata_829520
  314. mov r1, #0x12
  315. b cpu_rev_var_ls
  316. endfunc check_errata_829520
  317. add_erratum_entry cortex_a57, ERRATUM(829520), ERRATA_A57_829520
  318. /* ---------------------------------------------------
  319. * Errata Workaround for Cortex A57 Errata #833471.
  320. * This applies only to revision <= r1p2 of Cortex A57.
  321. * Inputs:
  322. * r0: variant[4:7] and revision[0:3] of current cpu.
  323. * Shall clobber: r0-r3
  324. * ---------------------------------------------------
  325. */
  326. func errata_a57_833471_wa
  327. /*
  328. * Compare r0 against revision r1p2
  329. */
  330. mov r2, lr
  331. bl check_errata_833471
  332. mov lr, r2
  333. cmp r0, #ERRATA_NOT_APPLIES
  334. beq 1f
  335. ldcopr16 r0, r1, CORTEX_A57_CPUACTLR
  336. orr64_imm r1, r1, CORTEX_A57_CPUACTLR_FORCE_FPSCR_FLUSH
  337. stcopr16 r0, r1, CORTEX_A57_CPUACTLR
  338. 1:
  339. bx lr
  340. endfunc errata_a57_833471_wa
  341. func check_errata_833471
  342. mov r1, #0x12
  343. b cpu_rev_var_ls
  344. endfunc check_errata_833471
  345. add_erratum_entry cortex_a57, ERRATUM(833471), ERRATA_A57_833471
  346. /* ---------------------------------------------------
  347. * Errata Workaround for Cortex A57 Errata #859972.
  348. * This applies only to revision <= r1p3 of Cortex A57.
  349. * Inputs:
  350. * r0: variant[4:7] and revision[0:3] of current cpu.
  351. * Shall clobber: r0-r3
  352. * ---------------------------------------------------
  353. */
  354. func errata_a57_859972_wa
  355. mov r2, lr
  356. bl check_errata_859972
  357. mov lr, r2
  358. cmp r0, #ERRATA_NOT_APPLIES
  359. beq 1f
  360. ldcopr16 r0, r1, CORTEX_A57_CPUACTLR
  361. orr64_imm r1, r1, CORTEX_A57_CPUACTLR_DIS_INSTR_PREFETCH
  362. stcopr16 r0, r1, CORTEX_A57_CPUACTLR
  363. 1:
  364. bx lr
  365. endfunc errata_a57_859972_wa
  366. func check_errata_859972
  367. mov r1, #0x13
  368. b cpu_rev_var_ls
  369. endfunc check_errata_859972
  370. add_erratum_entry cortex_a57, ERRATUM(859972), ERRATA_A57_859972
  371. func check_errata_cve_2017_5715
  372. mov r0, #ERRATA_MISSING
  373. bx lr
  374. endfunc check_errata_cve_2017_5715
  375. add_erratum_entry cortex_a57, CVE(2017, 5715), WORKAROUND_CVE_2017_5715
  376. func check_errata_cve_2018_3639
  377. #if WORKAROUND_CVE_2018_3639
  378. mov r0, #ERRATA_APPLIES
  379. #else
  380. mov r0, #ERRATA_MISSING
  381. #endif
  382. bx lr
  383. endfunc check_errata_cve_2018_3639
  384. add_erratum_entry cortex_a57, CVE(2018, 3639), WORKAROUND_CVE_2018_3639
  385. func check_errata_cve_2022_23960
  386. mov r0, #ERRATA_MISSING
  387. bx lr
  388. endfunc check_errata_cve_2022_23960
  389. add_erratum_entry cortex_a57, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
  390. /* -------------------------------------------------
  391. * The CPU Ops reset function for Cortex-A57.
  392. * Shall clobber: r0-r6
  393. * -------------------------------------------------
  394. */
  395. func cortex_a57_reset_func
  396. mov r5, lr
  397. bl cpu_get_rev_var
  398. mov r4, r0
  399. #if ERRATA_A57_806969
  400. mov r0, r4
  401. bl errata_a57_806969_wa
  402. #endif
  403. #if ERRATA_A57_813420
  404. mov r0, r4
  405. bl errata_a57_813420_wa
  406. #endif
  407. #if ERRATA_A57_814670
  408. mov r0, r4
  409. bl errata_a57_814670_wa
  410. #endif
  411. #if A57_DISABLE_NON_TEMPORAL_HINT
  412. mov r0, r4
  413. bl a57_disable_ldnp_overread
  414. #endif
  415. #if ERRATA_A57_826974
  416. mov r0, r4
  417. bl errata_a57_826974_wa
  418. #endif
  419. #if ERRATA_A57_826977
  420. mov r0, r4
  421. bl errata_a57_826977_wa
  422. #endif
  423. #if ERRATA_A57_828024
  424. mov r0, r4
  425. bl errata_a57_828024_wa
  426. #endif
  427. #if ERRATA_A57_829520
  428. mov r0, r4
  429. bl errata_a57_829520_wa
  430. #endif
  431. #if ERRATA_A57_833471
  432. mov r0, r4
  433. bl errata_a57_833471_wa
  434. #endif
  435. #if ERRATA_A57_859972
  436. mov r0, r4
  437. bl errata_a57_859972_wa
  438. #endif
  439. #if WORKAROUND_CVE_2018_3639
  440. ldcopr16 r0, r1, CORTEX_A57_CPUACTLR
  441. orr64_imm r0, r1, CORTEX_A57_CPUACTLR_DIS_LOAD_PASS_STORE
  442. stcopr16 r0, r1, CORTEX_A57_CPUACTLR
  443. isb
  444. dsb sy
  445. #endif
  446. /* ---------------------------------------------
  447. * Enable the SMP bit.
  448. * ---------------------------------------------
  449. */
  450. ldcopr16 r0, r1, CORTEX_A57_ECTLR
  451. orr64_imm r0, r1, CORTEX_A57_ECTLR_SMP_BIT
  452. stcopr16 r0, r1, CORTEX_A57_ECTLR
  453. isb
  454. bx r5
  455. endfunc cortex_a57_reset_func
  456. /* ----------------------------------------------------
  457. * The CPU Ops core power down function for Cortex-A57.
  458. * ----------------------------------------------------
  459. */
  460. func cortex_a57_core_pwr_dwn
  461. push {r12, lr}
  462. /* Assert if cache is enabled */
  463. #if ENABLE_ASSERTIONS
  464. ldcopr r0, SCTLR
  465. tst r0, #SCTLR_C_BIT
  466. ASM_ASSERT(eq)
  467. #endif
  468. /* ---------------------------------------------
  469. * Disable the L2 prefetches.
  470. * ---------------------------------------------
  471. */
  472. bl cortex_a57_disable_l2_prefetch
  473. /* ---------------------------------------------
  474. * Flush L1 caches.
  475. * ---------------------------------------------
  476. */
  477. mov r0, #DC_OP_CISW
  478. bl dcsw_op_level1
  479. /* ---------------------------------------------
  480. * Come out of intra cluster coherency
  481. * ---------------------------------------------
  482. */
  483. bl cortex_a57_disable_smp
  484. /* ---------------------------------------------
  485. * Force the debug interfaces to be quiescent
  486. * ---------------------------------------------
  487. */
  488. pop {r12, lr}
  489. b cortex_a57_disable_ext_debug
  490. endfunc cortex_a57_core_pwr_dwn
  491. /* -------------------------------------------------------
  492. * The CPU Ops cluster power down function for Cortex-A57.
  493. * Clobbers: r0-r3
  494. * -------------------------------------------------------
  495. */
  496. func cortex_a57_cluster_pwr_dwn
  497. push {r12, lr}
  498. /* Assert if cache is enabled */
  499. #if ENABLE_ASSERTIONS
  500. ldcopr r0, SCTLR
  501. tst r0, #SCTLR_C_BIT
  502. ASM_ASSERT(eq)
  503. #endif
  504. /* ---------------------------------------------
  505. * Disable the L2 prefetches.
  506. * ---------------------------------------------
  507. */
  508. bl cortex_a57_disable_l2_prefetch
  509. /* ---------------------------------------------
  510. * Flush L1 caches.
  511. * ---------------------------------------------
  512. */
  513. mov r0, #DC_OP_CISW
  514. bl dcsw_op_level1
  515. /* ---------------------------------------------
  516. * Disable the optional ACP.
  517. * ---------------------------------------------
  518. */
  519. bl plat_disable_acp
  520. /* ---------------------------------------------
  521. * Flush L2 caches.
  522. * ---------------------------------------------
  523. */
  524. mov r0, #DC_OP_CISW
  525. bl dcsw_op_level2
  526. /* ---------------------------------------------
  527. * Come out of intra cluster coherency
  528. * ---------------------------------------------
  529. */
  530. bl cortex_a57_disable_smp
  531. /* ---------------------------------------------
  532. * Force the debug interfaces to be quiescent
  533. * ---------------------------------------------
  534. */
  535. pop {r12, lr}
  536. b cortex_a57_disable_ext_debug
  537. endfunc cortex_a57_cluster_pwr_dwn
  538. declare_cpu_ops cortex_a57, CORTEX_A57_MIDR, \
  539. cortex_a57_reset_func, \
  540. cortex_a57_core_pwr_dwn, \
  541. cortex_a57_cluster_pwr_dwn