xref: /rk3399_ARM-atf/plat/arm/board/tc/include/tc_helpers.S (revision ad8b51418e3c9e19ddc957424ab19386711ba7ee)
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#define TC_HANDLER(rev)         plat_reset_handler_tc##rev
13#define PLAT_RESET_HANDLER(rev) TC_HANDLER(rev)
14
15	.globl	plat_arm_calc_core_pos
16	.globl	plat_reset_handler
17
18	/* ---------------------------------------------------------------------
19	 * unsigned int plat_arm_calc_core_pos(u_register_t mpidr)
20	 *
21	 * Function to calculate the core position on TC.
22	 *
23	 * (ClusterId * PLAT_MAX_CPUS_PER_CLUSTER * PLAT_MAX_PE_PER_CPU) +
24	 * (CPUId * PLAT_MAX_PE_PER_CPU) +
25	 * ThreadId
26	 *
27	 * which can be simplified as:
28	 *
29	 * ((ClusterId * PLAT_MAX_CPUS_PER_CLUSTER + CPUId) * PLAT_MAX_PE_PER_CPU)
30	 * + ThreadId
31	 * ---------------------------------------------------------------------
32	 */
33func plat_arm_calc_core_pos
34	/*
35	 * Check for MT bit in MPIDR. If not set, shift MPIDR to left to make it
36	 * look as if in a multi-threaded implementation.
37	 */
38	tst	x0, #MPIDR_MT_MASK
39	lsl	x3, x0, #MPIDR_AFFINITY_BITS
40	csel	x3, x3, x0, eq
41
42	/* Extract individual affinity fields from MPIDR */
43	ubfx	x0, x3, #MPIDR_AFF0_SHIFT, #MPIDR_AFFINITY_BITS
44	ubfx	x1, x3, #MPIDR_AFF1_SHIFT, #MPIDR_AFFINITY_BITS
45	ubfx	x2, x3, #MPIDR_AFF2_SHIFT, #MPIDR_AFFINITY_BITS
46
47	/* Compute linear position */
48	mov	x4, #PLAT_MAX_CPUS_PER_CLUSTER
49	madd	x1, x2, x4, x1
50	mov	x5, #PLAT_MAX_PE_PER_CPU
51	madd	x0, x1, x5, x0
52	ret
53endfunc plat_arm_calc_core_pos
54
55func enable_dsu_pmu_el1_access
56	sysreg_bit_set actlr_el2, CPUACTLR_CLUSTERPMUEN
57	sysreg_bit_set actlr_el3, CPUACTLR_CLUSTERPMUEN
58	ret
59endfunc enable_dsu_pmu_el1_access
60
61func TC_HANDLER(2)
62	ret
63endfunc TC_HANDLER(2)
64
65func TC_HANDLER(3)
66	mov	x9, lr
67	bl	enable_dsu_pmu_el1_access
68	mov	lr, x9
69	ret
70endfunc TC_HANDLER(3)
71
72	/* -----------------------------------------------------
73	 * void plat_reset_handler(void);
74	 * -----------------------------------------------------
75	 */
76func plat_reset_handler
77	mov	x8, lr
78	bl	PLAT_RESET_HANDLER(TARGET_PLATFORM)
79	mov	lr, x8
80	ret
81endfunc plat_reset_handler
82