switch_to.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #include <asm/fpu.h>
  19. struct task_struct;
  20. /**
  21. * resume - resume execution of a task
  22. * @prev: The task previously executed.
  23. * @next: The task to begin executing.
  24. * @next_ti: task_thread_info(next).
  25. *
  26. * This function is used whilst scheduling to save the context of prev & load
  27. * the context of next. Returns prev.
  28. */
  29. extern asmlinkage struct task_struct *resume(struct task_struct *prev,
  30. struct task_struct *next, struct thread_info *next_ti);
  31. extern unsigned int ll_bit;
  32. extern struct task_struct *ll_task;
  33. #ifdef CONFIG_MIPS_MT_FPAFF
  34. /*
  35. * Handle the scheduler resume end of FPU affinity management. We do this
  36. * inline to try to keep the overhead down. If we have been forced to run on
  37. * a "CPU" with an FPU because of a previous high level of FP computation,
  38. * but did not actually use the FPU during the most recent time-slice (CU1
  39. * isn't set), we undo the restriction on cpus_allowed.
  40. *
  41. * We're not calling set_cpus_allowed() here, because we have no need to
  42. * force prompt migration - we're already switching the current CPU to a
  43. * different thread.
  44. */
  45. #define __mips_mt_fpaff_switch_to(prev) \
  46. do { \
  47. struct thread_info *__prev_ti = task_thread_info(prev); \
  48. \
  49. if (cpu_has_fpu && \
  50. test_ti_thread_flag(__prev_ti, TIF_FPUBOUND) && \
  51. (!(KSTK_STATUS(prev) & ST0_CU1))) { \
  52. clear_ti_thread_flag(__prev_ti, TIF_FPUBOUND); \
  53. prev->cpus_allowed = prev->thread.user_cpus_allowed; \
  54. } \
  55. next->thread.emulated_fp = 0; \
  56. } while(0)
  57. #else
  58. #define __mips_mt_fpaff_switch_to(prev) do { (void) (prev); } while (0)
  59. #endif
  60. /*
  61. * Clear LLBit during context switches on MIPSr6 such that eretnc can be used
  62. * unconditionally when returning to userland in entry.S.
  63. */
  64. #define __clear_r6_hw_ll_bit() do { \
  65. if (cpu_has_mips_r6) \
  66. write_c0_lladdr(0); \
  67. } while (0)
  68. #define __clear_software_ll_bit() do { \
  69. if (!__builtin_constant_p(cpu_has_llsc) || !cpu_has_llsc) \
  70. ll_bit = 0; \
  71. } while (0)
  72. /*
  73. * Check FCSR for any unmasked exceptions pending set with `ptrace',
  74. * clear them and send a signal.
  75. */
  76. #define __sanitize_fcr31(next) \
  77. do { \
  78. unsigned long fcr31 = mask_fcr31_x(next->thread.fpu.fcr31); \
  79. void __user *pc; \
  80. \
  81. if (unlikely(fcr31)) { \
  82. pc = (void __user *)task_pt_regs(next)->cp0_epc; \
  83. next->thread.fpu.fcr31 &= ~fcr31; \
  84. force_fcr31_sig(fcr31, pc, next); \
  85. } \
  86. } while (0)
  87. /*
  88. * For newly created kernel threads switch_to() will return to
  89. * ret_from_kernel_thread, newly created user threads to ret_from_fork.
  90. * That is, everything following resume() will be skipped for new threads.
  91. * So everything that matters to new threads should be placed before resume().
  92. */
  93. #define switch_to(prev, next, last) \
  94. do { \
  95. __mips_mt_fpaff_switch_to(prev); \
  96. lose_fpu_inatomic(1, prev); \
  97. if (tsk_used_math(next)) \
  98. __sanitize_fcr31(next); \
  99. if (cpu_has_dsp) { \
  100. __save_dsp(prev); \
  101. __restore_dsp(next); \
  102. } \
  103. if (cop2_present) { \
  104. set_c0_status(ST0_CU2); \
  105. if ((KSTK_STATUS(prev) & ST0_CU2)) { \
  106. if (cop2_lazy_restore) \
  107. KSTK_STATUS(prev) &= ~ST0_CU2; \
  108. cop2_save(prev); \
  109. } \
  110. if (KSTK_STATUS(next) & ST0_CU2 && \
  111. !cop2_lazy_restore) { \
  112. cop2_restore(next); \
  113. } \
  114. clear_c0_status(ST0_CU2); \
  115. } \
  116. __clear_r6_hw_ll_bit(); \
  117. __clear_software_ll_bit(); \
  118. if (cpu_has_userlocal) \
  119. write_c0_userlocal(task_thread_info(next)->tp_value); \
  120. __restore_watch(next); \
  121. (last) = resume(prev, next, task_thread_info(next)); \
  122. } while (0)
  123. #endif /* _ASM_SWITCH_TO_H */