diff options
author | Trusted Logic <smc_support@trusted-logic.com> | 2011-10-06 14:25:21 -0500 |
---|---|---|
committer | Dan Murphy <dmurphy@ti.com> | 2011-10-12 08:07:16 -0500 |
commit | ae18a33b00dc18b45e06355a78f1506a96fc1cb4 (patch) | |
tree | adc071d5e7a5b415003b19855f55969c0994ba28 /security | |
parent | 103b37e48d5f22803545b070e3bc30ff9473466b (diff) | |
download | kernel_samsung_espresso10-ae18a33b00dc18b45e06355a78f1506a96fc1cb4.zip kernel_samsung_espresso10-ae18a33b00dc18b45e06355a78f1506a96fc1cb4.tar.gz kernel_samsung_espresso10-ae18a33b00dc18b45e06355a78f1506a96fc1cb4.tar.bz2 |
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/Makefile | 1 | ||||
-rw-r--r-- | security/smc/tf_conn.c | 87 | ||||
-rw-r--r-- | security/smc/tf_defs.h | 9 | ||||
-rw-r--r-- | security/smc/tf_device.c | 76 | ||||
-rw-r--r-- | security/smc/tf_protocol.h | 5 |
5 files changed, 178 insertions, 0 deletions
diff --git a/security/smc/Makefile b/security/smc/Makefile index ca49932..422a69f 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 660add6..ec8eeb7 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 a8a5ce5..23dc7ca 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 86313de..7c2c623 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 d7bbd7d..e3e6485 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__) */ |