xref: /rk3399_ARM-atf/plat/xilinx/versal_net/plat_topology.c (revision 522c175d2d03470de4073a4e5716851073d2bf22)
1 /*
2  * Copyright (c) 2018, Arm Limited and Contributors. All rights reserved.
3  * Copyright (c) 2018-2022, Xilinx, Inc. All rights reserved.
4  * Copyright (c) 2022, Advanced Micro Devices, Inc. All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include <common/debug.h>
10 #include <plat/common/platform.h>
11 
12 #include <plat_private.h>
13 #include <platform_def.h>
14 
15 static const uint8_t plat_power_domain_tree_desc[] = {
16 	/* Number of root nodes */
17 	1,
18 	/* Number of clusters */
19 	PLATFORM_CLUSTER_COUNT,
20 	/* Number of children for the first cluster node */
21 	PLATFORM_CORE_COUNT_PER_CLUSTER,
22 	/* Number of children for the second cluster node */
23 	PLATFORM_CORE_COUNT_PER_CLUSTER,
24 	/* Number of children for the third cluster node */
25 	PLATFORM_CORE_COUNT_PER_CLUSTER,
26 	/* Number of children for the fourth cluster node */
27 	PLATFORM_CORE_COUNT_PER_CLUSTER,
28 };
29 
30 const uint8_t *plat_get_power_domain_tree_desc(void)
31 {
32 	return plat_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  ******************************************************************************/
41 int32_t plat_core_pos_by_mpidr(u_register_t mpidr)
42 {
43 	uint32_t cluster_id, cpu_id;
44 	int32_t ret;
45 
46 	mpidr &= MPIDR_AFFINITY_MASK;
47 
48 	cluster_id = (uint32_t)MPIDR_AFFLVL2_VAL(mpidr);
49 	cpu_id = (uint32_t)MPIDR_AFFLVL1_VAL(mpidr);
50 
51 	if (cluster_id >= PLATFORM_CLUSTER_COUNT) {
52 		ret = E_INVALID_CLUSTER_COUNT;
53 		goto exit_label;
54 	}
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 		ret = E_INVALID_CORE_COUNT;
62 	} else {
63 		ret = (int32_t)(cpu_id + (cluster_id * PLATFORM_CORE_COUNT_PER_CLUSTER));
64 	}
65 
66 exit_label:
67 	return ret;
68 }
69