OP-TEE: build optee_linuxdriver into kernel
authorZhang Zhijie <zhangzj@rock-chips.com>
Tue, 20 Oct 2015 06:38:43 +0000 (14:38 +0800)
committerGerrit Code Review <gerrit@rock-chips.com>
Thu, 22 Oct 2015 04:13:58 +0000 (12:13 +0800)
Change-Id: I4cacc3b0670643ab02af592549de988f11c378df
Signed-off-by: Zhang Zhijie <zhangzj@rock-chips.com>
security/Kconfig
security/Makefile
security/optee_linuxdriver/armtz/Makefile
security/optee_linuxdriver/armtz/tee_tz_drv.c
security/optee_linuxdriver/core/Makefile
security/optee_linuxdriver/core/tee_core.c
security/optee_linuxdriver/core/tee_session.c
security/optee_linuxdriver/core/tee_shm.c

index 20a4e219f59bb1d56a0cab43378859d1eef720c5..c6ec32ab561237c346d2559ee87ec1f1ddc6c7da 100644 (file)
@@ -123,6 +123,7 @@ source security/tomoyo/Kconfig
 source security/apparmor/Kconfig
 source security/yama/Kconfig
 source security/tlk_driver/Kconfig
+source security/optee_linuxdriver/Kconfig
 
 source security/integrity/Kconfig
 
index fa723812ad85269077ccd555761d9a976678ad8e..39dbfa5879956a57c370ee986cb41bc8cce484ca 100644 (file)
@@ -30,3 +30,4 @@ subdir-$(CONFIG_INTEGRITY)            += integrity
 obj-$(CONFIG_INTEGRITY)                        += integrity/built-in.o
 
 obj-y                                  += tlk_driver/
+obj-y                                  += optee_linuxdriver/
index af2b10cfd8eb21fdba1424e310ec18001f890070..5e6987ba62df9e81f43918c13c4a62cc2a8ed8cd 100644 (file)
@@ -7,6 +7,8 @@ CFG_TEE_DRV_DEBUGFS?=0
 CFG_TEE_CORE_LOG_LEVEL?=2
 CFG_TEE_TA_LOG_LEVEL?=2
 
+M ?= security/optee_linuxdriver
+
 ccflags-y+=-Werror
 ccflags-y+=-I$(M)/include/arm_common
 ccflags-y+=-I$(M)/include/linux
@@ -17,7 +19,7 @@ ccflags-y+=-DCFG_TEE_DRV_DEBUGFS=${CFG_TEE_DRV_DEBUGFS}
 ccflags-y+=-DCFG_TEE_CORE_LOG_LEVEL=${CFG_TEE_CORE_LOG_LEVEL}
 ccflags-y+=-DCFG_TEE_TA_LOG_LEVEL=${CFG_TEE_TA_LOG_LEVEL}
 
-obj-m += optee_armtz.o
+obj-y += optee_armtz.o
 
 optee_armtz-objs:=   \
                tee_tz_drv.o \
index 6541b02e646f7622459947a03d34e87e3e402db5..70e7c5bb11987256690c4da34c4df9fee1c69f26 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/tee_core.h>
 #include <linux/tee_ioc.h>
 
+#include <asm/smp_plat.h>
 #include <tee_shm.h>
 #include <tee_supp_com.h>
 #include <tee_mutex_wait.h>
@@ -36,6 +37,8 @@
 #include "tee_tz_priv.h"
 #include "handle.h"
 
+#define SWITCH_CPU0_DEBUG
+
 #define _TEE_TZ_NAME "armtz"
 #define DEV (ptee->tee->dev)
 
@@ -64,6 +67,40 @@ static struct handle_db shm_handle_db = HANDLE_DB_INITIALIZER;
 /*******************************************************************
  * Calling TEE
  *******************************************************************/
+#ifdef CONFIG_SMP
+static void switch_cpumask_to_cpu0(cpumask_t *saved_cpu_mask)
+{
+       long ret;
+       cpumask_t local_cpu_mask = CPU_MASK_NONE;
+       pr_info("switch_cpumask_to_cpu cpu0\n");
+       cpu_set(0, local_cpu_mask);
+       cpumask_copy(saved_cpu_mask, tsk_cpus_allowed(current));
+       ret = sched_setaffinity(0, &local_cpu_mask);
+       if (ret)
+               pr_err("sched_setaffinity #1 -> 0x%lX", ret);
+}
+
+static void restore_cpumask(cpumask_t *saved_cpu_mask)
+{
+       long ret;
+       pr_info("restore_cpumask cpu0\n");
+       ret = sched_setaffinity(0, saved_cpu_mask);
+       if (ret)
+               pr_err("sched_setaffinity #2 -> 0x%lX", ret);
+}
+#else
+static inline void switch_cpumask_to_cpu0(void) {};
+static inline void restore_cpumask(void) {};
+#endif
+static int tee_smc_call_switchcpu0(struct smc_param *param)
+{
+       cpumask_t saved_cpu_mask;
+
+       switch_cpumask_to_cpu0(&saved_cpu_mask);
+       tee_smc_call(param);
+       restore_cpumask(&saved_cpu_mask);
+       return 0;
+}
 
 static void e_lock_teez(struct tee_tz *ptee)
 {
@@ -407,7 +444,11 @@ static void call_tee(struct tee_tz *ptee,
        while (true) {
                param.a0 = funcid;
 
+#ifdef SWITCH_CPU0_DEBUG
+               tee_smc_call_switchcpu0(&param);
+#else
                tee_smc_call(&param);
+#endif
                ret = param.a0;
 
                if (ret == TEESMC_RETURN_EBUSY) {
@@ -988,7 +1029,11 @@ static int register_outercache_mutex(struct tee_tz *ptee, bool reg)
        memset(&param, 0, sizeof(param));
        param.a0 = TEESMC32_ST_FASTCALL_L2CC_MUTEX;
        param.a1 = TEESMC_ST_L2CC_MUTEX_GET_ADDR;
+#ifdef SWITCH_CPU0_DEBUG
+       tee_smc_call_switchcpu0(&param);
+#else
        tee_smc_call(&param);
+#endif
 
        if (param.a0 != TEESMC_RETURN_OK) {
                dev_warn(DEV, "no TZ l2cc mutex service supported\n");
@@ -1013,7 +1058,11 @@ static int register_outercache_mutex(struct tee_tz *ptee, bool reg)
        memset(&param, 0, sizeof(param));
        param.a0 = TEESMC32_ST_FASTCALL_L2CC_MUTEX;
        param.a1 = TEESMC_ST_L2CC_MUTEX_ENABLE;
+#ifdef SWITCH_CPU0_DEBUG
+       tee_smc_call_switchcpu0(&param);
+#else
        tee_smc_call(&param);
+#endif
 
        if (param.a0 != TEESMC_RETURN_OK) {
 
@@ -1027,7 +1076,11 @@ out:
                memset(&param, 0, sizeof(param));
                param.a0 = TEESMC32_ST_FASTCALL_L2CC_MUTEX;
                param.a1 = TEESMC_ST_L2CC_MUTEX_DISABLE;
+#ifdef SWITCH_CPU0_DEBUG
+               tee_smc_call_switchcpu0(&param);
+#else
                tee_smc_call(&param);
+#endif
                outer_tz_mutex(NULL);
                if (vaddr)
                        iounmap(vaddr);
@@ -1053,7 +1106,11 @@ static int configure_shm(struct tee_tz *ptee)
 
        mutex_lock(&ptee->mutex);
        param.a0 = TEESMC32_ST_FASTCALL_GET_SHM_CONFIG;
+#ifdef SWITCH_CPU0_DEBUG
+       tee_smc_call_switchcpu0(&param);
+#else
        tee_smc_call(&param);
+#endif
        mutex_unlock(&ptee->mutex);
 
        if (param.a0 != TEESMC_RETURN_OK) {
@@ -1160,7 +1217,7 @@ static int tz_stop(struct tee *tee)
 
 /******************************************************************************/
 
-const struct tee_ops tee_fops = {
+static const struct tee_ops tee_fops = {
        .type = "tz",
        .owner = THIS_MODULE,
        .start = tz_start,
index 86cde19c607f813f34a8e197488aa3370606a377..8219201852b77fd1eb83c413c319fe1af4c51c03 100644 (file)
@@ -8,6 +8,8 @@ CFG_TEE_DRV_DEBUGFS?=0
 CFG_TEE_CORE_LOG_LEVEL?=2
 CFG_TEE_TA_LOG_LEVEL?=2
 
+M ?= security/optee_linuxdriver
+
 ccflags-y+=-Werror
 ccflags-y+=-I$(M)/include/linux
 ccflags-y+=-I$(M)/include
@@ -16,7 +18,7 @@ ccflags-y+=-DCFG_TEE_DRV_DEBUGFS=${CFG_TEE_DRV_DEBUGFS}
 ccflags-y+=-DCFG_TEE_CORE_LOG_LEVEL=${CFG_TEE_CORE_LOG_LEVEL}
 ccflags-y+=-DCFG_TEE_TA_LOG_LEVEL=${CFG_TEE_TA_LOG_LEVEL}
 
-obj-m += optee.o
+obj-y += optee.o
 
 optee-objs:=   \
                tee_core.o  \
index d337e39f56c9fd5dbbc5c0d7f03dfcaf5cf62862..8ef8ade7a3b558fc471a5c49031c8afb856a246e 100644 (file)
@@ -39,7 +39,7 @@
 
 #define _TEE_CORE_FW_VER "1:0.1"
 
-static char *_tee_supp_app_name = "tee-supplicant";
+static char *_tee_supp_app_name = "tee_supplicant";
 
 /* Store the class misc reference */
 static struct class *misc_class;
@@ -397,13 +397,14 @@ static long tee_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
        return ret;
 }
 
-const struct file_operations tee_fops = {
+static const struct file_operations tee_file_fops = {
        .owner = THIS_MODULE,
        .read = tee_supp_read,
        .write = tee_supp_write,
        .open = tee_ctx_open,
        .release = tee_ctx_release,
-       .unlocked_ioctl = tee_ioctl
+       .unlocked_ioctl = tee_ioctl,
+       .compat_ioctl = tee_ioctl
 };
 
 static void tee_plt_device_release(struct device *dev)
@@ -441,7 +442,7 @@ struct tee *tee_core_alloc(struct device *dev, char *name, int id,
        tee->miscdev.parent = dev;
        tee->miscdev.minor = MISC_DYNAMIC_MINOR;
        tee->miscdev.name = tee->name;
-       tee->miscdev.fops = &tee_fops;
+       tee->miscdev.fops = &tee_file_fops;
 
        mutex_init(&tee->lock);
        atomic_set(&tee->refcount, 0);
index 32391afef073601a76a1efdc485913ab6878dc31..e90725582cfcb7dc3c8037976fd8d0514754537f 100644 (file)
@@ -360,6 +360,7 @@ static int tee_session_release(struct inode *inode, struct file *filp)
 const struct file_operations tee_session_fops = {
        .owner = THIS_MODULE,
        .unlocked_ioctl = tee_session_ioctl,
+       .compat_ioctl = tee_session_ioctl,
        .release = tee_session_release,
 };
 
index 10d11af06a155096bb0866a963a622c6d672714b..ccc560c2594fd493857528595c0727c1bd7c7d1b 100644 (file)
@@ -372,7 +372,7 @@ static int export_buf(struct tee *tee, struct tee_shm *shm, int *export)
        dmabuf = dma_buf_export(&exp_info);
 #else
        dmabuf = dma_buf_export(shm, &_tee_shm_dma_buf_ops, shm->size_alloc,
-                               O_RDWR, 0);
+                               O_RDWR);
 #endif
        if (IS_ERR_OR_NULL(dmabuf)) {
                dev_err(_DEV(tee), "%s: dmabuf: couldn't export buffer (%ld)\n",