include: uapi: Add UUID to FFA tuple conversion helper am: 21251b7a3b

Original change: https://android-review.googlesource.com/c/trusty/lk/trusty/+/3500770

Change-Id: Ibd5e4052529bca97d81aaa06b5d379db8a1d819a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/lib/arm_ffa/arm_ffa.c b/lib/arm_ffa/arm_ffa.c
index cac3053..9656664 100644
--- a/lib/arm_ffa/arm_ffa.c
+++ b/lib/arm_ffa/arm_ffa.c
@@ -25,6 +25,7 @@
 #define LOCAL_TRACE 0
 
 #include <assert.h>
+#include <endian.h>
 #include <err.h>
 #include <interface/arm_ffa/arm_ffa.h>
 #include <inttypes.h>
@@ -32,6 +33,7 @@
 #include <kernel/vm.h>
 #include <lib/arm_ffa/arm_ffa.h>
 #include <lib/smc/smc.h>
+#include <lib/trusty/uuid.h>
 #include <lk/init.h>
 #include <lk/macros.h>
 #include <string.h>
@@ -54,6 +56,25 @@
     return ffa_init_state;
 }
 
+/**
+ * uuid_to_le64_pair() - convert uuid_t to (lo, hi)-pair per FFA spec.
+ *
+ * @uuid_lo_hi: Must be an array large enough to store a pair of 64-bit values.
+ *      These output elements are little-endian encoded. Upon function return,
+ *      uuid_lo_hi[0] contains what the FFA spec labels "Lo" - bytes [0-7], and
+ *      uuid_lo_hi[1] contains what the FFA spec labels "Hi" - bytes [8-15].
+ */
+static inline void uuid_to_le64_pair(uuid_t uuid_obj,
+                                     uint64_t uuid_lo_hi[static 2]) {
+    uuid_lo_hi[0] = (((uint64_t)htole16(uuid_obj.time_hi_and_version) << 48) |
+                     ((uint64_t)htole16(uuid_obj.time_mid) << 32) |
+                     ((uint64_t)htole32(uuid_obj.time_low)));
+
+    for (int i = 0; i < 8; i++) {
+        uuid_lo_hi[1] |= ((uint64_t)uuid_obj.clock_seq_and_node[i]) << (i * 8);
+    }
+}
+
 static status_t arm_ffa_call_id_get(uint16_t* id) {
     struct smc_ret8 smc_ret;