Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: Expose Loongson CPUCFG availability via HWCAP

The point is to allow userspace to probe for CPUCFG without possibly
triggering invalid instructions. In addition to that, future Loongson
feature bits could all be stuffed into CPUCFG bit fields (or "leaves"
in x86-speak) if Loongson does not make mistakes, so ELF HWCAP bits are
conserved.

Userspace can determine native CPUCFG availability by checking the LCSRP
(Loongson CSR Present) bit in CPUCFG output after seeing CPUCFG bit in
HWCAP. Native CPUCFG always sets the LCSRP bit, as CPUCFG is part of the
Loongson CSR ASE, while the emulation intentionally leaves this bit
clear.

The other existing Loongson-specific HWCAP bits are, to my best
knowledge, unused, as

(1) they are fairly recent additions,
(2) Loongson never back-ported the patch into their kernel fork, and
(3) Loongson's existing installed base rarely upgrade, if ever;

However, they are still considered userspace ABI, hence unfortunately
unremovable. But hopefully at least we could stop adding new Loongson
HWCAP bits in the future.

Cc: Paul Burton <paulburton@kernel.org>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: Huacai Chen <chenhc@lemote.com>
Signed-off-by: WANG Xuerui <git@xen0n.name>
Reviewed-by: Huacai Chen <chenhc@lemote.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

authored by

WANG Xuerui and committed by
Thomas Bogendoerfer
f06da27e 70768eba

+9 -1
+1
arch/mips/include/uapi/asm/hwcap.h
··· 17 17 #define HWCAP_LOONGSON_MMI (1 << 11) 18 18 #define HWCAP_LOONGSON_EXT (1 << 12) 19 19 #define HWCAP_LOONGSON_EXT2 (1 << 13) 20 + #define HWCAP_LOONGSON_CPUCFG (1 << 14) 20 21 21 22 #endif /* _UAPI_ASM_HWCAP_H */
+8 -1
arch/mips/loongson64/cpucfg-emul.c
··· 4 4 #include <linux/types.h> 5 5 #include <asm/cpu.h> 6 6 #include <asm/cpu-info.h> 7 + #include <asm/elf.h> 7 8 8 9 #include <loongson_regs.h> 9 10 #include <cpucfg-emul.h> ··· 129 128 130 129 /* CPUs with CPUCFG support don't need to synthesize anything. */ 131 130 if (cpu_has_cfg()) 132 - return; 131 + goto have_cpucfg_now; 133 132 134 133 c->loongson3_cpucfg_data[0] = 0; 135 134 c->loongson3_cpucfg_data[1] = 0; ··· 218 217 patch_cpucfg_sel1(c); 219 218 patch_cpucfg_sel2(c); 220 219 patch_cpucfg_sel3(c); 220 + 221 + have_cpucfg_now: 222 + /* We have usable CPUCFG now, emulated or not. 223 + * Announce CPUCFG availability to userspace via hwcap. 224 + */ 225 + elf_hwcap |= HWCAP_LOONGSON_CPUCFG; 221 226 }