diff mbox series

[1/1] OP-TEE use-case

Message ID 1537290690-7644-1-git-send-email-sumit.garg@linaro.org
State New
Headers show
Series [1/1] OP-TEE use-case | expand

Commit Message

Sumit Garg Sept. 18, 2018, 5:11 p.m. UTC
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Sumit Garg <sumit.garg@linaro.org>


Signed-off-by: Sumit Garg <sumit.garg@linaro.org>

---
 .../SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.c  | 48 ++++++++++++++++++++++
 .../SynQuacerDtbLoaderLib.inf                      |  1 +
 2 files changed, 49 insertions(+)

-- 
2.7.4
diff mbox series

Patch

diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.c b/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.c
index 96090c20502c..e76ba4879c09 100644
--- a/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.c
+++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.c
@@ -20,6 +20,7 @@ 
 #include <Library/DxeServicesLib.h>
 #include <Library/MemoryAllocationLib.h>
 #include <Library/OpteeLib.h>
+#include <Library/TimerLib.h>
 #include <Platform/VarStore.h>
 
 STATIC
@@ -109,6 +110,53 @@  DtPlatformLoadDtb (
     EnableDtNode (CopyDtb, "/firmware/optee");
   }
 
+/* This UUID is generated with uuidgen
+   the ITU-T UUID generator at http://www.itu.int/ITU-T/asn1/uuid.html */
+#define TA_TS_UUID { 0xab, 0x7a, 0x61, 0x7c, 0xb8, 0xe7, 0x4d, 0x8f, \
+                     0x83, 0x01, 0xd0, 0x9b, 0x61, 0x03, 0x6b, 0x64 }
+
+/* The Trusted Application Function ID(s) invoked to get random numbers */
+#define TA_CMD_GET_RNG  0
+
+  OpteeInit ();
+
+#if 1
+  OPTEE_OPEN_SESSION_ARG OpenSessionArg = { 0 };
+  OPTEE_INVOKE_FUNC_ARG InvokeFuncArg = { 0 };
+  UINT8 TaUuid[] =  TA_TS_UUID;
+  UINT64 RngData = 0;
+
+  memcpy (OpenSessionArg.Uuid, TaUuid, OPTEE_UUID_LEN);
+  OpteeOpenSession (&OpenSessionArg);
+  DEBUG ((EFI_D_WARN, "OP-TEE Session: 0x%X, Ret: 0x%X, RetOrigin: 0x%X\n", OpenSessionArg.Session, OpenSessionArg.Ret, OpenSessionArg.RetOrigin));
+
+  InvokeFuncArg.Func = TA_CMD_GET_RNG;
+  InvokeFuncArg.Session = OpenSessionArg.Session;
+
+  InvokeFuncArg.Params[0].Attr = OPTEE_MSG_ATTR_TYPE_MEM_INOUT;
+  InvokeFuncArg.Params[0].U.Mem.BufPtr = (UINT64) &RngData;
+  InvokeFuncArg.Params[0].U.Mem.Size = sizeof (UINT64);
+
+  Status = OpteeInvokeFunc (&InvokeFuncArg);
+  DEBUG ((EFI_D_WARN, "OP-TEE Invoke Status: 0x%X RngData: 0x%lX, Ret: 0x%X, RetOrigin: 0x%X\n", Status, RngData, InvokeFuncArg.Ret, InvokeFuncArg.RetOrigin));
+
+  MicroSecondDelay(16000);
+
+  memset(&InvokeFuncArg, 0, sizeof (OPTEE_INVOKE_FUNC_ARG));
+
+  InvokeFuncArg.Func = TA_CMD_GET_RNG;
+  InvokeFuncArg.Session = OpenSessionArg.Session;
+
+  InvokeFuncArg.Params[0].Attr = OPTEE_MSG_ATTR_TYPE_MEM_INOUT;
+  InvokeFuncArg.Params[0].U.Mem.BufPtr = (UINT64) &RngData;
+  InvokeFuncArg.Params[0].U.Mem.Size = sizeof (UINT64);
+
+  Status = OpteeInvokeFunc (&InvokeFuncArg);
+  DEBUG ((EFI_D_WARN, "OP-TEE Invoke Status: 0x%X RngData: 0x%lX, Ret: 0x%X, RetOrigin: 0x%X\n", Status, RngData, InvokeFuncArg.Ret, InvokeFuncArg.RetOrigin));
+
+  OpteeCloseSession (OpenSessionArg.Session);
+#endif
+
   *Dtb = CopyDtb;
   *DtbSize = CopyDtbSize;
 
diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.inf b/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.inf
index fd21f7c376ce..ca3c5931002a 100644
--- a/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.inf
+++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerDtbLoaderLib/SynQuacerDtbLoaderLib.inf
@@ -36,6 +36,7 @@  [LibraryClasses]
   FdtLib
   MemoryAllocationLib
   OpteeLib
+  TimerLib
 
 [Pcd]
   gSynQuacerTokenSpaceGuid.PcdPcieEnableMask