lib: arm_ffa: Add support for sending FFA_MSG_SEND_DIRECT_RESP2 messages

Bug: 380065728
Change-Id: I01506a98a249a00965db786fdba3cd05effd9066
diff --git a/lib/arm_ffa/arm_ffa.c b/lib/arm_ffa/arm_ffa.c
index 235f697..033d51a 100644
--- a/lib/arm_ffa/arm_ffa.c
+++ b/lib/arm_ffa/arm_ffa.c
@@ -552,6 +552,29 @@
     __UNREACHABLE;
 }
 
+struct smc_ret18 arm_ffa_msg_send_direct_resp2(
+        const struct smc_ret18* direct_req_regs,
+        uint64_t args[static ARM_FFA_MSG_EXTENDED_ARGS_COUNT]) {
+    uint32_t sender_receiver_id;
+
+    DEBUG_ASSERT(direct_req_regs);
+    DEBUG_ASSERT(args);
+    if ((uint32_t)direct_req_regs->r0 != SMC_FC64_FFA_MSG_SEND_DIRECT_REQ2) {
+        dprintf(CRITICAL, "Invalid direct request function id %x\n",
+                (uint32_t)direct_req_regs->r0);
+        return arm_ffa_call_error(FFA_ERROR_INVALID_PARAMETERS);
+    }
+
+    /* Copy and flip the sender from the direct message request */
+    sender_receiver_id =
+            (direct_req_regs->r1 >> 16) | ((uint32_t)ffa_local_id << 16);
+
+    return smc18(SMC_FC64_FFA_MSG_SEND_DIRECT_RESP2, sender_receiver_id, 0, 0,
+                 args[0], args[1], args[2], args[3], args[4], args[5], args[6],
+                 args[7], args[8], args[9], args[10], args[11], args[12],
+                 args[13]);
+}
+
 #if ARCH_ARM64
 status_t arm_ffa_msg_send_direct_req2(
         uuid_t uuid,
diff --git a/lib/arm_ffa/include/lib/arm_ffa/arm_ffa.h b/lib/arm_ffa/include/lib/arm_ffa/arm_ffa.h
index 1ce4039..9f16363 100644
--- a/lib/arm_ffa/include/lib/arm_ffa/arm_ffa.h
+++ b/lib/arm_ffa/include/lib/arm_ffa/arm_ffa.h
@@ -182,7 +182,7 @@
  *
  * @uuid: Handler UUID.
  * @receiver_id: Receiver ID.
- * @args: Contents of message - x4-x17. Must not be %NULL.
+ * @args: Contents of message request - x4-x17. Must not be %NULL.
  * @resp: The registers passed back in response to the direct message iff
  *        the request was successful. Must not be %NULL.
  *
@@ -195,6 +195,19 @@
         struct smc_ret18* resp);
 
 /**
+ * arm_ffa_msg_send_direct_resp2() - Send a direct message response.
+ *
+ * @direct_req_regs: The registers passed back in response to the direct message
+ *        iff the request was successful. Must not be %NULL.
+ * @args: Contents of message response - x4-x17. Must not be %NULL.
+ *
+ * Return: the values of the CPU registers on return to Trusty.
+ */
+struct smc_ret18 arm_ffa_msg_send_direct_resp2(
+        const struct smc_ret18* direct_req_regs,
+        uint64_t args[static ARM_FFA_MSG_EXTENDED_ARGS_COUNT]);
+
+/**
  * arm_ffa_console_log() - Output a buffer using %FFA_CONSOLE_LOG.
  *
  * @buf: The buffer to print.