Add topology helper to get parent node
It was not possible to get a parent node given an MPIDR
of the CPU using the current topology APIs. This patch adds
the `tftf_get_parent_node_from_mpidr()` API to achieve the same.
Change-Id: I818f1e628689928293c1fdb85606885e851a5785
Signed-off-by: Soby Mathew <soby.mathew@arm.com>
diff --git a/include/plat/common/plat_topology.h b/include/plat/common/plat_topology.h
index 0da0b5e..0ca5eff 100644
--- a/include/plat/common/plat_topology.h
+++ b/include/plat/common/plat_topology.h
@@ -161,6 +161,16 @@
*/
unsigned int tftf_get_mpidr_from_node(unsigned int cpu_node);
+
+/*
+ * Returns the index corresponding to the parent power domain at `pwrlvl` of the
+ * CPU specified by `mpidr`. Returns POWER_DOMAIN_INIT if any of input arguments
+ * are incorrect.
+ */
+unsigned int tftf_get_parent_node_from_mpidr(unsigned int mpidr,
+ unsigned int pwrlvl);
+
+
/*
* Query the platform topology to find another CPU than the one specified
* as an argument.
diff --git a/plat/common/plat_topology.c b/plat/common/plat_topology.c
index a7920c3..01e3461 100644
--- a/plat/common/plat_topology.c
+++ b/plat/common/plat_topology.c
@@ -317,6 +317,24 @@
return PWR_DOMAIN_INIT;
}
+unsigned int tftf_get_parent_node_from_mpidr(unsigned int mpidr, unsigned int pwrlvl)
+{
+ unsigned int core_pos = platform_get_core_pos(mpidr);
+ unsigned int node, i;
+
+ if (core_pos >= PLATFORM_CORE_COUNT)
+ return PWR_DOMAIN_INIT;
+
+ if (pwrlvl > PLAT_MAX_PWR_LEVEL)
+ return PWR_DOMAIN_INIT;
+
+ node = tftf_pwr_domain_start_idx[0] + core_pos;
+
+ for (i = 1; i <= pwrlvl; i++)
+ node = tftf_pd_nodes[node].parent_node;
+
+ return node;
+}
unsigned int tftf_get_mpidr_from_node(unsigned int cpu_node)
{