1
2
3
4
5
6
7
8
9#ifndef __ASM_ARM_MACRO_H__
10#define __ASM_ARM_MACRO_H__
11
12#ifdef CONFIG_ARM64
13#include <asm/system.h>
14#endif
15
16#ifdef __ASSEMBLY__
17
18
19
20
21
22
23
24
25
26
27
28.macro write32, addr, data
29 ldr r4, =\addr
30 ldr r5, =\data
31 str r5, [r4]
32.endm
33
34.macro write16, addr, data
35 ldr r4, =\addr
36 ldrh r5, =\data
37 strh r5, [r4]
38.endm
39
40.macro write8, addr, data
41 ldr r4, =\addr
42 ldrb r5, =\data
43 strb r5, [r4]
44.endm
45
46
47
48
49
50
51
52
53
54.macro wait_timer, time
55 ldr r4, =\time
561:
57 nop
58 subs r4, r4, #1
59 bcs 1b
60.endm
61
62#ifdef CONFIG_ARM64
63
64
65
66lr .req x30
67
68
69
70
71.macro switch_el, xreg, el3_label, el2_label, el1_label
72 mrs \xreg, CurrentEL
73 cmp \xreg, 0xc
74 b.eq \el3_label
75 cmp \xreg, 0x8
76 b.eq \el2_label
77 cmp \xreg, 0x4
78 b.eq \el1_label
79.endm
80
81
82
83
84.macro branch_if_a57_core, xreg, a57_label
85 mrs \xreg, midr_el1
86 lsr \xreg, \xreg, #4
87 and \xreg, \xreg, #0x00000FFF
88 cmp \xreg, #0xD07
89 b.eq \a57_label
90.endm
91
92
93
94
95.macro branch_if_a53_core, xreg, a53_label
96 mrs \xreg, midr_el1
97 lsr \xreg, \xreg, #4
98 and \xreg, \xreg, #0x00000FFF
99 cmp \xreg, #0xD03
100 b.eq \a53_label
101.endm
102
103
104
105
106
107.macro branch_if_slave, xreg, slave_label
108#ifdef CONFIG_ARMV8_MULTIENTRY
109
110 mrs \xreg, mpidr_el1
111 tst \xreg, #0xff
112 b.ne \slave_label
113 lsr \xreg, \xreg, #8
114 tst \xreg, #0xff
115 b.ne \slave_label
116 lsr \xreg, \xreg, #8
117 tst \xreg, #0xff
118 b.ne \slave_label
119 lsr \xreg, \xreg, #16
120 tst \xreg, #0xff
121 b.ne \slave_label
122#endif
123.endm
124
125
126
127
128
129.macro branch_if_master, xreg1, xreg2, master_label
130#ifdef CONFIG_ARMV8_MULTIENTRY
131
132 mrs \xreg1, mpidr_el1
133 lsr \xreg2, \xreg1, #32
134 lsl \xreg1, \xreg1, #40
135 lsr \xreg1, \xreg1, #40
136 orr \xreg1, \xreg1, \xreg2
137 cbz \xreg1, \master_label
138#else
139 b \master_label
140#endif
141.endm
142
143
144
145
146
147
148
149
150
151
152
153
154.macro armv8_switch_to_el2_m, ep, flag, tmp
155 msr cptr_el3, xzr
156 mov \tmp, #CPTR_EL2_RES1
157 msr cptr_el2, \tmp
158
159
160 msr cntvoff_el2, xzr
161
162
163
164
165
166
167
168 ldr \tmp, =(SCTLR_EL2_RES1 | SCTLR_EL2_EE_LE |\
169 SCTLR_EL2_WXN_DIS | SCTLR_EL2_ICACHE_DIS |\
170 SCTLR_EL2_SA_DIS | SCTLR_EL2_DCACHE_DIS |\
171 SCTLR_EL2_ALIGN_DIS | SCTLR_EL2_MMU_DIS)
172 msr sctlr_el2, \tmp
173
174 mov \tmp, sp
175 msr sp_el2, \tmp
176 mrs \tmp, vbar_el3
177 msr vbar_el2, \tmp
178
179
180 cmp \flag, #ES_TO_AARCH32
181 b.eq 1f
182
183
184
185
186
187
188#ifdef CONFIG_ARMV8_PSCI
189 ldr \tmp, =(SCR_EL3_RW_AARCH64 | SCR_EL3_HCE_EN |\
190 SCR_EL3_RES1 | SCR_EL3_NS_EN)
191#else
192 ldr \tmp, =(SCR_EL3_RW_AARCH64 | SCR_EL3_HCE_EN |\
193 SCR_EL3_SMD_DIS | SCR_EL3_RES1 |\
194 SCR_EL3_NS_EN)
195#endif
196 msr scr_el3, \tmp
197
198
199 ldr \tmp, =(SPSR_EL_DEBUG_MASK | SPSR_EL_SERR_MASK |\
200 SPSR_EL_IRQ_MASK | SPSR_EL_FIQ_MASK |\
201 SPSR_EL_M_AARCH64 | SPSR_EL_M_EL2H)
202 msr spsr_el3, \tmp
203 msr elr_el3, \ep
204 eret
205
2061:
207
208
209
210
211 ldr \tmp, =(SCR_EL3_RW_AARCH32 | SCR_EL3_HCE_EN |\
212 SCR_EL3_SMD_DIS | SCR_EL3_RES1 |\
213 SCR_EL3_NS_EN)
214 msr scr_el3, \tmp
215
216
217 ldr \tmp, =(SPSR_EL_END_LE | SPSR_EL_ASYN_MASK |\
218 SPSR_EL_IRQ_MASK | SPSR_EL_FIQ_MASK |\
219 SPSR_EL_T_A32 | SPSR_EL_M_AARCH32 |\
220 SPSR_EL_M_HYP)
221 msr spsr_el3, \tmp
222 msr elr_el3, \ep
223 eret
224.endm
225
226
227
228
229
230
231
232
233
234
235
236
237.macro armv8_switch_to_el1_m, ep, flag, tmp
238
239 mrs \tmp, cnthctl_el2
240
241 orr \tmp, \tmp, #(CNTHCTL_EL2_EL1PCEN_EN |\
242 CNTHCTL_EL2_EL1PCTEN_EN)
243 msr cnthctl_el2, \tmp
244 msr cntvoff_el2, xzr
245
246
247 mrs \tmp, midr_el1
248 msr vpidr_el2, \tmp
249 mrs \tmp, mpidr_el1
250 msr vmpidr_el2, \tmp
251
252
253 mov \tmp, #CPTR_EL2_RES1
254 msr cptr_el2, \tmp
255 msr hstr_el2, xzr
256 mov \tmp, #CPACR_EL1_FPEN_EN
257 msr cpacr_el1, \tmp
258
259
260
261
262
263
264
265
266 ldr \tmp, =(SCTLR_EL1_RES1 | SCTLR_EL1_UCI_DIS |\
267 SCTLR_EL1_EE_LE | SCTLR_EL1_WXN_DIS |\
268 SCTLR_EL1_NTWE_DIS | SCTLR_EL1_NTWI_DIS |\
269 SCTLR_EL1_UCT_DIS | SCTLR_EL1_DZE_DIS |\
270 SCTLR_EL1_ICACHE_DIS | SCTLR_EL1_UMA_DIS |\
271 SCTLR_EL1_SED_EN | SCTLR_EL1_ITD_EN |\
272 SCTLR_EL1_CP15BEN_DIS | SCTLR_EL1_SA0_DIS |\
273 SCTLR_EL1_SA_DIS | SCTLR_EL1_DCACHE_DIS |\
274 SCTLR_EL1_ALIGN_DIS | SCTLR_EL1_MMU_DIS)
275 msr sctlr_el1, \tmp
276
277 mov \tmp, sp
278 msr sp_el1, \tmp
279 mrs \tmp, vbar_el2
280 msr vbar_el1, \tmp
281
282
283 cmp \flag, #ES_TO_AARCH32
284 b.eq 1f
285
286
287 ldr \tmp, =(HCR_EL2_RW_AARCH64 | HCR_EL2_HCD_DIS)
288 msr hcr_el2, \tmp
289
290
291 ldr \tmp, =(SPSR_EL_DEBUG_MASK | SPSR_EL_SERR_MASK |\
292 SPSR_EL_IRQ_MASK | SPSR_EL_FIQ_MASK |\
293 SPSR_EL_M_AARCH64 | SPSR_EL_M_EL1H)
294 msr spsr_el2, \tmp
295 msr elr_el2, \ep
296 eret
297
2981:
299
300 ldr \tmp, =(HCR_EL2_RW_AARCH32 | HCR_EL2_HCD_DIS)
301 msr hcr_el2, \tmp
302
303
304 ldr \tmp, =(SPSR_EL_END_LE | SPSR_EL_ASYN_MASK |\
305 SPSR_EL_IRQ_MASK | SPSR_EL_FIQ_MASK |\
306 SPSR_EL_T_A32 | SPSR_EL_M_AARCH32 |\
307 SPSR_EL_M_SVC)
308 msr spsr_el2, \tmp
309 msr elr_el2, \ep
310 eret
311.endm
312
313#if defined(CONFIG_GICV3)
314.macro gic_wait_for_interrupt_m xreg1
3150 : wfi
316 mrs \xreg1, ICC_IAR1_EL1
317 msr ICC_EOIR1_EL1, \xreg1
318 cbnz \xreg1, 0b
319.endm
320#elif defined(CONFIG_GICV2)
321.macro gic_wait_for_interrupt_m xreg1, wreg2
3220 : wfi
323 ldr \wreg2, [\xreg1, GICC_AIAR]
324 str \wreg2, [\xreg1, GICC_AEOIR]
325 and \wreg2, \wreg2, #0x3ff
326 cbnz \wreg2, 0b
327.endm
328#endif
329
330#endif
331
332#endif
333#endif
334