aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolodymyr Babchuk <vlad.babchuk@gmail.com>2017-03-07 17:00:59 +0200
committerJérôme Forissier <jerome.forissier@linaro.org>2017-06-14 17:47:28 +0200
commit50f243138c228046a9313eac7d530b6f001db115 (patch)
treef6f50cc1371e4bab86e962cc697eea6885869eaa
parent2bfab7564f957e7c2805766428a4d8b0799a5e4f (diff)
msg_param: add msg_param.c with helper functions
This patch adds various helper functions to manipulate with parameters passed to/from normal world. Also it introduces new optee_param type which is used to pass long lists of parameters. Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Tested-by: Jens Wiklander <jens.wiklander@linaro.org> (Hikey)
-rw-r--r--core/include/kernel/msg_param.h114
-rw-r--r--core/kernel/msg_param.c84
-rw-r--r--core/kernel/sub.mk1
3 files changed, 199 insertions, 0 deletions
diff --git a/core/include/kernel/msg_param.h b/core/include/kernel/msg_param.h
new file mode 100644
index 00000000..34c6c284
--- /dev/null
+++ b/core/include/kernel/msg_param.h
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2017, EPAM Systems
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef KERNEL_MSG_PARAM_H
+#define KERNEL_MSG_PARAM_H
+
+#include <optee_msg.h>
+#include <stdio.h>
+#include <types_ext.h>
+#include <kernel/msg_param.h>
+#include <mm/mobj.h>
+
+/*
+ * This enum is used in tee_fill_memparam(). It describes direction of memory
+ * parameter.
+ */
+enum msg_param_mem_dir {
+ MSG_PARAM_MEM_DIR_IN = 0,
+ MSG_PARAM_MEM_DIR_OUT,
+ MSG_PARAM_MEM_DIR_INOUT,
+};
+
+/**
+ * msg_param_init_memparam() - fill memory reference parameter for RPC call
+ * @param - parameter to fill
+ * @mobj - mobj describing the shared memory buffer
+ * @offset - offset of the buffer
+ * @size - size of the buffer
+ * @cookie - NW cookie of the shared buffer
+ * @dir - data direction
+ *
+ * Idea behind this function is that thread_rpc_alloc() can return
+ * either buffer from preallocated memory pool, of buffer constructed
+ * from supplicant's memory. In first case parameter will have type
+ * OPTEE_MSG_ATTR_TYPE_TMEM_* and OPTEE_MSG_ATTR_TYPE_RMEM_ in second case.
+ * This function will fill parameter structure with right type, depending on
+ * the passed mobj.
+ *
+ * return:
+ * true on success, false on failure
+ */
+bool msg_param_init_memparam(struct optee_msg_param *param, struct mobj *mobj,
+ size_t offset, size_t size,
+ uint64_t cookie, enum msg_param_mem_dir dir);
+/**
+ * msg_param_get_buf_size() - helper functions that reads [T/R]MEM
+ * parameter size
+ *
+ * @param - struct optee_msg_param to read size from
+ *
+ * return:
+ * corresponding size field
+ */
+static inline size_t msg_param_get_buf_size(struct optee_msg_param *param)
+{
+ switch (param->attr & OPTEE_MSG_ATTR_TYPE_MASK) {
+ case OPTEE_MSG_ATTR_TYPE_TMEM_INPUT:
+ case OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT:
+ case OPTEE_MSG_ATTR_TYPE_TMEM_INOUT:
+ return param->u.tmem.size;
+ case OPTEE_MSG_ATTR_TYPE_RMEM_INPUT:
+ case OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT:
+ case OPTEE_MSG_ATTR_TYPE_RMEM_INOUT:
+ return param->u.rmem.size;
+ default:
+ return 0;
+ }
+}
+
+/**
+ * msg_param_attr_is_tmem - helper functions that cheks if parameter is tmem
+ *
+ * @param - struct optee_msg_param to check
+ *
+ * return:
+ * corresponding size field
+ */
+static inline bool msg_param_attr_is_tmem(struct optee_msg_param *param)
+{
+ switch (param->attr & OPTEE_MSG_ATTR_TYPE_MASK) {
+ case OPTEE_MSG_ATTR_TYPE_TMEM_INPUT:
+ case OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT:
+ case OPTEE_MSG_ATTR_TYPE_TMEM_INOUT:
+ return true;
+ default:
+ return false;
+ }
+}
+
+#endif /*KERNEL_MSG_PARAM_H*/
diff --git a/core/kernel/msg_param.c b/core/kernel/msg_param.c
new file mode 100644
index 00000000..71b9f22a
--- /dev/null
+++ b/core/kernel/msg_param.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2017, EPAM Systems
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <optee_msg.h>
+#include <stdio.h>
+#include <types_ext.h>
+#include <kernel/msg_param.h>
+#include <mm/mobj.h>
+
+bool msg_param_init_memparam(struct optee_msg_param *param, struct mobj *mobj,
+ size_t offset, size_t size,
+ uint64_t cookie, enum msg_param_mem_dir dir)
+{
+ if (mobj_matches(mobj, CORE_MEM_REG_SHM)) {
+ /* Registered SHM mobj */
+ switch (dir) {
+ case MSG_PARAM_MEM_DIR_IN:
+ param->attr = OPTEE_MSG_ATTR_TYPE_RMEM_INPUT;
+ break;
+ case MSG_PARAM_MEM_DIR_OUT:
+ param->attr = OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT;
+ break;
+ case MSG_PARAM_MEM_DIR_INOUT:
+ param->attr = OPTEE_MSG_ATTR_TYPE_RMEM_INOUT;
+ break;
+ default:
+ return false;
+ }
+
+ param->u.rmem.size = size;
+ param->u.rmem.offs = offset;
+ param->u.rmem.shm_ref = cookie;
+ } else if (mobj_matches(mobj, CORE_MEM_NSEC_SHM)) {
+ /* MOBJ from from predefined pool */
+ paddr_t pa;
+
+ if (mobj_get_pa(mobj, 0, 0, &pa) != TEE_SUCCESS)
+ return false;
+
+ switch (dir) {
+ case MSG_PARAM_MEM_DIR_IN:
+ param->attr = OPTEE_MSG_ATTR_TYPE_TMEM_INPUT;
+ break;
+ case MSG_PARAM_MEM_DIR_OUT:
+ param->attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT;
+ break;
+ case MSG_PARAM_MEM_DIR_INOUT:
+ param->attr = OPTEE_MSG_ATTR_TYPE_TMEM_INOUT;
+ break;
+ default:
+ return false;
+ }
+
+ param->u.tmem.buf_ptr = pa + offset;
+ param->u.tmem.shm_ref = cookie;
+ param->u.tmem.size = size;
+ } else
+ return false;
+ return true;
+}
diff --git a/core/kernel/sub.mk b/core/kernel/sub.mk
index aee623dc..45f54f39 100644
--- a/core/kernel/sub.mk
+++ b/core/kernel/sub.mk
@@ -1,6 +1,7 @@
srcs-y += assert.c
srcs-y += console.c
srcs-$(CFG_DT) += dt.c
+srcs-y += msg_param.c
srcs-y += tee_ta_manager.c
srcs-y += tee_misc.c
srcs-y += panic.c