Skip to content

Commit

Permalink
UefiCpuPkg/PiSmmCpuDxeSmm: Clarification for BSP & APs Sync Flow
Browse files Browse the repository at this point in the history
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 tianocore#6 and tianocore#11 are the basic synchronization requirements for all
cases.

Steps tianocore#1 and tianocore#2 are additional requirements if the
MmCpuSyncModeTradition mode is selected.

Steps tianocore#1, tianocore#2, tianocore#3, tianocore#4, tianocore#5, tianocore#7, tianocore#8, tianocore#9, and tianocore#10 are additional
requirements if the system needs to configure the MTRR.

Steps tianocore#9 and tianocore#10 are additional requirements if the system needs to
support the mSmmDebugAgentSupport.

Signed-off-by: Jiaxin Wu <[email protected]>
  • Loading branch information
jiaxinwu committed Oct 12, 2024
1 parent f7cf7d5 commit d42b2bf
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,14 @@ BSPHandler (
//
// Wait for all APs of arrival at this point
//
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #1: Wait APs

//
// Signal all APs it's time for:
// 1. Backup MTRRs if needed.
// 2. Perform SMM CPU Platform Hook before executing MMI Handler.
//
ReleaseAllAPs ();
ReleaseAllAPs (); /// #2: Signal APs

if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
//
Expand All @@ -545,12 +545,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
Expand All @@ -562,7 +562,7 @@ BSPHandler (
//
// Wait for all APs to complete their MTRR programming
//
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #5: Wait APs
}
}

Expand Down Expand Up @@ -632,18 +632,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
Expand All @@ -656,12 +656,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) {
Expand All @@ -686,7 +686,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().
Expand Down Expand Up @@ -812,14 +812,14 @@ APHandler (
//
// Notify BSP of arrival at this point
//
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #1: Signal BSP

//
// Wait for the signal from BSP to:
// 1. Backup MTRRs if needed.
// 2. Perform SMM CPU Platform Hook before executing MMI Handler.
//
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #2: Wait BSP
}

if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
Expand All @@ -831,12 +831,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
Expand All @@ -846,7 +846,7 @@ APHandler (
//
// Signal BSP the completion of this AP
//
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #5: Signal BSP
}

//
Expand All @@ -858,7 +858,7 @@ APHandler (
//
// 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
Expand Down Expand Up @@ -898,12 +898,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
Expand All @@ -916,12 +916,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
}

//
Expand All @@ -932,7 +932,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
}

/**
Expand Down

0 comments on commit d42b2bf

Please sign in to comment.