From a2a8558958cee97efd132361a2b29f2ee8339d91 Mon Sep 17 00:00:00 2001 From: Dun Tan Date: Tue, 11 Jun 2024 11:37:39 +0800 Subject: StandaloneMmPkg: Install gEfiMmCommunicationProtocolGuid Install gEfiMmCommunicationProtocolGuid instance in the MmCommunicationDxe driver. Signed-off-by: Dun Tan --- .../MmCommunicationDxe/MmCommunicationDxe.c | 51 +++++++++++++++++++++- .../MmCommunicationDxe/MmCommunicationDxe.h | 32 ++++++++++++++ .../MmCommunicationDxe/MmCommunicationDxe.inf | 1 + 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.c b/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.c index e216de529f..b4c634db77 100644 --- a/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.c +++ b/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.c @@ -16,6 +16,13 @@ EFI_MM_COMMUNICATION2_PROTOCOL mMmCommunication2 = { MmCommunicate2 }; +// +// PI 1.7 MM Communication Protocol instance +// +EFI_MM_COMMUNICATION_PROTOCOL mMmCommunication = { + MmCommunicate +}; + MM_COMM_BUFFER mMmCommonBuffer; EFI_SMM_CONTROL2_PROTOCOL *mSmmControl2; @@ -45,7 +52,7 @@ MmVirtualAddressChangeEvent ( Processes the communication buffer for Mm communication protocols. This function encapsulates the common logic for handling communication buffers - used by MmCommunicate2 functions. + used by MmCommunicate2 and MmCommunicate functions. @param[in, out] CommBuffer Pointer to the MM communication buffer @param[in, out] CommSize The size of the data buffer being passed in. On exit, the size of data @@ -164,6 +171,40 @@ MmCommunicate2 ( return ProcessCommunicationBuffer (CommBufferVirtual, CommSize); } +/** + Communicates with a registered handler. + + This function provides a service to send and receive messages from a registered UEFI service. + + @param[in] This The EFI_MM_COMMUNICATION_PROTOCOL instance. + @param[in, out] CommBuffer Pointer to the MM communication buffer + @param[in, out] CommSize The size of the data buffer being passed in. On exit, the size of data + being returned. Zero if the handler does not wish to reply with any data. + This parameter is optional and may be NULL. + + @retval EFI_SUCCESS The message was successfully posted. + @retval EFI_INVALID_PARAMETER The CommBuffer was NULL. + @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM implementation. + If this error is returned, the MessageLength field + in the CommBuffer header or the integer pointed by + CommSize, are updated to reflect the maximum payload + size the implementation can accommodate. + @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter or CommSize parameter, + if not omitted, are in address range that cannot be + accessed by the MM environment. + +**/ +EFI_STATUS +EFIAPI +MmCommunicate ( + IN CONST EFI_MM_COMMUNICATION_PROTOCOL *This, + IN OUT VOID *CommBuffer, + IN OUT UINTN *CommSize OPTIONAL + ) +{ + return ProcessCommunicationBuffer (CommBuffer, CommSize); +} + /** The Entry Point for MmCommunicateDxe driver. @@ -209,6 +250,14 @@ MmCommunicationEntryPoint ( ); ASSERT_EFI_ERROR (Status); + Status = gBS->InstallProtocolInterface ( + &Handle, + &gEfiMmCommunicationProtocolGuid, + EFI_NATIVE_INTERFACE, + &mMmCommunication + ); + ASSERT_EFI_ERROR (Status); + // // Register the event to convert the pointer for runtime. // diff --git a/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.h b/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.h index 90cab5e64f..603cc7691c 100644 --- a/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.h +++ b/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.h @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -59,4 +60,35 @@ MmCommunicate2 ( IN OUT UINTN *CommSize OPTIONAL ); +/** + Communicates with a registered handler. + + This function provides a service to send and receive messages from a registered UEFI service. + + @param[in] This The EFI_MM_COMMUNICATION_PROTOCOL instance. + @param[in, out] CommBufferPhysical Physical address of the MM communication buffer + @param[in, out] CommSize The size of the data buffer being passed in. On exit, the size of data + being returned. Zero if the handler does not wish to reply with any data. + This parameter is optional and may be NULL. + + @retval EFI_SUCCESS The message was successfully posted. + @retval EFI_INVALID_PARAMETER The CommBuffer was NULL. + @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM implementation. + If this error is returned, the MessageLength field + in the CommBuffer header or the integer pointed by + CommSize, are updated to reflect the maximum payload + size the implementation can accommodate. + @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter or CommSize parameter, + if not omitted, are in address range that cannot be + accessed by the MM environment. + +**/ +EFI_STATUS +EFIAPI +MmCommunicate ( + IN CONST EFI_MM_COMMUNICATION_PROTOCOL *This, + IN OUT VOID *CommBufferPhysical, + IN OUT UINTN *CommSize OPTIONAL + ); + #endif diff --git a/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.inf b/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.inf index 55c6611258..c46a3ba8bb 100644 --- a/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.inf +++ b/StandaloneMmPkg/Drivers/MmCommunicationDxe/MmCommunicationDxe.inf @@ -45,6 +45,7 @@ [Protocols] gEfiMmCommunication2ProtocolGuid gEfiSmmControl2ProtocolGuid + gEfiMmCommunicationProtocolGuid [Depex] gEfiSmmControl2ProtocolGuid -- cgit v1.2.3