Merge tag 'devicetree-for-4.16' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / drivers / of / base.c
index dd0b4201f1cc0f9020c9353700e9b127716799be..ad28de96e13f5a411ff51ad4a0b4f71e13f89938 100644 (file)
@@ -311,6 +311,32 @@ struct device_node *of_get_cpu_node(int cpu, unsigned int *thread)
 }
 EXPORT_SYMBOL(of_get_cpu_node);
 
+/**
+ * of_cpu_node_to_id: Get the logical CPU number for a given device_node
+ *
+ * @cpu_node: Pointer to the device_node for CPU.
+ *
+ * Returns the logical CPU number of the given CPU device_node.
+ * Returns -ENODEV if the CPU is not found.
+ */
+int of_cpu_node_to_id(struct device_node *cpu_node)
+{
+       int cpu;
+       bool found = false;
+       struct device_node *np;
+
+       for_each_possible_cpu(cpu) {
+               np = of_cpu_device_node_get(cpu);
+               found = (cpu_node == np);
+               of_node_put(np);
+               if (found)
+                       return cpu;
+       }
+
+       return -ENODEV;
+}
+EXPORT_SYMBOL(of_cpu_node_to_id);
+
 /**
  * __of_device_is_compatible() - Check if the node matches given constraints
  * @device: pointer to node