cortex_a57.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * Copyright (c) 2014-2024, Arm Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <arch.h>
  8. #include <asm_macros.S>
  9. #include <assert_macros.S>
  10. #include <common/bl_common.h>
  11. #include <common/debug.h>
  12. #include <cortex_a57.h>
  13. #include <cpu_macros.S>
  14. #include <plat_macros.S>
  15. /* ---------------------------------------------
  16. * Disable L1 data cache and unified L2 cache
  17. * ---------------------------------------------
  18. */
  19. func cortex_a57_disable_dcache
  20. sysreg_bit_clear sctlr_el3, SCTLR_C_BIT
  21. isb
  22. ret
  23. endfunc cortex_a57_disable_dcache
  24. /* ---------------------------------------------
  25. * Disable all types of L2 prefetches.
  26. * ---------------------------------------------
  27. */
  28. func cortex_a57_disable_l2_prefetch
  29. mrs x0, CORTEX_A57_ECTLR_EL1
  30. orr x0, x0, #CORTEX_A57_ECTLR_DIS_TWD_ACC_PFTCH_BIT
  31. mov x1, #CORTEX_A57_ECTLR_L2_IPFTCH_DIST_MASK
  32. orr x1, x1, #CORTEX_A57_ECTLR_L2_DPFTCH_DIST_MASK
  33. bic x0, x0, x1
  34. msr CORTEX_A57_ECTLR_EL1, x0
  35. isb
  36. dsb ish
  37. ret
  38. endfunc cortex_a57_disable_l2_prefetch
  39. /* ---------------------------------------------
  40. * Disable intra-cluster coherency
  41. * ---------------------------------------------
  42. */
  43. func cortex_a57_disable_smp
  44. sysreg_bit_clear CORTEX_A57_ECTLR_EL1, CORTEX_A57_ECTLR_SMP_BIT
  45. ret
  46. endfunc cortex_a57_disable_smp
  47. /* ---------------------------------------------
  48. * Disable debug interfaces
  49. * ---------------------------------------------
  50. */
  51. func cortex_a57_disable_ext_debug
  52. mov x0, #1
  53. msr osdlr_el1, x0
  54. isb
  55. apply_erratum cortex_a57, ERRATUM(817169), ERRATA_A57_817169, NO_GET_CPU_REV
  56. dsb sy
  57. ret
  58. endfunc cortex_a57_disable_ext_debug
  59. /*
  60. * Disable the over-read from the LDNP/STNP instruction. The SDEN doesn't
  61. * provide and erratum number, so assign it an obvious 1
  62. */
  63. workaround_reset_start cortex_a57, ERRATUM(1), A57_DISABLE_NON_TEMPORAL_HINT
  64. sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DIS_OVERREAD
  65. workaround_reset_end cortex_a57, ERRATUM(1)
  66. check_erratum_ls cortex_a57, ERRATUM(1), CPU_REV(1, 2)
  67. workaround_reset_start cortex_a57, ERRATUM(806969), ERRATA_A57_806969
  68. sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_NO_ALLOC_WBWA
  69. workaround_reset_end cortex_a57, ERRATUM(806969)
  70. check_erratum_ls cortex_a57, ERRATUM(806969), CPU_REV(0, 0)
  71. /* erratum always worked around, but report it correctly */
  72. check_erratum_ls cortex_a57, ERRATUM(813419), CPU_REV(0, 0)
  73. add_erratum_entry cortex_a57, ERRATUM(813419), ERRATUM_ALWAYS_CHOSEN, NO_APPLY_AT_RESET
  74. workaround_reset_start cortex_a57, ERRATUM(813420), ERRATA_A57_813420
  75. sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DCC_AS_DCCI
  76. workaround_reset_end cortex_a57, ERRATUM(813420)
  77. check_erratum_ls cortex_a57, ERRATUM(813420), CPU_REV(0, 0)
  78. workaround_reset_start cortex_a57, ERRATUM(814670), ERRATA_A57_814670
  79. sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DIS_DMB_NULLIFICATION
  80. workaround_reset_end cortex_a57, ERRATUM(814670)
  81. check_erratum_ls cortex_a57, ERRATUM(814670), CPU_REV(0, 0)
  82. workaround_runtime_start cortex_a57, ERRATUM(817169), ERRATA_A57_817169, CORTEX_A57_MIDR
  83. /* Invalidate any TLB address */
  84. mov x0, #0
  85. tlbi vae3, x0
  86. workaround_runtime_end cortex_a57, ERRATUM(817169), NO_ISB
  87. check_erratum_ls cortex_a57, ERRATUM(817169), CPU_REV(0, 1)
  88. workaround_reset_start cortex_a57, ERRATUM(826974), ERRATA_A57_826974
  89. sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DIS_LOAD_PASS_DMB
  90. workaround_reset_end cortex_a57, ERRATUM(826974)
  91. check_erratum_ls cortex_a57, ERRATUM(826974), CPU_REV(1, 1)
  92. workaround_reset_start cortex_a57, ERRATUM(826977), ERRATA_A57_826977
  93. sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_GRE_NGRE_AS_NGNRE
  94. workaround_reset_end cortex_a57, ERRATUM(826977)
  95. check_erratum_ls cortex_a57, ERRATUM(826977), CPU_REV(1, 1)
  96. workaround_reset_start cortex_a57, ERRATUM(828024), ERRATA_A57_828024
  97. mrs x1, CORTEX_A57_CPUACTLR_EL1
  98. /*
  99. * Setting the relevant bits in CPUACTLR_EL1 has to be done in 2
  100. * instructions here because the resulting bitmask doesn't fit in a
  101. * 16-bit value so it cannot be encoded in a single instruction.
  102. */
  103. orr x1, x1, #CORTEX_A57_CPUACTLR_EL1_NO_ALLOC_WBWA
  104. orr x1, x1, #(CORTEX_A57_CPUACTLR_EL1_DIS_L1_STREAMING | \
  105. CORTEX_A57_CPUACTLR_EL1_DIS_STREAMING)
  106. msr CORTEX_A57_CPUACTLR_EL1, x1
  107. workaround_reset_end cortex_a57, ERRATUM(828024)
  108. check_erratum_ls cortex_a57, ERRATUM(828024), CPU_REV(1, 1)
  109. workaround_reset_start cortex_a57, ERRATUM(829520), ERRATA_A57_829520
  110. sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DIS_INDIRECT_PREDICTOR
  111. workaround_reset_end cortex_a57, ERRATUM(829520)
  112. check_erratum_ls cortex_a57, ERRATUM(829520), CPU_REV(1, 2)
  113. workaround_reset_start cortex_a57, ERRATUM(833471), ERRATA_A57_833471
  114. sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_FORCE_FPSCR_FLUSH
  115. workaround_reset_end cortex_a57, ERRATUM(833471)
  116. check_erratum_ls cortex_a57, ERRATUM(833471), CPU_REV(1, 2)
  117. workaround_reset_start cortex_a57, ERRATUM(859972), ERRATA_A57_859972
  118. sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DIS_INSTR_PREFETCH
  119. workaround_reset_end cortex_a57, ERRATUM(859972)
  120. check_erratum_ls cortex_a57, ERRATUM(859972), CPU_REV(1, 3)
  121. check_erratum_chosen cortex_a57, ERRATUM(1319537), ERRATA_A57_1319537
  122. /* erratum has no workaround in the cpu. Generic code must take care */
  123. add_erratum_entry cortex_a57, ERRATUM(1319537), ERRATA_A57_1319537, NO_APPLY_AT_RESET
  124. workaround_reset_start cortex_a57, CVE(2017, 5715), WORKAROUND_CVE_2017_5715
  125. #if IMAGE_BL31
  126. override_vector_table wa_cve_2017_5715_mmu_vbar
  127. #endif
  128. workaround_reset_end cortex_a57, CVE(2017, 5715)
  129. check_erratum_chosen cortex_a57, CVE(2017, 5715), WORKAROUND_CVE_2017_5715
  130. workaround_reset_start cortex_a57, CVE(2018, 3639), WORKAROUND_CVE_2018_3639
  131. sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DIS_LOAD_PASS_STORE
  132. isb
  133. dsb sy
  134. workaround_reset_end cortex_a57, CVE(2018, 3639)
  135. check_erratum_chosen cortex_a57, CVE(2018, 3639), WORKAROUND_CVE_2018_3639
  136. workaround_reset_start cortex_a57, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
  137. #if IMAGE_BL31
  138. override_vector_table wa_cve_2017_5715_mmu_vbar
  139. #endif
  140. workaround_reset_end cortex_a57, CVE(2022, 23960)
  141. check_erratum_chosen cortex_a57, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
  142. cpu_reset_func_start cortex_a57
  143. #if A57_ENABLE_NONCACHEABLE_LOAD_FWD
  144. /* Enable higher performance non-cacheable load forwarding */
  145. sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_EN_NC_LOAD_FWD
  146. #endif
  147. /* Enable the SMP bit. */
  148. sysreg_bit_set CORTEX_A57_ECTLR_EL1, CORTEX_A57_ECTLR_SMP_BIT
  149. cpu_reset_func_end cortex_a57
  150. func check_smccc_arch_workaround_3
  151. mov x0, #ERRATA_APPLIES
  152. ret
  153. endfunc check_smccc_arch_workaround_3
  154. /* ----------------------------------------------------
  155. * The CPU Ops core power down function for Cortex-A57.
  156. * ----------------------------------------------------
  157. */
  158. func cortex_a57_core_pwr_dwn
  159. mov x18, x30
  160. /* ---------------------------------------------
  161. * Turn off caches.
  162. * ---------------------------------------------
  163. */
  164. bl cortex_a57_disable_dcache
  165. /* ---------------------------------------------
  166. * Disable the L2 prefetches.
  167. * ---------------------------------------------
  168. */
  169. bl cortex_a57_disable_l2_prefetch
  170. /* ---------------------------------------------
  171. * Flush L1 caches.
  172. * ---------------------------------------------
  173. */
  174. mov x0, #DCCISW
  175. bl dcsw_op_level1
  176. /* ---------------------------------------------
  177. * Come out of intra cluster coherency
  178. * ---------------------------------------------
  179. */
  180. bl cortex_a57_disable_smp
  181. /* ---------------------------------------------
  182. * Force the debug interfaces to be quiescent
  183. * ---------------------------------------------
  184. */
  185. mov x30, x18
  186. b cortex_a57_disable_ext_debug
  187. endfunc cortex_a57_core_pwr_dwn
  188. /* -------------------------------------------------------
  189. * The CPU Ops cluster power down function for Cortex-A57.
  190. * -------------------------------------------------------
  191. */
  192. func cortex_a57_cluster_pwr_dwn
  193. mov x18, x30
  194. /* ---------------------------------------------
  195. * Turn off caches.
  196. * ---------------------------------------------
  197. */
  198. bl cortex_a57_disable_dcache
  199. /* ---------------------------------------------
  200. * Disable the L2 prefetches.
  201. * ---------------------------------------------
  202. */
  203. bl cortex_a57_disable_l2_prefetch
  204. #if !SKIP_A57_L1_FLUSH_PWR_DWN
  205. /* -------------------------------------------------
  206. * Flush the L1 caches.
  207. * -------------------------------------------------
  208. */
  209. mov x0, #DCCISW
  210. bl dcsw_op_level1
  211. #endif
  212. /* ---------------------------------------------
  213. * Disable the optional ACP.
  214. * ---------------------------------------------
  215. */
  216. bl plat_disable_acp
  217. /* -------------------------------------------------
  218. * Flush the L2 caches.
  219. * -------------------------------------------------
  220. */
  221. mov x0, #DCCISW
  222. bl dcsw_op_level2
  223. /* ---------------------------------------------
  224. * Come out of intra cluster coherency
  225. * ---------------------------------------------
  226. */
  227. bl cortex_a57_disable_smp
  228. /* ---------------------------------------------
  229. * Force the debug interfaces to be quiescent
  230. * ---------------------------------------------
  231. */
  232. mov x30, x18
  233. b cortex_a57_disable_ext_debug
  234. endfunc cortex_a57_cluster_pwr_dwn
  235. /* ---------------------------------------------
  236. * This function provides cortex_a57 specific
  237. * register information for crash reporting.
  238. * It needs to return with x6 pointing to
  239. * a list of register names in ascii and
  240. * x8 - x15 having values of registers to be
  241. * reported.
  242. * ---------------------------------------------
  243. */
  244. .section .rodata.cortex_a57_regs, "aS"
  245. cortex_a57_regs: /* The ascii list of register names to be reported */
  246. .asciz "cpuectlr_el1", "cpumerrsr_el1", "l2merrsr_el1", ""
  247. func cortex_a57_cpu_reg_dump
  248. adr x6, cortex_a57_regs
  249. mrs x8, CORTEX_A57_ECTLR_EL1
  250. mrs x9, CORTEX_A57_MERRSR_EL1
  251. mrs x10, CORTEX_A57_L2MERRSR_EL1
  252. ret
  253. endfunc cortex_a57_cpu_reg_dump
  254. declare_cpu_ops_wa cortex_a57, CORTEX_A57_MIDR, \
  255. cortex_a57_reset_func, \
  256. check_erratum_cortex_a57_5715, \
  257. CPU_NO_EXTRA2_FUNC, \
  258. check_smccc_arch_workaround_3, \
  259. cortex_a57_core_pwr_dwn, \
  260. cortex_a57_cluster_pwr_dwn