6aba6fc406ad0e0f89e48611fe45e22403af8283
[deliverable/linux.git] / arch / s390 / include / asm / fpu / api.h
1 /*
2 * In-kernel FPU support functions
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 *
39 * Copyright IBM Corp. 2015
40 * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
41 */
42
43 #ifndef _ASM_S390_FPU_API_H
44 #define _ASM_S390_FPU_API_H
45
46 #include <linux/preempt.h>
47
48 void save_fpu_regs(void);
49
50 static inline int test_fp_ctl(u32 fpc)
51 {
52 u32 orig_fpc;
53 int rc;
54
55 asm volatile(
56 " efpc %1\n"
57 " sfpc %2\n"
58 "0: sfpc %1\n"
59 " la %0,0\n"
60 "1:\n"
61 EX_TABLE(0b,1b)
62 : "=d" (rc), "=&d" (orig_fpc)
63 : "d" (fpc), "0" (-EINVAL));
64 return rc;
65 }
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
105 #endif /* _ASM_S390_FPU_API_H */
This page took 0.032504 seconds and 5 git commands to generate.