xref: /rk3399_ARM-atf/lib/cpus/aarch64/neoverse_n1.S (revision 076b5f02e2747ef1b5a55f1c5d368df16f046b1c)
1b04ea14bSJohn Tsichritzis/*
2da6d75a0SJohn Tsichritzis * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
3b04ea14bSJohn Tsichritzis *
4b04ea14bSJohn Tsichritzis * SPDX-License-Identifier: BSD-3-Clause
5b04ea14bSJohn Tsichritzis */
6b04ea14bSJohn Tsichritzis
7b04ea14bSJohn Tsichritzis#include <arch.h>
8b04ea14bSJohn Tsichritzis#include <asm_macros.S>
9da6d75a0SJohn Tsichritzis#include <neoverse_n1.h>
10b04ea14bSJohn Tsichritzis#include <cpuamu.h>
11b04ea14bSJohn Tsichritzis#include <cpu_macros.S>
12b04ea14bSJohn Tsichritzis
13*076b5f02SJohn Tsichritzis/* Hardware handled coherency */
14*076b5f02SJohn Tsichritzis#if HW_ASSISTED_COHERENCY == 0
15*076b5f02SJohn Tsichritzis#error "Neoverse N1 must be compiled with HW_ASSISTED_COHERENCY enabled"
16*076b5f02SJohn Tsichritzis#endif
17*076b5f02SJohn Tsichritzis
18b04ea14bSJohn Tsichritzis/* --------------------------------------------------
19da6d75a0SJohn Tsichritzis * Errata Workaround for Neoverse N1 Errata
20da6d75a0SJohn Tsichritzis * This applies to revision r0p0 and r1p0 of Neoverse N1.
21b04ea14bSJohn Tsichritzis * Inputs:
22b04ea14bSJohn Tsichritzis * x0: variant[4:7] and revision[0:3] of current cpu.
23b04ea14bSJohn Tsichritzis * Shall clobber: x0-x17
24b04ea14bSJohn Tsichritzis * --------------------------------------------------
25b04ea14bSJohn Tsichritzis */
26da6d75a0SJohn Tsichritzisfunc errata_n1_1043202_wa
27b04ea14bSJohn Tsichritzis	/* Compare x0 against revision r1p0 */
28b04ea14bSJohn Tsichritzis	mov	x17, x30
29b04ea14bSJohn Tsichritzis	bl	check_errata_1043202
30b04ea14bSJohn Tsichritzis	cbz	x0, 1f
31b04ea14bSJohn Tsichritzis
32b04ea14bSJohn Tsichritzis	/* Apply instruction patching sequence */
33b04ea14bSJohn Tsichritzis	ldr	x0, =0x0
34b04ea14bSJohn Tsichritzis	msr	CPUPSELR_EL3, x0
35b04ea14bSJohn Tsichritzis	ldr	x0, =0xF3BF8F2F
36b04ea14bSJohn Tsichritzis	msr	CPUPOR_EL3, x0
37b04ea14bSJohn Tsichritzis	ldr	x0, =0xFFFFFFFF
38b04ea14bSJohn Tsichritzis	msr	CPUPMR_EL3, x0
39b04ea14bSJohn Tsichritzis	ldr	x0, =0x800200071
40b04ea14bSJohn Tsichritzis	msr	CPUPCR_EL3, x0
41b04ea14bSJohn Tsichritzis	isb
42b04ea14bSJohn Tsichritzis1:
43b04ea14bSJohn Tsichritzis	ret	x17
44da6d75a0SJohn Tsichritzisendfunc errata_n1_1043202_wa
45b04ea14bSJohn Tsichritzis
46b04ea14bSJohn Tsichritzisfunc check_errata_1043202
47b04ea14bSJohn Tsichritzis	/* Applies to r0p0 and r1p0 */
48b04ea14bSJohn Tsichritzis	mov	x1, #0x10
49b04ea14bSJohn Tsichritzis	b	cpu_rev_var_ls
50b04ea14bSJohn Tsichritzisendfunc check_errata_1043202
51b04ea14bSJohn Tsichritzis
52da6d75a0SJohn Tsichritzisfunc neoverse_n1_reset_func
53b04ea14bSJohn Tsichritzis	mov	x19, x30
548074448fSJohn Tsichritzis
558074448fSJohn Tsichritzis	/* Disables speculative loads */
568074448fSJohn Tsichritzis	msr	SSBS, xzr
578074448fSJohn Tsichritzis
58632ab3ebSLouis Mayencourt	/* Forces all cacheable atomic instructions to be near */
59632ab3ebSLouis Mayencourt	mrs	x0, NEOVERSE_N1_CPUACTLR2_EL1
60632ab3ebSLouis Mayencourt	orr	x0, x0, #NEOVERSE_N1_CPUACTLR2_EL1_BIT_2
61632ab3ebSLouis Mayencourt	msr	NEOVERSE_N1_CPUACTLR2_EL1, x0
62632ab3ebSLouis Mayencourt	isb
63632ab3ebSLouis Mayencourt
64b04ea14bSJohn Tsichritzis	bl	cpu_get_rev_var
65b04ea14bSJohn Tsichritzis	mov	x18, x0
66b04ea14bSJohn Tsichritzis
67da6d75a0SJohn Tsichritzis#if ERRATA_N1_1043202
68b04ea14bSJohn Tsichritzis	mov	x0, x18
69da6d75a0SJohn Tsichritzis	bl	errata_n1_1043202_wa
70b04ea14bSJohn Tsichritzis#endif
71b04ea14bSJohn Tsichritzis
72b04ea14bSJohn Tsichritzis#if ENABLE_AMU
73b04ea14bSJohn Tsichritzis	/* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */
74b04ea14bSJohn Tsichritzis	mrs	x0, actlr_el3
75da6d75a0SJohn Tsichritzis	orr	x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT
76b04ea14bSJohn Tsichritzis	msr	actlr_el3, x0
77b04ea14bSJohn Tsichritzis	isb
78b04ea14bSJohn Tsichritzis
79b04ea14bSJohn Tsichritzis	/* Make sure accesses from EL0/EL1 are not trapped to EL2 */
80b04ea14bSJohn Tsichritzis	mrs	x0, actlr_el2
81da6d75a0SJohn Tsichritzis	orr	x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT
82b04ea14bSJohn Tsichritzis	msr	actlr_el2, x0
83b04ea14bSJohn Tsichritzis	isb
84b04ea14bSJohn Tsichritzis
85b04ea14bSJohn Tsichritzis	/* Enable group0 counters */
86da6d75a0SJohn Tsichritzis	mov	x0, #NEOVERSE_N1_AMU_GROUP0_MASK
87b04ea14bSJohn Tsichritzis	msr	CPUAMCNTENSET_EL0, x0
88b04ea14bSJohn Tsichritzis	isb
89b04ea14bSJohn Tsichritzis#endif
90b04ea14bSJohn Tsichritzis	ret	x19
91da6d75a0SJohn Tsichritzisendfunc neoverse_n1_reset_func
92b04ea14bSJohn Tsichritzis
93b04ea14bSJohn Tsichritzis	/* ---------------------------------------------
94b04ea14bSJohn Tsichritzis	 * HW will do the cache maintenance while powering down
95b04ea14bSJohn Tsichritzis	 * ---------------------------------------------
96b04ea14bSJohn Tsichritzis	 */
97da6d75a0SJohn Tsichritzisfunc neoverse_n1_core_pwr_dwn
98b04ea14bSJohn Tsichritzis	/* ---------------------------------------------
99b04ea14bSJohn Tsichritzis	 * Enable CPU power down bit in power control register
100b04ea14bSJohn Tsichritzis	 * ---------------------------------------------
101b04ea14bSJohn Tsichritzis	 */
102da6d75a0SJohn Tsichritzis	mrs	x0, NEOVERSE_N1_CPUPWRCTLR_EL1
103da6d75a0SJohn Tsichritzis	orr	x0, x0, #NEOVERSE_N1_CORE_PWRDN_EN_MASK
104da6d75a0SJohn Tsichritzis	msr	NEOVERSE_N1_CPUPWRCTLR_EL1, x0
105b04ea14bSJohn Tsichritzis	isb
106b04ea14bSJohn Tsichritzis	ret
107da6d75a0SJohn Tsichritzisendfunc neoverse_n1_core_pwr_dwn
108b04ea14bSJohn Tsichritzis
109b04ea14bSJohn Tsichritzis#if REPORT_ERRATA
110b04ea14bSJohn Tsichritzis/*
111da6d75a0SJohn Tsichritzis * Errata printing function for Neoverse N1. Must follow AAPCS.
112b04ea14bSJohn Tsichritzis */
113da6d75a0SJohn Tsichritzisfunc neoverse_n1_errata_report
114b04ea14bSJohn Tsichritzis	stp	x8, x30, [sp, #-16]!
115b04ea14bSJohn Tsichritzis
116b04ea14bSJohn Tsichritzis	bl	cpu_get_rev_var
117b04ea14bSJohn Tsichritzis	mov	x8, x0
118b04ea14bSJohn Tsichritzis
119b04ea14bSJohn Tsichritzis	/*
120b04ea14bSJohn Tsichritzis	 * Report all errata. The revision-variant information is passed to
121b04ea14bSJohn Tsichritzis	 * checking functions of each errata.
122b04ea14bSJohn Tsichritzis	 */
123da6d75a0SJohn Tsichritzis	report_errata ERRATA_N1_1043202, neoverse_n1, 1043202
124b04ea14bSJohn Tsichritzis
125b04ea14bSJohn Tsichritzis	ldp	x8, x30, [sp], #16
126b04ea14bSJohn Tsichritzis	ret
127da6d75a0SJohn Tsichritzisendfunc neoverse_n1_errata_report
128b04ea14bSJohn Tsichritzis#endif
129b04ea14bSJohn Tsichritzis
130b04ea14bSJohn Tsichritzis	/* ---------------------------------------------
131da6d75a0SJohn Tsichritzis	 * This function provides neoverse_n1 specific
132b04ea14bSJohn Tsichritzis	 * register information for crash reporting.
133b04ea14bSJohn Tsichritzis	 * It needs to return with x6 pointing to
134b04ea14bSJohn Tsichritzis	 * a list of register names in ascii and
135b04ea14bSJohn Tsichritzis	 * x8 - x15 having values of registers to be
136b04ea14bSJohn Tsichritzis	 * reported.
137b04ea14bSJohn Tsichritzis	 * ---------------------------------------------
138b04ea14bSJohn Tsichritzis	 */
139da6d75a0SJohn Tsichritzis.section .rodata.neoverse_n1_regs, "aS"
140da6d75a0SJohn Tsichritzisneoverse_n1_regs:  /* The ascii list of register names to be reported */
141b04ea14bSJohn Tsichritzis	.asciz	"cpuectlr_el1", ""
142b04ea14bSJohn Tsichritzis
143da6d75a0SJohn Tsichritzisfunc neoverse_n1_cpu_reg_dump
144da6d75a0SJohn Tsichritzis	adr	x6, neoverse_n1_regs
145da6d75a0SJohn Tsichritzis	mrs	x8, NEOVERSE_N1_CPUECTLR_EL1
146b04ea14bSJohn Tsichritzis	ret
147da6d75a0SJohn Tsichritzisendfunc neoverse_n1_cpu_reg_dump
148b04ea14bSJohn Tsichritzis
149da6d75a0SJohn Tsichritzisdeclare_cpu_ops neoverse_n1, NEOVERSE_N1_MIDR, \
150da6d75a0SJohn Tsichritzis	neoverse_n1_reset_func, \
151da6d75a0SJohn Tsichritzis	neoverse_n1_core_pwr_dwn
152