blob: b0ad4d1c6a0f81cd238c820b78ff640ab5a4f840 [file] [log] [blame]
Dan Handley9df48042015-03-19 18:58:55 +00001/*
Summer Qin93c812f2017-02-28 16:46:17 +00002 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
Dan Handley9df48042015-03-19 18:58:55 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handley9df48042015-03-19 18:58:55 +00005 */
6
7#include <arch.h>
Soby Mathewfec4eb72015-07-01 16:16:20 +01008#include <plat_arm.h>
Dan Handley9df48042015-03-19 18:58:55 +00009#include <platform_def.h>
10
Soby Mathewfec4eb72015-07-01 16:16:20 +010011/*******************************************************************************
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 ******************************************************************************/
16int arm_check_mpidr(u_register_t mpidr)
Dan Handley9df48042015-03-19 18:58:55 +000017{
Soby Mathewfec4eb72015-07-01 16:16:20 +010018 unsigned int cluster_id, cpu_id;
Summer Qin93c812f2017-02-28 16:46:17 +000019 uint64_t valid_mask;
Soby Mathewfec4eb72015-07-01 16:16:20 +010020
Summer Qin93c812f2017-02-28 16:46:17 +000021#if ARM_PLAT_MT
22 unsigned int pe_id;
Soby Mathewfec4eb72015-07-01 16:16:20 +010023
Summer Qin93c812f2017-02-28 16:46:17 +000024 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);
Sathees Balya30952cc2018-09-27 14:41:02 +010032 cluster_id = (unsigned int) ((mpidr >> MPIDR_AFF1_SHIFT) &
33 MPIDR_AFFLVL_MASK);
34 cpu_id = (unsigned int) ((mpidr >> MPIDR_AFF0_SHIFT) &
35 MPIDR_AFFLVL_MASK);
Summer Qin93c812f2017-02-28 16:46:17 +000036#endif /* ARM_PLAT_MT */
37
38 mpidr &= MPIDR_AFFINITY_MASK;
Sathees Balya30952cc2018-09-27 14:41:02 +010039 if ((mpidr & valid_mask) != 0U)
Summer Qin93c812f2017-02-28 16:46:17 +000040 return -1;
Soby Mathewfec4eb72015-07-01 16:16:20 +010041
Soby Mathew47e43f22016-02-01 14:04:34 +000042 if (cluster_id >= PLAT_ARM_CLUSTER_COUNT)
Soby Mathewfec4eb72015-07-01 16:16:20 +010043 return -1;
44
45 /* Validate cpu_id by checking whether it represents a CPU in
46 one of the two clusters present on the platform. */
Soby Mathew47e43f22016-02-01 14:04:34 +000047 if (cpu_id >= plat_arm_get_cluster_core_count(mpidr))
Soby Mathewfec4eb72015-07-01 16:16:20 +010048 return -1;
49
Summer Qin93c812f2017-02-28 16:46:17 +000050#if ARM_PLAT_MT
51 if (pe_id >= plat_arm_get_cpu_pe_count(mpidr))
52 return -1;
53#endif /* ARM_PLAT_MT */
54
Soby Mathewfec4eb72015-07-01 16:16:20 +010055 return 0;
Dan Handley9df48042015-03-19 18:58:55 +000056}