fpu.h 2.8 KB

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