internal.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #ifndef _ASM_S390_FPU_INTERNAL_H
  8. #define _ASM_S390_FPU_INTERNAL_H
  9. #include <linux/string.h>
  10. #include <asm/ctl_reg.h>
  11. #include <asm/fpu/types.h>
  12. static inline void save_vx_regs_safe(__vector128 *vxrs)
  13. {
  14. unsigned long cr0, flags;
  15. flags = arch_local_irq_save();
  16. __ctl_store(cr0, 0, 0);
  17. __ctl_set_bit(0, 17);
  18. __ctl_set_bit(0, 18);
  19. asm volatile(
  20. " la 1,%0\n"
  21. " .word 0xe70f,0x1000,0x003e\n" /* vstm 0,15,0(1) */
  22. " .word 0xe70f,0x1100,0x0c3e\n" /* vstm 16,31,256(1) */
  23. : "=Q" (*(struct vx_array *) vxrs) : : "1");
  24. __ctl_load(cr0, 0, 0);
  25. arch_local_irq_restore(flags);
  26. }
  27. static inline void convert_vx_to_fp(freg_t *fprs, __vector128 *vxrs)
  28. {
  29. int i;
  30. for (i = 0; i < __NUM_FPRS; i++)
  31. fprs[i] = *(freg_t *)(vxrs + i);
  32. }
  33. static inline void convert_fp_to_vx(__vector128 *vxrs, freg_t *fprs)
  34. {
  35. int i;
  36. for (i = 0; i < __NUM_FPRS; i++)
  37. *(freg_t *)(vxrs + i) = fprs[i];
  38. }
  39. static inline void fpregs_store(_s390_fp_regs *fpregs, struct fpu *fpu)
  40. {
  41. fpregs->pad = 0;
  42. if (MACHINE_HAS_VX)
  43. convert_vx_to_fp((freg_t *)&fpregs->fprs, fpu->vxrs);
  44. else
  45. memcpy((freg_t *)&fpregs->fprs, fpu->fprs,
  46. sizeof(fpregs->fprs));
  47. }
  48. static inline void fpregs_load(_s390_fp_regs *fpregs, struct fpu *fpu)
  49. {
  50. if (MACHINE_HAS_VX)
  51. convert_fp_to_vx(fpu->vxrs, (freg_t *)&fpregs->fprs);
  52. else
  53. memcpy(fpu->fprs, (freg_t *)&fpregs->fprs,
  54. sizeof(fpregs->fprs));
  55. }
  56. #endif /* _ASM_S390_FPU_INTERNAL_H */