X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ArmPkg%2FLibrary%2FArmMmuLib%2FAArch64%2FArmMmuLibCore.c;h=d66df3e17a02a17c71b4ff947963de3f584320a6;hp=9e0593ce598bd74aa37ddf446efe2088af27b61e;hb=76c23f9e0d0d65866e4195b0bc12c1ca2763ced2;hpb=e0307a7dad02aa8c0cd8b3b0b9edce8ddb3fef2e diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c index 9e0593ce59..d66df3e17a 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c @@ -35,6 +35,10 @@ ArmMemoryAttributeToPageAttribute ( ) { switch (Attributes) { + case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK_NONSHAREABLE: + case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK_NONSHAREABLE: + return TT_ATTR_INDX_MEMORY_WRITE_BACK; + case ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK: case ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK: return TT_ATTR_INDX_MEMORY_WRITE_BACK | TT_SH_INNER_SHAREABLE; @@ -329,7 +333,7 @@ GetBlockEntryListFromAddress ( } STATIC -RETURN_STATUS +EFI_STATUS UpdateRegionMapping ( IN UINT64 *RootTable, IN UINT64 RegionStart, @@ -347,7 +351,7 @@ UpdateRegionMapping ( // Ensure the Length is aligned on 4KB boundary if ((RegionLength == 0) || ((RegionLength & (SIZE_4KB - 1)) != 0)) { ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER); - return RETURN_INVALID_PARAMETER; + return EFI_INVALID_PARAMETER; } do { @@ -357,7 +361,7 @@ UpdateRegionMapping ( BlockEntry = GetBlockEntryListFromAddress (RootTable, RegionStart, &TableLevel, &BlockEntrySize, &LastBlockEntry); if (BlockEntry == NULL) { // GetBlockEntryListFromAddress() return NULL when it fails to allocate new pages from the Translation Tables - return RETURN_OUT_OF_RESOURCES; + return EFI_OUT_OF_RESOURCES; } if (TableLevel != 3) { @@ -378,18 +382,18 @@ UpdateRegionMapping ( // Break the inner loop when next block is a table // Rerun GetBlockEntryListFromAddress to avoid page table memory leak - if (TableLevel != 3 && + if (TableLevel != 3 && BlockEntry <= LastBlockEntry && (*BlockEntry & TT_TYPE_MASK) == TT_TYPE_TABLE_ENTRY) { break; } } while ((RegionLength >= BlockEntrySize) && (BlockEntry <= LastBlockEntry)); } while (RegionLength != 0); - return RETURN_SUCCESS; + return EFI_SUCCESS; } STATIC -RETURN_STATUS +EFI_STATUS FillTranslationTable ( IN UINT64 *RootTable, IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryRegion @@ -446,15 +450,14 @@ GcdAttributeToPageAttribute ( return PageAttributes | TT_AF; } -RETURN_STATUS -SetMemoryAttributes ( +EFI_STATUS +ArmSetMemoryAttributes ( IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, - IN UINT64 Attributes, - IN EFI_PHYSICAL_ADDRESS VirtualMask + IN UINT64 Attributes ) { - RETURN_STATUS Status; + EFI_STATUS Status; UINT64 *TranslationTable; UINT64 PageAttributes; UINT64 PageAttributeMask; @@ -480,18 +483,18 @@ SetMemoryAttributes ( Length, PageAttributes, PageAttributeMask); - if (RETURN_ERROR (Status)) { + if (EFI_ERROR (Status)) { return Status; } // Invalidate all TLB entries so changes are synced ArmInvalidateTlb (); - return RETURN_SUCCESS; + return EFI_SUCCESS; } STATIC -RETURN_STATUS +EFI_STATUS SetMemoryRegionAttribute ( IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, @@ -499,23 +502,23 @@ SetMemoryRegionAttribute ( IN UINT64 BlockEntryMask ) { - RETURN_STATUS Status; + EFI_STATUS Status; UINT64 *RootTable; RootTable = ArmGetTTBR0BaseAddress (); Status = UpdateRegionMapping (RootTable, BaseAddress, Length, Attributes, BlockEntryMask); - if (RETURN_ERROR (Status)) { + if (EFI_ERROR (Status)) { return Status; } // Invalidate all TLB entries so changes are synced ArmInvalidateTlb (); - return RETURN_SUCCESS; + return EFI_SUCCESS; } -RETURN_STATUS +EFI_STATUS ArmSetMemoryRegionNoExec ( IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length @@ -536,7 +539,7 @@ ArmSetMemoryRegionNoExec ( ~TT_ADDRESS_MASK_BLOCK_ENTRY); } -RETURN_STATUS +EFI_STATUS ArmClearMemoryRegionNoExec ( IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length @@ -554,7 +557,7 @@ ArmClearMemoryRegionNoExec ( Mask); } -RETURN_STATUS +EFI_STATUS ArmSetMemoryRegionReadOnly ( IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length @@ -567,7 +570,7 @@ ArmSetMemoryRegionReadOnly ( ~TT_ADDRESS_MASK_BLOCK_ENTRY); } -RETURN_STATUS +EFI_STATUS ArmClearMemoryRegionReadOnly ( IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length @@ -580,7 +583,7 @@ ArmClearMemoryRegionReadOnly ( ~(TT_ADDRESS_MASK_BLOCK_ENTRY | TT_AP_MASK)); } -RETURN_STATUS +EFI_STATUS EFIAPI ArmConfigureMmu ( IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable, @@ -594,15 +597,22 @@ ArmConfigureMmu ( UINTN T0SZ; UINTN RootTableEntryCount; UINT64 TCR; - RETURN_STATUS Status; + EFI_STATUS Status; if(MemoryTable == NULL) { ASSERT (MemoryTable != NULL); - return RETURN_INVALID_PARAMETER; + return EFI_INVALID_PARAMETER; } - // Cover the entire GCD memory space - MaxAddress = (1UL << PcdGet8 (PcdPrePiCpuMemorySize)) - 1; + // + // Limit the virtual address space to what we can actually use: UEFI + // mandates a 1:1 mapping, so no point in making the virtual address + // space larger than the physical address space. We also have to take + // into account the architectural limitations that result from UEFI's + // use of 4 KB pages. + // + MaxAddress = MIN (LShiftU64 (1ULL, ArmGetPhysicalAddressBits ()) - 1, + MAX_ALLOC_ADDRESS); // Lookup the Table Level to get the information LookupAddresstoRootTable (MaxAddress, &T0SZ, &RootTableEntryCount); @@ -632,7 +642,7 @@ ArmConfigureMmu ( } else { DEBUG ((EFI_D_ERROR, "ArmConfigureMmu: The MaxAddress 0x%lX is not supported by this MMU configuration.\n", MaxAddress)); ASSERT (0); // Bigger than 48-bit memory space are not supported - return RETURN_UNSUPPORTED; + return EFI_UNSUPPORTED; } } else if (ArmReadCurrentEL () == AARCH64_EL1) { // Due to Cortex-A57 erratum #822227 we must set TG1[1] == 1, regardless of EPD1. @@ -654,11 +664,11 @@ ArmConfigureMmu ( } else { DEBUG ((EFI_D_ERROR, "ArmConfigureMmu: The MaxAddress 0x%lX is not supported by this MMU configuration.\n", MaxAddress)); ASSERT (0); // Bigger than 48-bit memory space are not supported - return RETURN_UNSUPPORTED; + return EFI_UNSUPPORTED; } } else { ASSERT (0); // UEFI is only expected to run at EL2 and EL1, not EL3. - return RETURN_UNSUPPORTED; + return EFI_UNSUPPORTED; } // @@ -680,7 +690,7 @@ ArmConfigureMmu ( // Allocate pages for translation table TranslationTable = AllocatePages (1); if (TranslationTable == NULL) { - return RETURN_OUT_OF_RESOURCES; + return EFI_OUT_OF_RESOURCES; } // We set TTBR0 just after allocating the table to retrieve its location from the subsequent // functions without needing to pass this value across the functions. The MMU is only enabled @@ -719,7 +729,7 @@ ArmConfigureMmu ( DEBUG_CODE_END (); Status = FillTranslationTable (TranslationTable, MemoryTable); - if (RETURN_ERROR (Status)) { + if (EFI_ERROR (Status)) { goto FREE_TRANSLATION_TABLE; } MemoryTable++; @@ -734,11 +744,12 @@ ArmConfigureMmu ( MAIR_ATTR(TT_ATTR_INDX_MEMORY_WRITE_BACK, MAIR_ATTR_NORMAL_MEMORY_WRITE_BACK)); // mapped to EFI_MEMORY_WB ArmDisableAlignmentCheck (); + ArmEnableStackAlignmentCheck (); ArmEnableInstructionCache (); ArmEnableDataCache (); ArmEnableMmu (); - return RETURN_SUCCESS; + return EFI_SUCCESS; FREE_TRANSLATION_TABLE: FreePages (TranslationTable, 1);