mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-24 22:24:37 +02:00
ArmPkg: Added CpuSetUserMemoryAttributes() for ARM.
This commit is contained in:
parent
b739cbd2b5
commit
1c10e31d45
@ -31,7 +31,8 @@
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
ConvertSectionToPages (
|
ConvertSectionToPages (
|
||||||
IN EFI_PHYSICAL_ADDRESS BaseAddress
|
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||||
|
IN volatile ARM_FIRST_LEVEL_DESCRIPTOR *FirstLevelTable
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINT32 FirstLevelIdx;
|
UINT32 FirstLevelIdx;
|
||||||
@ -40,14 +41,10 @@ ConvertSectionToPages (
|
|||||||
UINT32 PageDescriptor;
|
UINT32 PageDescriptor;
|
||||||
UINT32 Index;
|
UINT32 Index;
|
||||||
|
|
||||||
volatile ARM_FIRST_LEVEL_DESCRIPTOR *FirstLevelTable;
|
volatile ARM_PAGE_TABLE_ENTRY *PageTable;
|
||||||
volatile ARM_PAGE_TABLE_ENTRY *PageTable;
|
|
||||||
|
|
||||||
DEBUG ((DEBUG_PAGE, "Converting section at 0x%x to pages\n", (UINTN)BaseAddress));
|
DEBUG ((DEBUG_PAGE, "Converting section at 0x%x to pages\n", (UINTN)BaseAddress));
|
||||||
|
|
||||||
// Obtain page table base
|
|
||||||
FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress ();
|
|
||||||
|
|
||||||
// Calculate index into first level translation table for start of modification
|
// Calculate index into first level translation table for start of modification
|
||||||
FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS (BaseAddress) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;
|
FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS (BaseAddress) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;
|
||||||
ASSERT (FirstLevelIdx < TRANSLATION_TABLE_SECTION_COUNT);
|
ASSERT (FirstLevelIdx < TRANSLATION_TABLE_SECTION_COUNT);
|
||||||
@ -79,11 +76,12 @@ ConvertSectionToPages (
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
UpdatePageEntries (
|
UpdatePageEntries (
|
||||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||||
IN UINT64 Length,
|
IN UINT64 Length,
|
||||||
IN UINT64 Attributes,
|
IN UINT64 Attributes,
|
||||||
IN UINT32 EntryMask,
|
IN UINT32 EntryMask,
|
||||||
OUT BOOLEAN *FlushTlbs OPTIONAL
|
OUT BOOLEAN *FlushTlbs OPTIONAL,
|
||||||
|
IN volatile ARM_FIRST_LEVEL_DESCRIPTOR *FirstLevelTable
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -98,8 +96,7 @@ UpdatePageEntries (
|
|||||||
UINT32 CurrentPageTableEntry;
|
UINT32 CurrentPageTableEntry;
|
||||||
VOID *Mva;
|
VOID *Mva;
|
||||||
|
|
||||||
volatile ARM_FIRST_LEVEL_DESCRIPTOR *FirstLevelTable;
|
volatile ARM_PAGE_TABLE_ENTRY *PageTable;
|
||||||
volatile ARM_PAGE_TABLE_ENTRY *PageTable;
|
|
||||||
|
|
||||||
Status = EFI_SUCCESS;
|
Status = EFI_SUCCESS;
|
||||||
|
|
||||||
@ -163,9 +160,6 @@ UpdatePageEntries (
|
|||||||
EntryValue |= TT_DESCRIPTOR_PAGE_XN_MASK;
|
EntryValue |= TT_DESCRIPTOR_PAGE_XN_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtain page table base
|
|
||||||
FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress ();
|
|
||||||
|
|
||||||
// Calculate number of 4KB page table entries to change
|
// Calculate number of 4KB page table entries to change
|
||||||
NumPageEntries = (UINT32)(Length / TT_DESCRIPTOR_PAGE_SIZE);
|
NumPageEntries = (UINT32)(Length / TT_DESCRIPTOR_PAGE_SIZE);
|
||||||
|
|
||||||
@ -193,7 +187,10 @@ UpdatePageEntries (
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = ConvertSectionToPages (FirstLevelIdx << TT_DESCRIPTOR_SECTION_BASE_SHIFT);
|
Status = ConvertSectionToPages (
|
||||||
|
FirstLevelIdx << TT_DESCRIPTOR_SECTION_BASE_SHIFT,
|
||||||
|
FirstLevelTable
|
||||||
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
// Exit for loop
|
// Exit for loop
|
||||||
break;
|
break;
|
||||||
@ -240,21 +237,21 @@ UpdatePageEntries (
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
UpdateSectionEntries (
|
UpdateSectionEntries (
|
||||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||||
IN UINT64 Length,
|
IN UINT64 Length,
|
||||||
IN UINT64 Attributes,
|
IN UINT64 Attributes,
|
||||||
IN UINT32 EntryMask
|
IN UINT32 EntryMask,
|
||||||
|
IN volatile ARM_FIRST_LEVEL_DESCRIPTOR *FirstLevelTable
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT32 EntryValue;
|
UINT32 EntryValue;
|
||||||
UINT32 FirstLevelIdx;
|
UINT32 FirstLevelIdx;
|
||||||
UINT32 NumSections;
|
UINT32 NumSections;
|
||||||
UINT32 i;
|
UINT32 i;
|
||||||
UINT32 CurrentDescriptor;
|
UINT32 CurrentDescriptor;
|
||||||
UINT32 Descriptor;
|
UINT32 Descriptor;
|
||||||
VOID *Mva;
|
VOID *Mva;
|
||||||
volatile ARM_FIRST_LEVEL_DESCRIPTOR *FirstLevelTable;
|
|
||||||
|
|
||||||
Status = EFI_SUCCESS;
|
Status = EFI_SUCCESS;
|
||||||
|
|
||||||
@ -325,9 +322,6 @@ UpdateSectionEntries (
|
|||||||
EntryValue |= TT_DESCRIPTOR_SECTION_AF;
|
EntryValue |= TT_DESCRIPTOR_SECTION_AF;
|
||||||
}
|
}
|
||||||
|
|
||||||
// obtain page table base
|
|
||||||
FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress ();
|
|
||||||
|
|
||||||
// calculate index into first level translation table for start of modification
|
// calculate index into first level translation table for start of modification
|
||||||
FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS (BaseAddress) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;
|
FirstLevelIdx = TT_DESCRIPTOR_SECTION_BASE_ADDRESS (BaseAddress) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;
|
||||||
ASSERT (FirstLevelIdx < TRANSLATION_TABLE_SECTION_COUNT);
|
ASSERT (FirstLevelIdx < TRANSLATION_TABLE_SECTION_COUNT);
|
||||||
@ -347,7 +341,8 @@ UpdateSectionEntries (
|
|||||||
TT_DESCRIPTOR_SECTION_SIZE,
|
TT_DESCRIPTOR_SECTION_SIZE,
|
||||||
Attributes,
|
Attributes,
|
||||||
ConvertSectionAttributesToPageAttributes (EntryMask),
|
ConvertSectionAttributesToPageAttributes (EntryMask),
|
||||||
NULL
|
NULL,
|
||||||
|
FirstLevelTable
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// still a section entry
|
// still a section entry
|
||||||
@ -385,6 +380,7 @@ UpdateSectionEntries (
|
|||||||
@param Attributes A mask of EFI_MEMORY_xx constants.
|
@param Attributes A mask of EFI_MEMORY_xx constants.
|
||||||
@param SectionMask A mask of short descriptor section attributes
|
@param SectionMask A mask of short descriptor section attributes
|
||||||
describing which descriptor bits to update.
|
describing which descriptor bits to update.
|
||||||
|
@param UserPageTable The base address of the User page table.
|
||||||
|
|
||||||
@retval EFI_SUCCESS The attributes were set successfully.
|
@retval EFI_SUCCESS The attributes were set successfully.
|
||||||
@retval EFI_OUT_OF_RESOURCES The operation failed due to insufficient memory.
|
@retval EFI_OUT_OF_RESOURCES The operation failed due to insufficient memory.
|
||||||
@ -396,12 +392,14 @@ SetMemoryAttributes (
|
|||||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||||
IN UINT64 Length,
|
IN UINT64 Length,
|
||||||
IN UINT64 Attributes,
|
IN UINT64 Attributes,
|
||||||
IN UINT32 SectionMask
|
IN UINT32 SectionMask,
|
||||||
|
IN UINTN UserPageTable OPTIONAL
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT64 ChunkLength;
|
UINT64 ChunkLength;
|
||||||
BOOLEAN FlushTlbs;
|
BOOLEAN FlushTlbs;
|
||||||
|
volatile ARM_FIRST_LEVEL_DESCRIPTOR *FirstLevelTable;
|
||||||
|
|
||||||
if (BaseAddress > (UINT64)MAX_ADDRESS) {
|
if (BaseAddress > (UINT64)MAX_ADDRESS) {
|
||||||
DEBUG ((
|
DEBUG ((
|
||||||
@ -419,6 +417,13 @@ SetMemoryAttributes (
|
|||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtain page table base
|
||||||
|
if (UserPageTable == 0) {
|
||||||
|
FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress ();
|
||||||
|
} else {
|
||||||
|
FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)UserPageTable;
|
||||||
|
}
|
||||||
|
|
||||||
FlushTlbs = FALSE;
|
FlushTlbs = FALSE;
|
||||||
while (Length > 0) {
|
while (Length > 0) {
|
||||||
if ((BaseAddress % TT_DESCRIPTOR_SECTION_SIZE == 0) &&
|
if ((BaseAddress % TT_DESCRIPTOR_SECTION_SIZE == 0) &&
|
||||||
@ -438,7 +443,8 @@ SetMemoryAttributes (
|
|||||||
BaseAddress,
|
BaseAddress,
|
||||||
ChunkLength,
|
ChunkLength,
|
||||||
Attributes,
|
Attributes,
|
||||||
SectionMask
|
SectionMask,
|
||||||
|
FirstLevelTable
|
||||||
);
|
);
|
||||||
|
|
||||||
FlushTlbs = TRUE;
|
FlushTlbs = TRUE;
|
||||||
@ -466,7 +472,8 @@ SetMemoryAttributes (
|
|||||||
ChunkLength,
|
ChunkLength,
|
||||||
Attributes,
|
Attributes,
|
||||||
ConvertSectionAttributesToPageAttributes (SectionMask),
|
ConvertSectionAttributesToPageAttributes (SectionMask),
|
||||||
&FlushTlbs
|
&FlushTlbs,
|
||||||
|
FirstLevelTable
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -517,6 +524,7 @@ SetMemoryAttributes (
|
|||||||
@param[in] Length The size in bytes of the memory region.
|
@param[in] Length The size in bytes of the memory region.
|
||||||
@param[in] Attributes Mask of memory attributes to set.
|
@param[in] Attributes Mask of memory attributes to set.
|
||||||
@param[in] AttributeMask Mask of memory attributes to take into account.
|
@param[in] AttributeMask Mask of memory attributes to take into account.
|
||||||
|
@param[in] UserPageTable The base address of the User page table.
|
||||||
|
|
||||||
@retval EFI_SUCCESS The attributes were set for the memory region.
|
@retval EFI_SUCCESS The attributes were set for the memory region.
|
||||||
@retval EFI_INVALID_PARAMETER BaseAddress or Length is not suitably aligned.
|
@retval EFI_INVALID_PARAMETER BaseAddress or Length is not suitably aligned.
|
||||||
@ -531,7 +539,8 @@ ArmSetMemoryAttributes (
|
|||||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||||
IN UINT64 Length,
|
IN UINT64 Length,
|
||||||
IN UINT64 Attributes,
|
IN UINT64 Attributes,
|
||||||
IN UINT64 AttributeMask
|
IN UINT64 AttributeMask,
|
||||||
|
IN UINTN UserPageTable OPTIONAL
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINT32 TtEntryMask;
|
UINT32 TtEntryMask;
|
||||||
@ -584,6 +593,7 @@ ArmSetMemoryAttributes (
|
|||||||
BaseAddress,
|
BaseAddress,
|
||||||
Length,
|
Length,
|
||||||
Attributes,
|
Attributes,
|
||||||
TtEntryMask
|
TtEntryMask,
|
||||||
|
UserPageTable
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -584,6 +584,7 @@ GetMemoryRegionPage (
|
|||||||
On output, the base address of the region found.
|
On output, the base address of the region found.
|
||||||
@param[out] RegionLength The length of the region found.
|
@param[out] RegionLength The length of the region found.
|
||||||
@param[out] RegionAttributes The attributes of the region found.
|
@param[out] RegionAttributes The attributes of the region found.
|
||||||
|
@param[in] UserPageTable The base address of the User page table.
|
||||||
|
|
||||||
@retval EFI_SUCCESS Region found
|
@retval EFI_SUCCESS Region found
|
||||||
@retval EFI_NOT_FOUND Region not found
|
@retval EFI_NOT_FOUND Region not found
|
||||||
@ -596,7 +597,8 @@ EFI_STATUS
|
|||||||
GetMemoryRegion (
|
GetMemoryRegion (
|
||||||
IN OUT UINTN *BaseAddress,
|
IN OUT UINTN *BaseAddress,
|
||||||
OUT UINTN *RegionLength,
|
OUT UINTN *RegionLength,
|
||||||
OUT UINTN *RegionAttributes
|
OUT UINTN *RegionAttributes,
|
||||||
|
IN UINTN UserPageTable OPTIONAL
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -612,7 +614,11 @@ GetMemoryRegion (
|
|||||||
*RegionLength = 0;
|
*RegionLength = 0;
|
||||||
|
|
||||||
// Obtain page table base
|
// Obtain page table base
|
||||||
FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress ();
|
if (UserPageTable == 0) {
|
||||||
|
FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)ArmGetTTBR0BaseAddress ();
|
||||||
|
} else {
|
||||||
|
FirstLevelTable = (ARM_FIRST_LEVEL_DESCRIPTOR *)UserPageTable;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate index into first level translation table for start of modification
|
// Calculate index into first level translation table for start of modification
|
||||||
TableIndex = TT_DESCRIPTOR_SECTION_BASE_ADDRESS (*BaseAddress) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;
|
TableIndex = TT_DESCRIPTOR_SECTION_BASE_ADDRESS (*BaseAddress) >> TT_DESCRIPTOR_SECTION_BASE_SHIFT;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user