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