From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.6165.1613561271065429211 for ; Wed, 17 Feb 2021 03:27:51 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=softfail (domain: linaro.org, ip: 217.140.110.172, mailfrom: sughosh.ganu@linaro.org) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B03DD106F; Wed, 17 Feb 2021 03:27:50 -0800 (PST) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.16.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EEC913F73B; Wed, 17 Feb 2021 03:27:48 -0800 (PST) From: "Sughosh Ganu" To: devel@edk2.groups.io Cc: Sami Mujawar , Ilias Apalodimas , Ard Biesheuvel , Achin Gupta Subject: [PATCH v4 11/14] ArmPkg: Allow FF-A calls to get memory region's attributes Date: Wed, 17 Feb 2021 16:57:14 +0530 Message-Id: <20210217112717.6820-12-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210217112717.6820-1-sughosh.ganu@linaro.org> References: <20210217112717.6820-1-sughosh.ganu@linaro.org> From: Achin Gupta 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 Co-developed-by: Sughosh Ganu --- 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 #include #include +#include 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