xcr.h 811 B

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