[PATCH v3 1/5] MpInitLib: Allocate code buffer for PEI phase


Ni, Ray
 

Today's implementation assumes PEI phase runs at 32bit so
the execution-disable feature is not applicable.
It's not always TRUE.
The patch allocates 32bit&64bit code buffer for PEI phase as well.

Signed-off-by: Ray Ni <ray.ni@...>
Cc: Eric Dong <eric.dong@...>
---
UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 2 +-
UefiCpuPkg/Library/MpInitLib/MpLib.c | 2 +-
UefiCpuPkg/Library/MpInitLib/MpLib.h | 2 +-
UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 15 ++++++++++-----
4 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M=
pInitLib/DxeMpLib.c
index 60d14a5a0e..78cc3e2b93 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -162,7 +162,7 @@ GetWakeupBuffer (
@retval 0 Cannot find free memory below 4GB.=0D
**/=0D
UINTN=0D
-GetModeTransitionBuffer (=0D
+AllocateCodeBuffer (=0D
IN UINTN BufferSize=0D
)=0D
{=0D
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn=
itLib/MpLib.c
index 4a73787ee4..d761bdc487 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1056,7 +1056,7 @@ AllocateResetVector (
(CpuMpData->WakeupBuffer +=0D
CpuMpData->AddressMap.RendezvousFunnel=
Size +=0D
CpuMpData->AddressMap.SwitchToRealSize=
);=0D
- CpuMpData->WakeupBufferHigh =3D GetModeTransitionBuffer (=0D
+ CpuMpData->WakeupBufferHigh =3D AllocateCodeBuffer (=0D
CpuMpData->AddressMap.RendezvousFunnel=
Size +=0D
CpuMpData->AddressMap.SwitchToRealSize=
-=0D
CpuMpData->AddressMap.ModeTransitionOf=
fset=0D
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn=
itLib/MpLib.h
index f8c52426dd..59ab960897 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -442,7 +442,7 @@ GetWakeupBuffer (
@retval 0 Cannot find free memory below 4GB.=0D
**/=0D
UINTN=0D
-GetModeTransitionBuffer (=0D
+AllocateCodeBuffer (=0D
IN UINTN BufferSize=0D
);=0D
=0D
diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/M=
pInitLib/PeiMpLib.c
index efce574727..65400b95a2 100644
--- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
@@ -299,14 +299,19 @@ GetWakeupBuffer (
@retval 0 Cannot find free memory below 4GB.=0D
**/=0D
UINTN=0D
-GetModeTransitionBuffer (=0D
+AllocateCodeBuffer (=0D
IN UINTN BufferSize=0D
)=0D
{=0D
- //=0D
- // PEI phase doesn't need to do such transition. So simply return 0.=0D
- //=0D
- return 0;=0D
+ EFI_STATUS Status;=0D
+ EFI_PHYSICAL_ADDRESS Address;=0D
+=0D
+ Status =3D PeiServicesAllocatePages (EfiBootServicesCode, EFI_SIZE_TO_PA=
GES (BufferSize), &Address);=0D
+ if (EFI_ERROR (Status)) {=0D
+ Address =3D 0;=0D
+ }=0D
+=0D
+ return (UINTN)Address;=0D
}=0D
=0D
/**=0D
--=20
2.35.1.windows.2