target: Fix kref->refcount underflow in transport_cmd_finish_abort
[linux/fpc-iii.git] / arch / s390 / include / asm / fpu / api.h
blob02124d66bfb5d699b09ee3f2602b8ba89d206bb5
1 /*
2 * In-kernel FPU support functions
5 * Consider these guidelines before using in-kernel FPU functions:
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.
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:
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.
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.
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.
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.
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.
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.
39 * Copyright IBM Corp. 2015
40 * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
43 #ifndef _ASM_S390_FPU_API_H
44 #define _ASM_S390_FPU_API_H
46 #include <linux/preempt.h>
48 void save_fpu_regs(void);
50 static inline int test_fp_ctl(u32 fpc)
52 u32 orig_fpc;
53 int rc;
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;
67 #define KERNEL_FPC 1
68 #define KERNEL_VXR_V0V7 2
69 #define KERNEL_VXR_V8V15 4
70 #define KERNEL_VXR_V16V23 8
71 #define KERNEL_VXR_V24V31 16
73 #define KERNEL_VXR_LOW (KERNEL_VXR_V0V7|KERNEL_VXR_V8V15)
74 #define KERNEL_VXR_MID (KERNEL_VXR_V8V15|KERNEL_VXR_V16V23)
75 #define KERNEL_VXR_HIGH (KERNEL_VXR_V16V23|KERNEL_VXR_V24V31)
77 #define KERNEL_VXR (KERNEL_VXR_LOW|KERNEL_VXR_HIGH)
78 #define KERNEL_FPR (KERNEL_FPC|KERNEL_VXR_V0V7)
80 struct kernel_fpu;
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.
87 * Prefer using the kernel_fpu_begin()/kernel_fpu_end() pair of functions.
89 void __kernel_fpu_begin(struct kernel_fpu *state, u32 flags);
90 void __kernel_fpu_end(struct kernel_fpu *state, u32 flags);
93 static inline void kernel_fpu_begin(struct kernel_fpu *state, u32 flags)
95 preempt_disable();
96 state->mask = S390_lowcore.fpu_flags;
97 if (!test_cpu_flag(CIF_FPU))
98 /* Save user space FPU state and register contents */
99 save_fpu_regs();
100 else if (state->mask & flags)
101 /* Save FPU/vector register in-use by the kernel */
102 __kernel_fpu_begin(state, flags);
103 S390_lowcore.fpu_flags |= flags;
106 static inline void kernel_fpu_end(struct kernel_fpu *state, u32 flags)
108 S390_lowcore.fpu_flags = state->mask;
109 if (state->mask & flags)
110 /* Restore FPU/vector register in-use by the kernel */
111 __kernel_fpu_end(state, flags);
112 preempt_enable();
115 #endif /* _ASM_S390_FPU_API_H */