ArmPkg/ArmV7Mmu.h: Fixed XN bit conversion from section to small/large page format
[mirror_edk2.git] / ArmPkg / Include / Chipset / ArmV7Mmu.h
CommitLineData
d9e4abb1 1/** @file\r
2*\r
7fffeef9 3* Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
d9e4abb1 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
7fffeef9 69#define TT_DESCRIPTOR_SECTION_NS (1UL << 19)\r
d9e4abb1 70\r
71#define TT_DESCRIPTOR_SECTION_NG_MASK (1UL << 17)\r
72#define TT_DESCRIPTOR_SECTION_NG_GLOBAL (0UL << 17)\r
73#define TT_DESCRIPTOR_SECTION_NG_LOCAL (1UL << 17)\r
74\r
75#define TT_DESCRIPTOR_PAGE_NG_MASK (1UL << 11)\r
76#define TT_DESCRIPTOR_PAGE_NG_GLOBAL (0UL << 11)\r
77#define TT_DESCRIPTOR_PAGE_NG_LOCAL (1UL << 11)\r
78\r
79#define TT_DESCRIPTOR_SECTION_S_MASK (1UL << 16)\r
80#define TT_DESCRIPTOR_SECTION_S_NOT_SHARED (0UL << 16)\r
81#define TT_DESCRIPTOR_SECTION_S_SHARED (1UL << 16)\r
82\r
83#define TT_DESCRIPTOR_PAGE_S_MASK (1UL << 10)\r
84#define TT_DESCRIPTOR_PAGE_S_NOT_SHARED (0UL << 10)\r
85#define TT_DESCRIPTOR_PAGE_S_SHARED (1UL << 10)\r
86\r
87#define TT_DESCRIPTOR_SECTION_AP_MASK ((1UL << 15) | (3UL << 10))\r
88#define TT_DESCRIPTOR_SECTION_AP_NO_NO ((0UL << 15) | (0UL << 10))\r
89#define TT_DESCRIPTOR_SECTION_AP_RW_NO ((0UL << 15) | (1UL << 10))\r
90#define TT_DESCRIPTOR_SECTION_AP_RW_RO ((0UL << 15) | (2UL << 10))\r
91#define TT_DESCRIPTOR_SECTION_AP_RW_RW ((0UL << 15) | (3UL << 10))\r
92#define TT_DESCRIPTOR_SECTION_AP_RO_NO ((1UL << 15) | (1UL << 10))\r
93#define TT_DESCRIPTOR_SECTION_AP_RO_RO ((1UL << 15) | (3UL << 10))\r
94\r
95#define TT_DESCRIPTOR_PAGE_AP_MASK ((1UL << 9) | (3UL << 4))\r
96#define TT_DESCRIPTOR_PAGE_AP_NO_NO ((0UL << 9) | (0UL << 4))\r
97#define TT_DESCRIPTOR_PAGE_AP_RW_NO ((0UL << 9) | (1UL << 4))\r
98#define TT_DESCRIPTOR_PAGE_AP_RW_RO ((0UL << 9) | (2UL << 4))\r
99#define TT_DESCRIPTOR_PAGE_AP_RW_RW ((0UL << 9) | (3UL << 4))\r
100#define TT_DESCRIPTOR_PAGE_AP_RO_NO ((1UL << 9) | (1UL << 4))\r
101#define TT_DESCRIPTOR_PAGE_AP_RO_RO ((1UL << 9) | (3UL << 4))\r
102\r
103#define TT_DESCRIPTOR_SECTION_XN_MASK (0x1UL << 4)\r
104#define TT_DESCRIPTOR_PAGE_XN_MASK (0x1UL << 0)\r
105#define TT_DESCRIPTOR_LARGEPAGE_XN_MASK (0x1UL << 15)\r
106\r
107#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK ((3UL << 12) | (1UL << 3) | (1UL << 2))\r
108#define TT_DESCRIPTOR_SECTION_CACHEABLE_MASK (1UL << 3)\r
109#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 12) | (0UL << 3) | (0UL << 2))\r
110#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 12) | (0UL << 3) | (1UL << 2))\r
111#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 12) | (1UL << 3) | (0UL << 2))\r
112#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 12) | (1UL << 3) | (1UL << 2))\r
113#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE ((1UL << 12) | (0UL << 3) | (0UL << 2))\r
114#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 12) | (1UL << 3) | (1UL << 2))\r
115#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 12) | (0UL << 3) | (0UL << 2))\r
116\r
117#define TT_DESCRIPTOR_PAGE_SIZE (0x00001000)\r
118\r
119#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK ((3UL << 6) | (1UL << 3) | (1UL << 2))\r
120#define TT_DESCRIPTOR_PAGE_CACHEABLE_MASK (1UL << 3)\r
121#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 6) | (0UL << 3) | (0UL << 2))\r
122#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 6) | (0UL << 3) | (1UL << 2))\r
123#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 6) | (1UL << 3) | (0UL << 2))\r
124#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 6) | (1UL << 3) | (1UL << 2))\r
125#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE ((1UL << 6) | (0UL << 3) | (0UL << 2))\r
126#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 6) | (1UL << 3) | (1UL << 2))\r
127#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 6) | (0UL << 3) | (0UL << 2))\r
128\r
129#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_MASK ((3UL << 12) | (1UL << 3) | (1UL << 2))\r
130#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 12) | (0UL << 3) | (0UL << 2))\r
131#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 12) | (0UL << 3) | (1UL << 2))\r
132#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 12) | (1UL << 3) | (0UL << 2))\r
133#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 12) | (1UL << 3) | (1UL << 2))\r
134#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_NON_CACHEABLE ((1UL << 12) | (0UL << 3) | (0UL << 2))\r
135#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 12) | (1UL << 3) | (1UL << 2))\r
136#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 12) | (0UL << 3) | (0UL << 2))\r
137\r
138#define TT_DESCRIPTOR_CONVERT_TO_PAGE_AP(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_AP_MASK) >> 6) & TT_DESCRIPTOR_PAGE_AP_MASK)\r
139#define TT_DESCRIPTOR_CONVERT_TO_PAGE_NG(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_NG_MASK) >> 6) & TT_DESCRIPTOR_PAGE_NG_MASK)\r
140#define TT_DESCRIPTOR_CONVERT_TO_PAGE_S(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_S_MASK) >> 6) & TT_DESCRIPTOR_PAGE_S_MASK)\r
141#define TT_DESCRIPTOR_CONVERT_TO_PAGE_XN(Desc,IsLargePage) ((IsLargePage)? \\r
e7e50d6b
OM
142 ((((Desc) & TT_DESCRIPTOR_SECTION_XN_MASK) << 11) & TT_DESCRIPTOR_LARGEPAGE_XN_MASK): \\r
143 ((((Desc) & TT_DESCRIPTOR_SECTION_XN_MASK) >> 4) & TT_DESCRIPTOR_PAGE_XN_MASK))\r
d9e4abb1 144#define TT_DESCRIPTOR_CONVERT_TO_PAGE_CACHE_POLICY(Desc,IsLargePage) (IsLargePage? \\r
145 (((Desc) & TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK) & TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_MASK): \\r
146 (((((Desc) & (0x3 << 12)) >> 6) | (Desc & (0x3 << 2)))))\r
147\r
148#define TT_DESCRIPTOR_CONVERT_TO_SECTION_AP(Desc) ((((Desc) & TT_DESCRIPTOR_PAGE_AP_MASK) << 6) & TT_DESCRIPTOR_SECTION_AP_MASK)\r
149\r
150#define TT_DESCRIPTOR_CONVERT_TO_SECTION_CACHE_POLICY(Desc,IsLargePage) (IsLargePage? \\r
151 (((Desc) & TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_MASK) & TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK): \\r
152 (((((Desc) & (0x3 << 6)) << 6) | (Desc & (0x3 << 2)))))\r
153\r
154\r
155#define TT_DESCRIPTOR_SECTION_DOMAIN_MASK (0x0FUL << 5)\r
156#define TT_DESCRIPTOR_SECTION_DOMAIN(a) (((a) & 0x0FUL) << 5)\r
157\r
158#define TT_DESCRIPTOR_SECTION_BASE_ADDRESS_MASK (0xFFF00000)\r
159#define TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK (0xFFFFFC00)\r
160#define TT_DESCRIPTOR_SECTION_BASE_ADDRESS(a) ((a) & TT_DESCRIPTOR_SECTION_BASE_ADDRESS_MASK)\r
161#define TT_DESCRIPTOR_SECTION_BASE_SHIFT 20\r
162\r
163#define TT_DESCRIPTOR_PAGE_BASE_ADDRESS_MASK (0xFFFFF000)\r
164#define TT_DESCRIPTOR_PAGE_INDEX_MASK (0x000FF000)\r
165#define TT_DESCRIPTOR_PAGE_BASE_ADDRESS(a) ((a) & TT_DESCRIPTOR_PAGE_BASE_ADDRESS_MASK)\r
166#define TT_DESCRIPTOR_PAGE_BASE_SHIFT 12\r
167\r
7fffeef9 168#define TT_DESCRIPTOR_SECTION_WRITE_BACK(NonSecure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \\r
169 ((NonSecure) ? TT_DESCRIPTOR_SECTION_NS : 0) | \\r
170 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \\r
171 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \\r
172 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \\r
173 TT_DESCRIPTOR_SECTION_AP_RW_RW | \\r
174 TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC)\r
175#define TT_DESCRIPTOR_SECTION_WRITE_THROUGH(NonSecure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \\r
176 ((NonSecure) ? TT_DESCRIPTOR_SECTION_NS : 0) | \\r
177 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \\r
178 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \\r
179 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \\r
180 TT_DESCRIPTOR_SECTION_AP_RW_RW | \\r
181 TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC)\r
182#define TT_DESCRIPTOR_SECTION_DEVICE(NonSecure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \\r
183 ((NonSecure) ? TT_DESCRIPTOR_SECTION_NS : 0) | \\r
184 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \\r
185 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \\r
186 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \\r
187 TT_DESCRIPTOR_SECTION_AP_RW_RW | \\r
188 TT_DESCRIPTOR_SECTION_CACHE_POLICY_SHAREABLE_DEVICE)\r
189#define TT_DESCRIPTOR_SECTION_UNCACHED(NonSecure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \\r
190 ((NonSecure) ? TT_DESCRIPTOR_SECTION_NS : 0) | \\r
191 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \\r
192 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \\r
193 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \\r
194 TT_DESCRIPTOR_SECTION_AP_RW_RW | \\r
195 TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE)\r
d9e4abb1 196\r
197#define TT_DESCRIPTOR_PAGE_WRITE_BACK (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \\r
198 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \\r
199 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \\r
200 TT_DESCRIPTOR_PAGE_AP_RW_RW | \\r
201 TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC)\r
202#define TT_DESCRIPTOR_PAGE_WRITE_THROUGH (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \\r
203 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \\r
204 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \\r
205 TT_DESCRIPTOR_PAGE_AP_RW_RW | \\r
206 TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC)\r
207#define TT_DESCRIPTOR_PAGE_DEVICE (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \\r
208 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \\r
209 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \\r
210 TT_DESCRIPTOR_PAGE_AP_RW_RW | \\r
211 TT_DESCRIPTOR_PAGE_CACHE_POLICY_SHAREABLE_DEVICE)\r
212#define TT_DESCRIPTOR_PAGE_UNCACHED (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \\r
213 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \\r
214 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \\r
215 TT_DESCRIPTOR_PAGE_AP_RW_RW | \\r
216 TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE)\r
217\r
218#endif\r