// The first offset starts at 12bit. There are 4 levels of 9-bit address range from level 3 to level 0\r
#define TT_ADDRESS_AT_LEVEL(TableLevel) (1 << TT_ADDRESS_OFFSET_AT_LEVEL(TableLevel))\r
\r
+#define TT_LAST_BLOCK_ADDRESS(TranslationTable, EntryCount) \\r
+ ((UINT64*)((EFI_PHYSICAL_ADDRESS)(TranslationTable) + (((EntryCount) - 1) * sizeof(UINT64))))\r
+\r
// There are 512 entries per table when 4K Granularity\r
#define TT_ENTRY_COUNT 512\r
#define TT_ALIGNMENT_BLOCK_ENTRY BIT12\r
// Get the Table info from T0SZ\r
GetRootTranslationTableInfo (T0SZ, &RootTableLevel, &RootTableEntryCount);\r
// The last block of the root table depends on the number of entry in this table\r
- *LastBlockEntry = (UINT64*)((UINTN)RootTable + ((RootTableEntryCount - 1) * sizeof(UINT64)));\r
+ *LastBlockEntry = TT_LAST_BLOCK_ADDRESS(RootTable, RootTableEntryCount);\r
\r
// If the start address is 0x0 then we use the size of the region to identify the alignment\r
if (RegionStart == 0) {\r
BlockEntry = (UINT64*)TT_GET_ENTRY_FOR_ADDRESS (TranslationTable, IndexLevel + 1, RegionStart);\r
\r
// Set the last block for this new table\r
- *LastBlockEntry = (UINT64*)((UINTN)TranslationTable + ((TT_ENTRY_COUNT - 1) * sizeof(UINT64)));\r
+ *LastBlockEntry = TT_LAST_BLOCK_ADDRESS(TranslationTable, TT_ENTRY_COUNT);\r
}\r
} else if ((*BlockEntry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY) {\r
// If we are not at the last level then we need to split this BlockEntry\r
// Fill the BlockEntry with the new TranslationTable\r
*BlockEntry = ((UINTN)TranslationTable & TT_ADDRESS_MASK_DESCRIPTION_TABLE) | TableAttributes | TT_TYPE_TABLE_ENTRY;\r
// Update the last block entry with the newly created translation table\r
- *LastBlockEntry = (UINT64*)((UINTN)TranslationTable + ((TT_ENTRY_COUNT - 1) * sizeof(UINT64)));\r
+ *LastBlockEntry = TT_LAST_BLOCK_ADDRESS(TranslationTable, TT_ENTRY_COUNT);\r
\r
// Populate the newly created lower level table\r
BlockEntry = TranslationTable;\r