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