Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 1 | /* |
Jayanth Dodderi Chidanand | cc02b96 | 2023-04-12 18:05:58 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved. |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 5 | */ |
| 6 | #include <arch.h> |
| 7 | #include <asm_macros.S> |
| 8 | #include <assert_macros.S> |
| 9 | #include <cortex_a72.h> |
| 10 | #include <cpu_macros.S> |
| 11 | #include <plat_macros.S> |
Bipin Ravi | cf4d50a | 2022-02-15 23:24:51 -0600 | [diff] [blame] | 12 | #include "wa_cve_2022_23960_bhb_vector.S" |
| 13 | |
| 14 | #if WORKAROUND_CVE_2022_23960 |
| 15 | wa_cve_2022_23960_bhb_vector_table CORTEX_A72_BHB_LOOP_COUNT, cortex_a72 |
| 16 | #endif /* WORKAROUND_CVE_2022_23960 */ |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 17 | |
| 18 | /* --------------------------------------------- |
| 19 | * Disable L1 data cache and unified L2 cache |
| 20 | * --------------------------------------------- |
| 21 | */ |
| 22 | func cortex_a72_disable_dcache |
| 23 | mrs x1, sctlr_el3 |
| 24 | bic x1, x1, #SCTLR_C_BIT |
| 25 | msr sctlr_el3, x1 |
| 26 | isb |
| 27 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 28 | endfunc cortex_a72_disable_dcache |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 29 | |
| 30 | /* --------------------------------------------- |
| 31 | * Disable all types of L2 prefetches. |
| 32 | * --------------------------------------------- |
| 33 | */ |
| 34 | func cortex_a72_disable_l2_prefetch |
Varun Wadekar | 1384a16 | 2017-06-05 14:54:46 -0700 | [diff] [blame] | 35 | mrs x0, CORTEX_A72_ECTLR_EL1 |
| 36 | orr x0, x0, #CORTEX_A72_ECTLR_DIS_TWD_ACC_PFTCH_BIT |
| 37 | mov x1, #CORTEX_A72_ECTLR_L2_IPFTCH_DIST_MASK |
| 38 | orr x1, x1, #CORTEX_A72_ECTLR_L2_DPFTCH_DIST_MASK |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 39 | bic x0, x0, x1 |
Varun Wadekar | 1384a16 | 2017-06-05 14:54:46 -0700 | [diff] [blame] | 40 | msr CORTEX_A72_ECTLR_EL1, x0 |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 41 | isb |
| 42 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 43 | endfunc cortex_a72_disable_l2_prefetch |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 44 | |
| 45 | /* --------------------------------------------- |
| 46 | * Disable the load-store hardware prefetcher. |
| 47 | * --------------------------------------------- |
| 48 | */ |
| 49 | func cortex_a72_disable_hw_prefetcher |
Jayanth Dodderi Chidanand | 30da8af | 2023-06-23 08:27:09 +0100 | [diff] [blame] | 50 | sysreg_bit_set CORTEX_A72_CPUACTLR_EL1, CORTEX_A72_CPUACTLR_EL1_DISABLE_L1_DCACHE_HW_PFTCH |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 51 | isb |
| 52 | dsb ish |
| 53 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 54 | endfunc cortex_a72_disable_hw_prefetcher |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 55 | |
| 56 | /* --------------------------------------------- |
| 57 | * Disable intra-cluster coherency |
| 58 | * --------------------------------------------- |
| 59 | */ |
| 60 | func cortex_a72_disable_smp |
Jayanth Dodderi Chidanand | 30da8af | 2023-06-23 08:27:09 +0100 | [diff] [blame] | 61 | sysreg_bit_clear CORTEX_A72_ECTLR_EL1, CORTEX_A72_ECTLR_SMP_BIT |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 62 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 63 | endfunc cortex_a72_disable_smp |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 64 | |
| 65 | /* --------------------------------------------- |
| 66 | * Disable debug interfaces |
| 67 | * --------------------------------------------- |
| 68 | */ |
| 69 | func cortex_a72_disable_ext_debug |
| 70 | mov x0, #1 |
| 71 | msr osdlr_el1, x0 |
| 72 | isb |
| 73 | dsb sy |
| 74 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 75 | endfunc cortex_a72_disable_ext_debug |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 76 | |
Jayanth Dodderi Chidanand | cc02b96 | 2023-04-12 18:05:58 +0100 | [diff] [blame] | 77 | func check_smccc_arch_workaround_3 |
| 78 | cpu_check_csv2 x0, 1f |
| 79 | mov x0, #ERRATA_APPLIES |
| 80 | ret |
| 81 | 1: |
| 82 | mov x0, #ERRATA_NOT_APPLIES |
| 83 | ret |
| 84 | endfunc check_smccc_arch_workaround_3 |
| 85 | |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 86 | workaround_reset_start cortex_a72, ERRATUM(859971), ERRATA_A72_859971 |
Jayanth Dodderi Chidanand | 30da8af | 2023-06-23 08:27:09 +0100 | [diff] [blame] | 87 | sysreg_bit_set CORTEX_A72_CPUACTLR_EL1, CORTEX_A72_CPUACTLR_EL1_DIS_INSTR_PREFETCH |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 88 | workaround_reset_end cortex_a72, ERRATUM(859971) |
Eleanor Bonnici | c3b4ca1 | 2017-08-02 18:33:41 +0100 | [diff] [blame] | 89 | |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 90 | check_erratum_ls cortex_a72, ERRATUM(859971), CPU_REV(0, 3) |
Eleanor Bonnici | c3b4ca1 | 2017-08-02 18:33:41 +0100 | [diff] [blame] | 91 | |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 92 | /* Due to the nature of the errata it is applied unconditionally when chosen */ |
| 93 | check_erratum_chosen cortex_a72, ERRATUM(1319367), ERRATA_A72_1319367 |
| 94 | /* erratum workaround is interleaved with generic code */ |
| 95 | add_erratum_entry cortex_a72, ERRATUM(1319367), ERRATA_A72_1319367, NO_APPLY_AT_RESET |
| 96 | |
| 97 | workaround_reset_start cortex_a72, CVE(2017, 5715), WORKAROUND_CVE_2017_5715 |
| 98 | #if IMAGE_BL31 |
Jayanth Dodderi Chidanand | 30da8af | 2023-06-23 08:27:09 +0100 | [diff] [blame] | 99 | override_vector_table wa_cve_2017_5715_mmu_vbar |
Jayanth Dodderi Chidanand | cc02b96 | 2023-04-12 18:05:58 +0100 | [diff] [blame] | 100 | #endif |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 101 | workaround_reset_end cortex_a72, CVE(2017, 5715) |
Jayanth Dodderi Chidanand | cc02b96 | 2023-04-12 18:05:58 +0100 | [diff] [blame] | 102 | |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 103 | check_erratum_custom_start cortex_a72, CVE(2017, 5715) |
Dimitris Papastamos | 780cc95 | 2018-03-12 13:27:02 +0000 | [diff] [blame] | 104 | cpu_check_csv2 x0, 1f |
Dimitris Papastamos | 858bd61 | 2018-01-16 10:32:47 +0000 | [diff] [blame] | 105 | #if WORKAROUND_CVE_2017_5715 |
| 106 | mov x0, #ERRATA_APPLIES |
| 107 | #else |
| 108 | mov x0, #ERRATA_MISSING |
| 109 | #endif |
| 110 | ret |
Dimitris Papastamos | 780cc95 | 2018-03-12 13:27:02 +0000 | [diff] [blame] | 111 | 1: |
| 112 | mov x0, #ERRATA_NOT_APPLIES |
| 113 | ret |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 114 | check_erratum_custom_end cortex_a72, CVE(2017, 5715) |
Dimitris Papastamos | e6625ec | 2018-04-05 14:38:26 +0100 | [diff] [blame] | 115 | |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 116 | workaround_reset_start cortex_a72, CVE(2018, 3639), WORKAROUND_CVE_2018_3639 |
Jayanth Dodderi Chidanand | 30da8af | 2023-06-23 08:27:09 +0100 | [diff] [blame] | 117 | sysreg_bit_set CORTEX_A72_CPUACTLR_EL1, CORTEX_A72_CPUACTLR_EL1_DIS_LOAD_PASS_STORE |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 118 | isb |
| 119 | dsb sy |
| 120 | workaround_reset_end cortex_a72, CVE(2018, 3639) |
| 121 | check_erratum_chosen cortex_a72, CVE(2018, 3639), WORKAROUND_CVE_2018_3639 |
Bipin Ravi | cf4d50a | 2022-02-15 23:24:51 -0600 | [diff] [blame] | 122 | |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 123 | workaround_reset_start cortex_a72, CVE(2022, 23960), WORKAROUND_CVE_2022_23960 |
| 124 | #if IMAGE_BL31 |
| 125 | /* Skip installing vector table again if already done for CVE(2017, 5715) */ |
Bipin Ravi | cf4d50a | 2022-02-15 23:24:51 -0600 | [diff] [blame] | 126 | /* |
| 127 | * The Cortex-A72 generic vectors are overridden to apply the |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 128 | * mitigation on exception entry from lower ELs for revisions >= r1p0 |
Bipin Ravi | cf4d50a | 2022-02-15 23:24:51 -0600 | [diff] [blame] | 129 | * which has CSV2 implemented. |
| 130 | */ |
| 131 | adr x0, wa_cve_vbar_cortex_a72 |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 132 | mrs x1, vbar_el3 |
| 133 | cmp x0, x1 |
| 134 | b.eq 1f |
Bipin Ravi | cf4d50a | 2022-02-15 23:24:51 -0600 | [diff] [blame] | 135 | msr vbar_el3, x0 |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 136 | 1: |
| 137 | #endif /* IMAGE_BL31 */ |
| 138 | workaround_reset_end cortex_a72, CVE(2022, 23960) |
Bipin Ravi | cf4d50a | 2022-02-15 23:24:51 -0600 | [diff] [blame] | 139 | |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 140 | check_erratum_custom_start cortex_a72, CVE(2022, 23960) |
| 141 | #if WORKAROUND_CVE_2017_5715 || WORKAROUND_CVE_2022_23960 |
| 142 | cpu_check_csv2 x0, 1f |
| 143 | mov x0, #ERRATA_APPLIES |
| 144 | ret |
| 145 | 1: |
| 146 | #if WORKAROUND_CVE_2022_23960 |
| 147 | mov x0, #ERRATA_APPLIES |
| 148 | #else |
| 149 | mov x0, #ERRATA_MISSING |
Bipin Ravi | cf4d50a | 2022-02-15 23:24:51 -0600 | [diff] [blame] | 150 | #endif /* WORKAROUND_CVE_2022_23960 */ |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 151 | ret |
| 152 | #endif /* WORKAROUND_CVE_2017_5715 || WORKAROUND_CVE_2022_23960 */ |
| 153 | mov x0, #ERRATA_MISSING |
| 154 | ret |
| 155 | check_erratum_custom_end cortex_a72, CVE(2022, 23960) |
Dimitris Papastamos | 446f7f1 | 2017-11-30 14:53:53 +0000 | [diff] [blame] | 156 | |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 157 | cpu_reset_func_start cortex_a72 |
Dimitris Papastamos | e6625ec | 2018-04-05 14:38:26 +0100 | [diff] [blame] | 158 | |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 159 | /* --------------------------------------------- |
Eleanor Bonnici | c3b4ca1 | 2017-08-02 18:33:41 +0100 | [diff] [blame] | 160 | * Enable the SMP bit. |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 161 | * --------------------------------------------- |
| 162 | */ |
Jayanth Dodderi Chidanand | 30da8af | 2023-06-23 08:27:09 +0100 | [diff] [blame] | 163 | sysreg_bit_set CORTEX_A72_ECTLR_EL1, CORTEX_A72_ECTLR_SMP_BIT |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 164 | |
| 165 | cpu_reset_func_end cortex_a72 |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 166 | |
| 167 | /* ---------------------------------------------------- |
| 168 | * The CPU Ops core power down function for Cortex-A72. |
| 169 | * ---------------------------------------------------- |
| 170 | */ |
| 171 | func cortex_a72_core_pwr_dwn |
| 172 | mov x18, x30 |
| 173 | |
| 174 | /* --------------------------------------------- |
| 175 | * Turn off caches. |
| 176 | * --------------------------------------------- |
| 177 | */ |
| 178 | bl cortex_a72_disable_dcache |
| 179 | |
| 180 | /* --------------------------------------------- |
| 181 | * Disable the L2 prefetches. |
| 182 | * --------------------------------------------- |
| 183 | */ |
| 184 | bl cortex_a72_disable_l2_prefetch |
| 185 | |
| 186 | /* --------------------------------------------- |
| 187 | * Disable the load-store hardware prefetcher. |
| 188 | * --------------------------------------------- |
| 189 | */ |
| 190 | bl cortex_a72_disable_hw_prefetcher |
| 191 | |
| 192 | /* --------------------------------------------- |
| 193 | * Flush L1 caches. |
| 194 | * --------------------------------------------- |
| 195 | */ |
| 196 | mov x0, #DCCISW |
| 197 | bl dcsw_op_level1 |
| 198 | |
| 199 | /* --------------------------------------------- |
| 200 | * Come out of intra cluster coherency |
| 201 | * --------------------------------------------- |
| 202 | */ |
| 203 | bl cortex_a72_disable_smp |
| 204 | |
| 205 | /* --------------------------------------------- |
| 206 | * Force the debug interfaces to be quiescent |
| 207 | * --------------------------------------------- |
| 208 | */ |
| 209 | mov x30, x18 |
| 210 | b cortex_a72_disable_ext_debug |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 211 | endfunc cortex_a72_core_pwr_dwn |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 212 | |
| 213 | /* ------------------------------------------------------- |
| 214 | * The CPU Ops cluster power down function for Cortex-A72. |
| 215 | * ------------------------------------------------------- |
| 216 | */ |
| 217 | func cortex_a72_cluster_pwr_dwn |
| 218 | mov x18, x30 |
| 219 | |
| 220 | /* --------------------------------------------- |
| 221 | * Turn off caches. |
| 222 | * --------------------------------------------- |
| 223 | */ |
| 224 | bl cortex_a72_disable_dcache |
| 225 | |
| 226 | /* --------------------------------------------- |
| 227 | * Disable the L2 prefetches. |
| 228 | * --------------------------------------------- |
| 229 | */ |
| 230 | bl cortex_a72_disable_l2_prefetch |
| 231 | |
| 232 | /* --------------------------------------------- |
| 233 | * Disable the load-store hardware prefetcher. |
| 234 | * --------------------------------------------- |
| 235 | */ |
| 236 | bl cortex_a72_disable_hw_prefetcher |
| 237 | |
| 238 | #if !SKIP_A72_L1_FLUSH_PWR_DWN |
| 239 | /* --------------------------------------------- |
| 240 | * Flush L1 caches. |
| 241 | * --------------------------------------------- |
| 242 | */ |
| 243 | mov x0, #DCCISW |
| 244 | bl dcsw_op_level1 |
| 245 | #endif |
| 246 | |
| 247 | /* --------------------------------------------- |
| 248 | * Disable the optional ACP. |
| 249 | * --------------------------------------------- |
| 250 | */ |
| 251 | bl plat_disable_acp |
| 252 | |
| 253 | /* ------------------------------------------------- |
| 254 | * Flush the L2 caches. |
| 255 | * ------------------------------------------------- |
| 256 | */ |
| 257 | mov x0, #DCCISW |
| 258 | bl dcsw_op_level2 |
| 259 | |
| 260 | /* --------------------------------------------- |
| 261 | * Come out of intra cluster coherency |
| 262 | * --------------------------------------------- |
| 263 | */ |
| 264 | bl cortex_a72_disable_smp |
| 265 | |
| 266 | /* --------------------------------------------- |
| 267 | * Force the debug interfaces to be quiescent |
| 268 | * --------------------------------------------- |
| 269 | */ |
| 270 | mov x30, x18 |
| 271 | b cortex_a72_disable_ext_debug |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 272 | endfunc cortex_a72_cluster_pwr_dwn |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 273 | |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 274 | errata_report_shim cortex_a72 |
Eleanor Bonnici | c3b4ca1 | 2017-08-02 18:33:41 +0100 | [diff] [blame] | 275 | |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 276 | /* --------------------------------------------- |
| 277 | * This function provides cortex_a72 specific |
| 278 | * register information for crash reporting. |
| 279 | * It needs to return with x6 pointing to |
| 280 | * a list of register names in ascii and |
| 281 | * x8 - x15 having values of registers to be |
| 282 | * reported. |
| 283 | * --------------------------------------------- |
| 284 | */ |
| 285 | .section .rodata.cortex_a72_regs, "aS" |
| 286 | cortex_a72_regs: /* The ascii list of register names to be reported */ |
Naga Sureshkumar Relli | 6a72a91 | 2016-07-01 12:52:41 +0530 | [diff] [blame] | 287 | .asciz "cpuectlr_el1", "cpumerrsr_el1", "l2merrsr_el1", "" |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 288 | |
| 289 | func cortex_a72_cpu_reg_dump |
| 290 | adr x6, cortex_a72_regs |
Varun Wadekar | 1384a16 | 2017-06-05 14:54:46 -0700 | [diff] [blame] | 291 | mrs x8, CORTEX_A72_ECTLR_EL1 |
| 292 | mrs x9, CORTEX_A72_MERRSR_EL1 |
| 293 | mrs x10, CORTEX_A72_L2MERRSR_EL1 |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 294 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 295 | endfunc cortex_a72_cpu_reg_dump |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 296 | |
Dimitris Papastamos | ba51d9e | 2018-05-16 11:36:14 +0100 | [diff] [blame] | 297 | declare_cpu_ops_wa cortex_a72, CORTEX_A72_MIDR, \ |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 298 | cortex_a72_reset_func, \ |
Jayanth Dodderi Chidanand | b1cd7d5 | 2023-04-12 18:35:45 +0100 | [diff] [blame] | 299 | check_erratum_cortex_a72_5715, \ |
Dimitris Papastamos | ba51d9e | 2018-05-16 11:36:14 +0100 | [diff] [blame] | 300 | CPU_NO_EXTRA2_FUNC, \ |
Bipin Ravi | caa2e05 | 2022-02-23 23:45:50 -0600 | [diff] [blame] | 301 | check_smccc_arch_workaround_3, \ |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 302 | cortex_a72_core_pwr_dwn, \ |
| 303 | cortex_a72_cluster_pwr_dwn |