i387.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 1994 Linus Torvalds
  3. *
  4. * Pentium III FXSR, SSE support
  5. * General FPU state handling cleanups
  6. * Gareth Hughes <gareth@valinux.com>, May 2000
  7. * x86-64 work by Andi Kleen 2002
  8. */
  9. #ifndef _ASM_X86_I387_H
  10. #define _ASM_X86_I387_H
  11. #ifndef __ASSEMBLY__
  12. #include <linux/sched.h>
  13. #include <linux/hardirq.h>
  14. struct pt_regs;
  15. struct user_i387_struct;
  16. extern int init_fpu(struct task_struct *child);
  17. extern int dump_fpu(struct pt_regs *, struct user_i387_struct *);
  18. extern void math_state_restore(void);
  19. extern bool irq_fpu_usable(void);
  20. extern void kernel_fpu_begin(void);
  21. extern void kernel_fpu_end(void);
  22. /*
  23. * Some instructions like VIA's padlock instructions generate a spurious
  24. * DNA fault but don't modify SSE registers. And these instructions
  25. * get used from interrupt context as well. To prevent these kernel instructions
  26. * in interrupt context interacting wrongly with other user/kernel fpu usage, we
  27. * should use them only in the context of irq_ts_save/restore()
  28. */
  29. static inline int irq_ts_save(void)
  30. {
  31. /*
  32. * If in process context and not atomic, we can take a spurious DNA fault.
  33. * Otherwise, doing clts() in process context requires disabling preemption
  34. * or some heavy lifting like kernel_fpu_begin()
  35. */
  36. if (!in_atomic())
  37. return 0;
  38. if (read_cr0() & X86_CR0_TS) {
  39. clts();
  40. return 1;
  41. }
  42. return 0;
  43. }
  44. static inline void irq_ts_restore(int TS_state)
  45. {
  46. if (TS_state)
  47. stts();
  48. }
  49. /*
  50. * The question "does this thread have fpu access?"
  51. * is slightly racy, since preemption could come in
  52. * and revoke it immediately after the test.
  53. *
  54. * However, even in that very unlikely scenario,
  55. * we can just assume we have FPU access - typically
  56. * to save the FP state - we'll just take a #NM
  57. * fault and get the FPU access back.
  58. */
  59. static inline int user_has_fpu(void)
  60. {
  61. return current->thread.fpu.has_fpu;
  62. }
  63. extern void unlazy_fpu(struct task_struct *tsk);
  64. #endif /* __ASSEMBLY__ */
  65. #endif /* _ASM_X86_I387_H */