Skip to content

Commit 2ac8743

Browse files
ConchuODpalmer-dabbelt
authored andcommitted
RISC-V: split early & late of_node to hartid mapping
Some back and forth with Drew [1] about riscv_fill_hwcap() resulted in the realisation that it is not very useful to parse the DT & perform validation of riscv,isa every time we would like to get the id for a hart. Although it is no longer called in riscv_fill_hwcap(), riscv_of_processor_hartid() is called in several other places. Notably in setup_smp() it forms part of the logic for filling the mask of possible CPUs. Since a possible CPU must have passed this basic validation of riscv,isa, a repeat validation is not required. Rename riscv_of_processor_id() to riscv_early_of_processor_id(), which will be called from setup_smp() & introduce a new riscv_of_processor_id() which makes use of the pre-populated mask of possible cpus. Link: https://lore.kernel.org/linux-riscv/xvdswl3iyikwvamny7ikrxo2ncuixshtg3f6uucjahpe3xpc5c@ud4cz4fkg5dj/ [1] Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Conor Dooley <[email protected]> Reviewed-by: Sunil V L <[email protected]> Link: https://lore.kernel.org/r/20230607-glade-pastel-d8cbd9d9f3c6@spud Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent fed14be commit 2ac8743

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

arch/riscv/include/asm/processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static inline void wait_for_interrupt(void)
7575

7676
struct device_node;
7777
int riscv_of_processor_hartid(struct device_node *node, unsigned long *hartid);
78+
int riscv_early_of_processor_hartid(struct device_node *node, unsigned long *hartid);
7879
int riscv_of_parent_hartid(struct device_node *node, unsigned long *hartid);
7980

8081
extern void riscv_fill_hwcap(void);

arch/riscv/kernel/cpu.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@
2222
* isn't an enabled and valid RISC-V hart node.
2323
*/
2424
int riscv_of_processor_hartid(struct device_node *node, unsigned long *hart)
25+
{
26+
int cpu;
27+
28+
*hart = (unsigned long)of_get_cpu_hwid(node, 0);
29+
if (*hart == ~0UL) {
30+
pr_warn("Found CPU without hart ID\n");
31+
return -ENODEV;
32+
}
33+
34+
cpu = riscv_hartid_to_cpuid(*hart);
35+
if (cpu < 0)
36+
return cpu;
37+
38+
if (!cpu_possible(cpu))
39+
return -ENODEV;
40+
41+
return 0;
42+
}
43+
44+
int riscv_early_of_processor_hartid(struct device_node *node, unsigned long *hart)
2545
{
2646
const char *isa;
2747

@@ -30,7 +50,7 @@ int riscv_of_processor_hartid(struct device_node *node, unsigned long *hart)
3050
return -ENODEV;
3151
}
3252

33-
*hart = (unsigned long) of_get_cpu_hwid(node, 0);
53+
*hart = (unsigned long)of_get_cpu_hwid(node, 0);
3454
if (*hart == ~0UL) {
3555
pr_warn("Found CPU without hart ID\n");
3656
return -ENODEV;

arch/riscv/kernel/smpboot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static void __init of_parse_and_init_cpus(void)
148148
cpu_set_ops(0);
149149

150150
for_each_of_cpu_node(dn) {
151-
rc = riscv_of_processor_hartid(dn, &hart);
151+
rc = riscv_early_of_processor_hartid(dn, &hart);
152152
if (rc < 0)
153153
continue;
154154

0 commit comments

Comments
 (0)