• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 hikey960_power_domain_tree_desc[] = {
17 	/* Number of root nodes */
18 	1,
19 	/* Number of clusters */
20 	PLATFORM_CLUSTER_COUNT,
21 	/* Number of children for the first cluster node */
22 	PLATFORM_CORE_COUNT_PER_CLUSTER,
23 	/* Number of children for the second cluster node */
24 	PLATFORM_CORE_COUNT_PER_CLUSTER,
25 };
26 
27 /*******************************************************************************
28  * This function returns the HiKey topology tree information.
29  ******************************************************************************/
plat_get_power_domain_tree_desc(void)30 const unsigned char *plat_get_power_domain_tree_desc(void)
31 {
32 	return hikey960_power_domain_tree_desc;
33 }
34 
35 /*******************************************************************************
36  * This function implements a part of the critical interface between the psci
37  * generic layer and the platform that allows the former to query the platform
38  * to convert an MPIDR to a unique linear index. An error code (-1) is returned
39  * in case the MPIDR is invalid.
40  ******************************************************************************/
plat_core_pos_by_mpidr(u_register_t mpidr)41 int plat_core_pos_by_mpidr(u_register_t mpidr)
42 {
43 	unsigned int cluster_id, cpu_id;
44 
45 	mpidr &= MPIDR_AFFINITY_MASK;
46 
47 	if (mpidr & ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK))
48 		return -1;
49 
50 	cluster_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;
51 	cpu_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK;
52 
53 	if (cluster_id >= PLATFORM_CLUSTER_COUNT)
54 		return -1;
55 
56 	/*
57 	 * Validate cpu_id by checking whether it represents a CPU in
58 	 * one of the two clusters present on the platform.
59 	 */
60 	if (cpu_id >= PLATFORM_CORE_COUNT_PER_CLUSTER)
61 		return -1;
62 
63 	return (cpu_id + (cluster_id * 4));
64 }
65