fpu.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (C) 2002 MontaVista Software Inc.
  3. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #ifndef _ASM_FPU_H
  11. #define _ASM_FPU_H
  12. #include <linux/sched.h>
  13. #include <linux/thread_info.h>
  14. #include <asm/mipsregs.h>
  15. #include <asm/cpu.h>
  16. #include <asm/cpu-features.h>
  17. #include <asm/hazards.h>
  18. #include <asm/bitops.h>
  19. #include <asm/processor.h>
  20. #include <asm/current.h>
  21. #ifdef CONFIG_MIPS_MT_FPAFF
  22. #include <asm/mips_mt.h>
  23. #endif
  24. struct sigcontext;
  25. struct sigcontext32;
  26. extern asmlinkage int (*save_fp_context)(struct sigcontext __user *sc);
  27. extern asmlinkage int (*restore_fp_context)(struct sigcontext __user *sc);
  28. extern asmlinkage int (*save_fp_context32)(struct sigcontext32 __user *sc);
  29. extern asmlinkage int (*restore_fp_context32)(struct sigcontext32 __user *sc);
  30. extern void fpu_emulator_init_fpu(void);
  31. extern void _init_fpu(void);
  32. extern void _save_fp(struct task_struct *);
  33. extern void _restore_fp(struct task_struct *);
  34. #define __enable_fpu() \
  35. do { \
  36. set_c0_status(ST0_CU1); \
  37. enable_fpu_hazard(); \
  38. } while (0)
  39. #define __disable_fpu() \
  40. do { \
  41. clear_c0_status(ST0_CU1); \
  42. disable_fpu_hazard(); \
  43. } while (0)
  44. #define enable_fpu() \
  45. do { \
  46. if (cpu_has_fpu) \
  47. __enable_fpu(); \
  48. } while (0)
  49. #define disable_fpu() \
  50. do { \
  51. if (cpu_has_fpu) \
  52. __disable_fpu(); \
  53. } while (0)
  54. #define clear_fpu_owner() clear_thread_flag(TIF_USEDFPU)
  55. static inline int __is_fpu_owner(void)
  56. {
  57. return test_thread_flag(TIF_USEDFPU);
  58. }
  59. static inline int is_fpu_owner(void)
  60. {
  61. return cpu_has_fpu && __is_fpu_owner();
  62. }
  63. static inline void __own_fpu(void)
  64. {
  65. __enable_fpu();
  66. KSTK_STATUS(current) |= ST0_CU1;
  67. set_thread_flag(TIF_USEDFPU);
  68. }
  69. static inline void own_fpu_inatomic(int restore)
  70. {
  71. if (cpu_has_fpu && !__is_fpu_owner()) {
  72. __own_fpu();
  73. if (restore)
  74. _restore_fp(current);
  75. }
  76. }
  77. static inline void own_fpu(int restore)
  78. {
  79. preempt_disable();
  80. own_fpu_inatomic(restore);
  81. preempt_enable();
  82. }
  83. static inline void lose_fpu(int save)
  84. {
  85. preempt_disable();
  86. if (is_fpu_owner()) {
  87. if (save)
  88. _save_fp(current);
  89. KSTK_STATUS(current) &= ~ST0_CU1;
  90. clear_thread_flag(TIF_USEDFPU);
  91. __disable_fpu();
  92. }
  93. preempt_enable();
  94. }
  95. static inline void init_fpu(void)
  96. {
  97. preempt_disable();
  98. if (cpu_has_fpu) {
  99. __own_fpu();
  100. _init_fpu();
  101. } else {
  102. fpu_emulator_init_fpu();
  103. }
  104. preempt_enable();
  105. }
  106. static inline void save_fp(struct task_struct *tsk)
  107. {
  108. if (cpu_has_fpu)
  109. _save_fp(tsk);
  110. }
  111. static inline void restore_fp(struct task_struct *tsk)
  112. {
  113. if (cpu_has_fpu)
  114. _restore_fp(tsk);
  115. }
  116. static inline fpureg_t *get_fpu_regs(struct task_struct *tsk)
  117. {
  118. if (tsk == current) {
  119. preempt_disable();
  120. if (is_fpu_owner())
  121. _save_fp(current);
  122. preempt_enable();
  123. }
  124. return tsk->thread.fpu.fpr;
  125. }
  126. #endif /* _ASM_FPU_H */