xref: /rk3399_ARM-atf/plat/arm/board/tc/include/tc_helpers.S (revision d235708c0e449ba31dbd7fb0356155d3c8d17480)
1/*
2 * Copyright (c) 2024, 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 <platform_def.h>
10#include <cpu_macros.S>
11
12#include <cortex_gelas.h>
13
14#define TC_HANDLER(rev)         plat_reset_handler_tc##rev
15#define PLAT_RESET_HANDLER(rev) TC_HANDLER(rev)
16
17	.globl	plat_arm_calc_core_pos
18	.globl	plat_reset_handler
19
20	/* ---------------------------------------------------------------------
21	 * unsigned int plat_arm_calc_core_pos(u_register_t mpidr)
22	 *
23	 * Function to calculate the core position on TC.
24	 *
25	 * (ClusterId * PLAT_MAX_CPUS_PER_CLUSTER * PLAT_MAX_PE_PER_CPU) +
26	 * (CPUId * PLAT_MAX_PE_PER_CPU) +
27	 * ThreadId
28	 *
29	 * which can be simplified as:
30	 *
31	 * ((ClusterId * PLAT_MAX_CPUS_PER_CLUSTER + CPUId) * PLAT_MAX_PE_PER_CPU)
32	 * + ThreadId
33	 * ---------------------------------------------------------------------
34	 */
35func plat_arm_calc_core_pos
36	/*
37	 * Check for MT bit in MPIDR. If not set, shift MPIDR to left to make it
38	 * look as if in a multi-threaded implementation.
39	 */
40	tst	x0, #MPIDR_MT_MASK
41	lsl	x3, x0, #MPIDR_AFFINITY_BITS
42	csel	x3, x3, x0, eq
43
44	/* Extract individual affinity fields from MPIDR */
45	ubfx	x0, x3, #MPIDR_AFF0_SHIFT, #MPIDR_AFFINITY_BITS
46	ubfx	x1, x3, #MPIDR_AFF1_SHIFT, #MPIDR_AFFINITY_BITS
47	ubfx	x2, x3, #MPIDR_AFF2_SHIFT, #MPIDR_AFFINITY_BITS
48
49	/* Compute linear position */
50	mov	x4, #PLAT_MAX_CPUS_PER_CLUSTER
51	madd	x1, x2, x4, x1
52	mov	x5, #PLAT_MAX_PE_PER_CPU
53	madd	x0, x1, x5, x0
54	ret
55endfunc plat_arm_calc_core_pos
56
57func mark_extllc_presence
58#ifdef MCN_CONFIG_ADDR
59	mov_imm	x0, (MCN_CONFIG_ADDR(0))
60	ldr	w1, [x0]
61	ubfx	x1, x1, #MCN_CONFIG_SLC_PRESENT_BIT, #1
62	jump_if_cpu_midr CORTEX_GELAS_MIDR, GELAS
63	sysreg_bitfield_insert_from_gpr CPUECTLR_EL1, x1, CPUECTLR_EL1_EXTLLC_BIT, 1
64	ret
65GELAS:
66	sysreg_bitfield_insert_from_gpr CORTEX_GELAS_IMP_CPUECTLR_EL1, x1, CPUECTLR2_EL1_EXTLLC_BIT, 1
67#endif
68	ret
69endfunc mark_extllc_presence
70
71func enable_dsu_pmu_el1_access
72	sysreg_bit_set actlr_el2, CPUACTLR_CLUSTERPMUEN
73	sysreg_bit_set actlr_el3, CPUACTLR_CLUSTERPMUEN
74	ret
75endfunc enable_dsu_pmu_el1_access
76
77func TC_HANDLER(2)
78	ret
79endfunc TC_HANDLER(2)
80
81func TC_HANDLER(3)
82	mov	x9, lr
83	bl	mark_extllc_presence
84	bl	enable_dsu_pmu_el1_access
85	mov	lr, x9
86	ret
87endfunc TC_HANDLER(3)
88
89func TC_HANDLER(4)
90	mov	x9, lr
91	bl	mark_extllc_presence
92	bl	enable_dsu_pmu_el1_access
93	mov	lr, x9
94	ret
95endfunc TC_HANDLER(4)
96
97	/* -----------------------------------------------------
98	 * void plat_reset_handler(void);
99	 * -----------------------------------------------------
100	 */
101func plat_reset_handler
102	mov	x8, lr
103	bl	PLAT_RESET_HANDLER(TARGET_PLATFORM)
104	mov	lr, x8
105	ret
106endfunc plat_reset_handler
107