From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@gmail.com header.s=20221208 header.b=XehzCWBA; spf=pass (domain: gmail.com, ip: 209.85.210.178, mailfrom: kuqin12@gmail.com) Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-652699e72f7so880539b3a.3 for ; Thu, 08 Jun 2023 13:44:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686257079; x=1688849079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K5mla/VKnNMsNf9uvbJZtvOj9KxlUC+ok+Nk/DmWwLE=; b=XehzCWBA5LRRVkeA7dVDDTYz1785WkljCR/xJmrHfuj2ym81IY3iMMow1jtVVCtEvr OYwf5/BjmAIoWDDr8HQ+Dyo+gJFLqkl7l7PXudyPdfHKvhCRkyzh4sdQjdicL8/eRPpb qqUI1etOinjXLA415ykKvQKTz4gw4DWVmxSIS/C+ZyrGRLk5yNGb4Vv85ztlyM/HjHtT DgwluEe9HLy8aL3gl1mg5jlgP/V0saPuKnipthV/YQsQW/evC/b8Ws1f7HN1fCUJKl8o Y4uIYJJePVcowv5pSZiCnBoQf6SI3RhhjR0QMeegOvf8WTnY9wnQBcR2y+9NZ57D2mGz EN/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686257079; x=1688849079; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K5mla/VKnNMsNf9uvbJZtvOj9KxlUC+ok+Nk/DmWwLE=; b=gtXfXRlBjxmucpPntT5O2wfoIYAVxnTnFXi7NFPRPmU1LUQpGtwI1ojWl4V2PCK7Ca MgBainBZUa2M7QCbvrJogM1QzHd4n9vAztxm1wa7DV06sVnuh4v7kQS0di6yIChmYcqv +d+poScZSKfr4PwU10WtLDcw9oaOYCsFtcuekobZwSw2+Byv94beZVmdfqoBFaMMLoJI ewiWry9H0Tw8QKxyxXwifW1lamSOdeyTahfOXAvJ5fLLF+ERHf0DICR/Vk0wQkQvFbTo KtSbx4IpdEfDNRURXn0gTlwe53xs9DEnbNCm1Ne+PsdkVXI2Jjm+fL58cok9s1tAGLLb pWqg== X-Gm-Message-State: AC+VfDzukMpcVNw9ha0vueQcSDTXC/GxPw3yPEMCGaFwQxaILgbAmst5 84GJ4SbQKj2WlcQ5B9K5HfSU/NKKXwc= 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.40.1.windows.1 In-Reply-To: <20230608204434.2325-1-kuqin12@gmail.com> References: <20230608204434.2325-1-kuqin12@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=0D + Provides an interface to send MM request in PEI=0D +=0D + Copyright (c) 2016-2021, Arm Limited. All rights reserved.
=0D + Copyright (c) Microsoft Corporation.=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#include "MmCommunicationPei.h"=0D +=0D +//=0D +// Module globals=0D +//=0D +EFI_PEI_MM_COMMUNICATION_PPI mPeiMmCommunication =3D {=0D + MmCommunicationPeim=0D +};=0D +=0D +EFI_PEI_PPI_DESCRIPTOR mPeiMmCommunicationPpi =3D {=0D + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),=0D + &gEfiPeiMmCommunicationPpiGuid,=0D + &mPeiMmCommunication=0D +};=0D +=0D +/**=0D + Entry point of PEI MM Communication driver=0D +=0D + @param FileHandle Handle of the file being invoked.=0D + Type EFI_PEI_FILE_HANDLE is defined in FfsFindNextF= ile().=0D + @param PeiServices General purpose services available to every PEIM.=0D +=0D + @retval EFI_SUCCESS If the interface could be successfully installed=0D + @retval Others Returned from PeiServicesInstallPpi()=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +MmCommunicationPeiInitialize (=0D + IN EFI_PEI_FILE_HANDLE FileHandle,=0D + IN CONST EFI_PEI_SERVICES **PeiServices=0D + )=0D +{=0D + return PeiServicesInstallPpi (&mPeiMmCommunicationPpi);=0D +}=0D +=0D +/**=0D + MmCommunicationPeim=0D + Communicates with a registered handler.=0D + This function provides a service to send and receive messages from a reg= istered UEFI service during PEI.=0D +=0D + @param[in] This The EFI_PEI_MM_COMMUNICATION_PPI instanc= e.=0D + @param[in, out] CommBuffer Pointer to the data buffer=0D + @param[in, out] CommSize The size of the data buffer being passed= in. On exit, the=0D + size of data being returned. Zero if the= handler does not=0D + wish to reply with any data.=0D +=0D + @retval EFI_SUCCESS The message was successfully posted.=0D + @retval EFI_INVALID_PARAMETER CommBuffer was NULL or *CommSize does no= t match=0D + MessageLength + sizeof (EFI_MM_COMMUNICA= TE_HEADER).=0D + @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM imple= mentation.=0D + If this error is returned, the MessageLe= ngth field=0D + in the CommBuffer header or the integer = pointed by=0D + CommSize, are updated to reflect the max= imum payload=0D + size the implementation can accommodate.= =0D + @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter or CommS= ize parameter,=0D + if not omitted, are in address range tha= t cannot be=0D + accessed by the MM environment.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +MmCommunicationPeim (=0D + IN CONST EFI_PEI_MM_COMMUNICATION_PPI *This,=0D + IN OUT VOID *CommBuffer,=0D + IN OUT UINTN *CommSize=0D + )=0D +{=0D + EFI_MM_COMMUNICATE_HEADER *CommunicateHeader;=0D + ARM_SMC_ARGS CommunicateSmcArgs;=0D + EFI_STATUS Status;=0D + UINTN BufferSize;=0D +=0D + Status =3D EFI_ACCESS_DENIED;=0D + BufferSize =3D 0;=0D +=0D + ZeroMem (&CommunicateSmcArgs, sizeof (ARM_SMC_ARGS));=0D +=0D + // Check that our static buffer is looking good.=0D + // We are using PcdMmBufferBase to transfer variable data.=0D + // We are not using the full size of the buffer since there is a cost=0D + // of copying data between Normal and Secure World.=0D + ASSERT (PcdGet64 (PcdMmBufferSize) > 0 && PcdGet64 (PcdMmBufferBase) != =3D 0);=0D +=0D + //=0D + // Check parameters=0D + //=0D + if (CommBuffer =3D=3D NULL) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + // If the length of the CommBuffer is 0 then return the expected length.= =0D + // This case can be used by the consumer of this driver to find out the= =0D + // max size that can be used for allocating CommBuffer.=0D + if ((CommSize !=3D NULL) && \=0D + ((*CommSize =3D=3D 0) || (*CommSize > (UINTN)PcdGet64 (PcdMmBufferSi= ze))))=0D + {=0D + *CommSize =3D (UINTN)PcdGet64 (PcdMmBufferSize);=0D + return EFI_BAD_BUFFER_SIZE;=0D + }=0D +=0D + CommunicateHeader =3D (EFI_MM_COMMUNICATE_HEADER *)(UINTN)(PcdGet64 (Pcd= MmBufferBase));=0D +=0D + CopyMem ((VOID *)CommunicateHeader, CommBuffer, *CommSize);=0D +=0D + // CommBuffer is a mandatory parameter. Hence, Rely on=0D + // MessageLength + Header to ascertain the=0D + // total size of the communication payload rather than=0D + // rely on optional CommSize parameter=0D + BufferSize =3D CommunicateHeader->MessageLength +=0D + sizeof (CommunicateHeader->HeaderGuid) +=0D + sizeof (CommunicateHeader->MessageLength);=0D +=0D + //=0D + // If CommSize is supplied it must match MessageLength + sizeof (EFI_MM_= COMMUNICATE_HEADER);=0D + //=0D + if ((CommSize !=3D NULL) && (*CommSize !=3D BufferSize)) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + // SMC Function ID=0D + CommunicateSmcArgs.Arg0 =3D ARM_SMC_ID_MM_COMMUNICATE_AARCH64;=0D +=0D + // Cookie=0D + CommunicateSmcArgs.Arg1 =3D 0;=0D +=0D + // comm_buffer_address (64-bit physical address)=0D + CommunicateSmcArgs.Arg2 =3D (UINTN)CommunicateHeader;=0D +=0D + // comm_size_address (not used, indicated by setting to zero)=0D + CommunicateSmcArgs.Arg3 =3D 0;=0D +=0D + // Call the Standalone MM environment.=0D + ArmCallSmc (&CommunicateSmcArgs);=0D +=0D + switch (CommunicateSmcArgs.Arg0) {=0D + case ARM_SMC_MM_RET_SUCCESS:=0D + // On successful return, the size of data being returned is inferred= from=0D + // MessageLength + Header.=0D + BufferSize =3D CommunicateHeader->MessageLength +=0D + sizeof (CommunicateHeader->HeaderGuid) +=0D + sizeof (CommunicateHeader->MessageLength);=0D + CopyMem (CommBuffer, (VOID *)CommunicateHeader, BufferSize);=0D + if (CommSize !=3D NULL) {=0D + *CommSize =3D BufferSize;=0D + }=0D +=0D + Status =3D EFI_SUCCESS;=0D + break;=0D +=0D + case ARM_SMC_MM_RET_INVALID_PARAMS:=0D + Status =3D EFI_INVALID_PARAMETER;=0D + break;=0D +=0D + case ARM_SMC_MM_RET_DENIED:=0D + Status =3D EFI_ACCESS_DENIED;=0D + break;=0D +=0D + case ARM_SMC_MM_RET_NO_MEMORY:=0D + // Unexpected error since the CommSize was checked for zero length=0D + // prior to issuing the SMC=0D + Status =3D EFI_OUT_OF_RESOURCES;=0D + ASSERT (0);=0D + break;=0D +=0D + default:=0D + Status =3D EFI_ACCESS_DENIED;=0D + ASSERT (0);=0D + }=0D +=0D + return Status;=0D +}=0D 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=0D ArmPkg/Universal/Smbios/OemMiscLibNull/OemMiscLibNull.inf=0D =0D + ArmPkg/Drivers/MmCommunicationPei/MmCommunicationPei.inf=0D +=0D [Components.AARCH64]=0D ArmPkg/Drivers/ArmPsciMpServicesDxe/ArmPsciMpServicesDxe.inf=0D ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf=0D 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=0D + Provides an interface to send MM request in PEI=0D +=0D + Copyright (c) Microsoft Corporation.=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#ifndef MM_COMMUNICATION_PEI_H_=0D +#define MM_COMMUNICATION_PEI_H_=0D +=0D +#include =0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +#include =0D +=0D +#include =0D +=0D +#include =0D +=0D +/**=0D + Entry point of PEI MM Communication driver=0D +=0D + @param FileHandle Handle of the file being invoked.=0D + Type EFI_PEI_FILE_HANDLE is defined in FfsFindNextF= ile().=0D + @param PeiServices General purpose services available to every PEIM.=0D +=0D + @retval EFI_SUCCESS If the interface could be successfully installed=0D + @retval Others Returned from PeiServicesInstallPpi()=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +MmCommunicationPeiInitialize (=0D + IN EFI_PEI_FILE_HANDLE FileHandle,=0D + IN CONST EFI_PEI_SERVICES **PeiServices=0D + );=0D +=0D +/**=0D + MmCommunicationPeim=0D + Communicates with a registered handler.=0D + This function provides a service to send and receive messages from a reg= istered UEFI service during PEI.=0D +=0D + @param[in] This The EFI_PEI_MM_COMMUNICATION_PPI instanc= e.=0D + @param[in, out] CommBuffer Pointer to the data buffer=0D + @param[in, out] CommSize The size of the data buffer being passed= in. On exit, the=0D + size of data being returned. Zero if the= handler does not=0D + wish to reply with any data.=0D +=0D + @retval EFI_SUCCESS The message was successfully posted.=0D + @retval EFI_INVALID_PARAMETER CommBuffer was NULL or *CommSize does no= t match=0D + MessageLength + sizeof (EFI_MM_COMMUNICA= TE_HEADER).=0D + @retval EFI_BAD_BUFFER_SIZE The buffer is too large for the MM imple= mentation.=0D + If this error is returned, the MessageLe= ngth field=0D + in the CommBuffer header or the integer = pointed by=0D + CommSize, are updated to reflect the max= imum payload=0D + size the implementation can accommodate.= =0D + @retval EFI_ACCESS_DENIED The CommunicateBuffer parameter or CommS= ize parameter,=0D + if not omitted, are in address range tha= t cannot be=0D + accessed by the MM environment.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +MmCommunicationPeim (=0D + IN CONST EFI_PEI_MM_COMMUNICATION_PPI *This,=0D + IN OUT VOID *CommBuffer,=0D + IN OUT UINTN *CommSize=0D + );=0D +=0D +#endif /* MM_COMMUNICATION_PEI_H_ */=0D 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=0D +# PEI MM Communicate driver=0D +#=0D +# Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.
=0D +# Copyright (c) Microsoft Corporation.=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D MmCommunicationPei=0D + FILE_GUID =3D 58FFB346-1B75-42C7-AD69-37C652423C1A= =0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D + ENTRY_POINT =3D MmCommunicationPeiInitialize=0D +=0D +[Sources]=0D + MmCommunicationPei.c=0D + MmCommunicationPei.h=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + ArmPkg/ArmPkg.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + ArmSmcLib=0D + PeimEntryPoint=0D + PeiServicesLib=0D + HobLib=0D +=0D +[Pcd]=0D + gArmTokenSpaceGuid.PcdMmBufferBase=0D + gArmTokenSpaceGuid.PcdMmBufferSize=0D +=0D +[Ppis]=0D + gEfiPeiMmCommunicationPpiGuid ## PRODUCES=0D +=0D +[Depex]=0D + TRUE=0D --=20 2.40.1.windows.1