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.web08.3719.1623821659244088040 for ; Tue, 15 Jun 2021 22:34:19 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: sayanta.pattanayak@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 BD40012FC; Tue, 15 Jun 2021 22:34:17 -0700 (PDT) Received: from usa.arm.com (a077432.blr.arm.com [10.162.4.31]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 907233F719; Tue, 15 Jun 2021 22:34:16 -0700 (PDT) From: "Sayanta Pattanayak" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Sami Mujawar Subject: [edk2][PATCH V1 1/1] ArmPkg: introduce FF-A interface support in MM_COMMUNICATE Date: Wed, 16 Jun 2021 11:04:03 +0530 Message-Id: <20210616053403.30312-1-sayanta.pattanayak@arm.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Aditya Angadi With the introduction of Firmware Framework for Arm platforms (FF-A), normal world and secure world endpoints can use FF-A interface for communication with each other. In this patch, FFA_MSG_SEND_DIRECT_REQ and FFA_VERSION interfaces are introduced. This change adds an option to either use the existing SMC interface or the introduced FF-A interface based on the value of PcdFfaEnable. Signed-off-by: Aditya Angadi Signed-off-by: Sayanta Pattanayak --- ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf | 3 + ArmPkg/Include/IndustryStandard/ArmFfaSvc.h | 2 + ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c | 73 +++++++++++++= +++---- 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf b/ArmP= kg/Drivers/MmCommunicationDxe/MmCommunication.inf index 05b6de73ff34..da8462755a6f 100644 --- a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf +++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf @@ -52,5 +52,8 @@ gArmTokenSpaceGuid.PcdMmBufferBase gArmTokenSpaceGuid.PcdMmBufferSize =20 +[FeaturePcd.AARCH64] + gArmTokenSpaceGuid.PcdFfaEnable + [Depex] gEfiCpuArchProtocolGuid diff --git a/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h b/ArmPkg/Include= /IndustryStandard/ArmFfaSvc.h index 65b8343ade61..5a300a7295db 100644 --- a/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h +++ b/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h @@ -19,6 +19,8 @@ #define ARM_SVC_ID_FFA_VERSION_AARCH32 0x84000063 #define ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ_AARCH64 0xC400006F #define ARM_SVC_ID_FFA_MSG_SEND_DIRECT_RESP_AARCH64 0xC4000070 +#define ARM_SVC_ID_FFA_SUCCESS_AARCH64 0xC4000061 +#define ARM_SVC_ID_FFA_SUCCESS_AARCH32 0x84000060 =20 #define SPM_MAJOR_VERSION_FFA 1 #define SPM_MINOR_VERSION_FFA 0 diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c b/ArmPkg= /Drivers/MmCommunicationDxe/MmCommunication.c index b1e309580988..ff15903473ad 100644 --- a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c +++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c @@ -18,6 +18,7 @@ =20 #include =20 +#include #include =20 #include "MmCommunicate.h" @@ -73,6 +74,7 @@ MmCommunication2Communicate ( ARM_SMC_ARGS CommunicateSmcArgs; EFI_STATUS Status; UINTN BufferSize; + UINTN Ret; =20 Status =3D EFI_ACCESS_DENIED; BufferSize =3D 0; @@ -124,26 +126,55 @@ MmCommunication2Communicate ( return EFI_BAD_BUFFER_SIZE; } =20 - // SMC Function ID - CommunicateSmcArgs.Arg0 =3D ARM_SMC_ID_MM_COMMUNICATE_AARCH64; - - // Cookie - CommunicateSmcArgs.Arg1 =3D 0; - // Copy Communication Payload CopyMem ((VOID *)mNsCommBuffMemRegion.VirtualBase, CommBufferVirtual, = BufferSize); =20 - // comm_buffer_address (64-bit physical address) - CommunicateSmcArgs.Arg2 =3D (UINTN)mNsCommBuffMemRegion.PhysicalBase; + // Use the FF-A interface if enabled. + if (FeaturePcdGet (PcdFfaEnable)) { + // FF-A Interface ID for direct message communication + CommunicateSmcArgs.Arg0 =3D ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ_AARCH= 64; =20 - // comm_size_address (not used, indicated by setting to zero) - CommunicateSmcArgs.Arg3 =3D 0; + // FF-A Destination EndPoint ID, not used as of now + CommunicateSmcArgs.Arg1 =3D 0x0; + + // Reserved for future use(MBZ) + CommunicateSmcArgs.Arg2 =3D 0x0; + + // Arg3 onwards are the IMPLEMENTATION DEFINED FF-A parameters + // SMC Function ID + CommunicateSmcArgs.Arg3 =3D ARM_SMC_ID_MM_COMMUNICATE_AARCH64; + + // Cookie + CommunicateSmcArgs.Arg4 =3D 0x0; + + // comm_buffer_address (64-bit physical address) + CommunicateSmcArgs.Arg5 =3D (UINTN)mNsCommBuffMemRegion.PhysicalBase= ; + + // comm_size_address (not used, indicated by setting to zero) + CommunicateSmcArgs.Arg6 =3D 0; + } else { + // 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)mNsCommBuffMemRegion.PhysicalBase= ; + + // comm_size_address (not used, indicated by setting to zero) + CommunicateSmcArgs.Arg3 =3D 0; + } =20 // Call the Standalone MM environment. ArmCallSmc (&CommunicateSmcArgs); =20 - switch (CommunicateSmcArgs.Arg0) { - case ARM_SMC_MM_RET_SUCCESS: + Ret =3D CommunicateSmcArgs.Arg0; + + if ((FeaturePcdGet (PcdFfaEnable) && + (Ret =3D=3D ARM_SVC_ID_FFA_SUCCESS_AARCH64)) || + (Ret =3D=3D ARM_SMC_MM_RET_SUCCESS)) + { ZeroMem (CommBufferVirtual, BufferSize); // On successful return, the size of data being returned is inferred= from // MessageLength + Header. @@ -158,8 +189,14 @@ MmCommunication2Communicate ( BufferSize ); Status =3D EFI_SUCCESS; - break; + return Status; + } =20 + if (FeaturePcdGet (PcdFfaEnable)) + Ret =3D CommunicateSmcArgs.Arg2; + + // Error Codes are same for FF-A and SMC interface + switch (Ret) { case ARM_SMC_MM_RET_INVALID_PARAMS: Status =3D EFI_INVALID_PARAMETER; break; @@ -233,8 +270,14 @@ GetMmCompatibility () UINT32 MmVersion; ARM_SMC_ARGS MmVersionArgs; =20 - // MM_VERSION uses SMC32 calling conventions - MmVersionArgs.Arg0 =3D ARM_SMC_ID_MM_VERSION_AARCH32; + if (FeaturePcdGet (PcdFfaEnable)) { + MmVersionArgs.Arg0 =3D ARM_SVC_ID_FFA_VERSION_AARCH32; + MmVersionArgs.Arg1 =3D MM_CALLER_MAJOR_VER << MM_MAJOR_VER_SHIFT; + MmVersionArgs.Arg1 |=3D MM_CALLER_MINOR_VER; + } else { + // MM_VERSION uses SMC32 calling conventions + MmVersionArgs.Arg0 =3D ARM_SMC_ID_MM_VERSION_AARCH32; + } =20 ArmCallSmc (&MmVersionArgs); =20 --=20 2.17.1