tee: apply v16 delta

Applies the v16 of the generic TEE subsystem patch set.

Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
index c98a812..8890a185 100644
--- a/drivers/tee/optee/core.c
+++ b/drivers/tee/optee/core.c
@@ -14,6 +14,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/arm-smccc.h>
 #include <linux/errno.h>
 #include <linux/io.h>
 #include <linux/module.h>
@@ -329,9 +330,8 @@
 	 * point of view) or not, is_smp() returns the the information
 	 * needed, but can't be called directly from here.
 	 */
-#ifndef CONFIG_SMP
-	a1 |= OPTEE_SMC_NSEC_CAP_UNIPROCESSOR;
-#endif
+	if (!IS_ENABLED(CONFIG_SMP) || nr_cpu_ids == 1)
+		a1 |= OPTEE_SMC_NSEC_CAP_UNIPROCESSOR;
 
 	invoke_fn(OPTEE_SMC_EXCHANGE_CAPABILITIES, a1, 0, 0, 0, 0, 0, 0,
 		  &res.smccc);
@@ -406,6 +406,25 @@
 	return pool;
 }
 
+/* Simple wrapper functions to be able to use a function pointer */
+static void optee_smccc_smc(unsigned long a0, unsigned long a1,
+			    unsigned long a2, unsigned long a3,
+			    unsigned long a4, unsigned long a5,
+			    unsigned long a6, unsigned long a7,
+			    struct arm_smccc_res *res)
+{
+	arm_smccc_smc(a0, a1, a2, a3, a4, a5, a6, a7, res);
+}
+
+static void optee_smccc_hvc(unsigned long a0, unsigned long a1,
+			    unsigned long a2, unsigned long a3,
+			    unsigned long a4, unsigned long a5,
+			    unsigned long a6, unsigned long a7,
+			    struct arm_smccc_res *res)
+{
+	arm_smccc_hvc(a0, a1, a2, a3, a4, a5, a6, a7, res);
+}
+
 static optee_invoke_fn *get_invoke_func(struct device_node *np)
 {
 	const char *method;
@@ -418,9 +437,9 @@
 	}
 
 	if (!strcmp("hvc", method))
-		return arm_smccc_hvc;
+		return optee_smccc_hvc;
 	else if (!strcmp("smc", method))
-		return arm_smccc_smc;
+		return optee_smccc_smc;
 
 	pr_warn("invalid \"method\" property: %s\n", method);
 	return ERR_PTR(-EINVAL);
@@ -459,7 +478,7 @@
 	 * We have no other option for shared memory, if secure world
 	 * doesn't have any reserved memory we can use we can't continue.
 	 */
-	if (!(sec_caps & OPTEE_SMC_SEC_CAP_HAVE_RESERVERED_SHM))
+	if (!(sec_caps & OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM))
 		return ERR_PTR(-EINVAL);
 
 	pool = optee_config_shm_memremap(invoke_fn, &memremaped_shm);
diff --git a/drivers/tee/optee/optee_smc.h b/drivers/tee/optee/optee_smc.h
index d470d45..13b7c98 100644
--- a/drivers/tee/optee/optee_smc.h
+++ b/drivers/tee/optee/optee_smc.h
@@ -219,7 +219,7 @@
 /* Normal world works as a uniprocessor system */
 #define OPTEE_SMC_NSEC_CAP_UNIPROCESSOR		BIT(0)
 /* Secure world has reserved shared memory for normal world to use */
-#define OPTEE_SMC_SEC_CAP_HAVE_RESERVERED_SHM	BIT(0)
+#define OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM	BIT(0)
 /* Secure world can communicate via previously unregistered shared memory */
 #define OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM	BIT(1)
 #define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES	9
diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c
index 3cae959..ac34acd 100644
--- a/drivers/tee/tee_core.c
+++ b/drivers/tee/tee_core.c
@@ -618,6 +618,7 @@
 	clear_bit(teedev->id, dev_mask);
 	spin_unlock(&driver_lock);
 	mutex_destroy(&teedev->mutex);
+	idr_destroy(&teedev->idr);
 	kfree(teedev);
 }
 
@@ -695,6 +696,7 @@
 	teedev->num_users = 1;
 	init_completion(&teedev->c_no_users);
 	mutex_init(&teedev->mutex);
+	idr_init(&teedev->idr);
 
 	teedev->desc = teedesc;
 	teedev->pool = pool;
diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
index c2c90a8..549e5b9 100644
--- a/drivers/tee/tee_shm.c
+++ b/drivers/tee/tee_shm.c
@@ -303,7 +303,8 @@
 EXPORT_SYMBOL_GPL(tee_shm_get_pa);
 
 /**
- * tee_shm_get_from_id() - Find shared memory object and increase referece count
+ * tee_shm_get_from_id() - Find shared memory object and increase reference
+ * count
  * @ctx:	Context owning the shared memory
  * @id:		Id of shared memory object
  * @returns a pointer to 'struct tee_shm' on success or an ERR_PTR on failure
diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h
index 9c6106e..0f175b8 100644
--- a/include/linux/tee_drv.h
+++ b/include/linux/tee_drv.h
@@ -266,7 +266,8 @@
 int tee_shm_get_id(struct tee_shm *shm);
 
 /**
- * tee_shm_get_from_id() - Find shared memory object and increase referece count
+ * tee_shm_get_from_id() - Find shared memory object and increase reference
+ * count
  * @ctx:	Context owning the shared memory
  * @id:		Id of shared memory object
  * @returns a pointer to 'struct tee_shm' on success or an ERR_PTR on failure