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