public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v3 00/13] Add support for using FF-A calls
@ 2021-01-15  6:13 Sughosh Ganu
  2021-01-15  6:13 ` [PATCH v3 01/13] ArmPkg/IndustryStandard: Add barebones FF-A header Sughosh Ganu
                   ` (13 more replies)
  0 siblings, 14 replies; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:13 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas


The following patch series adds support for using the Firmware
Framework(FF-A) as a transport mechanism for requesting services from
the Secure Partition Manager(SPM). This is done through a Pcd which
can be used to enable the FF-A mechanism or to use the earlier used
SVC calls.

The patches have been pushed to my github repository[1]

Changes since V2:
* Added a STATIC storage class specifier for mSpmMajorVer and
  mSpmMinorVer variables
* Added a STATIC storage class specifier for mSpmMajorVerFfa and
  mSpmMinorVerFfa variables
* Add braces for if/else statements
* Add a check for EFI_NOT_FOUND as a possible return value from
  LocateStandaloneMmCorePeCoffData in _ModuleEntryPoint function
* Check for the return value in Arg0 after the Direct Request call to
  handle errors returned
* Put a comment to reflect the fact that FFA_INTERRUPT and FFA_SUCCESS
  response won't be expected in return to a Direct Request call to get
  the memory attributes
* Check for the return value in Arg0 after the Direct Request call to
  handle errors returned
* Put a comment to reflect the fact that FFA_INTERRUPT and FFA_SUCCESS
  response won't be expected in return to a Direct Request call to set
  the memory attributes

Changes since V1:
Handled review comments from Sami Mujawar

[1] - https://github.com/SNG-ARM/edk2/tree/implement_ffa_svc_optional_v3

Achin Gupta (7):
  ArmPkg/IndustryStandard: Add barebones FF-A header
  ArmPkg/ArmSvcLib: Return x4-x7 in output parameters
  StandaloneMmPkg: Use FF-A header file in Standalone MM Core entry
    point
  StandaloneMmPkg: Add option to use FF-A calls for communication with
    SPM
  StandaloneMmPkg: Use FF-A header file in Standalone MM Arm MMU library
  StandaloneMmMmuLib: Allow FF-A calls to get memory region's attributes
  StandaloneMmMmuLib: Allow FF-A calls to set memory region's attributes

Ilias Apalodimas (2):
  MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase
    to Pcd
  StandaloneMmPkg: Allow sending FFA Direct Request message to
    StandaloneMm

Sughosh Ganu (4):
  ArmPkg: Introduce support for PcdFfaEnable
  StandaloneMmPkg: Add macros for SPM version
  StandaloneMmPkg: Add the SPM version for FF-A
  StandaloneMmPkg: Add option to use FF-A calls for getting SPM version

 ArmPkg/ArmPkg.dec                             |   6 +
 .../ArmMmuStandaloneMmLib.inf                 |   3 +
 .../RuntimeDxe/VariableStandaloneMm.inf       |   6 +-
 .../StandaloneMmCoreEntryPoint.inf            |   3 +
 ArmPkg/Include/IndustryStandard/ArmFfaSvc.h   |  44 +++++
 ArmPkg/Include/IndustryStandard/ArmMmSvc.h    |   3 +
 ArmPkg/Include/Library/ArmSvcLib.h            |  10 +-
 .../AArch64/ArmMmuStandaloneMmLib.c           | 167 +++++++++++++++---
 .../StandaloneMmCpu/AArch64/EventHandle.c     |   4 +-
 .../AArch64/StandaloneMmCoreEntryPoint.c      | 133 +++++++++++---
 ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S     |   4 +-
 11 files changed, 322 insertions(+), 61 deletions(-)
 create mode 100644 ArmPkg/Include/IndustryStandard/ArmFfaSvc.h

-- 
2.17.1



^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v3 01/13] ArmPkg/IndustryStandard: Add barebones FF-A header
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
@ 2021-01-15  6:13 ` Sughosh Ganu
  2021-02-13 10:28   ` [edk2-devel] " Ard Biesheuvel
  2021-01-15  6:13 ` [PATCH v3 02/13] ArmPkg/ArmSvcLib: Return x4-x7 in output parameters Sughosh Ganu
                   ` (12 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:13 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Achin Gupta

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

This patch adds a rudimentary header file with defines for FF-A ABIs
that will be used as the transport between S-EL0 and the SPM

Signed-off-by: Achin Gupta <achin.gupta@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
---

Changes since V2: None

 ArmPkg/Include/IndustryStandard/ArmFfaSvc.h | 23 ++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h b/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
new file mode 100644
index 0000000000..1eadf48ab5
--- /dev/null
+++ b/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
@@ -0,0 +1,23 @@
+/** @file
+  Header file for FF-A ABI's that will be used for
+  communication between S-EL0 and the Secure Partition
+  Manager(SPM)
+
+  Copyright (c) 2020, ARM Limited. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Revision Reference:
+    - FF-A Version 1.0
+
+
+**/
+
+#ifndef ARM_FFA_SVC_H_
+#define ARM_FFA_SVC_H_
+
+#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
+
+#endif // ARM_FFA_SVC_H_
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v3 02/13] ArmPkg/ArmSvcLib: Return x4-x7 in output parameters
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
  2021-01-15  6:13 ` [PATCH v3 01/13] ArmPkg/IndustryStandard: Add barebones FF-A header Sughosh Ganu
@ 2021-01-15  6:13 ` Sughosh Ganu
  2021-02-13 10:28   ` [edk2-devel] " Ard Biesheuvel
  2021-01-15  6:13 ` [PATCH v3 03/13] StandaloneMmPkg: Use FF-A header file in Standalone MM Core entry point Sughosh Ganu
                   ` (11 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:13 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Achin Gupta

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

The Arm SMC calling convention standard v1.2 allows 8 input and output
parameter registers. The FF-A specification relies on this
communication. This patch extends the number of output registers
returned by ArmCallSvc() to match this convention.

Signed-off-by: Achin Gupta <achin.gupta@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
---

Changes since V2: None

 ArmPkg/Include/Library/ArmSvcLib.h        | 10 ++++++++--
 ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S |  4 +++-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/ArmPkg/Include/Library/ArmSvcLib.h b/ArmPkg/Include/Library/ArmSvcLib.h
index a94ead1965..a4414270f3 100644
--- a/ArmPkg/Include/Library/ArmSvcLib.h
+++ b/ArmPkg/Include/Library/ArmSvcLib.h
@@ -27,10 +27,16 @@ typedef struct {
 /**
   Trigger an SVC call
 
-  SVC calls can take up to 7 arguments and return up to 4 return values.
-  Therefore, the 4 first fields in the ARM_SVC_ARGS structure are used
+  SVC calls can take up to 8 arguments and return up to 8 return values.
+  Therefore, the 8 first fields in the ARM_SVC_ARGS structure are used
   for both input and output values.
 
+  @param[in, out]    Args Arguments to be passed as part of the SVC call
+                     The return values of the SVC call are also placed
+                     in the same structure
+
+  @retval None
+
 **/
 VOID
 ArmCallSvc (
diff --git a/ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S b/ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S
index ee265f94b9..1a7c10cb79 100644
--- a/ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S
+++ b/ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S
@@ -33,9 +33,11 @@ ASM_PFX(ArmCallSvc):
   ldr   x9, [sp, #16]
 
   // Store the SVC returned values into the ARM_SVC_ARGS structure.
-  // A SVC call can return up to 4 values - we do not need to store back x4-x7.
+  // A SVC call can return up to 8 values
   stp   x0, x1, [x9, #0]
   stp   x2, x3, [x9, #16]
+  stp   x4, x5, [x9, #32]
+  stp   x6, x7, [x9, #48]
 
   mov   x0, x9
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v3 03/13] StandaloneMmPkg: Use FF-A header file in Standalone MM Core entry point
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
  2021-01-15  6:13 ` [PATCH v3 01/13] ArmPkg/IndustryStandard: Add barebones FF-A header Sughosh Ganu
  2021-01-15  6:13 ` [PATCH v3 02/13] ArmPkg/ArmSvcLib: Return x4-x7 in output parameters Sughosh Ganu
@ 2021-01-15  6:13 ` Sughosh Ganu
  2021-01-15  6:13 ` [PATCH v3 04/13] ArmPkg: Introduce support for PcdFfaEnable Sughosh Ganu
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:13 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Achin Gupta

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

Add the Firmware Framework(FF-A) header in the StandaloneMm entry
point driver. Support for invoking the functions through FF-A will be
added in a subsequent patch.

Signed-off-by: Achin Gupta <achin.gupta@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
---

Changes since V2: None

 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
index fa2005e7e9..3d78e8e9ae 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
@@ -26,6 +26,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include <IndustryStandard/ArmStdSmc.h>
 #include <IndustryStandard/ArmMmSvc.h>
+#include <IndustryStandard/ArmFfaSvc.h>
 
 #define SPM_MAJOR_VER_MASK        0xFFFF0000
 #define SPM_MINOR_VER_MASK        0x0000FFFF
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v3 04/13] ArmPkg: Introduce support for PcdFfaEnable
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
                   ` (2 preceding siblings ...)
  2021-01-15  6:13 ` [PATCH v3 03/13] StandaloneMmPkg: Use FF-A header file in Standalone MM Core entry point Sughosh Ganu
@ 2021-01-15  6:13 ` Sughosh Ganu
  2021-02-13 10:29   ` [edk2-devel] " Ard Biesheuvel
  2021-01-15  6:13 ` [PATCH v3 05/13] StandaloneMmPkg: Add macros for SPM version Sughosh Ganu
                   ` (9 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:13 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Sughosh Ganu

The Secure Partition(SP) can request services from the Secure
Partition Manager Core(SPMC) either through FF-A calls or through the
existing SVC calls. Add a feature flag Pcd for enabling the FF-A
method -- when this is set to FALSE, the SP uses the existing SVC
calls for making the requests.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
---

Changes since V2: None

 ArmPkg/ArmPkg.dec | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec
index eaf1072d9e..507e16844c 100644
--- a/ArmPkg/ArmPkg.dec
+++ b/ArmPkg/ArmPkg.dec
@@ -78,6 +78,12 @@
   # Define if the GICv3 controller should use the GICv2 legacy
   gArmTokenSpaceGuid.PcdArmGicV3WithV2Legacy|FALSE|BOOLEAN|0x00000042
 
+  ## Used to select method for requesting services from S-EL1.<BR><BR
+  #   TRUE  - Selects FF-A calls for communication between S-EL0 and SPMC.<BR>
+  #   FALSE - Selects SVC calls for communication between S-EL0 and SPMC.<BR>
+  # @Prompt Enable FF-A support.
+  gArmTokenSpaceGuid.PcdFfaEnable|FALSE|BOOLEAN|0x0000005B
+
 [PcdsFeatureFlag.ARM]
   # Whether to map normal memory as non-shareable. FALSE is the safe choice, but
   # TRUE may be appropriate to fix performance problems if you don't care about
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v3 05/13] StandaloneMmPkg: Add macros for SPM version
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
                   ` (3 preceding siblings ...)
  2021-01-15  6:13 ` [PATCH v3 04/13] ArmPkg: Introduce support for PcdFfaEnable Sughosh Ganu
@ 2021-01-15  6:13 ` Sughosh Ganu
  2021-01-20 18:34   ` [edk2-devel] " Sami Mujawar
  2021-01-15  6:13 ` [PATCH v3 06/13] StandaloneMmPkg: Add the SPM version for FF-A Sughosh Ganu
                   ` (8 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:13 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Sughosh Ganu

Declare module wide variables for SPM major and minor versions to be
used in checking the SPM version compatibility. Declare the the values
of SPM major and minor versions as macros.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---

Changes since V2:
* Added a STATIC storage class specifier for mSpmMajorVer and
  mSpmMinorVer variables

 ArmPkg/Include/IndustryStandard/ArmMmSvc.h                                              |  3 +++
 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c | 10 +++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/ArmPkg/Include/IndustryStandard/ArmMmSvc.h b/ArmPkg/Include/IndustryStandard/ArmMmSvc.h
index ee29c2fecc..71a5398558 100644
--- a/ArmPkg/Include/IndustryStandard/ArmMmSvc.h
+++ b/ArmPkg/Include/IndustryStandard/ArmMmSvc.h
@@ -41,4 +41,7 @@
 #define ARM_SVC_SPM_RET_DENIED               -3
 #define ARM_SVC_SPM_RET_NO_MEMORY            -5
 
+#define SPM_MAJOR_VERSION                     0
+#define SPM_MINOR_VERSION                     1
+
 #endif
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
index 3d78e8e9ae..2643473e88 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
@@ -32,8 +32,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #define SPM_MINOR_VER_MASK        0x0000FFFF
 #define SPM_MAJOR_VER_SHIFT       16
 
-#define SPM_MAJOR_VER             0
-#define SPM_MINOR_VER             1
+STATIC CONST UINT32 mSpmMajorVer = SPM_MAJOR_VERSION;
+STATIC CONST UINT32 mSpmMinorVer = SPM_MINOR_VERSION;
 
 #define BOOT_PAYLOAD_VERSION      1
 
@@ -196,8 +196,8 @@ GetSpmVersion (VOID)
   // 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 ((SpmMajorVersion == SPM_MAJOR_VER) &&
-      (SpmMinorVersion >= SPM_MINOR_VER))
+  if ((SpmMajorVersion == mSpmMajorVer) &&
+      (SpmMinorVersion >= mSpmMinorVer))
   {
     DEBUG ((DEBUG_INFO, "SPM Version: Major=0x%x, Minor=0x%x\n",
            SpmMajorVersion, SpmMinorVersion));
@@ -206,7 +206,7 @@ GetSpmVersion (VOID)
   else
   {
     DEBUG ((DEBUG_INFO, "Incompatible SPM Versions.\n Current Version: Major=0x%x, Minor=0x%x.\n Expected: Major=0x%x, Minor>=0x%x.\n",
-            SpmMajorVersion, SpmMinorVersion, SPM_MAJOR_VER, SPM_MINOR_VER));
+            SpmMajorVersion, SpmMinorVersion, mSpmMajorVer, mSpmMinorVer));
     Status = EFI_UNSUPPORTED;
   }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v3 06/13] StandaloneMmPkg: Add the SPM version for FF-A
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
                   ` (4 preceding siblings ...)
  2021-01-15  6:13 ` [PATCH v3 05/13] StandaloneMmPkg: Add macros for SPM version Sughosh Ganu
@ 2021-01-15  6:13 ` Sughosh Ganu
  2021-01-20 18:38   ` [edk2-devel] " Sami Mujawar
  2021-01-15  6:13 ` [PATCH v3 07/13] StandaloneMmPkg: Add option to use FF-A calls for getting SPM version Sughosh Ganu
                   ` (7 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:13 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Sughosh Ganu

The Firmware Framework(FF-A) requires implementation of SPM version
v1.0. Add new macros for the version that will be used for FF-A.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---

Changes since V2:
* Added a STATIC storage class specifier for mSpmMajorVerFfa and
  mSpmMinorVerFfa variables

 ArmPkg/Include/IndustryStandard/ArmFfaSvc.h                                             | 3 +++
 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h b/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
index 1eadf48ab5..bdf6ce4676 100644
--- a/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
+++ b/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
@@ -20,4 +20,7 @@
 #define ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ_AARCH64      0xC400006F
 #define ARM_SVC_ID_FFA_MSG_SEND_DIRECT_RESP_AARCH64     0xC4000070
 
+#define SPM_MAJOR_VERSION_FFA                           1
+#define SPM_MINOR_VERSION_FFA                           0
+
 #endif // ARM_FFA_SVC_H_
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
index 2643473e88..3bd2516608 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
@@ -35,6 +35,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 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 BOOT_PAYLOAD_VERSION      1
 
 PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT      CpuDriverEntryPoint = NULL;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v3 07/13] StandaloneMmPkg: Add option to use FF-A calls for getting SPM version
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
                   ` (5 preceding siblings ...)
  2021-01-15  6:13 ` [PATCH v3 06/13] StandaloneMmPkg: Add the SPM version for FF-A Sughosh Ganu
@ 2021-01-15  6:13 ` Sughosh Ganu
  2021-01-15  6:13 ` [PATCH v3 08/13] StandaloneMmPkg: Add option to use FF-A calls for communication with SPM Sughosh Ganu
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:13 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Sughosh Ganu

With the introduction of Firmware Framework(FF-A), a Secure Partition
can get the SPM version either using FF-A calls or through the
existing svc calls. Use a runtime check to use either of the two
methods based on the Pcd feature flag value.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Co-developed-by: Achin Gupta <achin.gupta@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
---

Changes since V2: None

 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf       |  3 ++
 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c | 37 ++++++++++++++------
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
index 75a654b06d..073934a6f5 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
@@ -48,5 +48,8 @@
   gEfiStandaloneMmNonSecureBufferGuid
   gEfiArmTfCpuDriverEpDescriptorGuid
 
+[Pcd]
+  gArmTokenSpaceGuid.PcdFfaEnable
+
 [BuildOptions]
   GCC:*_*_*_CC_FLAGS = -fpie
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
index 3bd2516608..25ead004e6 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
@@ -23,6 +23,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/BaseLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/SerialPortLib.h>
+#include <Library/PcdLib.h>
 
 #include <IndustryStandard/ArmStdSmc.h>
 #include <IndustryStandard/ArmMmSvc.h>
@@ -31,6 +32,7 @@ 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;
@@ -178,19 +180,34 @@ EFI_STATUS
 GetSpmVersion (VOID)
 {
   EFI_STATUS   Status;
-  UINT16       SpmMajorVersion;
-  UINT16       SpmMinorVersion;
+  UINT16       CalleeSpmMajorVer;
+  UINT16       CallerSpmMajorVer;
+  UINT16       CalleeSpmMinorVer;
+  UINT16       CallerSpmMinorVer;
   UINT32       SpmVersion;
   ARM_SVC_ARGS SpmVersionArgs;
 
-  SpmVersionArgs.Arg0 = ARM_SVC_ID_SPM_VERSION_AARCH32;
+  if (FeaturePcdGet (PcdFfaEnable)) {
+    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;
+  }
 
   ArmCallSvc (&SpmVersionArgs);
 
   SpmVersion = SpmVersionArgs.Arg0;
+  if (SpmVersion == FFA_NOT_SUPPORTED) {
+    return EFI_UNSUPPORTED;
+  }
 
-  SpmMajorVersion = ((SpmVersion & SPM_MAJOR_VER_MASK) >> SPM_MAJOR_VER_SHIFT);
-  SpmMinorVersion = ((SpmVersion & SPM_MINOR_VER_MASK) >> 0);
+  CalleeSpmMajorVer = ((SpmVersion & SPM_MAJOR_VER_MASK) >> SPM_MAJOR_VER_SHIFT);
+  CalleeSpmMinorVer = ((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
@@ -199,17 +216,17 @@ GetSpmVersion (VOID)
   // 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 ((SpmMajorVersion == mSpmMajorVer) &&
-      (SpmMinorVersion >= mSpmMinorVer))
+  if ((CalleeSpmMajorVer == CallerSpmMajorVer) &&
+      (CalleeSpmMinorVer >= CallerSpmMinorVer))
   {
     DEBUG ((DEBUG_INFO, "SPM Version: Major=0x%x, Minor=0x%x\n",
-           SpmMajorVersion, SpmMinorVersion));
+           CalleeSpmMajorVer, CalleeSpmMinorVer));
     Status = EFI_SUCCESS;
   }
   else
   {
-    DEBUG ((DEBUG_INFO, "Incompatible SPM Versions.\n Current Version: Major=0x%x, Minor=0x%x.\n Expected: Major=0x%x, Minor>=0x%x.\n",
-            SpmMajorVersion, SpmMinorVersion, mSpmMajorVer, mSpmMinorVer));
+    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));
     Status = EFI_UNSUPPORTED;
   }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v3 08/13] StandaloneMmPkg: Add option to use FF-A calls for communication with SPM
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
                   ` (6 preceding siblings ...)
  2021-01-15  6:13 ` [PATCH v3 07/13] StandaloneMmPkg: Add option to use FF-A calls for getting SPM version Sughosh Ganu
@ 2021-01-15  6:13 ` Sughosh Ganu
  2021-01-20 18:44   ` [edk2-devel] " Sami Mujawar
  2021-01-15  6:14 ` [PATCH v3 09/13] StandaloneMmPkg: Use FF-A header file in Standalone MM Arm MMU library Sughosh Ganu
                   ` (5 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:13 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Achin Gupta

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

Add support for reporting completion of a MM request using either the
Firmware Framework(FF-A) ABI transport or through the earlier used SVC
calls.

Signed-off-by: Achin Gupta <achin.gupta@arm.com>
Co-developed-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---

Changes since V2:
* Add braces for if/else statements
* Add a check for EFI_NOT_FOUND as a possible return value from
  LocateStandaloneMmCorePeCoffData in _ModuleEntryPoint function

 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c | 88 ++++++++++++++++----
 1 file changed, 74 insertions(+), 14 deletions(-)

diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
index 25ead004e6..6c50f470aa 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
@@ -120,6 +120,7 @@ DelegatedEventLoop (
   IN ARM_SVC_ARGS *EventCompleteSvcArgs
   )
 {
+  BOOLEAN FfaEnabled;
   EFI_STATUS Status;
   UINTN SvcStatus;
 
@@ -131,16 +132,32 @@ DelegatedEventLoop (
     DEBUG ((DEBUG_INFO, "X1 :  0x%x\n", (UINT32) EventCompleteSvcArgs->Arg1));
     DEBUG ((DEBUG_INFO, "X2 :  0x%x\n", (UINT32) EventCompleteSvcArgs->Arg2));
     DEBUG ((DEBUG_INFO, "X3 :  0x%x\n", (UINT32) EventCompleteSvcArgs->Arg3));
-
-    Status = CpuDriverEntryPoint (
-               EventCompleteSvcArgs->Arg0,
-               EventCompleteSvcArgs->Arg3,
-               EventCompleteSvcArgs->Arg1
-               );
-
-    if (EFI_ERROR (Status)) {
-      DEBUG ((DEBUG_ERROR, "Failed delegated event 0x%x, Status 0x%x\n",
-              EventCompleteSvcArgs->Arg0, Status));
+    DEBUG ((DEBUG_INFO, "X4 :  0x%x\n", (UINT32) EventCompleteSvcArgs->Arg4));
+    DEBUG ((DEBUG_INFO, "X5 :  0x%x\n", (UINT32) EventCompleteSvcArgs->Arg5));
+    DEBUG ((DEBUG_INFO, "X6 :  0x%x\n", (UINT32) EventCompleteSvcArgs->Arg6));
+    DEBUG ((DEBUG_INFO, "X7 :  0x%x\n", (UINT32) EventCompleteSvcArgs->Arg7));
+
+    FfaEnabled = FeaturePcdGet (PcdFfaEnable);
+    if (FfaEnabled) {
+      Status = CpuDriverEntryPoint (
+                 EventCompleteSvcArgs->Arg0,
+                 EventCompleteSvcArgs->Arg6,
+                 EventCompleteSvcArgs->Arg3
+                 );
+      if (EFI_ERROR (Status)) {
+        DEBUG ((DEBUG_ERROR, "Failed delegated event 0x%x, Status 0x%x\n",
+          EventCompleteSvcArgs->Arg3, Status));
+      }
+    } else {
+      Status = CpuDriverEntryPoint (
+                 EventCompleteSvcArgs->Arg0,
+                 EventCompleteSvcArgs->Arg3,
+                 EventCompleteSvcArgs->Arg1
+                 );
+      if (EFI_ERROR (Status)) {
+        DEBUG ((DEBUG_ERROR, "Failed delegated event 0x%x, Status 0x%x\n",
+          EventCompleteSvcArgs->Arg0, Status));
+      }
     }
 
     switch (Status) {
@@ -164,8 +181,16 @@ DelegatedEventLoop (
       break;
     }
 
-    EventCompleteSvcArgs->Arg0 = ARM_SVC_ID_SP_EVENT_COMPLETE_AARCH64;
-    EventCompleteSvcArgs->Arg1 = SvcStatus;
+    if (FfaEnabled) {
+      EventCompleteSvcArgs->Arg0 = ARM_SVC_ID_FFA_MSG_SEND_DIRECT_RESP_AARCH64;
+      EventCompleteSvcArgs->Arg1 = 0;
+      EventCompleteSvcArgs->Arg2 = 0;
+      EventCompleteSvcArgs->Arg3 = ARM_SVC_ID_SP_EVENT_COMPLETE_AARCH64;
+      EventCompleteSvcArgs->Arg4 = SvcStatus;
+    } else {
+      EventCompleteSvcArgs->Arg0 = ARM_SVC_ID_SP_EVENT_COMPLETE_AARCH64;
+      EventCompleteSvcArgs->Arg1 = SvcStatus;
+    }
   }
 }
 
@@ -233,6 +258,32 @@ GetSpmVersion (VOID)
   return Status;
 }
 
+/**
+  Initialize parameters to be sent via SVC call.
+
+  @param[out]     InitMmFoundationSvcArgs  Args structure
+  @param[out]     Ret                      Return Code
+
+**/
+STATIC
+VOID
+InitArmSvcArgs (
+  OUT ARM_SVC_ARGS *InitMmFoundationSvcArgs,
+  OUT INT32 *Ret
+  )
+{
+  if (FeaturePcdGet (PcdFfaEnable)) {
+    InitMmFoundationSvcArgs->Arg0 = ARM_SVC_ID_FFA_MSG_SEND_DIRECT_RESP_AARCH64;
+    InitMmFoundationSvcArgs->Arg1 = 0;
+    InitMmFoundationSvcArgs->Arg2 = 0;
+    InitMmFoundationSvcArgs->Arg3 = ARM_SVC_ID_SP_EVENT_COMPLETE_AARCH64;
+    InitMmFoundationSvcArgs->Arg4 = *Ret;
+  } else {
+    InitMmFoundationSvcArgs->Arg0 = ARM_SVC_ID_SP_EVENT_COMPLETE_AARCH64;
+    InitMmFoundationSvcArgs->Arg1 = *Ret;
+  }
+}
+
 /**
   The entry point of Standalone MM Foundation.
 
@@ -255,6 +306,7 @@ _ModuleEntryPoint (
   EFI_SECURE_PARTITION_BOOT_INFO          *PayloadBootInfo;
   ARM_SVC_ARGS                            InitMmFoundationSvcArgs;
   EFI_STATUS                              Status;
+  INT32                                   Ret;
   UINT32                                  SectionHeaderOffset;
   UINT16                                  NumberOfSections;
   VOID                                    *HobStart;
@@ -346,8 +398,16 @@ _ModuleEntryPoint (
   DEBUG ((DEBUG_INFO, "Shared Cpu Driver EP 0x%lx\n", (UINT64) CpuDriverEntryPoint));
 
 finish:
+  if (Status == RETURN_UNSUPPORTED) {
+    Ret = -1;
+  } else if (Status == RETURN_INVALID_PARAMETER) {
+    Ret = -2;
+  } else if (Status == EFI_NOT_FOUND) {
+    Ret = -7;
+  } else {
+    Ret = 0;
+  }
   ZeroMem (&InitMmFoundationSvcArgs, sizeof(InitMmFoundationSvcArgs));
-  InitMmFoundationSvcArgs.Arg0 = ARM_SVC_ID_SP_EVENT_COMPLETE_AARCH64;
-  InitMmFoundationSvcArgs.Arg1 = Status;
+  InitArmSvcArgs (&InitMmFoundationSvcArgs, &Ret);
   DelegatedEventLoop (&InitMmFoundationSvcArgs);
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v3 09/13] StandaloneMmPkg: Use FF-A header file in Standalone MM Arm MMU library
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
                   ` (7 preceding siblings ...)
  2021-01-15  6:13 ` [PATCH v3 08/13] StandaloneMmPkg: Add option to use FF-A calls for communication with SPM Sughosh Ganu
@ 2021-01-15  6:14 ` Sughosh Ganu
  2021-01-15  6:14 ` [PATCH v3 10/13] StandaloneMmMmuLib: Allow FF-A calls to get memory region's attributes Sughosh Ganu
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:14 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Achin Gupta

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

Add the FF-A header for invoking the mmu functions using FF-A calls as
the transport mechanism. Support for invoking the functions through
FF-A will be added in a subsequent patch.

Signed-off-by: Achin Gupta <achin.gupta@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
---

Changes since V2: None

 ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c b/ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c
index 5a316bc256..e2770636fb 100644
--- a/ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c
+++ b/ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c
@@ -9,6 +9,7 @@
 
 #include <Uefi.h>
 #include <IndustryStandard/ArmMmSvc.h>
+#include <IndustryStandard/ArmFfaSvc.h>
 
 #include <Library/ArmLib.h>
 #include <Library/ArmMmuLib.h>
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v3 10/13] StandaloneMmMmuLib: Allow FF-A calls to get memory region's attributes
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
                   ` (8 preceding siblings ...)
  2021-01-15  6:14 ` [PATCH v3 09/13] StandaloneMmPkg: Use FF-A header file in Standalone MM Arm MMU library Sughosh Ganu
@ 2021-01-15  6:14 ` Sughosh Ganu
  2021-01-20 18:49   ` [edk2-devel] " Sami Mujawar
  2021-01-15  6:14 ` [PATCH v3 11/13] StandaloneMmMmuLib: Allow FF-A calls to set " Sughosh Ganu
                   ` (3 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:14 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Achin Gupta

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

Allow getting memory region's permissions using either of the Firmware
Framework(FF-A) ABI transport or through the earlier used SVC calls.

Signed-off-by: Achin Gupta <achin.gupta@arm.com>
Co-developed-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---

Changes since V2:
* Check for the return value in Arg0 after the Direct Request call to
  handle errors returned
* Put a comment to reflect the fact that FFA_INTERRUPT and FFA_SUCCESS
  response won't be expected in return to a Direct Request call to get
  the memory attributes

 ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf       |  3 +
 ArmPkg/Include/IndustryStandard/ArmFfaSvc.h                       | 18 +++++
 ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c | 78 ++++++++++++++++++--
 3 files changed, 93 insertions(+), 6 deletions(-)

diff --git a/ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf b/ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf
index 85973687f5..a29dd800b5 100644
--- a/ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf
+++ b/ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf
@@ -23,6 +23,9 @@
   ArmPkg/ArmPkg.dec
   MdePkg/MdePkg.dec
 
+[Pcd]
+  gArmTokenSpaceGuid.PcdFfaEnable
+
 [LibraryClasses]
   ArmLib
   CacheMaintenanceLib
diff --git a/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h b/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
index bdf6ce4676..65b8343ade 100644
--- a/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
+++ b/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
@@ -23,4 +23,22 @@
 #define SPM_MAJOR_VERSION_FFA                           1
 #define SPM_MINOR_VERSION_FFA                           0
 
+#define ARM_FFA_SPM_RET_SUCCESS                          0
+#define ARM_FFA_SPM_RET_NOT_SUPPORTED                   -1
+#define ARM_FFA_SPM_RET_INVALID_PARAMETERS              -2
+#define ARM_FFA_SPM_RET_NO_MEMORY                       -3
+#define ARM_FFA_SPM_RET_BUSY                            -4
+#define ARM_FFA_SPM_RET_INTERRUPTED                     -5
+#define ARM_FFA_SPM_RET_DENIED                          -6
+#define ARM_FFA_SPM_RET_RETRY                           -7
+#define ARM_FFA_SPM_RET_ABORTED                         -8
+
+// For now, the destination id to be used in the FF-A calls
+// is being hard-coded. Subsequently, support will be added
+// to get the endpoint id's dynamically
+// This is the endpoint id used by the optee os's implementation
+// of the spmc.
+// https://github.com/OP-TEE/optee_os/blob/master/core/arch/arm/kernel/stmm_sp.c#L66
+#define ARM_FFA_DESTINATION_ENDPOINT_ID                  3
+
 #endif // ARM_FFA_SVC_H_
diff --git a/ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c b/ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c
index e2770636fb..14fe781630 100644
--- a/ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c
+++ b/ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c
@@ -17,6 +17,7 @@
 #include <Library/BaseLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
 
 STATIC
 EFI_STATUS
@@ -25,20 +26,85 @@ GetMemoryPermissions (
   OUT UINT32                    *MemoryAttributes
   )
 {
+  INT32         Ret;
   ARM_SVC_ARGS  GetMemoryPermissionsSvcArgs;
+  BOOLEAN       FfaEnabled;
 
   ZeroMem (&GetMemoryPermissionsSvcArgs, sizeof (ARM_SVC_ARGS));
 
-  GetMemoryPermissionsSvcArgs.Arg0 = ARM_SVC_ID_SP_GET_MEM_ATTRIBUTES_AARCH64;
-  GetMemoryPermissionsSvcArgs.Arg1 = BaseAddress;
+  FfaEnabled = FeaturePcdGet (PcdFfaEnable);
+  if (FfaEnabled) {
+    GetMemoryPermissionsSvcArgs.Arg0 = ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ_AARCH64;
+    GetMemoryPermissionsSvcArgs.Arg1 = ARM_FFA_DESTINATION_ENDPOINT_ID;
+    GetMemoryPermissionsSvcArgs.Arg2 = 0;
+    GetMemoryPermissionsSvcArgs.Arg3 = ARM_SVC_ID_SP_GET_MEM_ATTRIBUTES_AARCH64;
+    GetMemoryPermissionsSvcArgs.Arg4 = BaseAddress;
+  } else {
+    GetMemoryPermissionsSvcArgs.Arg0 = ARM_SVC_ID_SP_GET_MEM_ATTRIBUTES_AARCH64;
+    GetMemoryPermissionsSvcArgs.Arg1 = BaseAddress;
+    GetMemoryPermissionsSvcArgs.Arg2 = 0;
+    GetMemoryPermissionsSvcArgs.Arg3 = 0;
+  }
 
+  *MemoryAttributes = 0;
   ArmCallSvc (&GetMemoryPermissionsSvcArgs);
-  if (GetMemoryPermissionsSvcArgs.Arg0 == ARM_SVC_SPM_RET_INVALID_PARAMS) {
-    *MemoryAttributes = 0;
-    return EFI_INVALID_PARAMETER;
+  if (FfaEnabled) {
+    // Getting memory attributes is an atomic call, with
+    // StandaloneMm at S-EL0 being the caller and the SPM
+    // core being the callee. Thus there won't be a
+    // FFA_INTERRUPT or FFA_SUCCESS response to the Direct
+    // Request sent above. This will have to be considered
+    // for other Direct Request calls which are not atomic
+    // We therefore check only for Direct Response by the
+    // callee.
+    if (GetMemoryPermissionsSvcArgs.Arg0 !=
+        ARM_SVC_ID_FFA_MSG_SEND_DIRECT_RESP_AARCH64) {
+      // If Arg0 is not a Direct Response, that means we
+      // have an FF-A error. We need to check Arg2 for the
+      // FF-A error code.
+      Ret = GetMemoryPermissionsSvcArgs.Arg2;
+      switch (Ret) {
+      case ARM_FFA_SPM_RET_INVALID_PARAMETERS:
+
+        return EFI_INVALID_PARAMETER;
+
+      case ARM_FFA_SPM_RET_DENIED:
+        return EFI_NOT_READY;
+
+      case ARM_FFA_SPM_RET_NOT_SUPPORTED:
+        return EFI_UNSUPPORTED;
+
+      case ARM_FFA_SPM_RET_BUSY:
+        return EFI_NOT_READY;
+
+      case ARM_FFA_SPM_RET_ABORTED:
+        return EFI_ABORTED;
+      }
+    } else if (GetMemoryPermissionsSvcArgs.Arg0 ==
+               ARM_SVC_ID_FFA_MSG_SEND_DIRECT_RESP_AARCH64) {
+      // A Direct Response means FF-A success
+      // Now check the payload for errors
+      // The callee sends back the return value
+      // in Arg3
+      Ret = GetMemoryPermissionsSvcArgs.Arg3;
+    }
+  } else {
+    Ret = GetMemoryPermissionsSvcArgs.Arg0;
+  }
+
+  if (Ret & BIT31) {
+    // Bit 31 set means there is an error retured
+    switch (Ret) {
+    case ARM_SVC_SPM_RET_INVALID_PARAMS:
+      return EFI_INVALID_PARAMETER;
+
+    case ARM_SVC_SPM_RET_NOT_SUPPORTED:
+      return EFI_UNSUPPORTED;
+    }
+  } else {
+    *MemoryAttributes = Ret;
   }
 
-  *MemoryAttributes = GetMemoryPermissionsSvcArgs.Arg0;
   return EFI_SUCCESS;
 }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v3 11/13] StandaloneMmMmuLib: Allow FF-A calls to set memory region's attributes
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
                   ` (9 preceding siblings ...)
  2021-01-15  6:14 ` [PATCH v3 10/13] StandaloneMmMmuLib: Allow FF-A calls to get memory region's attributes Sughosh Ganu
@ 2021-01-15  6:14 ` Sughosh Ganu
  2021-01-20 18:52   ` [edk2-devel] " Sami Mujawar
  2021-01-15  6:14 ` [PATCH v3 12/13] MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase to Pcd Sughosh Ganu
                   ` (2 subsequent siblings)
  13 siblings, 1 reply; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:14 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Achin Gupta

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

Allow setting memory region's permissions using either of the Firmware
Framework(FF-A) ABI transport or through the earlier used SVC calls.

Signed-off-by: Achin Gupta <achin.gupta@arm.com>
Co-developed-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---

Changes since V2:
* Check for the return value in Arg0 after the Direct Request call to
  handle errors returned
* Put a comment to reflect the fact that FFA_INTERRUPT and FFA_SUCCESS
  response won't be expected in return to a Direct Request call to set
  the memory attributes

 ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c | 88 +++++++++++++++-----
 1 file changed, 65 insertions(+), 23 deletions(-)

diff --git a/ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c b/ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c
index 14fe781630..a30369af9c 100644
--- a/ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c
+++ b/ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c
@@ -116,47 +116,89 @@ RequestMemoryPermissionChange (
   IN  UINTN                     Permissions
   )
 {
-  EFI_STATUS    Status;
+  INT32         Ret;
+  BOOLEAN       FfaEnabled;
   ARM_SVC_ARGS  ChangeMemoryPermissionsSvcArgs;
 
   ZeroMem (&ChangeMemoryPermissionsSvcArgs, sizeof (ARM_SVC_ARGS));
 
-  ChangeMemoryPermissionsSvcArgs.Arg0 = ARM_SVC_ID_SP_SET_MEM_ATTRIBUTES_AARCH64;
-  ChangeMemoryPermissionsSvcArgs.Arg1 = BaseAddress;
-  ChangeMemoryPermissionsSvcArgs.Arg2 = EFI_SIZE_TO_PAGES(Length);
-  ChangeMemoryPermissionsSvcArgs.Arg3 = Permissions;
+  FfaEnabled = FeaturePcdGet (PcdFfaEnable);
+
+  if (FfaEnabled) {
+    ChangeMemoryPermissionsSvcArgs.Arg0 = ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ_AARCH64;
+    ChangeMemoryPermissionsSvcArgs.Arg1 = ARM_FFA_DESTINATION_ENDPOINT_ID;
+    ChangeMemoryPermissionsSvcArgs.Arg2 = 0;
+    ChangeMemoryPermissionsSvcArgs.Arg3 = ARM_SVC_ID_SP_SET_MEM_ATTRIBUTES_AARCH64;
+    ChangeMemoryPermissionsSvcArgs.Arg4 = BaseAddress;
+    ChangeMemoryPermissionsSvcArgs.Arg5 = EFI_SIZE_TO_PAGES (Length);
+    ChangeMemoryPermissionsSvcArgs.Arg6 = Permissions;
+  } else {
+    ChangeMemoryPermissionsSvcArgs.Arg0 = ARM_SVC_ID_SP_SET_MEM_ATTRIBUTES_AARCH64;
+    ChangeMemoryPermissionsSvcArgs.Arg1 = BaseAddress;
+    ChangeMemoryPermissionsSvcArgs.Arg2 = EFI_SIZE_TO_PAGES (Length);
+    ChangeMemoryPermissionsSvcArgs.Arg3 = Permissions;
+  }
 
   ArmCallSvc (&ChangeMemoryPermissionsSvcArgs);
 
-  Status = ChangeMemoryPermissionsSvcArgs.Arg0;
+  if (FfaEnabled) {
+    // Setting memory attributes is an atomic call, with
+    // StandaloneMm at S-EL0 being the caller and the SPM
+    // core being the callee. Thus there won't be a
+    // FFA_INTERRUPT or FFA_SUCCESS response to the Direct
+    // Request sent above. This will have to be considered
+    // for other Direct Request calls which are not atomic
+    // We therefore check only for Direct Response by the
+    // callee.
+    if (ChangeMemoryPermissionsSvcArgs.Arg0 !=
+        ARM_SVC_ID_FFA_MSG_SEND_DIRECT_RESP_AARCH64) {
+      // If Arg0 is not a Direct Response, that means we
+      // have an FF-A error. We need to check Arg2 for the
+      // FF-A error code.
+      Ret = ChangeMemoryPermissionsSvcArgs.Arg2;
+      switch (Ret) {
+      case ARM_FFA_SPM_RET_INVALID_PARAMETERS:
+        return EFI_INVALID_PARAMETER;
 
-  switch (Status) {
-  case ARM_SVC_SPM_RET_SUCCESS:
-    Status = EFI_SUCCESS;
-    break;
+      case ARM_FFA_SPM_RET_DENIED:
+        return EFI_NOT_READY;
+
+      case ARM_FFA_SPM_RET_NOT_SUPPORTED:
+        return EFI_UNSUPPORTED;
+
+      case ARM_FFA_SPM_RET_BUSY:
+        return EFI_NOT_READY;
+
+      case ARM_FFA_SPM_RET_ABORTED:
+        return EFI_ABORTED;
+      }
+    } else if (ChangeMemoryPermissionsSvcArgs.Arg0 ==
+               ARM_SVC_ID_FFA_MSG_SEND_DIRECT_RESP_AARCH64) {
+      // A Direct Response means FF-A success
+      // Now check the payload for errors
+      // The callee sends back the return value
+      // in Arg3
+      Ret = ChangeMemoryPermissionsSvcArgs.Arg3;
+    }
+  } else {
+    Ret = ChangeMemoryPermissionsSvcArgs.Arg0;
+  }
 
+  switch (Ret) {
   case ARM_SVC_SPM_RET_NOT_SUPPORTED:
-    Status = EFI_UNSUPPORTED;
-    break;
+    return EFI_UNSUPPORTED;
 
   case ARM_SVC_SPM_RET_INVALID_PARAMS:
-    Status = EFI_INVALID_PARAMETER;
-    break;
+    return EFI_INVALID_PARAMETER;
 
   case ARM_SVC_SPM_RET_DENIED:
-    Status = EFI_ACCESS_DENIED;
-    break;
+    return EFI_ACCESS_DENIED;
 
   case ARM_SVC_SPM_RET_NO_MEMORY:
-    Status = EFI_BAD_BUFFER_SIZE;
-    break;
-
-  default:
-    Status = EFI_ACCESS_DENIED;
-    ASSERT (0);
+    return EFI_BAD_BUFFER_SIZE;
   }
 
-  return Status;
+  return EFI_SUCCESS;
 }
 
 EFI_STATUS
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v3 12/13] MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase to Pcd
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
                   ` (10 preceding siblings ...)
  2021-01-15  6:14 ` [PATCH v3 11/13] StandaloneMmMmuLib: Allow FF-A calls to set " Sughosh Ganu
@ 2021-01-15  6:14 ` Sughosh Ganu
  2021-01-15  6:14 ` [PATCH v3 13/13] StandaloneMmPkg: Allow sending FFA Direct Request message to StandaloneMm Sughosh Ganu
  2021-02-18  3:34 ` 回复: [edk2-devel] [PATCH v3 00/13] Add support for using FF-A calls gaoliming
  13 siblings, 0 replies; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:14 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas

From: Ilias Apalodimas <ilias.apalodimas@linaro.org>

Instead of running StMM in SPM, OP-TEE creates a new secure partition,
which emulates SPM and isolates StMM from the rest of the Trusted
Applications (TAs). We can then compile StMM as an FD image and run it
in OP-TEE. With the addition of a new RPMB driver, we can leverage OP-TEE
and store variables to an RPMB device.

Since EDK2 upper layers expect byte addressable code, for the RPMB to
work, we need to allocate memory and sync it with the hardware on
read/writes. Since DynamicPCDs are not supported in that context we
can only use PatchablePCDs. So let's switch them to Pcd instead of
FixedPcd and accomodate the new driver.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
---

Changes since V2: None

 MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
index fada0bf3c5..2a25fbdada 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
@@ -119,10 +119,12 @@
   ## SOMETIMES_PRODUCES   ## Variable:L"VarErrorFlag"
   gEdkiiVarErrorFlagGuid
 
-[FixedPcd]
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize       ## CONSUMES
+[Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase       ## SOMETIMES_CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64     ## CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize       ## CONSUMES
+
+[FixedPcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize                  ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize              ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize          ## CONSUMES
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH v3 13/13] StandaloneMmPkg: Allow sending FFA Direct Request message to StandaloneMm
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
                   ` (11 preceding siblings ...)
  2021-01-15  6:14 ` [PATCH v3 12/13] MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase to Pcd Sughosh Ganu
@ 2021-01-15  6:14 ` Sughosh Ganu
  2021-02-18  3:34 ` 回复: [edk2-devel] [PATCH v3 00/13] Add support for using FF-A calls gaoliming
  13 siblings, 0 replies; 23+ messages in thread
From: Sughosh Ganu @ 2021-01-15  6:14 UTC (permalink / raw)
  To: devel
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Sughosh Ganu

From: Ilias Apalodimas <ilias.apalodimas@linaro.org>

Allow passing of a request to StandaloneMm Core through the Firmware
Framework(FF-A) using FFA_MSG_SEND_DIRECT_REQ method. This method is
used as a mechanism for requesting some service from StandaloneMm.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
---

Changes since V2: None

 StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
index d86d21bb01..63fbe26642 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c
@@ -22,6 +22,7 @@
 #include <Guid/ZeroGuid.h>
 #include <Guid/MmramMemoryReserve.h>
 
+#include <IndustryStandard/ArmFfaSvc.h>
 #include <IndustryStandard/ArmStdSmc.h>
 
 #include "StandaloneMmCpu.h"
@@ -91,7 +92,8 @@ PiMmStandaloneArmTfCpuDriverEntry (
   // receipt of a synchronous MM request. Use the Event ID to distinguish
   // between synchronous and asynchronous events.
   //
-  if (ARM_SMC_ID_MM_COMMUNICATE_AARCH64 != EventId) {
+  if ((ARM_SMC_ID_MM_COMMUNICATE_AARCH64 != EventId) &&
+      (ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ_AARCH64 != EventId)) {
     DEBUG ((DEBUG_INFO, "UnRecognized Event - 0x%x\n", EventId));
     return EFI_INVALID_PARAMETER;
   }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [edk2-devel] [PATCH v3 05/13] StandaloneMmPkg: Add macros for SPM version
  2021-01-15  6:13 ` [PATCH v3 05/13] StandaloneMmPkg: Add macros for SPM version Sughosh Ganu
@ 2021-01-20 18:34   ` Sami Mujawar
  0 siblings, 0 replies; 23+ messages in thread
From: Sami Mujawar @ 2021-01-20 18:34 UTC (permalink / raw)
  To: Sughosh Ganu, devel

[-- Attachment #1: Type: text/plain, Size: 78 bytes --]

Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>

Regards,

Sami Mujawar

[-- Attachment #2: Type: text/html, Size: 100 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [edk2-devel] [PATCH v3 06/13] StandaloneMmPkg: Add the SPM version for FF-A
  2021-01-15  6:13 ` [PATCH v3 06/13] StandaloneMmPkg: Add the SPM version for FF-A Sughosh Ganu
@ 2021-01-20 18:38   ` Sami Mujawar
  0 siblings, 0 replies; 23+ messages in thread
From: Sami Mujawar @ 2021-01-20 18:38 UTC (permalink / raw)
  To: Sughosh Ganu, devel

[-- Attachment #1: Type: text/plain, Size: 78 bytes --]

Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>

Regards,

Sami Mujawar

[-- Attachment #2: Type: text/html, Size: 100 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [edk2-devel] [PATCH v3 08/13] StandaloneMmPkg: Add option to use FF-A calls for communication with SPM
  2021-01-15  6:13 ` [PATCH v3 08/13] StandaloneMmPkg: Add option to use FF-A calls for communication with SPM Sughosh Ganu
@ 2021-01-20 18:44   ` Sami Mujawar
  0 siblings, 0 replies; 23+ messages in thread
From: Sami Mujawar @ 2021-01-20 18:44 UTC (permalink / raw)
  To: Sughosh Ganu, devel

[-- Attachment #1: Type: text/plain, Size: 78 bytes --]

Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>

Regards,

Sami Mujawar

[-- Attachment #2: Type: text/html, Size: 100 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [edk2-devel] [PATCH v3 10/13] StandaloneMmMmuLib: Allow FF-A calls to get memory region's attributes
  2021-01-15  6:14 ` [PATCH v3 10/13] StandaloneMmMmuLib: Allow FF-A calls to get memory region's attributes Sughosh Ganu
@ 2021-01-20 18:49   ` Sami Mujawar
  0 siblings, 0 replies; 23+ messages in thread
From: Sami Mujawar @ 2021-01-20 18:49 UTC (permalink / raw)
  To: Sughosh Ganu, devel

[-- Attachment #1: Type: text/plain, Size: 78 bytes --]

Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>

Regards,

Sami Mujawar

[-- Attachment #2: Type: text/html, Size: 100 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [edk2-devel] [PATCH v3 11/13] StandaloneMmMmuLib: Allow FF-A calls to set memory region's attributes
  2021-01-15  6:14 ` [PATCH v3 11/13] StandaloneMmMmuLib: Allow FF-A calls to set " Sughosh Ganu
@ 2021-01-20 18:52   ` Sami Mujawar
  0 siblings, 0 replies; 23+ messages in thread
From: Sami Mujawar @ 2021-01-20 18:52 UTC (permalink / raw)
  To: Sughosh Ganu, devel

[-- Attachment #1: Type: text/plain, Size: 78 bytes --]

Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>

Regards,

Sami Mujawar

[-- Attachment #2: Type: text/html, Size: 100 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [edk2-devel] [PATCH v3 02/13] ArmPkg/ArmSvcLib: Return x4-x7 in output parameters
  2021-01-15  6:13 ` [PATCH v3 02/13] ArmPkg/ArmSvcLib: Return x4-x7 in output parameters Sughosh Ganu
@ 2021-02-13 10:28   ` Ard Biesheuvel
  0 siblings, 0 replies; 23+ messages in thread
From: Ard Biesheuvel @ 2021-02-13 10:28 UTC (permalink / raw)
  To: devel, Sughosh Ganu
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Achin Gupta

On Fri, 15 Jan 2021 at 07:14, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
>
> From: Achin Gupta <achin.gupta@arm.com>
>
> The Arm SMC calling convention standard v1.2 allows 8 input and output
> parameter registers. The FF-A specification relies on this
> communication. This patch extends the number of output registers
> returned by ArmCallSvc() to match this convention.
>
> Signed-off-by: Achin Gupta <achin.gupta@arm.com>
> Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>
> Changes since V2: None
>
>  ArmPkg/Include/Library/ArmSvcLib.h        | 10 ++++++++--
>  ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S |  4 +++-
>  2 files changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/ArmPkg/Include/Library/ArmSvcLib.h b/ArmPkg/Include/Library/ArmSvcLib.h
> index a94ead1965..a4414270f3 100644
> --- a/ArmPkg/Include/Library/ArmSvcLib.h
> +++ b/ArmPkg/Include/Library/ArmSvcLib.h
> @@ -27,10 +27,16 @@ typedef struct {
>  /**
>    Trigger an SVC call
>
> -  SVC calls can take up to 7 arguments and return up to 4 return values.
> -  Therefore, the 4 first fields in the ARM_SVC_ARGS structure are used
> +  SVC calls can take up to 8 arguments and return up to 8 return values.
> +  Therefore, the 8 first fields in the ARM_SVC_ARGS structure are used
>    for both input and output values.
>
> +  @param[in, out]    Args Arguments to be passed as part of the SVC call
> +                     The return values of the SVC call are also placed
> +                     in the same structure
> +
> +  @retval None
> +
>  **/
>  VOID
>  ArmCallSvc (
> diff --git a/ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S b/ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S
> index ee265f94b9..1a7c10cb79 100644
> --- a/ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S
> +++ b/ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S
> @@ -33,9 +33,11 @@ ASM_PFX(ArmCallSvc):
>    ldr   x9, [sp, #16]
>
>    // Store the SVC returned values into the ARM_SVC_ARGS structure.
> -  // A SVC call can return up to 4 values - we do not need to store back x4-x7.
> +  // A SVC call can return up to 8 values
>    stp   x0, x1, [x9, #0]
>    stp   x2, x3, [x9, #16]
> +  stp   x4, x5, [x9, #32]
> +  stp   x6, x7, [x9, #48]
>
>    mov   x0, x9
>
> --
> 2.17.1
>
>
>
> 
>
>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [edk2-devel] [PATCH v3 01/13] ArmPkg/IndustryStandard: Add barebones FF-A header
  2021-01-15  6:13 ` [PATCH v3 01/13] ArmPkg/IndustryStandard: Add barebones FF-A header Sughosh Ganu
@ 2021-02-13 10:28   ` Ard Biesheuvel
  0 siblings, 0 replies; 23+ messages in thread
From: Ard Biesheuvel @ 2021-02-13 10:28 UTC (permalink / raw)
  To: devel, Sughosh Ganu
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas, Achin Gupta

On Fri, 15 Jan 2021 at 07:14, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
>
> From: Achin Gupta <achin.gupta@arm.com>
>
> This patch adds a rudimentary header file with defines for FF-A ABIs
> that will be used as the transport between S-EL0 and the SPM
>
> Signed-off-by: Achin Gupta <achin.gupta@arm.com>
> Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>
> Changes since V2: None
>
>  ArmPkg/Include/IndustryStandard/ArmFfaSvc.h | 23 ++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git a/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h b/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
> new file mode 100644
> index 0000000000..1eadf48ab5
> --- /dev/null
> +++ b/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
> @@ -0,0 +1,23 @@
> +/** @file
> +  Header file for FF-A ABI's that will be used for
> +  communication between S-EL0 and the Secure Partition
> +  Manager(SPM)
> +
> +  Copyright (c) 2020, ARM Limited. All rights reserved.
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +  @par Revision Reference:
> +    - FF-A Version 1.0
> +
> +
> +**/
> +
> +#ifndef ARM_FFA_SVC_H_
> +#define ARM_FFA_SVC_H_
> +
> +#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
> +
> +#endif // ARM_FFA_SVC_H_
> --
> 2.17.1
>
>
>
> 
>
>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [edk2-devel] [PATCH v3 04/13] ArmPkg: Introduce support for PcdFfaEnable
  2021-01-15  6:13 ` [PATCH v3 04/13] ArmPkg: Introduce support for PcdFfaEnable Sughosh Ganu
@ 2021-02-13 10:29   ` Ard Biesheuvel
  0 siblings, 0 replies; 23+ messages in thread
From: Ard Biesheuvel @ 2021-02-13 10:29 UTC (permalink / raw)
  To: devel, Sughosh Ganu
  Cc: Sami Mujawar, Ard Biesheuvel, Leif Lindholm, Sahil Malhotra,
	Ilias Apalodimas

On Fri, 15 Jan 2021 at 07:14, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
>
> The Secure Partition(SP) can request services from the Secure
> Partition Manager Core(SPMC) either through FF-A calls or through the
> existing SVC calls. Add a feature flag Pcd for enabling the FF-A
> method -- when this is set to FALSE, the SP uses the existing SVC
> calls for making the requests.
>
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>
> Changes since V2: None
>
>  ArmPkg/ArmPkg.dec | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec
> index eaf1072d9e..507e16844c 100644
> --- a/ArmPkg/ArmPkg.dec
> +++ b/ArmPkg/ArmPkg.dec
> @@ -78,6 +78,12 @@
>    # Define if the GICv3 controller should use the GICv2 legacy
>    gArmTokenSpaceGuid.PcdArmGicV3WithV2Legacy|FALSE|BOOLEAN|0x00000042
>
> +  ## Used to select method for requesting services from S-EL1.<BR><BR
> +  #   TRUE  - Selects FF-A calls for communication between S-EL0 and SPMC.<BR>
> +  #   FALSE - Selects SVC calls for communication between S-EL0 and SPMC.<BR>
> +  # @Prompt Enable FF-A support.
> +  gArmTokenSpaceGuid.PcdFfaEnable|FALSE|BOOLEAN|0x0000005B
> +
>  [PcdsFeatureFlag.ARM]
>    # Whether to map normal memory as non-shareable. FALSE is the safe choice, but
>    # TRUE may be appropriate to fix performance problems if you don't care about
> --
> 2.17.1
>
>
>
> 
>
>

^ permalink raw reply	[flat|nested] 23+ messages in thread

* 回复: [edk2-devel] [PATCH v3 00/13] Add support for using FF-A calls
  2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
                   ` (12 preceding siblings ...)
  2021-01-15  6:14 ` [PATCH v3 13/13] StandaloneMmPkg: Allow sending FFA Direct Request message to StandaloneMm Sughosh Ganu
@ 2021-02-18  3:34 ` gaoliming
  13 siblings, 0 replies; 23+ messages in thread
From: gaoliming @ 2021-02-18  3:34 UTC (permalink / raw)
  To: devel, sughosh.ganu
  Cc: 'Sami Mujawar', 'Ard Biesheuvel',
	'Leif Lindholm', 'Sahil Malhotra',
	'Ilias Apalodimas'

Sughosh:
  This is a new feature. Can you submit one BZ
(https://bugzilla.tianocore.org/) to record it?

Thanks
Liming
> -----邮件原件-----
> 发件人: bounce+27952+70357+4905953+8761045@groups.io
> <bounce+27952+70357+4905953+8761045@groups.io> 代表 Sughosh Ganu
> 发送时间: 2021年1月15日 14:14
> 收件人: devel@edk2.groups.io
> 抄送: Sami Mujawar <sami.mujawar@arm.com>; Ard Biesheuvel
> <ard.biesheuvel@arm.com>; Leif Lindholm <leif@nuviainc.com>; Sahil
> Malhotra <sahil.malhotra@linaro.org>; Ilias Apalodimas
> <ilias.apalodimas@linaro.org>
> 主题: [edk2-devel] [PATCH v3 00/13] Add support for using FF-A calls
> 
> 
> The following patch series adds support for using the Firmware
> Framework(FF-A) as a transport mechanism for requesting services from
> the Secure Partition Manager(SPM). This is done through a Pcd which
> can be used to enable the FF-A mechanism or to use the earlier used
> SVC calls.
> 
> The patches have been pushed to my github repository[1]
> 
> Changes since V2:
> * Added a STATIC storage class specifier for mSpmMajorVer and
>   mSpmMinorVer variables
> * Added a STATIC storage class specifier for mSpmMajorVerFfa and
>   mSpmMinorVerFfa variables
> * Add braces for if/else statements
> * Add a check for EFI_NOT_FOUND as a possible return value from
>   LocateStandaloneMmCorePeCoffData in _ModuleEntryPoint function
> * Check for the return value in Arg0 after the Direct Request call to
>   handle errors returned
> * Put a comment to reflect the fact that FFA_INTERRUPT and FFA_SUCCESS
>   response won't be expected in return to a Direct Request call to get
>   the memory attributes
> * Check for the return value in Arg0 after the Direct Request call to
>   handle errors returned
> * Put a comment to reflect the fact that FFA_INTERRUPT and FFA_SUCCESS
>   response won't be expected in return to a Direct Request call to set
>   the memory attributes
> 
> Changes since V1:
> Handled review comments from Sami Mujawar
> 
> [1] -
> https://github.com/SNG-ARM/edk2/tree/implement_ffa_svc_optional_v3
> 
> Achin Gupta (7):
>   ArmPkg/IndustryStandard: Add barebones FF-A header
>   ArmPkg/ArmSvcLib: Return x4-x7 in output parameters
>   StandaloneMmPkg: Use FF-A header file in Standalone MM Core entry
>     point
>   StandaloneMmPkg: Add option to use FF-A calls for communication with
>     SPM
>   StandaloneMmPkg: Use FF-A header file in Standalone MM Arm MMU
> library
>   StandaloneMmMmuLib: Allow FF-A calls to get memory region's attributes
>   StandaloneMmMmuLib: Allow FF-A calls to set memory region's attributes
> 
> Ilias Apalodimas (2):
>   MdeModulePkg/VariableStandaloneMm: Set
> PcdFlashNvStorageVariableBase
>     to Pcd
>   StandaloneMmPkg: Allow sending FFA Direct Request message to
>     StandaloneMm
> 
> Sughosh Ganu (4):
>   ArmPkg: Introduce support for PcdFfaEnable
>   StandaloneMmPkg: Add macros for SPM version
>   StandaloneMmPkg: Add the SPM version for FF-A
>   StandaloneMmPkg: Add option to use FF-A calls for getting SPM version
> 
>  ArmPkg/ArmPkg.dec                             |   6 +
>  .../ArmMmuStandaloneMmLib.inf                 |   3 +
>  .../RuntimeDxe/VariableStandaloneMm.inf       |   6 +-
>  .../StandaloneMmCoreEntryPoint.inf            |   3 +
>  ArmPkg/Include/IndustryStandard/ArmFfaSvc.h   |  44 +++++
>  ArmPkg/Include/IndustryStandard/ArmMmSvc.h    |   3 +
>  ArmPkg/Include/Library/ArmSvcLib.h            |  10 +-
>  .../AArch64/ArmMmuStandaloneMmLib.c           | 167
> +++++++++++++++---
>  .../StandaloneMmCpu/AArch64/EventHandle.c     |   4 +-
>  .../AArch64/StandaloneMmCoreEntryPoint.c      | 133 +++++++++++---
>  ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S     |   4 +-
>  11 files changed, 322 insertions(+), 61 deletions(-)
>  create mode 100644 ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
> 
> --
> 2.17.1
> 
> 
> 
> 
> 
> 




^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2021-02-18  3:35 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-15  6:13 [PATCH v3 00/13] Add support for using FF-A calls Sughosh Ganu
2021-01-15  6:13 ` [PATCH v3 01/13] ArmPkg/IndustryStandard: Add barebones FF-A header Sughosh Ganu
2021-02-13 10:28   ` [edk2-devel] " Ard Biesheuvel
2021-01-15  6:13 ` [PATCH v3 02/13] ArmPkg/ArmSvcLib: Return x4-x7 in output parameters Sughosh Ganu
2021-02-13 10:28   ` [edk2-devel] " Ard Biesheuvel
2021-01-15  6:13 ` [PATCH v3 03/13] StandaloneMmPkg: Use FF-A header file in Standalone MM Core entry point Sughosh Ganu
2021-01-15  6:13 ` [PATCH v3 04/13] ArmPkg: Introduce support for PcdFfaEnable Sughosh Ganu
2021-02-13 10:29   ` [edk2-devel] " Ard Biesheuvel
2021-01-15  6:13 ` [PATCH v3 05/13] StandaloneMmPkg: Add macros for SPM version Sughosh Ganu
2021-01-20 18:34   ` [edk2-devel] " Sami Mujawar
2021-01-15  6:13 ` [PATCH v3 06/13] StandaloneMmPkg: Add the SPM version for FF-A Sughosh Ganu
2021-01-20 18:38   ` [edk2-devel] " Sami Mujawar
2021-01-15  6:13 ` [PATCH v3 07/13] StandaloneMmPkg: Add option to use FF-A calls for getting SPM version Sughosh Ganu
2021-01-15  6:13 ` [PATCH v3 08/13] StandaloneMmPkg: Add option to use FF-A calls for communication with SPM Sughosh Ganu
2021-01-20 18:44   ` [edk2-devel] " Sami Mujawar
2021-01-15  6:14 ` [PATCH v3 09/13] StandaloneMmPkg: Use FF-A header file in Standalone MM Arm MMU library Sughosh Ganu
2021-01-15  6:14 ` [PATCH v3 10/13] StandaloneMmMmuLib: Allow FF-A calls to get memory region's attributes Sughosh Ganu
2021-01-20 18:49   ` [edk2-devel] " Sami Mujawar
2021-01-15  6:14 ` [PATCH v3 11/13] StandaloneMmMmuLib: Allow FF-A calls to set " Sughosh Ganu
2021-01-20 18:52   ` [edk2-devel] " Sami Mujawar
2021-01-15  6:14 ` [PATCH v3 12/13] MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase to Pcd Sughosh Ganu
2021-01-15  6:14 ` [PATCH v3 13/13] StandaloneMmPkg: Allow sending FFA Direct Request message to StandaloneMm Sughosh Ganu
2021-02-18  3:34 ` 回复: [edk2-devel] [PATCH v3 00/13] Add support for using FF-A calls gaoliming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox