xref: /openbmc/linux/arch/arm64/include/asm/fpsimd.h (revision 68198dca)
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 #include <asm/errno.h>
21 
22 #ifndef __ASSEMBLY__
23 
24 #include <linux/cache.h>
25 #include <linux/stddef.h>
26 
27 /*
28  * FP/SIMD storage area has:
29  *  - FPSR and FPCR
30  *  - 32 128-bit data registers
31  *
32  * Note that user_fpsimd forms a prefix of this structure, which is
33  * relied upon in the ptrace FP/SIMD accessors.
34  */
35 struct fpsimd_state {
36 	union {
37 		struct user_fpsimd_state user_fpsimd;
38 		struct {
39 			__uint128_t vregs[32];
40 			u32 fpsr;
41 			u32 fpcr;
42 			/*
43 			 * For ptrace compatibility, pad to next 128-bit
44 			 * boundary here if extending this struct.
45 			 */
46 		};
47 	};
48 	/* the id of the last cpu to have restored this state */
49 	unsigned int cpu;
50 };
51 
52 #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
53 /* Masks for extracting the FPSR and FPCR from the FPSCR */
54 #define VFP_FPSCR_STAT_MASK	0xf800009f
55 #define VFP_FPSCR_CTRL_MASK	0x07f79f00
56 /*
57  * The VFP state has 32x64-bit registers and a single 32-bit
58  * control/status register.
59  */
60 #define VFP_STATE_SIZE		((32 * 8) + 4)
61 #endif
62 
63 struct task_struct;
64 
65 extern void fpsimd_save_state(struct fpsimd_state *state);
66 extern void fpsimd_load_state(struct fpsimd_state *state);
67 
68 extern void fpsimd_thread_switch(struct task_struct *next);
69 extern void fpsimd_flush_thread(void);
70 
71 extern void fpsimd_signal_preserve_current_state(void);
72 extern void fpsimd_preserve_current_state(void);
73 extern void fpsimd_restore_current_state(void);
74 extern void fpsimd_update_current_state(struct fpsimd_state *state);
75 
76 extern void fpsimd_flush_task_state(struct task_struct *target);
77 extern void sve_flush_cpu_state(void);
78 
79 /* Maximum VL that SVE VL-agnostic software can transparently support */
80 #define SVE_VL_ARCH_MAX 0x100
81 
82 extern void sve_save_state(void *state, u32 *pfpsr);
83 extern void sve_load_state(void const *state, u32 const *pfpsr,
84 			   unsigned long vq_minus_1);
85 extern unsigned int sve_get_vl(void);
86 extern int sve_kernel_enable(void *);
87 
88 extern int __ro_after_init sve_max_vl;
89 
90 #ifdef CONFIG_ARM64_SVE
91 
92 extern size_t sve_state_size(struct task_struct const *task);
93 
94 extern void sve_alloc(struct task_struct *task);
95 extern void fpsimd_release_task(struct task_struct *task);
96 extern void fpsimd_sync_to_sve(struct task_struct *task);
97 extern void sve_sync_to_fpsimd(struct task_struct *task);
98 extern void sve_sync_from_fpsimd_zeropad(struct task_struct *task);
99 
100 extern int sve_set_vector_length(struct task_struct *task,
101 				 unsigned long vl, unsigned long flags);
102 
103 extern int sve_set_current_vl(unsigned long arg);
104 extern int sve_get_current_vl(void);
105 
106 /*
107  * Probing and setup functions.
108  * Calls to these functions must be serialised with one another.
109  */
110 extern void __init sve_init_vq_map(void);
111 extern void sve_update_vq_map(void);
112 extern int sve_verify_vq_map(void);
113 extern void __init sve_setup(void);
114 
115 #else /* ! CONFIG_ARM64_SVE */
116 
117 static inline void sve_alloc(struct task_struct *task) { }
118 static inline void fpsimd_release_task(struct task_struct *task) { }
119 static inline void sve_sync_to_fpsimd(struct task_struct *task) { }
120 static inline void sve_sync_from_fpsimd_zeropad(struct task_struct *task) { }
121 
122 static inline int sve_set_current_vl(unsigned long arg)
123 {
124 	return -EINVAL;
125 }
126 
127 static inline int sve_get_current_vl(void)
128 {
129 	return -EINVAL;
130 }
131 
132 static inline void sve_init_vq_map(void) { }
133 static inline void sve_update_vq_map(void) { }
134 static inline int sve_verify_vq_map(void) { return 0; }
135 static inline void sve_setup(void) { }
136 
137 #endif /* ! CONFIG_ARM64_SVE */
138 
139 /* For use by EFI runtime services calls only */
140 extern void __efi_fpsimd_begin(void);
141 extern void __efi_fpsimd_end(void);
142 
143 #endif
144 
145 #endif
146