Sync up ArmPkg with patch from mailing list. Changed name of BdsLib.h to BdsUnixLib...
[mirror_edk2.git] / ArmPkg / Include / Chipset / ArmV7.h
1 /** @file
2
3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef __ARM_V7_H__
16 #define __ARM_V7_H__
17
18 // Domain Access Control Register
19 #define DOMAIN_ACCESS_CONTROL_MASK(a) (3UL << (2 * (a)))
20 #define DOMAIN_ACCESS_CONTROL_NONE(a) (0UL << (2 * (a)))
21 #define DOMAIN_ACCESS_CONTROL_CLIENT(a) (1UL << (2 * (a)))
22 #define DOMAIN_ACCESS_CONTROL_RESERVED(a) (2UL << (2 * (a)))
23 #define DOMAIN_ACCESS_CONTROL_MANAGER(a) (3UL << (2 * (a)))
24
25 #define TTBR_NOT_OUTER_SHAREABLE BIT5
26 #define TTBR_RGN_OUTER_NON_CACHEABLE 0
27 #define TTBR_RGN_OUTER_WRITE_BACK_ALLOC BIT3
28 #define TTBR_RGN_OUTER_WRITE_THROUGH BIT4
29 #define TTBR_RGN_OUTER_WRITE_BACK_NO_ALLOC (BIT3|BIT4)
30 #define TTBR_SHAREABLE BIT1
31 #define TTBR_NON_SHAREABLE 0
32 #define TTBR_INNER_CACHEABLE BIT0
33 #define TTBR_NON_INNER_CACHEABLE BIT0
34 #define TTBR_RGN_INNER_NON_CACHEABLE 0
35 #define TTBR_RGN_INNER_WRITE_BACK_ALLOC BIT6
36 #define TTBR_RGN_INNER_WRITE_THROUGH BIT0
37 #define TTBR_RGN_INNER_WRITE_BACK_NO_ALLOC (BIT0|BIT6)
38
39 #define TTBR_WRITE_THROUGH_NO_ALLOC ( TTBR_RGN_OUTER_WRITE_BACK_ALLOC | TTBR_RGN_INNER_WRITE_BACK_ALLOC )
40 #define TTBR_WRITE_BACK_NO_ALLOC ( TTBR_RGN_OUTER_WRITE_BACK_NO_ALLOC | TTBR_RGN_INNER_WRITE_BACK_NO_ALLOC )
41 #define TTBR_NON_CACHEABLE ( TTBR_RGN_OUTER_NON_CACHEABLE | TTBR_RGN_INNER_NON_CACHEABLE )
42 #define TTBR_WRITE_BACK_ALLOC ( TTBR_RGN_OUTER_WRITE_BACK_ALLOC | TTBR_RGN_INNER_WRITE_BACK_ALLOC )
43
44
45 #define TRANSLATION_TABLE_SECTION_COUNT 4096
46 #define TRANSLATION_TABLE_SECTION_SIZE (sizeof(UINT32) * TRANSLATION_TABLE_SECTION_COUNT)
47 #define TRANSLATION_TABLE_SECTION_ALIGNMENT (sizeof(UINT32) * TRANSLATION_TABLE_SECTION_COUNT)
48 #define TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK (TRANSLATION_TABLE_SECTION_ALIGNMENT - 1)
49
50 #define TRANSLATION_TABLE_PAGE_COUNT 256
51 #define TRANSLATION_TABLE_PAGE_SIZE (sizeof(UINT32) * TRANSLATION_TABLE_PAGE_COUNT)
52 #define TRANSLATION_TABLE_PAGE_ALIGNMENT (sizeof(UINT32) * TRANSLATION_TABLE_PAGE_COUNT)
53 #define TRANSLATION_TABLE_PAGE_ALIGNMENT_MASK (TRANSLATION_TABLE_PAGE_ALIGNMENT - 1)
54
55 #define TRANSLATION_TABLE_ENTRY_FOR_VIRTUAL_ADDRESS(table, address) ((UINT32 *)(table) + (((UINTN)(address)) >> 20))
56
57 // Translation table descriptor types
58 #define TT_DESCRIPTOR_SECTION_TYPE_MASK ((1UL << 18) | (3UL << 0))
59 #define TT_DESCRIPTOR_SECTION_TYPE_FAULT (0UL << 0)
60 #define TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE (1UL << 0)
61 #define TT_DESCRIPTOR_SECTION_TYPE_SECTION ((0UL << 18) | (2UL << 0))
62 #define TT_DESCRIPTOR_SECTION_TYPE_SUPERSECTION ((1UL << 18) | (2UL << 0))
63 #define TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE(Desc) (((Desc) & 3UL) == TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE)
64
65 // Translation table descriptor types
66 #define TT_DESCRIPTOR_PAGE_TYPE_MASK (3UL << 0)
67 #define TT_DESCRIPTOR_PAGE_TYPE_FAULT (0UL << 0)
68 #define TT_DESCRIPTOR_PAGE_TYPE_PAGE (2UL << 0)
69 #define TT_DESCRIPTOR_PAGE_TYPE_PAGE_XN (3UL << 0)
70 #define TT_DESCRIPTOR_PAGE_TYPE_LARGEPAGE (1UL << 0)
71
72 // Section descriptor definitions
73 #define TT_DESCRIPTOR_SECTION_SIZE (0x00100000)
74
75 #define TT_DESCRIPTOR_SECTION_NS_MASK (1UL << 19)
76 #define TT_DESCRIPTOR_SECTION_NS_SECURE (0UL << 19)
77 #define TT_DESCRIPTOR_SECTION_NS_NON_SECURE (1UL << 19)
78
79 #define TT_DESCRIPTOR_SECTION_NG_MASK (1UL << 17)
80 #define TT_DESCRIPTOR_SECTION_NG_GLOBAL (0UL << 17)
81 #define TT_DESCRIPTOR_SECTION_NG_LOCAL (1UL << 17)
82
83 #define TT_DESCRIPTOR_PAGE_NG_MASK (1UL << 11)
84 #define TT_DESCRIPTOR_PAGE_NG_GLOBAL (0UL << 11)
85 #define TT_DESCRIPTOR_PAGE_NG_LOCAL (1UL << 11)
86
87 #define TT_DESCRIPTOR_SECTION_S_MASK (1UL << 16)
88 #define TT_DESCRIPTOR_SECTION_S_NOT_SHARED (0UL << 16)
89 #define TT_DESCRIPTOR_SECTION_S_SHARED (1UL << 16)
90
91 #define TT_DESCRIPTOR_PAGE_S_MASK (1UL << 10)
92 #define TT_DESCRIPTOR_PAGE_S_NOT_SHARED (0UL << 10)
93 #define TT_DESCRIPTOR_PAGE_S_SHARED (1UL << 10)
94
95 #define TT_DESCRIPTOR_SECTION_AP_MASK ((1UL << 15) | (3UL << 10))
96 #define TT_DESCRIPTOR_SECTION_AP_NO_NO ((0UL << 15) | (0UL << 10))
97 #define TT_DESCRIPTOR_SECTION_AP_RW_NO ((0UL << 15) | (1UL << 10))
98 #define TT_DESCRIPTOR_SECTION_AP_RW_RO ((0UL << 15) | (2UL << 10))
99 #define TT_DESCRIPTOR_SECTION_AP_RW_RW ((0UL << 15) | (3UL << 10))
100 #define TT_DESCRIPTOR_SECTION_AP_RO_NO ((1UL << 15) | (1UL << 10))
101 #define TT_DESCRIPTOR_SECTION_AP_RO_RO ((1UL << 15) | (3UL << 10))
102
103 #define TT_DESCRIPTOR_PAGE_AP_MASK ((1UL << 9) | (3UL << 4))
104 #define TT_DESCRIPTOR_PAGE_AP_NO_NO ((0UL << 9) | (0UL << 4))
105 #define TT_DESCRIPTOR_PAGE_AP_RW_NO ((0UL << 9) | (1UL << 4))
106 #define TT_DESCRIPTOR_PAGE_AP_RW_RO ((0UL << 9) | (2UL << 4))
107 #define TT_DESCRIPTOR_PAGE_AP_RW_RW ((0UL << 9) | (3UL << 4))
108 #define TT_DESCRIPTOR_PAGE_AP_RO_NO ((1UL << 9) | (1UL << 4))
109 #define TT_DESCRIPTOR_PAGE_AP_RO_RO ((1UL << 9) | (3UL << 4))
110
111 #define TT_DESCRIPTOR_SECTION_XN_MASK (0x1UL << 4)
112 #define TT_DESCRIPTOR_PAGE_XN_MASK (0x1UL << 0)
113 #define TT_DESCRIPTOR_LARGEPAGE_XN_MASK (0x1UL << 15)
114
115 #define TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK ((3UL << 12) | (1UL << 3) | (1UL << 2))
116 #define TT_DESCRIPTOR_SECTION_CACHEABLE_MASK (1UL << 3)
117 #define TT_DESCRIPTOR_SECTION_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 12) | (0UL << 3) | (0UL << 2))
118 #define TT_DESCRIPTOR_SECTION_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 12) | (0UL << 3) | (1UL << 2))
119 #define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 12) | (1UL << 3) | (0UL << 2))
120 #define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 12) | (1UL << 3) | (1UL << 2))
121 #define TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE ((1UL << 12) | (0UL << 3) | (0UL << 2))
122 #define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 12) | (1UL << 3) | (1UL << 2))
123 #define TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 12) | (0UL << 3) | (0UL << 2))
124
125 #define TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK ((3UL << 6) | (1UL << 3) | (1UL << 2))
126 #define TT_DESCRIPTOR_PAGE_CACHEABLE_MASK (1UL << 3)
127 #define TT_DESCRIPTOR_PAGE_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 6) | (0UL << 3) | (0UL << 2))
128 #define TT_DESCRIPTOR_PAGE_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 6) | (0UL << 3) | (1UL << 2))
129 #define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 6) | (1UL << 3) | (0UL << 2))
130 #define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 6) | (1UL << 3) | (1UL << 2))
131 #define TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE ((1UL << 6) | (0UL << 3) | (0UL << 2))
132 #define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 6) | (1UL << 3) | (1UL << 2))
133 #define TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 6) | (0UL << 3) | (0UL << 2))
134
135 #define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_MASK ((3UL << 12) | (0UL << 3) | (0UL << 2))
136 #define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 12) | (0UL << 3) | (0UL << 2))
137 #define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 12) | (0UL << 3) | (1UL << 2))
138 #define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 12) | (1UL << 3) | (0UL << 2))
139 #define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 12) | (1UL << 3) | (1UL << 2))
140 #define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_NON_CACHEABLE ((1UL << 12) | (0UL << 3) | (0UL << 2))
141 #define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 12) | (1UL << 3) | (1UL << 2))
142 #define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 12) | (0UL << 3) | (0UL << 2))
143
144 #define TT_DESCRIPTOR_CONVERT_TO_PAGE_AP(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_AP_MASK) >> 6) & TT_DESCRIPTOR_PAGE_AP_MASK)
145 #define TT_DESCRIPTOR_CONVERT_TO_PAGE_NG(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_NG_MASK) >> 6) & TT_DESCRIPTOR_PAGE_NG_MASK)
146 #define TT_DESCRIPTOR_CONVERT_TO_PAGE_S(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_S_MASK) >> 6) & TT_DESCRIPTOR_PAGE_S_MASK)
147 #define TT_DESCRIPTOR_CONVERT_TO_PAGE_XN(Desc,IsLargePage) ((IsLargePage)? \
148 ((((Desc) & TT_DESCRIPTOR_SECTION_XN_MASK) >> 4) & TT_DESCRIPTOR_LARGEPAGE_XN_MASK): \
149 ((((Desc) & TT_DESCRIPTOR_SECTION_XN_MASK) << 11) & TT_DESCRIPTOR_PAGE_XN_MASK))
150 #define TT_DESCRIPTOR_CONVERT_TO_PAGE_CACHE_POLICY(Desc,IsLargePage) (IsLargePage? \
151 (((Desc) & TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK) & TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_MASK): \
152 (((((Desc) & (0x3 << 12)) >> 6) | (Desc & (0x3 << 2)))))
153
154 #define TT_DESCRIPTOR_SECTION_DOMAIN_MASK (0x0FUL << 5)
155 #define TT_DESCRIPTOR_SECTION_DOMAIN(a) (((a) & 0x0FUL) << 5)
156
157 #define TT_DESCRIPTOR_SECTION_BASE_ADDRESS_MASK (0xFFF00000)
158 #define TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK (0xFFFFFC00)
159 #define TT_DESCRIPTOR_SECTION_BASE_ADDRESS(a) ((a) & TT_DESCRIPTOR_SECTION_BASE_ADDRESS_MASK)
160 #define TT_DESCRIPTOR_SECTION_BASE_SHIFT 20
161
162 #define TT_DESCRIPTOR_PAGE_BASE_ADDRESS_MASK (0xFFFFF000)
163 #define TT_DESCRIPTOR_PAGE_INDEX_MASK (0x000FF000)
164 #define TT_DESCRIPTOR_PAGE_BASE_ADDRESS(a) ((a) & TT_DESCRIPTOR_PAGE_BASE_ADDRESS_MASK)
165 #define TT_DESCRIPTOR_PAGE_BASE_SHIFT 12
166
167 #define TT_DESCRIPTOR_SECTION_WRITE_BACK(Secure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \
168 ((Secure) ? TT_DESCRIPTOR_SECTION_NS_SECURE : TT_DESCRIPTOR_SECTION_NS_NON_SECURE ) | \
169 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \
170 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \
171 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \
172 TT_DESCRIPTOR_SECTION_AP_RW_RW | \
173 TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC)
174 #define TT_DESCRIPTOR_SECTION_WRITE_THROUGH(Secure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \
175 ((Secure) ? TT_DESCRIPTOR_SECTION_NS_SECURE : TT_DESCRIPTOR_SECTION_NS_NON_SECURE ) | \
176 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \
177 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \
178 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \
179 TT_DESCRIPTOR_SECTION_AP_RW_RW | \
180 TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC)
181 #define TT_DESCRIPTOR_SECTION_DEVICE(Secure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \
182 ((Secure) ? TT_DESCRIPTOR_SECTION_NS_SECURE : TT_DESCRIPTOR_SECTION_NS_NON_SECURE ) | \
183 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \
184 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \
185 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \
186 TT_DESCRIPTOR_SECTION_AP_RW_RW | \
187 TT_DESCRIPTOR_SECTION_CACHE_POLICY_SHAREABLE_DEVICE)
188 #define TT_DESCRIPTOR_SECTION_UNCACHED(Secure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \
189 ((Secure) ? TT_DESCRIPTOR_SECTION_NS_SECURE : TT_DESCRIPTOR_SECTION_NS_NON_SECURE ) | \
190 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \
191 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \
192 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \
193 TT_DESCRIPTOR_SECTION_AP_RW_RW | \
194 TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE)
195
196 // Cortex A9 feature bit definitions
197 #define A9_FEATURE_PARITY (1<<9)
198 #define A9_FEATURE_AOW (1<<8)
199 #define A9_FEATURE_EXCL (1<<7)
200 #define A9_FEATURE_SMP (1<<6)
201 #define A9_FEATURE_FOZ (1<<3)
202 #define A9_FEATURE_DPREF (1<<2)
203 #define A9_FEATURE_HINT (1<<1)
204 #define A9_FEATURE_FWD (1<<0)
205
206 // SCU register offsets & masks
207 #define SCU_CONTROL_OFFSET 0x0
208 #define SCU_CONFIG_OFFSET 0x4
209 #define SCU_INVALL_OFFSET 0xC
210 #define SCU_FILT_START_OFFSET 0x40
211 #define SCU_FILT_END_OFFSET 0x44
212 #define SCU_SACR_OFFSET 0x50
213 #define SCU_SSACR_OFFSET 0x54
214
215 #define SMP_GIC_CPUIF_BASE 0x100
216 #define SMP_GIC_DIST_BASE 0x1000
217
218 // CPACR - Coprocessor Access Control Register defintions
219 #define CPACR_CP_DENIED(cp) 0x00
220 #define CPACR_CP_PRIV(cp) ((0x1 << ((cp) << 1)) & 0x0FFFFFFF)
221 #define CPACR_CP_FULL(cp) ((0x3 << ((cp) << 1)) & 0x0FFFFFFF)
222 #define CPACR_ASEDIS (1 << 31)
223 #define CPACR_D32DIS (1 << 30)
224 #define CPACR_CP_FULL_ACCESS 0x0FFFFFFF
225
226 // NSACR - Non-Secure Access Control Register defintions
227 #define NSACR_CP(cp) ((1 << (cp)) & 0x3FFF)
228 #define NSACR_NSD32DIS (1 << 14)
229 #define NSACR_NSASEDIS (1 << 15)
230 #define NSACR_PLE (1 << 16)
231 #define NSACR_TL (1 << 17)
232 #define NSACR_NS_SMP (1 << 18)
233 #define NSACR_RFR (1 << 19)
234
235 // SCR - Secure Configuration Register defintions
236 #define SCR_NS (1 << 0)
237 #define SCR_IRQ (1 << 1)
238 #define SCR_FIQ (1 << 2)
239 #define SCR_EA (1 << 3)
240 #define SCR_FW (1 << 4)
241 #define SCR_AW (1 << 5)
242
243 VOID
244 EFIAPI
245 ArmEnableSWPInstruction (
246 VOID
247 );
248
249 VOID
250 EFIAPI
251 ArmWriteNsacr (
252 IN UINT32 SetWayFormat
253 );
254
255 VOID
256 EFIAPI
257 ArmWriteScr (
258 IN UINT32 SetWayFormat
259 );
260
261 VOID
262 EFIAPI
263 ArmWriteVMBar (
264 IN UINT32 SetWayFormat
265 );
266
267 VOID
268 EFIAPI
269 ArmWriteVBar (
270 IN UINT32 SetWayFormat
271 );
272
273 UINT32
274 EFIAPI
275 ArmReadVBar (
276 VOID
277 );
278
279 VOID
280 EFIAPI
281 ArmWriteCPACR (
282 IN UINT32 SetWayFormat
283 );
284
285 VOID
286 EFIAPI
287 ArmEnableVFP (
288 VOID
289 );
290
291 VOID
292 EFIAPI
293 ArmCallWFI (
294 VOID
295 );
296
297 VOID
298 EFIAPI
299 ArmInvalidScu (
300 VOID
301 );
302
303
304 UINTN
305 EFIAPI
306 ArmGetScuBaseAddress (
307 VOID
308 );
309
310 UINT32
311 EFIAPI
312 ArmIsScuEnable(
313 VOID
314 );
315
316 VOID
317 EFIAPI
318 ArmWriteAuxCr (
319 IN UINT32 Bit
320 );
321
322 UINT32
323 EFIAPI
324 ArmReadAuxCr (
325 VOID
326 );
327
328 VOID
329 EFIAPI
330 ArmSetAuxCrBit (
331 IN UINT32 Bits
332 );
333
334 VOID
335 EFIAPI
336 ArmSetupSmpNonSecure (
337 IN UINTN CoreId
338 );
339
340
341 UINTN
342 EFIAPI
343 ArmReadCbar(
344 VOID
345 );
346
347 VOID
348 EFIAPI
349 ArmInvalidateInstructionAndDataTlb(
350 VOID
351 );
352
353
354 UINTN
355 EFIAPI
356 ArmReadMpidr(
357 VOID
358 );
359
360
361 #endif // __ARM_V7_H__