xref: /rk3399_ARM-atf/lib/cpus/aarch64/neoverse_n1.S (revision 4d8801fe5aa0d26ab3df42d31f0e7129209d301b)
1/*
2 * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <neoverse_n1.h>
10#include <cpuamu.h>
11#include <cpu_macros.S>
12
13/* Hardware handled coherency */
14#if HW_ASSISTED_COHERENCY == 0
15#error "Neoverse N1 must be compiled with HW_ASSISTED_COHERENCY enabled"
16#endif
17
18/* 64-bit only core */
19#if CTX_INCLUDE_AARCH32_REGS == 1
20#error "Neoverse-N1 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0"
21#endif
22
23/* --------------------------------------------------
24 * Errata Workaround for Neoverse N1 Erratum 1043202.
25 * This applies to revision r0p0 and r1p0 of Neoverse N1.
26 * Inputs:
27 * x0: variant[4:7] and revision[0:3] of current cpu.
28 * Shall clobber: x0-x17
29 * --------------------------------------------------
30 */
31func errata_n1_1043202_wa
32	/* Compare x0 against revision r1p0 */
33	mov	x17, x30
34	bl	check_errata_1043202
35	cbz	x0, 1f
36
37	/* Apply instruction patching sequence */
38	ldr	x0, =0x0
39	msr	CPUPSELR_EL3, x0
40	ldr	x0, =0xF3BF8F2F
41	msr	CPUPOR_EL3, x0
42	ldr	x0, =0xFFFFFFFF
43	msr	CPUPMR_EL3, x0
44	ldr	x0, =0x800200071
45	msr	CPUPCR_EL3, x0
46	isb
471:
48	ret	x17
49endfunc errata_n1_1043202_wa
50
51func check_errata_1043202
52	/* Applies to r0p0 and r1p0 */
53	mov	x1, #0x10
54	b	cpu_rev_var_ls
55endfunc check_errata_1043202
56
57/* --------------------------------------------------
58 * Disable speculative loads if Neoverse N1 supports
59 * SSBS.
60 *
61 * Shall clobber: x0.
62 * --------------------------------------------------
63 */
64func neoverse_n1_disable_speculative_loads
65	/* Check if the PE implements SSBS */
66	mrs	x0, id_aa64pfr1_el1
67	tst	x0, #(ID_AA64PFR1_EL1_SSBS_MASK << ID_AA64PFR1_EL1_SSBS_SHIFT)
68	b.eq	1f
69
70	/* Disable speculative loads */
71	msr	SSBS, xzr
72	isb
73
741:
75	ret
76endfunc neoverse_n1_disable_speculative_loads
77
78/* --------------------------------------------------
79 * Errata Workaround for Neoverse N1 Errata #1073348
80 * This applies to revision r0p0 and r1p0 of Neoverse N1.
81 * Inputs:
82 * x0: variant[4:7] and revision[0:3] of current cpu.
83 * Shall clobber: x0-x17
84 * --------------------------------------------------
85 */
86func errata_n1_1073348_wa
87	/* Compare x0 against revision r1p0 */
88	mov	x17, x30
89	bl	check_errata_1073348
90	cbz	x0, 1f
91	mrs	x1, NEOVERSE_N1_CPUACTLR_EL1
92	orr	x1, x1, NEOVERSE_N1_CPUACTLR_EL1_BIT_6
93	msr	NEOVERSE_N1_CPUACTLR_EL1, x1
94	isb
951:
96	ret	x17
97endfunc errata_n1_1073348_wa
98
99func check_errata_1073348
100	/* Applies to r0p0 and r1p0 */
101	mov	x1, #0x10
102	b	cpu_rev_var_ls
103endfunc check_errata_1073348
104
105/* --------------------------------------------------
106 * Errata Workaround for Neoverse N1 Errata #1130799
107 * This applies to revision <=r2p0 of Neoverse N1.
108 * Inputs:
109 * x0: variant[4:7] and revision[0:3] of current cpu.
110 * Shall clobber: x0-x17
111 * --------------------------------------------------
112 */
113func errata_n1_1130799_wa
114	/* Compare x0 against revision r2p0 */
115	mov	x17, x30
116	bl	check_errata_1130799
117	cbz	x0, 1f
118	mrs	x1, NEOVERSE_N1_CPUACTLR2_EL1
119	orr	x1, x1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_59
120	msr	NEOVERSE_N1_CPUACTLR2_EL1, x1
121	isb
1221:
123	ret	x17
124endfunc errata_n1_1130799_wa
125
126func check_errata_1130799
127	/* Applies to <=r2p0 */
128	mov	x1, #0x20
129	b	cpu_rev_var_ls
130endfunc check_errata_1130799
131
132/* --------------------------------------------------
133 * Errata Workaround for Neoverse N1 Errata #1165347
134 * This applies to revision <=r2p0 of Neoverse N1.
135 * Inputs:
136 * x0: variant[4:7] and revision[0:3] of current cpu.
137 * Shall clobber: x0-x17
138 * --------------------------------------------------
139 */
140func errata_n1_1165347_wa
141	/* Compare x0 against revision r2p0 */
142	mov	x17, x30
143	bl	check_errata_1165347
144	cbz	x0, 1f
145	mrs	x1, NEOVERSE_N1_CPUACTLR2_EL1
146	orr	x1, x1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_0
147	orr	x1, x1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_15
148	msr	NEOVERSE_N1_CPUACTLR2_EL1, x1
149	isb
1501:
151	ret	x17
152endfunc errata_n1_1165347_wa
153
154func check_errata_1165347
155	/* Applies to <=r2p0 */
156	mov	x1, #0x20
157	b	cpu_rev_var_ls
158endfunc check_errata_1165347
159
160/* --------------------------------------------------
161 * Errata Workaround for Neoverse N1 Errata #1207823
162 * This applies to revision <=r2p0 of Neoverse N1.
163 * Inputs:
164 * x0: variant[4:7] and revision[0:3] of current cpu.
165 * Shall clobber: x0-x17
166 * --------------------------------------------------
167 */
168func errata_n1_1207823_wa
169	/* Compare x0 against revision r2p0 */
170	mov	x17, x30
171	bl	check_errata_1207823
172	cbz	x0, 1f
173	mrs	x1, NEOVERSE_N1_CPUACTLR2_EL1
174	orr	x1, x1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_11
175	msr	NEOVERSE_N1_CPUACTLR2_EL1, x1
176	isb
1771:
178	ret	x17
179endfunc errata_n1_1207823_wa
180
181func check_errata_1207823
182	/* Applies to <=r2p0 */
183	mov	x1, #0x20
184	b	cpu_rev_var_ls
185endfunc check_errata_1207823
186
187/* --------------------------------------------------
188 * Errata Workaround for Neoverse N1 Errata #1220197
189 * This applies to revision <=r2p0 of Neoverse N1.
190 * Inputs:
191 * x0: variant[4:7] and revision[0:3] of current cpu.
192 * Shall clobber: x0-x17
193 * --------------------------------------------------
194 */
195func errata_n1_1220197_wa
196	/* Compare x0 against revision r2p0 */
197	mov	x17, x30
198	bl	check_errata_1220197
199	cbz	x0, 1f
200	mrs	x1, NEOVERSE_N1_CPUECTLR_EL1
201	orr	x1, x1, NEOVERSE_N1_WS_THR_L2_MASK
202	msr	NEOVERSE_N1_CPUECTLR_EL1, x1
203	isb
2041:
205	ret	x17
206endfunc errata_n1_1220197_wa
207
208func check_errata_1220197
209	/* Applies to <=r2p0 */
210	mov	x1, #0x20
211	b	cpu_rev_var_ls
212endfunc check_errata_1220197
213
214/* --------------------------------------------------
215 * Errata Workaround for Neoverse N1 Errata #1257314
216 * This applies to revision <=r3p0 of Neoverse N1.
217 * Inputs:
218 * x0: variant[4:7] and revision[0:3] of current cpu.
219 * Shall clobber: x0-x17
220 * --------------------------------------------------
221 */
222func errata_n1_1257314_wa
223	/* Compare x0 against revision r3p0 */
224	mov	x17, x30
225	bl	check_errata_1257314
226	cbz	x0, 1f
227	mrs	x1, NEOVERSE_N1_CPUACTLR3_EL1
228	orr	x1, x1, NEOVERSE_N1_CPUACTLR3_EL1_BIT_10
229	msr	NEOVERSE_N1_CPUACTLR3_EL1, x1
230	isb
2311:
232	ret	x17
233endfunc errata_n1_1257314_wa
234
235func check_errata_1257314
236	/* Applies to <=r3p0 */
237	mov	x1, #0x30
238	b	cpu_rev_var_ls
239endfunc check_errata_1257314
240
241/* --------------------------------------------------
242 * Errata Workaround for Neoverse N1 Errata #1262606
243 * This applies to revision <=r3p0 of Neoverse N1.
244 * Inputs:
245 * x0: variant[4:7] and revision[0:3] of current cpu.
246 * Shall clobber: x0-x17
247 * --------------------------------------------------
248 */
249func errata_n1_1262606_wa
250	/* Compare x0 against revision r3p0 */
251	mov	x17, x30
252	bl	check_errata_1262606
253	cbz	x0, 1f
254	mrs	x1, NEOVERSE_N1_CPUACTLR_EL1
255	orr	x1, x1, NEOVERSE_N1_CPUACTLR_EL1_BIT_13
256	msr	NEOVERSE_N1_CPUACTLR_EL1, x1
257	isb
2581:
259	ret	x17
260endfunc errata_n1_1262606_wa
261
262func check_errata_1262606
263	/* Applies to <=r3p0 */
264	mov	x1, #0x30
265	b	cpu_rev_var_ls
266endfunc check_errata_1262606
267
268/* --------------------------------------------------
269 * Errata Workaround for Neoverse N1 Errata #1262888
270 * This applies to revision <=r3p0 of Neoverse N1.
271 * Inputs:
272 * x0: variant[4:7] and revision[0:3] of current cpu.
273 * Shall clobber: x0-x17
274 * --------------------------------------------------
275 */
276func errata_n1_1262888_wa
277	/* Compare x0 against revision r3p0 */
278	mov	x17, x30
279	bl	check_errata_1262888
280	cbz	x0, 1f
281	mrs	x1, NEOVERSE_N1_CPUECTLR_EL1
282	orr	x1, x1, NEOVERSE_N1_CPUECTLR_EL1_MM_TLBPF_DIS_BIT
283	msr	NEOVERSE_N1_CPUECTLR_EL1, x1
284	isb
2851:
286	ret	x17
287endfunc errata_n1_1262888_wa
288
289func check_errata_1262888
290	/* Applies to <=r3p0 */
291	mov	x1, #0x30
292	b	cpu_rev_var_ls
293endfunc check_errata_1262888
294
295/* --------------------------------------------------
296 * Errata Workaround for Neoverse N1 Errata #1275112
297 * This applies to revision <=r3p0 of Neoverse N1.
298 * Inputs:
299 * x0: variant[4:7] and revision[0:3] of current cpu.
300 * Shall clobber: x0-x17
301 * --------------------------------------------------
302 */
303func errata_n1_1275112_wa
304	/* Compare x0 against revision r3p0 */
305	mov	x17, x30
306	bl	check_errata_1275112
307	cbz	x0, 1f
308	mrs	x1, NEOVERSE_N1_CPUACTLR_EL1
309	orr	x1, x1, NEOVERSE_N1_CPUACTLR_EL1_BIT_13
310	msr	NEOVERSE_N1_CPUACTLR_EL1, x1
311	isb
3121:
313	ret	x17
314endfunc errata_n1_1275112_wa
315
316func check_errata_1275112
317	/* Applies to <=r3p0 */
318	mov	x1, #0x30
319	b	cpu_rev_var_ls
320endfunc check_errata_1275112
321
322/* --------------------------------------------------
323 * Errata Workaround for Neoverse N1 Erratum 1315703.
324 * This applies to revision <= r3p0 of Neoverse N1.
325 * Inputs:
326 * x0: variant[4:7] and revision[0:3] of current cpu.
327 * Shall clobber: x0-x17
328 * --------------------------------------------------
329 */
330func errata_n1_1315703_wa
331	/* Compare x0 against revision r3p1 */
332	mov	x17, x30
333	bl	check_errata_1315703
334	cbz	x0, 1f
335
336	mrs	x0, NEOVERSE_N1_CPUACTLR2_EL1
337	orr	x0, x0, #NEOVERSE_N1_CPUACTLR2_EL1_BIT_16
338	msr	NEOVERSE_N1_CPUACTLR2_EL1, x0
339	isb
340
3411:
342	ret	x17
343endfunc errata_n1_1315703_wa
344
345func check_errata_1315703
346	/* Applies to everything <= r3p0. */
347	mov	x1, #0x30
348	b	cpu_rev_var_ls
349endfunc check_errata_1315703
350
351func neoverse_n1_reset_func
352	mov	x19, x30
353
354	bl neoverse_n1_disable_speculative_loads
355
356	/* Forces all cacheable atomic instructions to be near */
357	mrs	x0, NEOVERSE_N1_CPUACTLR2_EL1
358	orr	x0, x0, #NEOVERSE_N1_CPUACTLR2_EL1_BIT_2
359	msr	NEOVERSE_N1_CPUACTLR2_EL1, x0
360	isb
361
362	bl	cpu_get_rev_var
363	mov	x18, x0
364
365#if ERRATA_N1_1043202
366	mov	x0, x18
367	bl	errata_n1_1043202_wa
368#endif
369
370#if ERRATA_N1_1073348
371	mov	x0, x18
372	bl	errata_n1_1073348_wa
373#endif
374
375#if ERRATA_N1_1130799
376	mov	x0, x18
377	bl	errata_n1_1130799_wa
378#endif
379
380#if ERRATA_N1_1165347
381	mov	x0, x18
382	bl	errata_n1_1165347_wa
383#endif
384
385#if ERRATA_N1_1207823
386	mov	x0, x18
387	bl	errata_n1_1207823_wa
388#endif
389
390#if ERRATA_N1_1220197
391	mov	x0, x18
392	bl	errata_n1_1220197_wa
393#endif
394
395#if ERRATA_N1_1257314
396	mov	x0, x18
397	bl	errata_n1_1257314_wa
398#endif
399
400#if ERRATA_N1_1262606
401	mov	x0, x18
402	bl	errata_n1_1262606_wa
403#endif
404
405#if ERRATA_N1_1262888
406	mov	x0, x18
407	bl	errata_n1_1262888_wa
408#endif
409
410#if ERRATA_N1_1275112
411	mov	x0, x18
412	bl	errata_n1_1275112_wa
413#endif
414
415#if ERRATA_N1_1315703
416	mov	x0, x18
417	bl	errata_n1_1315703_wa
418#endif
419
420#if ENABLE_AMU
421	/* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */
422	mrs	x0, actlr_el3
423	orr	x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT
424	msr	actlr_el3, x0
425	isb
426
427	/* Make sure accesses from EL0/EL1 are not trapped to EL2 */
428	mrs	x0, actlr_el2
429	orr	x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT
430	msr	actlr_el2, x0
431	isb
432
433	/* Enable group0 counters */
434	mov	x0, #NEOVERSE_N1_AMU_GROUP0_MASK
435	msr	CPUAMCNTENSET_EL0, x0
436	isb
437#endif
438
439#if ERRATA_DSU_936184
440	bl	errata_dsu_936184_wa
441#endif
442
443	ret	x19
444endfunc neoverse_n1_reset_func
445
446	/* ---------------------------------------------
447	 * HW will do the cache maintenance while powering down
448	 * ---------------------------------------------
449	 */
450func neoverse_n1_core_pwr_dwn
451	/* ---------------------------------------------
452	 * Enable CPU power down bit in power control register
453	 * ---------------------------------------------
454	 */
455	mrs	x0, NEOVERSE_N1_CPUPWRCTLR_EL1
456	orr	x0, x0, #NEOVERSE_N1_CORE_PWRDN_EN_MASK
457	msr	NEOVERSE_N1_CPUPWRCTLR_EL1, x0
458	isb
459	ret
460endfunc neoverse_n1_core_pwr_dwn
461
462#if REPORT_ERRATA
463/*
464 * Errata printing function for Neoverse N1. Must follow AAPCS.
465 */
466func neoverse_n1_errata_report
467	stp	x8, x30, [sp, #-16]!
468
469	bl	cpu_get_rev_var
470	mov	x8, x0
471
472	/*
473	 * Report all errata. The revision-variant information is passed to
474	 * checking functions of each errata.
475	 */
476	report_errata ERRATA_N1_1043202, neoverse_n1, 1043202
477	report_errata ERRATA_N1_1073348, neoverse_n1, 1073348
478	report_errata ERRATA_N1_1130799, neoverse_n1, 1130799
479	report_errata ERRATA_N1_1165347, neoverse_n1, 1165347
480	report_errata ERRATA_N1_1207823, neoverse_n1, 1207823
481	report_errata ERRATA_N1_1220197, neoverse_n1, 1220197
482	report_errata ERRATA_N1_1257314, neoverse_n1, 1257314
483	report_errata ERRATA_N1_1262606, neoverse_n1, 1262606
484	report_errata ERRATA_N1_1262888, neoverse_n1, 1262888
485	report_errata ERRATA_N1_1275112, neoverse_n1, 1275112
486	report_errata ERRATA_N1_1315703, neoverse_n1, 1315703
487	report_errata ERRATA_DSU_936184, neoverse_n1, dsu_936184
488
489	ldp	x8, x30, [sp], #16
490	ret
491endfunc neoverse_n1_errata_report
492#endif
493
494	/* ---------------------------------------------
495	 * This function provides neoverse_n1 specific
496	 * register information for crash reporting.
497	 * It needs to return with x6 pointing to
498	 * a list of register names in ascii and
499	 * x8 - x15 having values of registers to be
500	 * reported.
501	 * ---------------------------------------------
502	 */
503.section .rodata.neoverse_n1_regs, "aS"
504neoverse_n1_regs:  /* The ascii list of register names to be reported */
505	.asciz	"cpuectlr_el1", ""
506
507func neoverse_n1_cpu_reg_dump
508	adr	x6, neoverse_n1_regs
509	mrs	x8, NEOVERSE_N1_CPUECTLR_EL1
510	ret
511endfunc neoverse_n1_cpu_reg_dump
512
513declare_cpu_ops neoverse_n1, NEOVERSE_N1_MIDR, \
514	neoverse_n1_reset_func, \
515	neoverse_n1_core_pwr_dwn
516