]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmLib/Common/AArch64/ArmLibSupport.S
ArmPkg/ArmLib: Added helper functions for accessing CPU ACTLR
[mirror_edk2.git] / ArmPkg / Library / ArmLib / Common / AArch64 / ArmLibSupport.S
CommitLineData
93deac7e
HL
1#------------------------------------------------------------------------------\r
2#\r
3# Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
eaa84fd5 4# Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.\r
93deac7e
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 <AsmMacroIoLibV8.h>\r
17\r
18.text\r
19.align 3\r
f6c5a29b 20GCC_ASM_EXPORT (ArmReadMidr)\r
93deac7e
HL
21GCC_ASM_EXPORT (ArmCacheInfo)\r
22GCC_ASM_EXPORT (ArmGetInterruptState)\r
23GCC_ASM_EXPORT (ArmGetFiqState)\r
24GCC_ASM_EXPORT (ArmGetTTBR0BaseAddress)\r
25GCC_ASM_EXPORT (ArmSetTTBR0)\r
26GCC_ASM_EXPORT (ArmGetTCR)\r
27GCC_ASM_EXPORT (ArmSetTCR)\r
28GCC_ASM_EXPORT (ArmGetMAIR)\r
29GCC_ASM_EXPORT (ArmSetMAIR)\r
30GCC_ASM_EXPORT (ArmWriteCpacr)\r
31GCC_ASM_EXPORT (ArmWriteAuxCr)\r
32GCC_ASM_EXPORT (ArmReadAuxCr)\r
33GCC_ASM_EXPORT (ArmInvalidateTlb)\r
34GCC_ASM_EXPORT (ArmUpdateTranslationTableEntry)\r
d6dc67ba 35GCC_ASM_EXPORT (ArmWriteCptr)\r
93deac7e
HL
36GCC_ASM_EXPORT (ArmWriteScr)\r
37GCC_ASM_EXPORT (ArmWriteMVBar)\r
38GCC_ASM_EXPORT (ArmCallWFE)\r
39GCC_ASM_EXPORT (ArmCallSEV)\r
52d44f77
OM
40GCC_ASM_EXPORT (ArmReadCpuExCr)\r
41GCC_ASM_EXPORT (ArmWriteCpuExCr)\r
42GCC_ASM_EXPORT (ArmReadCpuActlr)\r
43GCC_ASM_EXPORT (ArmWriteCpuActlr)\r
93deac7e
HL
44\r
45#------------------------------------------------------------------------------\r
46\r
47.set DAIF_FIQ_BIT, (1 << 0)\r
48.set DAIF_IRQ_BIT, (1 << 1)\r
49\r
f6c5a29b 50ASM_PFX(ArmReadMidr):\r
93deac7e
HL
51 mrs x0, midr_el1 // Read from Main ID Register (MIDR)\r
52 ret\r
53\r
54ASM_PFX(ArmCacheInfo):\r
55 mrs x0, ctr_el0 // Read from Cache Type Regiter (CTR)\r
56 ret\r
57\r
58ASM_PFX(ArmGetInterruptState):\r
59 mrs x0, daif\r
60 tst w0, #DAIF_IRQ_BIT // Check if IRQ is enabled. Enabled if 0.\r
61 mov w0, #0\r
62 mov w1, #1\r
63 csel w0, w1, w0, ne\r
64 ret\r
65\r
66ASM_PFX(ArmGetFiqState):\r
67 mrs x0, daif\r
68 tst w0, #DAIF_FIQ_BIT // Check if FIQ is enabled. Enabled if 0.\r
69 mov w0, #0\r
70 mov w1, #1\r
71 csel w0, w1, w0, ne\r
72 ret\r
73\r
74ASM_PFX(ArmWriteCpacr):\r
75 msr cpacr_el1, x0 // Coprocessor Access Control Reg (CPACR)\r
76 ret\r
77\r
78ASM_PFX(ArmWriteAuxCr):\r
79 EL1_OR_EL2(x1)\r
801:msr actlr_el1, x0 // Aux Control Reg (ACTLR) at EL1. Also available in EL2 and EL3\r
27995cd5 81 ret\r
93deac7e 822:msr actlr_el2, x0 // Aux Control Reg (ACTLR) at EL1. Also available in EL2 and EL3\r
27995cd5 83 ret\r
93deac7e
HL
84\r
85ASM_PFX(ArmReadAuxCr):\r
86 EL1_OR_EL2(x1)\r
871:mrs x0, actlr_el1 // Aux Control Reg (ACTLR) at EL1. Also available in EL2 and EL3\r
27995cd5 88 ret\r
93deac7e 892:mrs x0, actlr_el2 // Aux Control Reg (ACTLR) at EL1. Also available in EL2 and EL3\r
27995cd5 90 ret\r
93deac7e
HL
91\r
92ASM_PFX(ArmSetTTBR0):\r
93 EL1_OR_EL2_OR_EL3(x1)\r
941:msr ttbr0_el1, x0 // Translation Table Base Reg 0 (TTBR0)\r
95 b 4f\r
962:msr ttbr0_el2, x0 // Translation Table Base Reg 0 (TTBR0)\r
97 b 4f\r
983:msr ttbr0_el3, x0 // Translation Table Base Reg 0 (TTBR0)\r
994:isb\r
100 ret\r
101\r
102ASM_PFX(ArmGetTTBR0BaseAddress):\r
103 EL1_OR_EL2(x1)\r
1041:mrs x0, ttbr0_el1\r
105 b 3f\r
1062:mrs x0, ttbr0_el2\r
1073:LoadConstantToReg(0xFFFFFFFFFFFF, x1) /* Look at bottom 48 bits */\r
108 and x0, x0, x1\r
109 isb\r
110 ret\r
111\r
112ASM_PFX(ArmGetTCR):\r
113 EL1_OR_EL2_OR_EL3(x1)\r
1141:mrs x0, tcr_el1\r
115 b 4f\r
1162:mrs x0, tcr_el2\r
117 b 4f\r
1183:mrs x0, tcr_el3\r
1194:isb\r
120 ret\r
121\r
122ASM_PFX(ArmSetTCR):\r
123 EL1_OR_EL2_OR_EL3(x1)\r
1241:msr tcr_el1, x0\r
125 b 4f\r
1262:msr tcr_el2, x0\r
127 b 4f\r
1283:msr tcr_el3, x0\r
1294:isb\r
130 ret\r
131\r
132ASM_PFX(ArmGetMAIR):\r
133 EL1_OR_EL2_OR_EL3(x1)\r
1341:mrs x0, mair_el1\r
135 b 4f\r
1362:mrs x0, mair_el2\r
137 b 4f\r
1383:mrs x0, mair_el3\r
1394:isb\r
140 ret\r
141\r
142ASM_PFX(ArmSetMAIR):\r
143 EL1_OR_EL2_OR_EL3(x1)\r
1441:msr mair_el1, x0\r
145 b 4f\r
1462:msr mair_el2, x0\r
147 b 4f\r
1483:msr mair_el3, x0\r
1494:isb\r
150 ret\r
151\r
152\r
153//\r
154//VOID\r
155//ArmUpdateTranslationTableEntry (\r
156// IN VOID *TranslationTableEntry // X0\r
157// IN VOID *MVA // X1\r
158// );\r
159ASM_PFX(ArmUpdateTranslationTableEntry):\r
160 dc civac, x0 // Clean and invalidate data line\r
161 dsb sy\r
162 EL1_OR_EL2_OR_EL3(x0)\r
1631: tlbi vaae1, x1 // TLB Invalidate VA , EL1\r
164 b 4f\r
1652: tlbi vae2, x1 // TLB Invalidate VA , EL2\r
166 b 4f\r
1673: tlbi vae3, x1 // TLB Invalidate VA , EL3\r
1684: dsb sy\r
169 isb\r
170 ret\r
171\r
172ASM_PFX(ArmInvalidateTlb):\r
173 EL1_OR_EL2_OR_EL3(x0)\r
70f89c0b 1741: tlbi vmalle1\r
93deac7e
HL
175 b 4f\r
1762: tlbi alle2\r
177 b 4f\r
1783: tlbi alle3\r
1794: dsb sy\r
180 isb\r
181 ret\r
182\r
d6dc67ba 183ASM_PFX(ArmWriteCptr):\r
93deac7e 184 msr cptr_el3, x0 // EL3 Coprocessor Trap Reg (CPTR)\r
d6dc67ba 185 ret\r
93deac7e
HL
186\r
187ASM_PFX(ArmWriteScr):\r
188 msr scr_el3, x0 // Secure configuration register EL3\r
189 ret\r
190\r
191ASM_PFX(ArmWriteMVBar):\r
27995cd5 192 msr vbar_el3, x0 // Exception Vector Base address for Monitor on EL3\r
93deac7e
HL
193 ret\r
194\r
195ASM_PFX(ArmCallWFE):\r
196 wfe\r
197 ret\r
198\r
199ASM_PFX(ArmCallSEV):\r
200 sev\r
201 ret\r
202\r
52d44f77
OM
203ASM_PFX(ArmReadCpuExCr):\r
204 mrs x0, S3_1_c15_c2_1\r
205 ret\r
206\r
207ASM_PFX(ArmWriteCpuExCr):\r
208 msr S3_1_c15_c2_1, x0\r
209 dsb sy\r
210 isb\r
211 ret\r
212\r
213ASM_PFX(ArmReadCpuActlr):\r
214 mrs x0, S3_1_c15_c2_0\r
215 ret\r
216\r
217ASM_PFX(ArmWriteCpuActlr):\r
218 msr S3_1_c15_c2_0, x0\r
219 dsb sy\r
220 isb\r
221 ret\r
93deac7e
HL
222\r
223ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r