]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmLib/AArch64/AArch64Support.S
ArmPkg: ArmLib: purge incorrect ArmDrainWriteBuffer () alias
[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
25402f5d
HL
29GCC_ASM_EXPORT (ArmEnableMmu)\r
30GCC_ASM_EXPORT (ArmDisableMmu)\r
31GCC_ASM_EXPORT (ArmDisableCachesAndMmu)\r
32GCC_ASM_EXPORT (ArmMmuEnabled)\r
33GCC_ASM_EXPORT (ArmEnableDataCache)\r
34GCC_ASM_EXPORT (ArmDisableDataCache)\r
35GCC_ASM_EXPORT (ArmEnableInstructionCache)\r
36GCC_ASM_EXPORT (ArmDisableInstructionCache)\r
37GCC_ASM_EXPORT (ArmDisableAlignmentCheck)\r
38GCC_ASM_EXPORT (ArmEnableAlignmentCheck)\r
39GCC_ASM_EXPORT (ArmEnableBranchPrediction)\r
40GCC_ASM_EXPORT (ArmDisableBranchPrediction)\r
41GCC_ASM_EXPORT (AArch64AllDataCachesOperation)\r
25402f5d 42GCC_ASM_EXPORT (ArmDataMemoryBarrier)\r
cf93a378 43GCC_ASM_EXPORT (ArmDataSynchronizationBarrier)\r
25402f5d
HL
44GCC_ASM_EXPORT (ArmInstructionSynchronizationBarrier)\r
45GCC_ASM_EXPORT (ArmWriteVBar)\r
f0247796 46GCC_ASM_EXPORT (ArmReadVBar)\r
25402f5d
HL
47GCC_ASM_EXPORT (ArmEnableVFP)\r
48GCC_ASM_EXPORT (ArmCallWFI)\r
25402f5d
HL
49GCC_ASM_EXPORT (ArmReadMpidr)\r
50GCC_ASM_EXPORT (ArmReadTpidrurw)\r
51GCC_ASM_EXPORT (ArmWriteTpidrurw)\r
52GCC_ASM_EXPORT (ArmIsArchTimerImplemented)\r
53GCC_ASM_EXPORT (ArmReadIdPfr0)\r
54GCC_ASM_EXPORT (ArmReadIdPfr1)\r
55GCC_ASM_EXPORT (ArmWriteHcr)\r
56GCC_ASM_EXPORT (ArmReadCurrentEL)\r
57\r
58.set CTRL_M_BIT, (1 << 0)\r
59.set CTRL_A_BIT, (1 << 1)\r
60.set CTRL_C_BIT, (1 << 2)\r
61.set CTRL_I_BIT, (1 << 12)\r
62.set CTRL_V_BIT, (1 << 12)\r
63.set CPACR_VFP_BITS, (3 << 20)\r
64\r
65ASM_PFX(ArmInvalidateDataCacheEntryByMVA):\r
66 dc ivac, x0 // Invalidate single data cache line\r
25402f5d
HL
67 ret\r
68\r
69\r
70ASM_PFX(ArmCleanDataCacheEntryByMVA):\r
71 dc cvac, x0 // Clean single data cache line\r
25402f5d
HL
72 ret\r
73\r
74\r
75ASM_PFX(ArmCleanInvalidateDataCacheEntryByMVA):\r
76 dc civac, x0 // Clean and invalidate single data cache line\r
25402f5d
HL
77 ret\r
78\r
79\r
80ASM_PFX(ArmInvalidateDataCacheEntryBySetWay):\r
81 dc isw, x0 // Invalidate this line\r
25402f5d
HL
82 ret\r
83\r
84\r
85ASM_PFX(ArmCleanInvalidateDataCacheEntryBySetWay):\r
86 dc cisw, x0 // Clean and Invalidate this line\r
25402f5d
HL
87 ret\r
88\r
89\r
90ASM_PFX(ArmCleanDataCacheEntryBySetWay):\r
91 dc csw, x0 // Clean this line\r
25402f5d
HL
92 ret\r
93\r
94\r
95ASM_PFX(ArmInvalidateInstructionCache):\r
96 ic iallu // Invalidate entire instruction cache\r
97 dsb sy\r
98 isb\r
99 ret\r
100\r
101\r
102ASM_PFX(ArmEnableMmu):\r
103 EL1_OR_EL2_OR_EL3(x1)\r
1041: mrs x0, sctlr_el1 // Read System control register EL1\r
105 b 4f\r
1062: mrs x0, sctlr_el2 // Read System control register EL2\r
107 b 4f\r
1083: mrs x0, sctlr_el3 // Read System control register EL3\r
1094: orr x0, x0, #CTRL_M_BIT // Set MMU enable bit\r
110 EL1_OR_EL2_OR_EL3(x1)\r
70f89c0b 1111: tlbi vmalle1\r
ee95f9e1 112 dsb nsh\r
25402f5d
HL
113 isb\r
114 msr sctlr_el1, x0 // Write back\r
115 b 4f\r
1162: tlbi alle2\r
ee95f9e1 117 dsb nsh\r
25402f5d
HL
118 isb\r
119 msr sctlr_el2, x0 // Write back\r
120 b 4f\r
1213: tlbi alle3\r
ee95f9e1 122 dsb nsh\r
25402f5d
HL
123 isb\r
124 msr sctlr_el3, x0 // Write back\r
ee95f9e1 1254: isb\r
25402f5d
HL
126 ret\r
127\r
128\r
129ASM_PFX(ArmDisableMmu):\r
130 EL1_OR_EL2_OR_EL3(x1)\r
1311: mrs x0, sctlr_el1 // Read System Control Register EL1\r
132 b 4f\r
1332: mrs x0, sctlr_el2 // Read System Control Register EL2\r
134 b 4f\r
1353: mrs x0, sctlr_el3 // Read System Control Register EL3\r
73ca5009 1364: and x0, x0, #~CTRL_M_BIT // Clear MMU enable bit\r
25402f5d
HL
137 EL1_OR_EL2_OR_EL3(x1)\r
1381: msr sctlr_el1, x0 // Write back\r
70f89c0b 139 tlbi vmalle1\r
25402f5d
HL
140 b 4f\r
1412: msr sctlr_el2, x0 // Write back\r
142 tlbi alle2\r
143 b 4f\r
1443: msr sctlr_el3, x0 // Write back\r
145 tlbi alle3\r
1464: dsb sy\r
147 isb\r
148 ret\r
149\r
150\r
151ASM_PFX(ArmDisableCachesAndMmu):\r
152 EL1_OR_EL2_OR_EL3(x1)\r
1531: mrs x0, sctlr_el1 // Get control register EL1\r
154 b 4f\r
1552: mrs x0, sctlr_el2 // Get control register EL2\r
156 b 4f\r
1573: mrs x0, sctlr_el3 // Get control register EL3\r
73ca5009
BJ
1584: mov x1, #~(CTRL_M_BIT | CTRL_C_BIT | CTRL_I_BIT) // Disable MMU, D & I caches\r
159 and x0, x0, x1\r
25402f5d
HL
160 EL1_OR_EL2_OR_EL3(x1)\r
1611: msr sctlr_el1, x0 // Write back control register\r
162 b 4f\r
1632: msr sctlr_el2, x0 // Write back control register\r
164 b 4f\r
1653: msr sctlr_el3, x0 // Write back control register\r
1664: dsb sy\r
167 isb\r
168 ret\r
169\r
170\r
171ASM_PFX(ArmMmuEnabled):\r
172 EL1_OR_EL2_OR_EL3(x1)\r
1731: mrs x0, sctlr_el1 // Get control register EL1\r
174 b 4f\r
1752: mrs x0, sctlr_el2 // Get control register EL2\r
176 b 4f\r
1773: mrs x0, sctlr_el3 // Get control register EL3\r
1784: and x0, x0, #CTRL_M_BIT\r
179 ret\r
180\r
181\r
182ASM_PFX(ArmEnableDataCache):\r
183 EL1_OR_EL2_OR_EL3(x1)\r
1841: mrs x0, sctlr_el1 // Get control register EL1\r
185 b 4f\r
1862: mrs x0, sctlr_el2 // Get control register EL2\r
187 b 4f\r
1883: mrs x0, sctlr_el3 // Get control register EL3\r
1894: orr x0, x0, #CTRL_C_BIT // Set C bit\r
190 EL1_OR_EL2_OR_EL3(x1)\r
1911: msr sctlr_el1, x0 // Write back control register\r
192 b 4f\r
1932: msr sctlr_el2, x0 // Write back control register\r
194 b 4f\r
1953: msr sctlr_el3, x0 // Write back control register\r
1964: dsb sy\r
197 isb\r
198 ret\r
199\r
200\r
201ASM_PFX(ArmDisableDataCache):\r
202 EL1_OR_EL2_OR_EL3(x1)\r
2031: mrs x0, sctlr_el1 // Get control register EL1\r
204 b 4f\r
2052: mrs x0, sctlr_el2 // Get control register EL2\r
206 b 4f\r
2073: mrs x0, sctlr_el3 // Get control register EL3\r
73ca5009 2084: and x0, x0, #~CTRL_C_BIT // Clear C bit\r
25402f5d
HL
209 EL1_OR_EL2_OR_EL3(x1)\r
2101: msr sctlr_el1, x0 // Write back control register\r
211 b 4f\r
2122: msr sctlr_el2, x0 // Write back control register\r
213 b 4f\r
2143: msr sctlr_el3, x0 // Write back control register\r
2154: dsb sy\r
216 isb\r
217 ret\r
218\r
219\r
220ASM_PFX(ArmEnableInstructionCache):\r
221 EL1_OR_EL2_OR_EL3(x1)\r
2221: mrs x0, sctlr_el1 // Get control register EL1\r
223 b 4f\r
2242: mrs x0, sctlr_el2 // Get control register EL2\r
225 b 4f\r
2263: mrs x0, sctlr_el3 // Get control register EL3\r
2274: orr x0, x0, #CTRL_I_BIT // Set I bit\r
228 EL1_OR_EL2_OR_EL3(x1)\r
2291: msr sctlr_el1, x0 // Write back control register\r
230 b 4f\r
2312: msr sctlr_el2, x0 // Write back control register\r
232 b 4f\r
2333: msr sctlr_el3, x0 // Write back control register\r
2344: dsb sy\r
235 isb\r
236 ret\r
237\r
238\r
239ASM_PFX(ArmDisableInstructionCache):\r
240 EL1_OR_EL2_OR_EL3(x1)\r
2411: mrs x0, sctlr_el1 // Get control register EL1\r
242 b 4f\r
2432: mrs x0, sctlr_el2 // Get control register EL2\r
244 b 4f\r
2453: mrs x0, sctlr_el3 // Get control register EL3\r
73ca5009 2464: and x0, x0, #~CTRL_I_BIT // Clear I bit\r
25402f5d
HL
247 EL1_OR_EL2_OR_EL3(x1)\r
2481: msr sctlr_el1, x0 // Write back control register\r
249 b 4f\r
2502: msr sctlr_el2, x0 // Write back control register\r
251 b 4f\r
2523: msr sctlr_el3, x0 // Write back control register\r
2534: dsb sy\r
254 isb\r
255 ret\r
256\r
257\r
258ASM_PFX(ArmEnableAlignmentCheck):\r
259 EL1_OR_EL2(x1)\r
2601: mrs x0, sctlr_el1 // Get control register EL1\r
261 b 3f\r
2622: mrs x0, sctlr_el2 // Get control register EL2\r
2633: orr x0, x0, #CTRL_A_BIT // Set A (alignment check) bit\r
264 EL1_OR_EL2(x1)\r
2651: msr sctlr_el1, x0 // Write back control register\r
266 b 3f\r
2672: msr sctlr_el2, x0 // Write back control register\r
2683: dsb sy\r
269 isb\r
270 ret\r
271\r
272\r
273ASM_PFX(ArmDisableAlignmentCheck):\r
274 EL1_OR_EL2_OR_EL3(x1)\r
2751: mrs x0, sctlr_el1 // Get control register EL1\r
276 b 4f\r
2772: mrs x0, sctlr_el2 // Get control register EL2\r
278 b 4f\r
2793: mrs x0, sctlr_el3 // Get control register EL3\r
73ca5009 2804: and x0, x0, #~CTRL_A_BIT // Clear A (alignment check) bit\r
25402f5d
HL
281 EL1_OR_EL2_OR_EL3(x1)\r
2821: msr sctlr_el1, x0 // Write back control register\r
283 b 4f\r
2842: msr sctlr_el2, x0 // Write back control register\r
285 b 4f\r
2863: msr sctlr_el3, x0 // Write back control register\r
2874: dsb sy\r
288 isb\r
289 ret\r
290\r
291\r
292// Always turned on in AArch64. Else implementation specific. Leave in for C compatibility for now\r
293ASM_PFX(ArmEnableBranchPrediction):\r
294 ret\r
295\r
296\r
297// Always turned on in AArch64. Else implementation specific. Leave in for C compatibility for now.\r
298ASM_PFX(ArmDisableBranchPrediction):\r
299 ret\r
300\r
301\r
302ASM_PFX(AArch64AllDataCachesOperation):\r
303// We can use regs 0-7 and 9-15 without having to save/restore.\r
fb7ea611
OM
304// Save our link register on the stack. - The stack must always be quad-word aligned\r
305 str x30, [sp, #-16]!\r
25402f5d
HL
306 mov x1, x0 // Save Function call in x1\r
307 mrs x6, clidr_el1 // Read EL1 CLIDR\r
308 and x3, x6, #0x7000000 // Mask out all but Level of Coherency (LoC)\r
433a49a0
OM
309 lsr x3, x3, #23 // Left align cache level value - the level is shifted by 1 to the\r
310 // right to ease the access to CSSELR and the Set/Way operation.\r
25402f5d
HL
311 cbz x3, L_Finished // No need to clean if LoC is 0\r
312 mov x10, #0 // Start clean at cache level 0\r
25402f5d
HL
313\r
314Loop1:\r
315 add x2, x10, x10, lsr #1 // Work out 3x cachelevel for cache info\r
316 lsr x12, x6, x2 // bottom 3 bits are the Cache type for this level\r
317 and x12, x12, #7 // get those 3 bits alone\r
318 cmp x12, #2 // what cache at this level?\r
319 b.lt L_Skip // no cache or only instruction cache at this level\r
320 msr csselr_el1, x10 // write the Cache Size selection register with current level (CSSELR)\r
321 isb // isb to sync the change to the CacheSizeID reg\r
322 mrs x12, ccsidr_el1 // reads current Cache Size ID register (CCSIDR)\r
323 and x2, x12, #0x7 // extract the line length field\r
324 add x2, x2, #4 // add 4 for the line length offset (log2 16 bytes)\r
325 mov x4, #0x400\r
326 sub x4, x4, #1\r
327 and x4, x4, x12, lsr #3 // x4 is the max number on the way size (right aligned)\r
328 clz w5, w4 // w5 is the bit position of the way size increment\r
329 mov x7, #0x00008000\r
330 sub x7, x7, #1\r
331 and x7, x7, x12, lsr #13 // x7 is the max number of the index size (right aligned)\r
332\r
333Loop2:\r
334 mov x9, x4 // x9 working copy of the max way size (right aligned)\r
335\r
336Loop3:\r
337 lsl x11, x9, x5\r
338 orr x0, x10, x11 // factor in the way number and cache number\r
339 lsl x11, x7, x2\r
340 orr x0, x0, x11 // factor in the index number\r
341\r
342 blr x1 // Goto requested cache operation\r
343\r
344 subs x9, x9, #1 // decrement the way number\r
345 b.ge Loop3\r
346 subs x7, x7, #1 // decrement the index\r
347 b.ge Loop2\r
348L_Skip:\r
349 add x10, x10, #2 // increment the cache number\r
350 cmp x3, x10\r
351 b.gt Loop1\r
352\r
353L_Finished:\r
354 dsb sy\r
355 isb\r
356 ldr x30, [sp], #0x10\r
357 ret\r
358\r
359\r
360ASM_PFX(ArmDataMemoryBarrier):\r
361 dmb sy\r
362 ret\r
363\r
364\r
cf93a378 365ASM_PFX(ArmDataSynchronizationBarrier):\r
25402f5d
HL
366 dsb sy\r
367 ret\r
368\r
369\r
370ASM_PFX(ArmInstructionSynchronizationBarrier):\r
371 isb\r
372 ret\r
373\r
374\r
375ASM_PFX(ArmWriteVBar):\r
376 EL1_OR_EL2_OR_EL3(x1)\r
3771: msr vbar_el1, x0 // Set the Address of the EL1 Vector Table in the VBAR register\r
378 b 4f\r
3792: msr vbar_el2, x0 // Set the Address of the EL2 Vector Table in the VBAR register\r
380 b 4f\r
3813: msr vbar_el3, x0 // Set the Address of the EL3 Vector Table in the VBAR register\r
3824: isb\r
383 ret\r
384\r
f0247796
OM
385ASM_PFX(ArmReadVBar):\r
386 EL1_OR_EL2_OR_EL3(x1)\r
3871: mrs x0, vbar_el1 // Set the Address of the EL1 Vector Table in the VBAR register\r
388 ret\r
3892: mrs x0, vbar_el2 // Set the Address of the EL2 Vector Table in the VBAR register\r
390 ret\r
3913: mrs x0, vbar_el3 // Set the Address of the EL3 Vector Table in the VBAR register\r
392 ret\r
393\r
394\r
25402f5d
HL
395ASM_PFX(ArmEnableVFP):\r
396 // Check whether floating-point is implemented in the processor.\r
397 mov x1, x30 // Save LR\r
398 bl ArmReadIdPfr0 // Read EL1 Processor Feature Register (PFR0)\r
399 mov x30, x1 // Restore LR\r
400 ands x0, x0, #AARCH64_PFR0_FP// Extract bits indicating VFP implementation\r
401 cmp x0, #0 // VFP is implemented if '0'.\r
402 b.ne 4f // Exit if VFP not implemented.\r
403 // FVP is implemented.\r
404 // Make sure VFP exceptions are not trapped (to any exception level).\r
405 mrs x0, cpacr_el1 // Read EL1 Coprocessor Access Control Register (CPACR)\r
406 orr x0, x0, #CPACR_VFP_BITS // Disable FVP traps to EL1\r
407 msr cpacr_el1, x0 // Write back EL1 Coprocessor Access Control Register (CPACR)\r
408 mov x1, #AARCH64_CPTR_TFP // TFP Bit for trapping VFP Exceptions\r
409 EL1_OR_EL2_OR_EL3(x2)\r
4101:ret // Not configurable in EL1\r
4112:mrs x0, cptr_el2 // Disable VFP traps to EL2\r
412 bic x0, x0, x1\r
413 msr cptr_el2, x0\r
414 ret\r
4153:mrs x0, cptr_el3 // Disable VFP traps to EL3\r
416 bic x0, x0, x1\r
417 msr cptr_el3, x0\r
4184:ret\r
419\r
420\r
421ASM_PFX(ArmCallWFI):\r
422 wfi\r
423 ret\r
424\r
425\r
25402f5d
HL
426ASM_PFX(ArmReadMpidr):\r
427 mrs x0, mpidr_el1 // read EL1 MPIDR\r
428 ret\r
429\r
430\r
431// Keep old function names for C compatibilty for now. Change later?\r
432ASM_PFX(ArmReadTpidrurw):\r
433 mrs x0, tpidr_el0 // read tpidr_el0 (v7 TPIDRURW) -> (v8 TPIDR_EL0)\r
434 ret\r
435\r
436\r
437// Keep old function names for C compatibilty for now. Change later?\r
438ASM_PFX(ArmWriteTpidrurw):\r
439 msr tpidr_el0, x0 // write tpidr_el0 (v7 TPIDRURW) -> (v8 TPIDR_EL0)\r
440 ret\r
441\r
442\r
443// Arch timers are mandatory on AArch64\r
444ASM_PFX(ArmIsArchTimerImplemented):\r
445 mov x0, #1\r
446 ret\r
447\r
448\r
449ASM_PFX(ArmReadIdPfr0):\r
450 mrs x0, id_aa64pfr0_el1 // Read ID_AA64PFR0 Register\r
451 ret\r
452\r
453\r
454// Q: id_aa64pfr1_el1 not defined yet. What does this funtion want to access?\r
455// A: used to setup arch timer. Check if we have security extensions, permissions to set stuff.\r
456// See: ArmPkg/Library/ArmArchTimerLib/AArch64/ArmArchTimerLib.c\r
457// Not defined yet, but stick in here for now, should read all zeros.\r
458ASM_PFX(ArmReadIdPfr1):\r
459 mrs x0, id_aa64pfr1_el1 // Read ID_PFR1 Register\r
460 ret\r
461\r
462// VOID ArmWriteHcr(UINTN Hcr)\r
463ASM_PFX(ArmWriteHcr):\r
464 msr hcr_el2, x0 // Write the passed HCR value\r
465 ret\r
466\r
467// UINTN ArmReadCurrentEL(VOID)\r
468ASM_PFX(ArmReadCurrentEL):\r
469 mrs x0, CurrentEL\r
470 ret\r
471\r
25402f5d 472ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r