blob: f2d963d8283bda17791c1e2a7704ef15583c8ac9 [file] [log] [blame]
Usama Arifbec5afd2020-04-17 16:13:39 +01001/*
Jagdish Gediya4df2d372024-04-22 13:30:51 +00002 * Copyright (c) 2024, ARM Limited and Contributors. All rights reserved.
Usama Arifbec5afd2020-04-17 16:13:39 +01003 *
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
Jagdish Gediya71d2d2b2024-07-17 15:34:28 +010012#define TC_HANDLER(rev) plat_reset_handler_tc##rev
13#define PLAT_RESET_HANDLER(rev) TC_HANDLER(rev)
14
Usama Arifbec5afd2020-04-17 16:13:39 +010015 .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 *
Usama Ariff1513622021-04-09 17:07:41 +010021 * Function to calculate the core position on TC.
Usama Arifbec5afd2020-04-17 16:13:39 +010022 *
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
Jagdish Gediya71d2d2b2024-07-17 15:34:28 +010055func 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
Usama Arifbec5afd2020-04-17 16:13:39 +010072 /* -----------------------------------------------------
73 * void plat_reset_handler(void);
Usama Arifbec5afd2020-04-17 16:13:39 +010074 * -----------------------------------------------------
75 */
76func plat_reset_handler
Jagdish Gediya71d2d2b2024-07-17 15:34:28 +010077 mov x8, lr
78 bl PLAT_RESET_HANDLER(TARGET_PLATFORM)
79 mov lr, x8
Usama Arifbec5afd2020-04-17 16:13:39 +010080 ret
81endfunc plat_reset_handler