blob: 6a5fa32f615bc24e63ed4278267ce3160185c5e5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Ralf Baechle98de9202007-07-28 00:49:58 +01006 * Copyright (C) 2003, 04, 07 Ralf Baechle <ralf@linux-mips.org>
Ralf Baechlea3c49462006-03-13 16:16:29 +00007 * Copyright (C) MIPS Technologies, Inc.
8 * written by Ralf Baechle <ralf@linux-mips.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10#ifndef _ASM_HAZARDS_H
11#define _ASM_HAZARDS_H
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Ralf Baechle36396f32006-09-25 15:49:49 +010014#ifdef __ASSEMBLY__
Ralf Baechled7d86aa2006-09-08 04:13:49 +020015#define ASMMACRO(name, code...) .macro name; code; .endm
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#else
17
Ralf Baechled7d86aa2006-09-08 04:13:49 +020018#define ASMMACRO(name, code...) \
19__asm__(".macro " #name "; " #code "; .endm"); \
20 \
21static inline void name(void) \
22{ \
23 __asm__ __volatile__ (#name); \
24}
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Ralf Baechle98de9202007-07-28 00:49:58 +010026/*
27 * MIPS R2 instruction hazard barrier. Needs to be called as a subroutine.
28 */
29extern void mips_ihb(void);
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#endif
32
Ralf Baechled7d86aa2006-09-08 04:13:49 +020033ASMMACRO(_ssnop,
34 sll $0, $0, 1
35 )
36
37ASMMACRO(_ehb,
38 sll $0, $0, 3
39 )
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041/*
Ralf Baechled7d86aa2006-09-08 04:13:49 +020042 * TLB hazards
43 */
44#if defined(CONFIG_CPU_MIPSR2)
45
46/*
47 * MIPSR2 defines ehb for hazard avoidance
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 */
49
Ralf Baechled7d86aa2006-09-08 04:13:49 +020050ASMMACRO(mtc0_tlbw_hazard,
51 _ehb
52 )
53ASMMACRO(tlbw_use_hazard,
54 _ehb
55 )
56ASMMACRO(tlb_probe_hazard,
57 _ehb
58 )
59ASMMACRO(irq_enable_hazard,
Ralf Baechle7605b392007-03-20 13:56:50 +000060 _ehb
Ralf Baechled7d86aa2006-09-08 04:13:49 +020061 )
62ASMMACRO(irq_disable_hazard,
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 _ehb
Ralf Baechled7d86aa2006-09-08 04:13:49 +020064 )
65ASMMACRO(back_to_back_c0_hazard,
66 _ehb
67 )
Ralf Baechle7043ad42005-12-22 13:41:29 +010068/*
69 * gcc has a tradition of misscompiling the previous construct using the
70 * address of a label as argument to inline assembler. Gas otoh has the
71 * annoying difference between la and dla which are only usable for 32-bit
72 * rsp. 64-bit code, so can't be used without conditional compilation.
73 * The alterantive is switching the assembler to 64-bit code which happens
74 * to work right even for 32-bit code ...
75 */
Ralf Baechlecc61c1f2005-07-12 18:35:38 +000076#define instruction_hazard() \
77do { \
Ralf Baechle7043ad42005-12-22 13:41:29 +010078 unsigned long tmp; \
79 \
Ralf Baechlecc61c1f2005-07-12 18:35:38 +000080 __asm__ __volatile__( \
Ralf Baechle7043ad42005-12-22 13:41:29 +010081 " .set mips64r2 \n" \
82 " dla %0, 1f \n" \
Ralf Baechlecc61c1f2005-07-12 18:35:38 +000083 " jr.hb %0 \n" \
Ralf Baechle7043ad42005-12-22 13:41:29 +010084 " .set mips0 \n" \
85 "1: \n" \
86 : "=r" (tmp)); \
Ralf Baechlecc61c1f2005-07-12 18:35:38 +000087} while (0)
88
Ralf Baechled7d86aa2006-09-08 04:13:49 +020089#elif defined(CONFIG_CPU_R10000)
90
91/*
92 * R10000 rocks - all hazards handled in hardware, so this becomes a nobrainer.
93 */
94
95ASMMACRO(mtc0_tlbw_hazard,
96 )
97ASMMACRO(tlbw_use_hazard,
98 )
99ASMMACRO(tlb_probe_hazard,
100 )
101ASMMACRO(irq_enable_hazard,
102 )
103ASMMACRO(irq_disable_hazard,
104 )
105ASMMACRO(back_to_back_c0_hazard,
106 )
Ralf Baechlecc61c1f2005-07-12 18:35:38 +0000107#define instruction_hazard() do { } while (0)
Ralf Baechled7d86aa2006-09-08 04:13:49 +0200108
109#elif defined(CONFIG_CPU_RM9000)
110
111/*
112 * RM9000 hazards. When the JTLB is updated by tlbwi or tlbwr, a subsequent
113 * use of the JTLB for instructions should not occur for 4 cpu cycles and use
114 * for data translations should not occur for 3 cpu cycles.
115 */
116
117ASMMACRO(mtc0_tlbw_hazard,
118 _ssnop; _ssnop; _ssnop; _ssnop
119 )
120ASMMACRO(tlbw_use_hazard,
121 _ssnop; _ssnop; _ssnop; _ssnop
122 )
123ASMMACRO(tlb_probe_hazard,
124 _ssnop; _ssnop; _ssnop; _ssnop
125 )
126ASMMACRO(irq_enable_hazard,
127 )
128ASMMACRO(irq_disable_hazard,
129 )
130ASMMACRO(back_to_back_c0_hazard,
131 )
132#define instruction_hazard() do { } while (0)
133
134#elif defined(CONFIG_CPU_SB1)
135
136/*
137 * Mostly like R4000 for historic reasons
138 */
139ASMMACRO(mtc0_tlbw_hazard,
140 )
141ASMMACRO(tlbw_use_hazard,
142 )
143ASMMACRO(tlb_probe_hazard,
144 )
145ASMMACRO(irq_enable_hazard,
146 )
147ASMMACRO(irq_disable_hazard,
148 _ssnop; _ssnop; _ssnop
149 )
150ASMMACRO(back_to_back_c0_hazard,
151 )
152#define instruction_hazard() do { } while (0)
153
154#else
155
156/*
157 * Finally the catchall case for all other processors including R4000, R4400,
158 * R4600, R4700, R5000, RM7000, NEC VR41xx etc.
159 *
160 * The taken branch will result in a two cycle penalty for the two killed
161 * instructions on R4000 / R4400. Other processors only have a single cycle
162 * hazard so this is nice trick to have an optimal code for a range of
163 * processors.
164 */
165ASMMACRO(mtc0_tlbw_hazard,
Yoichi Yuasa3f318372007-01-24 22:22:06 +0900166 nop; nop
Ralf Baechled7d86aa2006-09-08 04:13:49 +0200167 )
168ASMMACRO(tlbw_use_hazard,
169 nop; nop; nop
170 )
171ASMMACRO(tlb_probe_hazard,
172 nop; nop; nop
173 )
174ASMMACRO(irq_enable_hazard,
Ralf Baechle7b0fdaa2007-09-03 16:22:26 +0200175 _ssnop; _ssnop; _ssnop;
Ralf Baechled7d86aa2006-09-08 04:13:49 +0200176 )
177ASMMACRO(irq_disable_hazard,
178 nop; nop; nop
179 )
180ASMMACRO(back_to_back_c0_hazard,
181 _ssnop; _ssnop; _ssnop;
182 )
183#define instruction_hazard() do { } while (0)
184
Ralf Baechlecc61c1f2005-07-12 18:35:38 +0000185#endif
186
Chris Dearman0b624952007-05-08 16:09:13 +0100187
188/* FPU hazards */
189
190#if defined(CONFIG_CPU_SB1)
191ASMMACRO(enable_fpu_hazard,
192 .set push;
193 .set mips64;
194 .set noreorder;
195 _ssnop;
196 bnezl $0,.+4;
Ralf Baechlea1b53a72007-05-09 17:49:53 +0100197 _ssnop;
Chris Dearman0b624952007-05-08 16:09:13 +0100198 .set pop
199)
200ASMMACRO(disable_fpu_hazard,
201)
202
203#elif defined(CONFIG_CPU_MIPSR2)
204ASMMACRO(enable_fpu_hazard,
205 _ehb
206)
207ASMMACRO(disable_fpu_hazard,
208 _ehb
209)
210#else
211ASMMACRO(enable_fpu_hazard,
212 nop; nop; nop; nop
213)
214ASMMACRO(disable_fpu_hazard,
215 _ehb
216)
217#endif
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219#endif /* _ASM_HAZARDS_H */