Skip to content

Commit f06da27

Browse files
xen0ntsbogend
authored andcommitted
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 <[email protected]> Cc: Jiaxun Yang <[email protected]> Cc: Huacai Chen <[email protected]> Signed-off-by: WANG Xuerui <[email protected]> Reviewed-by: Huacai Chen <[email protected]> Signed-off-by: Thomas Bogendoerfer <[email protected]>
1 parent 70768eb commit f06da27

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

arch/mips/include/uapi/asm/hwcap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
#define HWCAP_LOONGSON_MMI (1 << 11)
1818
#define HWCAP_LOONGSON_EXT (1 << 12)
1919
#define HWCAP_LOONGSON_EXT2 (1 << 13)
20+
#define HWCAP_LOONGSON_CPUCFG (1 << 14)
2021

2122
#endif /* _UAPI_ASM_HWCAP_H */

arch/mips/loongson64/cpucfg-emul.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/types.h>
55
#include <asm/cpu.h>
66
#include <asm/cpu-info.h>
7+
#include <asm/elf.h>
78

89
#include <loongson_regs.h>
910
#include <cpucfg-emul.h>
@@ -128,7 +129,7 @@ void loongson3_cpucfg_synthesize_data(struct cpuinfo_mips *c)
128129

129130
/* CPUs with CPUCFG support don't need to synthesize anything. */
130131
if (cpu_has_cfg())
131-
return;
132+
goto have_cpucfg_now;
132133

133134
c->loongson3_cpucfg_data[0] = 0;
134135
c->loongson3_cpucfg_data[1] = 0;
@@ -217,4 +218,10 @@ void loongson3_cpucfg_synthesize_data(struct cpuinfo_mips *c)
217218
patch_cpucfg_sel1(c);
218219
patch_cpucfg_sel2(c);
219220
patch_cpucfg_sel3(c);
221+
222+
have_cpucfg_now:
223+
/* We have usable CPUCFG now, emulated or not.
224+
* Announce CPUCFG availability to userspace via hwcap.
225+
*/
226+
elf_hwcap |= HWCAP_LOONGSON_CPUCFG;
220227
}

0 commit comments

Comments
 (0)