switch_to.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994, 95, 96, 97, 98, 99, 2003, 06 by Ralf Baechle
  7. * Copyright (C) 1996 by Paul M. Antoine
  8. * Copyright (C) 1999 Silicon Graphics
  9. * Kevin D. Kissell, kevink@mips.org and Carsten Langgaard, carstenl@mips.com
  10. * Copyright (C) 2000 MIPS Technologies, Inc.
  11. */
  12. #ifndef _ASM_SWITCH_TO_H
  13. #define _ASM_SWITCH_TO_H
  14. #include <asm/cpu-features.h>
  15. #include <asm/watch.h>
  16. #include <asm/dsp.h>
  17. #include <asm/cop2.h>
  18. struct task_struct;
  19. /*
  20. * switch_to(n) should switch tasks to task nr n, first
  21. * checking that n isn't the current task, in which case it does nothing.
  22. */
  23. extern asmlinkage void *resume(void *last, void *next, void *next_ti, u32 __usedfpu);
  24. extern unsigned int ll_bit;
  25. extern struct task_struct *ll_task;
  26. #ifdef CONFIG_MIPS_MT_FPAFF
  27. /*
  28. * Handle the scheduler resume end of FPU affinity management. We do this
  29. * inline to try to keep the overhead down. If we have been forced to run on
  30. * a "CPU" with an FPU because of a previous high level of FP computation,
  31. * but did not actually use the FPU during the most recent time-slice (CU1
  32. * isn't set), we undo the restriction on cpus_allowed.
  33. *
  34. * We're not calling set_cpus_allowed() here, because we have no need to
  35. * force prompt migration - we're already switching the current CPU to a
  36. * different thread.
  37. */
  38. #define __mips_mt_fpaff_switch_to(prev) \
  39. do { \
  40. struct thread_info *__prev_ti = task_thread_info(prev); \
  41. \
  42. if (cpu_has_fpu && \
  43. test_ti_thread_flag(__prev_ti, TIF_FPUBOUND) && \
  44. (!(KSTK_STATUS(prev) & ST0_CU1))) { \
  45. clear_ti_thread_flag(__prev_ti, TIF_FPUBOUND); \
  46. prev->cpus_allowed = prev->thread.user_cpus_allowed; \
  47. } \
  48. next->thread.emulated_fp = 0; \
  49. } while(0)
  50. #else
  51. #define __mips_mt_fpaff_switch_to(prev) do { (void) (prev); } while (0)
  52. #endif
  53. #define __clear_software_ll_bit() \
  54. do { \
  55. if (!__builtin_constant_p(cpu_has_llsc) || !cpu_has_llsc) \
  56. ll_bit = 0; \
  57. } while (0)
  58. #define switch_to(prev, next, last) \
  59. do { \
  60. u32 __usedfpu, __c0_stat; \
  61. __mips_mt_fpaff_switch_to(prev); \
  62. if (cpu_has_dsp) \
  63. __save_dsp(prev); \
  64. if (cop2_present && (KSTK_STATUS(prev) & ST0_CU2)) { \
  65. if (cop2_lazy_restore) \
  66. KSTK_STATUS(prev) &= ~ST0_CU2; \
  67. __c0_stat = read_c0_status(); \
  68. write_c0_status(__c0_stat | ST0_CU2); \
  69. cop2_save(&prev->thread.cp2); \
  70. write_c0_status(__c0_stat & ~ST0_CU2); \
  71. } \
  72. __clear_software_ll_bit(); \
  73. __usedfpu = test_and_clear_tsk_thread_flag(prev, TIF_USEDFPU); \
  74. (last) = resume(prev, next, task_thread_info(next), __usedfpu); \
  75. } while (0)
  76. #define finish_arch_switch(prev) \
  77. do { \
  78. u32 __c0_stat; \
  79. if (cop2_present && !cop2_lazy_restore && \
  80. (KSTK_STATUS(current) & ST0_CU2)) { \
  81. __c0_stat = read_c0_status(); \
  82. write_c0_status(__c0_stat | ST0_CU2); \
  83. cop2_restore(&current->thread.cp2); \
  84. write_c0_status(__c0_stat & ~ST0_CU2); \
  85. } \
  86. if (cpu_has_dsp) \
  87. __restore_dsp(current); \
  88. if (cpu_has_userlocal) \
  89. write_c0_userlocal(current_thread_info()->tp_value); \
  90. __restore_watch(); \
  91. } while (0)
  92. #endif /* _ASM_SWITCH_TO_H */