]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg: Allow FF-A calls to set memory region's attributes
authorAchin Gupta <achin.gupta@arm.com>
Fri, 19 Feb 2021 06:36:05 +0000 (12:06 +0530)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 23 Feb 2021 15:40:37 +0000 (15:40 +0000)
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>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c

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