1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __ASM_X86_XSAVE_H
3#define __ASM_X86_XSAVE_H
4
5#include <linux/types.h>
6#include <asm/processor.h>
7#include <linux/uaccess.h>
8
9/* Bit 63 of XCR0 is reserved for future expansion */
10#define XFEATURE_MASK_EXTEND (~(XFEATURE_MASK_FPSSE | (1ULL << 63)))
11
12#define XSTATE_CPUID 0x0000000d
13
14#define FXSAVE_SIZE 512
15
16#define XSAVE_HDR_SIZE 64
17#define XSAVE_HDR_OFFSET FXSAVE_SIZE
18
19#define XSAVE_YMM_SIZE 256
20#define XSAVE_YMM_OFFSET (XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET)
21
22/* Supervisor features */
23#define XFEATURE_MASK_SUPERVISOR (XFEATURE_MASK_PT)
24
25/* All currently supported features */
26#define XCNTXT_MASK (XFEATURE_MASK_FP | \
27 XFEATURE_MASK_SSE | \
28 XFEATURE_MASK_YMM | \
29 XFEATURE_MASK_OPMASK | \
30 XFEATURE_MASK_ZMM_Hi256 | \
31 XFEATURE_MASK_Hi16_ZMM | \
32 XFEATURE_MASK_PKRU | \
33 XFEATURE_MASK_BNDREGS | \
34 XFEATURE_MASK_BNDCSR)
35
36#ifdef CONFIG_X86_64
37#define REX_PREFIX "0x48, "
38#else
39#define REX_PREFIX
40#endif
41
42extern u64 xfeatures_mask;
43extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
44
45extern void __init update_regset_xstate_info(unsigned int size,
46 u64 xstate_mask);
47
48void fpu__xstate_clear_all_cpu_caps(void);
49void *get_xsave_addr(struct xregs_state *xsave, int xstate);
50const void *get_xsave_field_ptr(int xstate_field);
51int using_compacted_format(void);
52int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int offset, unsigned int size);
53int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, unsigned int offset, unsigned int size);
54int copy_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf);
55int copy_user_to_xstate(struct xregs_state *xsave, const void __user *ubuf);
56
57/* Validate an xstate header supplied by userspace (ptrace or sigreturn) */
58extern int validate_xstate_header(const struct xstate_header *hdr);
59
60#endif
61