blob: a981d02c7a589140891efdf6250d5eb5cac335b8 [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 Wadekar28463b92015-07-14 17:11:20 +05303 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar28463b92015-07-14 17:11:20 +05305 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <assert_macros.S>
Varun Wadekare34bd092018-01-10 17:03:22 -080010#include <context.h>
Varun Wadekar28463b92015-07-14 17:11:20 +053011#include <denver.h>
12#include <cpu_macros.S>
13#include <plat_macros.S>
14
Varun Wadekare34bd092018-01-10 17:03:22 -080015 /* -------------------------------------------------
16 * CVE-2017-5715 mitigation
17 *
18 * Flush the indirect branch predictor and RSB on
19 * entry to EL3 by issuing a newly added instruction
20 * for Denver CPUs.
21 *
22 * To achieve this without performing any branch
23 * instruction, a per-cpu vbar is installed which
24 * executes the workaround and then branches off to
25 * the corresponding vector entry in the main vector
26 * table.
27 * -------------------------------------------------
28 */
29 .globl workaround_bpflush_runtime_exceptions
30
31vector_base workaround_bpflush_runtime_exceptions
32
33 .macro apply_workaround
34 stp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0]
35
36 /* -------------------------------------------------
37 * A new write-only system register where a write of
38 * 1 to bit 0 will cause the indirect branch predictor
39 * and RSB to be flushed.
40 *
41 * A write of 0 to bit 0 will be ignored. A write of
42 * 1 to any other bit will cause an MCA.
43 * -------------------------------------------------
44 */
45 mov x0, #1
46 msr s3_0_c15_c0_6, x0
47 isb
48
49 ldp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0]
50 .endm
51
52 /* ---------------------------------------------------------------------
53 * Current EL with SP_EL0 : 0x0 - 0x200
54 * ---------------------------------------------------------------------
55 */
56vector_entry workaround_bpflush_sync_exception_sp_el0
57 b sync_exception_sp_el0
Roberto Vargas95f30ab2018-04-17 11:31:43 +010058end_vector_entry workaround_bpflush_sync_exception_sp_el0
Varun Wadekare34bd092018-01-10 17:03:22 -080059
60vector_entry workaround_bpflush_irq_sp_el0
61 b irq_sp_el0
Roberto Vargas95f30ab2018-04-17 11:31:43 +010062end_vector_entry workaround_bpflush_irq_sp_el0
Varun Wadekare34bd092018-01-10 17:03:22 -080063
64vector_entry workaround_bpflush_fiq_sp_el0
65 b fiq_sp_el0
Roberto Vargas95f30ab2018-04-17 11:31:43 +010066end_vector_entry workaround_bpflush_fiq_sp_el0
Varun Wadekare34bd092018-01-10 17:03:22 -080067
68vector_entry workaround_bpflush_serror_sp_el0
69 b serror_sp_el0
Roberto Vargas95f30ab2018-04-17 11:31:43 +010070end_vector_entry workaround_bpflush_serror_sp_el0
Varun Wadekare34bd092018-01-10 17:03:22 -080071
72 /* ---------------------------------------------------------------------
73 * Current EL with SP_ELx: 0x200 - 0x400
74 * ---------------------------------------------------------------------
75 */
76vector_entry workaround_bpflush_sync_exception_sp_elx
77 b sync_exception_sp_elx
Roberto Vargas95f30ab2018-04-17 11:31:43 +010078end_vector_entry workaround_bpflush_sync_exception_sp_elx
Varun Wadekare34bd092018-01-10 17:03:22 -080079
80vector_entry workaround_bpflush_irq_sp_elx
81 b irq_sp_elx
Roberto Vargas95f30ab2018-04-17 11:31:43 +010082end_vector_entry workaround_bpflush_irq_sp_elx
Varun Wadekare34bd092018-01-10 17:03:22 -080083
84vector_entry workaround_bpflush_fiq_sp_elx
85 b fiq_sp_elx
Roberto Vargas95f30ab2018-04-17 11:31:43 +010086end_vector_entry workaround_bpflush_fiq_sp_elx
Varun Wadekare34bd092018-01-10 17:03:22 -080087
88vector_entry workaround_bpflush_serror_sp_elx
89 b serror_sp_elx
Roberto Vargas95f30ab2018-04-17 11:31:43 +010090end_vector_entry workaround_bpflush_serror_sp_elx
Varun Wadekare34bd092018-01-10 17:03:22 -080091
92 /* ---------------------------------------------------------------------
93 * Lower EL using AArch64 : 0x400 - 0x600
94 * ---------------------------------------------------------------------
95 */
96vector_entry workaround_bpflush_sync_exception_aarch64
97 apply_workaround
98 b sync_exception_aarch64
Roberto Vargas95f30ab2018-04-17 11:31:43 +010099end_vector_entry workaround_bpflush_sync_exception_aarch64
Varun Wadekare34bd092018-01-10 17:03:22 -0800100
101vector_entry workaround_bpflush_irq_aarch64
102 apply_workaround
103 b irq_aarch64
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100104end_vector_entry workaround_bpflush_irq_aarch64
Varun Wadekare34bd092018-01-10 17:03:22 -0800105
106vector_entry workaround_bpflush_fiq_aarch64
107 apply_workaround
108 b fiq_aarch64
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100109end_vector_entry workaround_bpflush_fiq_aarch64
Varun Wadekare34bd092018-01-10 17:03:22 -0800110
111vector_entry workaround_bpflush_serror_aarch64
112 apply_workaround
113 b serror_aarch64
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100114end_vector_entry workaround_bpflush_serror_aarch64
Varun Wadekare34bd092018-01-10 17:03:22 -0800115
116 /* ---------------------------------------------------------------------
117 * Lower EL using AArch32 : 0x600 - 0x800
118 * ---------------------------------------------------------------------
119 */
120vector_entry workaround_bpflush_sync_exception_aarch32
121 apply_workaround
122 b sync_exception_aarch32
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100123end_vector_entry workaround_bpflush_sync_exception_aarch32
Varun Wadekare34bd092018-01-10 17:03:22 -0800124
125vector_entry workaround_bpflush_irq_aarch32
126 apply_workaround
127 b irq_aarch32
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100128end_vector_entry workaround_bpflush_irq_aarch32
Varun Wadekare34bd092018-01-10 17:03:22 -0800129
130vector_entry workaround_bpflush_fiq_aarch32
131 apply_workaround
132 b fiq_aarch32
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100133end_vector_entry workaround_bpflush_fiq_aarch32
Varun Wadekare34bd092018-01-10 17:03:22 -0800134
135vector_entry workaround_bpflush_serror_aarch32
136 apply_workaround
137 b serror_aarch32
Roberto Vargas95f30ab2018-04-17 11:31:43 +0100138end_vector_entry workaround_bpflush_serror_aarch32
Varun Wadekare34bd092018-01-10 17:03:22 -0800139
Varun Wadekard43583c2016-02-22 11:09:41 -0800140 .global denver_disable_dco
141
Varun Wadekar28463b92015-07-14 17:11:20 +0530142 /* ---------------------------------------------
143 * Disable debug interfaces
144 * ---------------------------------------------
145 */
146func denver_disable_ext_debug
147 mov x0, #1
148 msr osdlr_el1, x0
149 isb
150 dsb sy
151 ret
152endfunc denver_disable_ext_debug
153
154 /* ----------------------------------------------------
155 * Enable dynamic code optimizer (DCO)
156 * ----------------------------------------------------
157 */
158func denver_enable_dco
159 mrs x0, mpidr_el1
160 and x0, x0, #0xF
161 mov x1, #1
162 lsl x1, x1, x0
163 msr s3_0_c15_c0_2, x1
Varun Wadekar28463b92015-07-14 17:11:20 +0530164 ret
165endfunc denver_enable_dco
166
167 /* ----------------------------------------------------
168 * Disable dynamic code optimizer (DCO)
169 * ----------------------------------------------------
170 */
171func denver_disable_dco
172
173 /* turn off background work */
174 mrs x0, mpidr_el1
175 and x0, x0, #0xF
176 mov x1, #1
177 lsl x1, x1, x0
178 lsl x2, x1, #16
179 msr s3_0_c15_c0_2, x2
180 isb
181
182 /* wait till the background work turns off */
1831: mrs x2, s3_0_c15_c0_2
184 lsr x2, x2, #32
185 and w2, w2, 0xFFFF
186 and x2, x2, x1
187 cbnz x2, 1b
188
189 ret
190endfunc denver_disable_dco
191
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700192func check_errata_cve_2017_5715
193 mov x0, #ERRATA_MISSING
194#if WORKAROUND_CVE_2017_5715
195 /*
196 * Check if the CPU supports the special instruction
197 * required to flush the indirect branch predictor and
198 * RSB. Support for this operation can be determined by
199 * comparing bits 19:16 of ID_AFR0_EL1 with 0b0001.
200 */
201 mrs x1, id_afr0_el1
202 mov x2, #0x10000
203 and x1, x1, x2
204 cbz x1, 1f
205 mov x0, #ERRATA_APPLIES
2061:
207#endif
208 ret
209endfunc check_errata_cve_2017_5715
210
Varun Wadekar28463b92015-07-14 17:11:20 +0530211 /* -------------------------------------------------
212 * The CPU Ops reset function for Denver.
213 * -------------------------------------------------
214 */
215func denver_reset_func
216
217 mov x19, x30
218
Varun Wadekare34bd092018-01-10 17:03:22 -0800219#if IMAGE_BL31 && 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 x0, id_afr0_el1
227 mov x1, #0x10000
228 and x0, x0, x1
229 cmp x0, #0
230 adr x1, workaround_bpflush_runtime_exceptions
231 mrs x2, vbar_el3
232 csel x0, x1, x2, ne
233 msr vbar_el3, x0
234#endif
235
Varun Wadekar28463b92015-07-14 17:11:20 +0530236 /* ----------------------------------------------------
237 * Enable dynamic code optimizer (DCO)
238 * ----------------------------------------------------
239 */
240 bl denver_enable_dco
241
242 ret x19
243endfunc denver_reset_func
244
245 /* ----------------------------------------------------
246 * The CPU Ops core power down function for Denver.
247 * ----------------------------------------------------
248 */
249func denver_core_pwr_dwn
250
251 mov x19, x30
252
Varun Wadekar28463b92015-07-14 17:11:20 +0530253 /* ---------------------------------------------
254 * Force the debug interfaces to be quiescent
255 * ---------------------------------------------
256 */
257 bl denver_disable_ext_debug
258
259 ret x19
260endfunc denver_core_pwr_dwn
261
262 /* -------------------------------------------------------
263 * The CPU Ops cluster power down function for Denver.
264 * -------------------------------------------------------
265 */
266func denver_cluster_pwr_dwn
267 ret
268endfunc denver_cluster_pwr_dwn
269
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700270#if REPORT_ERRATA
271 /*
272 * Errata printing function for Denver. Must follow AAPCS.
273 */
274func denver_errata_report
275 stp x8, x30, [sp, #-16]!
276
277 bl cpu_get_rev_var
278 mov x8, x0
279
280 /*
281 * Report all errata. The revision-variant information is passed to
282 * checking functions of each errata.
283 */
284 report_errata WORKAROUND_CVE_2017_5715, denver, cve_2017_5715
285
286 ldp x8, x30, [sp], #16
287 ret
288endfunc denver_errata_report
289#endif
290
Varun Wadekar28463b92015-07-14 17:11:20 +0530291 /* ---------------------------------------------
292 * This function provides Denver specific
293 * register information for crash reporting.
294 * It needs to return with x6 pointing to
295 * a list of register names in ascii and
296 * x8 - x15 having values of registers to be
297 * reported.
298 * ---------------------------------------------
299 */
300.section .rodata.denver_regs, "aS"
301denver_regs: /* The ascii list of register names to be reported */
302 .asciz "actlr_el1", ""
303
304func denver_cpu_reg_dump
305 adr x6, denver_regs
306 mrs x8, ACTLR_EL1
307 ret
308endfunc denver_cpu_reg_dump
309
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700310declare_cpu_ops_wa denver, DENVER_MIDR_PN0, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530311 denver_reset_func, \
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700312 check_errata_cve_2017_5715, \
313 CPU_NO_EXTRA2_FUNC, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530314 denver_core_pwr_dwn, \
315 denver_cluster_pwr_dwn
316
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700317declare_cpu_ops_wa denver, DENVER_MIDR_PN1, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530318 denver_reset_func, \
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700319 check_errata_cve_2017_5715, \
320 CPU_NO_EXTRA2_FUNC, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530321 denver_core_pwr_dwn, \
322 denver_cluster_pwr_dwn
323
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700324declare_cpu_ops_wa denver, DENVER_MIDR_PN2, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530325 denver_reset_func, \
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700326 check_errata_cve_2017_5715, \
327 CPU_NO_EXTRA2_FUNC, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530328 denver_core_pwr_dwn, \
329 denver_cluster_pwr_dwn
330
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700331declare_cpu_ops_wa denver, DENVER_MIDR_PN3, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530332 denver_reset_func, \
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700333 check_errata_cve_2017_5715, \
334 CPU_NO_EXTRA2_FUNC, \
Varun Wadekar3c337a62015-09-03 17:15:06 +0530335 denver_core_pwr_dwn, \
336 denver_cluster_pwr_dwn
337
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700338declare_cpu_ops_wa denver, DENVER_MIDR_PN4, \
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000339 denver_reset_func, \
Varun Wadekarbc242fa2018-07-06 13:39:52 -0700340 check_errata_cve_2017_5715, \
341 CPU_NO_EXTRA2_FUNC, \
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000342 denver_core_pwr_dwn, \
343 denver_cluster_pwr_dwn