1414 * Returns the hart ID of the given device tree node, or -ENODEV if the node
1515 * isn't an enabled and valid RISC-V hart node.
1616 */
17- int riscv_of_processor_hartid (struct device_node * node )
17+ int riscv_of_processor_hartid (struct device_node * node , unsigned long * hart )
1818{
1919 const char * isa ;
20- u32 hart ;
2120
2221 if (!of_device_is_compatible (node , "riscv" )) {
2322 pr_warn ("Found incompatible CPU\n" );
2423 return - ENODEV ;
2524 }
2625
27- hart = of_get_cpu_hwid (node , 0 );
28- if (hart == ~0U ) {
26+ * hart = ( unsigned long ) of_get_cpu_hwid (node , 0 );
27+ if (* hart == ~0UL ) {
2928 pr_warn ("Found CPU without hart ID\n" );
3029 return - ENODEV ;
3130 }
3231
3332 if (!of_device_is_available (node )) {
34- pr_info ("CPU with hartid=%d is not available\n" , hart );
33+ pr_info ("CPU with hartid=%lu is not available\n" , * hart );
3534 return - ENODEV ;
3635 }
3736
3837 if (of_property_read_string (node , "riscv,isa" , & isa )) {
39- pr_warn ("CPU with hartid=%d has no \"riscv,isa\" property\n" , hart );
38+ pr_warn ("CPU with hartid=%lu has no \"riscv,isa\" property\n" , * hart );
4039 return - ENODEV ;
4140 }
4241 if (isa [0 ] != 'r' || isa [1 ] != 'v' ) {
43- pr_warn ("CPU with hartid=%d has an invalid ISA of \"%s\"\n" , hart , isa );
42+ pr_warn ("CPU with hartid=%lu has an invalid ISA of \"%s\"\n" , * hart , isa );
4443 return - ENODEV ;
4544 }
4645
47- return hart ;
46+ return 0 ;
4847}
4948
5049/*
@@ -53,11 +52,16 @@ int riscv_of_processor_hartid(struct device_node *node)
5352 * To achieve this, we walk up the DT tree until we find an active
5453 * RISC-V core (HART) node and extract the cpuid from it.
5554 */
56- int riscv_of_parent_hartid (struct device_node * node )
55+ int riscv_of_parent_hartid (struct device_node * node , unsigned long * hartid )
5756{
57+ int rc ;
58+
5859 for (; node ; node = node -> parent ) {
59- if (of_device_is_compatible (node , "riscv" ))
60- return riscv_of_processor_hartid (node );
60+ if (of_device_is_compatible (node , "riscv" )) {
61+ rc = riscv_of_processor_hartid (node , hartid );
62+ if (!rc )
63+ return 0 ;
64+ }
6165 }
6266
6367 return -1 ;
0 commit comments