12#define TTBR_NOT_OUTER_SHAREABLE BIT5
13#define TTBR_RGN_OUTER_NON_CACHEABLE 0
14#define TTBR_RGN_OUTER_WRITE_BACK_ALLOC BIT3
15#define TTBR_RGN_OUTER_WRITE_THROUGH BIT4
16#define TTBR_RGN_OUTER_WRITE_BACK_NO_ALLOC (BIT3|BIT4)
17#define TTBR_SHAREABLE BIT1
18#define TTBR_NON_SHAREABLE 0
19#define TTBR_INNER_CACHEABLE BIT0
20#define TTBR_INNER_NON_CACHEABLE 0
21#define TTBR_RGN_INNER_NON_CACHEABLE 0
22#define TTBR_RGN_INNER_WRITE_BACK_ALLOC BIT6
23#define TTBR_RGN_INNER_WRITE_THROUGH BIT0
24#define TTBR_RGN_INNER_WRITE_BACK_NO_ALLOC (BIT0|BIT6)
26#define TTBR_WRITE_THROUGH ( TTBR_RGN_OUTER_WRITE_THROUGH | TTBR_INNER_CACHEABLE | TTBR_SHAREABLE)
27#define TTBR_WRITE_BACK_NO_ALLOC ( TTBR_RGN_OUTER_WRITE_BACK_NO_ALLOC | TTBR_INNER_CACHEABLE | TTBR_SHAREABLE)
28#define TTBR_NON_CACHEABLE ( TTBR_RGN_OUTER_NON_CACHEABLE | TTBR_INNER_NON_CACHEABLE )
29#define TTBR_WRITE_BACK_ALLOC ( TTBR_RGN_OUTER_WRITE_BACK_ALLOC | TTBR_INNER_CACHEABLE | TTBR_SHAREABLE)
31#define TTBR_MP_WRITE_THROUGH ( TTBR_RGN_OUTER_WRITE_THROUGH | TTBR_RGN_INNER_WRITE_THROUGH | TTBR_SHAREABLE)
32#define TTBR_MP_WRITE_BACK_NO_ALLOC ( TTBR_RGN_OUTER_WRITE_BACK_NO_ALLOC | TTBR_RGN_INNER_WRITE_BACK_NO_ALLOC | TTBR_SHAREABLE)
33#define TTBR_MP_NON_CACHEABLE ( TTBR_RGN_OUTER_NON_CACHEABLE | TTBR_RGN_INNER_NON_CACHEABLE )
34#define TTBR_MP_WRITE_BACK_ALLOC ( TTBR_RGN_OUTER_WRITE_BACK_ALLOC | TTBR_RGN_INNER_WRITE_BACK_ALLOC | TTBR_SHAREABLE)
36#define TRANSLATION_TABLE_SECTION_COUNT 4096
37#define TRANSLATION_TABLE_SECTION_SIZE (sizeof(UINT32) * TRANSLATION_TABLE_SECTION_COUNT)
38#define TRANSLATION_TABLE_SECTION_ALIGNMENT (sizeof(UINT32) * TRANSLATION_TABLE_SECTION_COUNT)
39#define TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK (TRANSLATION_TABLE_SECTION_ALIGNMENT - 1)
41#define TRANSLATION_TABLE_PAGE_COUNT 256
42#define TRANSLATION_TABLE_PAGE_SIZE (sizeof(UINT32) * TRANSLATION_TABLE_PAGE_COUNT)
43#define TRANSLATION_TABLE_PAGE_ALIGNMENT (sizeof(UINT32) * TRANSLATION_TABLE_PAGE_COUNT)
44#define TRANSLATION_TABLE_PAGE_ALIGNMENT_MASK (TRANSLATION_TABLE_PAGE_ALIGNMENT - 1)
46#define TRANSLATION_TABLE_ENTRY_FOR_VIRTUAL_ADDRESS(table, address) ((UINT32 *)(table) + (((UINTN)(address)) >> 20))
49#define TT_DESCRIPTOR_SECTION_TYPE_MASK ((1UL << 18) | (3UL << 0))
50#define TT_DESCRIPTOR_SECTION_TYPE_FAULT (0UL << 0)
51#define TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE (1UL << 0)
52#define TT_DESCRIPTOR_SECTION_TYPE_SECTION ((0UL << 18) | (2UL << 0))
53#define TT_DESCRIPTOR_SECTION_TYPE_SUPERSECTION ((1UL << 18) | (2UL << 0))
54#define TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE(Desc) (((Desc) & 3UL) == TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE)
57#define TT_DESCRIPTOR_PAGE_TYPE_MASK (1UL << 1)
58#define TT_DESCRIPTOR_PAGE_TYPE_FAULT (0UL << 1)
59#define TT_DESCRIPTOR_PAGE_TYPE_PAGE (1UL << 1)
62#define TT_DESCRIPTOR_SECTION_SIZE (0x00100000)
64#define TT_DESCRIPTOR_SECTION_NS_MASK (1UL << 19)
65#define TT_DESCRIPTOR_SECTION_NS (1UL << 19)
67#define TT_DESCRIPTOR_SECTION_NG_MASK (1UL << 17)
68#define TT_DESCRIPTOR_SECTION_NG_GLOBAL (0UL << 17)
69#define TT_DESCRIPTOR_SECTION_NG_LOCAL (1UL << 17)
71#define TT_DESCRIPTOR_PAGE_NG_MASK (1UL << 11)
72#define TT_DESCRIPTOR_PAGE_NG_GLOBAL (0UL << 11)
73#define TT_DESCRIPTOR_PAGE_NG_LOCAL (1UL << 11)
75#define TT_DESCRIPTOR_SECTION_S_MASK (1UL << 16)
76#define TT_DESCRIPTOR_SECTION_S_NOT_SHARED (0UL << 16)
77#define TT_DESCRIPTOR_SECTION_S_SHARED (1UL << 16)
79#define TT_DESCRIPTOR_PAGE_S_MASK (1UL << 10)
80#define TT_DESCRIPTOR_PAGE_S_NOT_SHARED (0UL << 10)
81#define TT_DESCRIPTOR_PAGE_S_SHARED (1UL << 10)
83#define TT_DESCRIPTOR_SECTION_AP_MASK ((1UL << 15) | (1UL << 11))
84#define TT_DESCRIPTOR_SECTION_AP_NO_RW ((0UL << 15) | (0UL << 11))
85#define TT_DESCRIPTOR_SECTION_AP_RW_RW ((0UL << 15) | (1UL << 11))
86#define TT_DESCRIPTOR_SECTION_AP_NO_RO ((1UL << 15) | (0UL << 11))
87#define TT_DESCRIPTOR_SECTION_AP_RO_RO ((1UL << 15) | (1UL << 11))
89#define TT_DESCRIPTOR_SECTION_AF (1UL << 10)
91#define TT_DESCRIPTOR_PAGE_AP_MASK ((1UL << 9) | (1UL << 5))
92#define TT_DESCRIPTOR_PAGE_AP_NO_RW ((0UL << 9) | (0UL << 5))
93#define TT_DESCRIPTOR_PAGE_AP_RW_RW ((0UL << 9) | (1UL << 5))
94#define TT_DESCRIPTOR_PAGE_AP_NO_RO ((1UL << 9) | (0UL << 5))
95#define TT_DESCRIPTOR_PAGE_AP_RO_RO ((1UL << 9) | (1UL << 5))
97#define TT_DESCRIPTOR_PAGE_AF (1UL << 4)
99#define TT_DESCRIPTOR_SECTION_XN_MASK (0x1UL << 4)
100#define TT_DESCRIPTOR_PAGE_XN_MASK (0x1UL << 0)
102#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK ((3UL << 12) | (1UL << 3) | (1UL << 2))
103#define TT_DESCRIPTOR_SECTION_CACHEABLE_MASK (1UL << 3)
104#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 12) | (0UL << 3) | (0UL << 2))
105#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 12) | (0UL << 3) | (1UL << 2))
106#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 12) | (1UL << 3) | (0UL << 2))
107#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 12) | (1UL << 3) | (1UL << 2))
108#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE ((1UL << 12) | (0UL << 3) | (0UL << 2))
109#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 12) | (1UL << 3) | (1UL << 2))
110#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 12) | (0UL << 3) | (0UL << 2))
112#define TT_DESCRIPTOR_PAGE_SIZE (0x00001000)
114#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK ((3UL << 6) | (1UL << 3) | (1UL << 2))
115#define TT_DESCRIPTOR_PAGE_CACHEABLE_MASK (1UL << 3)
116#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 6) | (0UL << 3) | (0UL << 2))
117#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 6) | (0UL << 3) | (1UL << 2))
118#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 6) | (1UL << 3) | (0UL << 2))
119#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 6) | (1UL << 3) | (1UL << 2))
120#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE ((1UL << 6) | (0UL << 3) | (0UL << 2))
121#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 6) | (1UL << 3) | (1UL << 2))
122#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 6) | (0UL << 3) | (0UL << 2))
124#define TT_DESCRIPTOR_CONVERT_TO_PAGE_AP(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_AP_MASK) >> 6) & TT_DESCRIPTOR_PAGE_AP_MASK)
125#define TT_DESCRIPTOR_CONVERT_TO_PAGE_NG(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_NG_MASK) >> 6) & TT_DESCRIPTOR_PAGE_NG_MASK)
126#define TT_DESCRIPTOR_CONVERT_TO_PAGE_S(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_S_MASK) >> 6) & TT_DESCRIPTOR_PAGE_S_MASK)
127#define TT_DESCRIPTOR_CONVERT_TO_PAGE_AF(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_AF) >> 6) & TT_DESCRIPTOR_PAGE_AF)
128#define TT_DESCRIPTOR_CONVERT_TO_PAGE_XN(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_XN_MASK) >> 4) & TT_DESCRIPTOR_PAGE_XN_MASK)
129#define TT_DESCRIPTOR_CONVERT_TO_PAGE_CACHE_POLICY(Desc) ((((Desc) & (0x3 << 12)) >> 6) | (Desc & (0x3 << 2)))
131#define TT_DESCRIPTOR_CONVERT_TO_SECTION_AP(Desc) ((((Desc) & TT_DESCRIPTOR_PAGE_AP_MASK) << 6) & TT_DESCRIPTOR_SECTION_AP_MASK)
132#define TT_DESCRIPTOR_CONVERT_TO_SECTION_S(Desc) ((((Desc) & TT_DESCRIPTOR_PAGE_S_MASK) << 6) & TT_DESCRIPTOR_SECTION_S_MASK)
133#define TT_DESCRIPTOR_CONVERT_TO_SECTION_AF(Desc) ((((Desc) & TT_DESCRIPTOR_PAGE_AF) << 6) & TT_DESCRIPTOR_SECTION_AF)
134#define TT_DESCRIPTOR_CONVERT_TO_SECTION_XN(Desc) ((((Desc) & TT_DESCRIPTOR_PAGE_XN_MASK) << 4) & TT_DESCRIPTOR_SECTION_XN_MASK)
135#define TT_DESCRIPTOR_CONVERT_TO_SECTION_CACHE_POLICY(Desc) ((((Desc) & (0x3 << 6)) << 6) | (Desc & (0x3 << 2)))
137#define TT_DESCRIPTOR_SECTION_ATTRIBUTE_MASK (TT_DESCRIPTOR_SECTION_NS_MASK | TT_DESCRIPTOR_SECTION_NG_MASK | \
138 TT_DESCRIPTOR_SECTION_S_MASK | TT_DESCRIPTOR_SECTION_AP_MASK | \
139 TT_DESCRIPTOR_SECTION_AF | \
140 TT_DESCRIPTOR_SECTION_XN_MASK | TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK)
142#define TT_DESCRIPTOR_PAGE_ATTRIBUTE_MASK (TT_DESCRIPTOR_PAGE_NG_MASK | TT_DESCRIPTOR_PAGE_S_MASK | \
143 TT_DESCRIPTOR_PAGE_AP_MASK | TT_DESCRIPTOR_PAGE_XN_MASK | \
144 TT_DESCRIPTOR_PAGE_AF | \
145 TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK)
147#define TT_DESCRIPTOR_SECTION_DOMAIN_MASK (0x0FUL << 5)
148#define TT_DESCRIPTOR_SECTION_DOMAIN(a) (((a) & 0x0FUL) << 5)
150#define TT_DESCRIPTOR_SECTION_BASE_ADDRESS_MASK (0xFFF00000)
151#define TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK (0xFFFFFC00)
152#define TT_DESCRIPTOR_SECTION_BASE_ADDRESS(a) ((a) & TT_DESCRIPTOR_SECTION_BASE_ADDRESS_MASK)
153#define TT_DESCRIPTOR_SECTION_BASE_SHIFT 20
155#define TT_DESCRIPTOR_PAGE_BASE_ADDRESS_MASK (0xFFFFF000)
156#define TT_DESCRIPTOR_PAGE_INDEX_MASK (0x000FF000)
157#define TT_DESCRIPTOR_PAGE_BASE_ADDRESS(a) ((a) & TT_DESCRIPTOR_PAGE_BASE_ADDRESS_MASK)
158#define TT_DESCRIPTOR_PAGE_BASE_SHIFT 12
160#define TT_DESCRIPTOR_SECTION_DEFAULT (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \
161 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \
162 TT_DESCRIPTOR_SECTION_S_SHARED | \
163 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \
164 TT_DESCRIPTOR_SECTION_AP_RW_RW | \
165 TT_DESCRIPTOR_SECTION_AF)
167#define TT_DESCRIPTOR_SECTION_WRITE_BACK (TT_DESCRIPTOR_SECTION_DEFAULT | \
168 TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC)
170#define TT_DESCRIPTOR_SECTION_WRITE_THROUGH (TT_DESCRIPTOR_SECTION_DEFAULT | \
171 TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC)
173#define TT_DESCRIPTOR_SECTION_DEVICE (TT_DESCRIPTOR_SECTION_DEFAULT | \
174 TT_DESCRIPTOR_SECTION_CACHE_POLICY_SHAREABLE_DEVICE)
176#define TT_DESCRIPTOR_SECTION_UNCACHED (TT_DESCRIPTOR_SECTION_DEFAULT | \
177 TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE)
179#define TT_DESCRIPTOR_PAGE_WRITE_BACK (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \
180 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \
181 TT_DESCRIPTOR_PAGE_S_SHARED | \
182 TT_DESCRIPTOR_PAGE_AP_RW_RW | \
183 TT_DESCRIPTOR_PAGE_AF | \
184 TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC)
185#define TT_DESCRIPTOR_PAGE_WRITE_THROUGH (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \
186 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \
187 TT_DESCRIPTOR_PAGE_S_SHARED | \
188 TT_DESCRIPTOR_PAGE_AP_RW_RW | \
189 TT_DESCRIPTOR_PAGE_AF | \
190 TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC)
191#define TT_DESCRIPTOR_PAGE_DEVICE (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \
192 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \
193 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \
194 TT_DESCRIPTOR_PAGE_AP_RW_RW | \
195 TT_DESCRIPTOR_PAGE_AF | \
196 TT_DESCRIPTOR_PAGE_XN_MASK | \
197 TT_DESCRIPTOR_PAGE_CACHE_POLICY_SHAREABLE_DEVICE)
198#define TT_DESCRIPTOR_PAGE_UNCACHED (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \
199 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \
200 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \
201 TT_DESCRIPTOR_PAGE_AP_RW_RW | \
202 TT_DESCRIPTOR_PAGE_AF | \
203 TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE)
206typedef UINT32 ARM_FIRST_LEVEL_DESCRIPTOR;
209typedef UINT32 ARM_PAGE_TABLE_ENTRY;
212ConvertSectionAttributesToPageAttributes (
213 IN UINT32 SectionAttributes