From 7162ac72c46a360955e2af312d475e6eae7dbe71 Mon Sep 17 00:00:00 2001 From: Jiaxin Wu Date: Sat, 12 Oct 2024 11:03:50 +0800 Subject: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Clarification for BSP & APs Sync Flow This patch does not impact functionality. It aims to clarify the synchronization flow between the BSP and APs to enhance code readability and understanding: Steps #6 and #11 are the basic synchronization requirements for all cases. Steps #1 is additional requirements if the MmCpuSyncModeTradition mode is selected. Steps #1, #2, #3, #4, #5, #7, #8, #9, and #10 are additional requirements if the system needs to configure the MTRR. Steps #9 and #10 are additional requirements if the system needs to support the mSmmDebugAgentSupport. Signed-off-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 44 +++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 210b23af21d8..2df2cb9f22db 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -522,13 +522,13 @@ BSPHandler ( // // Wait for all APs to get ready for programming MTRRs // - SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #1: Wait APs if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Signal all APs it's time for backup MTRRs // - ReleaseAllAPs (); + ReleaseAllAPs (); /// #2: Signal APs // // SmmCpuSyncWaitForAPs() may wait for ever if an AP happens to enter SMM at @@ -543,12 +543,12 @@ BSPHandler ( // // Wait for all APs to complete their MTRR saving // - SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #3: Wait APs // // Let all processors program SMM MTRRs together // - ReleaseAllAPs (); + ReleaseAllAPs (); /// #4: Signal APs // // SmmCpuSyncWaitForAPs() may wait for ever if an AP happens to enter SMM at @@ -560,7 +560,7 @@ BSPHandler ( // // Wait for all APs to complete their MTRR programming // - SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #5: Wait APs } } @@ -625,18 +625,18 @@ BSPHandler ( // Notify all APs to exit // *mSmmMpSyncData->InsideSmm = FALSE; - ReleaseAllAPs (); + ReleaseAllAPs (); /// #6: Signal APs if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Wait for all APs the readiness to program MTRRs // - SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #7: Wait APs // // Signal APs to restore MTRRs // - ReleaseAllAPs (); + ReleaseAllAPs (); /// #8: Signal APs // // Restore OS MTRRs @@ -649,12 +649,12 @@ BSPHandler ( // // Wait for all APs to complete their pending tasks including MTRR programming if needed. // - SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #9: Wait APs // // Signal APs to Reset states/semaphore for this processor // - ReleaseAllAPs (); + ReleaseAllAPs (); /// #10: Signal APs } if (mSmmDebugAgentSupport) { @@ -679,7 +679,7 @@ BSPHandler ( // Gather APs to exit SMM synchronously. Note the Present flag is cleared by now but // WaitForAllAps does not depend on the Present flag. // - SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #11: Wait APs // // At this point, all APs should have exited from APHandler(). @@ -805,14 +805,14 @@ APHandler ( // // Notify BSP of arrival at this point // - SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #1: Signal BSP } if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Wait for the signal from BSP to backup MTRRs // - SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #2: Wait BSP // // Backup OS MTRRs @@ -822,12 +822,12 @@ APHandler ( // // Signal BSP the completion of this AP // - SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #3: Signal BSP // // Wait for BSP's signal to program MTRRs // - SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #4: Wait BSP // // Replace OS MTRRs with SMI MTRRs @@ -837,14 +837,14 @@ APHandler ( // // Signal BSP the completion of this AP // - SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #5: Signal BSP } while (TRUE) { // // Wait for something to happen // - SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #6: Wait BSP // // Check if BSP wants to exit SMM @@ -884,12 +884,12 @@ APHandler ( // // Notify BSP the readiness of this AP to program MTRRs // - SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #7: Signal BSP // // Wait for the signal from BSP to program MTRRs // - SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #8: Wait BSP // // Restore OS MTRRs @@ -902,12 +902,12 @@ APHandler ( // // Notify BSP the readiness of this AP to Reset states/semaphore for this processor // - SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #9: Signal BSP // // Wait for the signal from BSP to Reset states/semaphore for this processor // - SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #10: Wait BSP } // @@ -918,7 +918,7 @@ APHandler ( // // Notify BSP the readiness of this AP to exit SMM // - SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #11: Signal BSP } /**