UINT32 SectionDescriptor;\r
UINT32 TranslationTable;\r
UINT32 BaseSectionAddress;\r
+ UINT32 FirstPageOffset;\r
\r
switch (Attributes) {\r
case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK:\r
TT_DESCRIPTOR_SECTION_TYPE_PAGE_TABLE;\r
}\r
\r
- PageEntry = ((UINT32 *)(TranslationTable) + ((PhysicalBase & TT_DESCRIPTOR_PAGE_INDEX_MASK) >> TT_DESCRIPTOR_PAGE_BASE_SHIFT));\r
+ FirstPageOffset = (PhysicalBase & TT_DESCRIPTOR_PAGE_INDEX_MASK) >> TT_DESCRIPTOR_PAGE_BASE_SHIFT;\r
+ PageEntry = (UINT32 *)TranslationTable + FirstPageOffset;\r
Pages = RemainLength / TT_DESCRIPTOR_PAGE_SIZE;\r
\r
+ ASSERT (FirstPageOffset + Pages <= TRANSLATION_TABLE_PAGE_COUNT);\r
+\r
for (Index = 0; Index < Pages; Index++) {\r
*PageEntry++ = TT_DESCRIPTOR_PAGE_BASE_ADDRESS(PhysicalBase) | PageAttributes;\r
PhysicalBase += TT_DESCRIPTOR_PAGE_SIZE;\r
UINT32 Attributes;\r
UINT32 PhysicalBase;\r
UINT64 RemainLength;\r
+ UINT32 PageMapLength;\r
\r
ASSERT(MemoryRegion->Length > 0);\r
\r
SectionEntry = TRANSLATION_TABLE_ENTRY_FOR_VIRTUAL_ADDRESS(TranslationTable, MemoryRegion->VirtualBase);\r
\r
while (RemainLength != 0) {\r
- if (PhysicalBase % TT_DESCRIPTOR_SECTION_SIZE == 0) {\r
- if (RemainLength >= TT_DESCRIPTOR_SECTION_SIZE) {\r
- // Case: Physical address aligned on the Section Size (1MB) && the length is greater than the Section Size\r
- *SectionEntry++ = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(PhysicalBase) | Attributes;\r
- PhysicalBase += TT_DESCRIPTOR_SECTION_SIZE;\r
- } else {\r
- // Case: Physical address aligned on the Section Size (1MB) && the length does not fill a section\r
- PopulateLevel2PageTable (SectionEntry++, PhysicalBase, RemainLength, MemoryRegion->Attributes);\r
-\r
- // It must be the last entry\r
- break;\r
- }\r
+ if (PhysicalBase % TT_DESCRIPTOR_SECTION_SIZE == 0 &&\r
+ RemainLength >= TT_DESCRIPTOR_SECTION_SIZE) {\r
+ // Case: Physical address aligned on the Section Size (1MB) && the length\r
+ // is greater than the Section Size\r
+ *SectionEntry++ = TT_DESCRIPTOR_SECTION_BASE_ADDRESS(PhysicalBase) | Attributes;\r
+ PhysicalBase += TT_DESCRIPTOR_SECTION_SIZE;\r
+ RemainLength -= TT_DESCRIPTOR_SECTION_SIZE;\r
} else {\r
+ PageMapLength = MIN (RemainLength, TT_DESCRIPTOR_SECTION_SIZE) -\r
+ (PhysicalBase % TT_DESCRIPTOR_SECTION_SIZE);\r
+\r
+ // Case: Physical address aligned on the Section Size (1MB) && the length\r
+ // does not fill a section\r
// Case: Physical address NOT aligned on the Section Size (1MB)\r
- PopulateLevel2PageTable (SectionEntry++, PhysicalBase, RemainLength, MemoryRegion->Attributes);\r
- // Aligned the address\r
- PhysicalBase = (PhysicalBase + TT_DESCRIPTOR_SECTION_SIZE) & ~(TT_DESCRIPTOR_SECTION_SIZE-1);\r
+ PopulateLevel2PageTable (SectionEntry++, PhysicalBase, PageMapLength,\r
+ MemoryRegion->Attributes);\r
\r
// If it is the last entry\r
if (RemainLength < TT_DESCRIPTOR_SECTION_SIZE) {\r
break;\r
}\r
+\r
+ PhysicalBase += PageMapLength;\r
+ RemainLength -= PageMapLength;\r
}\r
- RemainLength -= TT_DESCRIPTOR_SECTION_SIZE;\r
}\r
}\r
\r