fpsimd.h 4.6 KB
Newer Older
C
Catalin Marinas 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright (C) 2012 ARM Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef __ASM_FP_H
#define __ASM_FP_H

19
#include <asm/errno.h>
20
#include <asm/ptrace.h>
21 22
#include <asm/processor.h>
#include <asm/sigcontext.h>
23
#include <asm/sysreg.h>
C
Catalin Marinas 已提交
24 25 26

#ifndef __ASSEMBLY__

27
#include <linux/build_bug.h>
28
#include <linux/cache.h>
29
#include <linux/init.h>
30 31
#include <linux/stddef.h>

C
Catalin Marinas 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44
#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
/* Masks for extracting the FPSR and FPCR from the FPSCR */
#define VFP_FPSCR_STAT_MASK	0xf800009f
#define VFP_FPSCR_CTRL_MASK	0x07f79f00
/*
 * The VFP state has 32x64-bit registers and a single 32-bit
 * control/status register.
 */
#define VFP_STATE_SIZE		((32 * 8) + 4)
#endif

struct task_struct;

45 46
extern void fpsimd_save_state(struct user_fpsimd_state *state);
extern void fpsimd_load_state(struct user_fpsimd_state *state);
C
Catalin Marinas 已提交
47

48 49
extern void fpsimd_save(void);

C
Catalin Marinas 已提交
50 51 52
extern void fpsimd_thread_switch(struct task_struct *next);
extern void fpsimd_flush_thread(void);

D
Dave Martin 已提交
53
extern void fpsimd_signal_preserve_current_state(void);
54
extern void fpsimd_preserve_current_state(void);
55
extern void fpsimd_restore_current_state(void);
56
extern void fpsimd_update_current_state(struct user_fpsimd_state const *state);
57

58 59 60
extern void fpsimd_bind_task_to_cpu(void);
extern void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *state);

61
extern void fpsimd_flush_task_state(struct task_struct *target);
62
extern void fpsimd_flush_cpu_state(void);
63
extern void sve_flush_cpu_state(void);
64

65 66 67
/* Maximum VL that SVE VL-agnostic software can transparently support */
#define SVE_VL_ARCH_MAX 0x100

68 69 70 71 72 73 74 75 76 77 78
/* Offset of FFR in the SVE register dump */
static inline size_t sve_ffr_offset(int vl)
{
	return SVE_SIG_FFR_OFFSET(sve_vq_from_vl(vl)) - SVE_SIG_REGS_OFFSET;
}

static inline void *sve_pffr(struct thread_struct *thread)
{
	return (char *)thread->sve_state + sve_ffr_offset(thread->sve_vl);
}

79 80 81 82
extern void sve_save_state(void *state, u32 *pfpsr);
extern void sve_load_state(void const *state, u32 const *pfpsr,
			   unsigned long vq_minus_1);
extern unsigned int sve_get_vl(void);
83 84 85

struct arm64_cpu_capabilities;
extern void sve_kernel_enable(const struct arm64_cpu_capabilities *__unused);
86

87 88
extern u64 read_zcr_features(void);

89 90
extern int __ro_after_init sve_max_vl;

91 92 93 94 95 96
#ifdef CONFIG_ARM64_SVE

extern size_t sve_state_size(struct task_struct const *task);

extern void sve_alloc(struct task_struct *task);
extern void fpsimd_release_task(struct task_struct *task);
97 98 99 100
extern void fpsimd_sync_to_sve(struct task_struct *task);
extern void sve_sync_to_fpsimd(struct task_struct *task);
extern void sve_sync_from_fpsimd_zeropad(struct task_struct *task);

101 102
extern int sve_set_vector_length(struct task_struct *task,
				 unsigned long vl, unsigned long flags);
103

104 105 106
extern int sve_set_current_vl(unsigned long arg);
extern int sve_get_current_vl(void);

107 108 109 110 111 112 113 114 115 116
static inline void sve_user_disable(void)
{
	sysreg_clear_set(cpacr_el1, CPACR_EL1_ZEN_EL0EN, 0);
}

static inline void sve_user_enable(void)
{
	sysreg_clear_set(cpacr_el1, 0, CPACR_EL1_ZEN_EL0EN);
}

117 118 119 120 121 122 123 124 125
/*
 * Probing and setup functions.
 * Calls to these functions must be serialised with one another.
 */
extern void __init sve_init_vq_map(void);
extern void sve_update_vq_map(void);
extern int sve_verify_vq_map(void);
extern void __init sve_setup(void);

126 127 128 129
#else /* ! CONFIG_ARM64_SVE */

static inline void sve_alloc(struct task_struct *task) { }
static inline void fpsimd_release_task(struct task_struct *task) { }
130 131 132
static inline void sve_sync_to_fpsimd(struct task_struct *task) { }
static inline void sve_sync_from_fpsimd_zeropad(struct task_struct *task) { }

133 134 135 136 137 138 139 140 141 142
static inline int sve_set_current_vl(unsigned long arg)
{
	return -EINVAL;
}

static inline int sve_get_current_vl(void)
{
	return -EINVAL;
}

143 144 145
static inline void sve_user_disable(void) { BUILD_BUG(); }
static inline void sve_user_enable(void) { BUILD_BUG(); }

146 147 148 149
static inline void sve_init_vq_map(void) { }
static inline void sve_update_vq_map(void) { }
static inline int sve_verify_vq_map(void) { return 0; }
static inline void sve_setup(void) { }
150 151 152

#endif /* ! CONFIG_ARM64_SVE */

153 154 155 156
/* For use by EFI runtime services calls only */
extern void __efi_fpsimd_begin(void);
extern void __efi_fpsimd_end(void);

C
Catalin Marinas 已提交
157 158 159
#endif

#endif