From nobody Tue Feb 10 15:29:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105955+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105955+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1686257080; cv=none; d=zohomail.com; s=zohoarc; b=mBu5KIqpV9j4KLD+PS4S3tK8iSNWV8FOBoEP30z6tcgG6FF0D04BMJgxNAQvQYyl/Gk34uTHnOAQWxTtFxhKhNYpQoziO8AFefBtC58UeFEFvvt7Sx2bERCRbwNdJ2z2PCyu9JaXawc3BAVpqg7ST3fdcXwiFdllGFjw3MgY8mQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686257080; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=gvn7AfxzskA4+E16wDf4M9sMuuJz5YSRHK3Q+9RQQLM=; b=mkJUH8o1CTZbK1EF/D+Oa2kZuICkiTJD7/UE+1KIkupbQSldP2L/sTBdj1oNBMIwmy2fXok4+cjAxBj2SGObJ1yQjRJNKZXyq/1Y3jl4x6yBL7swmD/h3thtDqlmSj3qCf2oPiahesDF9V430jFkHt2NntpDon3N9BkQARVUzBg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105955+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1686257080867219.3370673623607; Thu, 8 Jun 2023 13:44:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id CWhdYY1788612xox9cwl0eQI; Thu, 08 Jun 2023 13:44:40 -0700 X-Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by mx.groups.io with SMTP id smtpd.web10.5113.1686257080058899159 for ; Thu, 08 Jun 2023 13:44:40 -0700 X-Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-652699e72f7so880539b3a.3 for ; Thu, 08 Jun 2023 13:44:40 -0700 (PDT) X-Gm-Message-State: 78aefBIMAILZ8B6iKD8EIqRNx1787277AA= X-Google-Smtp-Source: ACHHUZ4cI5DRm51ycCB0ehCJFESE5a+qQ2Mlo/RdEY/Htntf4jZxc4tQZgqwRXkXv1juCJ9V0/oJ5g== X-Received: by 2002:a05:6a00:1948:b0:63b:5c82:e209 with SMTP id s8-20020a056a00194800b0063b5c82e209mr7103198pfk.10.1686257079011; Thu, 08 Jun 2023 13:44:39 -0700 (PDT) X-Received: from MININT-0U7P5GU.redmond.corp.microsoft.com ([2001:4898:80e8:2:fc6a:9362:be2c:efe5]) by smtp.gmail.com with ESMTPSA id k15-20020aa7820f000000b0065e279c5c2csm1450767pfi.181.2023.06.08.13.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 13:44:38 -0700 (PDT) From: "Kun Qin" To: devel@edk2.groups.io Cc: Leif Lindholm , Ard Biesheuvel , Sami Mujawar , Ronny Hansen , Shriram Masanamuthu Chinnathurai , Preshit Harlikar Subject: [edk2-devel] [PATCH v1 1/2] ArmPkg: MmCommunicationPei: Introduce MM communicate in PEI Date: Thu, 8 Jun 2023 13:44:33 -0700 Message-Id: <20230608204434.2325-2-kuqin12@gmail.com> In-Reply-To: <20230608204434.2325-1-kuqin12@gmail.com> References: <20230608204434.2325-1-kuqin12@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kuqin12@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1686257080; bh=EJcfdeSkYVzVTaxAkbgcfViNe/byv6P4wZmklL135w8=; h=Cc:Date:From:Reply-To:Subject:To; b=kx0V2Oz2R7UsQPO8+9HAj5TxG+lCHIHZcFwfcgbvhKtDUvySl6mIN5yX+2qoyrEDRzz rwfgGyCuOzDzeapOP76jCGUVWkMf/LD0PEJh6P5K98IE3W8rRRXEeLn1/xaB1gHLX5Dh5 PYeheuv6/9IVrLsaAjPcycGbINm4qQEt2iA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1686257081588100004 Content-Type: text/plain; charset="utf-8" From: Kun Qin REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4464 This change introduced the MM communicate support in PEI phase for ARM based platforms. Similar to the DXE counterpart, `PcdMmBufferBase` is used as communicate buffer and SMC will be invoked to communicate to TrustZone when MMI is requested. Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Sami Mujawar Co-authored-by: Ronny Hansen Co-authored-by: Shriram Masanamuthu Chinnathurai Co-authored-by: Preshit Harlikar Signed-off-by: Kun Qin --- ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c | 178 +++++++++++= +++++++++ ArmPkg/ArmPkg.dsc | 2 + ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.h | 76 +++++++++ ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.inf | 41 +++++ 4 files changed, 297 insertions(+) diff --git a/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c b/ArmPk= g/Drivers/MmCommunicationPei/MmCommunicationPei.c new file mode 100644 index 000000000000..0f1f763a347d --- /dev/null +++ b/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.c @@ -0,0 +1,178 @@ +/** @file -- MmCommunicationPei.c + Provides an interface to send MM request in PEI + + Copyright (c) 2016-2021, Arm Limited. All rights reserved.
+ Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "MmCommunicationPei.h" + +// +// Module globals +// +EFI_PEI_MM_COMMUNICATION_PPI mPeiMmCommunication =3D { + MmCommunicationPeim +}; + +EFI_PEI_PPI_DESCRIPTOR mPeiMmCommunicationPpi =3D { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gEfiPeiMmCommunicationPpiGuid, + &mPeiMmCommunication +}; + +/** + Entry point of PEI MM Communication driver + + @param FileHandle Handle of the file being invoked. + Type EFI_PEI_FILE_HANDLE is defined in FfsFindNextF= ile(). + @param PeiServices General purpose services available to every PEIM. + + @retval EFI_SUCCESS If the interface could be successfully installed + @retval Others Returned from PeiServicesInstallPpi() +**/ +EFI_STATUS +EFIAPI +MmCommunicationPeiInitialize ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + return PeiServicesInstallPpi (&mPeiMmCommunicationPpi); +} + +/** + MmCommunicationPeim + Communicates with a registered handler. + This function provides a service to send and receive messages from a reg= istered UEFI service during PEI. + + @param[in] This The EFI_PEI_MM_COMMUNICATION_PPI instanc= e. + @param[in, out] CommBuffer Pointer to the data 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. + + @retval EFI_SUCCESS The message was successfully posted. + @retval EFI_INVALID_PARAMETER CommBuffer was NULL or *CommSize does no= t match + MessageLength + sizeof (EFI_MM_COMMUNICA= TE_HEADER). + @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM imple= mentation. + If this error is returned, the MessageLe= ngth field + in the CommBuffer header or the integer = pointed by + CommSize, are updated to reflect the max= imum payload + size the implementation can accommodate. + @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter or CommS= ize parameter, + if not omitted, are in address range tha= t cannot be + accessed by the MM environment. +**/ +EFI_STATUS +EFIAPI +MmCommunicationPeim ( + IN CONST EFI_PEI_MM_COMMUNICATION_PPI *This, + IN OUT VOID *CommBuffer, + IN OUT UINTN *CommSize + ) +{ + EFI_MM_COMMUNICATE_HEADER *CommunicateHeader; + ARM_SMC_ARGS CommunicateSmcArgs; + EFI_STATUS Status; + UINTN BufferSize; + + Status =3D EFI_ACCESS_DENIED; + BufferSize =3D 0; + + ZeroMem (&CommunicateSmcArgs, sizeof (ARM_SMC_ARGS)); + + // Check that our static buffer is looking good. + // We are using PcdMmBufferBase to transfer variable data. + // We are not using the full size of the buffer since there is a cost + // of copying data between Normal and Secure World. + ASSERT (PcdGet64 (PcdMmBufferSize) > 0 && PcdGet64 (PcdMmBufferBase) != =3D 0); + + // + // Check parameters + // + if (CommBuffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // If the length of the CommBuffer is 0 then return the expected length. + // This case can be used by the consumer of this driver to find out the + // max size that can be used for allocating CommBuffer. + if ((CommSize !=3D NULL) && \ + ((*CommSize =3D=3D 0) || (*CommSize > (UINTN)PcdGet64 (PcdMmBufferSi= ze)))) + { + *CommSize =3D (UINTN)PcdGet64 (PcdMmBufferSize); + return EFI_BAD_BUFFER_SIZE; + } + + CommunicateHeader =3D (EFI_MM_COMMUNICATE_HEADER *)(UINTN)(PcdGet64 (Pcd= MmBufferBase)); + + CopyMem ((VOID *)CommunicateHeader, CommBuffer, *CommSize); + + // CommBuffer is a mandatory parameter. Hence, Rely on + // MessageLength + Header to ascertain the + // total size of the communication payload rather than + // rely on optional CommSize parameter + BufferSize =3D CommunicateHeader->MessageLength + + sizeof (CommunicateHeader->HeaderGuid) + + sizeof (CommunicateHeader->MessageLength); + + // + // If CommSize is supplied it must match MessageLength + sizeof (EFI_MM_= COMMUNICATE_HEADER); + // + if ((CommSize !=3D NULL) && (*CommSize !=3D BufferSize)) { + return EFI_INVALID_PARAMETER; + } + + // SMC Function ID + CommunicateSmcArgs.Arg0 =3D ARM_SMC_ID_MM_COMMUNICATE_AARCH64; + + // Cookie + CommunicateSmcArgs.Arg1 =3D 0; + + // comm_buffer_address (64-bit physical address) + CommunicateSmcArgs.Arg2 =3D (UINTN)CommunicateHeader; + + // comm_size_address (not used, indicated by setting to zero) + CommunicateSmcArgs.Arg3 =3D 0; + + // Call the Standalone MM environment. + ArmCallSmc (&CommunicateSmcArgs); + + switch (CommunicateSmcArgs.Arg0) { + case ARM_SMC_MM_RET_SUCCESS: + // On successful return, the size of data being returned is inferred= from + // MessageLength + Header. + BufferSize =3D CommunicateHeader->MessageLength + + sizeof (CommunicateHeader->HeaderGuid) + + sizeof (CommunicateHeader->MessageLength); + CopyMem (CommBuffer, (VOID *)CommunicateHeader, BufferSize); + if (CommSize !=3D NULL) { + *CommSize =3D BufferSize; + } + + Status =3D EFI_SUCCESS; + break; + + case ARM_SMC_MM_RET_INVALID_PARAMS: + Status =3D EFI_INVALID_PARAMETER; + break; + + case ARM_SMC_MM_RET_DENIED: + Status =3D EFI_ACCESS_DENIED; + break; + + case ARM_SMC_MM_RET_NO_MEMORY: + // Unexpected error since the CommSize was checked for zero length + // prior to issuing the SMC + Status =3D EFI_OUT_OF_RESOURCES; + ASSERT (0); + break; + + default: + Status =3D EFI_ACCESS_DENIED; + ASSERT (0); + } + + return Status; +} diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 6b938ce8b671..4939b3d59b7f 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -162,6 +162,8 @@ [Components.common] ArmPkg/Universal/Smbios/SmbiosMiscDxe/SmbiosMiscDxe.inf ArmPkg/Universal/Smbios/OemMiscLibNull/OemMiscLibNull.inf =20 + ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.inf + [Components.AARCH64] ArmPkg/Drivers/ArmPsciMpServicesDxe/ArmPsciMpServicesDxe.inf ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf diff --git a/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.h b/ArmPk= g/Drivers/MmCommunicationPei/MmCommunicationPei.h new file mode 100644 index 000000000000..a99baa2496a9 --- /dev/null +++ b/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.h @@ -0,0 +1,76 @@ +/** @file -- MmCommunicationPei.h + Provides an interface to send MM request in PEI + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MM_COMMUNICATION_PEI_H_ +#define MM_COMMUNICATION_PEI_H_ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include + +/** + Entry point of PEI MM Communication driver + + @param FileHandle Handle of the file being invoked. + Type EFI_PEI_FILE_HANDLE is defined in FfsFindNextF= ile(). + @param PeiServices General purpose services available to every PEIM. + + @retval EFI_SUCCESS If the interface could be successfully installed + @retval Others Returned from PeiServicesInstallPpi() +**/ +EFI_STATUS +EFIAPI +MmCommunicationPeiInitialize ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ); + +/** + MmCommunicationPeim + Communicates with a registered handler. + This function provides a service to send and receive messages from a reg= istered UEFI service during PEI. + + @param[in] This The EFI_PEI_MM_COMMUNICATION_PPI instanc= e. + @param[in, out] CommBuffer Pointer to the data 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. + + @retval EFI_SUCCESS The message was successfully posted. + @retval EFI_INVALID_PARAMETER CommBuffer was NULL or *CommSize does no= t match + MessageLength + sizeof (EFI_MM_COMMUNICA= TE_HEADER). + @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM imple= mentation. + If this error is returned, the MessageLe= ngth field + in the CommBuffer header or the integer = pointed by + CommSize, are updated to reflect the max= imum payload + size the implementation can accommodate. + @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter or CommS= ize parameter, + if not omitted, are in address range tha= t cannot be + accessed by the MM environment. +**/ +EFI_STATUS +EFIAPI +MmCommunicationPeim ( + IN CONST EFI_PEI_MM_COMMUNICATION_PPI *This, + IN OUT VOID *CommBuffer, + IN OUT UINTN *CommSize + ); + +#endif /* MM_COMMUNICATION_PEI_H_ */ diff --git a/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.inf b/Arm= Pkg/Drivers/MmCommunicationPei/MmCommunicationPei.inf new file mode 100644 index 000000000000..f4e359dafd75 --- /dev/null +++ b/ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.inf @@ -0,0 +1,41 @@ +## @file -- MmCommunicationPei.inf +# PEI MM Communicate driver +# +# Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.
+# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D MmCommunicationPei + FILE_GUID =3D 58FFB346-1B75-42C7-AD69-37C652423C1A + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D MmCommunicationPeiInitialize + +[Sources] + MmCommunicationPei.c + MmCommunicationPei.h + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ArmPkg/ArmPkg.dec + +[LibraryClasses] + DebugLib + ArmSmcLib + PeimEntryPoint + PeiServicesLib + HobLib + +[Pcd] + gArmTokenSpaceGuid.PcdMmBufferBase + gArmTokenSpaceGuid.PcdMmBufferSize + +[Ppis] + gEfiPeiMmCommunicationPpiGuid ## PRODUCES + +[Depex] + TRUE --=20 2.40.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105955): https://edk2.groups.io/g/devel/message/105955 Mute This Topic: https://groups.io/mt/99415825/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-