blob: 24ab1755faa73cb9cdba2fad6d1e4e9c2a5da1ba [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/** @file
2*
3* Copyright (c) 2011-2013, ARM Limited. All rights reserved.
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 __ARMV7_MMU_H_
16#define __ARMV7_MMU_H_
17
18#define TTBR_NOT_OUTER_SHAREABLE BIT5
19#define TTBR_RGN_OUTER_NON_CACHEABLE 0
20#define TTBR_RGN_OUTER_WRITE_BACK_ALLOC BIT3
21#define TTBR_RGN_OUTER_WRITE_THROUGH BIT4
22#define TTBR_RGN_OUTER_WRITE_BACK_NO_ALLOC (BIT3|BIT4)
23#define TTBR_SHAREABLE BIT1
24#define TTBR_NON_SHAREABLE 0
25#define TTBR_INNER_CACHEABLE BIT0
26#define TTBR_NON_INNER_CACHEABLE BIT0
27#define TTBR_RGN_INNER_NON_CACHEABLE 0
28#define TTBR_RGN_INNER_WRITE_BACK_ALLOC BIT6
29#define TTBR_RGN_INNER_WRITE_THROUGH BIT0
30#define TTBR_RGN_INNER_WRITE_BACK_NO_ALLOC (BIT0|BIT6)
31
32#define TTBR_WRITE_THROUGH_NO_ALLOC ( TTBR_RGN_OUTER_WRITE_BACK_ALLOC | TTBR_RGN_INNER_WRITE_BACK_ALLOC )
33#define TTBR_WRITE_BACK_NO_ALLOC ( TTBR_RGN_OUTER_WRITE_BACK_NO_ALLOC | TTBR_RGN_INNER_WRITE_BACK_NO_ALLOC )
34#define TTBR_NON_CACHEABLE ( TTBR_RGN_OUTER_NON_CACHEABLE | TTBR_RGN_INNER_NON_CACHEABLE )
35#define TTBR_WRITE_BACK_ALLOC ( TTBR_RGN_OUTER_WRITE_BACK_ALLOC | TTBR_RGN_INNER_WRITE_BACK_ALLOC )
36
37
38#define TRANSLATION_TABLE_SECTION_COUNT 4096
39#define TRANSLATION_TABLE_SECTION_SIZE (sizeof(UINT32) * TRANSLATION_TABLE_SECTION_COUNT)
40#define TRANSLATION_TABLE_SECTION_ALIGNMENT (sizeof(UINT32) * TRANSLATION_TABLE_SECTION_COUNT)
41#define TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK (TRANSLATION_TABLE_SECTION_ALIGNMENT - 1)
42
43#define TRANSLATION_TABLE_PAGE_COUNT 256
44#define TRANSLATION_TABLE_PAGE_SIZE (sizeof(UINT32) * TRANSLATION_TABLE_PAGE_COUNT)
45#define TRANSLATION_TABLE_PAGE_ALIGNMENT (sizeof(UINT32) * TRANSLATION_TABLE_PAGE_COUNT)
46#define TRANSLATION_TABLE_PAGE_ALIGNMENT_MASK (TRANSLATION_TABLE_PAGE_ALIGNMENT - 1)
47
48#define TRANSLATION_TABLE_ENTRY_FOR_VIRTUAL_ADDRESS(table, address) ((UINT32 *)(table) + (((UINTN)(address)) >> 20))
49
50// Translation table descriptor types
51#define TT_DESCRIPTOR_SECTION_TYPE_MASK ((1UL << 18) | (3UL << 0))
52#define TT_DESCRIPTOR_SECTION_TYPE_FAULT (0UL << 0)
53#define TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE (1UL << 0)
54#define TT_DESCRIPTOR_SECTION_TYPE_SECTION ((0UL << 18) | (2UL << 0))
55#define TT_DESCRIPTOR_SECTION_TYPE_SUPERSECTION ((1UL << 18) | (2UL << 0))
56#define TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE(Desc) (((Desc) & 3UL) == TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE)
57
58// Translation table descriptor types
59#define TT_DESCRIPTOR_PAGE_TYPE_MASK (3UL << 0)
60#define TT_DESCRIPTOR_PAGE_TYPE_FAULT (0UL << 0)
61#define TT_DESCRIPTOR_PAGE_TYPE_PAGE (2UL << 0)
62#define TT_DESCRIPTOR_PAGE_TYPE_PAGE_XN (3UL << 0)
63#define TT_DESCRIPTOR_PAGE_TYPE_LARGEPAGE (1UL << 0)
64
65// Section descriptor definitions
66#define TT_DESCRIPTOR_SECTION_SIZE (0x00100000)
67
68#define TT_DESCRIPTOR_SECTION_NS_MASK (1UL << 19)
69#define TT_DESCRIPTOR_SECTION_NS (1UL << 19)
70
71#define TT_DESCRIPTOR_SECTION_NG_MASK (1UL << 17)
72#define TT_DESCRIPTOR_SECTION_NG_GLOBAL (0UL << 17)
73#define TT_DESCRIPTOR_SECTION_NG_LOCAL (1UL << 17)
74
75#define TT_DESCRIPTOR_PAGE_NG_MASK (1UL << 11)
76#define TT_DESCRIPTOR_PAGE_NG_GLOBAL (0UL << 11)
77#define TT_DESCRIPTOR_PAGE_NG_LOCAL (1UL << 11)
78
79#define TT_DESCRIPTOR_SECTION_S_MASK (1UL << 16)
80#define TT_DESCRIPTOR_SECTION_S_NOT_SHARED (0UL << 16)
81#define TT_DESCRIPTOR_SECTION_S_SHARED (1UL << 16)
82
83#define TT_DESCRIPTOR_PAGE_S_MASK (1UL << 10)
84#define TT_DESCRIPTOR_PAGE_S_NOT_SHARED (0UL << 10)
85#define TT_DESCRIPTOR_PAGE_S_SHARED (1UL << 10)
86
87#define TT_DESCRIPTOR_SECTION_AP_MASK ((1UL << 15) | (3UL << 10))
88#define TT_DESCRIPTOR_SECTION_AP_NO_NO ((0UL << 15) | (0UL << 10))
89#define TT_DESCRIPTOR_SECTION_AP_RW_NO ((0UL << 15) | (1UL << 10))
90#define TT_DESCRIPTOR_SECTION_AP_RW_RO ((0UL << 15) | (2UL << 10))
91#define TT_DESCRIPTOR_SECTION_AP_RW_RW ((0UL << 15) | (3UL << 10))
92#define TT_DESCRIPTOR_SECTION_AP_RO_NO ((1UL << 15) | (1UL << 10))
93#define TT_DESCRIPTOR_SECTION_AP_RO_RO ((1UL << 15) | (3UL << 10))
94
95#define TT_DESCRIPTOR_PAGE_AP_MASK ((1UL << 9) | (3UL << 4))
96#define TT_DESCRIPTOR_PAGE_AP_NO_NO ((0UL << 9) | (0UL << 4))
97#define TT_DESCRIPTOR_PAGE_AP_RW_NO ((0UL << 9) | (1UL << 4))
98#define TT_DESCRIPTOR_PAGE_AP_RW_RO ((0UL << 9) | (2UL << 4))
99#define TT_DESCRIPTOR_PAGE_AP_RW_RW ((0UL << 9) | (3UL << 4))
100#define TT_DESCRIPTOR_PAGE_AP_RO_NO ((1UL << 9) | (1UL << 4))
101#define TT_DESCRIPTOR_PAGE_AP_RO_RO ((1UL << 9) | (3UL << 4))
102
103#define TT_DESCRIPTOR_SECTION_XN_MASK (0x1UL << 4)
104#define TT_DESCRIPTOR_PAGE_XN_MASK (0x1UL << 0)
105#define TT_DESCRIPTOR_LARGEPAGE_XN_MASK (0x1UL << 15)
106
107#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK ((3UL << 12) | (1UL << 3) | (1UL << 2))
108#define TT_DESCRIPTOR_SECTION_CACHEABLE_MASK (1UL << 3)
109#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 12) | (0UL << 3) | (0UL << 2))
110#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 12) | (0UL << 3) | (1UL << 2))
111#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 12) | (1UL << 3) | (0UL << 2))
112#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 12) | (1UL << 3) | (1UL << 2))
113#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE ((1UL << 12) | (0UL << 3) | (0UL << 2))
114#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 12) | (1UL << 3) | (1UL << 2))
115#define TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 12) | (0UL << 3) | (0UL << 2))
116
117#define TT_DESCRIPTOR_PAGE_SIZE (0x00001000)
118
119#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK ((3UL << 6) | (1UL << 3) | (1UL << 2))
120#define TT_DESCRIPTOR_PAGE_CACHEABLE_MASK (1UL << 3)
121#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 6) | (0UL << 3) | (0UL << 2))
122#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 6) | (0UL << 3) | (1UL << 2))
123#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 6) | (1UL << 3) | (0UL << 2))
124#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 6) | (1UL << 3) | (1UL << 2))
125#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE ((1UL << 6) | (0UL << 3) | (0UL << 2))
126#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 6) | (1UL << 3) | (1UL << 2))
127#define TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 6) | (0UL << 3) | (0UL << 2))
128
129#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_MASK ((3UL << 12) | (1UL << 3) | (1UL << 2))
130#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_STRONGLY_ORDERED ((0UL << 12) | (0UL << 3) | (0UL << 2))
131#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_SHAREABLE_DEVICE ((0UL << 12) | (0UL << 3) | (1UL << 2))
132#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC ((0UL << 12) | (1UL << 3) | (0UL << 2))
133#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_WRITE_BACK_NO_ALLOC ((0UL << 12) | (1UL << 3) | (1UL << 2))
134#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_NON_CACHEABLE ((1UL << 12) | (0UL << 3) | (0UL << 2))
135#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_WRITE_BACK_ALLOC ((1UL << 12) | (1UL << 3) | (1UL << 2))
136#define TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_NON_SHAREABLE_DEVICE ((2UL << 12) | (0UL << 3) | (0UL << 2))
137
138#define TT_DESCRIPTOR_CONVERT_TO_PAGE_AP(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_AP_MASK) >> 6) & TT_DESCRIPTOR_PAGE_AP_MASK)
139#define TT_DESCRIPTOR_CONVERT_TO_PAGE_NG(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_NG_MASK) >> 6) & TT_DESCRIPTOR_PAGE_NG_MASK)
140#define TT_DESCRIPTOR_CONVERT_TO_PAGE_S(Desc) ((((Desc) & TT_DESCRIPTOR_SECTION_S_MASK) >> 6) & TT_DESCRIPTOR_PAGE_S_MASK)
141#define TT_DESCRIPTOR_CONVERT_TO_PAGE_XN(Desc,IsLargePage) ((IsLargePage)? \
142 ((((Desc) & TT_DESCRIPTOR_SECTION_XN_MASK) << 11) & TT_DESCRIPTOR_LARGEPAGE_XN_MASK): \
143 ((((Desc) & TT_DESCRIPTOR_SECTION_XN_MASK) >> 4) & TT_DESCRIPTOR_PAGE_XN_MASK))
144#define TT_DESCRIPTOR_CONVERT_TO_PAGE_CACHE_POLICY(Desc,IsLargePage) (IsLargePage? \
145 (((Desc) & TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK) & TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_MASK): \
146 (((((Desc) & (0x3 << 12)) >> 6) | (Desc & (0x3 << 2)))))
147
148#define TT_DESCRIPTOR_CONVERT_TO_SECTION_AP(Desc) ((((Desc) & TT_DESCRIPTOR_PAGE_AP_MASK) << 6) & TT_DESCRIPTOR_SECTION_AP_MASK)
149
150#define TT_DESCRIPTOR_CONVERT_TO_SECTION_CACHE_POLICY(Desc,IsLargePage) (IsLargePage? \
151 (((Desc) & TT_DESCRIPTOR_LARGEPAGE_CACHE_POLICY_MASK) & TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK): \
152 (((((Desc) & (0x3 << 6)) << 6) | (Desc & (0x3 << 2)))))
153
154#define TT_DESCRIPTOR_SECTION_ATTRIBUTE_MASK (TT_DESCRIPTOR_SECTION_NS_MASK | TT_DESCRIPTOR_SECTION_NG_MASK | \
155 TT_DESCRIPTOR_SECTION_S_MASK | TT_DESCRIPTOR_SECTION_AP_MASK | \
156 TT_DESCRIPTOR_SECTION_XN_MASK | TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK)
157
158#define TT_DESCRIPTOR_PAGE_ATTRIBUTE_MASK (TT_DESCRIPTOR_PAGE_NG_MASK | TT_DESCRIPTOR_PAGE_S_MASK | \
159 TT_DESCRIPTOR_PAGE_AP_MASK | TT_DESCRIPTOR_PAGE_XN_MASK | \
160 TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK)
161
162#define TT_DESCRIPTOR_SECTION_DOMAIN_MASK (0x0FUL << 5)
163#define TT_DESCRIPTOR_SECTION_DOMAIN(a) (((a) & 0x0FUL) << 5)
164
165#define TT_DESCRIPTOR_SECTION_BASE_ADDRESS_MASK (0xFFF00000)
166#define TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK (0xFFFFFC00)
167#define TT_DESCRIPTOR_SECTION_BASE_ADDRESS(a) ((a) & TT_DESCRIPTOR_SECTION_BASE_ADDRESS_MASK)
168#define TT_DESCRIPTOR_SECTION_BASE_SHIFT 20
169
170#define TT_DESCRIPTOR_PAGE_BASE_ADDRESS_MASK (0xFFFFF000)
171#define TT_DESCRIPTOR_PAGE_INDEX_MASK (0x000FF000)
172#define TT_DESCRIPTOR_PAGE_BASE_ADDRESS(a) ((a) & TT_DESCRIPTOR_PAGE_BASE_ADDRESS_MASK)
173#define TT_DESCRIPTOR_PAGE_BASE_SHIFT 12
174
175#define TT_DESCRIPTOR_SECTION_WRITE_BACK(NonSecure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \
176 ((NonSecure) ? TT_DESCRIPTOR_SECTION_NS : 0) | \
177 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \
178 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \
179 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \
180 TT_DESCRIPTOR_SECTION_AP_RW_RW | \
181 TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC)
182#define TT_DESCRIPTOR_SECTION_WRITE_THROUGH(NonSecure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \
183 ((NonSecure) ? TT_DESCRIPTOR_SECTION_NS : 0) | \
184 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \
185 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \
186 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \
187 TT_DESCRIPTOR_SECTION_AP_RW_RW | \
188 TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC)
189#define TT_DESCRIPTOR_SECTION_DEVICE(NonSecure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \
190 ((NonSecure) ? TT_DESCRIPTOR_SECTION_NS : 0) | \
191 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \
192 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \
193 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \
194 TT_DESCRIPTOR_SECTION_AP_RW_RW | \
195 TT_DESCRIPTOR_SECTION_CACHE_POLICY_SHAREABLE_DEVICE)
196#define TT_DESCRIPTOR_SECTION_UNCACHED(NonSecure) (TT_DESCRIPTOR_SECTION_TYPE_SECTION | \
197 ((NonSecure) ? TT_DESCRIPTOR_SECTION_NS : 0) | \
198 TT_DESCRIPTOR_SECTION_NG_GLOBAL | \
199 TT_DESCRIPTOR_SECTION_S_NOT_SHARED | \
200 TT_DESCRIPTOR_SECTION_DOMAIN(0) | \
201 TT_DESCRIPTOR_SECTION_AP_RW_RW | \
202 TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE)
203
204#define TT_DESCRIPTOR_PAGE_WRITE_BACK (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \
205 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \
206 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \
207 TT_DESCRIPTOR_PAGE_AP_RW_RW | \
208 TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC)
209#define TT_DESCRIPTOR_PAGE_WRITE_THROUGH (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \
210 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \
211 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \
212 TT_DESCRIPTOR_PAGE_AP_RW_RW | \
213 TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC)
214#define TT_DESCRIPTOR_PAGE_DEVICE (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \
215 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \
216 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \
217 TT_DESCRIPTOR_PAGE_AP_RW_RW | \
218 TT_DESCRIPTOR_PAGE_CACHE_POLICY_SHAREABLE_DEVICE)
219#define TT_DESCRIPTOR_PAGE_UNCACHED (TT_DESCRIPTOR_PAGE_TYPE_PAGE | \
220 TT_DESCRIPTOR_PAGE_NG_GLOBAL | \
221 TT_DESCRIPTOR_PAGE_S_NOT_SHARED | \
222 TT_DESCRIPTOR_PAGE_AP_RW_RW | \
223 TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE)
224
225UINT32
226ConvertSectionAttributesToPageAttributes (
227 IN UINT32 SectionAttributes,
228 IN BOOLEAN IsLargePage
229 );
230
231#endif