xref: /rk3399_ARM-atf/plat/arm/board/fvp/fvp_topology.c (revision 09d40e0e08283a249e7dce0e106c07c5141f9b7e)
13fc4124cSDan Handley /*
21af540efSRoberto Vargas  * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
33fc4124cSDan Handley  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
53fc4124cSDan Handley  */
63fc4124cSDan Handley 
73fc4124cSDan Handley #include <platform_def.h>
8*09d40e0eSAntonio Nino Diaz 
9*09d40e0eSAntonio Nino Diaz #include <arch.h>
10*09d40e0eSAntonio Nino Diaz #include <lib/cassert.h>
11*09d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
12*09d40e0eSAntonio Nino Diaz 
13*09d40e0eSAntonio Nino Diaz #include <plat_arm.h>
14*09d40e0eSAntonio Nino Diaz #include <arm_config.h>
153fc4124cSDan Handley #include "drivers/pwrc/fvp_pwrc.h"
163fc4124cSDan Handley 
170108047aSSoby Mathew /* The FVP power domain tree descriptor */
181af540efSRoberto Vargas static unsigned char fvp_power_domain_tree_desc[FVP_CLUSTER_COUNT + 2];
190108047aSSoby Mathew 
200108047aSSoby Mathew 
2189509904SSathees Balya CASSERT(((FVP_CLUSTER_COUNT > 0) && (FVP_CLUSTER_COUNT <= 256)),
2289509904SSathees Balya 			assert_invalid_fvp_cluster_count);
230108047aSSoby Mathew 
240108047aSSoby Mathew /*******************************************************************************
250108047aSSoby Mathew  * This function dynamically constructs the topology according to
260108047aSSoby Mathew  * FVP_CLUSTER_COUNT and returns it.
270108047aSSoby Mathew  ******************************************************************************/
280108047aSSoby Mathew const unsigned char *plat_get_power_domain_tree_desc(void)
290108047aSSoby Mathew {
3089509904SSathees Balya 	int i;
310108047aSSoby Mathew 
3238dce70fSSoby Mathew 	/*
33e35a3fb5SSoby Mathew 	 * The highest level is the system level. The next level is constituted
34e35a3fb5SSoby Mathew 	 * by clusters and then cores in clusters.
3538dce70fSSoby Mathew 	 */
36e35a3fb5SSoby Mathew 	fvp_power_domain_tree_desc[0] = 1;
37e35a3fb5SSoby Mathew 	fvp_power_domain_tree_desc[1] = FVP_CLUSTER_COUNT;
383fc4124cSDan Handley 
390108047aSSoby Mathew 	for (i = 0; i < FVP_CLUSTER_COUNT; i++)
40e35a3fb5SSoby Mathew 		fvp_power_domain_tree_desc[i + 2] = FVP_MAX_CPUS_PER_CLUSTER;
41e35a3fb5SSoby Mathew 
420108047aSSoby Mathew 
430108047aSSoby Mathew 	return fvp_power_domain_tree_desc;
440108047aSSoby Mathew }
450108047aSSoby Mathew 
460108047aSSoby Mathew /*******************************************************************************
470108047aSSoby Mathew  * This function returns the core count within the cluster corresponding to
480108047aSSoby Mathew  * `mpidr`.
490108047aSSoby Mathew  ******************************************************************************/
500108047aSSoby Mathew unsigned int plat_arm_get_cluster_core_count(u_register_t mpidr)
510108047aSSoby Mathew {
520108047aSSoby Mathew 	return FVP_MAX_CPUS_PER_CLUSTER;
530108047aSSoby Mathew }
543fc4124cSDan Handley 
553fc4124cSDan Handley /*******************************************************************************
563fc4124cSDan Handley  * This function implements a part of the critical interface between the psci
5738dce70fSSoby Mathew  * generic layer and the platform that allows the former to query the platform
5838dce70fSSoby Mathew  * to convert an MPIDR to a unique linear index. An error code (-1) is returned
5938dce70fSSoby Mathew  * in case the MPIDR is invalid.
603fc4124cSDan Handley  ******************************************************************************/
6138dce70fSSoby Mathew int plat_core_pos_by_mpidr(u_register_t mpidr)
623fc4124cSDan Handley {
63955242d8SJeenu Viswambharan 	unsigned int clus_id, cpu_id, thread_id;
64955242d8SJeenu Viswambharan 
65955242d8SJeenu Viswambharan 	/* Validate affinity fields */
6689509904SSathees Balya 	if ((arm_config.flags & ARM_CONFIG_FVP_SHIFTED_AFF) != 0U) {
67955242d8SJeenu Viswambharan 		thread_id = MPIDR_AFFLVL0_VAL(mpidr);
68955242d8SJeenu Viswambharan 		cpu_id = MPIDR_AFFLVL1_VAL(mpidr);
69955242d8SJeenu Viswambharan 		clus_id = MPIDR_AFFLVL2_VAL(mpidr);
70955242d8SJeenu Viswambharan 	} else {
71955242d8SJeenu Viswambharan 		thread_id = 0;
72955242d8SJeenu Viswambharan 		cpu_id = MPIDR_AFFLVL0_VAL(mpidr);
73955242d8SJeenu Viswambharan 		clus_id = MPIDR_AFFLVL1_VAL(mpidr);
74955242d8SJeenu Viswambharan 	}
75955242d8SJeenu Viswambharan 
76955242d8SJeenu Viswambharan 	if (clus_id >= FVP_CLUSTER_COUNT)
77955242d8SJeenu Viswambharan 		return -1;
78955242d8SJeenu Viswambharan 	if (cpu_id >= FVP_MAX_CPUS_PER_CLUSTER)
79955242d8SJeenu Viswambharan 		return -1;
80955242d8SJeenu Viswambharan 	if (thread_id >= FVP_MAX_PE_PER_CPU)
81955242d8SJeenu Viswambharan 		return -1;
82955242d8SJeenu Viswambharan 
8338dce70fSSoby Mathew 	if (fvp_pwrc_read_psysr(mpidr) == PSYSR_INVALID)
8438dce70fSSoby Mathew 		return -1;
853fc4124cSDan Handley 
8611ad8f20SJeenu Viswambharan 	/*
8711ad8f20SJeenu Viswambharan 	 * Core position calculation for FVP platform depends on the MT bit in
8811ad8f20SJeenu Viswambharan 	 * MPIDR. This function cannot assume that the supplied MPIDR has the MT
8911ad8f20SJeenu Viswambharan 	 * bit set even if the implementation has. For example, PSCI clients
9011ad8f20SJeenu Viswambharan 	 * might supply MPIDR values without the MT bit set. Therefore, we
9111ad8f20SJeenu Viswambharan 	 * inject the current PE's MT bit so as to get the calculation correct.
9211ad8f20SJeenu Viswambharan 	 * This of course assumes that none or all CPUs on the platform has MT
9311ad8f20SJeenu Viswambharan 	 * bit set.
9411ad8f20SJeenu Viswambharan 	 */
9511ad8f20SJeenu Viswambharan 	mpidr |= (read_mpidr_el1() & MPIDR_MT_MASK);
9689509904SSathees Balya 	return (int) plat_arm_calc_core_pos(mpidr);
973fc4124cSDan Handley }
98