1 /* 2 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <arch.h> 8 #include <plat_arm.h> 9 #include <platform_def.h> 10 11 /******************************************************************************* 12 * This function validates an MPIDR by checking whether it falls within the 13 * acceptable bounds. An error code (-1) is returned if an incorrect mpidr 14 * is passed. 15 ******************************************************************************/ arm_check_mpidr(u_register_t mpidr)16int arm_check_mpidr(u_register_t mpidr) 17 { 18 unsigned int cluster_id, cpu_id; 19 uint64_t valid_mask; 20 21 #if ARM_PLAT_MT 22 unsigned int pe_id; 23 24 valid_mask = ~(MPIDR_AFFLVL_MASK | 25 (MPIDR_AFFLVL_MASK << MPIDR_AFF1_SHIFT) | 26 (MPIDR_AFFLVL_MASK << MPIDR_AFF2_SHIFT)); 27 cluster_id = (mpidr >> MPIDR_AFF2_SHIFT) & MPIDR_AFFLVL_MASK; 28 cpu_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK; 29 pe_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK; 30 #else 31 valid_mask = ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK); 32 cluster_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK; 33 cpu_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK; 34 #endif /* ARM_PLAT_MT */ 35 36 mpidr &= MPIDR_AFFINITY_MASK; 37 if (mpidr & valid_mask) 38 return -1; 39 40 if (cluster_id >= PLAT_ARM_CLUSTER_COUNT) 41 return -1; 42 43 /* Validate cpu_id by checking whether it represents a CPU in 44 one of the two clusters present on the platform. */ 45 if (cpu_id >= plat_arm_get_cluster_core_count(mpidr)) 46 return -1; 47 48 #if ARM_PLAT_MT 49 if (pe_id >= plat_arm_get_cpu_pe_count(mpidr)) 50 return -1; 51 #endif /* ARM_PLAT_MT */ 52 53 return 0; 54 } 55