]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
NetworkPkg: HttpDxe response/cancel issue fix
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / MpService.c
index 22ff813b344d58ba71269e74a8fef4160ce3efa4..add770ff3cbfe0f29c2bee0017fedf093e760d17 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,9 +1205,12 @@ InitializeSmmCpuSemaphores (
   VOID\r
   )\r
 {\r
+  UINTN                      CpuIndex;\r
   UINTN                      ProcessorCount;\r
   UINTN                      TotalSize;\r
   UINTN                      GlobalSemaphoresSize;\r
+  UINTN                      CpuSemaphoresSize;\r
+  UINTN                      MsrSemahporeSize;\r
   UINTN                      SemaphoreSize;\r
   UINTN                      Pages;\r
   UINTN                      *SemaphoreBlock;\r
@@ -1216,7 +1219,9 @@ InitializeSmmCpuSemaphores (
   SemaphoreSize   = GetSpinLockProperties ();\r
   ProcessorCount = gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus;\r
   GlobalSemaphoresSize = (sizeof (SMM_CPU_SEMAPHORE_GLOBAL) / sizeof (VOID *)) * SemaphoreSize;\r
-  TotalSize = GlobalSemaphoresSize;\r
+  CpuSemaphoresSize    = (sizeof (SMM_CPU_SEMAPHORE_CPU) / sizeof (VOID *)) * ProcessorCount * SemaphoreSize;\r
+  MsrSemahporeSize     = MSR_SPIN_LOCK_INIT_NUM * SemaphoreSize;\r
+  TotalSize = GlobalSemaphoresSize + CpuSemaphoresSize + MsrSemahporeSize;\r
   DEBUG((EFI_D_INFO, "One Semaphore Size    = 0x%x\n", SemaphoreSize));\r
   DEBUG((EFI_D_INFO, "Total Semaphores Size = 0x%x\n", TotalSize));\r
   Pages = EFI_SIZE_TO_PAGES (TotalSize);\r
@@ -1236,12 +1241,34 @@ InitializeSmmCpuSemaphores (
   mSmmCpuSemaphores.SemaphoreGlobal.CodeAccessCheckLock\r
                                                   = (SPIN_LOCK *)SemaphoreAddr;\r
 \r
+  SemaphoreAddr = (UINTN)SemaphoreBlock + GlobalSemaphoresSize;\r
+  mSmmCpuSemaphores.SemaphoreCpu.Busy    = (SPIN_LOCK *)SemaphoreAddr;\r
+  SemaphoreAddr += ProcessorCount * SemaphoreSize;\r
+  mSmmCpuSemaphores.SemaphoreCpu.Run     = (UINT32 *)SemaphoreAddr;\r
+  SemaphoreAddr += ProcessorCount * SemaphoreSize;\r
+  mSmmCpuSemaphores.SemaphoreCpu.Present = (BOOLEAN *)SemaphoreAddr;\r
+\r
+  SemaphoreAddr = (UINTN)SemaphoreBlock + GlobalSemaphoresSize + CpuSemaphoresSize;\r
+  mSmmCpuSemaphores.SemaphoreMsr.Msr              = (SPIN_LOCK *)SemaphoreAddr;\r
+  mSmmCpuSemaphores.SemaphoreMsr.AvailableCounter =\r
+        ((UINTN)SemaphoreBlock + Pages * SIZE_4KB - SemaphoreAddr) / SemaphoreSize;\r
+  ASSERT (mSmmCpuSemaphores.SemaphoreMsr.AvailableCounter >= MSR_SPIN_LOCK_INIT_NUM);\r
+\r
   mSmmMpSyncData->Counter       = mSmmCpuSemaphores.SemaphoreGlobal.Counter;\r
   mSmmMpSyncData->InsideSmm     = mSmmCpuSemaphores.SemaphoreGlobal.InsideSmm;\r
   mSmmMpSyncData->AllCpusInSync = mSmmCpuSemaphores.SemaphoreGlobal.AllCpusInSync;\r
   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