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_IFSET(msk)	END_FTR_SECTION((msk), (msk))
70 #define END_FTR_SECTION_IFCLR(msk)	END_FTR_SECTION((msk), 0)
71 
72 /* CPU feature sections with alternatives, use BEGIN_FTR_SECTION to start */
73 #define FTR_SECTION_ELSE	FTR_SECTION_ELSE_NESTED(97)
74 #define ALT_FTR_SECTION_END_NESTED(msk, val, label)	\
75 	MAKE_FTR_SECTION_ENTRY(msk, val, label, __ftr_fixup)
76 #define ALT_FTR_SECTION_END_NESTED_IFSET(msk, label)	\
77 	ALT_FTR_SECTION_END_NESTED(msk, msk, label)
78 #define ALT_FTR_SECTION_END_NESTED_IFCLR(msk, label)	\
79 	ALT_FTR_SECTION_END_NESTED(msk, 0, label)
80 #define ALT_FTR_SECTION_END(msk, val)	\
81 	ALT_FTR_SECTION_END_NESTED(msk, val, 97)
82 #define ALT_FTR_SECTION_END_IFSET(msk)	\
83 	ALT_FTR_SECTION_END_NESTED_IFSET(msk, 97)
84 #define ALT_FTR_SECTION_END_IFCLR(msk)	\
85 	ALT_FTR_SECTION_END_NESTED_IFCLR(msk, 97)
86 
87 /* MMU feature dependent sections */
88 #define BEGIN_MMU_FTR_SECTION_NESTED(label)	START_FTR_SECTION(label)
89 #define BEGIN_MMU_FTR_SECTION			START_FTR_SECTION(97)
90 
91 #define END_MMU_FTR_SECTION_NESTED(msk, val, label) 		\
92 	FTR_SECTION_ELSE_NESTED(label)				\
93 	MAKE_FTR_SECTION_ENTRY(msk, val, label, __mmu_ftr_fixup)
94 
95 #define END_MMU_FTR_SECTION(msk, val)		\
96 	END_MMU_FTR_SECTION_NESTED(msk, val, 97)
97 
98 #define END_MMU_FTR_SECTION_IFSET(msk)	END_MMU_FTR_SECTION((msk), (msk))
99 #define END_MMU_FTR_SECTION_IFCLR(msk)	END_MMU_FTR_SECTION((msk), 0)
100 
101 /* MMU feature sections with alternatives, use BEGIN_FTR_SECTION to start */
102 #define MMU_FTR_SECTION_ELSE_NESTED(label)	FTR_SECTION_ELSE_NESTED(label)
103 #define MMU_FTR_SECTION_ELSE	MMU_FTR_SECTION_ELSE_NESTED(97)
104 #define ALT_MMU_FTR_SECTION_END_NESTED(msk, val, label)	\
105 	MAKE_FTR_SECTION_ENTRY(msk, val, label, __mmu_ftr_fixup)
106 #define ALT_MMU_FTR_SECTION_END_NESTED_IFSET(msk, label)	\
107 	ALT_MMU_FTR_SECTION_END_NESTED(msk, msk, label)
108 #define ALT_MMU_FTR_SECTION_END_NESTED_IFCLR(msk, label)	\
109 	ALT_MMU_FTR_SECTION_END_NESTED(msk, 0, label)
110 #define ALT_MMU_FTR_SECTION_END(msk, val)	\
111 	ALT_MMU_FTR_SECTION_END_NESTED(msk, val, 97)
112 #define ALT_MMU_FTR_SECTION_END_IFSET(msk)	\
113 	ALT_MMU_FTR_SECTION_END_NESTED_IFSET(msk, 97)
114 #define ALT_MMU_FTR_SECTION_END_IFCLR(msk)	\
115 	ALT_MMU_FTR_SECTION_END_NESTED_IFCLR(msk, 97)
116 
117 /* Firmware feature dependent sections */
118 #define BEGIN_FW_FTR_SECTION_NESTED(label)	START_FTR_SECTION(label)
119 #define BEGIN_FW_FTR_SECTION			START_FTR_SECTION(97)
120 
121 #define END_FW_FTR_SECTION_NESTED(msk, val, label) 		\
122 	FTR_SECTION_ELSE_NESTED(label)				\
123 	MAKE_FTR_SECTION_ENTRY(msk, val, label, __fw_ftr_fixup)
124 
125 #define END_FW_FTR_SECTION(msk, val)		\
126 	END_FW_FTR_SECTION_NESTED(msk, val, 97)
127 
128 #define END_FW_FTR_SECTION_IFSET(msk)	END_FW_FTR_SECTION((msk), (msk))
129 #define END_FW_FTR_SECTION_IFCLR(msk)	END_FW_FTR_SECTION((msk), 0)
130 
131 /* Firmware feature sections with alternatives */
132 #define FW_FTR_SECTION_ELSE_NESTED(label)	FTR_SECTION_ELSE_NESTED(label)
133 #define FW_FTR_SECTION_ELSE	FTR_SECTION_ELSE_NESTED(97)
134 #define ALT_FW_FTR_SECTION_END_NESTED(msk, val, label)	\
135 	MAKE_FTR_SECTION_ENTRY(msk, val, label, __fw_ftr_fixup)
136 #define ALT_FW_FTR_SECTION_END_NESTED_IFSET(msk, label)	\
137 	ALT_FW_FTR_SECTION_END_NESTED(msk, msk, label)
138 #define ALT_FW_FTR_SECTION_END_NESTED_IFCLR(msk, label)	\
139 	ALT_FW_FTR_SECTION_END_NESTED(msk, 0, label)
140 #define ALT_FW_FTR_SECTION_END(msk, val)	\
141 	ALT_FW_FTR_SECTION_END_NESTED(msk, val, 97)
142 #define ALT_FW_FTR_SECTION_END_IFSET(msk)	\
143 	ALT_FW_FTR_SECTION_END_NESTED_IFSET(msk, 97)
144 #define ALT_FW_FTR_SECTION_END_IFCLR(msk)	\
145 	ALT_FW_FTR_SECTION_END_NESTED_IFCLR(msk, 97)
146 
147 #ifndef __ASSEMBLY__
148 
149 #define ASM_FTR_IF(section_if, section_else, msk, val)	\
150 	stringify_in_c(BEGIN_FTR_SECTION)			\
151 	section_if "; "						\
152 	stringify_in_c(FTR_SECTION_ELSE)			\
153 	section_else "; "					\
154 	stringify_in_c(ALT_FTR_SECTION_END((msk), (val)))
155 
156 #define ASM_FTR_IFSET(section_if, section_else, msk)	\
157 	ASM_FTR_IF(section_if, section_else, (msk), (msk))
158 
159 #define ASM_FTR_IFCLR(section_if, section_else, msk)	\
160 	ASM_FTR_IF(section_if, section_else, (msk), 0)
161 
162 #define ASM_MMU_FTR_IF(section_if, section_else, msk, val)	\
163 	stringify_in_c(BEGIN_MMU_FTR_SECTION)			\
164 	section_if "; "						\
165 	stringify_in_c(MMU_FTR_SECTION_ELSE)			\
166 	section_else "; "					\
167 	stringify_in_c(ALT_MMU_FTR_SECTION_END((msk), (val)))
168 
169 #define ASM_MMU_FTR_IFSET(section_if, section_else, msk)	\
170 	ASM_MMU_FTR_IF(section_if, section_else, (msk), (msk))
171 
172 #define ASM_MMU_FTR_IFCLR(section_if, section_else, msk)	\
173 	ASM_MMU_FTR_IF(section_if, section_else, (msk), 0)
174 
175 #endif /* __ASSEMBLY__ */
176 
177 /* LWSYNC feature sections */
178 #define START_LWSYNC_SECTION(label)	label##1:
179 #define MAKE_LWSYNC_SECTION_ENTRY(label, sect)		\
180 label##2:						\
181 	.pushsection sect,"a";				\
182 	.align 2;					\
183 label##3:					       	\
184 	FTR_ENTRY_OFFSET label##1b-label##3b;		\
185 	.popsection;
186 
187 #endif /* __ASM_POWERPC_FEATURE_FIXUPS_H */
188