Skip to content

Commit d42b2bf

Browse files
committed
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 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]>
1 parent f7cf7d5 commit d42b2bf

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c

+22-22
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,14 @@ BSPHandler (
522522
//
523523
// Wait for all APs of arrival at this point
524524
//
525-
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
525+
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #1: Wait APs
526526

527527
//
528528
// Signal all APs it's time for:
529529
// 1. Backup MTRRs if needed.
530530
// 2. Perform SMM CPU Platform Hook before executing MMI Handler.
531531
//
532-
ReleaseAllAPs ();
532+
ReleaseAllAPs (); /// #2: Signal APs
533533

534534
if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
535535
//
@@ -545,12 +545,12 @@ BSPHandler (
545545
//
546546
// Wait for all APs to complete their MTRR saving
547547
//
548-
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
548+
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #3: Wait APs
549549

550550
//
551551
// Let all processors program SMM MTRRs together
552552
//
553-
ReleaseAllAPs ();
553+
ReleaseAllAPs (); /// #4: Signal APs
554554

555555
//
556556
// SmmCpuSyncWaitForAPs() may wait for ever if an AP happens to enter SMM at
@@ -562,7 +562,7 @@ BSPHandler (
562562
//
563563
// Wait for all APs to complete their MTRR programming
564564
//
565-
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
565+
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #5: Wait APs
566566
}
567567
}
568568

@@ -632,18 +632,18 @@ BSPHandler (
632632
// Notify all APs to exit
633633
//
634634
*mSmmMpSyncData->InsideSmm = FALSE;
635-
ReleaseAllAPs ();
635+
ReleaseAllAPs (); /// #6: Signal APs
636636

637637
if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
638638
//
639639
// Wait for all APs the readiness to program MTRRs
640640
//
641-
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
641+
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #7: Wait APs
642642

643643
//
644644
// Signal APs to restore MTRRs
645645
//
646-
ReleaseAllAPs ();
646+
ReleaseAllAPs (); /// #8: Signal APs
647647

648648
//
649649
// Restore OS MTRRs
@@ -656,12 +656,12 @@ BSPHandler (
656656
//
657657
// Wait for all APs to complete their pending tasks including MTRR programming if needed.
658658
//
659-
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
659+
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #9: Wait APs
660660

661661
//
662662
// Signal APs to Reset states/semaphore for this processor
663663
//
664-
ReleaseAllAPs ();
664+
ReleaseAllAPs (); /// #10: Signal APs
665665
}
666666

667667
if (mSmmDebugAgentSupport) {
@@ -686,7 +686,7 @@ BSPHandler (
686686
// Gather APs to exit SMM synchronously. Note the Present flag is cleared by now but
687687
// WaitForAllAps does not depend on the Present flag.
688688
//
689-
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
689+
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #11: Wait APs
690690

691691
//
692692
// At this point, all APs should have exited from APHandler().
@@ -812,14 +812,14 @@ APHandler (
812812
//
813813
// Notify BSP of arrival at this point
814814
//
815-
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
815+
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #1: Signal BSP
816816

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

825825
if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
@@ -831,12 +831,12 @@ APHandler (
831831
//
832832
// Signal BSP the completion of this AP
833833
//
834-
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
834+
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #3: Signal BSP
835835

836836
//
837837
// Wait for BSP's signal to program MTRRs
838838
//
839-
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
839+
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #4: Wait BSP
840840

841841
//
842842
// Replace OS MTRRs with SMI MTRRs
@@ -846,7 +846,7 @@ APHandler (
846846
//
847847
// Signal BSP the completion of this AP
848848
//
849-
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
849+
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #5: Signal BSP
850850
}
851851

852852
//
@@ -858,7 +858,7 @@ APHandler (
858858
//
859859
// Wait for something to happen
860860
//
861-
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
861+
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #6: Wait BSP
862862

863863
//
864864
// Check if BSP wants to exit SMM
@@ -898,12 +898,12 @@ APHandler (
898898
//
899899
// Notify BSP the readiness of this AP to program MTRRs
900900
//
901-
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
901+
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #7: Signal BSP
902902

903903
//
904904
// Wait for the signal from BSP to program MTRRs
905905
//
906-
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
906+
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #8: Wait BSP
907907

908908
//
909909
// Restore OS MTRRs
@@ -916,12 +916,12 @@ APHandler (
916916
//
917917
// Notify BSP the readiness of this AP to Reset states/semaphore for this processor
918918
//
919-
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
919+
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #9: Signal BSP
920920

921921
//
922922
// Wait for the signal from BSP to Reset states/semaphore for this processor
923923
//
924-
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
924+
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #10: Wait BSP
925925
}
926926

927927
//
@@ -932,7 +932,7 @@ APHandler (
932932
//
933933
// Notify BSP the readiness of this AP to exit SMM
934934
//
935-
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
935+
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #11: Signal BSP
936936
}
937937

938938
/**

0 commit comments

Comments
 (0)