From: Jens Wiklander <jens.wiklander@linaro.org>
To: linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
javier@javigon.com
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
tpmdd-devel@lists.sourceforge.net, valentin.manea@huawei.com,
jean-michel.delorme@st.com, emmanuel.michel@st.com,
Jens Wiklander <jens.wiklander@linaro.org>
Subject: [RFC PATCH 2/2] tee: add OP-TEE driver
Date: Fri, 17 Apr 2015 09:50:57 +0200 [thread overview]
Message-ID: <1429257057-7935-3-git-send-email-jens.wiklander@linaro.org> (raw)
In-Reply-To: <1429257057-7935-1-git-send-email-jens.wiklander@linaro.org>
Adds mostly stubbed OP-TEE driver which also can be compiled as a
loadable module.
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
---
drivers/tee/Kconfig | 10 +++
drivers/tee/Makefile | 1 +
drivers/tee/optee/Kconfig | 7 ++
drivers/tee/optee/Makefile | 2 +
drivers/tee/optee/core.c | 192 +++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 212 insertions(+)
create mode 100644 drivers/tee/optee/Kconfig
create mode 100644 drivers/tee/optee/Makefile
create mode 100644 drivers/tee/optee/core.c
diff --git a/drivers/tee/Kconfig b/drivers/tee/Kconfig
index 64a8cd7..b269276 100644
--- a/drivers/tee/Kconfig
+++ b/drivers/tee/Kconfig
@@ -6,3 +6,13 @@ config TEE
help
This implements a generic interface towards a Trusted Execution
Environment (TEE).
+
+if TEE
+
+menu "TEE drivers"
+
+source "drivers/tee/optee/Kconfig"
+
+endmenu
+
+endif
diff --git a/drivers/tee/Makefile b/drivers/tee/Makefile
index 60d2dab..53f3c76 100644
--- a/drivers/tee/Makefile
+++ b/drivers/tee/Makefile
@@ -1,3 +1,4 @@
obj-y += tee.o
obj-y += tee_shm.o
obj-y += tee_shm_pool.o
+obj-$(CONFIG_OPTEE) += optee/
diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig
new file mode 100644
index 0000000..f43af5e
--- /dev/null
+++ b/drivers/tee/optee/Kconfig
@@ -0,0 +1,7 @@
+# OP-TEE Trusted Execution Environment Configuration
+config OPTEE
+ tristate "OP-TEE"
+ default n
+ select DMA_CMA
+ help
+ This implements the OP-TEE Trusted Execution Environment (TEE) driver.
diff --git a/drivers/tee/optee/Makefile b/drivers/tee/optee/Makefile
new file mode 100644
index 0000000..124d22c
--- /dev/null
+++ b/drivers/tee/optee/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_OPTEE) += optee.o
+optee-objs += core.o
diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
new file mode 100644
index 0000000..e0f0755
--- /dev/null
+++ b/drivers/tee/optee/core.c
@@ -0,0 +1,192 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/types.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/dma-contiguous.h>
+#include <linux/cma.h>
+#include <linux/tee/tee_drv.h>
+
+#define DRIVER_NAME "tee-optee"
+#define OPTEE_VERSION 1
+
+struct optee {
+ struct tee_device *supp_teedev;
+ struct tee_device *teedev;
+ struct device *dev;
+ struct tee_shm_pool *pool;
+};
+
+struct optee_context_data {
+ int dummy;
+};
+
+static void optee_get_version(struct tee_context *ctx,
+ u32 *version, u8 *uuid)
+{
+ *version = OPTEE_VERSION;
+ memset(uuid, 0, TEE_UUID_SIZE);
+}
+
+static int optee_open(struct tee_context *ctx)
+{
+ ctx->data = kzalloc(sizeof(struct optee_context_data), GFP_KERNEL);
+ if (!ctx->data)
+ return -ENOMEM;
+ return 0;
+}
+
+static void optee_release(struct tee_context *ctx)
+{
+ kfree(ctx->data);
+ ctx->data = NULL;
+}
+
+static int optee_cmd(struct tee_context *ctx, void __user *buf, size_t len)
+{
+ return -EINVAL;
+}
+
+static int optee_shm_share(struct tee_shm *shm)
+{
+ /* No special action needed to share memory with OP-TEE */
+ return 0;
+}
+
+static void optee_shm_unshare(struct tee_shm *shm)
+{
+}
+
+static struct tee_driver_ops optee_ops = {
+ .get_version = optee_get_version,
+ .open = optee_open,
+ .release = optee_release,
+ .cmd = optee_cmd,
+ .shm_share = optee_shm_share,
+ .shm_unshare = optee_shm_unshare,
+};
+
+static struct tee_desc optee_desc = {
+ .name = DRIVER_NAME "-clnt",
+ .ops = &optee_ops,
+ .owner = THIS_MODULE,
+};
+
+static int optee_supp_cmd(struct tee_context *teectx, void __user *buf,
+ size_t len)
+{
+ return -EINVAL;
+}
+
+static struct tee_driver_ops optee_supp_ops = {
+ .get_version = optee_get_version,
+ .open = optee_open,
+ .release = optee_release,
+ .cmd = optee_supp_cmd,
+ .shm_share = optee_shm_share,
+ .shm_unshare = optee_shm_unshare,
+};
+
+static struct tee_desc optee_supp_desc = {
+ .name = DRIVER_NAME "-supp",
+ .ops = &optee_supp_ops,
+ .owner = THIS_MODULE,
+ .flags = TEE_DESC_PRIVILEGED,
+};
+
+static int optee_probe(struct platform_device *pdev)
+{
+ struct tee_shm_pool *pool;
+ struct optee *optee;
+ u_long vaddr;
+ phys_addr_t paddr;
+ size_t size;
+ int ret;
+
+ pool = tee_shm_pool_alloc_cma(&pdev->dev, &vaddr, &paddr, &size);
+ if (IS_ERR(pool))
+ return PTR_ERR(pool);
+
+ dev_info(&pdev->dev, "pool: va 0x%lx pa 0x%lx size %zx\n",
+ vaddr, (u_long)paddr, size);
+
+ optee = devm_kzalloc(&pdev->dev, sizeof(*optee), GFP_KERNEL);
+ if (!optee) {
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ optee->dev = &pdev->dev;
+
+ optee->teedev = tee_register(&optee_desc, &pdev->dev, pool, optee);
+ if (IS_ERR(optee->teedev)) {
+ ret = PTR_ERR(optee->teedev);
+ goto err;
+ }
+
+ optee->supp_teedev = tee_register(&optee_supp_desc, &pdev->dev, pool,
+ optee);
+ if (!optee->teedev) {
+ ret = PTR_ERR(optee->teedev);
+ goto err;
+ }
+
+ optee->pool = pool;
+ platform_set_drvdata(pdev, optee);
+
+ dev_info(&pdev->dev, "initialized driver\n");
+ return 0;
+err:
+ if (optee && optee->teedev)
+ tee_unregister(optee->teedev);
+ if (pool)
+ tee_shm_pool_free(pool);
+ return ret;
+}
+
+static int optee_remove(struct platform_device *pdev)
+{
+ struct optee *optee = platform_get_drvdata(pdev);
+
+ tee_unregister(optee->teedev);
+ tee_unregister(optee->supp_teedev);
+ tee_shm_pool_free(optee->pool);
+
+ return 0;
+}
+
+static const struct of_device_id optee_match[] = {
+ { .compatible = "optee,optee-tz" },
+ {},
+};
+
+static struct platform_driver optee_driver = {
+ .driver = {
+ .name = DRIVER_NAME,
+ .of_match_table = optee_match,
+ },
+ .probe = optee_probe,
+ .remove = optee_remove,
+};
+
+module_platform_driver(optee_driver);
+
+MODULE_AUTHOR("Linaro");
+MODULE_DESCRIPTION("OP-TEE TEE driver");
+MODULE_SUPPORTED_DEVICE("");
+MODULE_VERSION("1.0");
+MODULE_LICENSE("GPL v2");
--
1.9.1
next prev parent reply other threads:[~2015-04-17 7:52 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-17 7:50 [RFC PATCH 0/2] generic TEE subsystem Jens Wiklander
2015-04-17 7:50 ` [RFC PATCH 1/2] tee: " Jens Wiklander
2015-04-17 16:30 ` [tpmdd-devel] " Jason Gunthorpe
2015-04-18 9:01 ` Russell King - ARM Linux
2015-04-18 17:29 ` Jason Gunthorpe
2015-04-18 21:57 ` Russell King - ARM Linux
2015-04-20 5:08 ` Jason Gunthorpe
2015-04-20 14:54 ` Greg Kroah-Hartman
2015-04-20 15:56 ` Jason Gunthorpe
2015-04-20 16:05 ` Greg Kroah-Hartman
2015-04-20 13:02 ` Jens Wiklander
2015-04-20 17:55 ` Jason Gunthorpe
2015-04-21 5:59 ` Jens Wiklander
2015-04-17 20:07 ` Arnd Bergmann
2015-04-18 7:20 ` Paul Bolle
2015-04-20 6:20 ` Jens Wiklander
2015-04-20 18:20 ` [tpmdd-devel] " Jason Gunthorpe
2015-04-21 10:45 ` Jens Wiklander
2015-04-18 8:55 ` Greg Kroah-Hartman
2015-04-18 8:57 ` Greg Kroah-Hartman
2015-04-18 9:04 ` Russell King - ARM Linux
2015-04-18 18:47 ` Greg Kroah-Hartman
2015-04-18 19:02 ` Russell King - ARM Linux
2015-04-18 20:37 ` Greg Kroah-Hartman
2015-04-18 20:50 ` Russell King - ARM Linux
2015-04-19 7:00 ` Greg Kroah-Hartman
2015-04-17 7:50 ` Jens Wiklander [this message]
2015-04-18 8:57 ` [RFC PATCH 2/2] tee: add OP-TEE driver Greg Kroah-Hartman
2015-04-18 9:36 ` Javier González
2015-04-18 18:49 ` Greg Kroah-Hartman
2015-04-18 19:01 ` Arnd Bergmann
2015-04-19 11:17 ` Javier González
2015-04-19 19:47 ` Arnd Bergmann
2015-04-20 7:05 ` Javier González
2015-04-20 6:42 ` Jens Wiklander
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1429257057-7935-3-git-send-email-jens.wiklander@linaro.org \
--to=jens.wiklander@linaro.org \
--cc=arnd@arndb.de \
--cc=devicetree@vger.kernel.org \
--cc=emmanuel.michel@st.com \
--cc=gregkh@linuxfoundation.org \
--cc=herbert@gondor.apana.org.au \
--cc=javier@javigon.com \
--cc=jean-michel.delorme@st.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tpmdd-devel@lists.sourceforge.net \
--cc=valentin.manea@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).