KVM: arm64: Optimise FPSIMD handling to reduce guest/host thrashing
[linux-block.git] / arch / arm64 / include / asm / fpsimd.h
CommitLineData
53631b54
CM
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>
2d2123bc 20#include <asm/errno.h>
53631b54
CM
21
22#ifndef __ASSEMBLY__
23
7582e220 24#include <linux/cache.h>
b4f9b390 25#include <linux/init.h>
bc0ee476
DM
26#include <linux/stddef.h>
27
53631b54
CM
28#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
29/* Masks for extracting the FPSR and FPCR from the FPSCR */
30#define VFP_FPSCR_STAT_MASK 0xf800009f
31#define VFP_FPSCR_CTRL_MASK 0x07f79f00
32/*
33 * The VFP state has 32x64-bit registers and a single 32-bit
34 * control/status register.
35 */
36#define VFP_STATE_SIZE ((32 * 8) + 4)
37#endif
38
39struct task_struct;
40
20b85472
DM
41extern void fpsimd_save_state(struct user_fpsimd_state *state);
42extern void fpsimd_load_state(struct user_fpsimd_state *state);
53631b54 43
e6b673b7
DM
44extern void fpsimd_save(void);
45
53631b54
CM
46extern void fpsimd_thread_switch(struct task_struct *next);
47extern void fpsimd_flush_thread(void);
48
8cd969d2 49extern void fpsimd_signal_preserve_current_state(void);
c51f9269 50extern void fpsimd_preserve_current_state(void);
005f78cd 51extern void fpsimd_restore_current_state(void);
0abdeff5 52extern void fpsimd_update_current_state(struct user_fpsimd_state const *state);
c51f9269 53
e6b673b7
DM
54extern void fpsimd_bind_task_to_cpu(void);
55extern void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *state);
56
005f78cd 57extern void fpsimd_flush_task_state(struct task_struct *target);
e6b673b7 58extern void fpsimd_flush_cpu_state(void);
17eed27b 59extern void sve_flush_cpu_state(void);
005f78cd 60
7582e220
DM
61/* Maximum VL that SVE VL-agnostic software can transparently support */
62#define SVE_VL_ARCH_MAX 0x100
63
1fc5dce7
DM
64extern void sve_save_state(void *state, u32 *pfpsr);
65extern void sve_load_state(void const *state, u32 const *pfpsr,
66 unsigned long vq_minus_1);
67extern unsigned int sve_get_vl(void);
c0cda3b8
DM
68
69struct arm64_cpu_capabilities;
70extern void sve_kernel_enable(const struct arm64_cpu_capabilities *__unused);
1fc5dce7 71
7582e220
DM
72extern int __ro_after_init sve_max_vl;
73
bc0ee476
DM
74#ifdef CONFIG_ARM64_SVE
75
76extern size_t sve_state_size(struct task_struct const *task);
77
78extern void sve_alloc(struct task_struct *task);
79extern void fpsimd_release_task(struct task_struct *task);
43d4da2c
DM
80extern void fpsimd_sync_to_sve(struct task_struct *task);
81extern void sve_sync_to_fpsimd(struct task_struct *task);
82extern void sve_sync_from_fpsimd_zeropad(struct task_struct *task);
83
7582e220
DM
84extern int sve_set_vector_length(struct task_struct *task,
85 unsigned long vl, unsigned long flags);
bc0ee476 86
2d2123bc
DM
87extern int sve_set_current_vl(unsigned long arg);
88extern int sve_get_current_vl(void);
89
2e0f2478
DM
90/*
91 * Probing and setup functions.
92 * Calls to these functions must be serialised with one another.
93 */
94extern void __init sve_init_vq_map(void);
95extern void sve_update_vq_map(void);
96extern int sve_verify_vq_map(void);
97extern void __init sve_setup(void);
98
bc0ee476
DM
99#else /* ! CONFIG_ARM64_SVE */
100
101static inline void sve_alloc(struct task_struct *task) { }
102static inline void fpsimd_release_task(struct task_struct *task) { }
43d4da2c
DM
103static inline void sve_sync_to_fpsimd(struct task_struct *task) { }
104static inline void sve_sync_from_fpsimd_zeropad(struct task_struct *task) { }
105
2d2123bc
DM
106static inline int sve_set_current_vl(unsigned long arg)
107{
108 return -EINVAL;
109}
110
111static inline int sve_get_current_vl(void)
112{
113 return -EINVAL;
114}
115
2e0f2478
DM
116static inline void sve_init_vq_map(void) { }
117static inline void sve_update_vq_map(void) { }
118static inline int sve_verify_vq_map(void) { return 0; }
119static inline void sve_setup(void) { }
bc0ee476
DM
120
121#endif /* ! CONFIG_ARM64_SVE */
122
4328825d
DM
123/* For use by EFI runtime services calls only */
124extern void __efi_fpsimd_begin(void);
125extern void __efi_fpsimd_end(void);
126
53631b54
CM
127#endif
128
129#endif