Skip to content

Commit fbdc619

Browse files
Atish Patrapalmer-dabbelt
authored andcommitted
RISC-V: Assign hwcap as per comman capabilities.
Currently, we set hwcap based on first valid hart from DT. This may not be correct always as that hart might not be current booting cpu or may have a different capability. Set hwcap as the capabilities supported by all possible harts with "okay" status. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Johan Hovold <johan@kernel.org> Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
1 parent 291debb commit fbdc619

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

‎arch/riscv/kernel/cpufeature.c‎

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/of.h>
2121
#include <asm/processor.h>
2222
#include <asm/hwcap.h>
23+
#include <asm/smp.h>
2324

2425
unsigned long elf_hwcap __read_mostly;
2526
#ifdef CONFIG_FPU
@@ -42,28 +43,30 @@ void riscv_fill_hwcap(void)
4243

4344
elf_hwcap = 0;
4445

45-
/*
46-
* We don't support running Linux on hertergenous ISA systems. For
47-
* now, we just check the ISA of the first "okay" processor.
48-
*/
4946
for_each_of_cpu_node(node) {
50-
if (riscv_of_processor_hartid(node) >= 0)
51-
break;
52-
}
53-
if (!node) {
54-
pr_warn("Unable to find \"cpu\" devicetree entry\n");
55-
return;
56-
}
47+
unsigned long this_hwcap = 0;
5748

58-
if (of_property_read_string(node, "riscv,isa", &isa)) {
59-
pr_warn("Unable to find \"riscv,isa\" devicetree entry\n");
60-
of_node_put(node);
61-
return;
62-
}
63-
of_node_put(node);
49+
if (riscv_of_processor_hartid(node) < 0)
50+
continue;
6451

65-
for (i = 0; i < strlen(isa); ++i)
66-
elf_hwcap |= isa2hwcap[(unsigned char)(isa[i])];
52+
if (of_property_read_string(node, "riscv,isa", &isa)) {
53+
pr_warn("Unable to find \"riscv,isa\" devicetree entry\n");
54+
continue;
55+
}
56+
57+
for (i = 0; i < strlen(isa); ++i)
58+
this_hwcap |= isa2hwcap[(unsigned char)(isa[i])];
59+
60+
/*
61+
* All "okay" hart should have same isa. Set HWCAP based on
62+
* common capabilities of every "okay" hart, in case they don't
63+
* have.
64+
*/
65+
if (elf_hwcap)
66+
elf_hwcap &= this_hwcap;
67+
else
68+
elf_hwcap = this_hwcap;
69+
}
6770

6871
/* We don't support systems with F but without D, so mask those out
6972
* here. */

0 commit comments

Comments
 (0)