tegra_topology.c 1.34 KB
Newer Older
1
/*
2
 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
7
 */

#include <platform_def.h>
8
9

#include <arch.h>
10
#include <platform.h>
11
#include <lib/psci/psci.h>
12

13
#pragma weak plat_core_pos_by_mpidr
14

15
16
/*******************************************************************************
 * This function implements a part of the critical interface between the psci
17
18
19
 * generic layer and the platform that allows the former to query the platform
 * to convert an MPIDR to a unique linear index. An error code (-1) is returned
 * in case the MPIDR is invalid.
20
 ******************************************************************************/
21
int32_t plat_core_pos_by_mpidr(u_register_t mpidr)
22
{
23
	u_register_t cluster_id, cpu_id;
24
	int32_t result;
25
26
27

	cluster_id = (mpidr >> (u_register_t)MPIDR_AFF1_SHIFT) & (u_register_t)MPIDR_AFFLVL_MASK;
	cpu_id = (mpidr >> (u_register_t)MPIDR_AFF0_SHIFT) & (u_register_t)MPIDR_AFFLVL_MASK;
28

29
	result = (int32_t)cpu_id + ((int32_t)cluster_id * 4);
30

31
32
33
	if (cluster_id >= (u_register_t)PLATFORM_CLUSTER_COUNT) {
		result = PSCI_E_NOT_PRESENT;
	}
34
35
36
37
38

	/*
	 * Validate cpu_id by checking whether it represents a CPU in
	 * one of the two clusters present on the platform.
	 */
39
40
41
	if (cpu_id >= (u_register_t)PLATFORM_MAX_CPUS_PER_CLUSTER) {
		result = PSCI_E_NOT_PRESENT;
	}
42

43
	return result;
44
}