ArmPkg/ArmV7: Move the MMU specific macros into 'Chipset/ArmV7Mmu.h
[mirror_edk2.git] / ArmPkg / Include / Chipset / ArmV7Mmu.h
CommitLineData
d9e4abb1 1/** @file\r
2*\r
3* Copyright (c) 2011, ARM Limited. All rights reserved.\r
4* \r
5* This program and the accompanying materials \r
6* are licensed and made available under the terms and conditions of the BSD License \r
7* which accompanies this distribution. The full text of the license may be found at \r
8* http://opensource.org/licenses/bsd-license.php \r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12*\r
13**/\r
14\r
15#ifndef __ARMV7_MMU_H_\r
16#define __ARMV7_MMU_H_\r
17\r
18#define TTBR_NOT_OUTER_SHAREABLE BIT5\r
19#define TTBR_RGN_OUTER_NON_CACHEABLE 0\r
20#define TTBR_RGN_OUTER_WRITE_BACK_ALLOC BIT3\r
21#define TTBR_RGN_OUTER_WRITE_THROUGH BIT4\r
22#define TTBR_RGN_OUTER_WRITE_BACK_NO_ALLOC (BIT3|BIT4)\r
23#define TTBR_SHAREABLE BIT1\r
24#define TTBR_NON_SHAREABLE 0\r
25#define TTBR_INNER_CACHEABLE BIT0\r
26#define TTBR_NON_INNER_CACHEABLE BIT0\r
27#define TTBR_RGN_INNER_NON_CACHEABLE 0\r
28#define TTBR_RGN_INNER_WRITE_BACK_ALLOC BIT6\r
29#define TTBR_RGN_INNER_WRITE_THROUGH BIT0\r
30#define TTBR_RGN_INNER_WRITE_BACK_NO_ALLOC (BIT0|BIT6)\r
31\r
32#define TTBR_WRITE_THROUGH_NO_ALLOC ( TTBR_RGN_OUTER_WRITE_BACK_ALLOC | TTBR_RGN_INNER_WRITE_BACK_ALLOC )\r
33#define TTBR_WRITE_BACK_NO_ALLOC ( TTBR_RGN_OUTER_WRITE_BACK_NO_ALLOC | TTBR_RGN_INNER_WRITE_BACK_NO_ALLOC )\r
34#define TTBR_NON_CACHEABLE ( TTBR_RGN_OUTER_NON_CACHEABLE | TTBR_RGN_INNER_NON_CACHEABLE )\r
35#define TTBR_WRITE_BACK_ALLOC ( TTBR_RGN_OUTER_WRITE_BACK_ALLOC | TTBR_RGN_INNER_WRITE_BACK_ALLOC )\r
36\r
37\r
38#define TRANSLATION_TABLE_SECTION_COUNT 4096\r
39#define TRANSLATION_TABLE_SECTION_SIZE (sizeof(UINT32) * TRANSLATION_TABLE_SECTION_COUNT)\r
40#define TRANSLATION_TABLE_SECTION_ALIGNMENT (sizeof(UINT32) * TRANSLATION_TABLE_SECTION_COUNT)\r
41#define TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK (TRANSLATION_TABLE_SECTION_ALIGNMENT - 1)\r
42\r
43#define TRANSLATION_TABLE_PAGE_COUNT 256\r
44#define TRANSLATION_TABLE_PAGE_SIZE (sizeof(UINT32) * TRANSLATION_TABLE_PAGE_COUNT)\r
45#define TRANSLATION_TABLE_PAGE_ALIGNMENT (sizeof(UINT32) * TRANSLATION_TABLE_PAGE_COUNT)\r
46#define TRANSLATION_TABLE_PAGE_ALIGNMENT_MASK (TRANSLATION_TABLE_PAGE_ALIGNMENT - 1)\r
47\r
48#define TRANSLATION_TABLE_ENTRY_FOR_VIRTUAL_ADDRESS(table, address) ((UINT32 *)(table) + (((UINTN)(address)) >> 20))\r
49\r
50// Translation table descriptor types\r
51#define TT_DESCRIPTOR_SECTION_TYPE_MASK ((1UL << 18) | (3UL << 0))\r
52#define TT_DESCRIPTOR_SECTION_TYPE_FAULT (0UL << 0)\r
53#define TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE (1UL << 0)\r
54#define TT_DESCRIPTOR_SECTION_TYPE_SECTION ((0UL << 18) | (2UL << 0))\r
55#define TT_DESCRIPTOR_SECTION_TYPE_SUPERSECTION ((1UL << 18) | (2UL << 0))\r
56#define TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE(Desc) (((Desc) & 3UL) == TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE)\r
57\r
58// Translation table descriptor types\r
59#define TT_DESCRIPTOR_PAGE_TYPE_MASK (3UL << 0)\r
60#define TT_DESCRIPTOR_PAGE_TYPE_FAULT (0UL << 0)\r
61#define TT_DESCRIPTOR_PAGE_TYPE_PAGE (2UL << 0)\r
62#define TT_DESCRIPTOR_PAGE_TYPE_PAGE_XN (3UL << 0)\r
63#define TT_DESCRIPTOR_PAGE_TYPE_LARGEPAGE (1UL << 0)\r
64\r
65// Section descriptor definitions\r
66#define TT_DESCRIPTOR_SECTION_SIZE (0x00100000)\r
67\r
68#define TT_DESCRIPTOR_SECTION_NS_MASK (1UL << 19)\r
69#define TT_DESCRIPTOR_SECTION_NS_SECURE (0UL << 19)\r
70#define TT_DESCRIPTOR_SECTION_NS_NON_SECURE (1UL << 19)\r
71\r
72#define TT_DESCRIPTOR_SECTION_NG_MASK (1UL << 17)\r
73#define TT_DESCRIPTOR_SECTION_NG_GLOBAL (0UL << 17)\r
74#define TT_DESCRIPTOR_SECTION_NG_LOCAL (1UL << 17)\r
75\r
76#define TT_DESCRIPTOR_PAGE_NG_MASK (1UL << 11)\r
77#define TT_DESCRIPTOR_PAGE_NG_GLOBAL (0UL << 11)\r
78#define TT_DESCRIPTOR_PAGE_NG_LOCAL (1UL << 11)\r
79\r
80#define TT_DESCRIPTOR_SECTION_S_MASK (1UL << 16)\r
81#define TT_DESCRIPTOR_SECTION_S_NOT_SHARED (0UL << 16)\r
82#define TT_DESCRIPTOR_SECTION_S_SHARED (1UL << 16)\r
83\r
84#define TT_DESCRIPTOR_PAGE_S_MASK (1UL << 10)\r
85#define TT_DESCRIPTOR_PAGE_S_NOT_SHARED (0UL << 10)\r
86#define TT_DESCRIPTOR_PAGE_S_SHARED (1UL << 10)\r
87\r
88#define TT_DESCRIPTOR_SECTION_AP_MASK ((1UL << 15) | (3UL << 10))\r
89#define TT_DESCRIPTOR_SECTION_AP_NO_NO ((0UL << 15) | (0UL << 10))\r
90#define TT_DESCRIPTOR_SECTION_AP_RW_NO ((0UL << 15) | (1UL << 10))\r
91#define TT_DESCRIPTOR_SECTION_AP_RW_RO ((0UL << 15) | (2UL << 10))\r
92#define TT_DESCRIPTOR_SECTION_AP_RW_RW ((0UL << 15) | (3UL << 10))\r
93#define TT_DESCRIPTOR_SECTION_AP_RO_NO ((1UL << 15) | (1UL << 10))\r
94#define TT_DESCRIPTOR_SECTION_AP_RO_RO ((1UL << 15) | (3UL << 10))\r
95\r
96#define TT_DESCRIPTOR_PAGE_AP_MASK ((1UL << 9) | (3UL << 4))\r
97#define TT_DESCRIPTOR_PAGE_AP_NO_NO ((0UL << 9) | (0UL << 4))\r
98#define TT_DESCRIPTOR_PAGE_AP_RW_NO ((0UL << 9) | (1UL << 4))\r
99#define TT_DESCRIPTOR_PAGE_AP_RW_RO ((0UL << 9) | (2UL << 4))\r
100#define TT_DESCRIPTOR_PAGE_AP_RW_RW ((0UL << 9) | (3UL << 4))\r
101#define TT_DESCRIPTOR_PAGE_AP_RO_NO ((1UL << 9) | (1UL << 4))\r
102#define TT_DESCRIPTOR_PAGE_AP_RO_RO ((1UL << 9) | (3UL << 4))\r
103\r
104#define TT_DESCRIPTOR_SECTION_XN_MASK (0x1UL << 4)\r
105#define TT_DESCRIPTOR_PAGE_XN_MASK (0x1UL << 0)\r
106#define TT_DESCRIPTOR_LARGEPAGE_XN_MASK (0x1UL << 15)\r
107\r
108#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK ((3UL << 12) | (1UL << 3) | (1UL << 2))\r
109#define TT_DESCRIPTOR_SECTION_CACHEABLE_MASK (1UL << 3)\r
110#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 12) | (0UL << 3) | (0UL << 2))\r
111#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 12) | (0UL << 3) | (1UL << 2))\r
112#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 12) | (1UL << 3) | (0UL << 2))\r
113#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 12) | (1UL << 3) | (1UL << 2))\r
114#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE ((1UL << 12) | (0UL << 3) | (0UL << 2))\r
115#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 12) | (1UL << 3) | (1UL << 2))\r
116#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 12) | (0UL << 3) | (0UL << 2))\r
117\r
118#define TT_DESCRIPTOR_PAGE_SIZE (0x00001000)\r
119\r
120#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK ((3UL << 6) | (1UL << 3) | (1UL << 2))\r
121#define TT_DESCRIPTOR_PAGE_CACHEABLE_MASK (1UL << 3)\r
122#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 6) | (0UL << 3) | (0UL << 2))\r
123#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 6) | (0UL << 3) | (1UL << 2))\r
124#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 6) | (1UL << 3) | (0UL << 2))\r
125#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 6) | (1UL << 3) | (1UL << 2))\r
126#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE ((1UL << 6) | (0UL << 3) | (0UL << 2))\r
127#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 6) | (1UL << 3) | (1UL << 2))\r
128#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 6) | (0UL << 3) | (0UL << 2))\r
129\r
130#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_MASK ((3UL << 12) | (1UL << 3) | (1UL << 2))\r
131#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 12) | (0UL << 3) | (0UL << 2))\r
132#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 12) | (0UL << 3) | (1UL << 2))\r
133#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 12) | (1UL << 3) | (0UL << 2))\r
134#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 12) | (1UL << 3) | (1UL << 2))\r
135#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_NON_CACHEABLE ((1UL << 12) | (0UL << 3) | (0UL << 2))\r
136#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 12) | (1UL << 3) | (1UL << 2))\r
137#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 12) | (0UL << 3) | (0UL << 2))\r
138\r
139#define TT_DESCRIPTOR_CONVERT_TO_PAGE_AP(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_AP_MASK) >> 6) & TT_DESCRIPTOR_PAGE_AP_MASK)\r
140#define TT_DESCRIPTOR_CONVERT_TO_PAGE_NG(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_NG_MASK) >> 6) & TT_DESCRIPTOR_PAGE_NG_MASK)\r
141#define TT_DESCRIPTOR_CONVERT_TO_PAGE_S(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_S_MASK) >> 6) & TT_DESCRIPTOR_PAGE_S_MASK)\r
142#define TT_DESCRIPTOR_CONVERT_TO_PAGE_XN(Desc,IsLargePage) ((IsLargePage)? \\r
143 ((((Desc) & TT_DESCRIPTOR_SECTION_XN_MASK) >> 4) & TT_DESCRIPTOR_LARGEPAGE_XN_MASK): \\r
144 ((((Desc) & TT_DESCRIPTOR_SECTION_XN_MASK) << 11) & TT_DESCRIPTOR_PAGE_XN_MASK))\r
145#define TT_DESCRIPTOR_CONVERT_TO_PAGE_CACHE_POLICY(Desc,IsLargePage) (IsLargePage? \\r
146 (((Desc) & TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK) & TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_MASK): \\r
147 (((((Desc) & (0x3 << 12)) >> 6) | (Desc & (0x3 << 2)))))\r
148\r
149#define TT_DESCRIPTOR_CONVERT_TO_SECTION_AP(Desc) ((((Desc) & TT_DESCRIPTOR_PAGE_AP_MASK) << 6) & TT_DESCRIPTOR_SECTION_AP_MASK)\r
150\r
151#define TT_DESCRIPTOR_CONVERT_TO_SECTION_CACHE_POLICY(Desc,IsLargePage) (IsLargePage? \\r
152 (((Desc) & TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_MASK) & TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK): \\r
153 (((((Desc) & (0x3 << 6)) << 6) | (Desc & (0x3 << 2)))))\r
154\r
155\r
156#define TT_DESCRIPTOR_SECTION_DOMAIN_MASK (0x0FUL << 5)\r
157#define TT_DESCRIPTOR_SECTION_DOMAIN(a) (((a) & 0x0FUL) << 5)\r
158\r
159#define TT_DESCRIPTOR_SECTION_BASE_ADDRESS_MASK (0xFFF00000)\r
160#define TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK (0xFFFFFC00)\r
161#define TT_DESCRIPTOR_SECTION_BASE_ADDRESS(a) ((a) & TT_DESCRIPTOR_SECTION_BASE_ADDRESS_MASK)\r
162#define TT_DESCRIPTOR_SECTION_BASE_SHIFT 20\r
163\r
164#define TT_DESCRIPTOR_PAGE_BASE_ADDRESS_MASK (0xFFFFF000)\r
165#define TT_DESCRIPTOR_PAGE_INDEX_MASK (0x000FF000)\r
166#define TT_DESCRIPTOR_PAGE_BASE_ADDRESS(a) ((a) & TT_DESCRIPTOR_PAGE_BASE_ADDRESS_MASK)\r
167#define TT_DESCRIPTOR_PAGE_BASE_SHIFT 12\r
168\r
169#define TT_DESCRIPTOR_SECTION_WRITE_BACK(Secure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \\r
170 ((Secure) ? TT_DESCRIPTOR_SECTION_NS_SECURE : TT_DESCRIPTOR_SECTION_NS_NON_SECURE ) | \\r
171 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \\r
172 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \\r
173 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \\r
174 TT_DESCRIPTOR_SECTION_AP_RW_RW | \\r
175 TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC)\r
176#define TT_DESCRIPTOR_SECTION_WRITE_THROUGH(Secure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \\r
177 ((Secure) ? TT_DESCRIPTOR_SECTION_NS_SECURE : TT_DESCRIPTOR_SECTION_NS_NON_SECURE ) | \\r
178 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \\r
179 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \\r
180 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \\r
181 TT_DESCRIPTOR_SECTION_AP_RW_RW | \\r
182 TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC)\r
183#define TT_DESCRIPTOR_SECTION_DEVICE(Secure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \\r
184 ((Secure) ? TT_DESCRIPTOR_SECTION_NS_SECURE : TT_DESCRIPTOR_SECTION_NS_NON_SECURE ) | \\r
185 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \\r
186 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \\r
187 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \\r
188 TT_DESCRIPTOR_SECTION_AP_RW_RW | \\r
189 TT_DESCRIPTOR_SECTION_CACHE_POLICY_SHAREABLE_DEVICE)\r
190#define TT_DESCRIPTOR_SECTION_UNCACHED(Secure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \\r
191 ((Secure) ? TT_DESCRIPTOR_SECTION_NS_SECURE : TT_DESCRIPTOR_SECTION_NS_NON_SECURE ) | \\r
192 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \\r
193 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \\r
194 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \\r
195 TT_DESCRIPTOR_SECTION_AP_RW_RW | \\r
196 TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE)\r
197\r
198#define TT_DESCRIPTOR_PAGE_WRITE_BACK (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \\r
199 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \\r
200 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \\r
201 TT_DESCRIPTOR_PAGE_AP_RW_RW | \\r
202 TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC)\r
203#define TT_DESCRIPTOR_PAGE_WRITE_THROUGH (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \\r
204 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \\r
205 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \\r
206 TT_DESCRIPTOR_PAGE_AP_RW_RW | \\r
207 TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC)\r
208#define TT_DESCRIPTOR_PAGE_DEVICE (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \\r
209 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \\r
210 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \\r
211 TT_DESCRIPTOR_PAGE_AP_RW_RW | \\r
212 TT_DESCRIPTOR_PAGE_CACHE_POLICY_SHAREABLE_DEVICE)\r
213#define TT_DESCRIPTOR_PAGE_UNCACHED (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \\r
214 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \\r
215 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \\r
216 TT_DESCRIPTOR_PAGE_AP_RW_RW | \\r
217 TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE)\r
218\r
219#endif\r