diff options
author | Jeff Fan <jeff.fan@intel.com> | 2016-03-22 10:21:27 +0800 |
---|---|---|
committer | Hao Wu <hao.a.wu@intel.com> | 2016-07-06 16:20:43 +0800 |
commit | 43097c4d6fb36e9d554f4119196ab5a3671271a0 (patch) | |
tree | 442d26be233402a4f6f81c21a9e9694fffb7af90 | |
parent | 72324c1fa6ed5c526c77b62b5a38e6bbe4455abb (diff) | |
download | edk2-platforms-43097c4d6fb36e9d554f4119196ab5a3671271a0.tar.xz |
UefiCpuPkg/PiSmmCpuDxeSmm: Using CPU semaphores in aligned buffer
Update each CPU semaphores to the ones in allocated aligned
semaphores buffer.
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
(cherry picked from commit ed3d5ecb342dd6cca299ac72b30d4855a8b804a4)
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 78 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 4 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 6 |
3 files changed, 49 insertions, 39 deletions
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 19843e5638..59cecc3fe8 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -123,7 +123,7 @@ WaitForAllAPs ( BspIndex = mSmmMpSyncData->BspIndex;
while (NumberOfAPs-- > 0) {
- WaitForSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);
+ WaitForSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);
}
}
@@ -142,8 +142,8 @@ ReleaseAllAPs ( BspIndex = mSmmMpSyncData->BspIndex;
for (Index = mMaxNumberOfCpus; Index-- > 0;) {
- if (Index != BspIndex && mSmmMpSyncData->CpuData[Index].Present) {
- ReleaseSemaphore (&mSmmMpSyncData->CpuData[Index].Run);
+ if (Index != BspIndex && *(mSmmMpSyncData->CpuData[Index].Present)) {
+ ReleaseSemaphore (mSmmMpSyncData->CpuData[Index].Run);
}
}
}
@@ -175,7 +175,7 @@ AllCpusInSmmWithExceptions ( CpuData = mSmmMpSyncData->CpuData;
ProcessorInfo = gSmmCpuPrivate->ProcessorInfo;
for (Index = mMaxNumberOfCpus; Index-- > 0;) {
- if (!CpuData[Index].Present && ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) {
+ if (!(*(CpuData[Index].Present)) && ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) {
if (((Exceptions & ARRIVAL_EXCEPTION_DELAYED) != 0) && SmmCpuFeaturesGetSmmRegister (Index, SmmRegSmmDelayed) != 0) {
continue;
}
@@ -251,7 +251,7 @@ SmmWaitForApArrival ( // Send SMI IPIs to bring outside processors in
//
for (Index = mMaxNumberOfCpus; Index-- > 0;) {
- if (!mSmmMpSyncData->CpuData[Index].Present && gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) {
+ if (!(*(mSmmMpSyncData->CpuData[Index].Present)) && gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) {
SendSmiIpi ((UINT32)gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId);
}
}
@@ -333,7 +333,7 @@ BSPHandler ( //
// Mark this processor's presence
//
- mSmmMpSyncData->CpuData[CpuIndex].Present = TRUE;
+ *(mSmmMpSyncData->CpuData[CpuIndex].Present) = TRUE;
//
// Clear platform top level SMI status bit before calling SMI handlers. If
@@ -412,7 +412,7 @@ BSPHandler ( //
// The BUSY lock is initialized to Acquired state
//
- AcquireSpinLockOrFail (&mSmmMpSyncData->CpuData[CpuIndex].Busy);
+ AcquireSpinLockOrFail (mSmmMpSyncData->CpuData[CpuIndex].Busy);
//
// Perform the pre tasks
@@ -428,9 +428,9 @@ BSPHandler ( // Make sure all APs have completed their pending none-block tasks
//
for (Index = mMaxNumberOfCpus; Index-- > 0;) {
- if (Index != CpuIndex && mSmmMpSyncData->CpuData[Index].Present) {
- AcquireSpinLock (&mSmmMpSyncData->CpuData[Index].Busy);
- ReleaseSpinLock (&mSmmMpSyncData->CpuData[Index].Busy);;
+ if (Index != CpuIndex && *(mSmmMpSyncData->CpuData[Index].Present)) {
+ AcquireSpinLock (mSmmMpSyncData->CpuData[Index].Busy);
+ ReleaseSpinLock (mSmmMpSyncData->CpuData[Index].Busy);
}
}
@@ -457,7 +457,7 @@ BSPHandler ( while (TRUE) {
PresentCount = 0;
for (Index = mMaxNumberOfCpus; Index-- > 0;) {
- if (mSmmMpSyncData->CpuData[Index].Present) {
+ if (*(mSmmMpSyncData->CpuData[Index].Present)) {
PresentCount ++;
}
}
@@ -515,7 +515,7 @@ BSPHandler ( //
// Clear the Present flag of BSP
//
- mSmmMpSyncData->CpuData[CpuIndex].Present = FALSE;
+ *(mSmmMpSyncData->CpuData[CpuIndex].Present) = FALSE;
//
// Gather APs to exit SMM synchronously. Note the Present flag is cleared by now but
@@ -617,20 +617,20 @@ APHandler ( //
// Mark this processor's presence
//
- mSmmMpSyncData->CpuData[CpuIndex].Present = TRUE;
+ *(mSmmMpSyncData->CpuData[CpuIndex].Present) = TRUE;
if (SyncMode == SmmCpuSyncModeTradition || SmmCpuFeaturesNeedConfigureMtrrs()) {
//
// Notify BSP of arrival at this point
//
- ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);
+ ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);
}
if (SmmCpuFeaturesNeedConfigureMtrrs()) {
//
// Wait for the signal from BSP to backup MTRRs
//
- WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);
+ WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run);
//
// Backup OS MTRRs
@@ -640,12 +640,12 @@ APHandler ( //
// Signal BSP the completion of this AP
//
- ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);
+ ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);
//
// Wait for BSP's signal to program MTRRs
//
- WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);
+ WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run);
//
// Replace OS MTRRs with SMI MTRRs
@@ -655,14 +655,14 @@ APHandler ( //
// Signal BSP the completion of this AP
//
- ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);
+ ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);
}
while (TRUE) {
//
// Wait for something to happen
//
- WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);
+ WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run);
//
// Check if BSP wants to exit SMM
@@ -675,7 +675,7 @@ APHandler ( // BUSY should be acquired by SmmStartupThisAp()
//
ASSERT (
- !AcquireSpinLockOrFail (&mSmmMpSyncData->CpuData[CpuIndex].Busy)
+ !AcquireSpinLockOrFail (mSmmMpSyncData->CpuData[CpuIndex].Busy)
);
//
@@ -688,19 +688,19 @@ APHandler ( //
// Release BUSY
//
- ReleaseSpinLock (&mSmmMpSyncData->CpuData[CpuIndex].Busy);
+ ReleaseSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy);
}
if (SmmCpuFeaturesNeedConfigureMtrrs()) {
//
// Notify BSP the readiness of this AP to program MTRRs
//
- ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);
+ ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);
//
// Wait for the signal from BSP to program MTRRs
//
- WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);
+ WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run);
//
// Restore OS MTRRs
@@ -712,22 +712,22 @@ APHandler ( //
// Notify BSP the readiness of this AP to Reset states/semaphore for this processor
//
- ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);
+ ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);
//
// Wait for the signal from BSP to Reset states/semaphore for this processor
//
- WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);
+ WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run);
//
// Reset states/semaphore for this processor
//
- mSmmMpSyncData->CpuData[CpuIndex].Present = FALSE;
+ *(mSmmMpSyncData->CpuData[CpuIndex].Present) = FALSE;
//
// Notify BSP the readiness of this AP to exit SMM
//
- ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);
+ ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);
}
@@ -928,19 +928,19 @@ SmmStartupThisAp ( {
if (CpuIndex >= gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus ||
CpuIndex == gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu ||
- !mSmmMpSyncData->CpuData[CpuIndex].Present ||
+ !(*(mSmmMpSyncData->CpuData[CpuIndex].Present)) ||
gSmmCpuPrivate->Operation[CpuIndex] == SmmCpuRemove ||
- !AcquireSpinLockOrFail (&mSmmMpSyncData->CpuData[CpuIndex].Busy)) {
+ !AcquireSpinLockOrFail (mSmmMpSyncData->CpuData[CpuIndex].Busy)) {
return EFI_INVALID_PARAMETER;
}
mSmmMpSyncData->CpuData[CpuIndex].Procedure = Procedure;
mSmmMpSyncData->CpuData[CpuIndex].Parameter = ProcArguments;
- ReleaseSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);
+ ReleaseSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run);
if (FeaturePcdGet (PcdCpuSmmBlockStartupThisAp)) {
- AcquireSpinLock (&mSmmMpSyncData->CpuData[CpuIndex].Busy);
- ReleaseSpinLock (&mSmmMpSyncData->CpuData[CpuIndex].Busy);
+ AcquireSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy);
+ ReleaseSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy);
}
return EFI_SUCCESS;
}
@@ -1078,7 +1078,7 @@ SmiRendezvous ( // E.g., with Relaxed AP flow, SmmStartupThisAp() may be called immediately
// after AP's present flag is detected.
//
- InitializeSpinLock (&mSmmMpSyncData->CpuData[CpuIndex].Busy);
+ InitializeSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy);
}
//
@@ -1166,7 +1166,7 @@ SmiRendezvous ( }
}
- ASSERT (mSmmMpSyncData->CpuData[CpuIndex].Run == 0);
+ ASSERT (*mSmmMpSyncData->CpuData[CpuIndex].Run == 0);
//
// Wait for BSP's signal to exit SMI
@@ -1200,6 +1200,7 @@ InitializeSmmCpuSemaphores ( VOID
)
{
+ UINTN CpuIndex;
UINTN ProcessorCount;
UINTN TotalSize;
UINTN GlobalSemaphoresSize;
@@ -1246,6 +1247,15 @@ InitializeSmmCpuSemaphores ( mPFLock = mSmmCpuSemaphores.SemaphoreGlobal.PFLock;
mConfigSmmCodeAccessCheckLock = mSmmCpuSemaphores.SemaphoreGlobal.CodeAccessCheckLock;
+ for (CpuIndex = 0; CpuIndex < ProcessorCount; CpuIndex ++) {
+ mSmmMpSyncData->CpuData[CpuIndex].Busy =
+ (SPIN_LOCK *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Busy + SemaphoreSize * CpuIndex);
+ mSmmMpSyncData->CpuData[CpuIndex].Run =
+ (UINT32 *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Run + SemaphoreSize * CpuIndex);
+ mSmmMpSyncData->CpuData[CpuIndex].Present =
+ (BOOLEAN *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Present + SemaphoreSize * CpuIndex);
+ }
+
mSemaphoreSize = SemaphoreSize;
}
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c index 4ef535fb4e..8b3bb343ce 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -246,7 +246,7 @@ SmmReadSaveState ( // the pseudo register value for EFI_SMM_SAVE_STATE_REGISTER_PROCESSOR_ID is returned in Buffer.
// Otherwise, EFI_NOT_FOUND is returned.
//
- if (mSmmMpSyncData->CpuData[CpuIndex].Present) {
+ if (*(mSmmMpSyncData->CpuData[CpuIndex].Present)) {
*(UINT64 *)Buffer = gSmmCpuPrivate->ProcessorInfo[CpuIndex].ProcessorId;
return EFI_SUCCESS;
} else {
@@ -254,7 +254,7 @@ SmmReadSaveState ( }
}
- if (!mSmmMpSyncData->CpuData[CpuIndex].Present) {
+ if (!(*(mSmmMpSyncData->CpuData[CpuIndex].Present))) {
return EFI_INVALID_PARAMETER;
}
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h index 5c14f83119..fd441ad3a1 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -294,11 +294,11 @@ SmmRelocationSemaphoreComplete ( /// The type of SMM CPU Information
///
typedef struct {
- SPIN_LOCK Busy;
+ SPIN_LOCK *Busy;
volatile EFI_AP_PROCEDURE Procedure;
volatile VOID *Parameter;
- volatile UINT32 Run;
- volatile BOOLEAN Present;
+ volatile UINT32 *Run;
+ volatile BOOLEAN *Present;
} SMM_CPU_DATA_BLOCK;
typedef enum {
|