xref: /rk3399_ARM-atf/plat/rpi/common/rpi3_topology.c (revision 4f2b984852556afc3543d90150c46be4aaadbc75)
1*4f2b9848SAndre Przywara /*
2*4f2b9848SAndre Przywara  * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
3*4f2b9848SAndre Przywara  *
4*4f2b9848SAndre Przywara  * SPDX-License-Identifier: BSD-3-Clause
5*4f2b9848SAndre Przywara  */
6*4f2b9848SAndre Przywara 
7*4f2b9848SAndre Przywara #include <stdint.h>
8*4f2b9848SAndre Przywara 
9*4f2b9848SAndre Przywara #include <platform_def.h>
10*4f2b9848SAndre Przywara 
11*4f2b9848SAndre Przywara #include <arch.h>
12*4f2b9848SAndre Przywara 
13*4f2b9848SAndre Przywara #include <rpi_shared.h>
14*4f2b9848SAndre Przywara 
15*4f2b9848SAndre Przywara /* The power domain tree descriptor */
16*4f2b9848SAndre Przywara static unsigned char power_domain_tree_desc[] = {
17*4f2b9848SAndre Przywara 	/* Number of root nodes */
18*4f2b9848SAndre Przywara 	PLATFORM_CLUSTER_COUNT,
19*4f2b9848SAndre Przywara 	/* Number of children for the first node */
20*4f2b9848SAndre Przywara 	PLATFORM_CLUSTER0_CORE_COUNT,
21*4f2b9848SAndre Przywara };
22*4f2b9848SAndre Przywara 
23*4f2b9848SAndre Przywara /*******************************************************************************
24*4f2b9848SAndre Przywara  * This function returns the ARM default topology tree information.
25*4f2b9848SAndre Przywara  ******************************************************************************/
26*4f2b9848SAndre Przywara const unsigned char *plat_get_power_domain_tree_desc(void)
27*4f2b9848SAndre Przywara {
28*4f2b9848SAndre Przywara 	return power_domain_tree_desc;
29*4f2b9848SAndre Przywara }
30*4f2b9848SAndre Przywara 
31*4f2b9848SAndre Przywara /*******************************************************************************
32*4f2b9848SAndre Przywara  * This function implements a part of the critical interface between the psci
33*4f2b9848SAndre Przywara  * generic layer and the platform that allows the former to query the platform
34*4f2b9848SAndre Przywara  * to convert an MPIDR to a unique linear index. An error code (-1) is returned
35*4f2b9848SAndre Przywara  * in case the MPIDR is invalid.
36*4f2b9848SAndre Przywara  ******************************************************************************/
37*4f2b9848SAndre Przywara int plat_core_pos_by_mpidr(u_register_t mpidr)
38*4f2b9848SAndre Przywara {
39*4f2b9848SAndre Przywara 	unsigned int cluster_id, cpu_id;
40*4f2b9848SAndre Przywara 
41*4f2b9848SAndre Przywara 	mpidr &= MPIDR_AFFINITY_MASK;
42*4f2b9848SAndre Przywara 	if (mpidr & ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)) {
43*4f2b9848SAndre Przywara 		return -1;
44*4f2b9848SAndre Przywara 	}
45*4f2b9848SAndre Przywara 
46*4f2b9848SAndre Przywara 	cluster_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;
47*4f2b9848SAndre Przywara 	cpu_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK;
48*4f2b9848SAndre Przywara 
49*4f2b9848SAndre Przywara 	if (cluster_id >= PLATFORM_CLUSTER_COUNT) {
50*4f2b9848SAndre Przywara 		return -1;
51*4f2b9848SAndre Przywara 	}
52*4f2b9848SAndre Przywara 
53*4f2b9848SAndre Przywara 	if (cpu_id >= PLATFORM_MAX_CPUS_PER_CLUSTER) {
54*4f2b9848SAndre Przywara 		return -1;
55*4f2b9848SAndre Przywara 	}
56*4f2b9848SAndre Przywara 
57*4f2b9848SAndre Przywara 	return plat_rpi3_calc_core_pos(mpidr);
58*4f2b9848SAndre Przywara }
59