Hendrik Brueckner | 904818e | 2015-06-11 15:33:54 +0200 | [diff] [blame] | 1 | /* |
Hendrik Brueckner | b075390 | 2015-10-06 12:25:59 +0200 | [diff] [blame] | 2 | * FPU state and register content conversion primitives |
Hendrik Brueckner | 904818e | 2015-06-11 15:33:54 +0200 | [diff] [blame] | 3 | * |
| 4 | * Copyright IBM Corp. 2015 |
| 5 | * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com> |
| 6 | */ |
| 7 | |
| 8 | #ifndef _ASM_S390_FPU_INTERNAL_H |
| 9 | #define _ASM_S390_FPU_INTERNAL_H |
| 10 | |
Hendrik Brueckner | 904818e | 2015-06-11 15:33:54 +0200 | [diff] [blame] | 11 | #include <linux/string.h> |
Hendrik Brueckner | 904818e | 2015-06-11 15:33:54 +0200 | [diff] [blame] | 12 | #include <asm/ctl_reg.h> |
Hendrik Brueckner | b075390 | 2015-10-06 12:25:59 +0200 | [diff] [blame] | 13 | #include <asm/fpu/types.h> |
Hendrik Brueckner | 904818e | 2015-06-11 15:33:54 +0200 | [diff] [blame] | 14 | |
Martin Schwidefsky | 1a36a39 | 2015-10-29 10:28:26 +0100 | [diff] [blame] | 15 | static inline void save_vx_regs(__vector128 *vxrs) |
Hendrik Brueckner | 904818e | 2015-06-11 15:33:54 +0200 | [diff] [blame] | 16 | { |
Hendrik Brueckner | 904818e | 2015-06-11 15:33:54 +0200 | [diff] [blame] | 17 | asm volatile( |
| 18 | " la 1,%0\n" |
Hendrik Brueckner | 9977e88 | 2015-06-10 12:53:42 +0200 | [diff] [blame] | 19 | " .word 0xe70f,0x1000,0x003e\n" /* vstm 0,15,0(1) */ |
| 20 | " .word 0xe70f,0x1100,0x0c3e\n" /* vstm 16,31,256(1) */ |
| 21 | : "=Q" (*(struct vx_array *) vxrs) : : "1"); |
Hendrik Brueckner | 904818e | 2015-06-11 15:33:54 +0200 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | static inline void convert_vx_to_fp(freg_t *fprs, __vector128 *vxrs) |
| 25 | { |
| 26 | int i; |
| 27 | |
| 28 | for (i = 0; i < __NUM_FPRS; i++) |
| 29 | fprs[i] = *(freg_t *)(vxrs + i); |
| 30 | } |
| 31 | |
| 32 | static inline void convert_fp_to_vx(__vector128 *vxrs, freg_t *fprs) |
| 33 | { |
| 34 | int i; |
| 35 | |
| 36 | for (i = 0; i < __NUM_FPRS; i++) |
| 37 | *(freg_t *)(vxrs + i) = fprs[i]; |
| 38 | } |
| 39 | |
| 40 | static inline void fpregs_store(_s390_fp_regs *fpregs, struct fpu *fpu) |
| 41 | { |
| 42 | fpregs->pad = 0; |
Martin Schwidefsky | 1b17cb7 | 2016-02-19 15:29:05 +0100 | [diff] [blame^] | 43 | fpregs->fpc = fpu->fpc; |
Hendrik Brueckner | b5510d9 | 2015-09-29 10:04:41 +0200 | [diff] [blame] | 44 | if (MACHINE_HAS_VX) |
Hendrik Brueckner | 904818e | 2015-06-11 15:33:54 +0200 | [diff] [blame] | 45 | convert_vx_to_fp((freg_t *)&fpregs->fprs, fpu->vxrs); |
| 46 | else |
| 47 | memcpy((freg_t *)&fpregs->fprs, fpu->fprs, |
| 48 | sizeof(fpregs->fprs)); |
| 49 | } |
| 50 | |
| 51 | static inline void fpregs_load(_s390_fp_regs *fpregs, struct fpu *fpu) |
| 52 | { |
Martin Schwidefsky | 1b17cb7 | 2016-02-19 15:29:05 +0100 | [diff] [blame^] | 53 | fpu->fpc = fpregs->fpc; |
Hendrik Brueckner | b5510d9 | 2015-09-29 10:04:41 +0200 | [diff] [blame] | 54 | if (MACHINE_HAS_VX) |
Hendrik Brueckner | 904818e | 2015-06-11 15:33:54 +0200 | [diff] [blame] | 55 | convert_fp_to_vx(fpu->vxrs, (freg_t *)&fpregs->fprs); |
| 56 | else |
| 57 | memcpy(fpu->fprs, (freg_t *)&fpregs->fprs, |
| 58 | sizeof(fpregs->fprs)); |
| 59 | } |
| 60 | |
Hendrik Brueckner | 904818e | 2015-06-11 15:33:54 +0200 | [diff] [blame] | 61 | #endif /* _ASM_S390_FPU_INTERNAL_H */ |