\r
#define MIN_T0SZ 16\r
#define BITS_PER_LEVEL 9\r
+#define MAX_VA_BITS 48\r
+\r
+STATIC\r
+UINTN\r
+GetRootTableEntryCount (\r
+ IN UINTN T0SZ\r
+ )\r
+{\r
+ return TT_ENTRY_COUNT >> (T0SZ - MIN_T0SZ) % BITS_PER_LEVEL;\r
+}\r
\r
VOID\r
GetRootTranslationTableInfo (\r
return EFI_SUCCESS;\r
}\r
\r
-STATIC\r
-VOID\r
-LookupAddresstoRootTable (\r
- IN UINT64 MaxAddress,\r
- OUT UINTN *T0SZ,\r
- OUT UINTN *TableEntryCount\r
- )\r
-{\r
- UINTN TopBit;\r
-\r
- // Check the parameters are not NULL\r
- ASSERT ((T0SZ != NULL) && (TableEntryCount != NULL));\r
-\r
- // Look for the highest bit set in MaxAddress\r
- for (TopBit = 63; TopBit != 0; TopBit--) {\r
- if ((1ULL << TopBit) & MaxAddress) {\r
- // MaxAddress top bit is found\r
- TopBit = TopBit + 1;\r
- break;\r
- }\r
- }\r
- ASSERT (TopBit != 0);\r
-\r
- // Calculate T0SZ from the top bit of the MaxAddress\r
- *T0SZ = 64 - TopBit;\r
-\r
- // Get the Table info from T0SZ\r
- GetRootTranslationTableInfo (*T0SZ, NULL, TableEntryCount);\r
-}\r
-\r
STATIC\r
EFI_STATUS\r
UpdateRegionMapping (\r
)\r
{\r
VOID* TranslationTable;\r
+ UINTN MaxAddressBits;\r
UINT64 MaxAddress;\r
UINTN T0SZ;\r
UINTN RootTableEntryCount;\r
// into account the architectural limitations that result from UEFI's\r
// use of 4 KB pages.\r
//\r
- MaxAddress = MIN (LShiftU64 (1ULL, ArmGetPhysicalAddressBits ()) - 1,\r
- MAX_ALLOC_ADDRESS);\r
+ MaxAddressBits = MIN (ArmGetPhysicalAddressBits (), MAX_VA_BITS);\r
+ MaxAddress = LShiftU64 (1ULL, MaxAddressBits) - 1;\r
\r
- // Lookup the Table Level to get the information\r
- LookupAddresstoRootTable (MaxAddress, &T0SZ, &RootTableEntryCount);\r
+ T0SZ = 64 - MaxAddressBits;\r
+ RootTableEntryCount = GetRootTableEntryCount (T0SZ);\r
\r
//\r
// Set TCR that allows us to retrieve T0SZ in the subsequent functions\r