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.web11.1233.1689086243199488614 for ; Tue, 11 Jul 2023 07:37:23 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: nishant.sharma@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 178631FB; Tue, 11 Jul 2023 07:38:05 -0700 (PDT) Received: from usa.arm.com (iss-desktop02.cambridge.arm.com [10.1.196.79]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EE2773F740; Tue, 11 Jul 2023 07:37:21 -0700 (PDT) From: "Nishant Sharma" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Sami Mujawar , Thomas Abraham , Sayanta Pattanayak , Achin Gupta Subject: [edk2-platforms][PATCH V1 08/20] StandaloneMmPkg: Add backwards compatible support to detect FF-A v1.1 Date: Tue, 11 Jul 2023 15:36:46 +0100 Message-Id: <20230711143658.781597-9-nishant.sharma@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230711143658.781597-1-nishant.sharma@arm.com> References: <20230711143658.781597-1-nishant.sharma@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Achin Gupta For better or worse, an StMM SP can communicate with the SPM through one of these interfaces. 1. SPM_MM interface 2. FF-A v1.0 interface 3. FF-A v1.1 interface 2) implements only minimal FF-A support. It reuses the initialisation ABI defined by 1) and wraps the remaining communicaton in FFA_MSG_SEND_DIRECT_REQ/RESP ABIs. 3) uses FF-A ABIs from the spec for both initialisation and communication= . Detecting these variations in the GetSpmVersion() function is tedious. Th= is patch restores the original function that discovered configuration 1). It defines a new function to discover presence of FF-A and differentiate between v1.0 and v1.1. Signed-off-by: Achin Gupta Signed-off-by: Nishant Sharma --- StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreE= ntryPoint.c | 132 +++++++++++++------- 1 file changed, 87 insertions(+), 45 deletions(-) diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/Stand= aloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPo= int/Arm/StandaloneMmCoreEntryPoint.c index 682b55b5478a..9f6af55c86c4 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMm= CoreEntryPoint.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMm= CoreEntryPoint.c @@ -32,13 +32,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define SPM_MAJOR_VER_MASK 0xFFFF0000 #define SPM_MINOR_VER_MASK 0x0000FFFF #define SPM_MAJOR_VER_SHIFT 16 -#define FFA_NOT_SUPPORTED -1 =20 -STATIC CONST UINT32 mSpmMajorVer =3D SPM_MAJOR_VERSION; -STATIC CONST UINT32 mSpmMinorVer =3D SPM_MINOR_VERSION; - -STATIC CONST UINT32 mSpmMajorVerFfa =3D SPM_MAJOR_VERSION_FFA; -STATIC CONST UINT32 mSpmMinorVerFfa =3D SPM_MINOR_VERSION_FFA; +#define SPM_MAJOR_VER 0 +#define SPM_MINOR_VER 1 =20 #define BOOT_PAYLOAD_VERSION 1 =20 @@ -110,6 +106,70 @@ GetAndPrintBootinformation ( } =20 return PayloadBootInfo; + +/** + An StMM SP implements partial support for FF-A v1.0. The FF-A ABIs are= used to + get and set permissions of memory pages in collaboration with the SPMC= and + signalling completion of initialisation. The original Arm MM communica= tion + interface is used for communication with the Normal world. A TF-A spec= ific + interface is used for initialising the SP. + + With FF-A v1.1, the StMM SP uses only FF-A ABIs for initialisation and + communication. This is subject to support for FF-A v1.1 in the SPMC. I= f this + is not the case, the StMM implementation reverts to the FF-A v1.0 + behaviour. Any of this is applicable only if the feature flag PcdFfaEn= able is + TRUE. + + This function helps the caller determine whether FF-A v1.1 or v1.0 are + available and if only FF-A ABIs can be used at runtime. +**/ +STATIC +EFI_STATUS +CheckFfaCompatibility (BOOLEAN *UseOnlyFfaAbis) +{ + UINT16 SpmcMajorVer; + UINT16 SpmcMinorVer; + UINT32 SpmcVersion; + ARM_SVC_ARGS SpmcVersionArgs =3D {0}; + + // Sanity check in case of a spurious call. + if (FixedPcdGet32 (PcdFfaEnable) =3D=3D 0) { + return EFI_UNSUPPORTED; + } + + // Send the SPMC our version to see whether it supports the same or no= t. + SpmcVersionArgs.Arg0 =3D ARM_SVC_ID_FFA_VERSION_AARCH32; + SpmcVersionArgs.Arg1 =3D FFA_VERSION_COMPILED; + + ArmCallSvc (&SpmcVersionArgs); + SpmcVersion =3D SpmcVersionArgs.Arg0; + + // If the SPMC barfs then bail. + if (SpmcVersion =3D=3D ARM_FFA_SPM_RET_NOT_SUPPORTED) { + return EFI_UNSUPPORTED; + } + + // Extract the SPMC version + SpmcMajorVer =3D (SpmcVersion >> FFA_VERSION_MAJOR_SHIFT) & FFA_VERSIO= N_MAJOR_MASK; + SpmcMinorVer =3D (SpmcVersion >> FFA_VERSION_MINOR_SHIFT) & FFA_VERSIO= N_MINOR_MASK; + + // If the major versions differ then all bets are off. + if (SpmcMajorVer !=3D SPM_MAJOR_VERSION_FFA) { + return EFI_UNSUPPORTED; + } + + // We advertised v1.1 as our version. If the SPMC supports it, it must= return + // the same or a compatible version. If it does not then FF-A ABIs can= not be + // used for all communication. + if (SpmcMinorVer >=3D SPM_MINOR_VERSION_FFA) { + *UseOnlyFfaAbis =3D TRUE; + } else { + *UseOnlyFfaAbis =3D FALSE; + } + + // We have validated that there is a compatible FF-A + // implementation. So. return success. + return EFI_SUCCESS; } =20 /** @@ -219,34 +279,19 @@ GetSpmVersion ( ) { EFI_STATUS Status; - UINT16 CalleeSpmMajorVer; - UINT16 CallerSpmMajorVer; - UINT16 CalleeSpmMinorVer; - UINT16 CallerSpmMinorVer; + UINT16 SpmMajorVersion; + UINT16 SpmMinorVersion; UINT32 SpmVersion; ARM_SVC_ARGS SpmVersionArgs; =20 - if (FixedPcdGet32 (PcdFfaEnable) !=3D 0) { - SpmVersionArgs.Arg0 =3D ARM_SVC_ID_FFA_VERSION_AARCH32; - SpmVersionArgs.Arg1 =3D mSpmMajorVerFfa << SPM_MAJOR_VER_SHIFT; - SpmVersionArgs.Arg1 |=3D mSpmMinorVerFfa; - CallerSpmMajorVer =3D mSpmMajorVerFfa; - CallerSpmMinorVer =3D mSpmMinorVerFfa; - } else { - SpmVersionArgs.Arg0 =3D ARM_SVC_ID_SPM_VERSION_AARCH32; - CallerSpmMajorVer =3D mSpmMajorVer; - CallerSpmMinorVer =3D mSpmMinorVer; - } + SpmVersionArgs.Arg0 =3D ARM_SVC_ID_SPM_VERSION_AARCH32; =20 ArmCallSvc (&SpmVersionArgs); =20 SpmVersion =3D SpmVersionArgs.Arg0; - if (SpmVersion =3D=3D FFA_NOT_SUPPORTED) { - return EFI_UNSUPPORTED; - } =20 - CalleeSpmMajorVer =3D ((SpmVersion & SPM_MAJOR_VER_MASK) >> SPM_MAJOR_= VER_SHIFT); - CalleeSpmMinorVer =3D ((SpmVersion & SPM_MINOR_VER_MASK) >> 0); + SpmMajorVersion =3D ((SpmVersion & SPM_MAJOR_VER_MASK) >> SPM_MAJOR_VE= R_SHIFT); + SpmMinorVersion =3D ((SpmVersion & SPM_MINOR_VER_MASK) >> 0); =20 // Different major revision values indicate possibly incompatible func= tions. // For two revisions, A and B, for which the major revision values are @@ -255,25 +300,17 @@ GetSpmVersion ( // revision A must work in a compatible way with revision B. // However, it is possible for revision B to have a higher // function count than revision A. - if ((CalleeSpmMajorVer =3D=3D CallerSpmMajorVer) && - (CalleeSpmMinorVer >=3D CallerSpmMinorVer)) - { - DEBUG (( - DEBUG_INFO, - "SPM Version: Major=3D0x%x, Minor=3D0x%x\n", - CalleeSpmMajorVer, - CalleeSpmMinorVer - )); + if ((SpmMajorVersion =3D=3D SPM_MAJOR_VER) && + (SpmMinorVersion >=3D SPM_MINOR_VER)) { + DEBUG ((DEBUG_INFO, "SPM Version: Major=3D0x%x, Minor=3D0x%x\n", + SpmMajorVersion, SpmMinorVersion)); Status =3D EFI_SUCCESS; } else { - DEBUG (( - DEBUG_INFO, - "Incompatible SPM Versions.\n Callee Version: Major=3D0x%x, Minor=3D= 0x%x.\n Caller: Major=3D0x%x, Minor>=3D0x%x.\n", - CalleeSpmMajorVer, - CalleeSpmMinorVer, - CallerSpmMajorVer, - CallerSpmMinorVer - )); + DEBUG ((DEBUG_INFO, "Incompatible SPM Versions.\n")); + DEBUG ((DEBUG_INFO, "Current Version: Major=3D0x%x, Minor=3D0x%x.\n"= , + SpmMajorVersion, SpmMinorVersion)); + DEBUG ((DEBUG_INFO, "Expected: Major=3D0x%x, Minor>=3D0x%x.\n", + SPM_MAJOR_VER, SPM_MINOR_VER)); Status =3D EFI_UNSUPPORTED; } =20 @@ -335,9 +372,14 @@ ModuleEntryPoint ( VOID *TeData; UINTN TeDataSize; EFI_PHYSICAL_ADDRESS ImageBase; + BOOLEAN UseOnlyFfaAbis =3D FALSE; =20 - // Get Secure Partition Manager Version Information - Status =3D GetSpmVersion (); + if (FixedPcdGet32 (PcdFfaEnable) !=3D 0) { + Status =3D CheckFfaCompatibility (&UseOnlyFfaAbis); + } else { + // Get Secure Partition Manager Version Information + Status =3D GetSpmVersion (); + } if (EFI_ERROR (Status)) { goto finish; } --=20 2.34.1