1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copied from arch/arm64/kernel/cpufeature.c
5 * Copyright (C) 2015 ARM Ltd.
6 * Copyright (C) 2017 SiFive
10 #include <asm/processor.h>
11 #include <asm/hwcap.h>
14 unsigned long elf_hwcap __read_mostly;
16 bool has_fpu __read_mostly;
19 void riscv_fill_hwcap(void)
21 struct device_node *node;
24 static unsigned long isa2hwcap[256] = {0};
26 isa2hwcap['i'] = isa2hwcap['I'] = COMPAT_HWCAP_ISA_I;
27 isa2hwcap['m'] = isa2hwcap['M'] = COMPAT_HWCAP_ISA_M;
28 isa2hwcap['a'] = isa2hwcap['A'] = COMPAT_HWCAP_ISA_A;
29 isa2hwcap['f'] = isa2hwcap['F'] = COMPAT_HWCAP_ISA_F;
30 isa2hwcap['d'] = isa2hwcap['D'] = COMPAT_HWCAP_ISA_D;
31 isa2hwcap['c'] = isa2hwcap['C'] = COMPAT_HWCAP_ISA_C;
35 for_each_of_cpu_node(node) {
36 unsigned long this_hwcap = 0;
38 if (riscv_of_processor_hartid(node) < 0)
41 if (of_property_read_string(node, "riscv,isa", &isa)) {
42 pr_warn("Unable to find \"riscv,isa\" devicetree entry\n");
46 for (i = 0; i < strlen(isa); ++i)
47 this_hwcap |= isa2hwcap[(unsigned char)(isa[i])];
50 * All "okay" hart should have same isa. Set HWCAP based on
51 * common capabilities of every "okay" hart, in case they don't
55 elf_hwcap &= this_hwcap;
57 elf_hwcap = this_hwcap;
60 /* We don't support systems with F but without D, so mask those out
62 if ((elf_hwcap & COMPAT_HWCAP_ISA_F) && !(elf_hwcap & COMPAT_HWCAP_ISA_D)) {
63 pr_info("This kernel does not support systems with F but not D\n");
64 elf_hwcap &= ~COMPAT_HWCAP_ISA_F;
67 pr_info("elf_hwcap is 0x%lx\n", elf_hwcap);
70 if (elf_hwcap & (COMPAT_HWCAP_ISA_F | COMPAT_HWCAP_ISA_D))