xref: /optee_os/core/arch/arm/include/kernel/vfp.h (revision bc879b1765afacd8a2b7673236037181011cabea)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2015, Linaro Limited
4  */
5 
6 #ifndef KERNEL_VFP_H
7 #define KERNEL_VFP_H
8 
9 #include <types_ext.h>
10 #include <compiler.h>
11 
12 #ifdef ARM32
13 /*
14  * Advanced SIMD/floating point state on ARMv7-A or ARMv8-A AArch32 has:
15  * - 32 64-bit data registers
16  * - FPSCR (32 bits)
17  * - FPEXC (32 bits)
18  */
19 
20 #define VFP_NUM_REGS	32
21 
22 struct vfp_reg {
23 	uint64_t v;
24 };
25 
26 struct vfp_state {
27 	uint32_t fpexc;
28 	uint32_t fpscr;
29 	struct vfp_reg reg[VFP_NUM_REGS];
30 };
31 #endif
32 
33 #ifdef ARM64
34 /*
35  * Advanced SIMD/floating point state on ARMv8-A AArch64 has:
36  * - 32 128-bit data registers
37  * - FPSR (32 bits)
38  * - FPCR (32 bits)
39  * - CPACR_EL1.FPEN (2 bits)
40  */
41 
42 #define VFP_NUM_REGS	32
43 
44 struct vfp_reg {
45 	uint8_t v[16];
46 } __aligned(16);
47 
48 struct vfp_state {
49 	struct vfp_reg reg[VFP_NUM_REGS];
50 	uint32_t fpsr;
51 	uint32_t fpcr;
52 	uint32_t cpacr_el1;
53 	bool force_save; /* Save to reg even if VFP was not enabled */
54 };
55 #endif
56 
57 #ifdef CFG_WITH_VFP
58 /* vfp_is_enabled() - Returns true if VFP is enabled */
59 bool vfp_is_enabled(void);
60 
61 /* vfp_enable() - Enables vfp */
62 void vfp_enable(void);
63 
64 /* vfp_disable() - Disables vfp */
65 void vfp_disable(void);
66 #else
67 static inline bool vfp_is_enabled(void)
68 {
69 	return false;
70 }
71 
72 static inline void vfp_enable(void)
73 {
74 }
75 
76 static inline void vfp_disable(void)
77 {
78 }
79 #endif
80 
81 /*
82  * vfp_lazy_save_state_init() - Saves VFP enable status and disables VFP
83  * @state:	VFP state structure to initialize
84  */
85 void vfp_lazy_save_state_init(struct vfp_state *state);
86 
87 /*
88  * vfp_lazy_save_state_final() - Saves rest of VFP state
89  * @state:	VFP state to save to
90  *
91  * If VFP was enabled when vfp_lazy_save_state_init() was called: save rest
92  * of state and disable VFP. Otherwise, do nothing.
93  */
94 void vfp_lazy_save_state_final(struct vfp_state *state);
95 
96 /*
97  * vfp_lazy_restore_state() - Lazy restore VFP state
98  * @state:		VFP state to restore
99  *
100  * Restores VFP enable status and also restores rest of VFP state if
101  * vfp_lazy_save_state_final() was called on this state.
102  */
103 void vfp_lazy_restore_state(struct vfp_state *state, bool full_state);
104 
105 #endif /*KERNEL_VFP_H*/
106