Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 1 | /* |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2023, Arm Limited. All rights reserved. |
Varun Wadekar | 83561e3 | 2023-09-20 15:13:16 +0000 | [diff] [blame] | 3 | * Copyright (c) 2021-2023, NVIDIA Corporation. All rights reserved. |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 4 | * |
| 5 | * SPDX-License-Identifier: BSD-3-Clause |
| 6 | */ |
| 7 | |
| 8 | #include <arch.h> |
| 9 | #include <asm_macros.S> |
| 10 | #include <common/bl_common.h> |
Jimmy Brisson | 7cc90c4 | 2020-09-30 15:34:51 -0500 | [diff] [blame] | 11 | #include <cortex_a78_ae.h> |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 12 | #include <cpu_macros.S> |
| 13 | #include <plat_macros.S> |
Bipin Ravi | eb4d12b | 2022-03-12 01:58:02 -0600 | [diff] [blame] | 14 | #include "wa_cve_2022_23960_bhb_vector.S" |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 15 | |
| 16 | /* Hardware handled coherency */ |
| 17 | #if HW_ASSISTED_COHERENCY == 0 |
Jimmy Brisson | 7cc90c4 | 2020-09-30 15:34:51 -0500 | [diff] [blame] | 18 | #error "cortex_a78_ae must be compiled with HW_ASSISTED_COHERENCY enabled" |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 19 | #endif |
| 20 | |
Bipin Ravi | eb4d12b | 2022-03-12 01:58:02 -0600 | [diff] [blame] | 21 | #if WORKAROUND_CVE_2022_23960 |
| 22 | wa_cve_2022_23960_bhb_vector_table CORTEX_A78_AE_BHB_LOOP_COUNT, cortex_a78_ae |
| 23 | #endif /* WORKAROUND_CVE_2022_23960 */ |
| 24 | |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 25 | workaround_reset_start cortex_a78_ae, ERRATUM(1941500), ERRATA_A78_AE_1941500 |
Varun Wadekar | 83561e3 | 2023-09-20 15:13:16 +0000 | [diff] [blame] | 26 | sysreg_bit_set CORTEX_A78_AE_CPUECTLR_EL1, CORTEX_A78_AE_CPUECTLR_EL1_BIT_8 |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 27 | workaround_reset_end cortex_a78_ae, ERRATUM(1941500) |
Varun Wadekar | 0914fc4 | 2021-07-27 02:32:29 -0700 | [diff] [blame] | 28 | |
Boyan Karatotev | 24c7c66 | 2023-04-05 16:29:25 +0100 | [diff] [blame] | 29 | check_erratum_ls cortex_a78_ae, ERRATUM(1941500), CPU_REV(0, 1) |
Varun Wadekar | 0914fc4 | 2021-07-27 02:32:29 -0700 | [diff] [blame] | 30 | |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 31 | workaround_reset_start cortex_a78_ae, ERRATUM(1951502), ERRATA_A78_AE_1951502 |
Varun Wadekar | a3110ad | 2021-07-27 00:39:40 -0700 | [diff] [blame] | 32 | msr S3_6_c15_c8_0, xzr |
| 33 | ldr x0, =0x10E3900002 |
| 34 | msr S3_6_c15_c8_2, x0 |
| 35 | ldr x0, =0x10FFF00083 |
| 36 | msr S3_6_c15_c8_3, x0 |
| 37 | ldr x0, =0x2001003FF |
| 38 | msr S3_6_c15_c8_1, x0 |
| 39 | |
| 40 | mov x0, #1 |
| 41 | msr S3_6_c15_c8_0, x0 |
| 42 | ldr x0, =0x10E3800082 |
| 43 | msr S3_6_c15_c8_2, x0 |
| 44 | ldr x0, =0x10FFF00083 |
| 45 | msr S3_6_c15_c8_3, x0 |
| 46 | ldr x0, =0x2001003FF |
| 47 | msr S3_6_c15_c8_1, x0 |
| 48 | |
| 49 | mov x0, #2 |
| 50 | msr S3_6_c15_c8_0, x0 |
| 51 | ldr x0, =0x10E3800200 |
| 52 | msr S3_6_c15_c8_2, x0 |
| 53 | ldr x0, =0x10FFF003E0 |
| 54 | msr S3_6_c15_c8_3, x0 |
| 55 | ldr x0, =0x2001003FF |
| 56 | msr S3_6_c15_c8_1, x0 |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 57 | workaround_reset_end cortex_a78_ae, ERRATUM(1951502) |
Varun Wadekar | a3110ad | 2021-07-27 00:39:40 -0700 | [diff] [blame] | 58 | |
Boyan Karatotev | 24c7c66 | 2023-04-05 16:29:25 +0100 | [diff] [blame] | 59 | check_erratum_ls cortex_a78_ae, ERRATUM(1951502), CPU_REV(0, 1) |
Varun Wadekar | a3110ad | 2021-07-27 00:39:40 -0700 | [diff] [blame] | 60 | |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 61 | workaround_reset_start cortex_a78_ae, ERRATUM(2376748), ERRATA_A78_AE_2376748 |
Varun Wadekar | 9030a6c | 2022-03-09 22:04:00 +0000 | [diff] [blame] | 62 | /* ------------------------------------------------------- |
| 63 | * Set CPUACTLR2_EL1[0] to 1 to force PLDW/PFRM ST to |
| 64 | * behave like PLD/PRFM LD and not cause invalidations to |
| 65 | * other PE caches. There might be a small performance |
| 66 | * degradation to this workaround for certain workloads |
| 67 | * that share data. |
| 68 | * ------------------------------------------------------- |
| 69 | */ |
Boyan Karatotev | 24c7c66 | 2023-04-05 16:29:25 +0100 | [diff] [blame] | 70 | sysreg_bit_set CORTEX_A78_AE_ACTLR2_EL1, CORTEX_A78_AE_ACTLR2_EL1_BIT_0 |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 71 | workaround_reset_end cortex_a78_ae, ERRATUM(2376748) |
Varun Wadekar | 9030a6c | 2022-03-09 22:04:00 +0000 | [diff] [blame] | 72 | |
Sona Mathew | 2089775 | 2023-10-10 16:48:57 -0500 | [diff] [blame] | 73 | check_erratum_ls cortex_a78_ae, ERRATUM(2376748), CPU_REV(0, 2) |
Varun Wadekar | ac6bf2e | 2022-03-09 22:20:32 +0000 | [diff] [blame] | 74 | |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 75 | workaround_reset_start cortex_a78_ae, ERRATUM(2395408), ERRATA_A78_AE_2395408 |
Varun Wadekar | ac6bf2e | 2022-03-09 22:20:32 +0000 | [diff] [blame] | 76 | /* -------------------------------------------------------- |
| 77 | * Disable folding of demand requests into older prefetches |
| 78 | * with L2 miss requests outstanding by setting the |
| 79 | * CPUACTLR2_EL1[40] to 1. |
| 80 | * -------------------------------------------------------- |
| 81 | */ |
Boyan Karatotev | 24c7c66 | 2023-04-05 16:29:25 +0100 | [diff] [blame] | 82 | sysreg_bit_set CORTEX_A78_AE_ACTLR2_EL1, CORTEX_A78_AE_ACTLR2_EL1_BIT_40 |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 83 | workaround_reset_end cortex_a78_ae, ERRATUM(2395408) |
Varun Wadekar | ac6bf2e | 2022-03-09 22:20:32 +0000 | [diff] [blame] | 84 | |
Boyan Karatotev | 24c7c66 | 2023-04-05 16:29:25 +0100 | [diff] [blame] | 85 | check_erratum_ls cortex_a78_ae, ERRATUM(2395408), CPU_REV(0, 1) |
Bipin Ravi | eb4d12b | 2022-03-12 01:58:02 -0600 | [diff] [blame] | 86 | |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 87 | workaround_reset_start cortex_a78_ae, CVE(2022, 23960), WORKAROUND_CVE_2022_23960 |
| 88 | #if IMAGE_BL31 |
| 89 | /* |
| 90 | * The Cortex-A78AE generic vectors are overridden to apply errata |
| 91 | * mitigation on exception entry from lower ELs. |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 92 | */ |
Boyan Karatotev | 24c7c66 | 2023-04-05 16:29:25 +0100 | [diff] [blame] | 93 | override_vector_table wa_cve_vbar_cortex_a78_ae |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 94 | #endif /* IMAGE_BL31 */ |
| 95 | workaround_reset_end cortex_a78_ae, CVE(2022, 23960) |
Varun Wadekar | a3110ad | 2021-07-27 00:39:40 -0700 | [diff] [blame] | 96 | |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 97 | check_erratum_chosen cortex_a78_ae, CVE(2022, 23960), WORKAROUND_CVE_2022_23960 |
Varun Wadekar | 0914fc4 | 2021-07-27 02:32:29 -0700 | [diff] [blame] | 98 | |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 99 | cpu_reset_func_start cortex_a78_ae |
Andre Przywara | 0b7f1b0 | 2023-03-21 13:53:19 +0000 | [diff] [blame] | 100 | #if ENABLE_FEAT_AMU |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 101 | /* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */ |
Boyan Karatotev | 24c7c66 | 2023-04-05 16:29:25 +0100 | [diff] [blame] | 102 | sysreg_bit_clear actlr_el3, CORTEX_A78_ACTLR_TAM_BIT |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 103 | |
| 104 | /* Make sure accesses from non-secure EL0/EL1 are not trapped to EL2 */ |
Boyan Karatotev | 24c7c66 | 2023-04-05 16:29:25 +0100 | [diff] [blame] | 105 | sysreg_bit_clear actlr_el2, CORTEX_A78_ACTLR_TAM_BIT |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 106 | |
| 107 | /* Enable group0 counters */ |
Jimmy Brisson | 3571fb9 | 2020-06-01 10:18:22 -0500 | [diff] [blame] | 108 | mov x0, #CORTEX_A78_AMU_GROUP0_MASK |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 109 | msr CPUAMCNTENSET0_EL0, x0 |
| 110 | |
| 111 | /* Enable group1 counters */ |
Jimmy Brisson | 3571fb9 | 2020-06-01 10:18:22 -0500 | [diff] [blame] | 112 | mov x0, #CORTEX_A78_AMU_GROUP1_MASK |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 113 | msr CPUAMCNTENSET1_EL0, x0 |
Varun Wadekar | a3110ad | 2021-07-27 00:39:40 -0700 | [diff] [blame] | 114 | #endif |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 115 | cpu_reset_func_end cortex_a78_ae |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 116 | |
| 117 | /* ------------------------------------------------------- |
| 118 | * HW will do the cache maintenance while powering down |
| 119 | * ------------------------------------------------------- |
| 120 | */ |
Jimmy Brisson | 7cc90c4 | 2020-09-30 15:34:51 -0500 | [diff] [blame] | 121 | func cortex_a78_ae_core_pwr_dwn |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 122 | /* ------------------------------------------------------- |
| 123 | * Enable CPU power down bit in power control register |
| 124 | * ------------------------------------------------------- |
| 125 | */ |
Boyan Karatotev | 24c7c66 | 2023-04-05 16:29:25 +0100 | [diff] [blame] | 126 | sysreg_bit_set CORTEX_A78_CPUPWRCTLR_EL1, CORTEX_A78_CPUPWRCTLR_EL1_CORE_PWRDN_EN_BIT |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 127 | isb |
| 128 | ret |
Jimmy Brisson | 7cc90c4 | 2020-09-30 15:34:51 -0500 | [diff] [blame] | 129 | endfunc cortex_a78_ae_core_pwr_dwn |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 130 | |
Boyan Karatotev | 496ae96 | 2023-04-05 11:02:22 +0100 | [diff] [blame] | 131 | errata_report_shim cortex_a78_ae |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 132 | |
| 133 | /* ------------------------------------------------------- |
Jimmy Brisson | 7cc90c4 | 2020-09-30 15:34:51 -0500 | [diff] [blame] | 134 | * This function provides cortex_a78_ae specific |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 135 | * register information for crash reporting. |
| 136 | * It needs to return with x6 pointing to |
| 137 | * a list of register names in ascii and |
| 138 | * x8 - x15 having values of registers to be |
| 139 | * reported. |
| 140 | * ------------------------------------------------------- |
| 141 | */ |
Jimmy Brisson | 7cc90c4 | 2020-09-30 15:34:51 -0500 | [diff] [blame] | 142 | .section .rodata.cortex_a78_ae_regs, "aS" |
| 143 | cortex_a78_ae_regs: /* The ascii list of register names to be reported */ |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 144 | .asciz "cpuectlr_el1", "" |
| 145 | |
Jimmy Brisson | 7cc90c4 | 2020-09-30 15:34:51 -0500 | [diff] [blame] | 146 | func cortex_a78_ae_cpu_reg_dump |
| 147 | adr x6, cortex_a78_ae_regs |
Jimmy Brisson | 3571fb9 | 2020-06-01 10:18:22 -0500 | [diff] [blame] | 148 | mrs x8, CORTEX_A78_CPUECTLR_EL1 |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 149 | ret |
Jimmy Brisson | 7cc90c4 | 2020-09-30 15:34:51 -0500 | [diff] [blame] | 150 | endfunc cortex_a78_ae_cpu_reg_dump |
Artsem Artsemenka | fea97f7 | 2019-09-16 15:11:21 +0100 | [diff] [blame] | 151 | |
Jimmy Brisson | 7cc90c4 | 2020-09-30 15:34:51 -0500 | [diff] [blame] | 152 | declare_cpu_ops cortex_a78_ae, CORTEX_A78_AE_MIDR, \ |
Varun Wadekar | a3110ad | 2021-07-27 00:39:40 -0700 | [diff] [blame] | 153 | cortex_a78_ae_reset_func, \ |
Jimmy Brisson | 7cc90c4 | 2020-09-30 15:34:51 -0500 | [diff] [blame] | 154 | cortex_a78_ae_core_pwr_dwn |