cortex_x2.S 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright (c) 2021-2024, 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_x2.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 X2 must be compiled with HW_ASSISTED_COHERENCY enabled"
  16. #endif
  17. /* 64-bit only core */
  18. #if CTX_INCLUDE_AARCH32_REGS == 1
  19. #error "Cortex X2 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0"
  20. #endif
  21. #if WORKAROUND_CVE_2022_23960
  22. wa_cve_2022_23960_bhb_vector_table CORTEX_X2_BHB_LOOP_COUNT, cortex_x2
  23. #endif /* WORKAROUND_CVE_2022_23960 */
  24. /* Disable hardware page aggregation. Enables mitigation for `CVE-2024-5660` */
  25. workaround_reset_start cortex_x2, CVE(2024, 5660), WORKAROUND_CVE_2024_5660
  26. sysreg_bit_set CORTEX_X2_CPUECTLR_EL1, BIT(46)
  27. workaround_reset_end cortex_x2, CVE(2024, 5660)
  28. check_erratum_ls cortex_x2, CVE(2024, 5660), CPU_REV(2, 1)
  29. workaround_reset_start cortex_x2, ERRATUM(2002765), ERRATA_X2_2002765
  30. ldr x0, =0x6
  31. msr S3_6_C15_C8_0, x0 /* CPUPSELR_EL3 */
  32. ldr x0, =0xF3A08002
  33. msr S3_6_C15_C8_2, x0 /* CPUPOR_EL3 */
  34. ldr x0, =0xFFF0F7FE
  35. msr S3_6_C15_C8_3, x0 /* CPUPMR_EL3 */
  36. ldr x0, =0x40000001003ff
  37. msr S3_6_C15_C8_1, x0 /* CPUPCR_EL3 */
  38. workaround_reset_end cortex_x2, ERRATUM(2002765)
  39. check_erratum_ls cortex_x2, ERRATUM(2002765), CPU_REV(2, 0)
  40. workaround_reset_start cortex_x2, ERRATUM(2017096), ERRATA_X2_2017096
  41. sysreg_bit_set CORTEX_X2_CPUECTLR_EL1, CORTEX_X2_CPUECTLR_EL1_PFSTIDIS_BIT
  42. workaround_reset_end cortex_x2, ERRATUM(2017096)
  43. check_erratum_ls cortex_x2, ERRATUM(2017096), CPU_REV(2, 0)
  44. workaround_reset_start cortex_x2, ERRATUM(2058056), ERRATA_X2_2058056
  45. sysreg_bitfield_insert CORTEX_X2_CPUECTLR2_EL1, CORTEX_X2_CPUECTLR2_EL1_PF_MODE_CNSRV, \
  46. CORTEX_X2_CPUECTLR2_EL1_PF_MODE_SHIFT, CORTEX_X2_CPUECTLR2_EL1_PF_MODE_WIDTH
  47. workaround_reset_end cortex_x2, ERRATUM(2058056)
  48. check_erratum_ls cortex_x2, ERRATUM(2058056), CPU_REV(2, 1)
  49. workaround_reset_start cortex_x2, ERRATUM(2081180), ERRATA_X2_2081180
  50. /* Apply instruction patching sequence */
  51. ldr x0, =0x3
  52. msr CORTEX_X2_IMP_CPUPSELR_EL3, x0
  53. ldr x0, =0xF3A08002
  54. msr CORTEX_X2_IMP_CPUPOR_EL3, x0
  55. ldr x0, =0xFFF0F7FE
  56. msr CORTEX_X2_IMP_CPUPMR_EL3, x0
  57. ldr x0, =0x10002001003FF
  58. msr CORTEX_X2_IMP_CPUPCR_EL3, x0
  59. ldr x0, =0x4
  60. msr CORTEX_X2_IMP_CPUPSELR_EL3, x0
  61. ldr x0, =0xBF200000
  62. msr CORTEX_X2_IMP_CPUPOR_EL3, x0
  63. ldr x0, =0xFFEF0000
  64. msr CORTEX_X2_IMP_CPUPMR_EL3, x0
  65. ldr x0, =0x10002001003F3
  66. msr CORTEX_X2_IMP_CPUPCR_EL3, x0
  67. workaround_reset_end cortex_x2, ERRATUM(2081180)
  68. check_erratum_ls cortex_x2, ERRATUM(2081180), CPU_REV(2, 0)
  69. workaround_reset_start cortex_x2, ERRATUM(2083908), ERRATA_X2_2083908
  70. /* Apply the workaround by setting bit 13 in CPUACTLR5_EL1. */
  71. sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, BIT(13)
  72. workaround_reset_end cortex_x2, ERRATUM(2083908)
  73. check_erratum_range cortex_x2, ERRATUM(2083908), CPU_REV(2, 0), CPU_REV(2, 0)
  74. workaround_reset_start cortex_x2, ERRATUM(2147715), ERRATA_X2_2147715
  75. /* Apply the workaround by setting bit 22 in CPUACTLR_EL1. */
  76. sysreg_bit_set CORTEX_X2_CPUACTLR_EL1, CORTEX_X2_CPUACTLR_EL1_BIT_22
  77. workaround_reset_end cortex_x2, ERRATUM(2147715)
  78. check_erratum_range cortex_x2, ERRATUM(2147715), CPU_REV(2, 0), CPU_REV(2, 0)
  79. workaround_reset_start cortex_x2, ERRATUM(2216384), ERRATA_X2_2216384
  80. sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, CORTEX_X2_CPUACTLR5_EL1_BIT_17
  81. /* Apply instruction patching sequence */
  82. ldr x0, =0x5
  83. msr CORTEX_X2_IMP_CPUPSELR_EL3, x0
  84. ldr x0, =0x10F600E000
  85. msr CORTEX_X2_IMP_CPUPOR_EL3, x0
  86. ldr x0, =0x10FF80E000
  87. msr CORTEX_X2_IMP_CPUPMR_EL3, x0
  88. ldr x0, =0x80000000003FF
  89. msr CORTEX_X2_IMP_CPUPCR_EL3, x0
  90. workaround_reset_end cortex_x2, ERRATUM(2216384)
  91. check_erratum_ls cortex_x2, ERRATUM(2216384), CPU_REV(2, 0)
  92. workaround_reset_start cortex_x2, ERRATUM(2282622), ERRATA_X2_2282622
  93. /* Apply the workaround */
  94. sysreg_bit_set CORTEX_X2_CPUACTLR2_EL1, BIT(0)
  95. workaround_reset_end cortex_x2, ERRATUM(2282622)
  96. check_erratum_ls cortex_x2, ERRATUM(2282622), CPU_REV(2, 1)
  97. workaround_reset_start cortex_x2, ERRATUM(2371105), ERRATA_X2_2371105
  98. /* Set bit 40 in CPUACTLR2_EL1 */
  99. sysreg_bit_set CORTEX_X2_CPUACTLR2_EL1, CORTEX_X2_CPUACTLR2_EL1_BIT_40
  100. workaround_reset_end cortex_x2, ERRATUM(2371105)
  101. check_erratum_ls cortex_x2, ERRATUM(2371105), CPU_REV(2, 0)
  102. workaround_reset_start cortex_x2, ERRATUM(2742423), ERRATA_X2_2742423
  103. /* Set CPUACTLR5_EL1[56:55] to 2'b01 */
  104. sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, BIT(55)
  105. sysreg_bit_clear CORTEX_X2_CPUACTLR5_EL1, BIT(56)
  106. workaround_reset_end cortex_x2, ERRATUM(2742423)
  107. check_erratum_ls cortex_x2, ERRATUM(2742423), CPU_REV(2, 1)
  108. workaround_runtime_start cortex_x2, ERRATUM(2768515), ERRATA_X2_2768515
  109. /* dsb before isb of power down sequence */
  110. dsb sy
  111. workaround_runtime_end cortex_x2, ERRATUM(2768515)
  112. check_erratum_ls cortex_x2, ERRATUM(2768515), CPU_REV(2, 1)
  113. workaround_reset_start cortex_x2, ERRATUM(2778471), ERRATA_X2_2778471
  114. sysreg_bit_set CORTEX_X2_CPUACTLR3_EL1, BIT(47)
  115. workaround_reset_end cortex_x2, ERRATUM(2778471)
  116. check_erratum_ls cortex_x2, ERRATUM(2778471), CPU_REV(2, 1)
  117. workaround_reset_start cortex_x2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
  118. #if IMAGE_BL31
  119. /*
  120. * The Cortex-X2 generic vectors are overridden to apply errata
  121. * mitigation on exception entry from lower ELs.
  122. */
  123. override_vector_table wa_cve_vbar_cortex_x2
  124. #endif /* IMAGE_BL31 */
  125. workaround_reset_end cortex_x2, CVE(2022, 23960)
  126. check_erratum_chosen cortex_x2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
  127. /*
  128. * ERRATA_DSU_2313941 :
  129. * The errata is defined in dsu_helpers.S but applies to cortex_x2
  130. * as well. Henceforth creating symbolic names to the already existing errata
  131. * workaround functions to get them registered under the Errata Framework.
  132. */
  133. .equ check_erratum_cortex_x2_2313941, check_errata_dsu_2313941
  134. .equ erratum_cortex_x2_2313941_wa, errata_dsu_2313941_wa
  135. add_erratum_entry cortex_x2, ERRATUM(2313941), ERRATA_DSU_2313941, APPLY_AT_RESET
  136. /* ----------------------------------------------------
  137. * HW will do the cache maintenance while powering down
  138. * ----------------------------------------------------
  139. */
  140. func cortex_x2_core_pwr_dwn
  141. /* ---------------------------------------------------
  142. * Enable CPU power down bit in power control register
  143. * ---------------------------------------------------
  144. */
  145. sysreg_bit_set CORTEX_X2_CPUPWRCTLR_EL1, CORTEX_X2_CPUPWRCTLR_EL1_CORE_PWRDN_BIT
  146. apply_erratum cortex_x2, ERRATUM(2768515), ERRATA_X2_2768515, NO_GET_CPU_REV
  147. isb
  148. ret
  149. endfunc cortex_x2_core_pwr_dwn
  150. cpu_reset_func_start cortex_x2
  151. /* Disable speculative loads */
  152. msr SSBS, xzr
  153. cpu_reset_func_end cortex_x2
  154. /* ---------------------------------------------
  155. * This function provides Cortex X2 specific
  156. * register information for crash reporting.
  157. * It needs to return with x6 pointing to
  158. * a list of register names in ascii and
  159. * x8 - x15 having values of registers to be
  160. * reported.
  161. * ---------------------------------------------
  162. */
  163. .section .rodata.cortex_x2_regs, "aS"
  164. cortex_x2_regs: /* The ascii list of register names to be reported */
  165. .asciz "cpuectlr_el1", ""
  166. func cortex_x2_cpu_reg_dump
  167. adr x6, cortex_x2_regs
  168. mrs x8, CORTEX_X2_CPUECTLR_EL1
  169. ret
  170. endfunc cortex_x2_cpu_reg_dump
  171. declare_cpu_ops cortex_x2, CORTEX_X2_MIDR, \
  172. cortex_x2_reset_func, \
  173. cortex_x2_core_pwr_dwn