Skip to content

Commit

Permalink
UefiCpuPkg: Add New Memory Attributes
Browse files Browse the repository at this point in the history
Add usage of EFI_MEMORY_SP and EFI_MEMORY_CPU_CRYPTO
attributes introduced in UEFI 2.8.
(UEFI 2.8, mantis 1919 and 1872).
Use attributes bitmasks, defined in MdePkg.

Signed-off-by: Oleksiy Yakovlev <[email protected]>
Reviewed-by: Laszlo Ersek <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Eric Dong <[email protected]>
Tested-by: Laszlo Ersek <[email protected]>
  • Loading branch information
Oleksiyy authored and mergify[bot] committed Jul 15, 2020
1 parent c2e38a5 commit e77966b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
11 changes: 4 additions & 7 deletions UefiCpuPkg/CpuDxe/CpuDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
#include "CpuMp.h"
#include "CpuPageTable.h"

#define CACHE_ATTRIBUTE_MASK (EFI_MEMORY_UC | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_MEMORY_WB | EFI_MEMORY_UCE | EFI_MEMORY_WP)
#define MEMORY_ATTRIBUTE_MASK (EFI_MEMORY_RP | EFI_MEMORY_XP | EFI_MEMORY_RO)

//
// Global Variables
//
Expand Down Expand Up @@ -417,8 +414,8 @@ CpuSetMemoryAttributes (
return EFI_SUCCESS;
}

CacheAttributes = Attributes & CACHE_ATTRIBUTE_MASK;
MemoryAttributes = Attributes & MEMORY_ATTRIBUTE_MASK;
CacheAttributes = Attributes & EFI_CACHE_ATTRIBUTE_MASK;
MemoryAttributes = Attributes & EFI_MEMORY_ATTRIBUTE_MASK;

if (Attributes != (CacheAttributes | MemoryAttributes)) {
return EFI_INVALID_PARAMETER;
Expand Down Expand Up @@ -677,7 +674,7 @@ SetGcdMemorySpaceAttributes (
gDS->SetMemorySpaceAttributes (
RegionStart,
RegionLength,
(MemorySpaceMap[Index].Attributes & ~EFI_MEMORY_CACHETYPE_MASK) | (MemorySpaceMap[Index].Capabilities & Attributes)
(MemorySpaceMap[Index].Attributes & ~EFI_CACHE_ATTRIBUTE_MASK) | (MemorySpaceMap[Index].Capabilities & Attributes)
);
}

Expand Down Expand Up @@ -754,7 +751,7 @@ RefreshMemoryAttributesFromMtrr (
gDS->SetMemorySpaceAttributes (
MemorySpaceMap[Index].BaseAddress,
MemorySpaceMap[Index].Length,
(MemorySpaceMap[Index].Attributes & ~EFI_MEMORY_CACHETYPE_MASK) |
(MemorySpaceMap[Index].Attributes & ~EFI_CACHE_ATTRIBUTE_MASK) |
(MemorySpaceMap[Index].Capabilities & DefaultAttributes)
);
}
Expand Down
13 changes: 0 additions & 13 deletions UefiCpuPkg/CpuDxe/CpuDxe.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@
#include <Guid/IdleLoopEvent.h>
#include <Guid/VectorHandoffTable.h>

#define EFI_MEMORY_CACHETYPE_MASK (EFI_MEMORY_UC | \
EFI_MEMORY_WC | \
EFI_MEMORY_WT | \
EFI_MEMORY_WB | \
EFI_MEMORY_UCE | \
EFI_MEMORY_WP \
)

#define EFI_MEMORY_PAGETYPE_MASK (EFI_MEMORY_RP | \
EFI_MEMORY_XP | \
EFI_MEMORY_RO \
)

#define HEAP_GUARD_NONSTOP_MODE \
((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT6|BIT4|BIT1|BIT0)) > BIT6)

Expand Down
6 changes: 3 additions & 3 deletions UefiCpuPkg/CpuDxe/CpuPageTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ ConvertMemoryPageAttributes (
return RETURN_INVALID_PARAMETER;
}

if ((Attributes & ~(EFI_MEMORY_RP | EFI_MEMORY_RO | EFI_MEMORY_XP)) != 0) {
if ((Attributes & ~EFI_MEMORY_ATTRIBUTE_MASK) != 0) {
DEBUG ((DEBUG_ERROR, "Attributes(0x%lx) has unsupported bit\n", Attributes));
return EFI_UNSUPPORTED;
}
Expand Down Expand Up @@ -1018,9 +1018,9 @@ RefreshGcdMemoryAttributesFromPaging (

Length = MIN (PageLength, MemorySpaceLength);
if (Attributes != (MemorySpaceMap[Index].Attributes &
EFI_MEMORY_PAGETYPE_MASK)) {
EFI_MEMORY_ATTRIBUTE_MASK)) {
NewAttributes = (MemorySpaceMap[Index].Attributes &
~EFI_MEMORY_PAGETYPE_MASK) | Attributes;
~EFI_MEMORY_ATTRIBUTE_MASK) | Attributes;
Status = gDS->SetMemorySpaceAttributes (
BaseAddress,
Length,
Expand Down
2 changes: 1 addition & 1 deletion UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ ConvertMemoryPageAttributes (
EFI_PHYSICAL_ADDRESS MaximumSupportMemAddress;

ASSERT (Attributes != 0);
ASSERT ((Attributes & ~(EFI_MEMORY_RP | EFI_MEMORY_RO | EFI_MEMORY_XP)) == 0);
ASSERT ((Attributes & ~EFI_MEMORY_ATTRIBUTE_MASK) == 0);

ASSERT ((BaseAddress & (SIZE_4KB - 1)) == 0);
ASSERT ((Length & (SIZE_4KB - 1)) == 0);
Expand Down

0 comments on commit e77966b

Please sign in to comment.