Ring3: Added MakeUserPageTableTemplate() for AARCH64.

This commit is contained in:
Mikhail Krichanov 2024-12-09 17:28:43 +03:00
parent 84ab39c635
commit 6da370bc11
4 changed files with 90 additions and 0 deletions
ArmPkg
Include/Library
Library/ArmMmuLib/AArch64
MdeModulePkg/Core/Dxe

View File

@ -21,6 +21,14 @@ ArmConfigureMmu (
OUT UINTN *TranslationTableSize OPTIONAL
);
EFI_STATUS
EFIAPI
ArmMakeUserPageTableTemplate (
IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable,
OUT UINTN *TranslationTableBase,
OUT UINTN *TranslationTableSize
);
VOID
EFIAPI
ArmReplaceLiveTranslationEntry (

View File

@ -772,6 +772,53 @@ FreeTranslationTable:
return Status;
}
EFI_STATUS
EFIAPI
ArmMakeUserPageTableTemplate (
IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable,
OUT UINTN *TranslationTableBase,
OUT UINTN *TranslationTableSize
)
{
VOID *TranslationTable;
UINTN MaxAddressBits;
UINT64 MaxAddress;
UINTN T0SZ;
UINTN RootTableEntryCount;
EFI_STATUS Status;
MaxAddressBits = MIN (ArmGetPhysicalAddressBits (), MAX_VA_BITS);
MaxAddress = LShiftU64 (1ULL, MaxAddressBits) - 1;
T0SZ = 64 - MaxAddressBits;
RootTableEntryCount = GetRootTableEntryCount (T0SZ);
TranslationTable = AllocatePages (1);
if (TranslationTable == NULL) {
return EFI_OUT_OF_RESOURCES;
}
ZeroMem (TranslationTable, RootTableEntryCount * sizeof (UINT64));
Status = UpdateRegionMapping (
MemoryTable->VirtualBase,
MemoryTable->Length,
ArmMemoryAttributeToPageAttribute (MemoryTable->Attributes),
0,
TranslationTable,
FALSE
);
if (EFI_ERROR (Status)) {
FreePages (TranslationTable, 1);
return Status;
}
*TranslationTableBase = (UINTN)TranslationTable;
*TranslationTableSize = RootTableEntryCount * sizeof (UINT64);
return EFI_SUCCESS;
}
RETURN_STATUS
EFIAPI
ArmMmuBaseLibConstructor (

View File

@ -151,6 +151,9 @@
gEfiGlobalVariableGuid ## SOMETIMES_CONSUMES ## SysCall
gEarlyPL011BaseAddressGuid ## CONSUMES
[Guids.ARM, Guids.AARCH64]
gArmVirtSystemMemorySizeGuid ## CONSUMES
[Ppis]
gEfiVectorHandoffInfoPpiGuid ## UNDEFINED # HOB
@ -231,6 +234,9 @@
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase ## CONSUMES
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaSize ## CONSUMES
[Pcd.ARM, Pcd.AARCH64]
gArmTokenSpaceGuid.PcdSystemMemoryBase ## CONSUMES
# [Hob]
# RESOURCE_DESCRIPTOR ## CONSUMES
# MEMORY_ALLOCATION ## CONSUMES

View File

@ -7,6 +7,7 @@
#include <Chipset/AArch64.h>
#include <Library/ArmLib.h>
#include <Library/ArmMmuLib.h>
#include <Library/DefaultExceptionHandlerLib.h>
#include "DxeMain.h"
@ -89,6 +90,34 @@ SysCallBootService (
return Status;
}
VOID
EFIAPI
MakeUserPageTableTemplate (
OUT UINTN *UserPageTableTemplate,
OUT UINTN *UserPageTableTemplateSize
)
{
ARM_MEMORY_REGION_DESCRIPTOR Descriptor;
VOID *MemorySizeHob;
MemorySizeHob = GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid);
ASSERT (MemorySizeHob != NULL);
if (MemorySizeHob == NULL) {
return;
}
Descriptor.PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
Descriptor.VirtualBase = Descriptor.PhysicalBase;
Descriptor.Length = *(UINT64 *)GET_GUID_HOB_DATA (MemorySizeHob);
Descriptor.Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
ArmMakeUserPageTableTemplate (
&Descriptor,
UserPageTableTemplate,
UserPageTableTemplateSize
);
}
VOID
EFIAPI
InitializeMsr (