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