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
6 * Copyright (C) 2003, 04, 07 Ralf Baechle <ralf@linux-mips.org>
7 * Copyright (C) MIPS Technologies, Inc.
8 * written by Ralf Baechle <ralf@linux-mips.org>
10 #ifndef _ASM_HAZARDS_H
11 #define _ASM_HAZARDS_H
13 #include <linux/stringify.h>
14 #include <asm/compiler.h>
25 #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) && !defined(CONFIG_CPU_CAVIUM_OCTEON)
28 * MIPSR2 defines ehb for hazard avoidance
31 #define __mtc0_tlbw_hazard \
34 #define __tlbw_use_hazard \
37 #define __tlb_probe_hazard \
40 #define __irq_enable_hazard \
43 #define __irq_disable_hazard \
46 #define __back_to_back_c0_hazard \
50 * gcc has a tradition of misscompiling the previous construct using the
51 * address of a label as argument to inline assembler. Gas otoh has the
52 * annoying difference between la and dla which are only usable for 32-bit
53 * rsp. 64-bit code, so can't be used without conditional compilation.
54 * The alterantive is switching the assembler to 64-bit code which happens
55 * to work right even for 32-bit code ...
57 #define instruction_hazard() \
61 __asm__ __volatile__( \
62 " .set "MIPS_ISA_LEVEL" \n" \
70 #elif (defined(CONFIG_CPU_MIPSR1) && !defined(CONFIG_MIPS_ALCHEMY)) || \
71 defined(CONFIG_CPU_BMIPS)
74 * These are slightly complicated by the fact that we guarantee R1 kernels to
75 * run fine on R2 processors.
78 #define __mtc0_tlbw_hazard \
83 #define __tlbw_use_hazard \
89 #define __tlb_probe_hazard \
95 #define __irq_enable_hazard \
101 #define __irq_disable_hazard \
107 #define __back_to_back_c0_hazard \
114 * gcc has a tradition of misscompiling the previous construct using the
115 * address of a label as argument to inline assembler. Gas otoh has the
116 * annoying difference between la and dla which are only usable for 32-bit
117 * rsp. 64-bit code, so can't be used without conditional compilation.
118 * The alterantive is switching the assembler to 64-bit code which happens
119 * to work right even for 32-bit code ...
121 #define __instruction_hazard() \
125 __asm__ __volatile__( \
126 " .set mips64r2 \n" \
134 #define instruction_hazard() \
136 if (cpu_has_mips_r2_r6) \
137 __instruction_hazard(); \
140 #elif defined(CONFIG_MIPS_ALCHEMY) || defined(CONFIG_CPU_CAVIUM_OCTEON) || \
141 defined(CONFIG_CPU_LOONGSON2) || defined(CONFIG_CPU_R10000) || \
142 defined(CONFIG_CPU_R5500) || defined(CONFIG_CPU_XLR)
145 * R10000 rocks - all hazards handled in hardware, so this becomes a nobrainer.
148 #define __mtc0_tlbw_hazard
150 #define __tlbw_use_hazard
152 #define __tlb_probe_hazard
154 #define __irq_enable_hazard
156 #define __irq_disable_hazard
158 #define __back_to_back_c0_hazard
160 #define instruction_hazard() do { } while (0)
162 #elif defined(CONFIG_CPU_SB1)
165 * Mostly like R4000 for historic reasons
167 #define __mtc0_tlbw_hazard
169 #define __tlbw_use_hazard
171 #define __tlb_probe_hazard
173 #define __irq_enable_hazard
175 #define __irq_disable_hazard \
180 #define __back_to_back_c0_hazard
182 #define instruction_hazard() do { } while (0)
187 * Finally the catchall case for all other processors including R4000, R4400,
188 * R4600, R4700, R5000, RM7000, NEC VR41xx etc.
190 * The taken branch will result in a two cycle penalty for the two killed
191 * instructions on R4000 / R4400. Other processors only have a single cycle
192 * hazard so this is nice trick to have an optimal code for a range of
195 #define __mtc0_tlbw_hazard \
199 #define __tlbw_use_hazard \
204 #define __tlb_probe_hazard \
209 #define __irq_enable_hazard \
214 #define __irq_disable_hazard \
219 #define __back_to_back_c0_hazard \
224 #define instruction_hazard() do { } while (0)
231 #if defined(CONFIG_CPU_SB1)
233 #define __enable_fpu_hazard \
242 #define __disable_fpu_hazard
244 #elif defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6)
246 #define __enable_fpu_hazard \
249 #define __disable_fpu_hazard \
254 #define __enable_fpu_hazard \
260 #define __disable_fpu_hazard \
267 #define _ssnop ___ssnop
269 #define mtc0_tlbw_hazard __mtc0_tlbw_hazard
270 #define tlbw_use_hazard __tlbw_use_hazard
271 #define tlb_probe_hazard __tlb_probe_hazard
272 #define irq_enable_hazard __irq_enable_hazard
273 #define irq_disable_hazard __irq_disable_hazard
274 #define back_to_back_c0_hazard __back_to_back_c0_hazard
275 #define enable_fpu_hazard __enable_fpu_hazard
276 #define disable_fpu_hazard __disable_fpu_hazard
282 __asm__ __volatile__( \
283 __stringify(___ssnop) \
289 __asm__ __volatile__( \
290 __stringify(___ehb) \
295 #define mtc0_tlbw_hazard() \
297 __asm__ __volatile__( \
298 __stringify(__mtc0_tlbw_hazard) \
303 #define tlbw_use_hazard() \
305 __asm__ __volatile__( \
306 __stringify(__tlbw_use_hazard) \
311 #define tlb_probe_hazard() \
313 __asm__ __volatile__( \
314 __stringify(__tlb_probe_hazard) \
319 #define irq_enable_hazard() \
321 __asm__ __volatile__( \
322 __stringify(__irq_enable_hazard) \
327 #define irq_disable_hazard() \
329 __asm__ __volatile__( \
330 __stringify(__irq_disable_hazard) \
335 #define back_to_back_c0_hazard() \
337 __asm__ __volatile__( \
338 __stringify(__back_to_back_c0_hazard) \
343 #define enable_fpu_hazard() \
345 __asm__ __volatile__( \
346 __stringify(__enable_fpu_hazard) \
351 #define disable_fpu_hazard() \
353 __asm__ __volatile__( \
354 __stringify(__disable_fpu_hazard) \
359 * MIPS R2 instruction hazard barrier. Needs to be called as a subroutine.
361 extern void mips_ihb(void);
363 #endif /* __ASSEMBLY__ */
365 #endif /* _ASM_HAZARDS_H */