blob: c6d12dade4e9bf5eb77187388aefcfbf404a1e45 [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);
Soby Mathewfec4eb72015-07-01 16:16:20 +010032 cluster_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;
33 cpu_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK;
Summer Qin93c812f2017-02-28 16:46:17 +000034#endif /* ARM_PLAT_MT */
35
36 mpidr &= MPIDR_AFFINITY_MASK;
37 if (mpidr & valid_mask)
38 return -1;
Soby Mathewfec4eb72015-07-01 16:16:20 +010039
Soby Mathew47e43f22016-02-01 14:04:34 +000040 if (cluster_id >= PLAT_ARM_CLUSTER_COUNT)
Soby Mathewfec4eb72015-07-01 16:16:20 +010041 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. */
Soby Mathew47e43f22016-02-01 14:04:34 +000045 if (cpu_id >= plat_arm_get_cluster_core_count(mpidr))
Soby Mathewfec4eb72015-07-01 16:16:20 +010046 return -1;
47
Summer Qin93c812f2017-02-28 16:46:17 +000048#if ARM_PLAT_MT
49 if (pe_id >= plat_arm_get_cpu_pe_count(mpidr))
50 return -1;
51#endif /* ARM_PLAT_MT */
52
Soby Mathewfec4eb72015-07-01 16:16:20 +010053 return 0;
Dan Handley9df48042015-03-19 18:58:55 +000054}