Kyle Swenson | 8d8f654 | 2021-03-15 11:02:55 -0600 | [diff] [blame^] | 1 | /* |
| 2 | * FPU state and register content conversion primitives |
| 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 | |
| 11 | #include <linux/string.h> |
| 12 | #include <asm/ctl_reg.h> |
| 13 | #include <asm/fpu/types.h> |
| 14 | |
| 15 | static inline void save_vx_regs_safe(__vector128 *vxrs) |
| 16 | { |
| 17 | unsigned long cr0, flags; |
| 18 | |
| 19 | flags = arch_local_irq_save(); |
| 20 | __ctl_store(cr0, 0, 0); |
| 21 | __ctl_set_bit(0, 17); |
| 22 | __ctl_set_bit(0, 18); |
| 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 | __ctl_load(cr0, 0, 0); |
| 29 | arch_local_irq_restore(flags); |
| 30 | } |
| 31 | |
| 32 | static inline void convert_vx_to_fp(freg_t *fprs, __vector128 *vxrs) |
| 33 | { |
| 34 | int i; |
| 35 | |
| 36 | for (i = 0; i < __NUM_FPRS; i++) |
| 37 | fprs[i] = *(freg_t *)(vxrs + i); |
| 38 | } |
| 39 | |
| 40 | static inline void convert_fp_to_vx(__vector128 *vxrs, freg_t *fprs) |
| 41 | { |
| 42 | int i; |
| 43 | |
| 44 | for (i = 0; i < __NUM_FPRS; i++) |
| 45 | *(freg_t *)(vxrs + i) = fprs[i]; |
| 46 | } |
| 47 | |
| 48 | static inline void fpregs_store(_s390_fp_regs *fpregs, struct fpu *fpu) |
| 49 | { |
| 50 | fpregs->pad = 0; |
| 51 | fpregs->fpc = fpu->fpc; |
| 52 | if (MACHINE_HAS_VX) |
| 53 | convert_vx_to_fp((freg_t *)&fpregs->fprs, fpu->vxrs); |
| 54 | else |
| 55 | memcpy((freg_t *)&fpregs->fprs, fpu->fprs, |
| 56 | sizeof(fpregs->fprs)); |
| 57 | } |
| 58 | |
| 59 | static inline void fpregs_load(_s390_fp_regs *fpregs, struct fpu *fpu) |
| 60 | { |
| 61 | fpu->fpc = fpregs->fpc; |
| 62 | if (MACHINE_HAS_VX) |
| 63 | convert_fp_to_vx(fpu->vxrs, (freg_t *)&fpregs->fprs); |
| 64 | else |
| 65 | memcpy(fpu->fprs, (freg_t *)&fpregs->fprs, |
| 66 | sizeof(fpregs->fprs)); |
| 67 | } |
| 68 | |
| 69 | #endif /* _ASM_S390_FPU_INTERNAL_H */ |