xref: /rk3399_ARM-atf/plat/arm/board/automotive_rd/platform/rdaspen/include/rdaspen_helpers.S (revision 8e94c57811fc2e3d74dea6cc05909b1aecaec21c)
1/*
2 * Copyright (c) 2025, Arm Limited. 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
11	.global plat_arm_calc_core_pos
12	.global plat_report_exception
13	.global plat_my_core_pos
14	.global plat_is_my_cpu_primary
15
16	/* ---------------------------------------------------------------------
17	 * unsigned int plat_arm_calc_core_pos(u_register_t mpidr)
18	 *
19	 * Function to calculate the core position.
20	 *
21	 * (ClusterId * PLAT_MAX_CPUS_PER_CLUSTER * PLAT_MAX_PE_PER_CPU) +
22	 * (CPUId * PLAT_MAX_PE_PER_CPU) + ThreadId
23	 *
24	 * which can be simplified as:
25	 *
26	 * ((ClusterId * PLAT_MAX_CPUS_PER_CLUSTER + CPUId) * PLAT_MAX_PE_PER_CPU)
27	 * + ThreadId
28	 * ---------------------------------------------------------------------
29	 */
30func plat_arm_calc_core_pos
31	/*
32	 * Check for MT bit in MPIDR. If not set, shift MPIDR to left to make it
33	 * look as if in a multi-threaded implementation.
34	 */
35	tst	x0, #MPIDR_MT_MASK
36	lsl	x3, x0, #MPIDR_AFFINITY_BITS
37	csel	x3, x3, x0, eq
38
39	/* Extract individual affinity fields from MPIDR */
40	ubfx	x0, x3, #MPIDR_AFF0_SHIFT, #MPIDR_AFFINITY_BITS
41	ubfx	x1, x3, #MPIDR_AFF1_SHIFT, #MPIDR_AFFINITY_BITS
42	ubfx	x2, x3, #MPIDR_AFF2_SHIFT, #MPIDR_AFFINITY_BITS
43
44	/* Compute linear position */
45	mov	x4, #PLAT_MAX_CPUS_PER_CLUSTER
46	madd	x1, x2, x4, x1
47	mov	x4, #PLAT_MAX_PE_PER_CPU
48	madd	x0, x1, x4, x0
49	ret
50endfunc plat_arm_calc_core_pos
51
52func plat_report_exception
53	ret
54endfunc plat_report_exception
55
56	/* ---------------------------------------------------------------------
57	 * unsigned int plat_my_core_pos(void)
58	 * This function uses the plat_arm_calc_core_pos()
59	 * definition to get the index of the calling CPU.
60	 * ---------------------------------------------------------------------
61	 */
62func plat_my_core_pos
63	mrs	x0, mpidr_el1
64	b	plat_arm_calc_core_pos
65endfunc plat_my_core_pos
66
67	/* ---------------------------------------------------------------------
68	 * unsigned int plat_is_my_cpu_primary (void);
69	 *
70	 * Find out whether the current cpu is the primary cpu
71	 * ---------------------------------------------------------------------
72	 */
73#if CSS_USE_SCMI_SDS_DRIVER
74func plat_is_my_cpu_primary
75	mov	x9, x30
76	bl	plat_my_core_pos
77	cmp	x0, #RDASPEN_PRIMARY_CPU
78	cset	w0, eq
79	ret	x9
80endfunc plat_is_my_cpu_primary
81#endif
82