1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * FPU state and register content conversion primitives
4 *
5 * Copyright IBM Corp. 2015
6 * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
7 */
8
9 #ifndef _ASM_S390_FPU_INTERNAL_H
10 #define _ASM_S390_FPU_INTERNAL_H
11
12 #include <linux/string.h>
13 #include <asm/facility.h>
14 #include <asm/fpu/types.h>
15
cpu_has_vx(void)16 static inline bool cpu_has_vx(void)
17 {
18 return likely(test_facility(129));
19 }
20
save_vx_regs(__vector128 * vxrs)21 static inline void save_vx_regs(__vector128 *vxrs)
22 {
23 asm volatile(
24 " la 1,%0\n"
25 " .word 0xe70f,0x1000,0x003e\n" /* vstm 0,15,0(1) */
26 " .word 0xe70f,0x1100,0x0c3e\n" /* vstm 16,31,256(1) */
27 : "=Q" (*(struct vx_array *) vxrs) : : "1");
28 }
29
convert_vx_to_fp(freg_t * fprs,__vector128 * vxrs)30 static inline void convert_vx_to_fp(freg_t *fprs, __vector128 *vxrs)
31 {
32 int i;
33
34 for (i = 0; i < __NUM_FPRS; i++)
35 fprs[i].ui = vxrs[i].high;
36 }
37
convert_fp_to_vx(__vector128 * vxrs,freg_t * fprs)38 static inline void convert_fp_to_vx(__vector128 *vxrs, freg_t *fprs)
39 {
40 int i;
41
42 for (i = 0; i < __NUM_FPRS; i++)
43 vxrs[i].high = fprs[i].ui;
44 }
45
fpregs_store(_s390_fp_regs * fpregs,struct fpu * fpu)46 static inline void fpregs_store(_s390_fp_regs *fpregs, struct fpu *fpu)
47 {
48 fpregs->pad = 0;
49 fpregs->fpc = fpu->fpc;
50 if (cpu_has_vx())
51 convert_vx_to_fp((freg_t *)&fpregs->fprs, fpu->vxrs);
52 else
53 memcpy((freg_t *)&fpregs->fprs, fpu->fprs,
54 sizeof(fpregs->fprs));
55 }
56
fpregs_load(_s390_fp_regs * fpregs,struct fpu * fpu)57 static inline void fpregs_load(_s390_fp_regs *fpregs, struct fpu *fpu)
58 {
59 fpu->fpc = fpregs->fpc;
60 if (cpu_has_vx())
61 convert_fp_to_vx(fpu->vxrs, (freg_t *)&fpregs->fprs);
62 else
63 memcpy(fpu->fprs, (freg_t *)&fpregs->fprs,
64 sizeof(fpregs->fprs));
65 }
66
67 #endif /* _ASM_S390_FPU_INTERNAL_H */
68