blob: c050b02a7aacd2461b2a28499b9f67ad60845674 [file] [log] [blame]
Varun Wadekar28463b92015-07-14 17:11:20 +05301/*
Varun Wadekare34bd092018-01-10 17:03:22 -08002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Varun Wadekar88d0f062020-05-24 16:26:22 -07003 * Copyright (c) 2020, 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 */
30 .globl workaround_bpflush_runtime_exceptions
31
32vector_base workaround_bpflush_runtime_exceptions
33
34 .macro apply_workaround
35 stp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0]
36
Varun Wadekar88d0f062020-05-24 16:26:22 -070037 /* Disable cycle counter when event counting is prohibited */
38 mrs x1, pmcr_el0
39 orr x0, x1, #PMCR_EL0_DP_BIT
40 msr pmcr_el0, x0
41 isb
42
Varun Wadekare34bd092018-01-10 17:03:22 -080043 /* -------------------------------------------------
44 * A new write-only system register where a write of
45 * 1 to bit 0 will cause the indirect branch predictor
46 * and RSB to be flushed.
47 *
48 * A write of 0 to bit 0 will be ignored. A write of
49 * 1 to any other bit will cause an MCA.
50 * -------------------------------------------------
51 */
52 mov x0, #1
53 msr s3_0_c15_c0_6, x0
54 isb
55
56 ldp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0]
57 .endm
58
59 /* ---------------------------------------------------------------------
60 * Current EL with SP_EL0 : 0x0 - 0x200
61 * ---------------------------------------------------------------------
62 */
63vector_entry workaround_bpflush_sync_exception_sp_el0
64 b sync_exception_sp_el0
Roberto Vargas95f30ab2018-04-17 11:31:43 +010065end_vector_entry workaround_bpflush_sync_exception_sp_el0
Varun Wadekare34bd092018-01-10 17:03:22 -080066
67vector_entry workaround_bpflush_irq_sp_el0
68 b irq_sp_el0
Roberto Vargas95f30ab2018-04-17 11:31:43 +010069end_vector_entry workaround_bpflush_irq_sp_el0
Varun Wadekare34bd092018-01-10 17:03:22 -080070
71vector_entry workaround_bpflush_fiq_sp_el0
72 b fiq_sp_el0
Roberto Vargas95f30ab2018-04-17 11:31:43 +010073end_vector_entry workaround_bpflush_fiq_sp_el0
Varun Wadekare34bd092018-01-10 17:03:22 -080074
75vector_entry workaround_bpflush_serror_sp_el0
76 b serror_sp_el0
Roberto Vargas95f30ab2018-04-17 11:31:43 +010077end_vector_entry workaround_bpflush_serror_sp_el0
Varun Wadekare34bd092018-01-10 17:03:22 -080078
79 /* ---------------------------------------------------------------------
80 * Current EL with SP_ELx: 0x200 - 0x400
81 * ---------------------------------------------------------------------
82 */
83vector_entry workaround_bpflush_sync_exception_sp_elx
84 b sync_exception_sp_elx
Roberto Vargas95f30ab2018-04-17 11:31:43 +010085end_vector_entry workaround_bpflush_sync_exception_sp_elx
Varun Wadekare34bd092018-01-10 17:03:22 -080086
87vector_entry workaround_bpflush_irq_sp_elx
88 b irq_sp_elx
Roberto Vargas95f30ab2018-04-17 11:31:43 +010089end_vector_entry workaround_bpflush_irq_sp_elx
Varun Wadekare34bd092018-01-10 17:03:22 -080090
91vector_entry workaround_bpflush_fiq_sp_elx
92 b fiq_sp_elx
Roberto Vargas95f30ab2018-04-17 11:31:43 +010093end_vector_entry workaround_bpflush_fiq_sp_elx
Varun Wadekare34bd092018-01-10 17:03:22 -080094
95vector_entry workaround_bpflush_serror_sp_elx
96 b serror_sp_elx
Roberto Vargas95f30ab2018-04-17 11:31:43 +010097end_vector_entry workaround_bpflush_serror_sp_elx
Varun Wadekare34bd092018-01-10 17:03:22 -080098
99 /* ---------------------------------------------------------------------
100 * Lower EL using AArch64 : 0x400 - 0x600
101 * ---------------------------------------------------------------------
102 */
103vector_entry workaround_bpflush_sync_exception_aarch64
104 apply_workaround
105 b sync_exception_aarch64
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100106end_vector_entry workaround_bpflush_sync_exception_aarch64
Varun Wadekare34bd092018-01-10 17:03:22 -0800107
108vector_entry workaround_bpflush_irq_aarch64
109 apply_workaround
110 b irq_aarch64
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100111end_vector_entry workaround_bpflush_irq_aarch64
Varun Wadekare34bd092018-01-10 17:03:22 -0800112
113vector_entry workaround_bpflush_fiq_aarch64
114 apply_workaround
115 b fiq_aarch64
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100116end_vector_entry workaround_bpflush_fiq_aarch64
Varun Wadekare34bd092018-01-10 17:03:22 -0800117
118vector_entry workaround_bpflush_serror_aarch64
119 apply_workaround
120 b serror_aarch64
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100121end_vector_entry workaround_bpflush_serror_aarch64
Varun Wadekare34bd092018-01-10 17:03:22 -0800122
123 /* ---------------------------------------------------------------------
124 * Lower EL using AArch32 : 0x600 - 0x800
125 * ---------------------------------------------------------------------
126 */
127vector_entry workaround_bpflush_sync_exception_aarch32
128 apply_workaround
129 b sync_exception_aarch32
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100130end_vector_entry workaround_bpflush_sync_exception_aarch32
Varun Wadekare34bd092018-01-10 17:03:22 -0800131
132vector_entry workaround_bpflush_irq_aarch32
133 apply_workaround
134 b irq_aarch32
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100135end_vector_entry workaround_bpflush_irq_aarch32
Varun Wadekare34bd092018-01-10 17:03:22 -0800136
137vector_entry workaround_bpflush_fiq_aarch32
138 apply_workaround
139 b fiq_aarch32
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100140end_vector_entry workaround_bpflush_fiq_aarch32
Varun Wadekare34bd092018-01-10 17:03:22 -0800141
142vector_entry workaround_bpflush_serror_aarch32
143 apply_workaround
144 b serror_aarch32
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100145end_vector_entry workaround_bpflush_serror_aarch32
Varun Wadekare34bd092018-01-10 17:03:22 -0800146
Varun Wadekard43583c2016-02-22 11:09:41 -0800147 .global denver_disable_dco
148
Varun Wadekar28463b92015-07-14 17:11:20 +0530149 /* ---------------------------------------------
150 * Disable debug interfaces
151 * ---------------------------------------------
152 */
153func denver_disable_ext_debug
154 mov x0, #1
155 msr osdlr_el1, x0
156 isb
157 dsb sy
158 ret
159endfunc denver_disable_ext_debug
160
161 /* ----------------------------------------------------
162 * Enable dynamic code optimizer (DCO)
163 * ----------------------------------------------------
164 */
165func denver_enable_dco
Kalyani Chidambaram892fff92018-10-08 17:01:01 -0700166 mov x18, x30
Varun Wadekar007a2062018-02-27 18:30:31 -0800167 bl plat_my_core_pos
Varun Wadekar28463b92015-07-14 17:11:20 +0530168 mov x1, #1
169 lsl x1, x1, x0
170 msr s3_0_c15_c0_2, x1
Kalyani Chidambaram892fff92018-10-08 17:01:01 -0700171 mov x30, x18
Varun Wadekar28463b92015-07-14 17:11:20 +0530172 ret
173endfunc denver_enable_dco
174
175 /* ----------------------------------------------------
176 * Disable dynamic code optimizer (DCO)
177 * ----------------------------------------------------
178 */
179func denver_disable_dco
180
Kalyani Chidambaram892fff92018-10-08 17:01:01 -0700181 mov x18, x30
Varun Wadekar007a2062018-02-27 18:30:31 -0800182
Varun Wadekar28463b92015-07-14 17:11:20 +0530183 /* turn off background work */
Varun Wadekar007a2062018-02-27 18:30:31 -0800184 bl plat_my_core_pos
Varun Wadekar28463b92015-07-14 17:11:20 +0530185 mov x1, #1
186 lsl x1, x1, x0
187 lsl x2, x1, #16
188 msr s3_0_c15_c0_2, x2
189 isb
190
191 /* wait till the background work turns off */
1921: mrs x2, s3_0_c15_c0_2
193 lsr x2, x2, #32
194 and w2, w2, 0xFFFF
195 and x2, x2, x1
196 cbnz x2, 1b
197
Kalyani Chidambaram892fff92018-10-08 17:01:01 -0700198 mov x30, x18
Varun Wadekar28463b92015-07-14 17:11:20 +0530199 ret
200endfunc denver_disable_dco
201
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700202func check_errata_cve_2017_5715
203 mov x0, #ERRATA_MISSING
204#if WORKAROUND_CVE_2017_5715
205 /*
206 * Check if the CPU supports the special instruction
207 * required to flush the indirect branch predictor and
208 * RSB. Support for this operation can be determined by
209 * comparing bits 19:16 of ID_AFR0_EL1 with 0b0001.
210 */
211 mrs x1, id_afr0_el1
212 mov x2, #0x10000
213 and x1, x1, x2
214 cbz x1, 1f
215 mov x0, #ERRATA_APPLIES
2161:
217#endif
218 ret
219endfunc check_errata_cve_2017_5715
220
Varun Wadekarcd38e6e2018-08-28 09:11:30 -0700221func check_errata_cve_2018_3639
222#if WORKAROUND_CVE_2018_3639
223 mov x0, #ERRATA_APPLIES
224#else
225 mov x0, #ERRATA_MISSING
226#endif
227 ret
228endfunc check_errata_cve_2018_3639
229
Varun Wadekar28463b92015-07-14 17:11:20 +0530230 /* -------------------------------------------------
231 * The CPU Ops reset function for Denver.
232 * -------------------------------------------------
233 */
234func denver_reset_func
235
236 mov x19, x30
237
Varun Wadekare34bd092018-01-10 17:03:22 -0800238#if IMAGE_BL31 && WORKAROUND_CVE_2017_5715
239 /*
240 * Check if the CPU supports the special instruction
241 * required to flush the indirect branch predictor and
242 * RSB. Support for this operation can be determined by
243 * comparing bits 19:16 of ID_AFR0_EL1 with 0b0001.
244 */
245 mrs x0, id_afr0_el1
246 mov x1, #0x10000
247 and x0, x0, x1
248 cmp x0, #0
249 adr x1, workaround_bpflush_runtime_exceptions
250 mrs x2, vbar_el3
251 csel x0, x1, x2, ne
252 msr vbar_el3, x0
253#endif
254
Varun Wadekarcd38e6e2018-08-28 09:11:30 -0700255#if WORKAROUND_CVE_2018_3639
256 /*
257 * Denver CPUs with DENVER_MIDR_PN3 or earlier, use different
258 * bits in the ACTLR_EL3 register to disable speculative
259 * store buffer and memory disambiguation.
260 */
261 mrs x0, midr_el1
262 mov_imm x1, DENVER_MIDR_PN4
263 cmp x0, x1
264 mrs x0, actlr_el3
265 mov x1, #(DENVER_CPU_DIS_MD_EL3 | DENVER_CPU_DIS_SSB_EL3)
266 mov x2, #(DENVER_PN4_CPU_DIS_MD_EL3 | DENVER_PN4_CPU_DIS_SSB_EL3)
267 csel x3, x1, x2, ne
268 orr x0, x0, x3
269 msr actlr_el3, x0
270 isb
271 dsb sy
272#endif
273
Varun Wadekar28463b92015-07-14 17:11:20 +0530274 /* ----------------------------------------------------
Varun Wadekar2b914122018-06-25 11:36:47 -0700275 * Reset ACTLR.PMSTATE to C1 state
276 * ----------------------------------------------------
277 */
278 mrs x0, actlr_el1
279 bic x0, x0, #DENVER_CPU_PMSTATE_MASK
280 orr x0, x0, #DENVER_CPU_PMSTATE_C1
281 msr actlr_el1, x0
282
283 /* ----------------------------------------------------
Varun Wadekar28463b92015-07-14 17:11:20 +0530284 * Enable dynamic code optimizer (DCO)
285 * ----------------------------------------------------
286 */
287 bl denver_enable_dco
288
289 ret x19
290endfunc denver_reset_func
291
292 /* ----------------------------------------------------
293 * The CPU Ops core power down function for Denver.
294 * ----------------------------------------------------
295 */
296func denver_core_pwr_dwn
297
298 mov x19, x30
299
Varun Wadekar28463b92015-07-14 17:11:20 +0530300 /* ---------------------------------------------
301 * Force the debug interfaces to be quiescent
302 * ---------------------------------------------
303 */
304 bl denver_disable_ext_debug
305
306 ret x19
307endfunc denver_core_pwr_dwn
308
309 /* -------------------------------------------------------
310 * The CPU Ops cluster power down function for Denver.
311 * -------------------------------------------------------
312 */
313func denver_cluster_pwr_dwn
314 ret
315endfunc denver_cluster_pwr_dwn
316
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700317#if REPORT_ERRATA
318 /*
319 * Errata printing function for Denver. Must follow AAPCS.
320 */
321func denver_errata_report
322 stp x8, x30, [sp, #-16]!
323
324 bl cpu_get_rev_var
325 mov x8, x0
326
327 /*
328 * Report all errata. The revision-variant information is passed to
329 * checking functions of each errata.
330 */
331 report_errata WORKAROUND_CVE_2017_5715, denver, cve_2017_5715
Varun Wadekarcd38e6e2018-08-28 09:11:30 -0700332 report_errata WORKAROUND_CVE_2018_3639, denver, cve_2018_3639
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700333
334 ldp x8, x30, [sp], #16
335 ret
336endfunc denver_errata_report
337#endif
338
Varun Wadekar28463b92015-07-14 17:11:20 +0530339 /* ---------------------------------------------
340 * This function provides Denver specific
341 * register information for crash reporting.
342 * It needs to return with x6 pointing to
343 * a list of register names in ascii and
344 * x8 - x15 having values of registers to be
345 * reported.
346 * ---------------------------------------------
347 */
348.section .rodata.denver_regs, "aS"
349denver_regs: /* The ascii list of register names to be reported */
350 .asciz "actlr_el1", ""
351
352func denver_cpu_reg_dump
353 adr x6, denver_regs
354 mrs x8, ACTLR_EL1
355 ret
356endfunc denver_cpu_reg_dump
357
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700358declare_cpu_ops_wa denver, DENVER_MIDR_PN0, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530359 denver_reset_func, \
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700360 check_errata_cve_2017_5715, \
361 CPU_NO_EXTRA2_FUNC, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530362 denver_core_pwr_dwn, \
363 denver_cluster_pwr_dwn
364
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700365declare_cpu_ops_wa denver, DENVER_MIDR_PN1, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530366 denver_reset_func, \
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700367 check_errata_cve_2017_5715, \
368 CPU_NO_EXTRA2_FUNC, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530369 denver_core_pwr_dwn, \
370 denver_cluster_pwr_dwn
371
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700372declare_cpu_ops_wa denver, DENVER_MIDR_PN2, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530373 denver_reset_func, \
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700374 check_errata_cve_2017_5715, \
375 CPU_NO_EXTRA2_FUNC, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530376 denver_core_pwr_dwn, \
377 denver_cluster_pwr_dwn
378
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700379declare_cpu_ops_wa denver, DENVER_MIDR_PN3, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530380 denver_reset_func, \
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700381 check_errata_cve_2017_5715, \
382 CPU_NO_EXTRA2_FUNC, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530383 denver_core_pwr_dwn, \
384 denver_cluster_pwr_dwn
385
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700386declare_cpu_ops_wa denver, DENVER_MIDR_PN4, \
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000387 denver_reset_func, \
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700388 check_errata_cve_2017_5715, \
389 CPU_NO_EXTRA2_FUNC, \
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000390 denver_core_pwr_dwn, \
391 denver_cluster_pwr_dwn