xref: /rk3399_ARM-atf/plat/hisilicon/hikey/hikey_topology.c (revision 1001202d24db95b4b812abee62ebeb9351710c1e)
1 /*
2  * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 #include <arch.h>
7 #include <platform_def.h>
8 #include <psci.h>
9 
10 /*
11  * The HiKey power domain tree descriptor. The cluster power domains
12  * are arranged so that when the PSCI generic code creates the power
13  * domain tree, the indices of the CPU power domain nodes it allocates
14  * match the linear indices returned by plat_core_pos_by_mpidr().
15  */
16 const unsigned char hikey_power_domain_tree_desc[] = {
17 	/* Number of root nodes */
18 	1,
19 	/* Number of clusters */
20 	PLATFORM_CLUSTER_COUNT,
21 	/* Number of CPU cores */
22 	PLATFORM_CORE_COUNT
23 };
24 
25 /*******************************************************************************
26  * This function returns the HiKey topology tree information.
27  ******************************************************************************/
28 const unsigned char *plat_get_power_domain_tree_desc(void)
29 {
30 	return hikey_power_domain_tree_desc;
31 }
32 
33 /*******************************************************************************
34  * This function implements a part of the critical interface between the psci
35  * generic layer and the platform that allows the former to query the platform
36  * to convert an MPIDR to a unique linear index. An error code (-1) is returned
37  * in case the MPIDR is invalid.
38  ******************************************************************************/
39 int plat_core_pos_by_mpidr(u_register_t mpidr)
40 {
41 	unsigned int cluster_id, cpu_id;
42 
43 	mpidr &= MPIDR_AFFINITY_MASK;
44 
45 	if (mpidr & ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK))
46 		return -1;
47 
48 	cluster_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;
49 	cpu_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK;
50 
51 	if (cluster_id >= PLATFORM_CLUSTER_COUNT)
52 		return -1;
53 
54 	/*
55 	 * Validate cpu_id by checking whether it represents a CPU in
56 	 * one of the two clusters present on the platform.
57 	 */
58 	if (cpu_id >= PLATFORM_CORE_COUNT_PER_CLUSTER)
59 		return -1;
60 
61 	return (cpu_id + (cluster_id * 4));
62 }
63