18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_FPU_XCR_H
38c2ecf20Sopenharmony_ci#define _ASM_X86_FPU_XCR_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci * MXCSR and XCR definitions:
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_cistatic inline void ldmxcsr(u32 mxcsr)
108c2ecf20Sopenharmony_ci{
118c2ecf20Sopenharmony_ci	asm volatile("ldmxcsr %0" :: "m" (mxcsr));
128c2ecf20Sopenharmony_ci}
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciextern unsigned int mxcsr_feature_mask;
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define XCR_XFEATURE_ENABLED_MASK	0x00000000
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistatic inline u64 xgetbv(u32 index)
198c2ecf20Sopenharmony_ci{
208c2ecf20Sopenharmony_ci	u32 eax, edx;
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci	asm volatile("xgetbv" : "=a" (eax), "=d" (edx) : "c" (index));
238c2ecf20Sopenharmony_ci	return eax + ((u64)edx << 32);
248c2ecf20Sopenharmony_ci}
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic inline void xsetbv(u32 index, u64 value)
278c2ecf20Sopenharmony_ci{
288c2ecf20Sopenharmony_ci	u32 eax = value;
298c2ecf20Sopenharmony_ci	u32 edx = value >> 32;
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci	asm volatile("xsetbv" :: "a" (eax), "d" (edx), "c" (index));
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#endif /* _ASM_X86_FPU_XCR_H */
35