2 * Copyright (c) 2013-2014 NVIDIA Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <linux/slab.h>
20 #include <linux/syscalls.h>
21 #include <linux/list.h>
22 #include <linux/completion.h>
23 #include <linux/workqueue.h>
24 #include <linux/bitops.h>
25 #include <linux/uaccess.h>
26 #include <linux/dma-mapping.h>
28 #include "ote_protocol.h"
30 static DECLARE_COMPLETION(req_ready);
31 static DECLARE_COMPLETION(req_complete);
33 static struct te_ss_op_legacy *ss_op_shmem_legacy;
34 static struct te_ss_op *ss_op_shmem;
35 static uint32_t ss_op_size;
37 static void indicate_ss_op_complete(void)
39 tlk_generic_smc(TE_SMC_SS_REQ_COMPLETE, 0, 0);
42 int te_handle_ss_ioctl_legacy(struct file *file, unsigned int ioctl_num,
43 unsigned long ioctl_param)
46 case TE_IOCTL_SS_NEW_REQ_LEGACY:
47 /* wait for a new request */
48 if (wait_for_completion_interruptible(&req_ready))
51 /* transfer pending request to daemon's buffer */
52 if (copy_to_user((void __user *)ioctl_param, ss_op_shmem_legacy,
54 pr_err("copy_to_user failed for new request\n");
59 case TE_IOCTL_SS_REQ_COMPLETE_LEGACY: /* request complete */
60 if (copy_from_user(ss_op_shmem_legacy,
61 (void __user *)ioctl_param, ss_op_size)) {
62 pr_err("copy_from_user failed for request\n");
66 /* signal the producer */
67 complete(&req_complete);
74 void tlk_ss_op_legacy(uint32_t size)
76 /* store size of request */
82 /* wait for the consumer's signal */
83 wait_for_completion(&req_complete);
85 /* signal completion to the secure world */
86 indicate_ss_op_complete();
89 static int __init tlk_ss_init_legacy(void)
91 dma_addr_t ss_op_shmem_dma;
93 /* allocate shared memory buffer */
94 ss_op_shmem_legacy = dma_alloc_coherent(NULL,
95 sizeof(struct te_ss_op_legacy), &ss_op_shmem_dma, GFP_KERNEL);
96 if (!ss_op_shmem_legacy) {
97 pr_err("%s: no memory available for fs operations\n", __func__);
101 tlk_generic_smc(TE_SMC_SS_REGISTER_HANDLER_LEGACY,
102 (uintptr_t)tlk_ss_op_legacy, (uintptr_t)ss_op_shmem_legacy);
107 arch_initcall(tlk_ss_init_legacy);
109 int te_handle_ss_ioctl(struct file *file, unsigned int ioctl_num,
110 unsigned long ioctl_param)
113 case TE_IOCTL_SS_NEW_REQ:
114 /* wait for a new request */
115 if (wait_for_completion_interruptible(&req_ready))
118 /* transfer pending request to daemon's buffer */
119 if (copy_to_user((void __user *)ioctl_param, ss_op_shmem->data,
120 ss_op_shmem->req_size)) {
121 pr_err("copy_to_user failed for new request\n");
126 case TE_IOCTL_SS_REQ_COMPLETE: /* request complete */
127 if (copy_from_user(ss_op_shmem->data,
128 (void __user *)ioctl_param, ss_op_shmem->req_size)) {
129 pr_err("copy_from_user failed for request\n");
133 /* signal the producer */
134 complete(&req_complete);
143 /* signal consumer */
144 complete(&req_ready);
146 /* wait for the consumer's signal */
147 wait_for_completion(&req_complete);
150 static int __init tlk_ss_init(void)
152 dma_addr_t ss_op_shmem_dma;
155 /* allocate shared memory buffer */
156 ss_op_shmem = dma_alloc_coherent(NULL, sizeof(struct te_ss_op),
157 &ss_op_shmem_dma, GFP_KERNEL);
159 pr_err("%s: no memory available for fs operations\n", __func__);
163 ret = tlk_generic_smc(TE_SMC_SS_REGISTER_HANDLER,
164 (uintptr_t)ss_op_shmem, 0);
166 dma_free_coherent(NULL, sizeof(struct te_ss_op),
167 (void *)ss_op_shmem, ss_op_shmem_dma);
175 arch_initcall(tlk_ss_init);