2 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
7 #include <platform_def.h>
10 #include <lib/psci/psci.h>
11 #include <plat/common/platform.h>
13 #pragma weak plat_core_pos_by_mpidr
15 /*******************************************************************************
16 * This function implements a part of the critical interface between the psci
17 * generic layer and the platform that allows the former to query the platform
18 * to convert an MPIDR to a unique linear index. An error code (-1) is returned
19 * in case the MPIDR is invalid.
20 ******************************************************************************/
21 int32_t plat_core_pos_by_mpidr(u_register_t mpidr
)
23 u_register_t cluster_id
, cpu_id
;
26 cluster_id
= (mpidr
>> (u_register_t
)MPIDR_AFF1_SHIFT
) &
27 (u_register_t
)MPIDR_AFFLVL_MASK
;
28 cpu_id
= (mpidr
>> (u_register_t
)MPIDR_AFF0_SHIFT
) &
29 (u_register_t
)MPIDR_AFFLVL_MASK
;
31 /* CorePos = CoreId + (ClusterId * cpus per cluster) */
32 result
= (int32_t)cpu_id
+ ((int32_t)cluster_id
*
33 PLATFORM_MAX_CPUS_PER_CLUSTER
);
35 if (cluster_id
>= (u_register_t
)PLATFORM_CLUSTER_COUNT
) {
36 result
= PSCI_E_NOT_PRESENT
;
40 * Validate cpu_id by checking whether it represents a CPU in
41 * one of the two clusters present on the platform.
43 if (cpu_id
>= (u_register_t
)PLATFORM_MAX_CPUS_PER_CLUSTER
) {
44 result
= PSCI_E_NOT_PRESENT
;