xref: /aosp_15_r20/external/arm-trusted-firmware/plat/layerscape/common/ls_topology.c (revision 54fd6939e177f8ff529b10183254802c76df6d08)
1*54fd6939SJiyong Park /*
2*54fd6939SJiyong Park  * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3*54fd6939SJiyong Park  *
4*54fd6939SJiyong Park  * SPDX-License-Identifier: BSD-3-Clause
5*54fd6939SJiyong Park  */
6*54fd6939SJiyong Park 
7*54fd6939SJiyong Park #include "plat_ls.h"
8*54fd6939SJiyong Park 
9*54fd6939SJiyong Park /*******************************************************************************
10*54fd6939SJiyong Park  * This function validates an MPIDR by checking whether it falls within the
11*54fd6939SJiyong Park  * acceptable bounds. An error code (-1) is returned if an incorrect mpidr
12*54fd6939SJiyong Park  * is passed.
13*54fd6939SJiyong Park  ******************************************************************************/
ls_check_mpidr(u_register_t mpidr)14*54fd6939SJiyong Park int ls_check_mpidr(u_register_t mpidr)
15*54fd6939SJiyong Park {
16*54fd6939SJiyong Park 	unsigned int cluster_id, cpu_id;
17*54fd6939SJiyong Park 	uint64_t valid_mask;
18*54fd6939SJiyong Park 
19*54fd6939SJiyong Park 	valid_mask = ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK);
20*54fd6939SJiyong Park 	cluster_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;
21*54fd6939SJiyong Park 	cpu_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK;
22*54fd6939SJiyong Park 
23*54fd6939SJiyong Park 	mpidr &= MPIDR_AFFINITY_MASK;
24*54fd6939SJiyong Park 	if (mpidr & valid_mask)
25*54fd6939SJiyong Park 		return -1;
26*54fd6939SJiyong Park 
27*54fd6939SJiyong Park 	if (cluster_id >= PLAT_LS_CLUSTER_COUNT)
28*54fd6939SJiyong Park 		return -1;
29*54fd6939SJiyong Park 
30*54fd6939SJiyong Park 	/*
31*54fd6939SJiyong Park 	 * Validate cpu_id by checking whether it represents a CPU in
32*54fd6939SJiyong Park 	 * one of the two clusters present on the platform.
33*54fd6939SJiyong Park 	 */
34*54fd6939SJiyong Park 	if (cpu_id >= plat_ls_get_cluster_core_count(mpidr))
35*54fd6939SJiyong Park 		return -1;
36*54fd6939SJiyong Park 
37*54fd6939SJiyong Park 
38*54fd6939SJiyong Park 	return 0;
39*54fd6939SJiyong Park }
40