]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmLib/AArch64/AArch64Support.S
ArmPkg/ArmLib: remove unused ArmCleanDataCacheToPoU()
[mirror_edk2.git] / ArmPkg / Library / ArmLib / AArch64 / AArch64Support.S
CommitLineData
25402f5d
HL
1#------------------------------------------------------------------------------\r
2#\r
3# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
9401d6f4 4# Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.\r
25402f5d
HL
5#\r
6# This program and the accompanying materials\r
7# are licensed and made available under the terms and conditions of the BSD License\r
8# which accompanies this distribution. The full text of the license may be found at\r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14#------------------------------------------------------------------------------\r
15\r
16#include <Chipset/AArch64.h>\r
17#include <AsmMacroIoLibV8.h>\r
18\r
19.text\r
20.align 3\r
21\r
22GCC_ASM_EXPORT (ArmInvalidateInstructionCache)\r
23GCC_ASM_EXPORT (ArmInvalidateDataCacheEntryByMVA)\r
24GCC_ASM_EXPORT (ArmCleanDataCacheEntryByMVA)\r
25GCC_ASM_EXPORT (ArmCleanInvalidateDataCacheEntryByMVA)\r
26GCC_ASM_EXPORT (ArmInvalidateDataCacheEntryBySetWay)\r
27GCC_ASM_EXPORT (ArmCleanDataCacheEntryBySetWay)\r
28GCC_ASM_EXPORT (ArmCleanInvalidateDataCacheEntryBySetWay)\r
29GCC_ASM_EXPORT (ArmDrainWriteBuffer)\r
30GCC_ASM_EXPORT (ArmEnableMmu)\r
31GCC_ASM_EXPORT (ArmDisableMmu)\r
32GCC_ASM_EXPORT (ArmDisableCachesAndMmu)\r
33GCC_ASM_EXPORT (ArmMmuEnabled)\r
34GCC_ASM_EXPORT (ArmEnableDataCache)\r
35GCC_ASM_EXPORT (ArmDisableDataCache)\r
36GCC_ASM_EXPORT (ArmEnableInstructionCache)\r
37GCC_ASM_EXPORT (ArmDisableInstructionCache)\r
38GCC_ASM_EXPORT (ArmDisableAlignmentCheck)\r
39GCC_ASM_EXPORT (ArmEnableAlignmentCheck)\r
40GCC_ASM_EXPORT (ArmEnableBranchPrediction)\r
41GCC_ASM_EXPORT (ArmDisableBranchPrediction)\r
42GCC_ASM_EXPORT (AArch64AllDataCachesOperation)\r
25402f5d 43GCC_ASM_EXPORT (ArmDataMemoryBarrier)\r
cf93a378 44GCC_ASM_EXPORT (ArmDataSynchronizationBarrier)\r
25402f5d
HL
45GCC_ASM_EXPORT (ArmInstructionSynchronizationBarrier)\r
46GCC_ASM_EXPORT (ArmWriteVBar)\r
f0247796 47GCC_ASM_EXPORT (ArmReadVBar)\r
25402f5d
HL
48GCC_ASM_EXPORT (ArmEnableVFP)\r
49GCC_ASM_EXPORT (ArmCallWFI)\r
25402f5d
HL
50GCC_ASM_EXPORT (ArmReadMpidr)\r
51GCC_ASM_EXPORT (ArmReadTpidrurw)\r
52GCC_ASM_EXPORT (ArmWriteTpidrurw)\r
53GCC_ASM_EXPORT (ArmIsArchTimerImplemented)\r
54GCC_ASM_EXPORT (ArmReadIdPfr0)\r
55GCC_ASM_EXPORT (ArmReadIdPfr1)\r
56GCC_ASM_EXPORT (ArmWriteHcr)\r
57GCC_ASM_EXPORT (ArmReadCurrentEL)\r
58\r
59.set CTRL_M_BIT, (1 << 0)\r
60.set CTRL_A_BIT, (1 << 1)\r
61.set CTRL_C_BIT, (1 << 2)\r
62.set CTRL_I_BIT, (1 << 12)\r
63.set CTRL_V_BIT, (1 << 12)\r
64.set CPACR_VFP_BITS, (3 << 20)\r
65\r
66ASM_PFX(ArmInvalidateDataCacheEntryByMVA):\r
67 dc ivac, x0 // Invalidate single data cache line\r
68 dsb sy\r
69 isb\r
70 ret\r
71\r
72\r
73ASM_PFX(ArmCleanDataCacheEntryByMVA):\r
74 dc cvac, x0 // Clean single data cache line\r
75 dsb sy\r
76 isb\r
77 ret\r
78\r
79\r
80ASM_PFX(ArmCleanInvalidateDataCacheEntryByMVA):\r
81 dc civac, x0 // Clean and invalidate single data cache line\r
82 dsb sy\r
83 isb\r
84 ret\r
85\r
86\r
87ASM_PFX(ArmInvalidateDataCacheEntryBySetWay):\r
88 dc isw, x0 // Invalidate this line\r
89 dsb sy\r
90 isb\r
91 ret\r
92\r
93\r
94ASM_PFX(ArmCleanInvalidateDataCacheEntryBySetWay):\r
95 dc cisw, x0 // Clean and Invalidate this line\r
96 dsb sy\r
97 isb\r
98 ret\r
99\r
100\r
101ASM_PFX(ArmCleanDataCacheEntryBySetWay):\r
102 dc csw, x0 // Clean this line\r
103 dsb sy\r
104 isb\r
105 ret\r
106\r
107\r
108ASM_PFX(ArmInvalidateInstructionCache):\r
109 ic iallu // Invalidate entire instruction cache\r
110 dsb sy\r
111 isb\r
112 ret\r
113\r
114\r
115ASM_PFX(ArmEnableMmu):\r
116 EL1_OR_EL2_OR_EL3(x1)\r
1171: mrs x0, sctlr_el1 // Read System control register EL1\r
118 b 4f\r
1192: mrs x0, sctlr_el2 // Read System control register EL2\r
120 b 4f\r
1213: mrs x0, sctlr_el3 // Read System control register EL3\r
1224: orr x0, x0, #CTRL_M_BIT // Set MMU enable bit\r
123 EL1_OR_EL2_OR_EL3(x1)\r
70f89c0b 1241: tlbi vmalle1\r
ee95f9e1 125 dsb nsh\r
25402f5d
HL
126 isb\r
127 msr sctlr_el1, x0 // Write back\r
128 b 4f\r
1292: tlbi alle2\r
ee95f9e1 130 dsb nsh\r
25402f5d
HL
131 isb\r
132 msr sctlr_el2, x0 // Write back\r
133 b 4f\r
1343: tlbi alle3\r
ee95f9e1 135 dsb nsh\r
25402f5d
HL
136 isb\r
137 msr sctlr_el3, x0 // Write back\r
ee95f9e1 1384: isb\r
25402f5d
HL
139 ret\r
140\r
141\r
142ASM_PFX(ArmDisableMmu):\r
143 EL1_OR_EL2_OR_EL3(x1)\r
1441: mrs x0, sctlr_el1 // Read System Control Register EL1\r
145 b 4f\r
1462: mrs x0, sctlr_el2 // Read System Control Register EL2\r
147 b 4f\r
1483: mrs x0, sctlr_el3 // Read System Control Register EL3\r
73ca5009 1494: and x0, x0, #~CTRL_M_BIT // Clear MMU enable bit\r
25402f5d
HL
150 EL1_OR_EL2_OR_EL3(x1)\r
1511: msr sctlr_el1, x0 // Write back\r
70f89c0b 152 tlbi vmalle1\r
25402f5d
HL
153 b 4f\r
1542: msr sctlr_el2, x0 // Write back\r
155 tlbi alle2\r
156 b 4f\r
1573: msr sctlr_el3, x0 // Write back\r
158 tlbi alle3\r
1594: dsb sy\r
160 isb\r
161 ret\r
162\r
163\r
164ASM_PFX(ArmDisableCachesAndMmu):\r
165 EL1_OR_EL2_OR_EL3(x1)\r
1661: mrs x0, sctlr_el1 // Get control register EL1\r
167 b 4f\r
1682: mrs x0, sctlr_el2 // Get control register EL2\r
169 b 4f\r
1703: mrs x0, sctlr_el3 // Get control register EL3\r
73ca5009
BJ
1714: mov x1, #~(CTRL_M_BIT | CTRL_C_BIT | CTRL_I_BIT) // Disable MMU, D & I caches\r
172 and x0, x0, x1\r
25402f5d
HL
173 EL1_OR_EL2_OR_EL3(x1)\r
1741: msr sctlr_el1, x0 // Write back control register\r
175 b 4f\r
1762: msr sctlr_el2, x0 // Write back control register\r
177 b 4f\r
1783: msr sctlr_el3, x0 // Write back control register\r
1794: dsb sy\r
180 isb\r
181 ret\r
182\r
183\r
184ASM_PFX(ArmMmuEnabled):\r
185 EL1_OR_EL2_OR_EL3(x1)\r
1861: mrs x0, sctlr_el1 // Get control register EL1\r
187 b 4f\r
1882: mrs x0, sctlr_el2 // Get control register EL2\r
189 b 4f\r
1903: mrs x0, sctlr_el3 // Get control register EL3\r
1914: and x0, x0, #CTRL_M_BIT\r
192 ret\r
193\r
194\r
195ASM_PFX(ArmEnableDataCache):\r
196 EL1_OR_EL2_OR_EL3(x1)\r
1971: mrs x0, sctlr_el1 // Get control register EL1\r
198 b 4f\r
1992: mrs x0, sctlr_el2 // Get control register EL2\r
200 b 4f\r
2013: mrs x0, sctlr_el3 // Get control register EL3\r
2024: orr x0, x0, #CTRL_C_BIT // Set C bit\r
203 EL1_OR_EL2_OR_EL3(x1)\r
2041: msr sctlr_el1, x0 // Write back control register\r
205 b 4f\r
2062: msr sctlr_el2, x0 // Write back control register\r
207 b 4f\r
2083: msr sctlr_el3, x0 // Write back control register\r
2094: dsb sy\r
210 isb\r
211 ret\r
212\r
213\r
214ASM_PFX(ArmDisableDataCache):\r
215 EL1_OR_EL2_OR_EL3(x1)\r
2161: mrs x0, sctlr_el1 // Get control register EL1\r
217 b 4f\r
2182: mrs x0, sctlr_el2 // Get control register EL2\r
219 b 4f\r
2203: mrs x0, sctlr_el3 // Get control register EL3\r
73ca5009 2214: and x0, x0, #~CTRL_C_BIT // Clear C bit\r
25402f5d
HL
222 EL1_OR_EL2_OR_EL3(x1)\r
2231: msr sctlr_el1, x0 // Write back control register\r
224 b 4f\r
2252: msr sctlr_el2, x0 // Write back control register\r
226 b 4f\r
2273: msr sctlr_el3, x0 // Write back control register\r
2284: dsb sy\r
229 isb\r
230 ret\r
231\r
232\r
233ASM_PFX(ArmEnableInstructionCache):\r
234 EL1_OR_EL2_OR_EL3(x1)\r
2351: mrs x0, sctlr_el1 // Get control register EL1\r
236 b 4f\r
2372: mrs x0, sctlr_el2 // Get control register EL2\r
238 b 4f\r
2393: mrs x0, sctlr_el3 // Get control register EL3\r
2404: orr x0, x0, #CTRL_I_BIT // Set I bit\r
241 EL1_OR_EL2_OR_EL3(x1)\r
2421: msr sctlr_el1, x0 // Write back control register\r
243 b 4f\r
2442: msr sctlr_el2, x0 // Write back control register\r
245 b 4f\r
2463: msr sctlr_el3, x0 // Write back control register\r
2474: dsb sy\r
248 isb\r
249 ret\r
250\r
251\r
252ASM_PFX(ArmDisableInstructionCache):\r
253 EL1_OR_EL2_OR_EL3(x1)\r
2541: mrs x0, sctlr_el1 // Get control register EL1\r
255 b 4f\r
2562: mrs x0, sctlr_el2 // Get control register EL2\r
257 b 4f\r
2583: mrs x0, sctlr_el3 // Get control register EL3\r
73ca5009 2594: and x0, x0, #~CTRL_I_BIT // Clear I bit\r
25402f5d
HL
260 EL1_OR_EL2_OR_EL3(x1)\r
2611: msr sctlr_el1, x0 // Write back control register\r
262 b 4f\r
2632: msr sctlr_el2, x0 // Write back control register\r
264 b 4f\r
2653: msr sctlr_el3, x0 // Write back control register\r
2664: dsb sy\r
267 isb\r
268 ret\r
269\r
270\r
271ASM_PFX(ArmEnableAlignmentCheck):\r
272 EL1_OR_EL2(x1)\r
2731: mrs x0, sctlr_el1 // Get control register EL1\r
274 b 3f\r
2752: mrs x0, sctlr_el2 // Get control register EL2\r
2763: orr x0, x0, #CTRL_A_BIT // Set A (alignment check) bit\r
277 EL1_OR_EL2(x1)\r
2781: msr sctlr_el1, x0 // Write back control register\r
279 b 3f\r
2802: msr sctlr_el2, x0 // Write back control register\r
2813: dsb sy\r
282 isb\r
283 ret\r
284\r
285\r
286ASM_PFX(ArmDisableAlignmentCheck):\r
287 EL1_OR_EL2_OR_EL3(x1)\r
2881: mrs x0, sctlr_el1 // Get control register EL1\r
289 b 4f\r
2902: mrs x0, sctlr_el2 // Get control register EL2\r
291 b 4f\r
2923: mrs x0, sctlr_el3 // Get control register EL3\r
73ca5009 2934: and x0, x0, #~CTRL_A_BIT // Clear A (alignment check) bit\r
25402f5d
HL
294 EL1_OR_EL2_OR_EL3(x1)\r
2951: msr sctlr_el1, x0 // Write back control register\r
296 b 4f\r
2972: msr sctlr_el2, x0 // Write back control register\r
298 b 4f\r
2993: msr sctlr_el3, x0 // Write back control register\r
3004: dsb sy\r
301 isb\r
302 ret\r
303\r
304\r
305// Always turned on in AArch64. Else implementation specific. Leave in for C compatibility for now\r
306ASM_PFX(ArmEnableBranchPrediction):\r
307 ret\r
308\r
309\r
310// Always turned on in AArch64. Else implementation specific. Leave in for C compatibility for now.\r
311ASM_PFX(ArmDisableBranchPrediction):\r
312 ret\r
313\r
314\r
315ASM_PFX(AArch64AllDataCachesOperation):\r
316// We can use regs 0-7 and 9-15 without having to save/restore.\r
fb7ea611
OM
317// Save our link register on the stack. - The stack must always be quad-word aligned\r
318 str x30, [sp, #-16]!\r
25402f5d
HL
319 mov x1, x0 // Save Function call in x1\r
320 mrs x6, clidr_el1 // Read EL1 CLIDR\r
321 and x3, x6, #0x7000000 // Mask out all but Level of Coherency (LoC)\r
433a49a0
OM
322 lsr x3, x3, #23 // Left align cache level value - the level is shifted by 1 to the\r
323 // right to ease the access to CSSELR and the Set/Way operation.\r
25402f5d
HL
324 cbz x3, L_Finished // No need to clean if LoC is 0\r
325 mov x10, #0 // Start clean at cache level 0\r
25402f5d
HL
326\r
327Loop1:\r
328 add x2, x10, x10, lsr #1 // Work out 3x cachelevel for cache info\r
329 lsr x12, x6, x2 // bottom 3 bits are the Cache type for this level\r
330 and x12, x12, #7 // get those 3 bits alone\r
331 cmp x12, #2 // what cache at this level?\r
332 b.lt L_Skip // no cache or only instruction cache at this level\r
333 msr csselr_el1, x10 // write the Cache Size selection register with current level (CSSELR)\r
334 isb // isb to sync the change to the CacheSizeID reg\r
335 mrs x12, ccsidr_el1 // reads current Cache Size ID register (CCSIDR)\r
336 and x2, x12, #0x7 // extract the line length field\r
337 add x2, x2, #4 // add 4 for the line length offset (log2 16 bytes)\r
338 mov x4, #0x400\r
339 sub x4, x4, #1\r
340 and x4, x4, x12, lsr #3 // x4 is the max number on the way size (right aligned)\r
341 clz w5, w4 // w5 is the bit position of the way size increment\r
342 mov x7, #0x00008000\r
343 sub x7, x7, #1\r
344 and x7, x7, x12, lsr #13 // x7 is the max number of the index size (right aligned)\r
345\r
346Loop2:\r
347 mov x9, x4 // x9 working copy of the max way size (right aligned)\r
348\r
349Loop3:\r
350 lsl x11, x9, x5\r
351 orr x0, x10, x11 // factor in the way number and cache number\r
352 lsl x11, x7, x2\r
353 orr x0, x0, x11 // factor in the index number\r
354\r
355 blr x1 // Goto requested cache operation\r
356\r
357 subs x9, x9, #1 // decrement the way number\r
358 b.ge Loop3\r
359 subs x7, x7, #1 // decrement the index\r
360 b.ge Loop2\r
361L_Skip:\r
362 add x10, x10, #2 // increment the cache number\r
363 cmp x3, x10\r
364 b.gt Loop1\r
365\r
366L_Finished:\r
367 dsb sy\r
368 isb\r
369 ldr x30, [sp], #0x10\r
370 ret\r
371\r
372\r
373ASM_PFX(ArmDataMemoryBarrier):\r
374 dmb sy\r
375 ret\r
376\r
377\r
cf93a378 378ASM_PFX(ArmDataSynchronizationBarrier):\r
25402f5d
HL
379ASM_PFX(ArmDrainWriteBuffer):\r
380 dsb sy\r
381 ret\r
382\r
383\r
384ASM_PFX(ArmInstructionSynchronizationBarrier):\r
385 isb\r
386 ret\r
387\r
388\r
389ASM_PFX(ArmWriteVBar):\r
390 EL1_OR_EL2_OR_EL3(x1)\r
3911: msr vbar_el1, x0 // Set the Address of the EL1 Vector Table in the VBAR register\r
392 b 4f\r
3932: msr vbar_el2, x0 // Set the Address of the EL2 Vector Table in the VBAR register\r
394 b 4f\r
3953: msr vbar_el3, x0 // Set the Address of the EL3 Vector Table in the VBAR register\r
3964: isb\r
397 ret\r
398\r
f0247796
OM
399ASM_PFX(ArmReadVBar):\r
400 EL1_OR_EL2_OR_EL3(x1)\r
4011: mrs x0, vbar_el1 // Set the Address of the EL1 Vector Table in the VBAR register\r
402 ret\r
4032: mrs x0, vbar_el2 // Set the Address of the EL2 Vector Table in the VBAR register\r
404 ret\r
4053: mrs x0, vbar_el3 // Set the Address of the EL3 Vector Table in the VBAR register\r
406 ret\r
407\r
408\r
25402f5d
HL
409ASM_PFX(ArmEnableVFP):\r
410 // Check whether floating-point is implemented in the processor.\r
411 mov x1, x30 // Save LR\r
412 bl ArmReadIdPfr0 // Read EL1 Processor Feature Register (PFR0)\r
413 mov x30, x1 // Restore LR\r
414 ands x0, x0, #AARCH64_PFR0_FP// Extract bits indicating VFP implementation\r
415 cmp x0, #0 // VFP is implemented if '0'.\r
416 b.ne 4f // Exit if VFP not implemented.\r
417 // FVP is implemented.\r
418 // Make sure VFP exceptions are not trapped (to any exception level).\r
419 mrs x0, cpacr_el1 // Read EL1 Coprocessor Access Control Register (CPACR)\r
420 orr x0, x0, #CPACR_VFP_BITS // Disable FVP traps to EL1\r
421 msr cpacr_el1, x0 // Write back EL1 Coprocessor Access Control Register (CPACR)\r
422 mov x1, #AARCH64_CPTR_TFP // TFP Bit for trapping VFP Exceptions\r
423 EL1_OR_EL2_OR_EL3(x2)\r
4241:ret // Not configurable in EL1\r
4252:mrs x0, cptr_el2 // Disable VFP traps to EL2\r
426 bic x0, x0, x1\r
427 msr cptr_el2, x0\r
428 ret\r
4293:mrs x0, cptr_el3 // Disable VFP traps to EL3\r
430 bic x0, x0, x1\r
431 msr cptr_el3, x0\r
4324:ret\r
433\r
434\r
435ASM_PFX(ArmCallWFI):\r
436 wfi\r
437 ret\r
438\r
439\r
25402f5d
HL
440ASM_PFX(ArmReadMpidr):\r
441 mrs x0, mpidr_el1 // read EL1 MPIDR\r
442 ret\r
443\r
444\r
445// Keep old function names for C compatibilty for now. Change later?\r
446ASM_PFX(ArmReadTpidrurw):\r
447 mrs x0, tpidr_el0 // read tpidr_el0 (v7 TPIDRURW) -> (v8 TPIDR_EL0)\r
448 ret\r
449\r
450\r
451// Keep old function names for C compatibilty for now. Change later?\r
452ASM_PFX(ArmWriteTpidrurw):\r
453 msr tpidr_el0, x0 // write tpidr_el0 (v7 TPIDRURW) -> (v8 TPIDR_EL0)\r
454 ret\r
455\r
456\r
457// Arch timers are mandatory on AArch64\r
458ASM_PFX(ArmIsArchTimerImplemented):\r
459 mov x0, #1\r
460 ret\r
461\r
462\r
463ASM_PFX(ArmReadIdPfr0):\r
464 mrs x0, id_aa64pfr0_el1 // Read ID_AA64PFR0 Register\r
465 ret\r
466\r
467\r
468// Q: id_aa64pfr1_el1 not defined yet. What does this funtion want to access?\r
469// A: used to setup arch timer. Check if we have security extensions, permissions to set stuff.\r
470// See: ArmPkg/Library/ArmArchTimerLib/AArch64/ArmArchTimerLib.c\r
471// Not defined yet, but stick in here for now, should read all zeros.\r
472ASM_PFX(ArmReadIdPfr1):\r
473 mrs x0, id_aa64pfr1_el1 // Read ID_PFR1 Register\r
474 ret\r
475\r
476// VOID ArmWriteHcr(UINTN Hcr)\r
477ASM_PFX(ArmWriteHcr):\r
478 msr hcr_el2, x0 // Write the passed HCR value\r
479 ret\r
480\r
481// UINTN ArmReadCurrentEL(VOID)\r
482ASM_PFX(ArmReadCurrentEL):\r
483 mrs x0, CurrentEL\r
484 ret\r
485\r
25402f5d 486ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r