From d9680b9485bcdc3810c3bafe78b939e30c328a56 Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Mon, 19 Aug 2013 17:36:16 +0000 Subject: [PATCH] ArmPkg/ArmLib: Introduced TT_LAST_BLOCK_ADDRESS() This macro return the address of the last entry of a translation table. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Olivier Martin git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14565 6f19259b-4bc3-4df7-8a09-765794883524 --- ArmPkg/Include/Chipset/AArch64Mmu.h | 3 +++ ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ArmPkg/Include/Chipset/AArch64Mmu.h b/ArmPkg/Include/Chipset/AArch64Mmu.h index 0799734a19..17c28fa205 100644 --- a/ArmPkg/Include/Chipset/AArch64Mmu.h +++ b/ArmPkg/Include/Chipset/AArch64Mmu.h @@ -43,6 +43,9 @@ // The first offset starts at 12bit. There are 4 levels of 9-bit address range from level 3 to level 0 #define TT_ADDRESS_AT_LEVEL(TableLevel) (1 << TT_ADDRESS_OFFSET_AT_LEVEL(TableLevel)) +#define TT_LAST_BLOCK_ADDRESS(TranslationTable, EntryCount) \ + ((UINT64*)((EFI_PHYSICAL_ADDRESS)(TranslationTable) + (((EntryCount) - 1) * sizeof(UINT64)))) + // There are 512 entries per table when 4K Granularity #define TT_ENTRY_COUNT 512 #define TT_ALIGNMENT_BLOCK_ENTRY BIT12 diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c b/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c index ae22e86fa9..bca397dcff 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c @@ -279,7 +279,7 @@ GetBlockEntryListFromAddress ( // Get the Table info from T0SZ GetRootTranslationTableInfo (T0SZ, &RootTableLevel, &RootTableEntryCount); // The last block of the root table depends on the number of entry in this table - *LastBlockEntry = (UINT64*)((UINTN)RootTable + ((RootTableEntryCount - 1) * sizeof(UINT64))); + *LastBlockEntry = TT_LAST_BLOCK_ADDRESS(RootTable, RootTableEntryCount); // If the start address is 0x0 then we use the size of the region to identify the alignment if (RegionStart == 0) { @@ -333,7 +333,7 @@ GetBlockEntryListFromAddress ( BlockEntry = (UINT64*)TT_GET_ENTRY_FOR_ADDRESS (TranslationTable, IndexLevel + 1, RegionStart); // Set the last block for this new table - *LastBlockEntry = (UINT64*)((UINTN)TranslationTable + ((TT_ENTRY_COUNT - 1) * sizeof(UINT64))); + *LastBlockEntry = TT_LAST_BLOCK_ADDRESS(TranslationTable, TT_ENTRY_COUNT); } } else if ((*BlockEntry & TT_TYPE_MASK) == TT_TYPE_BLOCK_ENTRY) { // If we are not at the last level then we need to split this BlockEntry @@ -376,7 +376,7 @@ GetBlockEntryListFromAddress ( // Fill the BlockEntry with the new TranslationTable *BlockEntry = ((UINTN)TranslationTable & TT_ADDRESS_MASK_DESCRIPTION_TABLE) | TableAttributes | TT_TYPE_TABLE_ENTRY; // Update the last block entry with the newly created translation table - *LastBlockEntry = (UINT64*)((UINTN)TranslationTable + ((TT_ENTRY_COUNT - 1) * sizeof(UINT64))); + *LastBlockEntry = TT_LAST_BLOCK_ADDRESS(TranslationTable, TT_ENTRY_COUNT); // Populate the newly created lower level table BlockEntry = TranslationTable;