aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorTrusted Logic <smc_support@trusted-logic.com>2011-10-06 14:25:21 -0500
committerBrian Swetland <swetland@google.com>2011-10-06 16:30:07 -0700
commitd293e31fe62677a0f612bb176fbbf7bc43f71039 (patch)
treee1d94bde54c275ce37023b0895c5e3fdded7d423 /security
parent18cfb8434c77570967dcecb4fe24aac05296fe7f (diff)
downloadkernel_samsung_tuna-d293e31fe62677a0f612bb176fbbf7bc43f71039.tar.gz
kernel_samsung_tuna-d293e31fe62677a0f612bb176fbbf7bc43f71039.tar.bz2
kernel_samsung_tuna-d293e31fe62677a0f612bb176fbbf7bc43f71039.zip
OMAP4: SMC: Introduce ION Handler
Change-Id: I5b60b02771ca56c9296a41f813c7807599904384 Signed-off-by: Gonzalo Alexandre <alexandre.gonzalo@trusted-logic.com> Signed-off-by: Florian Sylvestre <florian.sylvestre@trusted-logic.com> Signed-off-by: Praneeth Bajjuri <praneeth@ti.com> Signed-off-by: Trusted Logic <smc_support@trusted-logic.com> Signed-off-by: Bryan Buckley <bryan.buckley@ti.com>
Diffstat (limited to 'security')
-rw-r--r--security/smc/Makefile1
-rw-r--r--security/smc/tf_conn.c87
-rw-r--r--security/smc/tf_defs.h9
-rw-r--r--security/smc/tf_device.c76
-rw-r--r--security/smc/tf_protocol.h5
5 files changed, 178 insertions, 0 deletions
diff --git a/security/smc/Makefile b/security/smc/Makefile
index ca49932649b..422a69f0c40 100644
--- a/security/smc/Makefile
+++ b/security/smc/Makefile
@@ -25,6 +25,7 @@ endif
EXTRA_CFLAGS += -Iarch/arm/mach-omap2
EXTRA_CFLAGS += -Iarch/arm/plat-omap/include/plat
EXTRA_CFLAGS += -DCONFIG_TF_TEEC
+EXTRA_CFLAGS += -DCONFIG_TF_ION
tf_driver-objs += tf_util.o
tf_driver-objs += tf_conn.o
diff --git a/security/smc/tf_conn.c b/security/smc/tf_conn.c
index 660add6dbf7..ec8eeb7b58e 100644
--- a/security/smc/tf_conn.c
+++ b/security/smc/tf_conn.c
@@ -1227,6 +1227,9 @@ error:
}
+#ifdef CONFIG_TF_ION
+extern struct ion_device *omap_ion_device;
+#endif /* CONFIG_TF_ION */
/*
* Invokes a client command to the Secure World
*/
@@ -1238,6 +1241,9 @@ int tf_invoke_client_command(
int error = 0;
struct tf_shmem_desc *shmem_desc[4] = {NULL};
int i;
+#ifdef CONFIG_TF_ION
+ struct ion_handle *new_handle = NULL;
+#endif /* CONFIG_TF_ION */
dprintk(KERN_INFO "tf_invoke_client_command(%p)\n", connection);
@@ -1274,6 +1280,78 @@ int tf_invoke_client_command(
goto error;
}
}
+#ifdef CONFIG_TF_ION
+ else if (param_type == TF_PARAM_TYPE_MEMREF_ION_HANDLE) {
+ struct tf_command_invoke_client_command *invoke;
+ ion_phys_addr_t ion_addr;
+ size_t ion_len;
+ struct ion_buffer *buffer;
+
+ if (connection->ion_client == NULL) {
+ connection->ion_client = ion_client_create(
+ omap_ion_device,
+ (1 << ION_HEAP_TYPE_CARVEOUT),
+ "smc");
+ }
+ if (connection->ion_client == NULL) {
+ dprintk(KERN_ERR "%s(%p): "
+ "unable to create ion client\n",
+ __func__, connection);
+ error = -EFAULT;
+ goto error;
+ }
+
+ invoke = &command->invoke_client_command;
+
+ dprintk(KERN_INFO "ion_handle %x",
+ invoke->params[i].value.a);
+ buffer = ion_share(connection->ion_client,
+ (struct ion_handle *)invoke->params[i].value.a);
+ if (buffer == NULL) {
+ dprintk(KERN_ERR "%s(%p): "
+ "unable to share ion handle\n",
+ __func__, connection);
+ error = -EFAULT;
+ goto error;
+ }
+
+ dprintk(KERN_INFO "ion_buffer %p", buffer);
+ new_handle = ion_import(connection->ion_client, buffer);
+ if (new_handle == NULL) {
+ dprintk(KERN_ERR "%s(%p): "
+ "unable to import ion buffer\n",
+ __func__, connection);
+ error = -EFAULT;
+ goto error;
+ }
+
+ dprintk(KERN_INFO "new_handle %x", new_handle);
+ error = ion_phys(connection->ion_client,
+ new_handle,
+ &ion_addr,
+ &ion_len);
+ if (error) {
+ dprintk(KERN_ERR
+ "%s: unable to convert ion handle "
+ "0x%08X (error code 0x%08X)\n",
+ __func__,
+ new_handle,
+ error);
+ error = -EINVAL;
+ goto error;
+ }
+ dprintk(KERN_INFO
+ "%s: handle=0x%08x phys_add=0x%08x length=0x%08x\n",
+ __func__, invoke->params[i].value.a, ion_addr, ion_len);
+
+ invoke->params[i].value.a = (u32) ion_addr;
+ invoke->params[i].value.b = (u32) ion_len;
+
+ invoke->param_types &= ~((0xF) << (4*i));
+ invoke->param_types |=
+ TF_PARAM_TYPE_VALUE_INPUT << (4*i);
+ }
+#endif /* CONFIG_TF_ION */
}
command->invoke_client_command.device_context =
@@ -1283,6 +1361,10 @@ int tf_invoke_client_command(
answer, connection, true);
error:
+#ifdef CONFIG_TF_ION
+ if (new_handle != NULL)
+ ion_free(connection->ion_client, new_handle);
+#endif /* CONFIG_TF_ION */
/* Unmap de temp mem refs */
for (i = 0; i < 4; i++) {
if (shmem_desc[i] != NULL) {
@@ -1553,6 +1635,11 @@ void tf_close(struct tf_connection *connection)
*/
tf_cleanup_shared_memories(connection);
+#ifdef CONFIG_TF_ION
+ if (connection->ion_client != NULL)
+ ion_client_destroy(connection->ion_client);
+#endif
+
spin_lock(&(connection->dev->connection_list_lock));
list_del(&(connection->list));
spin_unlock(&(connection->dev->connection_list_lock));
diff --git a/security/smc/tf_defs.h b/security/smc/tf_defs.h
index a8a5ce50f2e..23dc7ca9cd7 100644
--- a/security/smc/tf_defs.h
+++ b/security/smc/tf_defs.h
@@ -36,6 +36,11 @@
#include "tf_protocol.h"
+#ifdef CONFIG_TF_ION
+#include <linux/ion.h>
+#include <linux/omap_ion.h>
+#endif
+
/*----------------------------------------------------------------------------*/
#define SIZE_1KB 0x400
@@ -497,6 +502,10 @@ struct tf_connection {
/* Lock to protect concurrent accesses to shortcut_list */
spinlock_t shortcut_list_lock;
#endif
+
+#ifdef CONFIG_TF_ION
+ struct ion_client *ion_client;
+#endif
};
/*----------------------------------------------------------------------------*/
diff --git a/security/smc/tf_device.c b/security/smc/tf_device.c
index 86313de57d6..7c2c62380b3 100644
--- a/security/smc/tf_device.c
+++ b/security/smc/tf_device.c
@@ -43,6 +43,10 @@
#include "s_version.h"
+#ifdef CONFIG_TF_ION
+extern struct ion_device *omap_ion_device;
+#endif
+
/*----------------------------------------------------------------------------
* Forward Declarations
*----------------------------------------------------------------------------*/
@@ -442,6 +446,78 @@ static long tf_device_ioctl(struct file *file, unsigned int ioctl_num,
result = TF_DRIVER_INTERFACE_VERSION;
goto exit;
+#ifdef CONFIG_TF_ION
+ case IOCTL_TF_ION_REGISTER: {
+ int ion_register;
+ /* ioctl is asking to register an ion handle */
+ if (copy_from_user(&ion_register,
+ (int *) ioctl_param,
+ sizeof(int))) {
+ dprintk(KERN_ERR "tf_device_ioctl(%p): "
+ "copy_from_user failed\n",
+ file);
+ result = -EFAULT;
+ goto exit;
+ }
+
+ connection = tf_conn_from_file(file);
+ BUG_ON(connection == NULL);
+
+ /* Initialize ION connection */
+ if (connection->ion_client == NULL) {
+ connection->ion_client = ion_client_create(
+ omap_ion_device,
+ (1 << ION_HEAP_TYPE_CARVEOUT),
+ "smc");
+ }
+
+ if (connection->ion_client == NULL) {
+ dprintk(KERN_ERR "tf_device_ioctl(%p): "
+ "unable to create ion client\n",
+ file);
+ result = -EFAULT;
+ goto exit;
+ }
+
+ /*
+ * TODO: We should use a reference count on this handle in order
+ * to not unregistered it while using it.
+ */
+ return (long)ion_import_fd(connection->ion_client, ion_register);
+ }
+
+ case IOCTL_TF_ION_UNREGISTER: {
+ int ion_register;
+ /* ioctl is asking to unregister an ion handle */
+
+ if (copy_from_user(&ion_register,
+ (int *) ioctl_param,
+ sizeof(int))) {
+ dprintk(KERN_ERR "tf_device_ioctl(%p): "
+ "copy_from_user failed\n",
+ file);
+ result = -EFAULT;
+ goto exit;
+ }
+
+ connection = tf_conn_from_file(file);
+ BUG_ON(connection == NULL);
+
+ if (connection->ion_client == NULL) {
+ dprintk(KERN_ERR "tf_device_ioctl(%p): "
+ "ion client does not exist\n",
+ file);
+ result = -EFAULT;
+ goto exit;
+ }
+
+ ion_free(connection->ion_client,
+ (struct ion_handle *) ion_register);
+
+ return S_SUCCESS;
+ }
+#endif
+
case IOCTL_TF_EXCHANGE:
/*
* ioctl is asking to perform a message exchange with the Secure
diff --git a/security/smc/tf_protocol.h b/security/smc/tf_protocol.h
index d7bbd7d50f3..e3e6485ed90 100644
--- a/security/smc/tf_protocol.h
+++ b/security/smc/tf_protocol.h
@@ -233,6 +233,7 @@ union tf_answer_param {
#define TF_PARAM_TYPE_MEMREF_TEMP_INPUT 0x5
#define TF_PARAM_TYPE_MEMREF_TEMP_OUTPUT 0x6
#define TF_PARAM_TYPE_MEMREF_TEMP_INOUT 0x7
+#define TF_PARAM_TYPE_MEMREF_ION_HANDLE 0xB
#define TF_PARAM_TYPE_MEMREF_INPUT 0xD
#define TF_PARAM_TYPE_MEMREF_OUTPUT 0xE
#define TF_PARAM_TYPE_MEMREF_INOUT 0xF
@@ -665,5 +666,9 @@ struct tf_version_information_buffer {
#define IOCTL_TF_EXCHANGE _IOWR('z', 1, union tf_command)
#define IOCTL_TF_GET_DESCRIPTION _IOR('z', 2, \
struct tf_version_information_buffer)
+#ifdef CONFIG_TF_ION
+#define IOCTL_TF_ION_REGISTER _IOR('z', 254, int)
+#define IOCTL_TF_ION_UNREGISTER _IOR('z', 255, int)
+#endif
#endif /* !defined(__TF_PROTOCOL_H__) */