summaryrefslogtreecommitdiff
path: root/security/tlk_driver/ote_protocol.h
blob: 608ee8981e7c72af8bda6e71a87734de01f7eb20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/*
 * Copyright (c) 2013-2014 NVIDIA Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef __OTE_PROTOCOL_H__
#define __OTE_PROTOCOL_H__

#include "ote_types.h"

#define TE_IOCTL_MAGIC_NUMBER ('t')
#define TE_IOCTL_OPEN_CLIENT_SESSION \
	_IOWR(TE_IOCTL_MAGIC_NUMBER, 0x10, union te_cmd)
#define TE_IOCTL_CLOSE_CLIENT_SESSION \
	_IOWR(TE_IOCTL_MAGIC_NUMBER, 0x11, union te_cmd)
#define TE_IOCTL_LAUNCH_OPERATION \
	_IOWR(TE_IOCTL_MAGIC_NUMBER, 0x14, union te_cmd)

/* ioctls using new structs (eventually to replace current ioctls) */
#define TE_IOCTL_OPEN_CLIENT_SESSION_COMPAT \
	_IOWR(TE_IOCTL_MAGIC_NUMBER, 0x10, union te_cmd_compat)
#define TE_IOCTL_CLOSE_CLIENT_SESSION_COMPAT \
	_IOWR(TE_IOCTL_MAGIC_NUMBER, 0x11, union te_cmd_compat)
#define TE_IOCTL_LAUNCH_OPERATION_COMPAT \
	_IOWR(TE_IOCTL_MAGIC_NUMBER, 0x14, union te_cmd_compat)

#define TE_IOCTL_SS_NEW_REQ_LEGACY \
	_IOR(TE_IOCTL_MAGIC_NUMBER,  0x20, struct te_ss_op_legacy)
#define TE_IOCTL_SS_REQ_COMPLETE_LEGACY \
	_IOWR(TE_IOCTL_MAGIC_NUMBER, 0x21, struct te_ss_op_legacy)

/* ioctls using new SS structs (eventually to replace current SS ioctls) */
#define TE_IOCTL_SS_NEW_REQ \
	_IOR(TE_IOCTL_MAGIC_NUMBER,  0x20, struct te_ss_op)
#define TE_IOCTL_SS_REQ_COMPLETE \
	_IOWR(TE_IOCTL_MAGIC_NUMBER, 0x21, struct te_ss_op)

#define TE_IOCTL_MIN_NR	_IOC_NR(TE_IOCTL_OPEN_CLIENT_SESSION)
#define TE_IOCTL_MAX_NR	_IOC_NR(TE_IOCTL_SS_REQ_COMPLETE)

/* shared buffer is 2 pages: 1st are requests, 2nd are params */
#define TE_CMD_DESC_MAX	(PAGE_SIZE / sizeof(struct te_request))
#define TE_PARAM_MAX	(PAGE_SIZE / sizeof(struct te_oper_param))

#define TE_CMD_DESC_MAX_COMPAT \
	(PAGE_SIZE / sizeof(struct te_request_compat))
#define TE_PARAM_MAX_COMPAT \
	(PAGE_SIZE / sizeof(struct te_oper_param_compat))

#define MAX_EXT_SMC_ARGS	12

extern struct mutex smc_lock;
extern struct tlk_device tlk_dev;

uint32_t _tlk_generic_smc(uint32_t arg0, uintptr_t arg1, uintptr_t arg2);
uint32_t tlk_generic_smc(uint32_t arg0, uintptr_t arg1, uintptr_t arg2);
uint32_t _tlk_extended_smc(uintptr_t *args);
uint32_t tlk_extended_smc(uintptr_t *args);
void tlk_irq_handler(void);

/* errors returned by secure world in reponse to SMC calls */
enum {
	TE_ERROR_PREEMPT_BY_IRQ = 0xFFFFFFFD,
	TE_ERROR_PREEMPT_BY_FS = 0xFFFFFFFE,
};

struct tlk_device {
	struct te_request *req_addr;
	dma_addr_t req_addr_phys;
	struct te_oper_param *param_addr;
	dma_addr_t param_addr_phys;

	struct te_request_compat *req_addr_compat;
	struct te_oper_param_compat *param_addr_compat;

	char *req_param_buf;

	unsigned long *param_bitmap;

	struct list_head used_cmd_list;
	struct list_head free_cmd_list;
};

struct te_cmd_req_desc {
	struct te_request *req_addr;
	struct list_head list;
};

struct te_cmd_req_desc_compat {
	struct te_request_compat *req_addr;
	struct list_head list;
};

struct te_shmem_desc {
	struct list_head list;
	void *buffer;
	size_t size;
	unsigned int mem_type;
};

struct tlk_context {
	struct tlk_device *dev;
	struct list_head shmem_alloc_list;
};

enum {
	/* Trusted Application Calls */
	TE_SMC_OPEN_SESSION		= 0x30000001,
	TE_SMC_CLOSE_SESSION		= 0x30000002,
	TE_SMC_LAUNCH_OPERATION		= 0x30000003,

	/* Trusted OS calls */
	TE_SMC_REGISTER_REQ_BUF		= 0x32000002,
	TE_SMC_REGISTER_IRQ_HANDLER	= 0x32000004,
	TE_SMC_NS_IRQ_DONE		= 0x32000005,
	TE_SMC_INIT_LOGGER		= 0x32000007,
	TE_SMC_SS_REGISTER_HANDLER_LEGACY	= 0x32000008,
	TE_SMC_SS_REQ_COMPLETE		= 0x32000009,
	TE_SMC_SS_REGISTER_HANDLER	= 0x32000010,

	/* SIP (SOC specific) calls.  */
	TE_SMC_PROGRAM_VPR		= 0x82000003,
};

enum {
	TE_PARAM_TYPE_NONE	= 0,
	TE_PARAM_TYPE_INT_RO    = 1,
	TE_PARAM_TYPE_INT_RW    = 2,
	TE_PARAM_TYPE_MEM_RO    = 3,
	TE_PARAM_TYPE_MEM_RW    = 4,
};

struct te_oper_param {
	uint32_t index;
	uint32_t type;
	union {
		struct {
			uint32_t val;
		} Int;
		struct {
			void  *base;
			uint32_t len;
		} Mem;
	} u;
	void *next_ptr_user;
};

struct te_oper_param_compat {
	uint32_t index;
	uint32_t type;
	union {
		struct {
			uint32_t val;
		} Int;
		struct {
			uint64_t base;
			uint32_t len;
		} Mem;
	} u;
	uint64_t next_ptr_user;
};

struct te_operation {
	uint32_t command;
	struct te_oper_param *list_head;
	/* Maintain a pointer to tail of list to easily add new param node */
	struct te_oper_param *list_tail;
	uint32_t list_count;
	uint32_t status;
	uint32_t iterface_side;
};

struct te_service_id {
	uint32_t time_low;
	uint16_t time_mid;
	uint16_t time_hi_and_version;
	uint8_t clock_seq_and_node[8];
};

/*
 * OpenSession
 */
struct te_opensession {
	struct te_service_id dest_uuid;
	struct te_operation operation;
	uint32_t answer;
};

/*
 * CloseSession
 */
struct te_closesession {
	uint32_t	session_id;
	uint32_t	answer;
};

/*
 * LaunchOperation
 */
struct te_launchop {
	uint32_t		session_id;
	struct te_operation	operation;
	uint32_t		answer;
};

union te_cmd {
	struct te_opensession	opensession;
	struct te_closesession	closesession;
	struct te_launchop	launchop;
};

/*
 * Compat versions of the original structs (eventually to replace
 * the old structs, once the lib/TLK kernel changes are in).
 */
struct te_operation_compat {
	uint32_t	command;
	uint32_t	status;
	uint64_t	list_head;
	uint64_t	list_tail;
	uint32_t	list_count;
	uint32_t	interface_side;
};

/*
 * OpenSession
 */
struct te_opensession_compat {
	struct te_service_id		dest_uuid;
	struct te_operation_compat	operation;
	uint64_t			answer;
};

/*
 * CloseSession
 */
struct te_closesession_compat {
	uint32_t	session_id;
	uint64_t	answer;
};

/*
 * LaunchOperation
 */
struct te_launchop_compat {
	uint32_t			session_id;
	struct te_operation_compat	operation;
	uint64_t			answer;
};

union te_cmd_compat {
	struct te_opensession_compat	opensession;
	struct te_closesession_compat	closesession;
	struct te_launchop_compat	launchop;
};

struct te_request {
	uint32_t		type;
	uint32_t		session_id;
	uint32_t		command_id;
	struct te_oper_param	*params;
	uint32_t		params_size;
	uint32_t		dest_uuid[4];
	uint32_t		result;
	uint32_t		result_origin;
};

struct te_request_compat {
	uint32_t		type;
	uint32_t		session_id;
	uint32_t		command_id;
	uint64_t		params;
	uint32_t		params_size;
	uint32_t		dest_uuid[4];
	uint32_t		result;
	uint32_t		result_origin;
};

struct te_answer {
	uint32_t	result;
	uint32_t	session_id;
	uint32_t	result_origin;
};

void te_open_session(struct te_opensession *cmd,
	struct te_request *request,
	struct tlk_context *context);

void te_close_session(struct te_closesession *cmd,
	struct te_request *request,
	struct tlk_context *context);

void te_launch_operation(struct te_launchop *cmd,
	struct te_request *request,
	struct tlk_context *context);

void te_open_session_compat(struct te_opensession_compat *cmd,
	struct te_request_compat *request,
	struct tlk_context *context);

void te_close_session_compat(struct te_closesession_compat *cmd,
	struct te_request_compat *request,
	struct tlk_context *context);

void te_launch_operation_compat(struct te_launchop_compat *cmd,
	struct te_request_compat *request,
	struct tlk_context *context);

#define SS_OP_MAX_DATA_SIZE	0x1000
struct te_ss_op {
	uint32_t	req_size;
	uint8_t		data[SS_OP_MAX_DATA_SIZE];
};

struct te_ss_op_legacy {
	uint8_t		data[SS_OP_MAX_DATA_SIZE];
};

int te_handle_ss_ioctl_legacy(struct file *file, unsigned int ioctl_num,
		unsigned long ioctl_param);
int te_handle_ss_ioctl(struct file *file, unsigned int ioctl_num,
		unsigned long ioctl_param);
int te_handle_fs_ioctl(struct file *file, unsigned int ioctl_num,
		unsigned long ioctl_param);
void ote_print_logs(void);
void tlk_ss_op(void);

#endif