2 * General floating pointer and vector register helpers
4 * Copyright IBM Corp. 2015
5 * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
8 #ifndef _ASM_S390_FPU_INTERNAL_H
9 #define _ASM_S390_FPU_INTERNAL_H
11 #define FPU_USE_VX 1 /* Vector extension is active */
15 #include <linux/errno.h>
16 #include <linux/string.h>
17 #include <asm/linkage.h>
18 #include <asm/ctl_reg.h>
19 #include <asm/sigcontext.h>
22 __u32 fpc; /* Floating-point control */
26 freg_t *fprs; /* Floating-point register save area */
27 __vector128 *vxrs; /* Vector register save area */
31 void save_fpu_regs(struct fpu *fpu);
33 #define is_vx_fpu(fpu) (!!((fpu)->flags & FPU_USE_VX))
34 #define is_vx_task(tsk) (!!((tsk)->thread.fpu.flags & FPU_USE_VX))
36 /* VX array structure for address operand constraints in inline assemblies */
37 struct vx_array { __vector128 _[__NUM_VXRS]; };
39 static inline int test_fp_ctl(u32 fpc)
51 : "=d" (rc), "=d" (orig_fpc)
52 : "d" (fpc), "0" (-EINVAL));
56 static inline void save_vx_regs_safe(__vector128 *vxrs)
58 unsigned long cr0, flags;
60 flags = arch_local_irq_save();
61 __ctl_store(cr0, 0, 0);
66 " .word 0xe70f,0x1000,0x003e\n" /* vstm 0,15,0(1) */
67 " .word 0xe70f,0x1100,0x0c3e\n" /* vstm 16,31,256(1) */
68 : "=Q" (*(struct vx_array *) vxrs) : : "1");
69 __ctl_load(cr0, 0, 0);
70 arch_local_irq_restore(flags);
73 static inline void convert_vx_to_fp(freg_t *fprs, __vector128 *vxrs)
77 for (i = 0; i < __NUM_FPRS; i++)
78 fprs[i] = *(freg_t *)(vxrs + i);
81 static inline void convert_fp_to_vx(__vector128 *vxrs, freg_t *fprs)
85 for (i = 0; i < __NUM_FPRS; i++)
86 *(freg_t *)(vxrs + i) = fprs[i];
89 static inline void fpregs_store(_s390_fp_regs *fpregs, struct fpu *fpu)
93 convert_vx_to_fp((freg_t *)&fpregs->fprs, fpu->vxrs);
95 memcpy((freg_t *)&fpregs->fprs, fpu->fprs,
96 sizeof(fpregs->fprs));
99 static inline void fpregs_load(_s390_fp_regs *fpregs, struct fpu *fpu)
102 convert_fp_to_vx(fpu->vxrs, (freg_t *)&fpregs->fprs);
104 memcpy(fpu->fprs, (freg_t *)&fpregs->fprs,
105 sizeof(fpregs->fprs));
110 #endif /* _ASM_S390_FPU_INTERNAL_H */