]> asedeno.scripts.mit.edu Git - linux.git/blob - arch/arm64/include/asm/fpsimd.h
arm64/sve: Probe SVE capabilities and usable vector lengths
[linux.git] / arch / arm64 / include / asm / fpsimd.h
1 /*
2  * Copyright (C) 2012 ARM Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16 #ifndef __ASM_FP_H
17 #define __ASM_FP_H
18
19 #include <asm/ptrace.h>
20
21 #ifndef __ASSEMBLY__
22
23 #include <linux/cache.h>
24 #include <linux/stddef.h>
25
26 /*
27  * FP/SIMD storage area has:
28  *  - FPSR and FPCR
29  *  - 32 128-bit data registers
30  *
31  * Note that user_fpsimd forms a prefix of this structure, which is
32  * relied upon in the ptrace FP/SIMD accessors.
33  */
34 struct fpsimd_state {
35         union {
36                 struct user_fpsimd_state user_fpsimd;
37                 struct {
38                         __uint128_t vregs[32];
39                         u32 fpsr;
40                         u32 fpcr;
41                 };
42         };
43         /* the id of the last cpu to have restored this state */
44         unsigned int cpu;
45 };
46
47
48 #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
49 /* Masks for extracting the FPSR and FPCR from the FPSCR */
50 #define VFP_FPSCR_STAT_MASK     0xf800009f
51 #define VFP_FPSCR_CTRL_MASK     0x07f79f00
52 /*
53  * The VFP state has 32x64-bit registers and a single 32-bit
54  * control/status register.
55  */
56 #define VFP_STATE_SIZE          ((32 * 8) + 4)
57 #endif
58
59 struct task_struct;
60
61 extern void fpsimd_save_state(struct fpsimd_state *state);
62 extern void fpsimd_load_state(struct fpsimd_state *state);
63
64 extern void fpsimd_thread_switch(struct task_struct *next);
65 extern void fpsimd_flush_thread(void);
66
67 extern void fpsimd_signal_preserve_current_state(void);
68 extern void fpsimd_preserve_current_state(void);
69 extern void fpsimd_restore_current_state(void);
70 extern void fpsimd_update_current_state(struct fpsimd_state *state);
71
72 extern void fpsimd_flush_task_state(struct task_struct *target);
73
74 /* Maximum VL that SVE VL-agnostic software can transparently support */
75 #define SVE_VL_ARCH_MAX 0x100
76
77 extern void sve_save_state(void *state, u32 *pfpsr);
78 extern void sve_load_state(void const *state, u32 const *pfpsr,
79                            unsigned long vq_minus_1);
80 extern unsigned int sve_get_vl(void);
81 extern int sve_kernel_enable(void *);
82
83 extern int __ro_after_init sve_max_vl;
84
85 #ifdef CONFIG_ARM64_SVE
86
87 extern size_t sve_state_size(struct task_struct const *task);
88
89 extern void sve_alloc(struct task_struct *task);
90 extern void fpsimd_release_task(struct task_struct *task);
91 extern int sve_set_vector_length(struct task_struct *task,
92                                  unsigned long vl, unsigned long flags);
93
94 /*
95  * Probing and setup functions.
96  * Calls to these functions must be serialised with one another.
97  */
98 extern void __init sve_init_vq_map(void);
99 extern void sve_update_vq_map(void);
100 extern int sve_verify_vq_map(void);
101 extern void __init sve_setup(void);
102
103 #else /* ! CONFIG_ARM64_SVE */
104
105 static inline void sve_alloc(struct task_struct *task) { }
106 static inline void fpsimd_release_task(struct task_struct *task) { }
107 static inline void sve_init_vq_map(void) { }
108 static inline void sve_update_vq_map(void) { }
109 static inline int sve_verify_vq_map(void) { return 0; }
110 static inline void sve_setup(void) { }
111
112 #endif /* ! CONFIG_ARM64_SVE */
113
114 /* For use by EFI runtime services calls only */
115 extern void __efi_fpsimd_begin(void);
116 extern void __efi_fpsimd_end(void);
117
118 #endif
119
120 #endif