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	U(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	U(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 };
54 #endif
55 
56 #ifdef CFG_WITH_VFP
57 /* vfp_is_enabled() - Returns true if VFP is enabled */
58 bool vfp_is_enabled(void);
59 
60 /* vfp_enable() - Enables vfp */
61 void vfp_enable(void);
62 
63 /* vfp_disable() - Disables vfp */
64 void vfp_disable(void);
65 #else
vfp_is_enabled(void)66 static inline bool vfp_is_enabled(void)
67 {
68 	return false;
69 }
70 
vfp_enable(void)71 static inline void vfp_enable(void)
72 {
73 }
74 
vfp_disable(void)75 static inline void vfp_disable(void)
76 {
77 }
78 #endif
79 
80 /*
81  * vfp_lazy_save_state_init() - Saves VFP enable status and disables VFP
82  * @state:	VFP state structure to initialize
83  */
84 void vfp_lazy_save_state_init(struct vfp_state *state);
85 
86 /*
87  * vfp_lazy_save_state_final() - Saves rest of VFP state
88  * @state:	VFP state to save to
89  * @force_save:	Forces saving of state regardless of previous state if true.
90  *
91  * If VFP was enabled when vfp_lazy_save_state_init() was called or
92  * @force_save is true: save rest of state and disable VFP. Otherwise, do
93  * nothing.
94  */
95 void vfp_lazy_save_state_final(struct vfp_state *state, bool force_save);
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