Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of: Add of_get_cpu_hwid() to read hardware ID from CPU nodes

There are various open coded implementions parsing the CPU node 'reg'
property which contains the CPU's hardware ID. Introduce a new function,
of_get_cpu_hwid(), to read the hardware ID.

All the callers should be DT only code, so no need for an empty
function.

Cc: Frank Rowand <frowand.list@gmail.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Tested-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Link: https://lore.kernel.org/r/20211006164332.1981454-2-robh@kernel.org

+23
+22
drivers/of/base.c
··· 286 286 } 287 287 EXPORT_SYMBOL(of_get_property); 288 288 289 + /** 290 + * of_get_cpu_hwid - Get the hardware ID from a CPU device node 291 + * 292 + * @cpun: CPU number(logical index) for which device node is required 293 + * @thread: The local thread number to get the hardware ID for. 294 + * 295 + * Return: The hardware ID for the CPU node or ~0ULL if not found. 296 + */ 297 + u64 of_get_cpu_hwid(struct device_node *cpun, unsigned int thread) 298 + { 299 + const __be32 *cell; 300 + int ac, len; 301 + 302 + ac = of_n_addr_cells(cpun); 303 + cell = of_get_property(cpun, "reg", &len); 304 + if (!cell || !ac || ((sizeof(*cell) * ac * (thread + 1)) > len)) 305 + return ~0ULL; 306 + 307 + cell += ac * thread; 308 + return of_read_number(cell, ac); 309 + } 310 + 289 311 /* 290 312 * arch_match_cpu_phys_id - Match the given logical CPU and physical id 291 313 *
+1
include/linux/of.h
··· 353 353 extern struct device_node *of_get_next_cpu_node(struct device_node *prev); 354 354 extern struct device_node *of_get_cpu_state_node(struct device_node *cpu_node, 355 355 int index); 356 + extern u64 of_get_cpu_hwid(struct device_node *cpun, unsigned int thread); 356 357 357 358 #define for_each_property_of_node(dn, pp) \ 358 359 for (pp = dn->properties; pp != NULL; pp = pp->next)