1 #ifndef __ASM_POWERPC_FEATURE_FIXUPS_H
2 #define __ASM_POWERPC_FEATURE_FIXUPS_H
3 
4 #include <asm/asm-const.h>
5 
6 /*
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version
10  * 2 of the License, or (at your option) any later version.
11  */
12 
13 /*
14  * Feature section common macros
15  *
16  * Note that the entries now contain offsets between the table entry
17  * and the code rather than absolute code pointers in order to be
18  * useable with the vdso shared library. There is also an assumption
19  * that values will be negative, that is, the fixup table has to be
20  * located after the code it fixes up.
21  */
22 #if defined(CONFIG_PPC64) && !defined(__powerpc64__)
23 /* 64 bits kernel, 32 bits code (ie. vdso32) */
24 #define FTR_ENTRY_LONG		.8byte
25 #define FTR_ENTRY_OFFSET	.long 0xffffffff; .long
26 #elif defined(CONFIG_PPC64)
27 #define FTR_ENTRY_LONG		.8byte
28 #define FTR_ENTRY_OFFSET	.8byte
29 #else
30 #define FTR_ENTRY_LONG		.long
31 #define FTR_ENTRY_OFFSET	.long
32 #endif
33 
34 #define START_FTR_SECTION(label)	label##1:
35 
36 #define FTR_SECTION_ELSE_NESTED(label)			\
37 label##2:						\
38 	.pushsection __ftr_alt_##label,"a";		\
39 	.align 2;					\
40 label##3:
41 
42 #define MAKE_FTR_SECTION_ENTRY(msk, val, label, sect)		\
43 label##4:							\
44 	.popsection;						\
45 	.pushsection sect,"a";					\
46 	.align 3;						\
47 label##5:							\
48 	FTR_ENTRY_LONG msk;					\
49 	FTR_ENTRY_LONG val;					\
50 	FTR_ENTRY_OFFSET label##1b-label##5b;			\
51 	FTR_ENTRY_OFFSET label##2b-label##5b;			\
52 	FTR_ENTRY_OFFSET label##3b-label##5b;			\
53 	FTR_ENTRY_OFFSET label##4b-label##5b;			\
54 	.ifgt (label##4b- label##3b)-(label##2b- label##1b);	\
55 	.error "Feature section else case larger than body";	\
56 	.endif;							\
57 	.popsection;
58 
59 
60 /* CPU feature dependent sections */
61 #define BEGIN_FTR_SECTION_NESTED(label)	START_FTR_SECTION(label)
62 #define BEGIN_FTR_SECTION		START_FTR_SECTION(97)
63 
64 #define END_FTR_SECTION_NESTED(msk, val, label) 		\
65 	FTR_SECTION_ELSE_NESTED(label)				\
66 	MAKE_FTR_SECTION_ENTRY(msk, val, label, __ftr_fixup)
67 
68 #define END_FTR_SECTION(msk, val)		\
69 	END_FTR_SECTION_NESTED(msk, val, 97)
70 
71 #define END_FTR_SECTION_NESTED_IFSET(msk, label)	\
72 	END_FTR_SECTION_NESTED((msk), (msk), label)
73 
74 #define END_FTR_SECTION_IFSET(msk)	END_FTR_SECTION((msk), (msk))
75 #define END_FTR_SECTION_IFCLR(msk)	END_FTR_SECTION((msk), 0)
76 
77 /* CPU feature sections with alternatives, use BEGIN_FTR_SECTION to start */
78 #define FTR_SECTION_ELSE	FTR_SECTION_ELSE_NESTED(97)
79 #define ALT_FTR_SECTION_END_NESTED(msk, val, label)	\
80 	MAKE_FTR_SECTION_ENTRY(msk, val, label, __ftr_fixup)
81 #define ALT_FTR_SECTION_END_NESTED_IFSET(msk, label)	\
82 	ALT_FTR_SECTION_END_NESTED(msk, msk, label)
83 #define ALT_FTR_SECTION_END_NESTED_IFCLR(msk, label)	\
84 	ALT_FTR_SECTION_END_NESTED(msk, 0, label)
85 #define ALT_FTR_SECTION_END(msk, val)	\
86 	ALT_FTR_SECTION_END_NESTED(msk, val, 97)
87 #define ALT_FTR_SECTION_END_IFSET(msk)	\
88 	ALT_FTR_SECTION_END_NESTED_IFSET(msk, 97)
89 #define ALT_FTR_SECTION_END_IFCLR(msk)	\
90 	ALT_FTR_SECTION_END_NESTED_IFCLR(msk, 97)
91 
92 /* MMU feature dependent sections */
93 #define BEGIN_MMU_FTR_SECTION_NESTED(label)	START_FTR_SECTION(label)
94 #define BEGIN_MMU_FTR_SECTION			START_FTR_SECTION(97)
95 
96 #define END_MMU_FTR_SECTION_NESTED(msk, val, label) 		\
97 	FTR_SECTION_ELSE_NESTED(label)				\
98 	MAKE_FTR_SECTION_ENTRY(msk, val, label, __mmu_ftr_fixup)
99 
100 #define END_MMU_FTR_SECTION(msk, val)		\
101 	END_MMU_FTR_SECTION_NESTED(msk, val, 97)
102 
103 #define END_MMU_FTR_SECTION_IFSET(msk)	END_MMU_FTR_SECTION((msk), (msk))
104 #define END_MMU_FTR_SECTION_IFCLR(msk)	END_MMU_FTR_SECTION((msk), 0)
105 
106 /* MMU feature sections with alternatives, use BEGIN_FTR_SECTION to start */
107 #define MMU_FTR_SECTION_ELSE_NESTED(label)	FTR_SECTION_ELSE_NESTED(label)
108 #define MMU_FTR_SECTION_ELSE	MMU_FTR_SECTION_ELSE_NESTED(97)
109 #define ALT_MMU_FTR_SECTION_END_NESTED(msk, val, label)	\
110 	MAKE_FTR_SECTION_ENTRY(msk, val, label, __mmu_ftr_fixup)
111 #define ALT_MMU_FTR_SECTION_END_NESTED_IFSET(msk, label)	\
112 	ALT_MMU_FTR_SECTION_END_NESTED(msk, msk, label)
113 #define ALT_MMU_FTR_SECTION_END_NESTED_IFCLR(msk, label)	\
114 	ALT_MMU_FTR_SECTION_END_NESTED(msk, 0, label)
115 #define ALT_MMU_FTR_SECTION_END(msk, val)	\
116 	ALT_MMU_FTR_SECTION_END_NESTED(msk, val, 97)
117 #define ALT_MMU_FTR_SECTION_END_IFSET(msk)	\
118 	ALT_MMU_FTR_SECTION_END_NESTED_IFSET(msk, 97)
119 #define ALT_MMU_FTR_SECTION_END_IFCLR(msk)	\
120 	ALT_MMU_FTR_SECTION_END_NESTED_IFCLR(msk, 97)
121 
122 /* Firmware feature dependent sections */
123 #define BEGIN_FW_FTR_SECTION_NESTED(label)	START_FTR_SECTION(label)
124 #define BEGIN_FW_FTR_SECTION			START_FTR_SECTION(97)
125 
126 #define END_FW_FTR_SECTION_NESTED(msk, val, label) 		\
127 	FTR_SECTION_ELSE_NESTED(label)				\
128 	MAKE_FTR_SECTION_ENTRY(msk, val, label, __fw_ftr_fixup)
129 
130 #define END_FW_FTR_SECTION(msk, val)		\
131 	END_FW_FTR_SECTION_NESTED(msk, val, 97)
132 
133 #define END_FW_FTR_SECTION_IFSET(msk)	END_FW_FTR_SECTION((msk), (msk))
134 #define END_FW_FTR_SECTION_IFCLR(msk)	END_FW_FTR_SECTION((msk), 0)
135 
136 /* Firmware feature sections with alternatives */
137 #define FW_FTR_SECTION_ELSE_NESTED(label)	FTR_SECTION_ELSE_NESTED(label)
138 #define FW_FTR_SECTION_ELSE	FTR_SECTION_ELSE_NESTED(97)
139 #define ALT_FW_FTR_SECTION_END_NESTED(msk, val, label)	\
140 	MAKE_FTR_SECTION_ENTRY(msk, val, label, __fw_ftr_fixup)
141 #define ALT_FW_FTR_SECTION_END_NESTED_IFSET(msk, label)	\
142 	ALT_FW_FTR_SECTION_END_NESTED(msk, msk, label)
143 #define ALT_FW_FTR_SECTION_END_NESTED_IFCLR(msk, label)	\
144 	ALT_FW_FTR_SECTION_END_NESTED(msk, 0, label)
145 #define ALT_FW_FTR_SECTION_END(msk, val)	\
146 	ALT_FW_FTR_SECTION_END_NESTED(msk, val, 97)
147 #define ALT_FW_FTR_SECTION_END_IFSET(msk)	\
148 	ALT_FW_FTR_SECTION_END_NESTED_IFSET(msk, 97)
149 #define ALT_FW_FTR_SECTION_END_IFCLR(msk)	\
150 	ALT_FW_FTR_SECTION_END_NESTED_IFCLR(msk, 97)
151 
152 #ifndef __ASSEMBLY__
153 
154 #define ASM_FTR_IF(section_if, section_else, msk, val)	\
155 	stringify_in_c(BEGIN_FTR_SECTION)			\
156 	section_if "; "						\
157 	stringify_in_c(FTR_SECTION_ELSE)			\
158 	section_else "; "					\
159 	stringify_in_c(ALT_FTR_SECTION_END((msk), (val)))
160 
161 #define ASM_FTR_IFSET(section_if, section_else, msk)	\
162 	ASM_FTR_IF(section_if, section_else, (msk), (msk))
163 
164 #define ASM_FTR_IFCLR(section_if, section_else, msk)	\
165 	ASM_FTR_IF(section_if, section_else, (msk), 0)
166 
167 #define ASM_MMU_FTR_IF(section_if, section_else, msk, val)	\
168 	stringify_in_c(BEGIN_MMU_FTR_SECTION)			\
169 	section_if "; "						\
170 	stringify_in_c(MMU_FTR_SECTION_ELSE)			\
171 	section_else "; "					\
172 	stringify_in_c(ALT_MMU_FTR_SECTION_END((msk), (val)))
173 
174 #define ASM_MMU_FTR_IFSET(section_if, section_else, msk)	\
175 	ASM_MMU_FTR_IF(section_if, section_else, (msk), (msk))
176 
177 #define ASM_MMU_FTR_IFCLR(section_if, section_else, msk)	\
178 	ASM_MMU_FTR_IF(section_if, section_else, (msk), 0)
179 
180 #endif /* __ASSEMBLY__ */
181 
182 /* LWSYNC feature sections */
183 #define START_LWSYNC_SECTION(label)	label##1:
184 #define MAKE_LWSYNC_SECTION_ENTRY(label, sect)		\
185 label##2:						\
186 	.pushsection sect,"a";				\
187 	.align 2;					\
188 label##3:					       	\
189 	FTR_ENTRY_OFFSET label##1b-label##3b;		\
190 	.popsection;
191 
192 #define STF_ENTRY_BARRIER_FIXUP_SECTION			\
193 953:							\
194 	.pushsection __stf_entry_barrier_fixup,"a";	\
195 	.align 2;					\
196 954:							\
197 	FTR_ENTRY_OFFSET 953b-954b;			\
198 	.popsection;
199 
200 #define STF_EXIT_BARRIER_FIXUP_SECTION			\
201 955:							\
202 	.pushsection __stf_exit_barrier_fixup,"a";	\
203 	.align 2;					\
204 956:							\
205 	FTR_ENTRY_OFFSET 955b-956b;			\
206 	.popsection;
207 
208 #define RFI_FLUSH_FIXUP_SECTION				\
209 951:							\
210 	.pushsection __rfi_flush_fixup,"a";		\
211 	.align 2;					\
212 952:							\
213 	FTR_ENTRY_OFFSET 951b-952b;			\
214 	.popsection;
215 
216 #define NOSPEC_BARRIER_FIXUP_SECTION			\
217 953:							\
218 	.pushsection __barrier_nospec_fixup,"a";	\
219 	.align 2;					\
220 954:							\
221 	FTR_ENTRY_OFFSET 953b-954b;			\
222 	.popsection;
223 
224 #define START_BTB_FLUSH_SECTION			\
225 955:							\
226 
227 #define END_BTB_FLUSH_SECTION			\
228 956:							\
229 	.pushsection __btb_flush_fixup,"a";	\
230 	.align 2;							\
231 957:						\
232 	FTR_ENTRY_OFFSET 955b-957b;			\
233 	FTR_ENTRY_OFFSET 956b-957b;			\
234 	.popsection;
235 
236 #ifndef __ASSEMBLY__
237 #include <linux/types.h>
238 
239 extern long stf_barrier_fallback;
240 extern long __start___stf_entry_barrier_fixup, __stop___stf_entry_barrier_fixup;
241 extern long __start___stf_exit_barrier_fixup, __stop___stf_exit_barrier_fixup;
242 extern long __start___rfi_flush_fixup, __stop___rfi_flush_fixup;
243 extern long __start___barrier_nospec_fixup, __stop___barrier_nospec_fixup;
244 extern long __start__btb_flush_fixup, __stop__btb_flush_fixup;
245 
246 void apply_feature_fixups(void);
247 void setup_feature_keys(void);
248 #endif
249 
250 #endif /* __ASM_POWERPC_FEATURE_FIXUPS_H */
251