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

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]

Ran the CI tests through the github draft pull request, and all the CI
test pass. Ran the PatchCheck script, with no errors.

Changes since V3:
* Put the PcdFfaEnable under the PcdsFeatureFlag.AARCH64 section to
  avoid build breakage for the X64 StandaloneMm builds.
* Put the macro definitions for the SPM major and minor versions in a
  separate patch, as suggested by Sami.
* Separated out the declaration of the SPM major and minor version
  macros in the earlier patch as was suggested by Sami.
* Put the macro definitions for the SPM major and minor versions with
  FF-A support in a separate patch, as suggested by Sami.
* Declare the PcdFfaEnable Pcd Feature flag under FeaturePcd.AARCH64
  to avoid build break for the X64 build of StandaloneMm.
* Change the patch header to have the ArmPkg prefix instead of
  StandaloneMmMmuLib as suggested by Sami.

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/sughoshg/edk2/tree/implement_ffa_svc_optional_v4

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
  ArmPkg: Use FF-A header file in Standalone MM Arm MMU library
  ArmPkg: Allow FF-A calls to get memory region's attributes
  ArmPkg: 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 (5):
  ArmPkg: Introduce support for PcdFfaEnable
  ArmPkg: Add macros for SPM version
  StandaloneMmPkg: Use macros for SPM version check
  ArmPkg: Add macros for SPM version with FF-A support enabled
  StandaloneMmPkg: Add option to use FF-A calls for getting SPM version

 ArmPkg/ArmPkg.dec                             |   7 +
 .../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, 323 insertions(+), 61 deletions(-)
 create mode 100644 ArmPkg/Include/IndustryStandard/ArmFfaSvc.h

-- 
2.17.1



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

* [PATCH v4 01/14] ArmPkg/IndustryStandard: Add barebones FF-A header
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 02/14] ArmPkg/ArmSvcLib: Return x4-x7 in output parameters Sughosh Ganu
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel, 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>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
---

Changes since V3: 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] 18+ messages in thread

* [PATCH v4 02/14] ArmPkg/ArmSvcLib: Return x4-x7 in output parameters
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 01/14] ArmPkg/IndustryStandard: Add barebones FF-A header Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 03/14] StandaloneMmPkg: Use FF-A header file in Standalone MM Core entry point Sughosh Ganu
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel, 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>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
---

Changes since V3: 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] 18+ messages in thread

* [PATCH v4 03/14] StandaloneMmPkg: Use FF-A header file in Standalone MM Core entry point
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 01/14] ArmPkg/IndustryStandard: Add barebones FF-A header Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 02/14] ArmPkg/ArmSvcLib: Return x4-x7 in output parameters Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 04/14] ArmPkg: Introduce support for PcdFfaEnable Sughosh Ganu
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel, 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 V3: 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] 18+ messages in thread

* [PATCH v4 04/14] ArmPkg: Introduce support for PcdFfaEnable
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
                   ` (2 preceding siblings ...)
  2021-02-17 11:27 ` [PATCH v4 03/14] StandaloneMmPkg: Use FF-A header file in Standalone MM Core entry point Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 05/14] ArmPkg: Add macros for SPM version Sughosh Ganu
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel, 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>
---

Changes since V3:
* Put the PcdFfaEnable under the PcdsFeatureFlag.AARCH64 section to
  avoid build breakage for the X64 StandaloneMm builds.

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

diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec
index f0b136a57a..a8a22c649f 100644
--- a/ArmPkg/ArmPkg.dec
+++ b/ArmPkg/ArmPkg.dec
@@ -84,6 +84,13 @@
   # hardware coherency (i.e., no virtualization or cache coherent DMA)
   gArmTokenSpaceGuid.PcdNormalMemoryNonshareableOverride|FALSE|BOOLEAN|0x00000043
 
+[PcdsFeatureFlag.AARCH64]
+  ## 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
+
 [PcdsFixedAtBuild.common]
   gArmTokenSpaceGuid.PcdTrustzoneSupport|FALSE|BOOLEAN|0x00000006
 
-- 
2.17.1


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

* [PATCH v4 05/14] ArmPkg: Add macros for SPM version
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
                   ` (3 preceding siblings ...)
  2021-02-17 11:27 ` [PATCH v4 04/14] ArmPkg: Introduce support for PcdFfaEnable Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 06/14] StandaloneMmPkg: Use macros for SPM version check Sughosh Ganu
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel, Sughosh Ganu

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

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

Changes since V3:
* Put the macro definitions for the SPM major and minor versions in a
  separate patch, as suggested by Sami.

 ArmPkg/Include/IndustryStandard/ArmMmSvc.h | 3 +++
 1 file changed, 3 insertions(+)

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
-- 
2.17.1


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

* [PATCH v4 06/14] StandaloneMmPkg: Use macros for SPM version check
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
                   ` (4 preceding siblings ...)
  2021-02-17 11:27 ` [PATCH v4 05/14] ArmPkg: Add macros for SPM version Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 07/14] ArmPkg: Add macros for SPM version with FF-A support enabled Sughosh Ganu
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel, Sughosh Ganu

Declare module wide variables for SPM major and minor versions to be
used in checking the SPM version compatibility. Use the SPM major and
minor version macros declared in the previous patch for the version
check.

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

Changes since V3:
* Separate out the declaration of the SPM major and minor version
  macros in the earlier patch as was suggested by Sami.

 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

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] 18+ messages in thread

* [PATCH v4 07/14] ArmPkg: Add macros for SPM version with FF-A support enabled
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
                   ` (5 preceding siblings ...)
  2021-02-17 11:27 ` [PATCH v4 06/14] StandaloneMmPkg: Use macros for SPM version check Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 08/14] StandaloneMmPkg: Add option to use FF-A calls for getting SPM version Sughosh Ganu
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel, Sughosh Ganu

Declare the values of SPM major and minor versions as macros with FF-A
enabled, which can be used in the module for checking the SPM version
compatibility. These SPM major and minor version numbers are mandated
for having support for the Firmware Framework(FF-A) feature enabled.

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

Changes since V3:
* Put the macro definitions for the SPM major and minor versions with
  FF-A support in a separate patch, as suggested by Sami.

 ArmPkg/Include/IndustryStandard/ArmFfaSvc.h | 3 +++
 1 file changed, 3 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_
-- 
2.17.1


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

* [PATCH v4 08/14] StandaloneMmPkg: Add option to use FF-A calls for getting SPM version
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
                   ` (6 preceding siblings ...)
  2021-02-17 11:27 ` [PATCH v4 07/14] ArmPkg: Add macros for SPM version with FF-A support enabled Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 09/14] StandaloneMmPkg: Add option to use FF-A calls for communication with SPM Sughosh Ganu
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel, 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>
---

Changes since V3:
* Declare the PcdFfaEnable Pcd Feature flag under FeaturePcd.AARCH64
  to avoid build break for the X64 build of StandaloneMm.

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

diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
index 313bc6f7bd..4fa426f58e 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
@@ -51,5 +51,8 @@
   gEfiStandaloneMmNonSecureBufferGuid
   gEfiArmTfCpuDriverEpDescriptorGuid
 
+[FeaturePcd.AARCH64]
+  gArmTokenSpaceGuid.PcdFfaEnable
+
 [BuildOptions]
   GCC:*_*_*_CC_FLAGS = -fpie
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/AArch64/StandaloneMmCoreEntryPoint.c
index 2643473e88..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,10 +32,14 @@ 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 BOOT_PAYLOAD_VERSION      1
 
 PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT      CpuDriverEntryPoint = NULL;
@@ -175,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
@@ -196,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] 18+ messages in thread

* [PATCH v4 09/14] StandaloneMmPkg: Add option to use FF-A calls for communication with SPM
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
                   ` (7 preceding siblings ...)
  2021-02-17 11:27 ` [PATCH v4 08/14] StandaloneMmPkg: Add option to use FF-A calls for getting SPM version Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 10/14] ArmPkg: Use FF-A header file in Standalone MM Arm MMU library Sughosh Ganu
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel, 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>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
---

Changes since V3: None

 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] 18+ messages in thread

* [PATCH v4 10/14] ArmPkg: Use FF-A header file in Standalone MM Arm MMU library
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
                   ` (8 preceding siblings ...)
  2021-02-17 11:27 ` [PATCH v4 09/14] StandaloneMmPkg: Add option to use FF-A calls for communication with SPM Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 11/14] ArmPkg: Allow FF-A calls to get memory region's attributes Sughosh Ganu
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel, 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 V3: 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] 18+ messages in thread

* [PATCH v4 11/14] ArmPkg: Allow FF-A calls to get memory region's attributes
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
                   ` (9 preceding siblings ...)
  2021-02-17 11:27 ` [PATCH v4 10/14] ArmPkg: Use FF-A header file in Standalone MM Arm MMU library Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 12/14] ArmPkg: Allow FF-A calls to set " Sughosh Ganu
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel, 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 V3:
* Change the patch header to have the ArmPkg prefix instead of
  StandaloneMmMmuLib as suggested by Sami.
* Put the PcdFfaEnable flag under FeaturePcd.AARCH64

 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..89dda509c5 100644
--- a/ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf
+++ b/ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf
@@ -23,6 +23,9 @@
   ArmPkg/ArmPkg.dec
   MdePkg/MdePkg.dec
 
+[FeaturePcd.AARCH64]
+  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] 18+ messages in thread

* [PATCH v4 12/14] ArmPkg: Allow FF-A calls to set memory region's attributes
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
                   ` (10 preceding siblings ...)
  2021-02-17 11:27 ` [PATCH v4 11/14] ArmPkg: Allow FF-A calls to get memory region's attributes Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 13/14] MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase to Pcd Sughosh Ganu
  2021-02-17 11:27 ` [PATCH v4 14/14] StandaloneMmPkg: Allow sending FFA Direct Request message to StandaloneMm Sughosh Ganu
  13 siblings, 0 replies; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel, 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>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
---

Changes since V3:
* Change the patch header to have the ArmPkg prefix instead of
  StandaloneMmMmuLib as suggested by Sami.

 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] 18+ messages in thread

* [PATCH v4 13/14] MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase to Pcd
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
                   ` (11 preceding siblings ...)
  2021-02-17 11:27 ` [PATCH v4 12/14] ArmPkg: Allow FF-A calls to set " Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  2021-02-18  3:13   ` 回复: [edk2-devel] " gaoliming
  2021-02-17 11:27 ` [PATCH v4 14/14] StandaloneMmPkg: Allow sending FFA Direct Request message to StandaloneMm Sughosh Ganu
  13 siblings, 1 reply; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel

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 V3: 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] 18+ messages in thread

* [PATCH v4 14/14] StandaloneMmPkg: Allow sending FFA Direct Request message to StandaloneMm
  2021-02-17 11:27 [PATCH v4 00/14] Add support for using FF-A calls Sughosh Ganu
                   ` (12 preceding siblings ...)
  2021-02-17 11:27 ` [PATCH v4 13/14] MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase to Pcd Sughosh Ganu
@ 2021-02-17 11:27 ` Sughosh Ganu
  13 siblings, 0 replies; 18+ messages in thread
From: Sughosh Ganu @ 2021-02-17 11:27 UTC (permalink / raw)
  To: devel; +Cc: Sami Mujawar, Ilias Apalodimas, Ard Biesheuvel, 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 V3: 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] 18+ messages in thread

* 回复: [edk2-devel] [PATCH v4 13/14] MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase to Pcd
  2021-02-17 11:27 ` [PATCH v4 13/14] MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase to Pcd Sughosh Ganu
@ 2021-02-18  3:13   ` gaoliming
  2021-02-18  9:17     ` Ilias Apalodimas
  0 siblings, 1 reply; 18+ messages in thread
From: gaoliming @ 2021-02-18  3:13 UTC (permalink / raw)
  To: devel, sughosh.ganu
  Cc: 'Sami Mujawar', 'Ilias Apalodimas',
	'Ard Biesheuvel'

I suggest to directly change [FixedPcd] to [Pcd] section. All Pcds can
support FixedAtBuild and PatchableInModule. 

With this change, Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>

Thanks
Liming
> -----邮件原件-----
> 发件人: bounce+27952+71734+4905953+8761045@groups.io
> <bounce+27952+71734+4905953+8761045@groups.io> 代表 Sughosh Ganu
> 发送时间: 2021年2月17日 19:27
> 收件人: devel@edk2.groups.io
> 抄送: Sami Mujawar <sami.mujawar@arm.com>; Ilias Apalodimas
> <ilias.apalodimas@linaro.org>; Ard Biesheuvel <ardb+tianocore@kernel.org>
> 主题: [edk2-devel] [PATCH v4 13/14] MdeModulePkg/VariableStandaloneMm:
> Set PcdFlashNvStorageVariableBase to Pcd
> 
> 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 V3: None
> 
>  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
> | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git
> a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.in
> f
> b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.in
> f
> index fada0bf3c5..2a25fbdada 100644
> ---
> a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.in
> f
> +++
> b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.in
> f
> @@ -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	[flat|nested] 18+ messages in thread

* Re: 回复: [edk2-devel] [PATCH v4 13/14] MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase to Pcd
  2021-02-18  3:13   ` 回复: [edk2-devel] " gaoliming
@ 2021-02-18  9:17     ` Ilias Apalodimas
  2021-02-19  1:15       ` 回复: " gaoliming
  0 siblings, 1 reply; 18+ messages in thread
From: Ilias Apalodimas @ 2021-02-18  9:17 UTC (permalink / raw)
  To: devel, gaoliming
  Cc: sughosh.ganu, 'Sami Mujawar', 'Ard Biesheuvel'

On Thu, Feb 18, 2021 at 11:13:21AM +0800, gaoliming wrote:
> I suggest to directly change [FixedPcd] to [Pcd] section. All Pcds can
> support FixedAtBuild and PatchableInModule. 

We can, but is there a reason to do that?
Wouldn't we be better of being more strict on the Pcd context we define for
each variable?

The values that were swapped from FixedPcd to Pcd are expected to change in
runtime, while the rest don't.

Thanks
/Ilias

> 
> With this change, Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
> 
> Thanks
> Liming
> > -----邮件原件-----
> > 发件人: bounce+27952+71734+4905953+8761045@groups.io
> > <bounce+27952+71734+4905953+8761045@groups.io> 代表 Sughosh Ganu
> > 发送时间: 2021年2月17日 19:27
> > 收件人: devel@edk2.groups.io
> > 抄送: Sami Mujawar <sami.mujawar@arm.com>; Ilias Apalodimas
> > <ilias.apalodimas@linaro.org>; Ard Biesheuvel <ardb+tianocore@kernel.org>
> > 主题: [edk2-devel] [PATCH v4 13/14] MdeModulePkg/VariableStandaloneMm:
> > Set PcdFlashNvStorageVariableBase to Pcd
> > 
> > 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 V3: None
> > 
> >  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
> > | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git
> > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.in
> > f
> > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.in
> > f
> > index fada0bf3c5..2a25fbdada 100644
> > ---
> > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.in
> > f
> > +++
> > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.in
> > f
> > @@ -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	[flat|nested] 18+ messages in thread

* 回复: 回复: [edk2-devel] [PATCH v4 13/14] MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase to Pcd
  2021-02-18  9:17     ` Ilias Apalodimas
@ 2021-02-19  1:15       ` gaoliming
  0 siblings, 0 replies; 18+ messages in thread
From: gaoliming @ 2021-02-19  1:15 UTC (permalink / raw)
  To: 'Ilias Apalodimas', devel
  Cc: sughosh.ganu, 'Sami Mujawar', 'Ard Biesheuvel'

Ilias:
 If you check other Variable module INF file, you can find they all use [Pcd] section. Module provides the flexibility instead of the limitation. In fact, variable module code has no fixed pcd usage. Platform can decide which PCD type should be used. In future, if other PCD is required to be configured as patchable in module, you don't need to modify variable INF again. 

Thanks
Liming
> -----邮件原件-----
> 发件人: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> 发送时间: 2021年2月18日 17:17
> 收件人: devel@edk2.groups.io; gaoliming@byosoft.com.cn
> 抄送: sughosh.ganu@linaro.org; 'Sami Mujawar' <sami.mujawar@arm.com>;
> 'Ard Biesheuvel' <ardb+tianocore@kernel.org>
> 主题: Re: 回复: [edk2-devel] [PATCH v4 13/14]
> MdeModulePkg/VariableStandaloneMm: Set PcdFlashNvStorageVariableBase
> to Pcd
> 
> On Thu, Feb 18, 2021 at 11:13:21AM +0800, gaoliming wrote:
> > I suggest to directly change [FixedPcd] to [Pcd] section. All Pcds can
> > support FixedAtBuild and PatchableInModule.
> 
> We can, but is there a reason to do that?
> Wouldn't we be better of being more strict on the Pcd context we define for
> each variable?
> 
> The values that were swapped from FixedPcd to Pcd are expected to change
> in
> runtime, while the rest don't.
> 
> Thanks
> /Ilias
> 
> >
> > With this change, Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
> >
> > Thanks
> > Liming
> > > -----邮件原件-----
> > > 发件人: bounce+27952+71734+4905953+8761045@groups.io
> > > <bounce+27952+71734+4905953+8761045@groups.io> 代表 Sughosh
> Ganu
> > > 发送时间: 2021年2月17日 19:27
> > > 收件人: devel@edk2.groups.io
> > > 抄送: Sami Mujawar <sami.mujawar@arm.com>; Ilias Apalodimas
> > > <ilias.apalodimas@linaro.org>; Ard Biesheuvel
> <ardb+tianocore@kernel.org>
> > > 主题: [edk2-devel] [PATCH v4 13/14]
> MdeModulePkg/VariableStandaloneMm:
> > > Set PcdFlashNvStorageVariableBase to Pcd
> > >
> > > 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 V3: None
> > >
> > >
> MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
> > > | 6 ++++--
> > >  1 file changed, 4 insertions(+), 2 deletions(-)
> > >
> > > diff --git
> > >
> a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.in
> > > f
> > >
> b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.in
> > > f
> > > index fada0bf3c5..2a25fbdada 100644
> > > ---
> > >
> a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.in
> > > f
> > > +++
> > >
> b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.in
> > > f
> > > @@ -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	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-02-19  1:16 UTC | newest]

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

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