hazards.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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) 2003, 2004 Ralf Baechle
  7. */
  8. #ifndef _ASM_HAZARDS_H
  9. #define _ASM_HAZARDS_H
  10. #include <linux/config.h>
  11. #ifdef __ASSEMBLY__
  12. .macro _ssnop
  13. sll $0, $0, 1
  14. .endm
  15. .macro _ehb
  16. sll $0, $0, 3
  17. .endm
  18. /*
  19. * RM9000 hazards. When the JTLB is updated by tlbwi or tlbwr, a subsequent
  20. * use of the JTLB for instructions should not occur for 4 cpu cycles and use
  21. * for data translations should not occur for 3 cpu cycles.
  22. */
  23. #ifdef CONFIG_CPU_RM9000
  24. .macro mtc0_tlbw_hazard
  25. .set push
  26. .set mips32
  27. _ssnop; _ssnop; _ssnop; _ssnop
  28. .set pop
  29. .endm
  30. .macro tlbw_eret_hazard
  31. .set push
  32. .set mips32
  33. _ssnop; _ssnop; _ssnop; _ssnop
  34. .set pop
  35. .endm
  36. #else
  37. /*
  38. * The taken branch will result in a two cycle penalty for the two killed
  39. * instructions on R4000 / R4400. Other processors only have a single cycle
  40. * hazard so this is nice trick to have an optimal code for a range of
  41. * processors.
  42. */
  43. .macro mtc0_tlbw_hazard
  44. b . + 8
  45. .endm
  46. .macro tlbw_eret_hazard
  47. .endm
  48. #endif
  49. /*
  50. * mtc0->mfc0 hazard
  51. * The 24K has a 2 cycle mtc0/mfc0 execution hazard.
  52. * It is a MIPS32R2 processor so ehb will clear the hazard.
  53. */
  54. #ifdef CONFIG_CPU_MIPSR2
  55. /*
  56. * Use a macro for ehb unless explicit support for MIPSR2 is enabled
  57. */
  58. #define irq_enable_hazard
  59. _ehb
  60. #define irq_disable_hazard
  61. _ehb
  62. #elif defined(CONFIG_CPU_R10000) || defined(CONFIG_CPU_RM9000) || \
  63. defined(CONFIG_CPU_SB1)
  64. /*
  65. * R10000 rocks - all hazards handled in hardware, so this becomes a nobrainer.
  66. */
  67. #define irq_enable_hazard
  68. #define irq_disable_hazard
  69. #else
  70. /*
  71. * Classic MIPS needs 1 - 3 nops or ssnops
  72. */
  73. #define irq_enable_hazard
  74. #define irq_disable_hazard \
  75. _ssnop; _ssnop; _ssnop
  76. #endif
  77. #else /* __ASSEMBLY__ */
  78. __asm__(
  79. " .macro _ssnop \n\t"
  80. " sll $0, $0, 1 \n\t"
  81. " .endm \n\t"
  82. " \n\t"
  83. " .macro _ehb \n\t"
  84. " sll $0, $0, 3 \n\t"
  85. " .endm \n\t");
  86. #ifdef CONFIG_CPU_RM9000
  87. /*
  88. * RM9000 hazards. When the JTLB is updated by tlbwi or tlbwr, a subsequent
  89. * use of the JTLB for instructions should not occur for 4 cpu cycles and use
  90. * for data translations should not occur for 3 cpu cycles.
  91. */
  92. #define mtc0_tlbw_hazard() \
  93. __asm__ __volatile__( \
  94. ".set\tmips32\n\t" \
  95. "_ssnop; _ssnop; _ssnop; _ssnop\n\t" \
  96. ".set\tmips0")
  97. #define tlbw_use_hazard() \
  98. __asm__ __volatile__( \
  99. ".set\tmips32\n\t" \
  100. "_ssnop; _ssnop; _ssnop; _ssnop\n\t" \
  101. ".set\tmips0")
  102. #define back_to_back_c0_hazard() do { } while (0)
  103. #else
  104. /*
  105. * Overkill warning ...
  106. */
  107. #define mtc0_tlbw_hazard() \
  108. __asm__ __volatile__( \
  109. ".set noreorder\n\t" \
  110. "nop; nop; nop; nop; nop; nop;\n\t" \
  111. ".set reorder\n\t")
  112. #define tlbw_use_hazard() \
  113. __asm__ __volatile__( \
  114. ".set noreorder\n\t" \
  115. "nop; nop; nop; nop; nop; nop;\n\t" \
  116. ".set reorder\n\t")
  117. #endif
  118. /*
  119. * Interrupt enable/disable hazards
  120. * Some processors have hazards when modifying
  121. * the status register to change the interrupt state
  122. */
  123. #ifdef CONFIG_CPU_MIPSR2
  124. __asm__(
  125. " .macro\tirq_enable_hazard \n\t"
  126. " _ehb \n\t"
  127. " .endm \n\t"
  128. " \n\t"
  129. " .macro\tirq_disable_hazard \n\t"
  130. " _ehb \n\t"
  131. " .endm \n\t"
  132. " \n\t"
  133. " .macro\tback_to_back_c0_hazard \n\t"
  134. " _ehb \n\t"
  135. " .endm");
  136. #define irq_enable_hazard() \
  137. __asm__ __volatile__( \
  138. "irq_enable_hazard")
  139. #define irq_disable_hazard() \
  140. __asm__ __volatile__( \
  141. "irq_disable_hazard")
  142. #define back_to_back_c0_hazard() \
  143. __asm__ __volatile__( \
  144. "back_to_back_c0_hazard")
  145. #elif defined(CONFIG_CPU_R10000) || defined(CONFIG_CPU_RM9000) || \
  146. defined(CONFIG_CPU_SB1)
  147. /*
  148. * R10000 rocks - all hazards handled in hardware, so this becomes a nobrainer.
  149. */
  150. __asm__(
  151. " .macro\tirq_enable_hazard \n\t"
  152. " .endm \n\t"
  153. " \n\t"
  154. " .macro\tirq_disable_hazard \n\t"
  155. " .endm");
  156. #define irq_enable_hazard() do { } while (0)
  157. #define irq_disable_hazard() do { } while (0)
  158. #define back_to_back_c0_hazard() do { } while (0)
  159. #else
  160. /*
  161. * Default for classic MIPS processors. Assume worst case hazards but don't
  162. * care about the irq_enable_hazard - sooner or later the hardware will
  163. * enable it and we don't care when exactly.
  164. */
  165. __asm__(
  166. " # \n\t"
  167. " # There is a hazard but we do not care \n\t"
  168. " # \n\t"
  169. " .macro\tirq_enable_hazard \n\t"
  170. " .endm \n\t"
  171. " \n\t"
  172. " .macro\tirq_disable_hazard \n\t"
  173. " _ssnop; _ssnop; _ssnop \n\t"
  174. " .endm");
  175. #define irq_enable_hazard() do { } while (0)
  176. #define irq_disable_hazard() \
  177. __asm__ __volatile__( \
  178. "irq_disable_hazard")
  179. #define back_to_back_c0_hazard() \
  180. __asm__ __volatile__( \
  181. " .set noreorder \n" \
  182. " nop; nop; nop \n" \
  183. " .set reorder \n")
  184. #endif
  185. #ifdef CONFIG_CPU_MIPSR2
  186. /*
  187. * gcc has a tradition of misscompiling the previous construct using the
  188. * address of a label as argument to inline assembler. Gas otoh has the
  189. * annoying difference between la and dla which are only usable for 32-bit
  190. * rsp. 64-bit code, so can't be used without conditional compilation.
  191. * The alterantive is switching the assembler to 64-bit code which happens
  192. * to work right even for 32-bit code ...
  193. */
  194. #define instruction_hazard() \
  195. do { \
  196. unsigned long tmp; \
  197. \
  198. __asm__ __volatile__( \
  199. " .set mips64r2 \n" \
  200. " dla %0, 1f \n" \
  201. " jr.hb %0 \n" \
  202. " .set mips0 \n" \
  203. "1: \n" \
  204. : "=r" (tmp)); \
  205. } while (0)
  206. #else
  207. #define instruction_hazard() do { } while (0)
  208. #endif
  209. #endif /* __ASSEMBLY__ */
  210. #endif /* _ASM_HAZARDS_H */