2019-06-03 13:44:50 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-07-11 09:07:09 +08:00
|
|
|
/*
|
|
|
|
* Copied from arch/arm64/kernel/cpufeature.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 ARM Ltd.
|
|
|
|
* Copyright (C) 2017 SiFive
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/hwcap.h>
|
2019-02-23 03:41:40 +08:00
|
|
|
#include <asm/smp.h>
|
2019-10-18 06:21:28 +08:00
|
|
|
#include <asm/switch_to.h>
|
2017-07-11 09:07:09 +08:00
|
|
|
|
|
|
|
unsigned long elf_hwcap __read_mostly;
|
2018-10-09 10:18:34 +08:00
|
|
|
#ifdef CONFIG_FPU
|
|
|
|
bool has_fpu __read_mostly;
|
|
|
|
#endif
|
2017-07-11 09:07:09 +08:00
|
|
|
|
|
|
|
void riscv_fill_hwcap(void)
|
|
|
|
{
|
2019-01-18 22:03:08 +08:00
|
|
|
struct device_node *node;
|
2017-07-11 09:07:09 +08:00
|
|
|
const char *isa;
|
|
|
|
size_t i;
|
|
|
|
static unsigned long isa2hwcap[256] = {0};
|
|
|
|
|
|
|
|
isa2hwcap['i'] = isa2hwcap['I'] = COMPAT_HWCAP_ISA_I;
|
|
|
|
isa2hwcap['m'] = isa2hwcap['M'] = COMPAT_HWCAP_ISA_M;
|
|
|
|
isa2hwcap['a'] = isa2hwcap['A'] = COMPAT_HWCAP_ISA_A;
|
|
|
|
isa2hwcap['f'] = isa2hwcap['F'] = COMPAT_HWCAP_ISA_F;
|
|
|
|
isa2hwcap['d'] = isa2hwcap['D'] = COMPAT_HWCAP_ISA_D;
|
|
|
|
isa2hwcap['c'] = isa2hwcap['C'] = COMPAT_HWCAP_ISA_C;
|
|
|
|
|
|
|
|
elf_hwcap = 0;
|
|
|
|
|
2019-01-18 22:03:08 +08:00
|
|
|
for_each_of_cpu_node(node) {
|
2019-02-23 03:41:40 +08:00
|
|
|
unsigned long this_hwcap = 0;
|
2017-07-11 09:07:09 +08:00
|
|
|
|
2019-02-23 03:41:40 +08:00
|
|
|
if (riscv_of_processor_hartid(node) < 0)
|
|
|
|
continue;
|
2017-07-11 09:07:09 +08:00
|
|
|
|
2019-02-23 03:41:40 +08:00
|
|
|
if (of_property_read_string(node, "riscv,isa", &isa)) {
|
|
|
|
pr_warn("Unable to find \"riscv,isa\" devicetree entry\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < strlen(isa); ++i)
|
|
|
|
this_hwcap |= isa2hwcap[(unsigned char)(isa[i])];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All "okay" hart should have same isa. Set HWCAP based on
|
|
|
|
* common capabilities of every "okay" hart, in case they don't
|
|
|
|
* have.
|
|
|
|
*/
|
|
|
|
if (elf_hwcap)
|
|
|
|
elf_hwcap &= this_hwcap;
|
|
|
|
else
|
|
|
|
elf_hwcap = this_hwcap;
|
|
|
|
}
|
2017-07-11 09:07:09 +08:00
|
|
|
|
2018-08-28 05:42:53 +08:00
|
|
|
/* We don't support systems with F but without D, so mask those out
|
|
|
|
* here. */
|
|
|
|
if ((elf_hwcap & COMPAT_HWCAP_ISA_F) && !(elf_hwcap & COMPAT_HWCAP_ISA_D)) {
|
2019-01-18 22:03:04 +08:00
|
|
|
pr_info("This kernel does not support systems with F but not D\n");
|
2018-08-28 05:42:53 +08:00
|
|
|
elf_hwcap &= ~COMPAT_HWCAP_ISA_F;
|
|
|
|
}
|
|
|
|
|
2019-01-18 22:03:04 +08:00
|
|
|
pr_info("elf_hwcap is 0x%lx\n", elf_hwcap);
|
2018-10-09 10:18:34 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_FPU
|
|
|
|
if (elf_hwcap & (COMPAT_HWCAP_ISA_F | COMPAT_HWCAP_ISA_D))
|
|
|
|
has_fpu = true;
|
|
|
|
#endif
|
2017-07-11 09:07:09 +08:00
|
|
|
}
|