security: nv_tee_driver: add return origin & input/output param support
[linux-3.10.git] / security / nv_tee_driver / tee_protocol.h
1 /*
2  * Copyright (c) 2013, NVIDIA Corporation.
3  *
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.
8  *
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
12  * more details.
13  *
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.
17  */
18
19 #ifndef __NV_TEE_PROTOCOL_H
20 #define __NV_TEE_PROTOCOL_H
21
22 #include "tee_types.h"
23 #include "tee_client_api.h"
24
25 #define TEE_IOCTL_MAGIC_NUMBER ('t')
26 #define TEE_IOCTL_OPEN_CLIENT_SESSION \
27         _IOWR(TEE_IOCTL_MAGIC_NUMBER, 0x10, union tee_cmd)
28 #define TEE_IOCTL_CLOSE_CLIENT_SESSION \
29         _IOWR(TEE_IOCTL_MAGIC_NUMBER, 0x11, union tee_cmd)
30 #define TEE_IOCTL_REGISTER_MEMORY \
31         _IOWR(TEE_IOCTL_MAGIC_NUMBER, 0x12, union tee_cmd)
32 #define TEE_IOCTL_RELEASE_SHARED_MEM \
33         _IOWR(TEE_IOCTL_MAGIC_NUMBER, 0x13, struct TEEC_SharedMemory)
34 #define TEE_IOCTL_INVOKE_COMMAND \
35         _IOWR(TEE_IOCTL_MAGIC_NUMBER, 0x14, union tee_cmd)
36 #define TEE_IOCTL_REQ_CANCELLATION \
37         _IOR(TEE_IOCTL_MAGIC_NUMBER, 0x15, union tee_cmd)
38
39 #define TEE_IOCTL_MIN_NR        _IOC_NR(TEE_IOCTL_OPEN_CLIENT_SESSION)
40 #define TEE_IOCTL_MAX_NR        _IOC_NR(TEE_IOCTL_REQ_CANCELLATION)
41
42 #define NV_CMD_DESC_MAX 120
43
44 extern void nv_tee_irq_handler(void);
45
46 struct nv_device {
47         unsigned long param_addr;
48         struct list_head used_cmd_list;
49         struct list_head free_cmd_list;
50 };
51
52 struct nv_cmd_param_desc {
53         unsigned long param_addr;
54         struct list_head list;
55 };
56
57 struct nv_shmem_desc {
58         struct list_head list;
59         void *buffer;
60         size_t size;
61         unsigned int mem_type;
62         struct page **pages;
63         unsigned int nr_pages;
64 };
65
66 struct nv_tee_context {
67         struct nv_device *dev;
68         struct list_head shmem_alloc_list;
69 };
70
71 enum {
72         /* Do a tee invoke */
73         TMK_SMC_INVOKE_CMD = 0xFFFF1000,
74         /* Get a pending answer without making new invokes */
75         TMK_SMC_GET_MORE = 0xFFFF1001,
76         /* Answer from secure side */
77         TMK_SMC_ANSWER = 0xFFFF1002,
78         /* No answers for now (secure side idle) */
79         TMK_SMC_NO_ANSWER = 0xFFFF1003,
80         /* Open Session */
81         TMK_SMC_OPEN_SESSION = 0xFFFF1004,
82         /* Close Session */
83         TMK_SMC_CLOSE_SESSION = 0xFFFF1005,
84         /* Alloc Shared Memory*/
85         TMK_SMC_ALLOC_SHARED_MEM = 0xFFFF1006,
86         /* Register Shared Memory*/
87         TMK_SMC_REG_SHARED_MEM = 0xFFFF1007,
88         /* Release Shared Memory*/
89         TMK_SMC_RELEASE_SHARED_MEM = 0xFFFF1008,
90 };
91
92 union tee_param {
93         struct {
94                 void    *buffer;
95                 size_t  size;
96         } memref;
97         struct {
98                 uint32_t        a;
99                 uint32_t        b;
100         } value;
101 };
102
103 /*
104  * structures for user app communication
105  */
106
107 /*
108  * OpenSession
109  */
110
111 struct tee_opensession {
112         struct TEEC_UUID dest_uuid;
113         uint32_t login_types;
114         uint32_t login_data;
115         struct TEEC_Operation operation;
116         uint32_t answer;
117 };
118
119 /*
120  * CloseSession
121  */
122 struct tee_closesession {
123         uint32_t        session_id;
124         uint32_t        answer;
125 };
126
127 /*
128  * Shared Memory request
129  */
130 struct tee_sharedmem {
131         uint32_t                session_id;
132         uint32_t                command_id;
133         struct TEEC_SharedMemory        memref;
134         uint32_t                answer;
135 };
136
137 /*
138  * Invoke Command request
139  */
140 struct tee_invokecmd {
141         uint32_t        session_id;
142         uint32_t        command_id;
143         struct TEEC_Operation   operation;
144         uint32_t        answer;
145 };
146
147 /*
148  * Request Cancellation request
149  */
150 struct tee_req_cancellation {
151         uint32_t        session_id;
152         uint32_t        command_id;
153         struct TEEC_Operation   operation;
154         uint32_t        answer;
155 };
156
157 union tee_cmd {
158         struct tee_opensession          opensession;
159         struct tee_closesession         closesession;
160         struct tee_sharedmem            sharedmem;
161         struct TEEC_SharedMemory                release_shared_mem;
162         struct tee_invokecmd            invokecmd;
163         struct tee_req_cancellation     cancellation;
164 };
165
166 struct tee_cmd_param {
167         uint32_t        param_types;
168         union tee_param params[4];
169         uint32_t        dest_uuid[4];
170 };
171
172 struct tee_request {
173         uint32_t                type;
174         uint32_t                session_id;
175         uint32_t                command_id;
176         struct tee_cmd_param    cmd_param;
177         uint32_t                result;
178         uint32_t                result_origin;
179 };
180
181 struct tee_answer {
182         uint32_t        type;
183         uint32_t        result;
184         uint32_t        return_origin;
185         uint32_t        session_id;
186         union TEEC_Param        params[4];
187 };
188
189 void tee_open_session(struct tee_opensession *cmd,
190         struct tee_request *request,
191         struct nv_tee_context *context);
192
193 void tee_close_session(struct tee_closesession *cmd,
194                 struct tee_request *request);
195
196 void tee_register_memory(struct tee_sharedmem *cmd,
197         struct tee_request *request,
198         struct nv_tee_context *context);
199
200 void tee_invoke_command(struct tee_invokecmd *cmd,
201         struct tee_request *request,
202         struct nv_tee_context *context);
203
204 void tee_unregister_memory(void *buffer,
205         struct nv_tee_context *context);
206
207 #endif