diff options
author | Kun Qin <kuqin@microsoft.com> | 2025-05-14 13:22:39 -0700 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2025-06-26 21:43:56 +0000 |
commit | 51d273d8c3dbc36f25f3d2af27bef6e01604d90c (patch) | |
tree | 758dea503ffc62261599dd8b9b9104b00f3cca8f | |
parent | 23e1fc6b0bea0849e1a9be0caf915f9121612353 (diff) | |
download | edk2-51d273d8c3dbc36f25f3d2af27bef6e01604d90c.zip edk2-51d273d8c3dbc36f25f3d2af27bef6e01604d90c.tar.gz edk2-51d273d8c3dbc36f25f3d2af27bef6e01604d90c.tar.bz2 |
MdeModulePkg: MmVariablePei: Use MM communicate v3
As the MM cores begin to support MM Communicate v3, this update moves the
driver to communicate to MM agent through MM Communicate v3 PPI.
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
3 files changed, 61 insertions, 17 deletions
diff --git a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c index 4f937e2..eac1da5 100644 --- a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c +++ b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c @@ -66,7 +66,9 @@ PopulateHeaderAndCommunicate ( {
EFI_STATUS Status;
EFI_PEI_MM_COMMUNICATION_PPI *MmCommunicationPpi;
+ EFI_PEI_MM_COMMUNICATION3_PPI *MmCommunicationPpiV3;
EFI_MM_COMMUNICATE_HEADER *MmCommunicateHeader;
+ EFI_MM_COMMUNICATE_HEADER_V3 *MmCommunicateHeaderV3;
SMM_VARIABLE_COMMUNICATE_HEADER *MmVarCommsHeader;
// Minimal sanity check
@@ -86,30 +88,67 @@ PopulateHeaderAndCommunicate ( goto Exit;
}
- Status = PeiServicesLocatePpi (&gEfiPeiMmCommunicationPpiGuid, 0, NULL, (VOID **)&MmCommunicationPpi);
+ MmCommunicationPpiV3 = NULL;
+ MmCommunicationPpi = NULL;
+
+ Status = PeiServicesLocatePpi (&gEfiPeiMmCommunication3PpiGuid, 0, NULL, (VOID **)&MmCommunicationPpiV3);
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a: Failed to locate PEI MM Communication PPI: %r\n", __func__, Status));
- goto Exit;
+ DEBUG ((DEBUG_WARN, "%a: Unable to locate PEI MM Communication3 PPI: %r\n", __func__, Status));
+ // Try to locate the older version of the PPI
+ Status = PeiServicesLocatePpi (&gEfiPeiMmCommunicationPpiGuid, 0, NULL, (VOID **)&MmCommunicationPpi);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to locate PEI MM Communication PPI: %r\n", __func__, Status));
+ goto Exit;
+ }
}
- // Zero the entire Communication Buffer Header
- MmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)CommunicateBuffer;
+ if (MmCommunicationPpiV3 != NULL) {
+ // Zero the entire Communication Buffer Header
+ MmCommunicateHeaderV3 = (EFI_MM_COMMUNICATE_HEADER_V3 *)CommunicateBuffer;
- ZeroMem (MmCommunicateHeader, SMM_COMMUNICATE_HEADER_SIZE);
+ ZeroMem (MmCommunicateHeaderV3, SMM_COMMUNICATE_HEADER_SIZE_V3);
- // Use gEfiSmmVariableProtocolGuid to request the MM variable service in Standalone MM
- CopyMem ((VOID *)&MmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid, sizeof (GUID));
+ // Use gEfiSmmVariableProtocolGuid to request the MM variable service in Standalone MM
+ CopyMem ((VOID *)&MmCommunicateHeaderV3->HeaderGuid, &gEfiMmCommunicateHeaderV3Guid, sizeof (GUID));
+ MmCommunicateHeaderV3->BufferSize = CommunicateBufferSize;
- // Program the MM header size
- MmCommunicateHeader->MessageLength = CommunicateBufferSize - SMM_COMMUNICATE_HEADER_SIZE;
+ CopyMem ((VOID *)&MmCommunicateHeaderV3->MessageGuid, &gEfiSmmVariableProtocolGuid, sizeof (GUID));
- MmVarCommsHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)(CommunicateBuffer + SMM_COMMUNICATE_HEADER_SIZE);
+ // Program the MM header size
+ MmCommunicateHeaderV3->MessageSize = CommunicateBufferSize - SMM_COMMUNICATE_HEADER_SIZE_V3;
- // We are only supporting GetVariable and GetNextVariableName
- MmVarCommsHeader->Function = Function;
+ MmVarCommsHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)(MmCommunicateHeaderV3->MessageData);
+
+ // We are only supporting GetVariable and GetNextVariableName
+ MmVarCommsHeader->Function = Function;
+
+ // Send the MM request using MmCommunicationPei
+ Status = MmCommunicationPpiV3->Communicate (MmCommunicationPpiV3, CommunicateBuffer);
+ } else if (MmCommunicationPpi != NULL) {
+ // Zero the entire Communication Buffer Header
+ MmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)CommunicateBuffer;
+
+ ZeroMem (MmCommunicateHeader, SMM_COMMUNICATE_HEADER_SIZE);
+
+ // Use gEfiSmmVariableProtocolGuid to request the MM variable service in Standalone MM
+ CopyMem ((VOID *)&MmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid, sizeof (GUID));
+
+ // Program the MM header size
+ MmCommunicateHeader->MessageLength = CommunicateBufferSize - SMM_COMMUNICATE_HEADER_SIZE;
+
+ MmVarCommsHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)(CommunicateBuffer + SMM_COMMUNICATE_HEADER_SIZE);
+
+ // We are only supporting GetVariable and GetNextVariableName
+ MmVarCommsHeader->Function = Function;
+
+ // Send the MM request using MmCommunicationPei
+ Status = MmCommunicationPpi->Communicate (MmCommunicationPpi, CommunicateBuffer, &CommunicateBufferSize);
+ } else {
+ // We should never reach here, but just in case
+ Status = EFI_UNSUPPORTED;
+ DEBUG ((DEBUG_ERROR, "%a: No MM Communication PPI found!\n", __func__));
+ }
- // Send the MM request using MmCommunicationPei
- Status = MmCommunicationPpi->Communicate (MmCommunicationPpi, CommunicateBuffer, &CommunicateBufferSize);
if (EFI_ERROR (Status)) {
// Received an error from MM interface.
DEBUG ((DEBUG_ERROR, "%a - MM Interface Error: %r\n", __func__, Status));
diff --git a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h index 0feed8c..0b38329 100644 --- a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h +++ b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h @@ -23,6 +23,7 @@ #include <Ppi/ReadOnlyVariable2.h>
#include <Ppi/MmCommunication.h>
+#include <Ppi/MmCommunication3.h>
#include <Protocol/SmmVariable.h>
#include <Protocol/MmCommunication.h>
diff --git a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf index 13e8052..1f972db 100644 --- a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf +++ b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf @@ -34,7 +34,11 @@ [Ppis]
gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES
- gEfiPeiMmCommunicationPpiGuid ## CONSUMES
+ gEfiPeiMmCommunication3PpiGuid ## CONSUMES
+ gEfiPeiMmCommunicationPpiGuid ## SOMETIMES_CONSUMES
+
+[Guids]
+ gEfiMmCommunicateHeaderV3Guid
[Depex]
- gEfiPeiMmCommunicationPpiGuid
+ gEfiPeiMmCommunicationPpiGuid OR gEfiPeiMmCommunication3PpiGuid
|