Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 1 | /* |
Manish V Badarkhe | 7672edf | 2020-08-03 18:43:14 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2020, 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> |
| 12 | |
| 13 | /* --------------------------------------------- |
| 14 | * Disable L1 data cache and unified L2 cache |
| 15 | * --------------------------------------------- |
| 16 | */ |
| 17 | func cortex_a72_disable_dcache |
| 18 | mrs x1, sctlr_el3 |
| 19 | bic x1, x1, #SCTLR_C_BIT |
| 20 | msr sctlr_el3, x1 |
| 21 | isb |
| 22 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 23 | endfunc cortex_a72_disable_dcache |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 24 | |
| 25 | /* --------------------------------------------- |
| 26 | * Disable all types of L2 prefetches. |
| 27 | * --------------------------------------------- |
| 28 | */ |
| 29 | func cortex_a72_disable_l2_prefetch |
Varun Wadekar | 1384a16 | 2017-06-05 14:54:46 -0700 | [diff] [blame] | 30 | mrs x0, CORTEX_A72_ECTLR_EL1 |
| 31 | orr x0, x0, #CORTEX_A72_ECTLR_DIS_TWD_ACC_PFTCH_BIT |
| 32 | mov x1, #CORTEX_A72_ECTLR_L2_IPFTCH_DIST_MASK |
| 33 | orr x1, x1, #CORTEX_A72_ECTLR_L2_DPFTCH_DIST_MASK |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 34 | bic x0, x0, x1 |
Varun Wadekar | 1384a16 | 2017-06-05 14:54:46 -0700 | [diff] [blame] | 35 | msr CORTEX_A72_ECTLR_EL1, x0 |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 36 | isb |
| 37 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 38 | endfunc cortex_a72_disable_l2_prefetch |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 39 | |
| 40 | /* --------------------------------------------- |
| 41 | * Disable the load-store hardware prefetcher. |
| 42 | * --------------------------------------------- |
| 43 | */ |
| 44 | func cortex_a72_disable_hw_prefetcher |
Eleanor Bonnici | 41b61be | 2017-08-09 16:42:40 +0100 | [diff] [blame] | 45 | mrs x0, CORTEX_A72_CPUACTLR_EL1 |
| 46 | orr x0, x0, #CORTEX_A72_CPUACTLR_EL1_DISABLE_L1_DCACHE_HW_PFTCH |
| 47 | msr CORTEX_A72_CPUACTLR_EL1, x0 |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 48 | isb |
| 49 | dsb ish |
| 50 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 51 | endfunc cortex_a72_disable_hw_prefetcher |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 52 | |
| 53 | /* --------------------------------------------- |
| 54 | * Disable intra-cluster coherency |
| 55 | * --------------------------------------------- |
| 56 | */ |
| 57 | func cortex_a72_disable_smp |
Varun Wadekar | 1384a16 | 2017-06-05 14:54:46 -0700 | [diff] [blame] | 58 | mrs x0, CORTEX_A72_ECTLR_EL1 |
| 59 | bic x0, x0, #CORTEX_A72_ECTLR_SMP_BIT |
| 60 | msr CORTEX_A72_ECTLR_EL1, x0 |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 61 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 62 | endfunc cortex_a72_disable_smp |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 63 | |
| 64 | /* --------------------------------------------- |
| 65 | * Disable debug interfaces |
| 66 | * --------------------------------------------- |
| 67 | */ |
| 68 | func cortex_a72_disable_ext_debug |
| 69 | mov x0, #1 |
| 70 | msr osdlr_el1, x0 |
| 71 | isb |
| 72 | dsb sy |
| 73 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 74 | endfunc cortex_a72_disable_ext_debug |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 75 | |
Eleanor Bonnici | c3b4ca1 | 2017-08-02 18:33:41 +0100 | [diff] [blame] | 76 | /* -------------------------------------------------- |
| 77 | * Errata Workaround for Cortex A72 Errata #859971. |
| 78 | * This applies only to revision <= r0p3 of Cortex A72. |
| 79 | * Inputs: |
| 80 | * x0: variant[4:7] and revision[0:3] of current cpu. |
| 81 | * Shall clobber: |
| 82 | * -------------------------------------------------- |
| 83 | */ |
| 84 | func errata_a72_859971_wa |
| 85 | mov x17,x30 |
| 86 | bl check_errata_859971 |
| 87 | cbz x0, 1f |
| 88 | mrs x1, CORTEX_A72_CPUACTLR_EL1 |
| 89 | orr x1, x1, #CORTEX_A72_CPUACTLR_EL1_DIS_INSTR_PREFETCH |
| 90 | msr CORTEX_A72_CPUACTLR_EL1, x1 |
| 91 | 1: |
| 92 | ret x17 |
| 93 | endfunc errata_a72_859971_wa |
| 94 | |
| 95 | func check_errata_859971 |
| 96 | mov x1, #0x03 |
| 97 | b cpu_rev_var_ls |
| 98 | endfunc check_errata_859971 |
| 99 | |
Dimitris Papastamos | 858bd61 | 2018-01-16 10:32:47 +0000 | [diff] [blame] | 100 | func check_errata_cve_2017_5715 |
Dimitris Papastamos | 780cc95 | 2018-03-12 13:27:02 +0000 | [diff] [blame] | 101 | cpu_check_csv2 x0, 1f |
Dimitris Papastamos | 858bd61 | 2018-01-16 10:32:47 +0000 | [diff] [blame] | 102 | #if WORKAROUND_CVE_2017_5715 |
| 103 | mov x0, #ERRATA_APPLIES |
| 104 | #else |
| 105 | mov x0, #ERRATA_MISSING |
| 106 | #endif |
| 107 | ret |
Dimitris Papastamos | 780cc95 | 2018-03-12 13:27:02 +0000 | [diff] [blame] | 108 | 1: |
| 109 | mov x0, #ERRATA_NOT_APPLIES |
| 110 | ret |
Dimitris Papastamos | 858bd61 | 2018-01-16 10:32:47 +0000 | [diff] [blame] | 111 | endfunc check_errata_cve_2017_5715 |
| 112 | |
Dimitris Papastamos | e6625ec | 2018-04-05 14:38:26 +0100 | [diff] [blame] | 113 | func check_errata_cve_2018_3639 |
| 114 | #if WORKAROUND_CVE_2018_3639 |
| 115 | mov x0, #ERRATA_APPLIES |
| 116 | #else |
| 117 | mov x0, #ERRATA_MISSING |
| 118 | #endif |
| 119 | ret |
| 120 | endfunc check_errata_cve_2018_3639 |
| 121 | |
Manish V Badarkhe | 7672edf | 2020-08-03 18:43:14 +0100 | [diff] [blame] | 122 | /* -------------------------------------------------- |
| 123 | * Errata workaround for Cortex A72 Errata #1319367. |
| 124 | * This applies to all revisions of Cortex A72. |
| 125 | * -------------------------------------------------- |
| 126 | */ |
| 127 | func check_errata_1319367 |
| 128 | #if ERRATA_A72_1319367 |
| 129 | mov x0, #ERRATA_APPLIES |
| 130 | #else |
| 131 | mov x0, #ERRATA_MISSING |
| 132 | #endif |
| 133 | ret |
| 134 | endfunc check_errata_1319367 |
| 135 | |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 136 | /* ------------------------------------------------- |
| 137 | * The CPU Ops reset function for Cortex-A72. |
| 138 | * ------------------------------------------------- |
| 139 | */ |
| 140 | func cortex_a72_reset_func |
Eleanor Bonnici | c3b4ca1 | 2017-08-02 18:33:41 +0100 | [diff] [blame] | 141 | mov x19, x30 |
| 142 | bl cpu_get_rev_var |
| 143 | mov x18, x0 |
| 144 | |
| 145 | #if ERRATA_A72_859971 |
| 146 | mov x0, x18 |
| 147 | bl errata_a72_859971_wa |
| 148 | #endif |
Dimitris Papastamos | 446f7f1 | 2017-11-30 14:53:53 +0000 | [diff] [blame] | 149 | |
| 150 | #if IMAGE_BL31 && WORKAROUND_CVE_2017_5715 |
Dimitris Papastamos | 780cc95 | 2018-03-12 13:27:02 +0000 | [diff] [blame] | 151 | cpu_check_csv2 x0, 1f |
Dimitris Papastamos | 570c06a | 2018-04-06 15:29:34 +0100 | [diff] [blame] | 152 | adr x0, wa_cve_2017_5715_mmu_vbar |
Dimitris Papastamos | 446f7f1 | 2017-11-30 14:53:53 +0000 | [diff] [blame] | 153 | msr vbar_el3, x0 |
Dimitris Papastamos | bb0aa39 | 2018-06-07 13:20:19 +0100 | [diff] [blame] | 154 | /* isb will be performed before returning from this function */ |
Dimitris Papastamos | 780cc95 | 2018-03-12 13:27:02 +0000 | [diff] [blame] | 155 | 1: |
Dimitris Papastamos | 446f7f1 | 2017-11-30 14:53:53 +0000 | [diff] [blame] | 156 | #endif |
| 157 | |
Dimitris Papastamos | e6625ec | 2018-04-05 14:38:26 +0100 | [diff] [blame] | 158 | #if WORKAROUND_CVE_2018_3639 |
| 159 | mrs x0, CORTEX_A72_CPUACTLR_EL1 |
| 160 | orr x0, x0, #CORTEX_A72_CPUACTLR_EL1_DIS_LOAD_PASS_STORE |
| 161 | msr CORTEX_A72_CPUACTLR_EL1, x0 |
| 162 | isb |
| 163 | dsb sy |
| 164 | #endif |
| 165 | |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 166 | /* --------------------------------------------- |
Eleanor Bonnici | c3b4ca1 | 2017-08-02 18:33:41 +0100 | [diff] [blame] | 167 | * Enable the SMP bit. |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 168 | * --------------------------------------------- |
| 169 | */ |
Varun Wadekar | 1384a16 | 2017-06-05 14:54:46 -0700 | [diff] [blame] | 170 | mrs x0, CORTEX_A72_ECTLR_EL1 |
| 171 | orr x0, x0, #CORTEX_A72_ECTLR_SMP_BIT |
| 172 | msr CORTEX_A72_ECTLR_EL1, x0 |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 173 | isb |
Eleanor Bonnici | c3b4ca1 | 2017-08-02 18:33:41 +0100 | [diff] [blame] | 174 | ret x19 |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 175 | endfunc cortex_a72_reset_func |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 176 | |
| 177 | /* ---------------------------------------------------- |
| 178 | * The CPU Ops core power down function for Cortex-A72. |
| 179 | * ---------------------------------------------------- |
| 180 | */ |
| 181 | func cortex_a72_core_pwr_dwn |
| 182 | mov x18, x30 |
| 183 | |
| 184 | /* --------------------------------------------- |
| 185 | * Turn off caches. |
| 186 | * --------------------------------------------- |
| 187 | */ |
| 188 | bl cortex_a72_disable_dcache |
| 189 | |
| 190 | /* --------------------------------------------- |
| 191 | * Disable the L2 prefetches. |
| 192 | * --------------------------------------------- |
| 193 | */ |
| 194 | bl cortex_a72_disable_l2_prefetch |
| 195 | |
| 196 | /* --------------------------------------------- |
| 197 | * Disable the load-store hardware prefetcher. |
| 198 | * --------------------------------------------- |
| 199 | */ |
| 200 | bl cortex_a72_disable_hw_prefetcher |
| 201 | |
| 202 | /* --------------------------------------------- |
| 203 | * Flush L1 caches. |
| 204 | * --------------------------------------------- |
| 205 | */ |
| 206 | mov x0, #DCCISW |
| 207 | bl dcsw_op_level1 |
| 208 | |
| 209 | /* --------------------------------------------- |
| 210 | * Come out of intra cluster coherency |
| 211 | * --------------------------------------------- |
| 212 | */ |
| 213 | bl cortex_a72_disable_smp |
| 214 | |
| 215 | /* --------------------------------------------- |
| 216 | * Force the debug interfaces to be quiescent |
| 217 | * --------------------------------------------- |
| 218 | */ |
| 219 | mov x30, x18 |
| 220 | b cortex_a72_disable_ext_debug |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 221 | endfunc cortex_a72_core_pwr_dwn |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 222 | |
| 223 | /* ------------------------------------------------------- |
| 224 | * The CPU Ops cluster power down function for Cortex-A72. |
| 225 | * ------------------------------------------------------- |
| 226 | */ |
| 227 | func cortex_a72_cluster_pwr_dwn |
| 228 | mov x18, x30 |
| 229 | |
| 230 | /* --------------------------------------------- |
| 231 | * Turn off caches. |
| 232 | * --------------------------------------------- |
| 233 | */ |
| 234 | bl cortex_a72_disable_dcache |
| 235 | |
| 236 | /* --------------------------------------------- |
| 237 | * Disable the L2 prefetches. |
| 238 | * --------------------------------------------- |
| 239 | */ |
| 240 | bl cortex_a72_disable_l2_prefetch |
| 241 | |
| 242 | /* --------------------------------------------- |
| 243 | * Disable the load-store hardware prefetcher. |
| 244 | * --------------------------------------------- |
| 245 | */ |
| 246 | bl cortex_a72_disable_hw_prefetcher |
| 247 | |
| 248 | #if !SKIP_A72_L1_FLUSH_PWR_DWN |
| 249 | /* --------------------------------------------- |
| 250 | * Flush L1 caches. |
| 251 | * --------------------------------------------- |
| 252 | */ |
| 253 | mov x0, #DCCISW |
| 254 | bl dcsw_op_level1 |
| 255 | #endif |
| 256 | |
| 257 | /* --------------------------------------------- |
| 258 | * Disable the optional ACP. |
| 259 | * --------------------------------------------- |
| 260 | */ |
| 261 | bl plat_disable_acp |
| 262 | |
| 263 | /* ------------------------------------------------- |
| 264 | * Flush the L2 caches. |
| 265 | * ------------------------------------------------- |
| 266 | */ |
| 267 | mov x0, #DCCISW |
| 268 | bl dcsw_op_level2 |
| 269 | |
| 270 | /* --------------------------------------------- |
| 271 | * Come out of intra cluster coherency |
| 272 | * --------------------------------------------- |
| 273 | */ |
| 274 | bl cortex_a72_disable_smp |
| 275 | |
| 276 | /* --------------------------------------------- |
| 277 | * Force the debug interfaces to be quiescent |
| 278 | * --------------------------------------------- |
| 279 | */ |
| 280 | mov x30, x18 |
| 281 | b cortex_a72_disable_ext_debug |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 282 | endfunc cortex_a72_cluster_pwr_dwn |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 283 | |
Eleanor Bonnici | c3b4ca1 | 2017-08-02 18:33:41 +0100 | [diff] [blame] | 284 | #if REPORT_ERRATA |
| 285 | /* |
| 286 | * Errata printing function for Cortex A72. Must follow AAPCS. |
| 287 | */ |
| 288 | func cortex_a72_errata_report |
| 289 | stp x8, x30, [sp, #-16]! |
| 290 | |
| 291 | bl cpu_get_rev_var |
| 292 | mov x8, x0 |
| 293 | |
| 294 | /* |
| 295 | * Report all errata. The revision-variant information is passed to |
| 296 | * checking functions of each errata. |
| 297 | */ |
| 298 | report_errata ERRATA_A72_859971, cortex_a72, 859971 |
Manish V Badarkhe | 7672edf | 2020-08-03 18:43:14 +0100 | [diff] [blame] | 299 | report_errata ERRATA_A72_1319367, cortex_a72, 1319367 |
Dimitris Papastamos | 858bd61 | 2018-01-16 10:32:47 +0000 | [diff] [blame] | 300 | report_errata WORKAROUND_CVE_2017_5715, cortex_a72, cve_2017_5715 |
Dimitris Papastamos | e6625ec | 2018-04-05 14:38:26 +0100 | [diff] [blame] | 301 | report_errata WORKAROUND_CVE_2018_3639, cortex_a72, cve_2018_3639 |
Eleanor Bonnici | c3b4ca1 | 2017-08-02 18:33:41 +0100 | [diff] [blame] | 302 | |
| 303 | ldp x8, x30, [sp], #16 |
| 304 | ret |
| 305 | endfunc cortex_a72_errata_report |
| 306 | #endif |
| 307 | |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 308 | /* --------------------------------------------- |
| 309 | * This function provides cortex_a72 specific |
| 310 | * register information for crash reporting. |
| 311 | * It needs to return with x6 pointing to |
| 312 | * a list of register names in ascii and |
| 313 | * x8 - x15 having values of registers to be |
| 314 | * reported. |
| 315 | * --------------------------------------------- |
| 316 | */ |
| 317 | .section .rodata.cortex_a72_regs, "aS" |
| 318 | 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] | 319 | .asciz "cpuectlr_el1", "cpumerrsr_el1", "l2merrsr_el1", "" |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 320 | |
| 321 | func cortex_a72_cpu_reg_dump |
| 322 | adr x6, cortex_a72_regs |
Varun Wadekar | 1384a16 | 2017-06-05 14:54:46 -0700 | [diff] [blame] | 323 | mrs x8, CORTEX_A72_ECTLR_EL1 |
| 324 | mrs x9, CORTEX_A72_MERRSR_EL1 |
| 325 | mrs x10, CORTEX_A72_L2MERRSR_EL1 |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 326 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 327 | endfunc cortex_a72_cpu_reg_dump |
Vikram Kanigiri | c47e011 | 2015-02-17 11:50:28 +0000 | [diff] [blame] | 328 | |
Dimitris Papastamos | ba51d9e | 2018-05-16 11:36:14 +0100 | [diff] [blame] | 329 | declare_cpu_ops_wa cortex_a72, CORTEX_A72_MIDR, \ |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 330 | cortex_a72_reset_func, \ |
Dimitris Papastamos | 914757c | 2018-03-12 14:47:09 +0000 | [diff] [blame] | 331 | check_errata_cve_2017_5715, \ |
Dimitris Papastamos | ba51d9e | 2018-05-16 11:36:14 +0100 | [diff] [blame] | 332 | CPU_NO_EXTRA2_FUNC, \ |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 333 | cortex_a72_core_pwr_dwn, \ |
| 334 | cortex_a72_cluster_pwr_dwn |