xref: /rk3399_ARM-atf/lib/cpus/aarch64/neoverse_n1.S (revision eca6e45336d81d924948bcff2f3db8488252f17b)
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
13076b5f02SJohn Tsichritzis/* Hardware handled coherency */
14076b5f02SJohn Tsichritzis#if HW_ASSISTED_COHERENCY == 0
15076b5f02SJohn Tsichritzis#error "Neoverse N1 must be compiled with HW_ASSISTED_COHERENCY enabled"
16076b5f02SJohn Tsichritzis#endif
17076b5f02SJohn 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
52*eca6e453SSami Mujawar/* --------------------------------------------------
53*eca6e453SSami Mujawar * Disable speculative loads if Neoverse N1 supports
54*eca6e453SSami Mujawar * SSBS.
55*eca6e453SSami Mujawar *
56*eca6e453SSami Mujawar * Shall clobber: x0.
57*eca6e453SSami Mujawar * --------------------------------------------------
58*eca6e453SSami Mujawar */
59*eca6e453SSami Mujawarfunc neoverse_n1_disable_speculative_loads
60*eca6e453SSami Mujawar	/* Check if the PE implements SSBS */
61*eca6e453SSami Mujawar	mrs	x0, id_aa64pfr1_el1
62*eca6e453SSami Mujawar	tst	x0, #(ID_AA64PFR1_EL1_SSBS_MASK << ID_AA64PFR1_EL1_SSBS_SHIFT)
63*eca6e453SSami Mujawar	b.eq	1f
64*eca6e453SSami Mujawar
65*eca6e453SSami Mujawar	/* Disable speculative loads */
66*eca6e453SSami Mujawar	msr	SSBS, xzr
67*eca6e453SSami Mujawar	isb
68*eca6e453SSami Mujawar
69*eca6e453SSami Mujawar1:
70*eca6e453SSami Mujawar	ret
71*eca6e453SSami Mujawarendfunc neoverse_n1_disable_speculative_loads
72*eca6e453SSami Mujawar
73da6d75a0SJohn Tsichritzisfunc neoverse_n1_reset_func
74b04ea14bSJohn Tsichritzis	mov	x19, x30
758074448fSJohn Tsichritzis
76*eca6e453SSami Mujawar	bl neoverse_n1_disable_speculative_loads
778074448fSJohn Tsichritzis
78632ab3ebSLouis Mayencourt	/* Forces all cacheable atomic instructions to be near */
79632ab3ebSLouis Mayencourt	mrs	x0, NEOVERSE_N1_CPUACTLR2_EL1
80632ab3ebSLouis Mayencourt	orr	x0, x0, #NEOVERSE_N1_CPUACTLR2_EL1_BIT_2
81632ab3ebSLouis Mayencourt	msr	NEOVERSE_N1_CPUACTLR2_EL1, x0
82632ab3ebSLouis Mayencourt	isb
83632ab3ebSLouis Mayencourt
84b04ea14bSJohn Tsichritzis	bl	cpu_get_rev_var
85b04ea14bSJohn Tsichritzis	mov	x18, x0
86b04ea14bSJohn Tsichritzis
87da6d75a0SJohn Tsichritzis#if ERRATA_N1_1043202
88b04ea14bSJohn Tsichritzis	mov	x0, x18
89da6d75a0SJohn Tsichritzis	bl	errata_n1_1043202_wa
90b04ea14bSJohn Tsichritzis#endif
91b04ea14bSJohn Tsichritzis
92b04ea14bSJohn Tsichritzis#if ENABLE_AMU
93b04ea14bSJohn Tsichritzis	/* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */
94b04ea14bSJohn Tsichritzis	mrs	x0, actlr_el3
95da6d75a0SJohn Tsichritzis	orr	x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT
96b04ea14bSJohn Tsichritzis	msr	actlr_el3, x0
97b04ea14bSJohn Tsichritzis	isb
98b04ea14bSJohn Tsichritzis
99b04ea14bSJohn Tsichritzis	/* Make sure accesses from EL0/EL1 are not trapped to EL2 */
100b04ea14bSJohn Tsichritzis	mrs	x0, actlr_el2
101da6d75a0SJohn Tsichritzis	orr	x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT
102b04ea14bSJohn Tsichritzis	msr	actlr_el2, x0
103b04ea14bSJohn Tsichritzis	isb
104b04ea14bSJohn Tsichritzis
105b04ea14bSJohn Tsichritzis	/* Enable group0 counters */
106da6d75a0SJohn Tsichritzis	mov	x0, #NEOVERSE_N1_AMU_GROUP0_MASK
107b04ea14bSJohn Tsichritzis	msr	CPUAMCNTENSET_EL0, x0
108b04ea14bSJohn Tsichritzis	isb
109b04ea14bSJohn Tsichritzis#endif
110b04ea14bSJohn Tsichritzis	ret	x19
111da6d75a0SJohn Tsichritzisendfunc neoverse_n1_reset_func
112b04ea14bSJohn Tsichritzis
113b04ea14bSJohn Tsichritzis	/* ---------------------------------------------
114b04ea14bSJohn Tsichritzis	 * HW will do the cache maintenance while powering down
115b04ea14bSJohn Tsichritzis	 * ---------------------------------------------
116b04ea14bSJohn Tsichritzis	 */
117da6d75a0SJohn Tsichritzisfunc neoverse_n1_core_pwr_dwn
118b04ea14bSJohn Tsichritzis	/* ---------------------------------------------
119b04ea14bSJohn Tsichritzis	 * Enable CPU power down bit in power control register
120b04ea14bSJohn Tsichritzis	 * ---------------------------------------------
121b04ea14bSJohn Tsichritzis	 */
122da6d75a0SJohn Tsichritzis	mrs	x0, NEOVERSE_N1_CPUPWRCTLR_EL1
123da6d75a0SJohn Tsichritzis	orr	x0, x0, #NEOVERSE_N1_CORE_PWRDN_EN_MASK
124da6d75a0SJohn Tsichritzis	msr	NEOVERSE_N1_CPUPWRCTLR_EL1, x0
125b04ea14bSJohn Tsichritzis	isb
126b04ea14bSJohn Tsichritzis	ret
127da6d75a0SJohn Tsichritzisendfunc neoverse_n1_core_pwr_dwn
128b04ea14bSJohn Tsichritzis
129b04ea14bSJohn Tsichritzis#if REPORT_ERRATA
130b04ea14bSJohn Tsichritzis/*
131da6d75a0SJohn Tsichritzis * Errata printing function for Neoverse N1. Must follow AAPCS.
132b04ea14bSJohn Tsichritzis */
133da6d75a0SJohn Tsichritzisfunc neoverse_n1_errata_report
134b04ea14bSJohn Tsichritzis	stp	x8, x30, [sp, #-16]!
135b04ea14bSJohn Tsichritzis
136b04ea14bSJohn Tsichritzis	bl	cpu_get_rev_var
137b04ea14bSJohn Tsichritzis	mov	x8, x0
138b04ea14bSJohn Tsichritzis
139b04ea14bSJohn Tsichritzis	/*
140b04ea14bSJohn Tsichritzis	 * Report all errata. The revision-variant information is passed to
141b04ea14bSJohn Tsichritzis	 * checking functions of each errata.
142b04ea14bSJohn Tsichritzis	 */
143da6d75a0SJohn Tsichritzis	report_errata ERRATA_N1_1043202, neoverse_n1, 1043202
144b04ea14bSJohn Tsichritzis
145b04ea14bSJohn Tsichritzis	ldp	x8, x30, [sp], #16
146b04ea14bSJohn Tsichritzis	ret
147da6d75a0SJohn Tsichritzisendfunc neoverse_n1_errata_report
148b04ea14bSJohn Tsichritzis#endif
149b04ea14bSJohn Tsichritzis
150b04ea14bSJohn Tsichritzis	/* ---------------------------------------------
151da6d75a0SJohn Tsichritzis	 * This function provides neoverse_n1 specific
152b04ea14bSJohn Tsichritzis	 * register information for crash reporting.
153b04ea14bSJohn Tsichritzis	 * It needs to return with x6 pointing to
154b04ea14bSJohn Tsichritzis	 * a list of register names in ascii and
155b04ea14bSJohn Tsichritzis	 * x8 - x15 having values of registers to be
156b04ea14bSJohn Tsichritzis	 * reported.
157b04ea14bSJohn Tsichritzis	 * ---------------------------------------------
158b04ea14bSJohn Tsichritzis	 */
159da6d75a0SJohn Tsichritzis.section .rodata.neoverse_n1_regs, "aS"
160da6d75a0SJohn Tsichritzisneoverse_n1_regs:  /* The ascii list of register names to be reported */
161b04ea14bSJohn Tsichritzis	.asciz	"cpuectlr_el1", ""
162b04ea14bSJohn Tsichritzis
163da6d75a0SJohn Tsichritzisfunc neoverse_n1_cpu_reg_dump
164da6d75a0SJohn Tsichritzis	adr	x6, neoverse_n1_regs
165da6d75a0SJohn Tsichritzis	mrs	x8, NEOVERSE_N1_CPUECTLR_EL1
166b04ea14bSJohn Tsichritzis	ret
167da6d75a0SJohn Tsichritzisendfunc neoverse_n1_cpu_reg_dump
168b04ea14bSJohn Tsichritzis
169da6d75a0SJohn Tsichritzisdeclare_cpu_ops neoverse_n1, NEOVERSE_N1_MIDR, \
170da6d75a0SJohn Tsichritzis	neoverse_n1_reset_func, \
171da6d75a0SJohn Tsichritzis	neoverse_n1_core_pwr_dwn
172