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 #ifndef __OTE_PROTOCOL_H__
20 #define __OTE_PROTOCOL_H__
22 #include "ote_types.h"
24 #define TE_IOCTL_MAGIC_NUMBER ('t')
25 #define TE_IOCTL_OPEN_CLIENT_SESSION \
26 _IOWR(TE_IOCTL_MAGIC_NUMBER, 0x10, union te_cmd)
27 #define TE_IOCTL_CLOSE_CLIENT_SESSION \
28 _IOWR(TE_IOCTL_MAGIC_NUMBER, 0x11, union te_cmd)
29 #define TE_IOCTL_LAUNCH_OPERATION \
30 _IOWR(TE_IOCTL_MAGIC_NUMBER, 0x14, union te_cmd)
32 /* ioctls using new structs (eventually to replace current ioctls) */
33 #define TE_IOCTL_OPEN_CLIENT_SESSION_COMPAT \
34 _IOWR(TE_IOCTL_MAGIC_NUMBER, 0x10, union te_cmd_compat)
35 #define TE_IOCTL_CLOSE_CLIENT_SESSION_COMPAT \
36 _IOWR(TE_IOCTL_MAGIC_NUMBER, 0x11, union te_cmd_compat)
37 #define TE_IOCTL_LAUNCH_OPERATION_COMPAT \
38 _IOWR(TE_IOCTL_MAGIC_NUMBER, 0x14, union te_cmd_compat)
40 #define TE_IOCTL_SS_NEW_REQ_LEGACY \
41 _IOR(TE_IOCTL_MAGIC_NUMBER, 0x20, struct te_ss_op_legacy)
42 #define TE_IOCTL_SS_REQ_COMPLETE_LEGACY \
43 _IOWR(TE_IOCTL_MAGIC_NUMBER, 0x21, struct te_ss_op_legacy)
45 /* ioctls using new SS structs (eventually to replace current SS ioctls) */
46 #define TE_IOCTL_SS_NEW_REQ \
47 _IOR(TE_IOCTL_MAGIC_NUMBER, 0x20, struct te_ss_op)
48 #define TE_IOCTL_SS_REQ_COMPLETE \
49 _IOWR(TE_IOCTL_MAGIC_NUMBER, 0x21, struct te_ss_op)
51 #define TE_IOCTL_MIN_NR _IOC_NR(TE_IOCTL_OPEN_CLIENT_SESSION)
52 #define TE_IOCTL_MAX_NR _IOC_NR(TE_IOCTL_SS_REQ_COMPLETE)
54 /* shared buffer is 2 pages: 1st are requests, 2nd are params */
55 #define TE_CMD_DESC_MAX (PAGE_SIZE / sizeof(struct te_request))
56 #define TE_PARAM_MAX (PAGE_SIZE / sizeof(struct te_oper_param))
58 #define TE_CMD_DESC_MAX_COMPAT \
59 (PAGE_SIZE / sizeof(struct te_request_compat))
60 #define TE_PARAM_MAX_COMPAT \
61 (PAGE_SIZE / sizeof(struct te_oper_param_compat))
63 #define MAX_EXT_SMC_ARGS 12
65 extern struct mutex smc_lock;
66 extern struct tlk_device tlk_dev;
68 uint32_t _tlk_generic_smc(uint32_t arg0, uintptr_t arg1, uintptr_t arg2);
69 uint32_t tlk_generic_smc(uint32_t arg0, uintptr_t arg1, uintptr_t arg2);
70 uint32_t _tlk_extended_smc(uintptr_t *args);
71 uint32_t tlk_extended_smc(uintptr_t *args);
72 void tlk_irq_handler(void);
74 /* errors returned by secure world in reponse to SMC calls */
76 TE_ERROR_PREEMPT_BY_IRQ = 0xFFFFFFFD,
77 TE_ERROR_PREEMPT_BY_FS = 0xFFFFFFFE,
81 struct te_request *req_addr;
82 dma_addr_t req_addr_phys;
83 struct te_oper_param *param_addr;
84 dma_addr_t param_addr_phys;
86 struct te_request_compat *req_addr_compat;
87 struct te_oper_param_compat *param_addr_compat;
91 unsigned long *param_bitmap;
93 struct list_head used_cmd_list;
94 struct list_head free_cmd_list;
97 struct te_cmd_req_desc {
98 struct te_request *req_addr;
99 struct list_head list;
102 struct te_cmd_req_desc_compat {
103 struct te_request_compat *req_addr;
104 struct list_head list;
107 struct te_shmem_desc {
108 struct list_head list;
111 unsigned int mem_type;
115 struct tlk_device *dev;
116 struct list_head shmem_alloc_list;
120 /* Trusted Application Calls */
121 TE_SMC_OPEN_SESSION = 0x30000001,
122 TE_SMC_CLOSE_SESSION = 0x30000002,
123 TE_SMC_LAUNCH_OPERATION = 0x30000003,
125 /* Trusted OS calls */
126 TE_SMC_REGISTER_REQ_BUF = 0x32000002,
127 TE_SMC_REGISTER_IRQ_HANDLER = 0x32000004,
128 TE_SMC_NS_IRQ_DONE = 0x32000005,
129 TE_SMC_INIT_LOGGER = 0x32000007,
130 TE_SMC_SS_REGISTER_HANDLER_LEGACY = 0x32000008,
131 TE_SMC_SS_REQ_COMPLETE = 0x32000009,
132 TE_SMC_SS_REGISTER_HANDLER = 0x32000010,
134 /* SIP (SOC specific) calls. */
135 TE_SMC_PROGRAM_VPR = 0x82000003,
139 TE_PARAM_TYPE_NONE = 0,
140 TE_PARAM_TYPE_INT_RO = 1,
141 TE_PARAM_TYPE_INT_RW = 2,
142 TE_PARAM_TYPE_MEM_RO = 3,
143 TE_PARAM_TYPE_MEM_RW = 4,
146 struct te_oper_param {
161 struct te_oper_param_compat {
173 uint64_t next_ptr_user;
176 struct te_operation {
178 struct te_oper_param *list_head;
179 /* Maintain a pointer to tail of list to easily add new param node */
180 struct te_oper_param *list_tail;
183 uint32_t iterface_side;
186 struct te_service_id {
189 uint16_t time_hi_and_version;
190 uint8_t clock_seq_and_node[8];
196 struct te_opensession {
197 struct te_service_id dest_uuid;
198 struct te_operation operation;
205 struct te_closesession {
215 struct te_operation operation;
220 struct te_opensession opensession;
221 struct te_closesession closesession;
222 struct te_launchop launchop;
226 * Compat versions of the original structs (eventually to replace
227 * the old structs, once the lib/TLK kernel changes are in).
229 struct te_operation_compat {
235 uint32_t interface_side;
241 struct te_opensession_compat {
242 struct te_service_id dest_uuid;
243 struct te_operation_compat operation;
250 struct te_closesession_compat {
258 struct te_launchop_compat {
260 struct te_operation_compat operation;
264 union te_cmd_compat {
265 struct te_opensession_compat opensession;
266 struct te_closesession_compat closesession;
267 struct te_launchop_compat launchop;
274 struct te_oper_param *params;
275 uint32_t params_size;
276 uint32_t dest_uuid[4];
278 uint32_t result_origin;
281 struct te_request_compat {
286 uint32_t params_size;
287 uint32_t dest_uuid[4];
289 uint32_t result_origin;
295 uint32_t result_origin;
298 void te_open_session(struct te_opensession *cmd,
299 struct te_request *request,
300 struct tlk_context *context);
302 void te_close_session(struct te_closesession *cmd,
303 struct te_request *request,
304 struct tlk_context *context);
306 void te_launch_operation(struct te_launchop *cmd,
307 struct te_request *request,
308 struct tlk_context *context);
310 void te_open_session_compat(struct te_opensession_compat *cmd,
311 struct te_request_compat *request,
312 struct tlk_context *context);
314 void te_close_session_compat(struct te_closesession_compat *cmd,
315 struct te_request_compat *request,
316 struct tlk_context *context);
318 void te_launch_operation_compat(struct te_launchop_compat *cmd,
319 struct te_request_compat *request,
320 struct tlk_context *context);
322 #define SS_OP_MAX_DATA_SIZE 0x1000
325 uint8_t data[SS_OP_MAX_DATA_SIZE];
328 struct te_ss_op_legacy {
329 uint8_t data[SS_OP_MAX_DATA_SIZE];
332 int te_handle_ss_ioctl_legacy(struct file *file, unsigned int ioctl_num,
333 unsigned long ioctl_param);
334 int te_handle_ss_ioctl(struct file *file, unsigned int ioctl_num,
335 unsigned long ioctl_param);
336 int te_handle_fs_ioctl(struct file *file, unsigned int ioctl_num,
337 unsigned long ioctl_param);
338 void ote_print_logs(void);
339 void tlk_ss_op(void);