switch_to.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #define __clear_software_ll_bit() \
  61. do { if (cpu_has_rw_llb) { \
  62. write_c0_lladdr(0); \
  63. } else { \
  64. if (!__builtin_constant_p(cpu_has_llsc) || !cpu_has_llsc)\
  65. ll_bit = 0; \
  66. } \
  67. } while (0)
  68. /*
  69. * Check FCSR for any unmasked exceptions pending set with `ptrace',
  70. * clear them and send a signal.
  71. */
  72. #define __sanitize_fcr31(next) \
  73. do { \
  74. unsigned long fcr31 = mask_fcr31_x(next->thread.fpu.fcr31); \
  75. void __user *pc; \
  76. \
  77. if (unlikely(fcr31)) { \
  78. pc = (void __user *)task_pt_regs(next)->cp0_epc; \
  79. next->thread.fpu.fcr31 &= ~fcr31; \
  80. force_fcr31_sig(fcr31, pc, next); \
  81. } \
  82. } while (0)
  83. /*
  84. * For newly created kernel threads switch_to() will return to
  85. * ret_from_kernel_thread, newly created user threads to ret_from_fork.
  86. * That is, everything following resume() will be skipped for new threads.
  87. * So everything that matters to new threads should be placed before resume().
  88. */
  89. #define switch_to(prev, next, last) \
  90. do { \
  91. __mips_mt_fpaff_switch_to(prev); \
  92. lose_fpu_inatomic(1, prev); \
  93. if (tsk_used_math(next)) \
  94. __sanitize_fcr31(next); \
  95. if (cpu_has_dsp) { \
  96. __save_dsp(prev); \
  97. __restore_dsp(next); \
  98. } \
  99. if (cop2_present) { \
  100. set_c0_status(ST0_CU2); \
  101. if ((KSTK_STATUS(prev) & ST0_CU2)) { \
  102. if (cop2_lazy_restore) \
  103. KSTK_STATUS(prev) &= ~ST0_CU2; \
  104. cop2_save(prev); \
  105. } \
  106. if (KSTK_STATUS(next) & ST0_CU2 && \
  107. !cop2_lazy_restore) { \
  108. cop2_restore(next); \
  109. } \
  110. clear_c0_status(ST0_CU2); \
  111. } \
  112. __clear_software_ll_bit(); \
  113. if (cpu_has_userlocal) \
  114. write_c0_userlocal(task_thread_info(next)->tp_value); \
  115. __restore_watch(next); \
  116. (last) = resume(prev, next, task_thread_info(next)); \
  117. } while (0)
  118. #endif /* _ASM_SWITCH_TO_H */