MIPS: emulate CPUCFG instruction on older Loongson64 cores
authorWANG Xuerui <git@xen0n.name>
Sat, 23 May 2020 13:37:01 +0000 (21:37 +0800)
committerThomas Bogendoerfer <tsbogend@alpha.franken.de>
Sun, 24 May 2020 07:26:55 +0000 (09:26 +0200)
commitec7a93188a75b57b9f704db6862e7137f01aa80b
tree84907800878283ad5358796589613757ed9783f2
parent8267e78f020a8de2752754c42ec1d56e92431477
MIPS: emulate CPUCFG instruction on older Loongson64 cores

CPUCFG is the instruction for querying processor characteristics on
newer Loongson processors, much like CPUID of x86. Since the instruction
is supposedly designed to provide a unified way to do feature detection
(without having to, for example, parse /proc/cpuinfo which is too
heavyweight), it is important to provide compatibility for older cores
without native support. Fortunately, most of the fields can be
synthesized without changes to semantics. Performance is not really big
a concern, because feature detection logic is not expected to be
invoked very often in typical userland applications.

The instruction can't be emulated on LOONGSON_2EF cores, according to
FlyGoat's experiments. Because the LWC2 opcode is assigned to other
valid instructions on 2E and 2F, no RI exception is raised for us to
intercept. So compatibility is only extended back furthest to
Loongson-3A1000. Loongson-2K is covered too, as it is basically a remix
of various blocks from the 3A/3B models from a kernel perspective.

This is lightly based on Loongson's work on their Linux 3.10 fork, for
being the authority on the right feature flags to fill in, where things
aren't otherwise discoverable.

Signed-off-by: WANG Xuerui <git@xen0n.name>
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: Huacai Chen <chenhc@lemote.com>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
arch/mips/Kconfig
arch/mips/include/asm/cpu-info.h
arch/mips/include/asm/mach-loongson64/cpucfg-emul.h [new file with mode: 0644]
arch/mips/kernel/cpu-probe.c
arch/mips/kernel/traps.c
arch/mips/loongson64/Makefile
arch/mips/loongson64/cpucfg-emul.c [new file with mode: 0644]