Skip to content

Commit 396c018

Browse files
vlsunilpalmer-dabbelt
authored andcommitted
RISC-V: cpufeature: Add ACPI support in riscv_fill_hwcap()
On ACPI based systems, the information about the hart like ISA is provided by the RISC-V Hart Capabilities Table (RHCT). Enable filling up hwcap structure based on the information in RHCT. Signed-off-by: Sunil V L <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Conor Dooley <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 914d6f4 commit 396c018

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

arch/riscv/kernel/cpufeature.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
* Copyright (C) 2017 SiFive
77
*/
88

9+
#include <linux/acpi.h>
910
#include <linux/bitmap.h>
1011
#include <linux/ctype.h>
1112
#include <linux/log2.h>
1213
#include <linux/memory.h>
1314
#include <linux/module.h>
1415
#include <linux/of.h>
1516
#include <linux/of_device.h>
17+
#include <asm/acpi.h>
1618
#include <asm/alternative.h>
1719
#include <asm/cacheflush.h>
1820
#include <asm/cpufeature.h>
@@ -100,6 +102,8 @@ void __init riscv_fill_hwcap(void)
100102
char print_str[NUM_ALPHA_EXTS + 1];
101103
int i, j, rc;
102104
unsigned long isa2hwcap[26] = {0};
105+
struct acpi_table_header *rhct;
106+
acpi_status status;
103107
unsigned int cpu;
104108

105109
isa2hwcap['i' - 'a'] = COMPAT_HWCAP_ISA_I;
@@ -113,22 +117,36 @@ void __init riscv_fill_hwcap(void)
113117

114118
bitmap_zero(riscv_isa, RISCV_ISA_EXT_MAX);
115119

120+
if (!acpi_disabled) {
121+
status = acpi_get_table(ACPI_SIG_RHCT, 0, &rhct);
122+
if (ACPI_FAILURE(status))
123+
return;
124+
}
125+
116126
for_each_possible_cpu(cpu) {
117127
unsigned long this_hwcap = 0;
118128
DECLARE_BITMAP(this_isa, RISCV_ISA_EXT_MAX);
119129
const char *temp;
120130

121-
node = of_cpu_device_node_get(cpu);
122-
if (!node) {
123-
pr_warn("Unable to find cpu node\n");
124-
continue;
125-
}
131+
if (acpi_disabled) {
132+
node = of_cpu_device_node_get(cpu);
133+
if (!node) {
134+
pr_warn("Unable to find cpu node\n");
135+
continue;
136+
}
126137

127-
rc = of_property_read_string(node, "riscv,isa", &isa);
128-
of_node_put(node);
129-
if (rc) {
130-
pr_warn("Unable to find \"riscv,isa\" devicetree entry\n");
131-
continue;
138+
rc = of_property_read_string(node, "riscv,isa", &isa);
139+
of_node_put(node);
140+
if (rc) {
141+
pr_warn("Unable to find \"riscv,isa\" devicetree entry\n");
142+
continue;
143+
}
144+
} else {
145+
rc = acpi_get_riscv_isa(rhct, cpu, &isa);
146+
if (rc < 0) {
147+
pr_warn("Unable to get ISA for the hart - %d\n", cpu);
148+
continue;
149+
}
132150
}
133151

134152
temp = isa;
@@ -265,6 +283,9 @@ void __init riscv_fill_hwcap(void)
265283
bitmap_and(riscv_isa, riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
266284
}
267285

286+
if (!acpi_disabled && rhct)
287+
acpi_put_table((struct acpi_table_header *)rhct);
288+
268289
/* We don't support systems with F but without D, so mask those out
269290
* here. */
270291
if ((elf_hwcap & COMPAT_HWCAP_ISA_F) && !(elf_hwcap & COMPAT_HWCAP_ISA_D)) {

0 commit comments

Comments
 (0)