29SectionToGcdAttributes (
30 IN UINT32 SectionAttributes,
31 OUT UINT64 *GcdAttributes
37 switch (SectionAttributes & TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK) {
38 case TT_DESCRIPTOR_SECTION_CACHE_POLICY_STRONGLY_ORDERED:
39 *GcdAttributes |= EFI_MEMORY_UC;
41 case TT_DESCRIPTOR_SECTION_CACHE_POLICY_SHAREABLE_DEVICE:
42 *GcdAttributes |= EFI_MEMORY_UC;
44 case TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC:
45 *GcdAttributes |= EFI_MEMORY_WT;
47 case TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_NO_ALLOC:
48 *GcdAttributes |= EFI_MEMORY_WB;
50 case TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE:
51 *GcdAttributes |= EFI_MEMORY_WC;
53 case TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC:
54 *GcdAttributes |= EFI_MEMORY_WB;
56 case TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_SHAREABLE_DEVICE:
57 *GcdAttributes |= EFI_MEMORY_UC;
60 return EFI_UNSUPPORTED;
64 switch (SectionAttributes & TT_DESCRIPTOR_SECTION_AP_MASK) {
65 case TT_DESCRIPTOR_SECTION_AP_NO_RW:
66 case TT_DESCRIPTOR_SECTION_AP_RW_RW:
71 case TT_DESCRIPTOR_SECTION_AP_NO_RO:
72 case TT_DESCRIPTOR_SECTION_AP_RO_RO:
73 *GcdAttributes |= EFI_MEMORY_RO;
78 if ((SectionAttributes & TT_DESCRIPTOR_SECTION_XN_MASK) != 0) {
79 *GcdAttributes |= EFI_MEMORY_XP;
82 if ((SectionAttributes & TT_DESCRIPTOR_SECTION_AF) == 0) {
83 *GcdAttributes |= EFI_MEMORY_RP;
100RegionAttributeToGcdAttribute (
106 SectionToGcdAttributes (PageAttributes, &Result);
123 IN UINT32 PageAttributes,
124 OUT UINT64 *GcdAttributes
130 switch (PageAttributes & TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK) {
131 case TT_DESCRIPTOR_PAGE_CACHE_POLICY_STRONGLY_ORDERED:
132 *GcdAttributes |= EFI_MEMORY_UC;
134 case TT_DESCRIPTOR_PAGE_CACHE_POLICY_SHAREABLE_DEVICE:
135 *GcdAttributes |= EFI_MEMORY_UC;
137 case TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC:
138 *GcdAttributes |= EFI_MEMORY_WT;
140 case TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_NO_ALLOC:
141 *GcdAttributes |= EFI_MEMORY_WB;
143 case TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_CACHEABLE:
144 *GcdAttributes |= EFI_MEMORY_WC;
146 case TT_DESCRIPTOR_PAGE_CACHE_POLICY_WRITE_BACK_ALLOC:
147 *GcdAttributes |= EFI_MEMORY_WB;
149 case TT_DESCRIPTOR_PAGE_CACHE_POLICY_NON_SHAREABLE_DEVICE:
150 *GcdAttributes |= EFI_MEMORY_UC;
153 return EFI_UNSUPPORTED;
157 switch (PageAttributes & TT_DESCRIPTOR_PAGE_AP_MASK) {
158 case TT_DESCRIPTOR_PAGE_AP_NO_RW:
159 case TT_DESCRIPTOR_PAGE_AP_RW_RW:
164 case TT_DESCRIPTOR_PAGE_AP_NO_RO:
165 case TT_DESCRIPTOR_PAGE_AP_RO_RO:
166 *GcdAttributes |= EFI_MEMORY_RO;
171 if ((PageAttributes & TT_DESCRIPTOR_PAGE_XN_MASK) != 0) {
172 *GcdAttributes |= EFI_MEMORY_XP;
175 if ((PageAttributes & TT_DESCRIPTOR_PAGE_AF) == 0) {
176 *GcdAttributes |= EFI_MEMORY_RP;
201 IN UINT32 SectionIndex,
202 IN UINT32 FirstLevelDescriptor,
206 IN OUT UINT64 *NextRegionLength,
207 IN OUT UINT32 *NextSectionAttributes
212 volatile ARM_PAGE_TABLE_ENTRY *SecondLevelTable;
213 UINT32 NextPageAttributes;
214 UINT32 PageAttributes;
216 UINT64 GcdAttributes;
219 BaseAddress = TT_DESCRIPTOR_PAGE_BASE_ADDRESS (SectionIndex << TT_DESCRIPTOR_SECTION_BASE_SHIFT);
223 TT_DESCRIPTOR_CONVERT_TO_PAGE_CACHE_POLICY (*NextSectionAttributes) |
224 TT_DESCRIPTOR_CONVERT_TO_PAGE_AF (*NextSectionAttributes) |
225 TT_DESCRIPTOR_CONVERT_TO_PAGE_AP (*NextSectionAttributes);
228 SecondLevelTable = (ARM_PAGE_TABLE_ENTRY *)(FirstLevelDescriptor & TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK);
230 for (i = 0; i < TRANSLATION_TABLE_PAGE_COUNT; i++) {
231 if ((SecondLevelTable[i] & TT_DESCRIPTOR_PAGE_TYPE_MASK) == TT_DESCRIPTOR_PAGE_TYPE_PAGE) {
233 PageAttributes = SecondLevelTable[i] & (TT_DESCRIPTOR_PAGE_CACHE_POLICY_MASK | TT_DESCRIPTOR_PAGE_AP_MASK | TT_DESCRIPTOR_PAGE_AF);
235 if (NextPageAttributes == 0) {
237 *NextRegionLength = 0;
238 *NextRegionBase = BaseAddress | (i << TT_DESCRIPTOR_PAGE_BASE_SHIFT);
239 NextPageAttributes = PageAttributes;
240 }
else if (PageAttributes != NextPageAttributes) {
242 Status = PageToGcdAttributes (NextPageAttributes, &GcdAttributes);
243 if (EFI_ERROR (Status)) {
252 *NextRegionLength = 0;
253 *NextRegionBase = BaseAddress | (i << TT_DESCRIPTOR_PAGE_BASE_SHIFT);
254 NextPageAttributes = PageAttributes;
256 }
else if (NextPageAttributes != 0) {
258 Status = PageToGcdAttributes (NextPageAttributes, &GcdAttributes);
259 if (EFI_ERROR (Status)) {
267 *NextRegionLength = 0;
268 *NextRegionBase = BaseAddress | (i << TT_DESCRIPTOR_PAGE_BASE_SHIFT);
269 NextPageAttributes = 0;
272 *NextRegionLength += TT_DESCRIPTOR_PAGE_SIZE;
276 *NextSectionAttributes =
277 TT_DESCRIPTOR_CONVERT_TO_SECTION_CACHE_POLICY (NextPageAttributes) |
278 TT_DESCRIPTOR_CONVERT_TO_SECTION_AF (NextPageAttributes) |
279 TT_DESCRIPTOR_CONVERT_TO_SECTION_AP (NextPageAttributes);
300 UINT64 NextRegionLength;
301 UINT32 NextSectionAttributes;
302 UINT32 SectionAttributes;
303 UINT64 GcdAttributes;
304 volatile ARM_FIRST_LEVEL_DESCRIPTOR *FirstLevelTable;
305 UINTN NumberOfDescriptors;
308 DEBUG ((DEBUG_PAGE,
"SyncCacheConfig()\n"));
311 ASSERT (ArmMmuEnabled ());
316 MemorySpaceMap =
NULL;
317 Status =
gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
319 if (EFI_ERROR (Status)) {
320 DEBUG ((DEBUG_ERROR,
"SyncCacheConfig - GetMemorySpaceMap() failed! Status: %r\n", Status));
332 FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)(ArmGetTTBR0BaseAddress ());
335 NextSectionAttributes = FirstLevelTable[0] & (TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK | TT_DESCRIPTOR_SECTION_AP_MASK | TT_DESCRIPTOR_SECTION_AF);
338 NextRegionBase = NextRegionLength = 0;
339 for (i = 0; i < TRANSLATION_TABLE_SECTION_COUNT; i++) {
340 if ((FirstLevelTable[i] & TT_DESCRIPTOR_SECTION_TYPE_MASK) == TT_DESCRIPTOR_SECTION_TYPE_SECTION) {
342 SectionAttributes = FirstLevelTable[i] & (TT_DESCRIPTOR_SECTION_CACHE_POLICY_MASK | TT_DESCRIPTOR_SECTION_AP_MASK | TT_DESCRIPTOR_SECTION_AF);
344 if (NextSectionAttributes == 0) {
346 NextRegionLength = 0;
347 NextRegionBase = TT_DESCRIPTOR_SECTION_BASE_ADDRESS (i << TT_DESCRIPTOR_SECTION_BASE_SHIFT);
348 NextSectionAttributes = SectionAttributes;
349 }
else if (SectionAttributes != NextSectionAttributes) {
351 Status = SectionToGcdAttributes (NextSectionAttributes, &GcdAttributes);
353 if (EFI_ERROR (Status)) {
354 DEBUG ((DEBUG_ERROR,
"SyncCacheConfig - SectionToGcdAttributes() failed! Status: %r\n", Status));
363 NextRegionLength = 0;
364 NextRegionBase = TT_DESCRIPTOR_SECTION_BASE_ADDRESS (i << TT_DESCRIPTOR_SECTION_BASE_SHIFT);
365 NextSectionAttributes = SectionAttributes;
368 NextRegionLength += TT_DESCRIPTOR_SECTION_SIZE;
369 }
else if (TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE (FirstLevelTable[i])) {
374 NextSectionAttributes = 0;
375 Status = SyncCacheConfigPage (
382 &NextSectionAttributes
387 ASSERT ((FirstLevelTable[i] & TT_DESCRIPTOR_SECTION_TYPE_MASK) != TT_DESCRIPTOR_SECTION_TYPE_SUPERSECTION);
390 if (NextSectionAttributes != 0) {
392 Status = SectionToGcdAttributes (NextSectionAttributes, &GcdAttributes);
393 if (EFI_ERROR (Status)) {
394 DEBUG ((DEBUG_ERROR,
"SyncCacheConfig - SectionToGcdAttributes() failed! Status: %r\n", Status));
402 NextRegionLength = 0;
403 NextRegionBase = TT_DESCRIPTOR_SECTION_BASE_ADDRESS (i << TT_DESCRIPTOR_SECTION_BASE_SHIFT);
404 NextSectionAttributes = 0;
407 NextRegionLength += TT_DESCRIPTOR_SECTION_SIZE;
411 if (NextSectionAttributes != 0) {
413 Status = SectionToGcdAttributes (NextSectionAttributes, &GcdAttributes);
414 if (EFI_ERROR (Status)) {
415 DEBUG ((DEBUG_ERROR,
"SyncCacheConfig - SectionToGcdAttributes() failed! Status: %r\n", Status));
437EfiAttributeToArmAttribute (
438 IN UINT64 EfiAttributes
441 UINT64 ArmAttributes;
443 switch (EfiAttributes & EFI_MEMORY_CACHETYPE_MASK) {
446 ArmAttributes = TT_DESCRIPTOR_SECTION_CACHE_POLICY_STRONGLY_ORDERED;
451 ArmAttributes = TT_DESCRIPTOR_SECTION_CACHE_POLICY_NON_CACHEABLE;
456 ArmAttributes = TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_THROUGH_NO_ALLOC;
461 ArmAttributes = TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC;
466 ArmAttributes = TT_DESCRIPTOR_SECTION_TYPE_FAULT;
471 if ((EfiAttributes & EFI_MEMORY_RO) != 0) {
472 ArmAttributes |= TT_DESCRIPTOR_SECTION_AP_RO_RO;
474 ArmAttributes |= TT_DESCRIPTOR_SECTION_AP_RW_RW;
478 if ((EfiAttributes & EFI_MEMORY_XP) != 0) {
479 ArmAttributes |= TT_DESCRIPTOR_SECTION_XN_MASK;
482 if ((EfiAttributes & EFI_MEMORY_RP) == 0) {
483 ArmAttributes |= TT_DESCRIPTOR_SECTION_AF;
486 return ArmAttributes;
507 IN UINT32 *PageTable,
513 UINT32 PageAttributes;
515 UINT32 PageDescriptor;
519 PageAttributes = ConvertSectionAttributesToPageAttributes (*RegionAttributes);
520 Status = EFI_NOT_FOUND;
524 TableIndex = ((*BaseAddress) & TT_DESCRIPTOR_PAGE_INDEX_MASK) >> TT_DESCRIPTOR_PAGE_BASE_SHIFT;
525 ASSERT (TableIndex < TRANSLATION_TABLE_PAGE_COUNT);
528 for ( ; TableIndex < TRANSLATION_TABLE_PAGE_COUNT; TableIndex++) {
530 PageDescriptor = PageTable[TableIndex];
532 if ((PageDescriptor & TT_DESCRIPTOR_PAGE_TYPE_MASK) == TT_DESCRIPTOR_PAGE_TYPE_FAULT) {
533 Status = (*RegionLength > 0) ?
EFI_SUCCESS : EFI_NO_MAPPING;
535 }
else if ((PageDescriptor & TT_DESCRIPTOR_PAGE_TYPE_PAGE) == TT_DESCRIPTOR_PAGE_TYPE_PAGE) {
536 if ((PageDescriptor & TT_DESCRIPTOR_PAGE_ATTRIBUTE_MASK) != PageAttributes) {
541 *RegionLength += TT_DESCRIPTOR_PAGE_SIZE;
544 Status = EFI_UNSUPPORTED;
580 UINT32 PageAttributes;
581 UINT32 PageTableIndex;
582 UINT32 SectionDescriptor;
583 ARM_FIRST_LEVEL_DESCRIPTOR *FirstLevelTable;
591 FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress ();
594 TableIndex = TT_DESCRIPTOR_SECTION_BASE_ADDRESS (*BaseAddress) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;
596 if (TableIndex >= TRANSLATION_TABLE_SECTION_COUNT) {
597 ASSERT (TableIndex < TRANSLATION_TABLE_SECTION_COUNT);
598 return EFI_INVALID_PARAMETER;
602 SectionDescriptor = FirstLevelTable[TableIndex];
603 if (!SectionDescriptor) {
604 return EFI_NOT_FOUND;
608 if (((SectionDescriptor & TT_DESCRIPTOR_SECTION_TYPE_MASK) == TT_DESCRIPTOR_SECTION_TYPE_SECTION) ||
609 ((SectionDescriptor & TT_DESCRIPTOR_SECTION_TYPE_MASK) == TT_DESCRIPTOR_SECTION_TYPE_SUPERSECTION))
611 *BaseAddress = (*BaseAddress) & TT_DESCRIPTOR_SECTION_BASE_ADDRESS_MASK;
612 *RegionAttributes = SectionDescriptor & TT_DESCRIPTOR_SECTION_ATTRIBUTE_MASK;
615 *BaseAddress = (*BaseAddress) & TT_DESCRIPTOR_PAGE_BASE_ADDRESS_MASK;
618 PageTable = (UINT32 *)(SectionDescriptor & TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK);
621 PageTableIndex = ((*BaseAddress) & TT_DESCRIPTOR_PAGE_INDEX_MASK) >> TT_DESCRIPTOR_PAGE_BASE_SHIFT;
622 ASSERT (PageTableIndex < TRANSLATION_TABLE_PAGE_COUNT);
624 PageAttributes = PageTable[PageTableIndex] & TT_DESCRIPTOR_PAGE_ATTRIBUTE_MASK;
625 *RegionAttributes = TT_DESCRIPTOR_CONVERT_TO_SECTION_CACHE_POLICY (PageAttributes) |
626 TT_DESCRIPTOR_CONVERT_TO_SECTION_S (PageAttributes) |
627 TT_DESCRIPTOR_CONVERT_TO_SECTION_XN (PageAttributes) |
628 TT_DESCRIPTOR_CONVERT_TO_SECTION_AF (PageAttributes) |
629 TT_DESCRIPTOR_CONVERT_TO_SECTION_AP (PageAttributes);
632 Status = EFI_NOT_FOUND;
634 for ( ; TableIndex < TRANSLATION_TABLE_SECTION_COUNT; TableIndex++) {
636 SectionDescriptor = FirstLevelTable[TableIndex];
639 if (TT_DESCRIPTOR_SECTION_TYPE_IS_PAGE_TABLE (SectionDescriptor)) {
641 PageTable = (UINT32 *)(SectionDescriptor & TT_DESCRIPTOR_SECTION_PAGETABLE_ADDRESS_MASK);
645 Status = GetMemoryRegionPage (PageTable, BaseAddress, RegionAttributes, &Length);
646 *RegionLength += Length;
649 if ((Status == EFI_NOT_FOUND) && (Length > 0)) {
654 }
else if (((SectionDescriptor & TT_DESCRIPTOR_SECTION_TYPE_MASK) == TT_DESCRIPTOR_SECTION_TYPE_SECTION) ||
655 ((SectionDescriptor & TT_DESCRIPTOR_SECTION_TYPE_MASK) == TT_DESCRIPTOR_SECTION_TYPE_SUPERSECTION))
657 if ((SectionDescriptor & TT_DESCRIPTOR_SECTION_ATTRIBUTE_MASK) != *RegionAttributes) {
661 *RegionLength = *RegionLength + TT_DESCRIPTOR_SECTION_SIZE;
670 if (*RegionLength > 0) {
EFI_STATUS SetGcdMemorySpaceAttributes(IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap, IN UINTN NumberOfDescriptors, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
UINT64 EFI_PHYSICAL_ADDRESS