blob: 884281d30e2f566ad72a77fac7449aee4d878d32 [file] [log] [blame]
Varun Wadekar28463b92015-07-14 17:11:20 +05301/*
Boyan Karatotev2ed12822023-04-05 11:26:35 +01002 * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
Varun Wadekared13c8c2022-05-24 15:00:06 +01003 * Copyright (c) 2020-2022, NVIDIA Corporation. All rights reserved.
Varun Wadekar28463b92015-07-14 17:11:20 +05304 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar28463b92015-07-14 17:11:20 +05306 */
7
8#include <arch.h>
9#include <asm_macros.S>
10#include <assert_macros.S>
Varun Wadekare34bd092018-01-10 17:03:22 -080011#include <context.h>
Varun Wadekar28463b92015-07-14 17:11:20 +053012#include <denver.h>
13#include <cpu_macros.S>
14#include <plat_macros.S>
15
Varun Wadekare34bd092018-01-10 17:03:22 -080016 /* -------------------------------------------------
17 * CVE-2017-5715 mitigation
18 *
19 * Flush the indirect branch predictor and RSB on
20 * entry to EL3 by issuing a newly added instruction
21 * for Denver CPUs.
22 *
23 * To achieve this without performing any branch
24 * instruction, a per-cpu vbar is installed which
25 * executes the workaround and then branches off to
26 * the corresponding vector entry in the main vector
27 * table.
28 * -------------------------------------------------
29 */
Varun Wadekare34bd092018-01-10 17:03:22 -080030vector_base workaround_bpflush_runtime_exceptions
31
32 .macro apply_workaround
33 stp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0]
34
Varun Wadekar88d0f062020-05-24 16:26:22 -070035 /* Disable cycle counter when event counting is prohibited */
36 mrs x1, pmcr_el0
37 orr x0, x1, #PMCR_EL0_DP_BIT
38 msr pmcr_el0, x0
39 isb
40
Varun Wadekare34bd092018-01-10 17:03:22 -080041 /* -------------------------------------------------
42 * A new write-only system register where a write of
43 * 1 to bit 0 will cause the indirect branch predictor
44 * and RSB to be flushed.
45 *
46 * A write of 0 to bit 0 will be ignored. A write of
47 * 1 to any other bit will cause an MCA.
48 * -------------------------------------------------
49 */
50 mov x0, #1
51 msr s3_0_c15_c0_6, x0
52 isb
53
54 ldp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0]
55 .endm
56
57 /* ---------------------------------------------------------------------
58 * Current EL with SP_EL0 : 0x0 - 0x200
59 * ---------------------------------------------------------------------
60 */
61vector_entry workaround_bpflush_sync_exception_sp_el0
62 b sync_exception_sp_el0
Roberto Vargas95f30ab2018-04-17 11:31:43 +010063end_vector_entry workaround_bpflush_sync_exception_sp_el0
Varun Wadekare34bd092018-01-10 17:03:22 -080064
65vector_entry workaround_bpflush_irq_sp_el0
66 b irq_sp_el0
Roberto Vargas95f30ab2018-04-17 11:31:43 +010067end_vector_entry workaround_bpflush_irq_sp_el0
Varun Wadekare34bd092018-01-10 17:03:22 -080068
69vector_entry workaround_bpflush_fiq_sp_el0
70 b fiq_sp_el0
Roberto Vargas95f30ab2018-04-17 11:31:43 +010071end_vector_entry workaround_bpflush_fiq_sp_el0
Varun Wadekare34bd092018-01-10 17:03:22 -080072
73vector_entry workaround_bpflush_serror_sp_el0
74 b serror_sp_el0
Roberto Vargas95f30ab2018-04-17 11:31:43 +010075end_vector_entry workaround_bpflush_serror_sp_el0
Varun Wadekare34bd092018-01-10 17:03:22 -080076
77 /* ---------------------------------------------------------------------
78 * Current EL with SP_ELx: 0x200 - 0x400
79 * ---------------------------------------------------------------------
80 */
81vector_entry workaround_bpflush_sync_exception_sp_elx
82 b sync_exception_sp_elx
Roberto Vargas95f30ab2018-04-17 11:31:43 +010083end_vector_entry workaround_bpflush_sync_exception_sp_elx
Varun Wadekare34bd092018-01-10 17:03:22 -080084
85vector_entry workaround_bpflush_irq_sp_elx
86 b irq_sp_elx
Roberto Vargas95f30ab2018-04-17 11:31:43 +010087end_vector_entry workaround_bpflush_irq_sp_elx
Varun Wadekare34bd092018-01-10 17:03:22 -080088
89vector_entry workaround_bpflush_fiq_sp_elx
90 b fiq_sp_elx
Roberto Vargas95f30ab2018-04-17 11:31:43 +010091end_vector_entry workaround_bpflush_fiq_sp_elx
Varun Wadekare34bd092018-01-10 17:03:22 -080092
93vector_entry workaround_bpflush_serror_sp_elx
94 b serror_sp_elx
Roberto Vargas95f30ab2018-04-17 11:31:43 +010095end_vector_entry workaround_bpflush_serror_sp_elx
Varun Wadekare34bd092018-01-10 17:03:22 -080096
97 /* ---------------------------------------------------------------------
98 * Lower EL using AArch64 : 0x400 - 0x600
99 * ---------------------------------------------------------------------
100 */
101vector_entry workaround_bpflush_sync_exception_aarch64
102 apply_workaround
103 b sync_exception_aarch64
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100104end_vector_entry workaround_bpflush_sync_exception_aarch64
Varun Wadekare34bd092018-01-10 17:03:22 -0800105
106vector_entry workaround_bpflush_irq_aarch64
107 apply_workaround
108 b irq_aarch64
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100109end_vector_entry workaround_bpflush_irq_aarch64
Varun Wadekare34bd092018-01-10 17:03:22 -0800110
111vector_entry workaround_bpflush_fiq_aarch64
112 apply_workaround
113 b fiq_aarch64
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100114end_vector_entry workaround_bpflush_fiq_aarch64
Varun Wadekare34bd092018-01-10 17:03:22 -0800115
116vector_entry workaround_bpflush_serror_aarch64
117 apply_workaround
118 b serror_aarch64
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100119end_vector_entry workaround_bpflush_serror_aarch64
Varun Wadekare34bd092018-01-10 17:03:22 -0800120
121 /* ---------------------------------------------------------------------
122 * Lower EL using AArch32 : 0x600 - 0x800
123 * ---------------------------------------------------------------------
124 */
125vector_entry workaround_bpflush_sync_exception_aarch32
126 apply_workaround
127 b sync_exception_aarch32
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100128end_vector_entry workaround_bpflush_sync_exception_aarch32
Varun Wadekare34bd092018-01-10 17:03:22 -0800129
130vector_entry workaround_bpflush_irq_aarch32
131 apply_workaround
132 b irq_aarch32
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100133end_vector_entry workaround_bpflush_irq_aarch32
Varun Wadekare34bd092018-01-10 17:03:22 -0800134
135vector_entry workaround_bpflush_fiq_aarch32
136 apply_workaround
137 b fiq_aarch32
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100138end_vector_entry workaround_bpflush_fiq_aarch32
Varun Wadekare34bd092018-01-10 17:03:22 -0800139
140vector_entry workaround_bpflush_serror_aarch32
141 apply_workaround
142 b serror_aarch32
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100143end_vector_entry workaround_bpflush_serror_aarch32
Varun Wadekare34bd092018-01-10 17:03:22 -0800144
Varun Wadekard43583c2016-02-22 11:09:41 -0800145 .global denver_disable_dco
146
Varun Wadekar28463b92015-07-14 17:11:20 +0530147 /* ---------------------------------------------
148 * Disable debug interfaces
149 * ---------------------------------------------
150 */
151func denver_disable_ext_debug
152 mov x0, #1
153 msr osdlr_el1, x0
154 isb
155 dsb sy
156 ret
157endfunc denver_disable_ext_debug
158
159 /* ----------------------------------------------------
160 * Enable dynamic code optimizer (DCO)
161 * ----------------------------------------------------
162 */
163func denver_enable_dco
Varun Wadekar5bd5ae92020-08-05 23:10:40 -0700164 /* DCO is not supported on PN5 and later */
165 mrs x1, midr_el1
166 mov_imm x2, DENVER_MIDR_PN4
167 cmp x1, x2
168 b.hi 1f
169
Kalyani Chidambaram892fff92018-10-08 17:01:01 -0700170 mov x18, x30
Varun Wadekar007a2062018-02-27 18:30:31 -0800171 bl plat_my_core_pos
Varun Wadekar28463b92015-07-14 17:11:20 +0530172 mov x1, #1
173 lsl x1, x1, x0
174 msr s3_0_c15_c0_2, x1
Kalyani Chidambaram892fff92018-10-08 17:01:01 -0700175 mov x30, x18
Varun Wadekar5bd5ae92020-08-05 23:10:40 -07001761: ret
Varun Wadekar28463b92015-07-14 17:11:20 +0530177endfunc denver_enable_dco
178
179 /* ----------------------------------------------------
180 * Disable dynamic code optimizer (DCO)
181 * ----------------------------------------------------
182 */
183func denver_disable_dco
Varun Wadekar5bd5ae92020-08-05 23:10:40 -0700184 /* DCO is not supported on PN5 and later */
185 mrs x1, midr_el1
186 mov_imm x2, DENVER_MIDR_PN4
187 cmp x1, x2
188 b.hi 2f
Varun Wadekar007a2062018-02-27 18:30:31 -0800189
Varun Wadekar28463b92015-07-14 17:11:20 +0530190 /* turn off background work */
Varun Wadekar5bd5ae92020-08-05 23:10:40 -0700191 mov x18, x30
Varun Wadekar007a2062018-02-27 18:30:31 -0800192 bl plat_my_core_pos
Varun Wadekar28463b92015-07-14 17:11:20 +0530193 mov x1, #1
194 lsl x1, x1, x0
195 lsl x2, x1, #16
196 msr s3_0_c15_c0_2, x2
197 isb
198
199 /* wait till the background work turns off */
2001: mrs x2, s3_0_c15_c0_2
201 lsr x2, x2, #32
202 and w2, w2, 0xFFFF
203 and x2, x2, x1
204 cbnz x2, 1b
205
Kalyani Chidambaram892fff92018-10-08 17:01:01 -0700206 mov x30, x18
Varun Wadekar5bd5ae92020-08-05 23:10:40 -07002072: ret
Varun Wadekar28463b92015-07-14 17:11:20 +0530208endfunc denver_disable_dco
209
Boyan Karatotev2ed12822023-04-05 11:26:35 +0100210workaround_reset_start denver, CVE(2017, 5715), WORKAROUND_CVE_2017_5715
211#if IMAGE_BL31
212 adr x1, workaround_bpflush_runtime_exceptions
213 msr vbar_el3, x1
214#endif
215workaround_reset_end denver, CVE(2017, 5715)
216
217check_erratum_custom_start denver, CVE(2017, 5715)
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700218 mov x0, #ERRATA_MISSING
219#if WORKAROUND_CVE_2017_5715
220 /*
221 * Check if the CPU supports the special instruction
222 * required to flush the indirect branch predictor and
223 * RSB. Support for this operation can be determined by
224 * comparing bits 19:16 of ID_AFR0_EL1 with 0b0001.
225 */
226 mrs x1, id_afr0_el1
227 mov x2, #0x10000
228 and x1, x1, x2
229 cbz x1, 1f
230 mov x0, #ERRATA_APPLIES
2311:
232#endif
233 ret
Boyan Karatotev2ed12822023-04-05 11:26:35 +0100234check_erratum_custom_end denver, CVE(2017, 5715)
Varun Wadekare34bd092018-01-10 17:03:22 -0800235
Boyan Karatotev2ed12822023-04-05 11:26:35 +0100236workaround_reset_start denver, CVE(2018, 3639), WORKAROUND_CVE_2018_3639
Varun Wadekarcd38e6e2018-08-28 09:11:30 -0700237 /*
238 * Denver CPUs with DENVER_MIDR_PN3 or earlier, use different
239 * bits in the ACTLR_EL3 register to disable speculative
240 * store buffer and memory disambiguation.
241 */
242 mrs x0, midr_el1
243 mov_imm x1, DENVER_MIDR_PN4
244 cmp x0, x1
245 mrs x0, actlr_el3
246 mov x1, #(DENVER_CPU_DIS_MD_EL3 | DENVER_CPU_DIS_SSB_EL3)
247 mov x2, #(DENVER_PN4_CPU_DIS_MD_EL3 | DENVER_PN4_CPU_DIS_SSB_EL3)
248 csel x3, x1, x2, ne
249 orr x0, x0, x3
250 msr actlr_el3, x0
251 isb
252 dsb sy
Boyan Karatotev2ed12822023-04-05 11:26:35 +0100253workaround_reset_end denver, CVE(2018, 3639)
254
255check_erratum_chosen denver, CVE(2018, 3639), WORKAROUND_CVE_2018_3639
Varun Wadekarcd38e6e2018-08-28 09:11:30 -0700256
Boyan Karatotev2ed12822023-04-05 11:26:35 +0100257cpu_reset_func_start denver
Varun Wadekar28463b92015-07-14 17:11:20 +0530258 /* ----------------------------------------------------
Varun Wadekar2b914122018-06-25 11:36:47 -0700259 * Reset ACTLR.PMSTATE to C1 state
260 * ----------------------------------------------------
261 */
262 mrs x0, actlr_el1
263 bic x0, x0, #DENVER_CPU_PMSTATE_MASK
264 orr x0, x0, #DENVER_CPU_PMSTATE_C1
265 msr actlr_el1, x0
266
267 /* ----------------------------------------------------
Varun Wadekar28463b92015-07-14 17:11:20 +0530268 * Enable dynamic code optimizer (DCO)
269 * ----------------------------------------------------
270 */
271 bl denver_enable_dco
Boyan Karatotev2ed12822023-04-05 11:26:35 +0100272cpu_reset_func_end denver
Varun Wadekar28463b92015-07-14 17:11:20 +0530273
274 /* ----------------------------------------------------
275 * The CPU Ops core power down function for Denver.
276 * ----------------------------------------------------
277 */
278func denver_core_pwr_dwn
279
280 mov x19, x30
281
Varun Wadekar28463b92015-07-14 17:11:20 +0530282 /* ---------------------------------------------
283 * Force the debug interfaces to be quiescent
284 * ---------------------------------------------
285 */
286 bl denver_disable_ext_debug
287
288 ret x19
289endfunc denver_core_pwr_dwn
290
291 /* -------------------------------------------------------
292 * The CPU Ops cluster power down function for Denver.
293 * -------------------------------------------------------
294 */
295func denver_cluster_pwr_dwn
296 ret
297endfunc denver_cluster_pwr_dwn
298
Boyan Karatotev2ed12822023-04-05 11:26:35 +0100299errata_report_shim denver
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700300
Varun Wadekar28463b92015-07-14 17:11:20 +0530301 /* ---------------------------------------------
302 * This function provides Denver specific
303 * register information for crash reporting.
304 * It needs to return with x6 pointing to
305 * a list of register names in ascii and
306 * x8 - x15 having values of registers to be
307 * reported.
308 * ---------------------------------------------
309 */
310.section .rodata.denver_regs, "aS"
311denver_regs: /* The ascii list of register names to be reported */
312 .asciz "actlr_el1", ""
313
314func denver_cpu_reg_dump
315 adr x6, denver_regs
316 mrs x8, ACTLR_EL1
317 ret
318endfunc denver_cpu_reg_dump
319
Varun Wadekar3bdb40b2020-08-28 14:00:15 -0700320/* macro to declare cpu_ops for Denver SKUs */
321.macro denver_cpu_ops_wa midr
322 declare_cpu_ops_wa denver, \midr, \
323 denver_reset_func, \
Boyan Karatotev2ed12822023-04-05 11:26:35 +0100324 check_erratum_denver_5715, \
Varun Wadekar3bdb40b2020-08-28 14:00:15 -0700325 CPU_NO_EXTRA2_FUNC, \
Varun Wadekared13c8c2022-05-24 15:00:06 +0100326 CPU_NO_EXTRA3_FUNC, \
Varun Wadekar3bdb40b2020-08-28 14:00:15 -0700327 denver_core_pwr_dwn, \
328 denver_cluster_pwr_dwn
329.endm
Alex Van Brunt5f68fa72019-07-23 10:00:42 -0700330
Varun Wadekar3bdb40b2020-08-28 14:00:15 -0700331denver_cpu_ops_wa DENVER_MIDR_PN0
332denver_cpu_ops_wa DENVER_MIDR_PN1
333denver_cpu_ops_wa DENVER_MIDR_PN2
334denver_cpu_ops_wa DENVER_MIDR_PN3
335denver_cpu_ops_wa DENVER_MIDR_PN4
336denver_cpu_ops_wa DENVER_MIDR_PN5
337denver_cpu_ops_wa DENVER_MIDR_PN6
338denver_cpu_ops_wa DENVER_MIDR_PN7
339denver_cpu_ops_wa DENVER_MIDR_PN8
Hemant Nigam96e081d2019-12-17 14:21:38 -0800340denver_cpu_ops_wa DENVER_MIDR_PN9