fpu.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 <linux/bitops.h>
  15. #include <asm/mipsregs.h>
  16. #include <asm/cpu.h>
  17. #include <asm/cpu-features.h>
  18. #include <asm/hazards.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 int fpu_emulator_save_context(struct sigcontext __user *sc);
  32. extern int fpu_emulator_restore_context(struct sigcontext __user *sc);
  33. extern void _init_fpu(void);
  34. extern void _save_fp(struct task_struct *);
  35. extern void _restore_fp(struct task_struct *);
  36. #define __enable_fpu() \
  37. do { \
  38. set_c0_status(ST0_CU1); \
  39. enable_fpu_hazard(); \
  40. } while (0)
  41. #define __disable_fpu() \
  42. do { \
  43. clear_c0_status(ST0_CU1); \
  44. disable_fpu_hazard(); \
  45. } while (0)
  46. #define enable_fpu() \
  47. do { \
  48. if (cpu_has_fpu) \
  49. __enable_fpu(); \
  50. } while (0)
  51. #define disable_fpu() \
  52. do { \
  53. if (cpu_has_fpu) \
  54. __disable_fpu(); \
  55. } while (0)
  56. #define clear_fpu_owner() clear_thread_flag(TIF_USEDFPU)
  57. static inline int __is_fpu_owner(void)
  58. {
  59. return test_thread_flag(TIF_USEDFPU);
  60. }
  61. static inline int is_fpu_owner(void)
  62. {
  63. return cpu_has_fpu && __is_fpu_owner();
  64. }
  65. static inline void __own_fpu(void)
  66. {
  67. __enable_fpu();
  68. KSTK_STATUS(current) |= ST0_CU1;
  69. set_thread_flag(TIF_USEDFPU);
  70. }
  71. static inline void own_fpu_inatomic(int restore)
  72. {
  73. if (cpu_has_fpu && !__is_fpu_owner()) {
  74. __own_fpu();
  75. if (restore)
  76. _restore_fp(current);
  77. }
  78. }
  79. static inline void own_fpu(int restore)
  80. {
  81. preempt_disable();
  82. own_fpu_inatomic(restore);
  83. preempt_enable();
  84. }
  85. static inline void lose_fpu(int save)
  86. {
  87. preempt_disable();
  88. if (is_fpu_owner()) {
  89. if (save)
  90. _save_fp(current);
  91. KSTK_STATUS(current) &= ~ST0_CU1;
  92. clear_thread_flag(TIF_USEDFPU);
  93. __disable_fpu();
  94. }
  95. preempt_enable();
  96. }
  97. static inline void init_fpu(void)
  98. {
  99. preempt_disable();
  100. if (cpu_has_fpu) {
  101. __own_fpu();
  102. _init_fpu();
  103. } else {
  104. fpu_emulator_init_fpu();
  105. }
  106. preempt_enable();
  107. }
  108. static inline void save_fp(struct task_struct *tsk)
  109. {
  110. if (cpu_has_fpu)
  111. _save_fp(tsk);
  112. }
  113. static inline void restore_fp(struct task_struct *tsk)
  114. {
  115. if (cpu_has_fpu)
  116. _restore_fp(tsk);
  117. }
  118. static inline fpureg_t *get_fpu_regs(struct task_struct *tsk)
  119. {
  120. if (tsk == current) {
  121. preempt_disable();
  122. if (is_fpu_owner())
  123. _save_fp(current);
  124. preempt_enable();
  125. }
  126. return tsk->thread.fpu.fpr;
  127. }
  128. #endif /* _ASM_FPU_H */