neoverse_n1.S 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 <cpuamu.h>
  9. #include <cpu_macros.S>
  10. #include <neoverse_n1.h>
  11. #include "wa_cve_2022_23960_bhb_vector.S"
  12. /* Hardware handled coherency */
  13. #if HW_ASSISTED_COHERENCY == 0
  14. #error "Neoverse N1 must be compiled with HW_ASSISTED_COHERENCY enabled"
  15. #endif
  16. /* 64-bit only core */
  17. #if CTX_INCLUDE_AARCH32_REGS == 1
  18. #error "Neoverse-N1 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0"
  19. #endif
  20. .global neoverse_n1_errata_ic_trap_handler
  21. #if WORKAROUND_CVE_2022_23960
  22. wa_cve_2022_23960_bhb_vector_table NEOVERSE_N1_BHB_LOOP_COUNT, neoverse_n1
  23. #endif /* WORKAROUND_CVE_2022_23960 */
  24. /*
  25. * ERRATA_DSU_936184:
  26. * The errata is defined in dsu_helpers.S and applies to Neoverse N1.
  27. * Henceforth creating symbolic names to the already existing errata
  28. * workaround functions to get them registered under the Errata Framework.
  29. */
  30. .equ check_erratum_neoverse_n1_936184, check_errata_dsu_936184
  31. .equ erratum_neoverse_n1_936184_wa, errata_dsu_936184_wa
  32. add_erratum_entry neoverse_n1, ERRATUM(936184), ERRATA_DSU_936184, APPLY_AT_RESET
  33. workaround_reset_start neoverse_n1, ERRATUM(1043202), ERRATA_N1_1043202
  34. /* Apply instruction patching sequence */
  35. ldr x0, =0x0
  36. msr CPUPSELR_EL3, x0
  37. ldr x0, =0xF3BF8F2F
  38. msr CPUPOR_EL3, x0
  39. ldr x0, =0xFFFFFFFF
  40. msr CPUPMR_EL3, x0
  41. ldr x0, =0x800200071
  42. msr CPUPCR_EL3, x0
  43. workaround_reset_end neoverse_n1, ERRATUM(1043202)
  44. check_erratum_ls neoverse_n1, ERRATUM(1043202), CPU_REV(1, 0)
  45. workaround_reset_start neoverse_n1, ERRATUM(1073348), ERRATA_N1_1073348
  46. sysreg_bit_set NEOVERSE_N1_CPUACTLR_EL1, NEOVERSE_N1_CPUACTLR_EL1_BIT_6
  47. workaround_reset_end neoverse_n1, ERRATUM(1073348)
  48. check_erratum_ls neoverse_n1, ERRATUM(1073348), CPU_REV(1, 0)
  49. workaround_reset_start neoverse_n1, ERRATUM(1130799), ERRATA_N1_1130799
  50. sysreg_bit_set NEOVERSE_N1_CPUACTLR2_EL1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_59
  51. workaround_reset_end neoverse_n1, ERRATUM(1130799)
  52. check_erratum_ls neoverse_n1, ERRATUM(1130799), CPU_REV(2, 0)
  53. workaround_reset_start neoverse_n1, ERRATUM(1165347), ERRATA_N1_1165347
  54. sysreg_bit_set NEOVERSE_N1_CPUACTLR2_EL1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_0
  55. sysreg_bit_set NEOVERSE_N1_CPUACTLR2_EL1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_15
  56. workaround_reset_end neoverse_n1, ERRATUM(1165347)
  57. check_erratum_ls neoverse_n1, ERRATUM(1165347), CPU_REV(2, 0)
  58. workaround_reset_start neoverse_n1, ERRATUM(1207823), ERRATA_N1_1207823
  59. sysreg_bit_set NEOVERSE_N1_CPUACTLR2_EL1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_11
  60. workaround_reset_end neoverse_n1, ERRATUM(1207823)
  61. check_erratum_ls neoverse_n1, ERRATUM(1207823), CPU_REV(2, 0)
  62. workaround_reset_start neoverse_n1, ERRATUM(1220197), ERRATA_N1_1220197
  63. sysreg_bit_set NEOVERSE_N1_CPUECTLR_EL1, NEOVERSE_N1_WS_THR_L2_MASK
  64. workaround_reset_end neoverse_n1, ERRATUM(1220197)
  65. check_erratum_ls neoverse_n1, ERRATUM(1220197), CPU_REV(2, 0)
  66. workaround_reset_start neoverse_n1, ERRATUM(1257314), ERRATA_N1_1257314
  67. sysreg_bit_set NEOVERSE_N1_CPUACTLR3_EL1, NEOVERSE_N1_CPUACTLR3_EL1_BIT_10
  68. workaround_reset_end neoverse_n1, ERRATUM(1257314)
  69. check_erratum_ls neoverse_n1, ERRATUM(1257314), CPU_REV(3, 0)
  70. workaround_reset_start neoverse_n1, ERRATUM(1262606), ERRATA_N1_1262606
  71. sysreg_bit_set NEOVERSE_N1_CPUACTLR_EL1, NEOVERSE_N1_CPUACTLR_EL1_BIT_13
  72. workaround_reset_end neoverse_n1, ERRATUM(1262606)
  73. check_erratum_ls neoverse_n1, ERRATUM(1262606), CPU_REV(3, 0)
  74. workaround_reset_start neoverse_n1, ERRATUM(1262888), ERRATA_N1_1262888
  75. sysreg_bit_set NEOVERSE_N1_CPUECTLR_EL1, NEOVERSE_N1_CPUECTLR_EL1_MM_TLBPF_DIS_BIT
  76. workaround_reset_end neoverse_n1, ERRATUM(1262888)
  77. check_erratum_ls neoverse_n1, ERRATUM(1262888), CPU_REV(3, 0)
  78. workaround_reset_start neoverse_n1, ERRATUM(1275112), ERRATA_N1_1275112
  79. sysreg_bit_set NEOVERSE_N1_CPUACTLR_EL1, NEOVERSE_N1_CPUACTLR_EL1_BIT_13
  80. workaround_reset_end neoverse_n1, ERRATUM(1275112)
  81. check_erratum_ls neoverse_n1, ERRATUM(1275112), CPU_REV(3, 0)
  82. workaround_reset_start neoverse_n1, ERRATUM(1315703), ERRATA_N1_1315703
  83. sysreg_bit_set NEOVERSE_N1_CPUACTLR2_EL1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_16
  84. workaround_reset_end neoverse_n1, ERRATUM(1315703)
  85. check_erratum_ls neoverse_n1, ERRATUM(1315703), CPU_REV(3, 0)
  86. workaround_reset_start neoverse_n1, ERRATUM(1542419), ERRATA_N1_1542419
  87. /* Apply instruction patching sequence */
  88. ldr x0, =0x0
  89. msr CPUPSELR_EL3, x0
  90. ldr x0, =0xEE670D35
  91. msr CPUPOR_EL3, x0
  92. ldr x0, =0xFFFF0FFF
  93. msr CPUPMR_EL3, x0
  94. ldr x0, =0x08000020007D
  95. msr CPUPCR_EL3, x0
  96. isb
  97. workaround_reset_end neoverse_n1, ERRATUM(1542419)
  98. check_erratum_range neoverse_n1, ERRATUM(1542419), CPU_REV(3, 0), CPU_REV(4, 0)
  99. workaround_reset_start neoverse_n1, ERRATUM(1868343), ERRATA_N1_1868343
  100. sysreg_bit_set NEOVERSE_N1_CPUACTLR_EL1, NEOVERSE_N1_CPUACTLR_EL1_BIT_13
  101. workaround_reset_end neoverse_n1, ERRATUM(1868343)
  102. check_erratum_ls neoverse_n1, ERRATUM(1868343), CPU_REV(4, 0)
  103. workaround_reset_start neoverse_n1, ERRATUM(1946160), ERRATA_N1_1946160
  104. mov x0, #3
  105. msr S3_6_C15_C8_0, x0
  106. ldr x0, =0x10E3900002
  107. msr S3_6_C15_C8_2, x0
  108. ldr x0, =0x10FFF00083
  109. msr S3_6_C15_C8_3, x0
  110. ldr x0, =0x2001003FF
  111. msr S3_6_C15_C8_1, x0
  112. mov x0, #4
  113. msr S3_6_C15_C8_0, x0
  114. ldr x0, =0x10E3800082
  115. msr S3_6_C15_C8_2, x0
  116. ldr x0, =0x10FFF00083
  117. msr S3_6_C15_C8_3, x0
  118. ldr x0, =0x2001003FF
  119. msr S3_6_C15_C8_1, x0
  120. mov x0, #5
  121. msr S3_6_C15_C8_0, x0
  122. ldr x0, =0x10E3800200
  123. msr S3_6_C15_C8_2, x0
  124. ldr x0, =0x10FFF003E0
  125. msr S3_6_C15_C8_3, x0
  126. ldr x0, =0x2001003FF
  127. msr S3_6_C15_C8_1, x0
  128. isb
  129. workaround_reset_end neoverse_n1, ERRATUM(1946160)
  130. check_erratum_range neoverse_n1, ERRATUM(1946160), CPU_REV(3, 0), CPU_REV(4, 1)
  131. workaround_runtime_start neoverse_n1, ERRATUM(2743102), ERRATA_N1_2743102
  132. /* dsb before isb of power down sequence */
  133. dsb sy
  134. workaround_runtime_end neoverse_n1, ERRATUM(2743102)
  135. check_erratum_ls neoverse_n1, ERRATUM(2743102), CPU_REV(4, 1)
  136. workaround_reset_start neoverse_n1, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
  137. #if IMAGE_BL31
  138. /*
  139. * The Neoverse-N1 generic vectors are overridden to apply errata
  140. * mitigation on exception entry from lower ELs.
  141. */
  142. override_vector_table wa_cve_vbar_neoverse_n1
  143. #endif /* IMAGE_BL31 */
  144. workaround_reset_end neoverse_n1, CVE(2022, 23960)
  145. check_erratum_chosen neoverse_n1, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
  146. /* --------------------------------------------------
  147. * Disable speculative loads if Neoverse N1 supports
  148. * SSBS.
  149. *
  150. * Shall clobber: x0.
  151. * --------------------------------------------------
  152. */
  153. func neoverse_n1_disable_speculative_loads
  154. /* Check if the PE implements SSBS */
  155. mrs x0, id_aa64pfr1_el1
  156. tst x0, #(ID_AA64PFR1_EL1_SSBS_MASK << ID_AA64PFR1_EL1_SSBS_SHIFT)
  157. b.eq 1f
  158. /* Disable speculative loads */
  159. msr SSBS, xzr
  160. 1:
  161. ret
  162. endfunc neoverse_n1_disable_speculative_loads
  163. cpu_reset_func_start neoverse_n1
  164. bl neoverse_n1_disable_speculative_loads
  165. /* Forces all cacheable atomic instructions to be near */
  166. sysreg_bit_set NEOVERSE_N1_CPUACTLR2_EL1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_2
  167. isb
  168. #if ENABLE_FEAT_AMU
  169. /* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */
  170. sysreg_bit_set actlr_el3, NEOVERSE_N1_ACTLR_AMEN_BIT
  171. /* Make sure accesses from EL0/EL1 are not trapped to EL2 */
  172. sysreg_bit_set actlr_el2, NEOVERSE_N1_ACTLR_AMEN_BIT
  173. /* Enable group0 counters */
  174. mov x0, #NEOVERSE_N1_AMU_GROUP0_MASK
  175. msr CPUAMCNTENSET_EL0, x0
  176. #endif
  177. #if NEOVERSE_Nx_EXTERNAL_LLC
  178. /* Some system may have External LLC, core needs to be made aware */
  179. sysreg_bit_set NEOVERSE_N1_CPUECTLR_EL1, NEOVERSE_N1_CPUECTLR_EL1_EXTLLC_BIT
  180. #endif
  181. cpu_reset_func_end neoverse_n1
  182. /* ---------------------------------------------
  183. * HW will do the cache maintenance while powering down
  184. * ---------------------------------------------
  185. */
  186. func neoverse_n1_core_pwr_dwn
  187. /* ---------------------------------------------
  188. * Enable CPU power down bit in power control register
  189. * ---------------------------------------------
  190. */
  191. sysreg_bit_set NEOVERSE_N1_CPUPWRCTLR_EL1, NEOVERSE_N1_CORE_PWRDN_EN_MASK
  192. apply_erratum neoverse_n1, ERRATUM(2743102), ERRATA_N1_2743102, NO_GET_CPU_REV
  193. isb
  194. ret
  195. endfunc neoverse_n1_core_pwr_dwn
  196. /*
  197. * Handle trap of EL0 IC IVAU instructions to EL3 by executing a TLB
  198. * inner-shareable invalidation to an arbitrary address followed by a DSB.
  199. *
  200. * x1: Exception Syndrome
  201. */
  202. func neoverse_n1_errata_ic_trap_handler
  203. cmp x1, #NEOVERSE_N1_EC_IC_TRAP
  204. b.ne 1f
  205. tlbi vae3is, xzr
  206. dsb sy
  207. # Skip the IC instruction itself
  208. mrs x3, elr_el3
  209. add x3, x3, #4
  210. msr elr_el3, x3
  211. ldp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0]
  212. ldp x2, x3, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2]
  213. ldp x4, x5, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X4]
  214. ldr x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR]
  215. /*
  216. * Issue Error Synchronization Barrier to synchronize SErrors before
  217. * exiting EL3. We're running with EAs unmasked, so any synchronized
  218. * errors would be taken immediately; therefore no need to inspect
  219. * DISR_EL1 register.
  220. */
  221. esb
  222. exception_return
  223. 1:
  224. ret
  225. endfunc neoverse_n1_errata_ic_trap_handler
  226. /* ---------------------------------------------
  227. * This function provides neoverse_n1 specific
  228. * register information for crash reporting.
  229. * It needs to return with x6 pointing to
  230. * a list of register names in ascii and
  231. * x8 - x15 having values of registers to be
  232. * reported.
  233. * ---------------------------------------------
  234. */
  235. .section .rodata.neoverse_n1_regs, "aS"
  236. neoverse_n1_regs: /* The ascii list of register names to be reported */
  237. .asciz "cpuectlr_el1", ""
  238. func neoverse_n1_cpu_reg_dump
  239. adr x6, neoverse_n1_regs
  240. mrs x8, NEOVERSE_N1_CPUECTLR_EL1
  241. ret
  242. endfunc neoverse_n1_cpu_reg_dump
  243. declare_cpu_ops_eh neoverse_n1, NEOVERSE_N1_MIDR, \
  244. neoverse_n1_reset_func, \
  245. neoverse_n1_errata_ic_trap_handler, \
  246. neoverse_n1_core_pwr_dwn