Browse Source

smcinvoke: adci interface adaptation as per QTEE

Adapted the latest IClientEnv adci and other
interface methods from QTEE.
Change-Id: I05730e56d656977fbc53a2d3dedb04426474be1c
Pawan Rai 2 years ago
parent
commit
ca9f562c5a

+ 30 - 4
include/linux/IClientEnv.h

@@ -11,8 +11,10 @@
 #define IClientEnv_OP_registerWithWhitelist 3
 #define IClientEnv_OP_notifyDomainChange 4
 #define IClientEnv_OP_registerWithCredentials 5
-#define IClientEnv_OP_accept 6
-#define IClientEnv_OP_adciShutdown 7
+#define IClientEnv_OP_loadCmnlibFromBuffer 6
+#define IClientEnv_OP_configTaRegion 7
+#define IClientEnv_OP_adciAccept 8
+#define IClientEnv_OP_adciShutdown 9
 
 #include "smcinvoke_object.h"
 
@@ -121,9 +123,33 @@ IClientEnv_registerWithCredentials(struct Object self, struct Object
 }
 
 static inline int32_t
-IClientEnv_accept(struct Object self)
+IClientEnv_loadCmnlibFromBuffer(struct Object self, const void *cmnlibElf_ptr, size_t cmnlibElf_len)
 {
-	return Object_invoke(self, IClientEnv_OP_accept, 0, 0);
+  union ObjectArg a[1]={{{0,0}}};
+  a[0].bi = (struct ObjectBufIn) { cmnlibElf_ptr, cmnlibElf_len * 1 };
+
+  return Object_invoke(self, IClientEnv_OP_loadCmnlibFromBuffer, a, ObjectCounts_pack(1, 0, 0, 0));
+}
+
+static inline int32_t
+IClientEnv_configTaRegion(struct Object self, uint64_t appRgnAddr_val, uint32_t appRgnSize_val)
+{
+  union ObjectArg a[1]={{{0,0}}};
+  struct {
+    uint64_t m_appRgnAddr;
+    uint32_t m_appRgnSize;
+  } i;
+  a[0].b = (struct ObjectBuf) { &i, 12 };
+  i.m_appRgnAddr = appRgnAddr_val;
+  i.m_appRgnSize = appRgnSize_val;
+
+  return Object_invoke(self, IClientEnv_OP_configTaRegion, a, ObjectCounts_pack(1, 0, 0, 0));
+}
+
+static inline int32_t
+IClientEnv_adciAccept(struct Object self)
+{
+	return Object_invoke(self, IClientEnv_OP_adciAccept, 0, 0);
 }
 
 static inline int32_t

+ 2 - 1
include/linux/smcinvoke_object.h

@@ -184,7 +184,8 @@ static inline void Object_replace(struct Object *loc, struct Object objNew)
 }
 
 #define Object_ASSIGN_NULL(loc)  Object_replace(&(loc), Object_NULL)
-#define SMCINVOKE_INTERFACE_MAX_RETRY		5
+#define SMCINVOKE_INTERFACE_MAX_RETRY       5
+#define SMCINVOKE_INTERFACE_BUSY_WAIT_MS    5
 
 int smcinvoke_release_from_kernel_client(int fd);
 

+ 8 - 6
smcinvoke/smcinvoke.c

@@ -622,23 +622,25 @@ static void smcinvoke_start_adci_thread(void)
 	ret = get_client_env_object(&adci_clientEnv);
 	if (ret) {
 		pr_err("failed to get clientEnv for ADCI invoke thread. ret = %d\n", ret);
+		/* Marking it Object_NULL in case of failure scenario in order to avoid
+		 * undefined behavior while releasing garbage adci_clientEnv object.
+		 */
 		adci_clientEnv = Object_NULL;
 		goto out;
 	}
 	/* Invoke call to QTEE which should never return if ADCI is supported */
 	do {
-		ret = IClientEnv_accept(adci_clientEnv);
+		ret = IClientEnv_adciAccept(adci_clientEnv);
 		if (ret == OBJECT_ERROR_BUSY) {
 			pr_err("Secure side is busy,will retry after 5 ms, retry_count = %d",retry_count);
-			msleep(5);
+			msleep(SMCINVOKE_INTERFACE_BUSY_WAIT_MS);
 		}
 	} while ((ret == OBJECT_ERROR_BUSY) && (retry_count++ < SMCINVOKE_INTERFACE_MAX_RETRY));
 
 	if (ret == OBJECT_ERROR_INVALID)
 		pr_err("ADCI feature is not supported on this chipsets, ret = %d\n", ret);
-	/* Need to take decesion here if we want to restart the ADCI thread */
 	else
-		pr_err("Received response from QTEE, ret = %d\n", ret);
+		pr_debug("Received response from QTEE, ret = %d\n", ret);
 out:
 	/* Control should reach to this point only if ADCI feature is not supported by QTEE
 	  (or) ADCI thread held in QTEE is released. */
@@ -751,7 +753,7 @@ static void smcinvoke_destroy_kthreads(void)
 			ret = IClientEnv_adciShutdown(adci_clientEnv);
 			if (ret == OBJECT_ERROR_BUSY) {
 				pr_err("Secure side is busy,will retry after 5 ms, retry_count = %d",retry_count);
-				msleep(5);
+				msleep(SMCINVOKE_INTERFACE_BUSY_WAIT_MS);
 			}
 		} while ((ret == OBJECT_ERROR_BUSY) && (retry_count++ < SMCINVOKE_INTERFACE_MAX_RETRY));
 		if(OBJECT_isERROR(ret)) {
@@ -2660,7 +2662,7 @@ static long process_invoke_req(struct file *filp, unsigned int cmd,
 			tzobj->tzhandle == SMCINVOKE_TZ_ROOT_OBJ &&
 			(req.op == IClientEnv_OP_notifyDomainChange ||
 			req.op == IClientEnv_OP_registerWithCredentials ||
-			req.op == IClientEnv_OP_accept ||
+			req.op == IClientEnv_OP_adciAccept ||
 			req.op == IClientEnv_OP_adciShutdown)) {
 		pr_err("invalid rootenv op\n");
 		return -EINVAL;

+ 1 - 1
smcinvoke/smcinvoke_kernel.c

@@ -312,7 +312,7 @@ int32_t get_client_env_object(struct Object *clientEnvObj)
 			Object_NULL, clientEnvObj);
 		if (ret == OBJECT_ERROR_BUSY) {
 			pr_err("Secure side is busy,will retry after 5 ms, retry_count = %d",retry_count);
-			msleep(5);
+			msleep(SMCINVOKE_INTERFACE_BUSY_WAIT_MS);
 		}
 	} while ((ret == OBJECT_ERROR_BUSY) && (retry_count++ < SMCINVOKE_INTERFACE_MAX_RETRY));