diff options
Diffstat (limited to 'arch/s390/include/asm/fpu/api.h')
-rw-r--r-- | arch/s390/include/asm/fpu/api.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/arch/s390/include/asm/fpu/api.h b/arch/s390/include/asm/fpu/api.h index 5e04f3cbd320..78ba3ddb9e18 100644 --- a/arch/s390/include/asm/fpu/api.h +++ b/arch/s390/include/asm/fpu/api.h | |||
@@ -1,6 +1,41 @@ | |||
1 | /* | 1 | /* |
2 | * In-kernel FPU support functions | 2 | * In-kernel FPU support functions |
3 | * | 3 | * |
4 | * | ||
5 | * Consider these guidelines before using in-kernel FPU functions: | ||
6 | * | ||
7 | * 1. Use kernel_fpu_begin() and kernel_fpu_end() to enclose all in-kernel | ||
8 | * use of floating-point or vector registers and instructions. | ||
9 | * | ||
10 | * 2. For kernel_fpu_begin(), specify the vector register range you want to | ||
11 | * use with the KERNEL_VXR_* constants. Consider these usage guidelines: | ||
12 | * | ||
13 | * a) If your function typically runs in process-context, use the lower | ||
14 | * half of the vector registers, for example, specify KERNEL_VXR_LOW. | ||
15 | * b) If your function typically runs in soft-irq or hard-irq context, | ||
16 | * prefer using the upper half of the vector registers, for example, | ||
17 | * specify KERNEL_VXR_HIGH. | ||
18 | * | ||
19 | * If you adhere to these guidelines, an interrupted process context | ||
20 | * does not require to save and restore vector registers because of | ||
21 | * disjoint register ranges. | ||
22 | * | ||
23 | * Also note that the __kernel_fpu_begin()/__kernel_fpu_end() functions | ||
24 | * includes logic to save and restore up to 16 vector registers at once. | ||
25 | * | ||
26 | * 3. You can nest kernel_fpu_begin()/kernel_fpu_end() by using different | ||
27 | * struct kernel_fpu states. Vector registers that are in use by outer | ||
28 | * levels are saved and restored. You can minimize the save and restore | ||
29 | * effort by choosing disjoint vector register ranges. | ||
30 | * | ||
31 | * 5. To use vector floating-point instructions, specify the KERNEL_FPC | ||
32 | * flag to save and restore floating-point controls in addition to any | ||
33 | * vector register range. | ||
34 | * | ||
35 | * 6. To use floating-point registers and instructions only, specify the | ||
36 | * KERNEL_FPR flag. This flag triggers a save and restore of vector | ||
37 | * registers V0 to V15 and floating-point controls. | ||
38 | * | ||
4 | * Copyright IBM Corp. 2015 | 39 | * Copyright IBM Corp. 2015 |
5 | * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com> | 40 | * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com> |
6 | */ | 41 | */ |
@@ -8,6 +43,8 @@ | |||
8 | #ifndef _ASM_S390_FPU_API_H | 43 | #ifndef _ASM_S390_FPU_API_H |
9 | #define _ASM_S390_FPU_API_H | 44 | #define _ASM_S390_FPU_API_H |
10 | 45 | ||
46 | #include <linux/preempt.h> | ||
47 | |||
11 | void save_fpu_regs(void); | 48 | void save_fpu_regs(void); |
12 | 49 | ||
13 | static inline int test_fp_ctl(u32 fpc) | 50 | static inline int test_fp_ctl(u32 fpc) |
@@ -27,4 +64,42 @@ static inline int test_fp_ctl(u32 fpc) | |||
27 | return rc; | 64 | return rc; |
28 | } | 65 | } |
29 | 66 | ||
67 | #define KERNEL_VXR_V0V7 1 | ||
68 | #define KERNEL_VXR_V8V15 2 | ||
69 | #define KERNEL_VXR_V16V23 4 | ||
70 | #define KERNEL_VXR_V24V31 8 | ||
71 | #define KERNEL_FPR 16 | ||
72 | #define KERNEL_FPC 256 | ||
73 | |||
74 | #define KERNEL_VXR_LOW (KERNEL_VXR_V0V7|KERNEL_VXR_V8V15) | ||
75 | #define KERNEL_VXR_MID (KERNEL_VXR_V8V15|KERNEL_VXR_V16V23) | ||
76 | #define KERNEL_VXR_HIGH (KERNEL_VXR_V16V23|KERNEL_VXR_V24V31) | ||
77 | |||
78 | #define KERNEL_FPU_MASK (KERNEL_VXR_LOW|KERNEL_VXR_HIGH|KERNEL_FPR) | ||
79 | |||
80 | struct kernel_fpu; | ||
81 | |||
82 | /* | ||
83 | * Note the functions below must be called with preemption disabled. | ||
84 | * Do not enable preemption before calling __kernel_fpu_end() to prevent | ||
85 | * an corruption of an existing kernel FPU state. | ||
86 | * | ||
87 | * Prefer using the kernel_fpu_begin()/kernel_fpu_end() pair of functions. | ||
88 | */ | ||
89 | void __kernel_fpu_begin(struct kernel_fpu *state, u32 flags); | ||
90 | void __kernel_fpu_end(struct kernel_fpu *state); | ||
91 | |||
92 | |||
93 | static inline void kernel_fpu_begin(struct kernel_fpu *state, u32 flags) | ||
94 | { | ||
95 | preempt_disable(); | ||
96 | __kernel_fpu_begin(state, flags); | ||
97 | } | ||
98 | |||
99 | static inline void kernel_fpu_end(struct kernel_fpu *state) | ||
100 | { | ||
101 | __kernel_fpu_end(state); | ||
102 | preempt_enable(); | ||
103 | } | ||
104 | |||
30 | #endif /* _ASM_S390_FPU_API_H */ | 105 | #endif /* _ASM_S390_FPU_API_H */ |