Merge tag 'devicetree-for-5.16' of git://git.kernel.org/pub/scm/linux/kernel/git...
[platform/kernel/linux-starfive.git] / drivers / of / base.c
index 0ac1725..61de453 100644 (file)
@@ -287,6 +287,28 @@ const void *of_get_property(const struct device_node *np, const char *name,
 }
 EXPORT_SYMBOL(of_get_property);
 
+/**
+ * of_get_cpu_hwid - Get the hardware ID from a CPU device node
+ *
+ * @cpun: CPU number(logical index) for which device node is required
+ * @thread: The local thread number to get the hardware ID for.
+ *
+ * Return: The hardware ID for the CPU node or ~0ULL if not found.
+ */
+u64 of_get_cpu_hwid(struct device_node *cpun, unsigned int thread)
+{
+       const __be32 *cell;
+       int ac, len;
+
+       ac = of_n_addr_cells(cpun);
+       cell = of_get_property(cpun, "reg", &len);
+       if (!cell || !ac || ((sizeof(*cell) * ac * (thread + 1)) > len))
+               return ~0ULL;
+
+       cell += ac * thread;
+       return of_read_number(cell, ac);
+}
+
 /*
  * arch_match_cpu_phys_id - Match the given logical CPU and physical id
  *