ls_helpers.S 4.21 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 * Copyright 2018-2021 NXP
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *
 */

#include <asm_macros.S>
#include <drivers/console.h>
#include <lib/cpus/aarch64/cortex_a72.h>

#include <platform_def.h>


	.globl	plat_crash_console_init
	.globl	plat_crash_console_putc
	.globl	plat_crash_console_flush
	.globl  plat_core_pos
	.globl  plat_my_core_pos
	.globl  plat_core_mask
	.globl  plat_my_core_mask
	.globl  plat_core_pos_by_mpidr
	.globl _disable_ldstr_pfetch_A53
	.globl _disable_ldstr_pfetch_A72
	.global	_set_smmu_pagesz_64

	/* int plat_crash_console_init(void)
	 * Function to initialize the crash console
	 * without a C Runtime to print crash report.
	 * Clobber list : x0 - x4
	 */

	/* int plat_crash_console_init(void)
	 * Use normal console by default. Switch it to crash
	 * mode so serial consoles become active again.
	 * NOTE: This default implementation will only work for
	 * crashes that occur after a normal console (marked
	 * valid for the crash state) has been registered with
	 * the console framework. To debug crashes that occur
	 * earlier, the platform has to override these functions
	 * with an implementation that initializes a console
	 * driver with hardcoded parameters. See
	 * docs/porting-guide.rst for more information.
	 */
func plat_crash_console_init
	mov	x3, x30
	mov	x0, #CONSOLE_FLAG_CRASH
	bl	console_switch_state
	mov	x0, #1
	ret	x3
endfunc plat_crash_console_init

	/* void plat_crash_console_putc(int character)
	 * Output through the normal console by default.
	 */
func plat_crash_console_putc
	b	console_putc
endfunc plat_crash_console_putc

	/* void plat_crash_console_flush(void)
	 * Flush normal console by default.
	 */
func plat_crash_console_flush
	b	console_flush
endfunc plat_crash_console_flush

/* This function implements a part of the critical interface between the psci
 * generic layer and the platform that allows the former to query the platform
 * to convert an MPIDR to a unique linear index. An error code (-1) is returned
 * in case the MPIDR is invalid.
 */
func plat_core_pos_by_mpidr

	b	plat_core_pos

endfunc plat_core_pos_by_mpidr

#if (SYMMETRICAL_CLUSTERS)
/* unsigned int plat_my_core_mask(void)
 *  generate a mask bit for this core
 */
func plat_my_core_mask
	mrs	x0, MPIDR_EL1
	b	plat_core_mask
endfunc plat_my_core_mask

/* unsigned int plat_core_mask(u_register_t mpidr)
 * generate a lsb-based mask bit for the core specified by mpidr in x0.
 *
 * SoC core = ((cluster * cpu_per_cluster) + core)
 * mask = (1 << SoC core)
 */
func plat_core_mask
	mov	w1, wzr
	mov	w2, wzr

	/* extract cluster */
	bfxil	w1, w0, #8, #8
	/* extract cpu # */
	bfxil	w2, w0, #0, #8

	mov	w0, wzr

	/* error checking */
	cmp	w1, #NUMBER_OF_CLUSTERS
	b.ge	1f
	cmp	w2, #CORES_PER_CLUSTER
	b.ge	1f

	mov	w0, #CORES_PER_CLUSTER
	mul	w1, w1, w0
	add	w1, w1, w2
	mov	w2, #0x1
	lsl	w0, w2, w1
1:
	ret
endfunc plat_core_mask

/*
 * unsigned int plat_my_core_pos(void)
 *  generate a linear core number for this core
 */
func plat_my_core_pos
	mrs	x0, MPIDR_EL1
	b	plat_core_pos
endfunc plat_my_core_pos

/*
 * unsigned int plat_core_pos(u_register_t mpidr)
 * Generate a linear core number for the core specified by mpidr.
 *
 * SoC core = ((cluster * cpu_per_cluster) + core)
 * Returns -1 if mpidr invalid
 */
func plat_core_pos
	mov	w1, wzr
	mov	w2, wzr
	bfxil	w1, w0, #8, #8	/* extract cluster */
	bfxil	w2, w0, #0, #8	/* extract cpu #   */

	mov	w0, #-1

	/* error checking */
	cmp	w1, #NUMBER_OF_CLUSTERS
	b.ge	1f
	cmp	w2, #CORES_PER_CLUSTER
	b.ge	1f

	mov	w0, #CORES_PER_CLUSTER
	mul	w1, w1, w0
	add	w0, w1, w2
1:
	ret
endfunc plat_core_pos

#endif

/* this function disables the load-store prefetch of the calling core
 * Note: this function is for A72 cores ONLY
 * in:  none
 * out: none
 * uses x0
 */
func _disable_ldstr_pfetch_A72

	mrs	x0, CORTEX_A72_CPUACTLR_EL1
	tst	x0, #CORTEX_A72_CPUACTLR_EL1_DISABLE_L1_DCACHE_HW_PFTCH
	b.eq	1f
	b	2f

.align 6
1:
	dsb	sy
	isb
	orr	x0, x0, #CORTEX_A72_CPUACTLR_EL1_DISABLE_L1_DCACHE_HW_PFTCH
	msr	CORTEX_A72_CPUACTLR_EL1, x0
	isb

2:
	ret
endfunc _disable_ldstr_pfetch_A72

/*
 * Function sets the SACR pagesize to 64k
 */
func _set_smmu_pagesz_64

	ldr	x1, =NXP_SMMU_ADDR
	ldr	w0, [x1, #0x10]
	orr	w0, w0, #1 << 16	/* setting to 64K page */
	str	w0, [x1, #0x10]

	ret
endfunc _set_smmu_pagesz_64