xref: /linux/arch/x86/include/asm/fpu/xcr.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_FPU_XCR_H
3 #define _ASM_X86_FPU_XCR_H
4 
5 #define XCR_XFEATURE_ENABLED_MASK	0x00000000
6 #define XCR_XFEATURE_IN_USE_MASK	0x00000001
7 
8 static __always_inline u64 xgetbv(u32 index)
9 {
10 	u32 eax, edx;
11 
12 	asm volatile("xgetbv" : "=a" (eax), "=d" (edx) : "c" (index));
13 	return eax + ((u64)edx << 32);
14 }
15 
16 static inline void xsetbv(u32 index, u64 value)
17 {
18 	u32 eax = value;
19 	u32 edx = value >> 32;
20 
21 	asm volatile("xsetbv" :: "a" (eax), "d" (edx), "c" (index));
22 }
23 
24 /*
25  * Return a mask of xfeatures which are currently being tracked
26  * by the processor as being in the initial configuration.
27  *
28  * Callers should check X86_FEATURE_XGETBV1.
29  */
30 static __always_inline u64 xfeatures_in_use(void)
31 {
32 	return xgetbv(XCR_XFEATURE_IN_USE_MASK);
33 }
34 
35 #endif /* _ASM_X86_FPU_XCR_H */
36