From 89c6073683e18cd3271d7263b0e2712c88c7ec12 Mon Sep 17 00:00:00 2001 From: Kun Qin Date: Fri, 19 Jun 2026 10:05:17 -0700 Subject: [PATCH] MdePkg,MdeModulePkg: ArmFfaLib: Expand to include first 4 registers The direct message arguments stripped off the header, making the underlying FF-A function interface to lose information when it comes to certain return code, i.e. FFA_YIELD and FFA_INTERRUPT. This change adds back the header field for this purpose so that the callers can decide how to act on the corresponding return codes. It then populates the header field for this purpose in FFA direct message functions so that the callers can decide how to act on the corresponding return codes. Continuous-integration-options: PatchCheck.ignore-multi-package Signed-off-by: Kun Qin --- MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c | 12 +++++++++--- MdePkg/Include/Library/ArmFfaLib.h | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c b/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c index 9c90bcada0..c8b068ebfa 100644 --- a/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c +++ b/MdeModulePkg/Library/ArmFfaLib/ArmFfaCommon.c @@ -749,13 +749,13 @@ ArmFfaLibRun ( ArmCallFfa (&FfaArgs); Status = FfaArgsToEfiStatus (&FfaArgs); - if (EFI_ERROR (Status)) { - return Status; - } if (DirectMsgArg != NULL) { ZeroMem (DirectMsgArg, sizeof (DIRECT_MSG_ARGS)); + // Copy the FFA header to the direct message arguments + CopyMem (&(DirectMsgArg->Header), &FfaArgs, sizeof (DirectMsgArg->Header)); + if (FfaArgs.Arg0 == ARM_FID_FFA_MSG_SEND_DIRECT_RESP) { DirectMsgArg->Arg0 = FfaArgs.Arg3; DirectMsgArg->Arg1 = FfaArgs.Arg4; @@ -790,6 +790,8 @@ ArmFfaLibRun ( @param [in] Flags Message flags @param [in, out] ImpDefArgs Implemented defined arguments and Implemented defined return values + The header registers (x0-x2) will be initialized + with the values from DestPartId and Flags. @retval EFI_SUCCESS Success @retval Others Error @@ -831,6 +833,7 @@ ArmFfaLibMsgSendDirectReq ( Status = FfaArgsToEfiStatus (&FfaArgs); if (EFI_ERROR (Status)) { + CopyMem (ImpDefArgs, &FfaArgs, sizeof (DIRECT_MSG_ARGS)); return Status; } @@ -850,6 +853,8 @@ ArmFfaLibMsgSendDirectReq ( @param [in] ServiceGuid Service guid @param [in, out] ImpDefArgs Implemented defined arguments and Implemented defined return values + The header registers (x0-x3) will be + initialized with the values from DestPartId and ServiceGuid. @retval EFI_SUCCESS Success @retval Others Error @@ -915,6 +920,7 @@ ArmFfaLibMsgSendDirectReq2 ( Status = FfaArgsToEfiStatus (&FfaArgs); if (EFI_ERROR (Status)) { + CopyMem (ImpDefArgs, &FfaArgs, sizeof (DIRECT_MSG_ARGS)); return Status; } diff --git a/MdePkg/Include/Library/ArmFfaLib.h b/MdePkg/Include/Library/ArmFfaLib.h index 9adfffb0e0..021b3056a8 100644 --- a/MdePkg/Include/Library/ArmFfaLib.h +++ b/MdePkg/Include/Library/ArmFfaLib.h @@ -53,6 +53,14 @@ typedef struct ArmFfaArgs { * FFA_SEND_MSG_DIRECT_REQ2/FFA_SEND_MSG_DIRECT_RESP2 (i.e. v2) */ typedef struct DirectMsgArgs { + /// Header containing the arguments for the header registers (x0-x2 (v1) or x0-x3 (v2)) + struct { + UINTN x0; + UINTN x1; + UINTN x2; + UINTN x3; + } Header; + /// Implementation define argument 0, this will be set to/from x3(v1) or x4(v2) UINTN Arg0; @@ -96,6 +104,8 @@ typedef struct DirectMsgArgs { UINTN Arg13; } DIRECT_MSG_ARGS; +STATIC_ASSERT (sizeof (DIRECT_MSG_ARGS) == sizeof (ARM_FFA_ARGS), "DIRECT_MSG_ARGS and ARM_FFA_ARGS must be the same size"); + /** Trigger FF-A ABI call according to PcdFfaLibConduitSmc.