From nobody Mon Feb 9 22:19:14 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+106800+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+106800+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1689086244; cv=none; d=zohomail.com; s=zohoarc; b=htPKgOBfrTjwMGeDCs3cttInvkRFS3a1ButAHRapI+vvIoe3RzQ4NQJlP1SElF1Htm4qDIwPQ1gXcUQFM2K4XILtuw0wuGtP5R/sTmIytnJB0EPF4WE01lx4XGTc0R9zV91yES1XWJvUXi8BiBgAsbw18ajr6/3z83M8spgBu/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689086244; 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=wfbP4m5tRZ2YWdDHHDAgMITlSpuRtiIg3qQ7TDul7x0=; b=bZ1cOS28mgPenUcFJAJW+IjnzJRaI08vFLl9eLdBhFpMoEbPD0Gr7N8cyWe09W5SMGiIvEdJayI/i+9QrTHAdZOhzWTVS/yZiuROOhEBeo9zi1OyvB7KWKJtL+fQpy7bhy0MM9DOk012Rp4LlsZQE6NDUx7HPSoCZVCVEQoTl7o= 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+106800+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 1689086244749410.29216986674726; Tue, 11 Jul 2023 07:37:24 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=mljBc2dzO+7YkrfMXBheY9obsUR8uu3iCXP91Lt3gRM=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-Received:X-Received:From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Unsubscribe:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:X-Gm-Message-State:Content-Transfer-Encoding; s=20140610; t=1689086244; v=1; b=AWzBi3b+g3W6dUFwPSDXfMkuspY5ULuAUyWIaj/zf7qDS+PwN0FyQhjC3ug6TIeVy1p0Nwp5 dsU6fREr0mDwWTGZOfLx0X/QIN/r7uoUmjcI1nDKJpXZbOgpPSu7vkqw7fyRGdJZkuraPyyUfIP 9hFoLrPzU/ke2qCt3Own+SNM= X-Received: by 127.0.0.2 with SMTP id wjUAYY1788612xRao2HbZmKO; Tue, 11 Jul 2023 07:37:24 -0700 X-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 X-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) X-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-devel] [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> In-Reply-To: <20230711143658.781597-1-nishant.sharma@arm.com> References: <20230711143658.781597-1-nishant.sharma@arm.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,nishant.sharma@arm.com X-Gm-Message-State: quBEwrjW3yNe63GRo9QBZH4hx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1689086246739100031 Content-Type: text/plain; charset="utf-8" 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. This 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/StandaloneMmCoreEnt= ryPoint.c | 132 +++++++++++++------- 1 file changed, 87 insertions(+), 45 deletions(-) diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/Standal= oneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/= Arm/StandaloneMmCoreEntryPoint.c index 682b55b5478a..9f6af55c86c4 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCo= reEntryPoint.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCo= reEntryPoint.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 u= sed to + get and set permissions of memory pages in collaboration with the SPMC a= nd + signalling completion of initialisation. The original Arm MM communicati= on + interface is used for communication with the Normal world. A TF-A specif= ic + 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. If = 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 PcdFfaEnab= le 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 not. + 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_VERSION_= MAJOR_MASK; + SpmcMinorVer =3D (SpmcVersion >> FFA_VERSION_MINOR_SHIFT) & FFA_VERSION_= 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 r= eturn + // the same or a compatible version. If it does not then FF-A ABIs canno= t 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_VE= R_SHIFT); - CalleeSpmMinorVer =3D ((SpmVersion & SPM_MINOR_VER_MASK) >> 0); + SpmMajorVersion =3D ((SpmVersion & SPM_MAJOR_VER_MASK) >> SPM_MAJOR_VER_= SHIFT); + SpmMinorVersion =3D ((SpmVersion & SPM_MINOR_VER_MASK) >> 0); =20 // Different major revision values indicate possibly incompatible functi= ons. // 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 -=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 (#106800): https://edk2.groups.io/g/devel/message/106800 Mute This Topic: https://groups.io/mt/100079880/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-