--- /dev/null
+/** @file\r
+ SMM CPU Rendezvous library header file.\r
+\r
+ Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef SMM_CPU_RENDEZVOUS_H_\r
+#define SMM_CPU_RENDEZVOUS_H_\r
+\r
+/**\r
+ This routine wait for all AP processors to arrive in SMM.\r
+\r
+ @param[in] BlockingMode Blocking mode or non-blocking mode.\r
+\r
+ @retval EFI_SUCCESS All processors checked in to SMM.\r
+ @retval EFI_TIMEOUT Wait for all APs until timeout.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmWaitForAllProcessor (\r
+ IN BOOLEAN BlockingMode\r
+ );\r
+\r
+#endif\r
/** @file\r
SMM CPU Service protocol definition.\r
\r
-Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2013 - 2022, Intel Corporation. All rights reserved.<BR>\r
SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
extern EFI_GUID gEfiSmmCpuServiceProtocolGuid;\r
\r
+//\r
+// EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL provide SMM CPU\r
+// rendezvous service support.\r
+//\r
+#define EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL_GUID \\r
+ { \\r
+ 0xaa00d50b, 0x4911, 0x428f, { 0xb9, 0x1a, 0xa5, 0x9d, 0xdb, 0x13, 0xe2, 0x4c } \\r
+ }\r
+\r
+typedef struct _EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL;\r
+\r
+/**\r
+ Wait for all APs to arrive SMM mode in given timeout constraint.\r
+\r
+ @param[in] This A pointer to the EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL instance.\r
+ @param[in] BlockingMode Block or non-block mode.\r
+\r
+ @retval EFI_SUCCESS All APs have arrived SMM mode except SMI disabled APs.\r
+ @retval EFI_TIMEOUT There are APs not in SMM mode in given timeout constraint.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EDKII_WAIT_FOR_ALL_PROCESSOR)(\r
+ IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This,\r
+ IN BOOLEAN BlockingMode\r
+ );\r
+\r
+struct _EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL {\r
+ EDKII_WAIT_FOR_ALL_PROCESSOR WaitForAllProcessor;\r
+};\r
+\r
+extern EFI_GUID gEdkiiSmmCpuRendezvousProtocolGuid;\r
+\r
#endif\r
--- /dev/null
+/** @file\r
+ SMM CPU Rendezvous sevice implement.\r
+\r
+ Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+#include <Uefi.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MmServicesTableLib.h>\r
+#include <Protocol/SmmCpuService.h>\r
+#include <Library/SmmCpuRendezvousLib.h>\r
+\r
+STATIC EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *mSmmCpuRendezvous = NULL;\r
+STATIC VOID *mRegistration = NULL;\r
+\r
+/**\r
+ Callback function to wait Smm cpu rendezvous service located.\r
+\r
+ SmmCpuRendezvousLib need to support MM_STANDALONE and DXE_SMM_DRIVER driver.\r
+ So do not use library constructor to locate the protocol.\r
+\r
+ @param[in] Protocol Points to the protocol's unique identifier.\r
+ @param[in] Interface Points to the interface instance.\r
+ @param[in] Handle The handle on which the interface was installed.\r
+\r
+ @retval EFI_SUCCESS Notification runs successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmCpuRendezvousProtocolNotify (\r
+ IN CONST EFI_GUID *Protocol,\r
+ IN VOID *Interface,\r
+ IN EFI_HANDLE Handle\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ Status = gMmst->MmLocateProtocol (\r
+ &gEdkiiSmmCpuRendezvousProtocolGuid,\r
+ NULL,\r
+ (VOID **)&mSmmCpuRendezvous\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ This routine wait for all AP processors to arrive in SMM.\r
+\r
+ @param[in] BlockingMode Blocking mode or non-blocking mode.\r
+\r
+ @retval EFI_SUCCESS All avaiable APs arrived.\r
+ @retval EFI_TIMEOUT Wait for all APs until timeout.\r
+ @retval OTHER Fail to register SMM CPU Rendezvous service Protocol.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmWaitForAllProcessor (\r
+ IN BOOLEAN BlockingMode\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ if ((mRegistration == NULL) && (mSmmCpuRendezvous == NULL)) {\r
+ //\r
+ // Locate SMM cpu rendezvous protocol for the first time execute the function.\r
+ //\r
+ Status = gMmst->MmLocateProtocol (\r
+ &gEdkiiSmmCpuRendezvousProtocolGuid,\r
+ NULL,\r
+ (VOID **)&mSmmCpuRendezvous\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ Status = gMmst->MmRegisterProtocolNotify (\r
+ &gEdkiiSmmCpuRendezvousProtocolGuid,\r
+ SmmCpuRendezvousProtocolNotify,\r
+ &mRegistration\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ }\r
+ }\r
+\r
+ //\r
+ // The platform have not set up. It doesn't need smm cpu rendezvous.\r
+ //\r
+ if (mSmmCpuRendezvous == NULL) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ Status = mSmmCpuRendezvous->WaitForAllProcessor (\r
+ mSmmCpuRendezvous,\r
+ BlockingMode\r
+ );\r
+ return Status;\r
+}\r
--- /dev/null
+## @file\r
+# SMM CPU Rendezvous service lib.\r
+#\r
+# This is SMM CPU rendezvous service lib that wait for all\r
+# APs to enter SMM mode.\r
+#\r
+# Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = SmmCpuRendezvousLib\r
+ FILE_GUID = 1509Bb36-9Ba4-438B-B195-Ac5914Db14E2\r
+ MODULE_TYPE = DXE_SMM_DRIVER\r
+ LIBRARY_CLASS = SmmCpuRendezvousLib|MM_STANDALONE DXE_SMM_DRIVER\r
+\r
+[Sources]\r
+ SmmCpuRendezvousLib.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ UefiCpuPkg/UefiCpuPkg.dec\r
+\r
+[LibraryClasses]\r
+ BaseLib\r
+ DebugLib\r
+ MmServicesTableLib\r
+\r
+[Pcd]\r
+ gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmApSyncTimeout ## CONSUMES\r
+\r
+[Protocols]\r
+ gEdkiiSmmCpuRendezvousProtocolGuid\r
/** @file\r
Implementation of SMM CPU Services Protocol.\r
\r
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR>\r
SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
SmmRegisterExceptionHandler\r
};\r
\r
+//\r
+// EDKII SMM CPU Rendezvous Service Protocol instance\r
+//\r
+EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL mSmmCpuRendezvousService = {\r
+ SmmCpuRendezvous\r
+};\r
+\r
/**\r
Gets processor information on the requested processor at the instant this call is made.\r
\r
@param ImageHandle The firmware allocated handle for the EFI image.\r
\r
@retval EFI_SUCCESS EFI SMM CPU Services Protocol was installed successfully.\r
+ @retval OTHER Fail to install Protocol.\r
**/\r
EFI_STATUS\r
InitializeSmmCpuServices (\r
&mSmmCpuService\r
);\r
ASSERT_EFI_ERROR (Status);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Status = gSmst->SmmInstallProtocolInterface (\r
+ &Handle,\r
+ &gEdkiiSmmCpuRendezvousProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ &mSmmCpuRendezvousService\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Wait for all processors enterring SMM until all CPUs are already synchronized or not.\r
+\r
+ If BlockingMode is False, timeout value is zero.\r
+\r
+ @param This A pointer to the EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL instance.\r
+ @param BlockingMode Blocking mode or non-blocking mode.\r
+\r
+ @retval EFI_SUCCESS All avaiable APs arrived.\r
+ @retval EFI_TIMEOUT Wait for all APs until timeout.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmCpuRendezvous (\r
+ IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This,\r
+ IN BOOLEAN BlockingMode\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ //\r
+ // Return success immediately if all CPUs are already synchronized.\r
+ //\r
+ if (mSmmMpSyncData->AllApArrivedWithException) {\r
+ Status = EFI_SUCCESS;\r
+ goto ON_EXIT;\r
+ }\r
+\r
+ if (!BlockingMode) {\r
+ Status = EFI_TIMEOUT;\r
+ goto ON_EXIT;\r
+ }\r
+\r
+ //\r
+ // There are some APs outside SMM, Wait for all avaiable APs to arrive.\r
+ //\r
+ SmmWaitForApArrival ();\r
+ Status = mSmmMpSyncData->AllApArrivedWithException ? EFI_SUCCESS : EFI_TIMEOUT;\r
+\r
+ON_EXIT:\r
+ if (!mSmmMpSyncData->AllApArrivedWithException) {\r
+ DEBUG ((DEBUG_INFO, "EdkiiSmmWaitForAllApArrival: Timeout to wait all APs arrival\n"));\r
+ }\r
+\r
return Status;\r
}\r
/** @file\r
SMM MP service implementation\r
\r
-Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR>\r
Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>\r
\r
SPDX-License-Identifier: BSD-2-Clause-Patent\r
// Sync with APs 1st timeout\r
//\r
for (Timer = StartSyncTimer ();\r
- !IsSyncTimerTimeout (Timer) && !(LmceEn && LmceSignal) &&\r
- !AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED);\r
+ !IsSyncTimerTimeout (Timer) && !(LmceEn && LmceSignal);\r
)\r
{\r
+ mSmmMpSyncData->AllApArrivedWithException = AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED);\r
+ if (mSmmMpSyncData->AllApArrivedWithException) {\r
+ break;\r
+ }\r
+\r
CpuPause ();\r
}\r
\r
// Sync with APs 2nd timeout.\r
//\r
for (Timer = StartSyncTimer ();\r
- !IsSyncTimerTimeout (Timer) &&\r
- !AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED);\r
+ !IsSyncTimerTimeout (Timer);\r
)\r
{\r
+ mSmmMpSyncData->AllApArrivedWithException = AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED);\r
+ if (mSmmMpSyncData->AllApArrivedWithException) {\r
+ break;\r
+ }\r
+\r
CpuPause ();\r
}\r
}\r
*mSmmMpSyncData->InsideSmm = FALSE;\r
*mSmmMpSyncData->AllCpusInSync = FALSE;\r
\r
+ mSmmMpSyncData->AllApArrivedWithException = FALSE;\r
+\r
for (CpuIndex = 0; CpuIndex < gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus; CpuIndex++) {\r
mSmmMpSyncData->CpuData[CpuIndex].Busy =\r
(SPIN_LOCK *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Busy + mSemaphoreSize * CpuIndex);\r
/** @file\r
Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU.\r
\r
-Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR>\r
Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>\r
\r
SPDX-License-Identifier: BSD-2-Clause-Patent\r
volatile SMM_CPU_SYNC_MODE EffectiveSyncMode;\r
volatile BOOLEAN SwitchBsp;\r
volatile BOOLEAN *CandidateBsp;\r
+ volatile BOOLEAN AllApArrivedWithException;\r
EFI_AP_PROCEDURE StartupProcedure;\r
VOID *StartupProcArgs;\r
} SMM_DISPATCHER_MP_SYNC_DATA;\r
VOID\r
);\r
\r
+/**\r
+ Choose blocking or non-blocking mode to Wait for all APs.\r
+\r
+ @param[in] This A pointer to the EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL instance.\r
+ @param[in] BlockingMode Blocking or non-blocking mode.\r
+\r
+ @retval EFI_SUCCESS All APs have arrived SMM mode except SMI disabled APs.\r
+ @retval EFI_TIMEOUT There are APs not in SMM mode in given timeout constraint.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SmmCpuRendezvous (\r
+ IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This,\r
+ IN BOOLEAN BlockingMode\r
+ );\r
+\r
+/**\r
+ Insure when this function returns, no AP will execute normal mode code before entering SMM, except SMI disabled APs.\r
+\r
+**/\r
+VOID\r
+SmmWaitForApArrival (\r
+ VOID\r
+ );\r
+\r
#endif\r
# This SMM driver performs SMM initialization, deploy SMM Entry Vector,\r
# provides CPU specific services in SMM.\r
#\r
-# Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR>\r
# Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>\r
#\r
# SPDX-License-Identifier: BSD-2-Clause-Patent\r
gEfiSmmReadyToLockProtocolGuid ## NOTIFY\r
gEfiSmmCpuServiceProtocolGuid ## PRODUCES\r
gEdkiiSmmMemoryAttributeProtocolGuid ## PRODUCES\r
- gEfiMmMpProtocolGuid ## PRODUCES\r
+ gEfiMmMpProtocolGuid ## PRODUCES\r
+ gEdkiiSmmCpuRendezvousProtocolGuid ## PRODUCES\r
\r
[Guids]\r
gEfiAcpiVariableGuid ## SOMETIMES_CONSUMES ## HOB # it is used for S3 boot.\r
## @file UefiCpuPkg.dec\r
# This Package provides UEFI compatible CPU modules and libraries.\r
#\r
-# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2022, Intel Corporation. All rights reserved.<BR>\r
#\r
# SPDX-License-Identifier: BSD-2-Clause-Patent\r
#\r
## @libraryclass Provides function for loading microcode.\r
MicrocodeLib|Include/Library/MicrocodeLib.h\r
\r
+ ## @libraryclass Provides function for SMM CPU Rendezvous Library.\r
+ SmmCpuRendezvousLib|Include/Library/SmmCpuRendezvousLib.h\r
+\r
[Guids]\r
gUefiCpuPkgTokenSpaceGuid = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa, 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}\r
gMsegSmramGuid = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1, 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }}\r
\r
[Protocols]\r
## Include/Protocol/SmmCpuService.h\r
- gEfiSmmCpuServiceProtocolGuid = { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94, 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }}\r
+ gEfiSmmCpuServiceProtocolGuid = { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94, 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }}\r
+ gEdkiiSmmCpuRendezvousProtocolGuid = { 0xaa00d50b, 0x4911, 0x428f, { 0xb9, 0x1a, 0xa5, 0x9d, 0xdb, 0x13, 0xe2, 0x4c }}\r
\r
## Include/Protocol/SmMonitorInit.h\r
gEfiSmMonitorInitProtocolGuid = { 0x228f344d, 0xb3de, 0x43bb, { 0xa4, 0xd7, 0xea, 0x20, 0xb, 0x1b, 0x14, 0x82 }}\r
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf\r
VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf\r
MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf\r
+ SmmCpuRendezvousLib|UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf\r
\r
[LibraryClasses.common.SEC]\r
PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf\r
}\r
UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf\r
UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf\r
+ UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf\r
\r
[BuildOptions]\r
*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES\r