From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.71.1588786090102317556 for ; Wed, 06 May 2020 10:28:10 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5FF1D1FB; Wed, 6 May 2020 10:28:09 -0700 (PDT) Received: from e123331-lin.nice.arm.com (unknown [10.37.8.179]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C856A3F71F; Wed, 6 May 2020 10:28:06 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Michael D Kinney , Liming Gao , Jian J Wang , Hao A Wu , Leif Lindholm , Sami Mujawar , Jiewen Yao Subject: [PATCH resend 6/7] MdeModulePkg/VariableSmmRuntimeDxe: switch to MM communicate 2 Date: Wed, 6 May 2020 19:27:33 +0200 Message-Id: <20200506172734.2475-7-ard.biesheuvel@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200506172734.2475-1-ard.biesheuvel@arm.com> References: <20200506172734.2475-1-ard.biesheuvel@arm.com> Switch to the new MM communicate 2 protocol which supports both traditional and standalone MM. Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Include/Guid/SmmVariableCommon.h | 6 +-- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c | 39 +++++++++++--------- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf | 4 +- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/MdeModulePkg/Include/Guid/SmmVariableCommon.h b/MdeModulePkg/Include/Guid/SmmVariableCommon.h index ceef44dfd2d7..8ddc94b92da6 100644 --- a/MdeModulePkg/Include/Guid/SmmVariableCommon.h +++ b/MdeModulePkg/Include/Guid/SmmVariableCommon.h @@ -20,7 +20,7 @@ extern EFI_GUID gSmmVariableWriteGuid; // // This structure is used for SMM variable. the collected statistics data is saved in SMRAM. It can be got from // SMI handler. The communication buffer should be: -// EFI_SMM_COMMUNICATE_HEADER + SMM_VARIABLE_COMMUNICATE_HEADER + payload. +// EFI_MM_COMMUNICATE_HEADER + SMM_VARIABLE_COMMUNICATE_HEADER + payload. // typedef struct { UINTN Function; @@ -53,7 +53,7 @@ typedef struct { // #define SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE 6 // -// The payload for this function is VARIABLE_INFO_ENTRY. The GUID in EFI_SMM_COMMUNICATE_HEADER +// The payload for this function is VARIABLE_INFO_ENTRY. The GUID in EFI_MM_COMMUNICATE_HEADER // is gEfiSmmVariableProtocolGuid. // #define SMM_VARIABLE_FUNCTION_GET_STATISTICS 7 @@ -81,7 +81,7 @@ typedef struct { /// /// Size of SMM communicate header, without including the payload. /// -#define SMM_COMMUNICATE_HEADER_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data)) +#define SMM_COMMUNICATE_HEADER_SIZE (OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data)) /// /// Size of SMM variable communicate header, without including the payload. diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c index ca833fb0244d..663a1aaa128f 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c @@ -21,7 +21,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include -#include +#include #include #include #include @@ -45,7 +45,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent EFI_HANDLE mHandle = NULL; EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable = NULL; EFI_EVENT mVirtualAddressChangeEvent = NULL; -EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication = NULL; +EFI_MM_COMMUNICATION2_PROTOCOL *mMmCommunication2 = NULL; UINT8 *mVariableBuffer = NULL; UINT8 *mVariableBufferPhysical = NULL; VARIABLE_INFO_ENTRY *mVariableInfo = NULL; @@ -210,7 +210,7 @@ InitCommunicateBuffer ( IN UINTN Function ) { - EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader; + EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader; SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader; @@ -218,7 +218,7 @@ InitCommunicateBuffer ( return EFI_INVALID_PARAMETER; } - SmmCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) mVariableBuffer; + SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *) mVariableBuffer; CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid); SmmCommunicateHeader->MessageLength = DataSize + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE; @@ -248,14 +248,17 @@ SendCommunicateBuffer ( { EFI_STATUS Status; UINTN CommSize; - EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader; + EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader; SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader; CommSize = DataSize + SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE; - Status = mSmmCommunication->Communicate (mSmmCommunication, mVariableBufferPhysical, &CommSize); + Status = mMmCommunication2->Communicate (mMmCommunication2, + mVariableBufferPhysical, + mVariableBuffer, + &CommSize); ASSERT_EFI_ERROR (Status); - SmmCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) mVariableBuffer; + SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *) mVariableBuffer; SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeader->Data; return SmmVariableFunctionHeader->ReturnStatus; } @@ -1309,7 +1312,7 @@ VariableAddressChangeEvent ( ) { EfiConvertPointer (0x0, (VOID **) &mVariableBuffer); - EfiConvertPointer (0x0, (VOID **) &mSmmCommunication); + EfiConvertPointer (0x0, (VOID **) &mMmCommunication2); EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **) &mVariableRuntimeHobCacheBuffer); EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **) &mVariableRuntimeNvCacheBuffer); EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **) &mVariableRuntimeVolatileCacheBuffer); @@ -1332,7 +1335,7 @@ GetVariablePayloadSize ( { EFI_STATUS Status; SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *SmmGetPayloadSize; - EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader; + EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader; SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader; UINTN CommSize; UINT8 *CommBuffer; @@ -1357,7 +1360,7 @@ GetVariablePayloadSize ( goto Done; } - SmmCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) CommBuffer; + SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *) CommBuffer; CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid); SmmCommunicateHeader->MessageLength = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE); @@ -1368,7 +1371,7 @@ GetVariablePayloadSize ( // // Send data to SMM. // - Status = mSmmCommunication->Communicate (mSmmCommunication, CommBuffer, &CommSize); + Status = mMmCommunication2->Communicate (mMmCommunication2, CommBuffer, CommBuffer, &CommSize); ASSERT_EFI_ERROR (Status); Status = SmmVariableFunctionHeader->ReturnStatus; @@ -1413,7 +1416,7 @@ GetRuntimeCacheInfo ( { EFI_STATUS Status; SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO *SmmGetRuntimeCacheInfo; - EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader; + EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader; SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader; UINTN CommSize; UINT8 *CommBuffer; @@ -1434,7 +1437,7 @@ GetRuntimeCacheInfo ( CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO); ZeroMem (CommBuffer, CommSize); - SmmCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) CommBuffer; + SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *) CommBuffer; CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid); SmmCommunicateHeader->MessageLength = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO); @@ -1445,7 +1448,7 @@ GetRuntimeCacheInfo ( // // Send data to SMM. // - Status = mSmmCommunication->Communicate (mSmmCommunication, CommBuffer, &CommSize); + Status = mMmCommunication2->Communicate (mMmCommunication2, CommBuffer, CommBuffer, &CommSize); ASSERT_EFI_ERROR (Status); if (CommSize <= SMM_VARIABLE_COMMUNICATE_HEADER_SIZE) { Status = EFI_BAD_BUFFER_SIZE; @@ -1486,7 +1489,7 @@ SendRuntimeVariableCacheContextToSmm ( { EFI_STATUS Status; SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *SmmRuntimeVarCacheContext; - EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeader; + EFI_MM_COMMUNICATE_HEADER *SmmCommunicateHeader; SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader; UINTN CommSize; UINT8 *CommBuffer; @@ -1507,7 +1510,7 @@ SendRuntimeVariableCacheContextToSmm ( CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT); ZeroMem (CommBuffer, CommSize); - SmmCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) CommBuffer; + SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *) CommBuffer; CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid); SmmCommunicateHeader->MessageLength = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT); @@ -1525,7 +1528,7 @@ SendRuntimeVariableCacheContextToSmm ( // // Send data to SMM. // - Status = mSmmCommunication->Communicate (mSmmCommunication, CommBuffer, &CommSize); + Status = mMmCommunication2->Communicate (mMmCommunication2, CommBuffer, CommBuffer, &CommSize); ASSERT_EFI_ERROR (Status); if (CommSize <= SMM_VARIABLE_COMMUNICATE_HEADER_SIZE) { Status = EFI_BAD_BUFFER_SIZE; @@ -1563,7 +1566,7 @@ SmmVariableReady ( return; } - Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication); + Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **) &mMmCommunication2); ASSERT_EFI_ERROR (Status); // diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf index 592862773390..01564e4c5068 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf @@ -60,7 +60,7 @@ [LibraryClasses] [Protocols] gEfiVariableWriteArchProtocolGuid ## PRODUCES gEfiVariableArchProtocolGuid ## PRODUCES - gEfiSmmCommunicationProtocolGuid ## CONSUMES + gEfiMmCommunication2ProtocolGuid ## CONSUMES ## CONSUMES ## NOTIFY ## UNDEFINED # Used to do smm communication @@ -100,7 +100,7 @@ [Guids] gEfiImageSecurityDatabaseGuid [Depex] - gEfiSmmCommunicationProtocolGuid + gEfiMmCommunication2ProtocolGuid [UserExtensions.TianoCore."ExtraFiles"] VariableSmmRuntimeDxeExtra.uni -- 2.17.1