1b4315306SDan Handley /* 2d8d6cf24SSummer Qin * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. 3b4315306SDan Handley * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 5b4315306SDan Handley */ 6b4315306SDan Handley 7b4315306SDan Handley #include <arch.h> 838dce70fSSoby Mathew #include <plat_arm.h> 9b4315306SDan Handley #include <platform_def.h> 10b4315306SDan Handley 1138dce70fSSoby Mathew /******************************************************************************* 1238dce70fSSoby Mathew * This function validates an MPIDR by checking whether it falls within the 1338dce70fSSoby Mathew * acceptable bounds. An error code (-1) is returned if an incorrect mpidr 1438dce70fSSoby Mathew * is passed. 1538dce70fSSoby Mathew ******************************************************************************/ 1638dce70fSSoby Mathew int arm_check_mpidr(u_register_t mpidr) 17b4315306SDan Handley { 1838dce70fSSoby Mathew unsigned int cluster_id, cpu_id; 19d8d6cf24SSummer Qin uint64_t valid_mask; 20b4315306SDan Handley 21d8d6cf24SSummer Qin #if ARM_PLAT_MT 22d8d6cf24SSummer Qin unsigned int pe_id; 2338dce70fSSoby Mathew 24d8d6cf24SSummer Qin valid_mask = ~(MPIDR_AFFLVL_MASK | 25d8d6cf24SSummer Qin (MPIDR_AFFLVL_MASK << MPIDR_AFF1_SHIFT) | 26d8d6cf24SSummer Qin (MPIDR_AFFLVL_MASK << MPIDR_AFF2_SHIFT)); 27d8d6cf24SSummer Qin cluster_id = (mpidr >> MPIDR_AFF2_SHIFT) & MPIDR_AFFLVL_MASK; 28d8d6cf24SSummer Qin cpu_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK; 29d8d6cf24SSummer Qin pe_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK; 30d8d6cf24SSummer Qin #else 31d8d6cf24SSummer Qin valid_mask = ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK); 32*89509904SSathees Balya cluster_id = (unsigned int) ((mpidr >> MPIDR_AFF1_SHIFT) & 33*89509904SSathees Balya MPIDR_AFFLVL_MASK); 34*89509904SSathees Balya cpu_id = (unsigned int) ((mpidr >> MPIDR_AFF0_SHIFT) & 35*89509904SSathees Balya MPIDR_AFFLVL_MASK); 36d8d6cf24SSummer Qin #endif /* ARM_PLAT_MT */ 37d8d6cf24SSummer Qin 38d8d6cf24SSummer Qin mpidr &= MPIDR_AFFINITY_MASK; 39*89509904SSathees Balya if ((mpidr & valid_mask) != 0U) 40d8d6cf24SSummer Qin return -1; 4138dce70fSSoby Mathew 420108047aSSoby Mathew if (cluster_id >= PLAT_ARM_CLUSTER_COUNT) 4338dce70fSSoby Mathew return -1; 4438dce70fSSoby Mathew 4538dce70fSSoby Mathew /* Validate cpu_id by checking whether it represents a CPU in 4638dce70fSSoby Mathew one of the two clusters present on the platform. */ 470108047aSSoby Mathew if (cpu_id >= plat_arm_get_cluster_core_count(mpidr)) 4838dce70fSSoby Mathew return -1; 4938dce70fSSoby Mathew 50d8d6cf24SSummer Qin #if ARM_PLAT_MT 51d8d6cf24SSummer Qin if (pe_id >= plat_arm_get_cpu_pe_count(mpidr)) 52d8d6cf24SSummer Qin return -1; 53d8d6cf24SSummer Qin #endif /* ARM_PLAT_MT */ 54d8d6cf24SSummer Qin 5538dce70fSSoby Mathew return 0; 56b4315306SDan Handley } 57