]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/PiSmmCpuDxeSmm: Using CPU semaphores in aligned buffer
authorJeff Fan <jeff.fan@intel.com>
Tue, 22 Mar 2016 02:21:27 +0000 (10:21 +0800)
committerMichael Kinney <michael.d.kinney@intel.com>
Tue, 24 May 2016 22:20:12 +0000 (15:20 -0700)
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>
UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h

index 241cd35d32a2989ba0ba0da177504bb256b9c0dc..399315bad8f59997292b338e5c227735ffc9e110 100644 (file)
@@ -123,7 +123,7 @@ WaitForAllAPs (
 \r
   BspIndex = mSmmMpSyncData->BspIndex;\r
   while (NumberOfAPs-- > 0) {\r
-    WaitForSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
+    WaitForSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);\r
   }\r
 }\r
 \r
@@ -142,8 +142,8 @@ ReleaseAllAPs (
 \r
   BspIndex = mSmmMpSyncData->BspIndex;\r
   for (Index = mMaxNumberOfCpus; Index-- > 0;) {\r
-    if (Index != BspIndex && mSmmMpSyncData->CpuData[Index].Present) {\r
-      ReleaseSemaphore (&mSmmMpSyncData->CpuData[Index].Run);\r
+    if (Index != BspIndex && *(mSmmMpSyncData->CpuData[Index].Present)) {\r
+      ReleaseSemaphore (mSmmMpSyncData->CpuData[Index].Run);\r
     }\r
   }\r
 }\r
@@ -175,7 +175,7 @@ AllCpusInSmmWithExceptions (
   CpuData = mSmmMpSyncData->CpuData;\r
   ProcessorInfo = gSmmCpuPrivate->ProcessorInfo;\r
   for (Index = mMaxNumberOfCpus; Index-- > 0;) {\r
-    if (!CpuData[Index].Present && ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) {\r
+    if (!(*(CpuData[Index].Present)) && ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) {\r
       if (((Exceptions & ARRIVAL_EXCEPTION_DELAYED) != 0) && SmmCpuFeaturesGetSmmRegister (Index, SmmRegSmmDelayed) != 0) {\r
         continue;\r
       }\r
@@ -251,7 +251,7 @@ SmmWaitForApArrival (
     // Send SMI IPIs to bring outside processors in\r
     //\r
     for (Index = mMaxNumberOfCpus; Index-- > 0;) {\r
-      if (!mSmmMpSyncData->CpuData[Index].Present && gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) {\r
+      if (!(*(mSmmMpSyncData->CpuData[Index].Present)) && gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID) {\r
         SendSmiIpi ((UINT32)gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId);\r
       }\r
     }\r
@@ -333,7 +333,7 @@ BSPHandler (
   //\r
   // Mark this processor's presence\r
   //\r
-  mSmmMpSyncData->CpuData[CpuIndex].Present = TRUE;\r
+  *(mSmmMpSyncData->CpuData[CpuIndex].Present) = TRUE;\r
 \r
   //\r
   // Clear platform top level SMI status bit before calling SMI handlers. If\r
@@ -412,7 +412,7 @@ BSPHandler (
   //\r
   // The BUSY lock is initialized to Acquired state\r
   //\r
-  AcquireSpinLockOrFail (&mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
+  AcquireSpinLockOrFail (mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
 \r
   //\r
   // Perform the pre tasks\r
@@ -428,9 +428,9 @@ BSPHandler (
   // Make sure all APs have completed their pending none-block tasks\r
   //\r
   for (Index = mMaxNumberOfCpus; Index-- > 0;) {\r
-    if (Index != CpuIndex && mSmmMpSyncData->CpuData[Index].Present) {\r
-      AcquireSpinLock (&mSmmMpSyncData->CpuData[Index].Busy);\r
-      ReleaseSpinLock (&mSmmMpSyncData->CpuData[Index].Busy);;\r
+    if (Index != CpuIndex && *(mSmmMpSyncData->CpuData[Index].Present)) {\r
+      AcquireSpinLock (mSmmMpSyncData->CpuData[Index].Busy);\r
+      ReleaseSpinLock (mSmmMpSyncData->CpuData[Index].Busy);\r
     }\r
   }\r
 \r
@@ -457,7 +457,7 @@ BSPHandler (
     while (TRUE) {\r
       PresentCount = 0;\r
       for (Index = mMaxNumberOfCpus; Index-- > 0;) {\r
-        if (mSmmMpSyncData->CpuData[Index].Present) {\r
+        if (*(mSmmMpSyncData->CpuData[Index].Present)) {\r
           PresentCount ++;\r
         }\r
       }\r
@@ -515,7 +515,7 @@ BSPHandler (
   //\r
   // Clear the Present flag of BSP\r
   //\r
-  mSmmMpSyncData->CpuData[CpuIndex].Present = FALSE;\r
+  *(mSmmMpSyncData->CpuData[CpuIndex].Present) = FALSE;\r
 \r
   //\r
   // Gather APs to exit SMM synchronously. Note the Present flag is cleared by now but\r
@@ -617,20 +617,20 @@ APHandler (
   //\r
   // Mark this processor's presence\r
   //\r
-  mSmmMpSyncData->CpuData[CpuIndex].Present = TRUE;\r
+  *(mSmmMpSyncData->CpuData[CpuIndex].Present) = TRUE;\r
 \r
   if (SyncMode == SmmCpuSyncModeTradition || SmmCpuFeaturesNeedConfigureMtrrs()) {\r
     //\r
     // Notify BSP of arrival at this point\r
     //\r
-    ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
+    ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);\r
   }\r
 \r
   if (SmmCpuFeaturesNeedConfigureMtrrs()) {\r
     //\r
     // Wait for the signal from BSP to backup MTRRs\r
     //\r
-    WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);\r
+    WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run);\r
 \r
     //\r
     // Backup OS MTRRs\r
@@ -640,12 +640,12 @@ APHandler (
     //\r
     // Signal BSP the completion of this AP\r
     //\r
-    ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
+    ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);\r
 \r
     //\r
     // Wait for BSP's signal to program MTRRs\r
     //\r
-    WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);\r
+    WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run);\r
 \r
     //\r
     // Replace OS MTRRs with SMI MTRRs\r
@@ -655,14 +655,14 @@ APHandler (
     //\r
     // Signal BSP the completion of this AP\r
     //\r
-    ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
+    ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);\r
   }\r
 \r
   while (TRUE) {\r
     //\r
     // Wait for something to happen\r
     //\r
-    WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);\r
+    WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run);\r
 \r
     //\r
     // Check if BSP wants to exit SMM\r
@@ -675,7 +675,7 @@ APHandler (
     // BUSY should be acquired by SmmStartupThisAp()\r
     //\r
     ASSERT (\r
-      !AcquireSpinLockOrFail (&mSmmMpSyncData->CpuData[CpuIndex].Busy)\r
+      !AcquireSpinLockOrFail (mSmmMpSyncData->CpuData[CpuIndex].Busy)\r
       );\r
 \r
     //\r
@@ -688,19 +688,19 @@ APHandler (
     //\r
     // Release BUSY\r
     //\r
-    ReleaseSpinLock (&mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
+    ReleaseSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
   }\r
 \r
   if (SmmCpuFeaturesNeedConfigureMtrrs()) {\r
     //\r
     // Notify BSP the readiness of this AP to program MTRRs\r
     //\r
-    ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
+    ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);\r
 \r
     //\r
     // Wait for the signal from BSP to program MTRRs\r
     //\r
-    WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);\r
+    WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run);\r
 \r
     //\r
     // Restore OS MTRRs\r
@@ -712,22 +712,22 @@ APHandler (
   //\r
   // Notify BSP the readiness of this AP to Reset states/semaphore for this processor\r
   //\r
-  ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
+  ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);\r
 \r
   //\r
   // Wait for the signal from BSP to Reset states/semaphore for this processor\r
   //\r
-  WaitForSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);\r
+  WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run);\r
 \r
   //\r
   // Reset states/semaphore for this processor\r
   //\r
-  mSmmMpSyncData->CpuData[CpuIndex].Present = FALSE;\r
+  *(mSmmMpSyncData->CpuData[CpuIndex].Present) = FALSE;\r
 \r
   //\r
   // Notify BSP the readiness of this AP to exit SMM\r
   //\r
-  ReleaseSemaphore (&mSmmMpSyncData->CpuData[BspIndex].Run);\r
+  ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run);\r
 \r
 }\r
 \r
@@ -928,19 +928,19 @@ SmmStartupThisAp (
 {\r
   if (CpuIndex >= gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus ||\r
       CpuIndex == gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu ||\r
-      !mSmmMpSyncData->CpuData[CpuIndex].Present ||\r
+      !(*(mSmmMpSyncData->CpuData[CpuIndex].Present)) ||\r
       gSmmCpuPrivate->Operation[CpuIndex] == SmmCpuRemove ||\r
-      !AcquireSpinLockOrFail (&mSmmMpSyncData->CpuData[CpuIndex].Busy)) {\r
+      !AcquireSpinLockOrFail (mSmmMpSyncData->CpuData[CpuIndex].Busy)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   mSmmMpSyncData->CpuData[CpuIndex].Procedure = Procedure;\r
   mSmmMpSyncData->CpuData[CpuIndex].Parameter = ProcArguments;\r
-  ReleaseSemaphore (&mSmmMpSyncData->CpuData[CpuIndex].Run);\r
+  ReleaseSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run);\r
 \r
   if (FeaturePcdGet (PcdCpuSmmBlockStartupThisAp)) {\r
-    AcquireSpinLock (&mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
-    ReleaseSpinLock (&mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
+    AcquireSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
+    ReleaseSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
   }\r
   return EFI_SUCCESS;\r
 }\r
@@ -1079,7 +1079,7 @@ SmiRendezvous (
       // E.g., with Relaxed AP flow, SmmStartupThisAp() may be called immediately\r
       // after AP's present flag is detected.\r
       //\r
-      InitializeSpinLock (&mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
+      InitializeSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy);\r
     }\r
 \r
     //\r
@@ -1169,7 +1169,7 @@ SmiRendezvous (
       }\r
     }\r
 \r
-    ASSERT (mSmmMpSyncData->CpuData[CpuIndex].Run == 0);\r
+    ASSERT (*mSmmMpSyncData->CpuData[CpuIndex].Run == 0);\r
 \r
     //\r
     // Wait for BSP's signal to exit SMI\r
@@ -1205,6 +1205,7 @@ InitializeSmmCpuSemaphores (
   VOID\r
   )\r
 {\r
+  UINTN                      CpuIndex;\r
   UINTN                      ProcessorCount;\r
   UINTN                      TotalSize;\r
   UINTN                      GlobalSemaphoresSize;\r
@@ -1251,6 +1252,15 @@ InitializeSmmCpuSemaphores (
   mPFLock                       = mSmmCpuSemaphores.SemaphoreGlobal.PFLock;\r
   mConfigSmmCodeAccessCheckLock = mSmmCpuSemaphores.SemaphoreGlobal.CodeAccessCheckLock;\r
 \r
+  for (CpuIndex = 0; CpuIndex < ProcessorCount; CpuIndex ++) {\r
+    mSmmMpSyncData->CpuData[CpuIndex].Busy    =\r
+      (SPIN_LOCK *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Busy + SemaphoreSize * CpuIndex);\r
+    mSmmMpSyncData->CpuData[CpuIndex].Run     =\r
+      (UINT32 *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Run + SemaphoreSize * CpuIndex);\r
+    mSmmMpSyncData->CpuData[CpuIndex].Present =\r
+      (BOOLEAN *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Present + SemaphoreSize * CpuIndex);\r
+  }\r
+\r
   mSemaphoreSize = SemaphoreSize;\r
 }\r
 \r
index 4ef535fb4ec388c5396987b4e2599cab62853d16..8b3bb343ce10e4d1bc59c7675107c0aa65131a8d 100644 (file)
@@ -246,7 +246,7 @@ SmmReadSaveState (
     // the pseudo register value for EFI_SMM_SAVE_STATE_REGISTER_PROCESSOR_ID is returned in Buffer.\r
     // Otherwise, EFI_NOT_FOUND is returned.\r
     //\r
-    if (mSmmMpSyncData->CpuData[CpuIndex].Present) {\r
+    if (*(mSmmMpSyncData->CpuData[CpuIndex].Present)) {\r
       *(UINT64 *)Buffer = gSmmCpuPrivate->ProcessorInfo[CpuIndex].ProcessorId;\r
       return EFI_SUCCESS;\r
     } else {\r
@@ -254,7 +254,7 @@ SmmReadSaveState (
     }\r
   }\r
 \r
-  if (!mSmmMpSyncData->CpuData[CpuIndex].Present) {\r
+  if (!(*(mSmmMpSyncData->CpuData[CpuIndex].Present))) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
index 5a0468027da565af9ee5fa4d42339b511e55e902..df5980cd420f3520e795fc699327f055fa8a9126 100644 (file)
@@ -295,11 +295,11 @@ SmmRelocationSemaphoreComplete (
 /// The type of SMM CPU Information\r
 ///\r
 typedef struct {\r
-  SPIN_LOCK                         Busy;\r
+  SPIN_LOCK                         *Busy;\r
   volatile EFI_AP_PROCEDURE         Procedure;\r
   volatile VOID                     *Parameter;\r
-  volatile UINT32                   Run;\r
-  volatile BOOLEAN                  Present;\r
+  volatile UINT32                   *Run;\r
+  volatile BOOLEAN                  *Present;\r
 } SMM_CPU_DATA_BLOCK;\r
 \r
 typedef enum {\r