1 /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
2 /*
3  * Copyright (c) 2017, 2019, The Linux Foundation. All rights reserved.
4  */
5 
6 #ifndef _QSEECOM_H_
7 #define _QSEECOM_H_
8 
9 #include <linux/types.h>
10 #include <linux/ioctl.h>
11 
12 #define MAX_ION_FD  4
13 #define MAX_APP_NAME_SIZE  64
14 #define QSEECOM_HASH_SIZE  32
15 
16 /* qseecom_ta_heap allocation retry delay (ms) and max attemp count */
17 #define QSEECOM_TA_ION_ALLOCATE_DELAY           50
18 #define QSEECOM_TA_ION_ALLOCATE_MAX_ATTEMP      20
19 
20 #define ICE_KEY_SIZE 32
21 #define ICE_SALT_SIZE 32
22 
23 /*
24  * struct qseecom_register_listener_req -
25  *      for register listener ioctl request
26  * @listener_id - service id (shared between userspace and QSE)
27  * @ifd_data_fd - ion handle
28  * @virt_sb_base - shared buffer base in user space
29  * @sb_size - shared buffer size
30  */
31 struct qseecom_register_listener_req {
32 	uint32_t listener_id; /* in */
33 	int32_t ifd_data_fd; /* in */
34 	void *virt_sb_base; /* in */
35 	uint32_t sb_size; /* in */
36 };
37 
38 /*
39  * struct qseecom_send_cmd_req - for send command ioctl request
40  * @cmd_req_len - command buffer length
41  * @cmd_req_buf - command buffer
42  * @resp_len - response buffer length
43  * @resp_buf - response buffer
44  */
45 struct qseecom_send_cmd_req {
46 	void *cmd_req_buf; /* in */
47 	unsigned int cmd_req_len; /* in */
48 	void *resp_buf; /* in/out */
49 	unsigned int resp_len; /* in/out */
50 };
51 
52 /*
53  * struct qseecom_ion_fd_info - ion fd handle data information
54  * @fd - ion handle to some memory allocated in user space
55  * @cmd_buf_offset - command buffer offset
56  */
57 struct qseecom_ion_fd_info {
58 	int32_t fd;
59 	uint32_t cmd_buf_offset;
60 };
61 /*
62  * struct qseecom_send_modfd_cmd_req - for send command ioctl request
63  * @cmd_req_len - command buffer length
64  * @cmd_req_buf - command buffer
65  * @resp_len - response buffer length
66  * @resp_buf - response buffer
67  * @ifd_data_fd - ion handle to memory allocated in user space
68  * @cmd_buf_offset - command buffer offset
69  */
70 struct qseecom_send_modfd_cmd_req {
71 	void *cmd_req_buf; /* in */
72 	unsigned int cmd_req_len; /* in */
73 	void *resp_buf; /* in/out */
74 	unsigned int resp_len; /* in/out */
75 	struct qseecom_ion_fd_info ifd_data[MAX_ION_FD];
76 };
77 
78 /*
79  * struct qseecom_listener_send_resp_req - signal to continue the send_cmd req.
80  * Used as a trigger from HLOS service to notify QSEECOM that it's done with its
81  * operation and provide the response for QSEECOM can continue the incomplete
82  * command execution
83  * @resp_len - Length of the response
84  * @resp_buf - Response buffer where the response of the cmd should go.
85  */
86 struct qseecom_send_resp_req {
87 	void *resp_buf; /* in */
88 	unsigned int resp_len; /* in */
89 };
90 
91 /*
92  * struct qseecom_load_img_data - for sending image length information and
93  * ion file descriptor to the qseecom driver. ion file descriptor is used
94  * for retrieving the ion file handle and in turn the physical address of
95  * the image location.
96  * @mdt_len - Length of the .mdt file in bytes.
97  * @img_len - Length of the .mdt + .b00 +..+.bxx images files in bytes
98  * @ion_fd - Ion file descriptor used when allocating memory.
99  * @img_name - Name of the image.
100  * @app_arch - Architecture of the image, i.e. 32bit or 64bit app
101  */
102 struct qseecom_load_img_req {
103 	uint32_t mdt_len; /* in */
104 	uint32_t img_len; /* in */
105 	int32_t  ifd_data_fd; /* in */
106 	char	 img_name[MAX_APP_NAME_SIZE]; /* in */
107 	uint32_t app_arch; /* in */
108 	uint32_t app_id; /* out*/
109 };
110 
111 struct qseecom_set_sb_mem_param_req {
112 	int32_t ifd_data_fd; /* in */
113 	void *virt_sb_base; /* in */
114 	uint32_t sb_len; /* in */
115 };
116 
117 /*
118  * struct qseecom_qseos_version_req - get qseos version
119  * @qseos_version - version number
120  */
121 struct qseecom_qseos_version_req {
122 	unsigned int qseos_version; /* in */
123 };
124 
125 /*
126  * struct qseecom_qseos_app_load_query - verify if app is loaded in qsee
127  * @app_name[MAX_APP_NAME_SIZE]-  name of the app.
128  * @app_id - app id.
129  */
130 struct qseecom_qseos_app_load_query {
131 	char app_name[MAX_APP_NAME_SIZE]; /* in */
132 	uint32_t app_id; /* out */
133 	uint32_t app_arch;
134 };
135 
136 struct qseecom_send_svc_cmd_req {
137 	uint32_t cmd_id;
138 	void *cmd_req_buf; /* in */
139 	unsigned int cmd_req_len; /* in */
140 	void *resp_buf; /* in/out */
141 	unsigned int resp_len; /* in/out */
142 };
143 
144 enum qseecom_key_management_usage_type {
145 	QSEOS_KM_USAGE_DISK_ENCRYPTION = 0x01,
146 	QSEOS_KM_USAGE_FILE_ENCRYPTION = 0x02,
147 	QSEOS_KM_USAGE_UFS_ICE_DISK_ENCRYPTION = 0x03,
148 	QSEOS_KM_USAGE_SDCC_ICE_DISK_ENCRYPTION = 0x04,
149 	QSEOS_KM_USAGE_MAX
150 };
151 
152 struct qseecom_create_key_req {
153 	unsigned char hash32[QSEECOM_HASH_SIZE];
154 	enum qseecom_key_management_usage_type usage;
155 };
156 
157 struct qseecom_wipe_key_req {
158 	enum qseecom_key_management_usage_type usage;
159 	int wipe_key_flag;/* 1->remove key from storage(alone with clear key) */
160 			  /* 0->do not remove from storage (clear key) */
161 };
162 
163 struct qseecom_update_key_userinfo_req {
164 	unsigned char current_hash32[QSEECOM_HASH_SIZE];
165 	unsigned char new_hash32[QSEECOM_HASH_SIZE];
166 	enum qseecom_key_management_usage_type usage;
167 };
168 
169 #define SHA256_DIGEST_LENGTH	(256/8)
170 /*
171  * struct qseecom_save_partition_hash_req
172  * @partition_id - partition id.
173  * @hash[SHA256_DIGEST_LENGTH] -  sha256 digest.
174  */
175 struct qseecom_save_partition_hash_req {
176 	int partition_id; /* in */
177 	char digest[SHA256_DIGEST_LENGTH]; /* in */
178 };
179 
180 /*
181  * struct qseecom_is_es_activated_req
182  * @is_activated - 1=true , 0=false
183  */
184 struct qseecom_is_es_activated_req {
185 	int is_activated; /* out */
186 };
187 
188 /*
189  * struct qseecom_mdtp_cipher_dip_req
190  * @in_buf - input buffer
191  * @in_buf_size - input buffer size
192  * @out_buf - output buffer
193  * @out_buf_size - output buffer size
194  * @direction - 0=encrypt, 1=decrypt
195  */
196 struct qseecom_mdtp_cipher_dip_req {
197 	uint8_t *in_buf;
198 	uint32_t in_buf_size;
199 	uint8_t *out_buf;
200 	uint32_t out_buf_size;
201 	uint32_t direction;
202 };
203 
204 enum qseecom_bandwidth_request_mode {
205 	INACTIVE = 0,
206 	LOW,
207 	MEDIUM,
208 	HIGH,
209 };
210 
211 /*
212  * struct qseecom_send_modfd_resp - for send command ioctl request
213  * @req_len - command buffer length
214  * @req_buf - command buffer
215  * @ifd_data_fd - ion handle to memory allocated in user space
216  * @cmd_buf_offset - command buffer offset
217  */
218 struct qseecom_send_modfd_listener_resp {
219 	void *resp_buf_ptr; /* in */
220 	unsigned int resp_len; /* in */
221 	struct qseecom_ion_fd_info ifd_data[MAX_ION_FD]; /* in */
222 };
223 
224 struct qseecom_qteec_req {
225 	void    *req_ptr;
226 	uint32_t    req_len;
227 	void    *resp_ptr;
228 	uint32_t    resp_len;
229 };
230 
231 struct qseecom_qteec_modfd_req {
232 	void    *req_ptr;
233 	uint32_t    req_len;
234 	void    *resp_ptr;
235 	uint32_t    resp_len;
236 	struct qseecom_ion_fd_info ifd_data[MAX_ION_FD];
237 };
238 
239 struct qseecom_sg_entry {
240 	uint32_t phys_addr;
241 	uint32_t len;
242 };
243 
244 struct qseecom_sg_entry_64bit {
245 	uint64_t phys_addr;
246 	uint32_t len;
247 } __attribute__ ((packed));
248 
249 /*
250  * sg list buf format version
251  * 1: Legacy format to support only 512 SG list entries
252  * 2: new format to support > 512 entries
253  */
254 #define QSEECOM_SG_LIST_BUF_FORMAT_VERSION_1	1
255 #define QSEECOM_SG_LIST_BUF_FORMAT_VERSION_2	2
256 
257 struct qseecom_sg_list_buf_hdr_64bit {
258 	struct qseecom_sg_entry_64bit  blank_entry;	/* must be all 0 */
259 	uint32_t version;		/* sg list buf format version */
260 	uint64_t new_buf_phys_addr;	/* PA of new buffer */
261 	uint32_t nents_total;		/* Total number of SG entries */
262 } __attribute__ ((packed));
263 
264 #define QSEECOM_SG_LIST_BUF_HDR_SZ_64BIT	\
265 			sizeof(struct qseecom_sg_list_buf_hdr_64bit)
266 
267 #define MAX_CE_PIPE_PAIR_PER_UNIT 3
268 #define INVALID_CE_INFO_UNIT_NUM 0xffffffff
269 
270 #define CE_PIPE_PAIR_USE_TYPE_FDE 0
271 #define CE_PIPE_PAIR_USE_TYPE_PFE 1
272 
273 struct qseecom_ce_pipe_entry {
274 	int valid;
275 	unsigned int ce_num;
276 	unsigned int ce_pipe_pair;
277 };
278 
279 struct qseecom_ice_data_t {
280 	int flag;
281 };
282 
283 #define MAX_CE_INFO_HANDLE_SIZE 32
284 struct qseecom_ce_info_req {
285 	unsigned char handle[MAX_CE_INFO_HANDLE_SIZE];
286 	unsigned int usage;
287 	unsigned int unit_num;
288 	unsigned int num_ce_pipe_entries;
289 	struct qseecom_ce_pipe_entry ce_pipe_entry[MAX_CE_PIPE_PAIR_PER_UNIT];
290 };
291 
292 struct qseecom_ice_key_data_t {
293 	uint8_t key[ICE_KEY_SIZE];
294 	uint32_t key_len;
295 	uint8_t salt[ICE_SALT_SIZE];
296 	uint32_t salt_len;
297 };
298 
299 #define SG_ENTRY_SZ		sizeof(struct qseecom_sg_entry)
300 #define SG_ENTRY_SZ_64BIT	sizeof(struct qseecom_sg_entry_64bit)
301 
302 struct file;
303 
304 
305 #define QSEECOM_IOC_MAGIC    0x97
306 
307 
308 #define QSEECOM_IOCTL_REGISTER_LISTENER_REQ \
309 	_IOWR(QSEECOM_IOC_MAGIC, 1, struct qseecom_register_listener_req)
310 
311 #define QSEECOM_IOCTL_UNREGISTER_LISTENER_REQ \
312 	_IO(QSEECOM_IOC_MAGIC, 2)
313 
314 #define QSEECOM_IOCTL_SEND_CMD_REQ \
315 	_IOWR(QSEECOM_IOC_MAGIC, 3, struct qseecom_send_cmd_req)
316 
317 #define QSEECOM_IOCTL_SEND_MODFD_CMD_REQ \
318 	_IOWR(QSEECOM_IOC_MAGIC, 4, struct qseecom_send_modfd_cmd_req)
319 
320 #define QSEECOM_IOCTL_RECEIVE_REQ \
321 	_IO(QSEECOM_IOC_MAGIC, 5)
322 
323 #define QSEECOM_IOCTL_SEND_RESP_REQ \
324 	_IO(QSEECOM_IOC_MAGIC, 6)
325 
326 #define QSEECOM_IOCTL_LOAD_APP_REQ \
327 	_IOWR(QSEECOM_IOC_MAGIC, 7, struct qseecom_load_img_req)
328 
329 #define QSEECOM_IOCTL_SET_MEM_PARAM_REQ \
330 	_IOWR(QSEECOM_IOC_MAGIC, 8, struct qseecom_set_sb_mem_param_req)
331 
332 #define QSEECOM_IOCTL_UNLOAD_APP_REQ \
333 	_IO(QSEECOM_IOC_MAGIC, 9)
334 
335 #define QSEECOM_IOCTL_GET_QSEOS_VERSION_REQ \
336 	_IOWR(QSEECOM_IOC_MAGIC, 10, struct qseecom_qseos_version_req)
337 
338 #define QSEECOM_IOCTL_PERF_ENABLE_REQ \
339 	_IO(QSEECOM_IOC_MAGIC, 11)
340 
341 #define QSEECOM_IOCTL_PERF_DISABLE_REQ \
342 	_IO(QSEECOM_IOC_MAGIC, 12)
343 
344 #define QSEECOM_IOCTL_LOAD_EXTERNAL_ELF_REQ \
345 	_IOWR(QSEECOM_IOC_MAGIC, 13, struct qseecom_load_img_req)
346 
347 #define QSEECOM_IOCTL_UNLOAD_EXTERNAL_ELF_REQ \
348 	_IO(QSEECOM_IOC_MAGIC, 14)
349 
350 #define QSEECOM_IOCTL_APP_LOADED_QUERY_REQ \
351 	_IOWR(QSEECOM_IOC_MAGIC, 15, struct qseecom_qseos_app_load_query)
352 
353 #define QSEECOM_IOCTL_SEND_CMD_SERVICE_REQ \
354 	_IOWR(QSEECOM_IOC_MAGIC, 16, struct qseecom_send_svc_cmd_req)
355 
356 #define QSEECOM_IOCTL_CREATE_KEY_REQ \
357 	_IOWR(QSEECOM_IOC_MAGIC, 17, struct qseecom_create_key_req)
358 
359 #define QSEECOM_IOCTL_WIPE_KEY_REQ \
360 	_IOWR(QSEECOM_IOC_MAGIC, 18, struct qseecom_wipe_key_req)
361 
362 #define QSEECOM_IOCTL_SAVE_PARTITION_HASH_REQ \
363 	_IOWR(QSEECOM_IOC_MAGIC, 19, struct qseecom_save_partition_hash_req)
364 
365 #define QSEECOM_IOCTL_IS_ES_ACTIVATED_REQ \
366 	_IOWR(QSEECOM_IOC_MAGIC, 20, struct qseecom_is_es_activated_req)
367 
368 #define QSEECOM_IOCTL_SEND_MODFD_RESP \
369 	_IOWR(QSEECOM_IOC_MAGIC, 21, struct qseecom_send_modfd_listener_resp)
370 
371 #define QSEECOM_IOCTL_SET_BUS_SCALING_REQ \
372 	_IOWR(QSEECOM_IOC_MAGIC, 23, int)
373 
374 #define QSEECOM_IOCTL_UPDATE_KEY_USER_INFO_REQ \
375 	_IOWR(QSEECOM_IOC_MAGIC, 24, struct qseecom_update_key_userinfo_req)
376 
377 #define QSEECOM_QTEEC_IOCTL_OPEN_SESSION_REQ \
378 	_IOWR(QSEECOM_IOC_MAGIC, 30, struct qseecom_qteec_modfd_req)
379 
380 #define QSEECOM_QTEEC_IOCTL_CLOSE_SESSION_REQ \
381 	_IOWR(QSEECOM_IOC_MAGIC, 31, struct qseecom_qteec_req)
382 
383 #define QSEECOM_QTEEC_IOCTL_INVOKE_MODFD_CMD_REQ \
384 	_IOWR(QSEECOM_IOC_MAGIC, 32, struct qseecom_qteec_modfd_req)
385 
386 #define QSEECOM_QTEEC_IOCTL_REQUEST_CANCELLATION_REQ \
387 	_IOWR(QSEECOM_IOC_MAGIC, 33, struct qseecom_qteec_modfd_req)
388 
389 #define QSEECOM_IOCTL_MDTP_CIPHER_DIP_REQ \
390 	_IOWR(QSEECOM_IOC_MAGIC, 34, struct qseecom_mdtp_cipher_dip_req)
391 
392 #define QSEECOM_IOCTL_SEND_MODFD_CMD_64_REQ \
393 	_IOWR(QSEECOM_IOC_MAGIC, 35, struct qseecom_send_modfd_cmd_req)
394 
395 #define QSEECOM_IOCTL_SEND_MODFD_RESP_64 \
396 	_IOWR(QSEECOM_IOC_MAGIC, 36, struct qseecom_send_modfd_listener_resp)
397 
398 #define QSEECOM_IOCTL_GET_CE_PIPE_INFO \
399 	_IOWR(QSEECOM_IOC_MAGIC, 40, struct qseecom_ce_info_req)
400 
401 #define QSEECOM_IOCTL_FREE_CE_PIPE_INFO \
402 	_IOWR(QSEECOM_IOC_MAGIC, 41, struct qseecom_ce_info_req)
403 
404 #define QSEECOM_IOCTL_QUERY_CE_PIPE_INFO \
405 	_IOWR(QSEECOM_IOC_MAGIC, 42, struct qseecom_ce_info_req)
406 
407 #define QSEECOM_IOCTL_SET_ICE_INFO \
408 	_IOWR(QSEECOM_IOC_MAGIC, 43, struct qseecom_ice_data_t)
409 
410 #define QSEECOM_IOCTL_FBE_CLEAR_KEY \
411 	_IOWR(QSEECOM_IOC_MAGIC, 44, struct qseecom_ice_key_data_t)
412 
413 #endif /* _QSEECOM_H_ */
414