public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Nishant Sharma" <nishant.sharma@arm.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Sami Mujawar <sami.mujawar@arm.com>,
	Thomas Abraham <thomas.abraham@arm.com>,
	Sayanta Pattanayak <sayanta.pattanayak@arm.com>,
	Achin Gupta <achin.gupta@arm.com>
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	[thread overview]
Message-ID: <20230711143658.781597-9-nishant.sharma@arm.com> (raw)
In-Reply-To: <20230711143658.781597-1-nishant.sharma@arm.com>

From: Achin Gupta <achin.gupta@arm.com>

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 <achin.gupta@arm.com>
Signed-off-by: Nishant Sharma <nishant.sharma@arm.com>
---
 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c | 132 +++++++++++++-------
 1 file changed, 87 insertions(+), 45 deletions(-)

diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
index 682b55b5478a..9f6af55c86c4 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.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
 
-STATIC CONST UINT32  mSpmMajorVer = SPM_MAJOR_VERSION;
-STATIC CONST UINT32  mSpmMinorVer = SPM_MINOR_VERSION;
-
-STATIC CONST UINT32  mSpmMajorVerFfa = SPM_MAJOR_VERSION_FFA;
-STATIC CONST UINT32  mSpmMinorVerFfa = SPM_MINOR_VERSION_FFA;
+#define SPM_MAJOR_VER     0
+#define SPM_MINOR_VER     1
 
 #define BOOT_PAYLOAD_VERSION  1
 
@@ -110,6 +106,70 @@ GetAndPrintBootinformation (
   }
 
   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 communication
+  interface is used for communication with the Normal world. A TF-A specific
+  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 PcdFfaEnable 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 = {0};
+
+  // Sanity check in case of a spurious call.
+  if (FixedPcdGet32 (PcdFfaEnable) == 0) {
+    return EFI_UNSUPPORTED;
+  }
+
+  // Send the SPMC our version to see whether it supports the same or not.
+  SpmcVersionArgs.Arg0 = ARM_SVC_ID_FFA_VERSION_AARCH32;
+  SpmcVersionArgs.Arg1 = FFA_VERSION_COMPILED;
+
+  ArmCallSvc (&SpmcVersionArgs);
+  SpmcVersion = SpmcVersionArgs.Arg0;
+
+  // If the SPMC barfs then bail.
+  if (SpmcVersion == ARM_FFA_SPM_RET_NOT_SUPPORTED) {
+    return EFI_UNSUPPORTED;
+  }
+
+  // Extract the SPMC version
+  SpmcMajorVer = (SpmcVersion >> FFA_VERSION_MAJOR_SHIFT) & FFA_VERSION_MAJOR_MASK;
+  SpmcMinorVer = (SpmcVersion >> FFA_VERSION_MINOR_SHIFT) & FFA_VERSION_MINOR_MASK;
+
+  // If the major versions differ then all bets are off.
+  if (SpmcMajorVer != 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 cannot be
+  // used for all communication.
+  if (SpmcMinorVer >= SPM_MINOR_VERSION_FFA) {
+    *UseOnlyFfaAbis = TRUE;
+  } else {
+    *UseOnlyFfaAbis = FALSE;
+  }
+
+  // We have validated that there is a compatible FF-A
+  // implementation. So. return success.
+  return EFI_SUCCESS;
 }
 
 /**
@@ -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;
 
-  if (FixedPcdGet32 (PcdFfaEnable) != 0) {
-    SpmVersionArgs.Arg0  = ARM_SVC_ID_FFA_VERSION_AARCH32;
-    SpmVersionArgs.Arg1  = mSpmMajorVerFfa << SPM_MAJOR_VER_SHIFT;
-    SpmVersionArgs.Arg1 |= mSpmMinorVerFfa;
-    CallerSpmMajorVer    = mSpmMajorVerFfa;
-    CallerSpmMinorVer    = mSpmMinorVerFfa;
-  } else {
-    SpmVersionArgs.Arg0 = ARM_SVC_ID_SPM_VERSION_AARCH32;
-    CallerSpmMajorVer   = mSpmMajorVer;
-    CallerSpmMinorVer   = mSpmMinorVer;
-  }
+  SpmVersionArgs.Arg0 = ARM_SVC_ID_SPM_VERSION_AARCH32;
 
   ArmCallSvc (&SpmVersionArgs);
 
   SpmVersion = SpmVersionArgs.Arg0;
-  if (SpmVersion == FFA_NOT_SUPPORTED) {
-    return EFI_UNSUPPORTED;
-  }
 
-  CalleeSpmMajorVer = ((SpmVersion & SPM_MAJOR_VER_MASK) >> SPM_MAJOR_VER_SHIFT);
-  CalleeSpmMinorVer = ((SpmVersion & SPM_MINOR_VER_MASK) >> 0);
+  SpmMajorVersion = ((SpmVersion & SPM_MAJOR_VER_MASK) >> SPM_MAJOR_VER_SHIFT);
+  SpmMinorVersion = ((SpmVersion & SPM_MINOR_VER_MASK) >> 0);
 
   // Different major revision values indicate possibly incompatible functions.
   // 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 == CallerSpmMajorVer) &&
-      (CalleeSpmMinorVer >= CallerSpmMinorVer))
-  {
-    DEBUG ((
-      DEBUG_INFO,
-      "SPM Version: Major=0x%x, Minor=0x%x\n",
-      CalleeSpmMajorVer,
-      CalleeSpmMinorVer
-      ));
+  if ((SpmMajorVersion == SPM_MAJOR_VER) &&
+      (SpmMinorVersion >= SPM_MINOR_VER)) {
+    DEBUG ((DEBUG_INFO, "SPM Version: Major=0x%x, Minor=0x%x\n",
+           SpmMajorVersion, SpmMinorVersion));
     Status = EFI_SUCCESS;
   } else {
-    DEBUG ((
-      DEBUG_INFO,
-      "Incompatible SPM Versions.\n Callee Version: Major=0x%x, Minor=0x%x.\n Caller: Major=0x%x, Minor>=0x%x.\n",
-      CalleeSpmMajorVer,
-      CalleeSpmMinorVer,
-      CallerSpmMajorVer,
-      CallerSpmMinorVer
-      ));
+    DEBUG ((DEBUG_INFO, "Incompatible SPM Versions.\n"));
+    DEBUG ((DEBUG_INFO, "Current Version: Major=0x%x, Minor=0x%x.\n",
+            SpmMajorVersion, SpmMinorVersion));
+    DEBUG ((DEBUG_INFO, "Expected: Major=0x%x, Minor>=0x%x.\n",
+            SPM_MAJOR_VER, SPM_MINOR_VER));
     Status = EFI_UNSUPPORTED;
   }
 
@@ -335,9 +372,14 @@ ModuleEntryPoint (
   VOID                            *TeData;
   UINTN                           TeDataSize;
   EFI_PHYSICAL_ADDRESS            ImageBase;
+  BOOLEAN                         UseOnlyFfaAbis = FALSE;
 
-  // Get Secure Partition Manager Version Information
-  Status = GetSpmVersion ();
+  if (FixedPcdGet32 (PcdFfaEnable) != 0) {
+    Status = CheckFfaCompatibility (&UseOnlyFfaAbis);
+  } else {
+    // Get Secure Partition Manager Version Information
+    Status = GetSpmVersion ();
+  }
   if (EFI_ERROR (Status)) {
     goto finish;
   }
-- 
2.34.1


  parent reply	other threads:[~2023-07-11 14:37 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-11 14:36 [edk2-platforms][PATCH V1 00/20] Add the support for ARM Firmware First Framework Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 01/20] ArmPkg: Change PcdFfaEnable flag datatype Nishant Sharma
2023-07-12 17:21   ` [edk2-devel] " Oliver Smith-Denny
2023-07-12 17:23     ` Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 02/20] StandaloneMmPkg: Allocate and initialise SP stack from internal memory Nishant Sharma
2023-07-12 17:47   ` [edk2-devel] " Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 03/20] StandaloneMmPkg: Include libfdt in the StMM Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 04/20] ArmPkg: Add data structures to receive FF-A boot information Nishant Sharma
2023-07-12 17:27   ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 05/20] ArmPkg/ArmFfaSvc: Add helper macros and fids Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 06/20] ArmPkg: Add support for FFA_MEM_PERM_GET/SET ABIs Nishant Sharma
2023-07-12 17:43   ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 07/20] StandaloneMmPkg: define new data structure to stage FF-A boot information Nishant Sharma
2023-07-11 14:36 ` Nishant Sharma [this message]
2023-07-12 20:31   ` [edk2-devel] [edk2-platforms][PATCH V1 08/20] StandaloneMmPkg: Add backwards compatible support to detect FF-A v1.1 Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 09/20] StandaloneMmPkg: parse SP manifest and populate new boot information Nishant Sharma
2023-07-13 15:24   ` [edk2-devel] " Girish Mahadevan
2023-07-13 16:48     ` Chris Fernald
2023-07-13 20:49       ` Achin Gupta
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 10/20] StandaloneMmPkg: Populate Hoblist for SP init from StMM " Nishant Sharma
2023-07-12 20:52   ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 11/20] StandaloneMmPkg: Skip zero sized sections while tweaking page permissions Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 12/20] StandaloneMmPkg: Add global check for FF-A abis Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 13/20] ArmPkg: Bump the StMM SP FF-A minor version to 1 Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 14/20] ArmPkg/MmCommunicationDxe: Introduce FF-A version check Nishant Sharma
2023-07-13 16:56   ` [edk2-devel] " Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 15/20] ArmPkg/MmCommunicationDxe: Add support for obtaining FF-A partition ID Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 16/20] ArmPkg/MmCommunicationDxe: Register FF-A RX/TX buffers Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 17/20] ArmPkg/MmCommunicationDxe: Unmap FF-A RX/TX buffers during ExitBootServices Nishant Sharma
2023-07-12 20:59   ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 18/20] ArmPkg/MmCommunicationDxe: Discover the StMM SP Nishant Sharma
2023-07-12 21:10   ` [edk2-devel] " Oliver Smith-Denny
2023-07-12 21:48   ` Girish Mahadevan
2023-07-13 17:16   ` Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 19/20] ArmPkg/MmCommunicationDxe: Use the FF-A transport for MM requests Nishant Sharma
2023-07-11 19:22   ` [edk2-devel] " Kun Qin
2023-07-12 14:21     ` achin.gupta
2023-07-12 17:13       ` Kun Qin
2023-07-12 21:49   ` Girish Mahadevan
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 20/20] StandaloneMmPkg: Add support for MM requests as FF-A direct messages Nishant Sharma
2023-07-12 21:13 ` [edk2-devel] [edk2-platforms][PATCH V1 00/20] Add the support for ARM Firmware First Framework Oliver Smith-Denny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230711143658.781597-9-nishant.sharma@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox