]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmLib/AArch64/ArmLibSupport.S
ArmPkg/ArmMmuLib AARCH64: cache-invalidate initial page table entries
[mirror_edk2.git] / ArmPkg / Library / ArmLib / AArch64 / ArmLibSupport.S
CommitLineData
93deac7e
HL
1#------------------------------------------------------------------------------\r
2#\r
3# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
07783fdd 4# Copyright (c) 2011 - 2016, ARM Limited. All rights reserved.\r
0efaa42f 5# Copyright (c) 2016, Linaro Limited. All rights reserved.\r
93deac7e 6#\r
4059386c 7# SPDX-License-Identifier: BSD-2-Clause-Patent\r
93deac7e
HL
8#\r
9#------------------------------------------------------------------------------\r
10\r
11#include <AsmMacroIoLibV8.h>\r
12\r
4af3dd80
EC
13.set DAIF_RD_FIQ_BIT, (1 << 6)\r
14.set DAIF_RD_IRQ_BIT, (1 << 7)\r
93deac7e 15\r
3391e20f
AB
16.set SCTLR_ELx_M_BIT_POS, (0)\r
17\r
0efaa42f 18ASM_FUNC(ArmReadMidr)\r
93deac7e
HL
19 mrs x0, midr_el1 // Read from Main ID Register (MIDR)\r
20 ret\r
21\r
0efaa42f 22ASM_FUNC(ArmCacheInfo)\r
93deac7e
HL
23 mrs x0, ctr_el0 // Read from Cache Type Regiter (CTR)\r
24 ret\r
25\r
0efaa42f 26ASM_FUNC(ArmGetInterruptState)\r
93deac7e 27 mrs x0, daif\r
4af3dd80
EC
28 tst w0, #DAIF_RD_IRQ_BIT // Check if IRQ is enabled. Enabled if 0 (Z=1)\r
29 cset w0, eq // if Z=1 return 1, else 0\r
93deac7e
HL
30 ret\r
31\r
0efaa42f 32ASM_FUNC(ArmGetFiqState)\r
93deac7e 33 mrs x0, daif\r
4af3dd80
EC
34 tst w0, #DAIF_RD_FIQ_BIT // Check if FIQ is enabled. Enabled if 0 (Z=1)\r
35 cset w0, eq // if Z=1 return 1, else 0\r
93deac7e
HL
36 ret\r
37\r
0efaa42f 38ASM_FUNC(ArmWriteCpacr)\r
93deac7e
HL
39 msr cpacr_el1, x0 // Coprocessor Access Control Reg (CPACR)\r
40 ret\r
41\r
0efaa42f 42ASM_FUNC(ArmWriteAuxCr)\r
93deac7e
HL
43 EL1_OR_EL2(x1)\r
441:msr actlr_el1, x0 // Aux Control Reg (ACTLR) at EL1. Also available in EL2 and EL3\r
27995cd5 45 ret\r
93deac7e 462:msr actlr_el2, x0 // Aux Control Reg (ACTLR) at EL1. Also available in EL2 and EL3\r
27995cd5 47 ret\r
93deac7e 48\r
0efaa42f 49ASM_FUNC(ArmReadAuxCr)\r
93deac7e
HL
50 EL1_OR_EL2(x1)\r
511:mrs x0, actlr_el1 // Aux Control Reg (ACTLR) at EL1. Also available in EL2 and EL3\r
27995cd5 52 ret\r
93deac7e 532:mrs x0, actlr_el2 // Aux Control Reg (ACTLR) at EL1. Also available in EL2 and EL3\r
27995cd5 54 ret\r
93deac7e 55\r
0efaa42f 56ASM_FUNC(ArmSetTTBR0)\r
93deac7e
HL
57 EL1_OR_EL2_OR_EL3(x1)\r
581:msr ttbr0_el1, x0 // Translation Table Base Reg 0 (TTBR0)\r
59 b 4f\r
602:msr ttbr0_el2, x0 // Translation Table Base Reg 0 (TTBR0)\r
61 b 4f\r
623:msr ttbr0_el3, x0 // Translation Table Base Reg 0 (TTBR0)\r
634:isb\r
64 ret\r
65\r
0efaa42f 66ASM_FUNC(ArmGetTTBR0BaseAddress)\r
93deac7e
HL
67 EL1_OR_EL2(x1)\r
681:mrs x0, ttbr0_el1\r
69 b 3f\r
702:mrs x0, ttbr0_el2\r
0efaa42f 713:and x0, x0, 0xFFFFFFFFFFFF /* Look at bottom 48 bits */\r
93deac7e
HL
72 isb\r
73 ret\r
74\r
0efaa42f 75ASM_FUNC(ArmGetTCR)\r
93deac7e
HL
76 EL1_OR_EL2_OR_EL3(x1)\r
771:mrs x0, tcr_el1\r
78 b 4f\r
792:mrs x0, tcr_el2\r
80 b 4f\r
813:mrs x0, tcr_el3\r
824:isb\r
83 ret\r
84\r
0efaa42f 85ASM_FUNC(ArmSetTCR)\r
93deac7e
HL
86 EL1_OR_EL2_OR_EL3(x1)\r
871:msr tcr_el1, x0\r
88 b 4f\r
892:msr tcr_el2, x0\r
90 b 4f\r
913:msr tcr_el3, x0\r
924:isb\r
93 ret\r
94\r
0efaa42f 95ASM_FUNC(ArmGetMAIR)\r
93deac7e
HL
96 EL1_OR_EL2_OR_EL3(x1)\r
971:mrs x0, mair_el1\r
98 b 4f\r
992:mrs x0, mair_el2\r
100 b 4f\r
1013:mrs x0, mair_el3\r
1024:isb\r
103 ret\r
104\r
0efaa42f 105ASM_FUNC(ArmSetMAIR)\r
93deac7e
HL
106 EL1_OR_EL2_OR_EL3(x1)\r
1071:msr mair_el1, x0\r
108 b 4f\r
1092:msr mair_el2, x0\r
110 b 4f\r
1113:msr mair_el3, x0\r
1124:isb\r
113 ret\r
114\r
115\r
116//\r
117//VOID\r
118//ArmUpdateTranslationTableEntry (\r
119// IN VOID *TranslationTableEntry // X0\r
120// IN VOID *MVA // X1\r
121// );\r
0efaa42f 122ASM_FUNC(ArmUpdateTranslationTableEntry)\r
d5788777
AB
123 dsb nshst\r
124 lsr x1, x1, #12\r
93deac7e
HL
125 EL1_OR_EL2_OR_EL3(x0)\r
1261: tlbi vaae1, x1 // TLB Invalidate VA , EL1\r
3391e20f 127 mrs x2, sctlr_el1\r
93deac7e
HL
128 b 4f\r
1292: tlbi vae2, x1 // TLB Invalidate VA , EL2\r
3391e20f 130 mrs x2, sctlr_el2\r
93deac7e
HL
131 b 4f\r
1323: tlbi vae3, x1 // TLB Invalidate VA , EL3\r
3391e20f
AB
133 mrs x2, sctlr_el3\r
1344: tbnz x2, SCTLR_ELx_M_BIT_POS, 5f\r
135 dc ivac, x0 // invalidate in Dcache if MMU is still off\r
1365: dsb nsh\r
93deac7e
HL
137 isb\r
138 ret\r
139\r
0efaa42f 140ASM_FUNC(ArmInvalidateTlb)\r
93deac7e 141 EL1_OR_EL2_OR_EL3(x0)\r
70f89c0b 1421: tlbi vmalle1\r
93deac7e
HL
143 b 4f\r
1442: tlbi alle2\r
145 b 4f\r
1463: tlbi alle3\r
1474: dsb sy\r
148 isb\r
149 ret\r
150\r
0efaa42f 151ASM_FUNC(ArmWriteCptr)\r
93deac7e 152 msr cptr_el3, x0 // EL3 Coprocessor Trap Reg (CPTR)\r
d6dc67ba 153 ret\r
93deac7e 154\r
0efaa42f 155ASM_FUNC(ArmWriteScr)\r
93deac7e 156 msr scr_el3, x0 // Secure configuration register EL3\r
b2d0e0c5 157 isb\r
93deac7e
HL
158 ret\r
159\r
0efaa42f 160ASM_FUNC(ArmWriteMVBar)\r
27995cd5 161 msr vbar_el3, x0 // Exception Vector Base address for Monitor on EL3\r
93deac7e
HL
162 ret\r
163\r
0efaa42f 164ASM_FUNC(ArmCallWFE)\r
93deac7e
HL
165 wfe\r
166 ret\r
167\r
0efaa42f 168ASM_FUNC(ArmCallSEV)\r
93deac7e
HL
169 sev\r
170 ret\r
171\r
0efaa42f 172ASM_FUNC(ArmReadCpuActlr)\r
52d44f77
OM
173 mrs x0, S3_1_c15_c2_0\r
174 ret\r
175\r
0efaa42f 176ASM_FUNC(ArmWriteCpuActlr)\r
52d44f77
OM
177 msr S3_1_c15_c2_0, x0\r
178 dsb sy\r
179 isb\r
180 ret\r
93deac7e 181\r
0efaa42f 182ASM_FUNC(ArmReadSctlr)\r
07783fdd
SV
183 EL1_OR_EL2_OR_EL3(x1)\r
1841:mrs x0, sctlr_el1\r
185 ret\r
1862:mrs x0, sctlr_el2\r
187 ret\r
1883:mrs x0, sctlr_el3\r
1894:ret\r
190\r
1e1d1697
MZ
191ASM_FUNC(ArmWriteSctlr)\r
192 EL1_OR_EL2_OR_EL3(x1)\r
1931:msr sctlr_el1, x0\r
194 ret\r
1952:msr sctlr_el2, x0\r
196 ret\r
1973:msr sctlr_el3, x0\r
1984:ret\r
199\r
95d04ebc
AB
200ASM_FUNC(ArmGetPhysicalAddressBits)\r
201 mrs x0, id_aa64mmfr0_el1\r
202 adr x1, .LPARanges\r
203 and x0, x0, #0xf\r
204 ldrb w0, [x1, x0]\r
205 ret\r
206\r
207//\r
208// Bits 0..3 of the AA64MFR0_EL1 system register encode the size of the\r
209// physical address space support on this CPU:\r
210// 0 == 32 bits, 1 == 36 bits, etc etc\r
211// 7 and up are reserved\r
212//\r
213.LPARanges:\r
214 .byte 32, 36, 40, 42, 44, 48, 52, 0\r
215 .byte 0, 0, 0, 0, 0, 0, 0, 0\r
216\r
93deac7e 217ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r