Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Chen Fan <chen.fan.f...@cn.fujitsu.com> --- UefiCpuPkg/CpuDxe/CpuMp.c | 89 +++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 42 deletions(-)
diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c index baab253..950db38 100644 --- a/UefiCpuPkg/CpuDxe/CpuMp.c +++ b/UefiCpuPkg/CpuDxe/CpuMp.c @@ -38,6 +38,36 @@ EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate = { }; /** + Get Mp Service Lock. + + @param CpuData the pointer to CPU_DATA_BLOCK of specified processor + +**/ +VOID +GetMpSpinLock ( + IN CPU_DATA_BLOCK *CpuData + ) +{ + while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) { + CpuPause (); + } +} + +/** + Release Mp Service Lock. + + @param CpuData the pointer to CPU_DATA_BLOCK of specified processor + +**/ +VOID +ReleaseMpSpinLock ( + IN CPU_DATA_BLOCK *CpuData + ) +{ + ReleaseSpinLock (&CpuData->CpuDataLock); +} + +/** Check whether caller processor is BSP. @retval TRUE the caller is BSP @@ -75,12 +105,9 @@ GetApState ( { CPU_STATE State; - while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) { - CpuPause (); - } - + GetMpSpinLock (CpuData); State = CpuData->State; - ReleaseSpinLock (&CpuData->CpuDataLock); + ReleaseMpSpinLock (CpuData); return State; } @@ -98,12 +125,9 @@ SetApState ( IN CPU_STATE State ) { - while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) { - CpuPause (); - } - + GetMpSpinLock (CpuData); CpuData->State = State; - ReleaseSpinLock (&CpuData->CpuDataLock); + ReleaseMpSpinLock (CpuData); } /** @@ -122,13 +146,10 @@ SetApProcedure ( IN VOID *ProcedureArgument ) { - while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) { - CpuPause (); - } - + GetMpSpinLock (CpuData); CpuData->Parameter = ProcedureArgument; CpuData->Procedure = Procedure; - ReleaseSpinLock (&CpuData->CpuDataLock); + ReleaseMpSpinLock (CpuData); } /** @@ -149,12 +170,9 @@ TestCpuStatusFlag ( { UINT32 Ret; - while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) { - CpuPause (); - } - + GetMpSpinLock (CpuData); Ret = CpuData->Info.StatusFlag & Flags; - ReleaseSpinLock (&CpuData->CpuDataLock); + ReleaseMpSpinLock (CpuData); return !!(Ret); } @@ -172,12 +190,9 @@ CpuStatusFlagOr ( IN UINT32 Flags ) { - while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) { - CpuPause (); - } - + GetMpSpinLock (CpuData); CpuData->Info.StatusFlag |= Flags; - ReleaseSpinLock (&CpuData->CpuDataLock); + ReleaseMpSpinLock (CpuData); } /** @@ -193,12 +208,9 @@ CpuStatusFlagAndNot ( IN UINT32 Flags ) { - while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) { - CpuPause (); - } - + GetMpSpinLock (CpuData); CpuData->Info.StatusFlag &= ~Flags; - ReleaseSpinLock (&CpuData->CpuDataLock); + ReleaseMpSpinLock (CpuData); } /** @@ -1127,25 +1139,18 @@ ProcessorToIdleState ( AsmApDoneWithCommonStack (); while (TRUE) { - while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) { - CpuPause (); - } - + GetMpSpinLock (CpuData); ProcedureArgument = CpuData->Parameter; Procedure = CpuData->Procedure; - ReleaseSpinLock (&CpuData->CpuDataLock); + ReleaseMpSpinLock (CpuData); if (Procedure != NULL) { Procedure (ProcedureArgument); - while (!AcquireSpinLockOrFail (&CpuData->CpuDataLock)) { - CpuPause (); - } - + GetMpSpinLock (CpuData); CpuData->Procedure = NULL; - ReleaseSpinLock (&CpuData->CpuDataLock); - - SetApState (CpuData, CpuStateFinished); + CpuData->State = CpuStateFinished; + ReleaseMpSpinLock (CpuData); } CpuPause (); -- 1.9.3 ------------------------------------------------------------------------------ _______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-devel