1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
4  * Copyright (C) 2017 Linaro Ltd.
5  */
6 #include <linux/overflow.h>
7 #include <linux/errno.h>
8 #include <linux/hash.h>
9 
10 #include "hfi_cmds.h"
11 
12 static enum hfi_version hfi_ver;
13 
14 void pkt_sys_init(struct hfi_sys_init_pkt *pkt, u32 arch_type)
15 {
16 	pkt->hdr.size = sizeof(*pkt);
17 	pkt->hdr.pkt_type = HFI_CMD_SYS_INIT;
18 	pkt->arch_type = arch_type;
19 }
20 
21 void pkt_sys_pc_prep(struct hfi_sys_pc_prep_pkt *pkt)
22 {
23 	pkt->hdr.size = sizeof(*pkt);
24 	pkt->hdr.pkt_type = HFI_CMD_SYS_PC_PREP;
25 }
26 
27 void pkt_sys_idle_indicator(struct hfi_sys_set_property_pkt *pkt, u32 enable)
28 {
29 	struct hfi_enable *hfi = (struct hfi_enable *)&pkt->data[1];
30 
31 	pkt->hdr.size = struct_size(pkt, data, 1) + sizeof(*hfi);
32 	pkt->hdr.pkt_type = HFI_CMD_SYS_SET_PROPERTY;
33 	pkt->num_properties = 1;
34 	pkt->data[0] = HFI_PROPERTY_SYS_IDLE_INDICATOR;
35 	hfi->enable = enable;
36 }
37 
38 void pkt_sys_debug_config(struct hfi_sys_set_property_pkt *pkt, u32 mode,
39 			  u32 config)
40 {
41 	struct hfi_debug_config *hfi;
42 
43 	pkt->hdr.size = struct_size(pkt, data, 1) + sizeof(*hfi);
44 	pkt->hdr.pkt_type = HFI_CMD_SYS_SET_PROPERTY;
45 	pkt->num_properties = 1;
46 	pkt->data[0] = HFI_PROPERTY_SYS_DEBUG_CONFIG;
47 	hfi = (struct hfi_debug_config *)&pkt->data[1];
48 	hfi->config = config;
49 	hfi->mode = mode;
50 }
51 
52 void pkt_sys_coverage_config(struct hfi_sys_set_property_pkt *pkt, u32 mode)
53 {
54 	pkt->hdr.size = struct_size(pkt, data, 2);
55 	pkt->hdr.pkt_type = HFI_CMD_SYS_SET_PROPERTY;
56 	pkt->num_properties = 1;
57 	pkt->data[0] = HFI_PROPERTY_SYS_CONFIG_COVERAGE;
58 	pkt->data[1] = mode;
59 }
60 
61 int pkt_sys_set_resource(struct hfi_sys_set_resource_pkt *pkt, u32 id, u32 size,
62 			 u32 addr, void *cookie)
63 {
64 	pkt->hdr.size = sizeof(*pkt);
65 	pkt->hdr.pkt_type = HFI_CMD_SYS_SET_RESOURCE;
66 	pkt->resource_handle = hash32_ptr(cookie);
67 
68 	switch (id) {
69 	case VIDC_RESOURCE_OCMEM:
70 	case VIDC_RESOURCE_VMEM: {
71 		struct hfi_resource_ocmem *res =
72 			(struct hfi_resource_ocmem *)&pkt->resource_data[0];
73 
74 		res->size = size;
75 		res->mem = addr;
76 		pkt->resource_type = HFI_RESOURCE_OCMEM;
77 		pkt->hdr.size += sizeof(*res) - sizeof(u32);
78 		break;
79 	}
80 	case VIDC_RESOURCE_NONE:
81 	default:
82 		return -ENOTSUPP;
83 	}
84 
85 	return 0;
86 }
87 
88 int pkt_sys_unset_resource(struct hfi_sys_release_resource_pkt *pkt, u32 id,
89 			   u32 size, void *cookie)
90 {
91 	pkt->hdr.size = sizeof(*pkt);
92 	pkt->hdr.pkt_type = HFI_CMD_SYS_RELEASE_RESOURCE;
93 	pkt->resource_handle = hash32_ptr(cookie);
94 
95 	switch (id) {
96 	case VIDC_RESOURCE_OCMEM:
97 	case VIDC_RESOURCE_VMEM:
98 		pkt->resource_type = HFI_RESOURCE_OCMEM;
99 		break;
100 	case VIDC_RESOURCE_NONE:
101 		break;
102 	default:
103 		return -ENOTSUPP;
104 	}
105 
106 	return 0;
107 }
108 
109 void pkt_sys_ping(struct hfi_sys_ping_pkt *pkt, u32 cookie)
110 {
111 	pkt->hdr.size = sizeof(*pkt);
112 	pkt->hdr.pkt_type = HFI_CMD_SYS_PING;
113 	pkt->client_data = cookie;
114 }
115 
116 void pkt_sys_power_control(struct hfi_sys_set_property_pkt *pkt, u32 enable)
117 {
118 	struct hfi_enable *hfi = (struct hfi_enable *)&pkt->data[1];
119 
120 	pkt->hdr.size = struct_size(pkt, data, 1) + sizeof(*hfi);
121 	pkt->hdr.pkt_type = HFI_CMD_SYS_SET_PROPERTY;
122 	pkt->num_properties = 1;
123 	pkt->data[0] = HFI_PROPERTY_SYS_CODEC_POWER_PLANE_CTRL;
124 	hfi->enable = enable;
125 }
126 
127 int pkt_sys_ssr_cmd(struct hfi_sys_test_ssr_pkt *pkt, u32 trigger_type)
128 {
129 	switch (trigger_type) {
130 	case HFI_TEST_SSR_SW_ERR_FATAL:
131 	case HFI_TEST_SSR_SW_DIV_BY_ZERO:
132 	case HFI_TEST_SSR_HW_WDOG_IRQ:
133 		break;
134 	default:
135 		return -EINVAL;
136 	}
137 
138 	pkt->hdr.size = sizeof(*pkt);
139 	pkt->hdr.pkt_type = HFI_CMD_SYS_TEST_SSR;
140 	pkt->trigger_type = trigger_type;
141 
142 	return 0;
143 }
144 
145 void pkt_sys_image_version(struct hfi_sys_get_property_pkt *pkt)
146 {
147 	pkt->hdr.size = sizeof(*pkt);
148 	pkt->hdr.pkt_type = HFI_CMD_SYS_GET_PROPERTY;
149 	pkt->num_properties = 1;
150 	pkt->data[0] = HFI_PROPERTY_SYS_IMAGE_VERSION;
151 }
152 
153 int pkt_session_init(struct hfi_session_init_pkt *pkt, void *cookie,
154 		     u32 session_type, u32 codec)
155 {
156 	if (!pkt || !cookie || !codec)
157 		return -EINVAL;
158 
159 	pkt->shdr.hdr.size = sizeof(*pkt);
160 	pkt->shdr.hdr.pkt_type = HFI_CMD_SYS_SESSION_INIT;
161 	pkt->shdr.session_id = hash32_ptr(cookie);
162 	pkt->session_domain = session_type;
163 	pkt->session_codec = codec;
164 
165 	return 0;
166 }
167 
168 void pkt_session_cmd(struct hfi_session_pkt *pkt, u32 pkt_type, void *cookie)
169 {
170 	pkt->shdr.hdr.size = sizeof(*pkt);
171 	pkt->shdr.hdr.pkt_type = pkt_type;
172 	pkt->shdr.session_id = hash32_ptr(cookie);
173 }
174 
175 int pkt_session_set_buffers(struct hfi_session_set_buffers_pkt *pkt,
176 			    void *cookie, struct hfi_buffer_desc *bd)
177 {
178 	unsigned int i;
179 
180 	if (!cookie || !pkt || !bd)
181 		return -EINVAL;
182 
183 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_SET_BUFFERS;
184 	pkt->shdr.session_id = hash32_ptr(cookie);
185 	pkt->buffer_size = bd->buffer_size;
186 	pkt->min_buffer_size = bd->buffer_size;
187 	pkt->num_buffers = bd->num_buffers;
188 
189 	if (bd->buffer_type == HFI_BUFFER_OUTPUT ||
190 	    bd->buffer_type == HFI_BUFFER_OUTPUT2) {
191 		struct hfi_buffer_info *bi;
192 
193 		pkt->extradata_size = bd->extradata_size;
194 		pkt->shdr.hdr.size = sizeof(*pkt) - sizeof(u32) +
195 			(bd->num_buffers * sizeof(*bi));
196 		bi = (struct hfi_buffer_info *)pkt->buffer_info;
197 		for (i = 0; i < pkt->num_buffers; i++) {
198 			bi->buffer_addr = bd->device_addr;
199 			bi->extradata_addr = bd->extradata_addr;
200 		}
201 	} else {
202 		pkt->extradata_size = 0;
203 		pkt->shdr.hdr.size = sizeof(*pkt) +
204 			((bd->num_buffers - 1) * sizeof(u32));
205 		for (i = 0; i < pkt->num_buffers; i++)
206 			pkt->buffer_info[i] = bd->device_addr;
207 	}
208 
209 	pkt->buffer_type = bd->buffer_type;
210 
211 	return 0;
212 }
213 
214 int pkt_session_unset_buffers(struct hfi_session_release_buffer_pkt *pkt,
215 			      void *cookie, struct hfi_buffer_desc *bd)
216 {
217 	unsigned int i;
218 
219 	if (!cookie || !pkt || !bd)
220 		return -EINVAL;
221 
222 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_RELEASE_BUFFERS;
223 	pkt->shdr.session_id = hash32_ptr(cookie);
224 	pkt->buffer_size = bd->buffer_size;
225 	pkt->num_buffers = bd->num_buffers;
226 
227 	if (bd->buffer_type == HFI_BUFFER_OUTPUT ||
228 	    bd->buffer_type == HFI_BUFFER_OUTPUT2) {
229 		struct hfi_buffer_info *bi;
230 
231 		bi = (struct hfi_buffer_info *)pkt->buffer_info;
232 		for (i = 0; i < pkt->num_buffers; i++) {
233 			bi->buffer_addr = bd->device_addr;
234 			bi->extradata_addr = bd->extradata_addr;
235 		}
236 		pkt->shdr.hdr.size =
237 				sizeof(struct hfi_session_set_buffers_pkt) -
238 				sizeof(u32) + (bd->num_buffers * sizeof(*bi));
239 	} else {
240 		for (i = 0; i < pkt->num_buffers; i++)
241 			pkt->buffer_info[i] = bd->device_addr;
242 
243 		pkt->extradata_size = 0;
244 		pkt->shdr.hdr.size =
245 				sizeof(struct hfi_session_set_buffers_pkt) +
246 				((bd->num_buffers - 1) * sizeof(u32));
247 	}
248 
249 	pkt->response_req = bd->response_required;
250 	pkt->buffer_type = bd->buffer_type;
251 
252 	return 0;
253 }
254 
255 int pkt_session_etb_decoder(struct hfi_session_empty_buffer_compressed_pkt *pkt,
256 			    void *cookie, struct hfi_frame_data *in_frame)
257 {
258 	if (!cookie)
259 		return -EINVAL;
260 
261 	pkt->shdr.hdr.size = sizeof(*pkt);
262 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_EMPTY_BUFFER;
263 	pkt->shdr.session_id = hash32_ptr(cookie);
264 	pkt->time_stamp_hi = upper_32_bits(in_frame->timestamp);
265 	pkt->time_stamp_lo = lower_32_bits(in_frame->timestamp);
266 	pkt->flags = in_frame->flags;
267 	pkt->mark_target = in_frame->mark_target;
268 	pkt->mark_data = in_frame->mark_data;
269 	pkt->offset = in_frame->offset;
270 	pkt->alloc_len = in_frame->alloc_len;
271 	pkt->filled_len = in_frame->filled_len;
272 	pkt->input_tag = in_frame->clnt_data;
273 	pkt->packet_buffer = in_frame->device_addr;
274 
275 	return 0;
276 }
277 
278 int pkt_session_etb_encoder(
279 		struct hfi_session_empty_buffer_uncompressed_plane0_pkt *pkt,
280 		void *cookie, struct hfi_frame_data *in_frame)
281 {
282 	if (!cookie || !in_frame->device_addr)
283 		return -EINVAL;
284 
285 	pkt->shdr.hdr.size = sizeof(*pkt);
286 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_EMPTY_BUFFER;
287 	pkt->shdr.session_id = hash32_ptr(cookie);
288 	pkt->view_id = 0;
289 	pkt->time_stamp_hi = upper_32_bits(in_frame->timestamp);
290 	pkt->time_stamp_lo = lower_32_bits(in_frame->timestamp);
291 	pkt->flags = in_frame->flags;
292 	pkt->mark_target = in_frame->mark_target;
293 	pkt->mark_data = in_frame->mark_data;
294 	pkt->offset = in_frame->offset;
295 	pkt->alloc_len = in_frame->alloc_len;
296 	pkt->filled_len = in_frame->filled_len;
297 	pkt->input_tag = in_frame->clnt_data;
298 	pkt->packet_buffer = in_frame->device_addr;
299 	pkt->extradata_buffer = in_frame->extradata_addr;
300 
301 	return 0;
302 }
303 
304 int pkt_session_ftb(struct hfi_session_fill_buffer_pkt *pkt, void *cookie,
305 		    struct hfi_frame_data *out_frame)
306 {
307 	if (!cookie || !out_frame || !out_frame->device_addr)
308 		return -EINVAL;
309 
310 	pkt->shdr.hdr.size = sizeof(*pkt);
311 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_FILL_BUFFER;
312 	pkt->shdr.session_id = hash32_ptr(cookie);
313 
314 	if (out_frame->buffer_type == HFI_BUFFER_OUTPUT)
315 		pkt->stream_id = 0;
316 	else if (out_frame->buffer_type == HFI_BUFFER_OUTPUT2)
317 		pkt->stream_id = 1;
318 
319 	pkt->output_tag = out_frame->clnt_data;
320 	pkt->packet_buffer = out_frame->device_addr;
321 	pkt->extradata_buffer = out_frame->extradata_addr;
322 	pkt->alloc_len = out_frame->alloc_len;
323 	pkt->filled_len = out_frame->filled_len;
324 	pkt->offset = out_frame->offset;
325 	pkt->data[0] = out_frame->extradata_size;
326 
327 	return 0;
328 }
329 
330 int pkt_session_parse_seq_header(
331 		struct hfi_session_parse_sequence_header_pkt *pkt,
332 		void *cookie, u32 seq_hdr, u32 seq_hdr_len)
333 {
334 	if (!cookie || !seq_hdr || !seq_hdr_len)
335 		return -EINVAL;
336 
337 	pkt->shdr.hdr.size = sizeof(*pkt);
338 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_PARSE_SEQUENCE_HEADER;
339 	pkt->shdr.session_id = hash32_ptr(cookie);
340 	pkt->header_len = seq_hdr_len;
341 	pkt->packet_buffer = seq_hdr;
342 
343 	return 0;
344 }
345 
346 int pkt_session_get_seq_hdr(struct hfi_session_get_sequence_header_pkt *pkt,
347 			    void *cookie, u32 seq_hdr, u32 seq_hdr_len)
348 {
349 	if (!cookie || !seq_hdr || !seq_hdr_len)
350 		return -EINVAL;
351 
352 	pkt->shdr.hdr.size = sizeof(*pkt);
353 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_GET_SEQUENCE_HEADER;
354 	pkt->shdr.session_id = hash32_ptr(cookie);
355 	pkt->buffer_len = seq_hdr_len;
356 	pkt->packet_buffer = seq_hdr;
357 
358 	return 0;
359 }
360 
361 int pkt_session_flush(struct hfi_session_flush_pkt *pkt, void *cookie, u32 type)
362 {
363 	switch (type) {
364 	case HFI_FLUSH_INPUT:
365 	case HFI_FLUSH_OUTPUT:
366 	case HFI_FLUSH_OUTPUT2:
367 	case HFI_FLUSH_ALL:
368 		break;
369 	default:
370 		return -EINVAL;
371 	}
372 
373 	pkt->shdr.hdr.size = sizeof(*pkt);
374 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_FLUSH;
375 	pkt->shdr.session_id = hash32_ptr(cookie);
376 	pkt->flush_type = type;
377 
378 	return 0;
379 }
380 
381 static int pkt_session_get_property_1x(struct hfi_session_get_property_pkt *pkt,
382 				       void *cookie, u32 ptype)
383 {
384 	switch (ptype) {
385 	case HFI_PROPERTY_PARAM_PROFILE_LEVEL_CURRENT:
386 	case HFI_PROPERTY_CONFIG_BUFFER_REQUIREMENTS:
387 		break;
388 	default:
389 		return -EINVAL;
390 	}
391 
392 	pkt->shdr.hdr.size = sizeof(*pkt);
393 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_GET_PROPERTY;
394 	pkt->shdr.session_id = hash32_ptr(cookie);
395 	pkt->num_properties = 1;
396 	pkt->data[0] = ptype;
397 
398 	return 0;
399 }
400 
401 static int pkt_session_set_property_1x(struct hfi_session_set_property_pkt *pkt,
402 				       void *cookie, u32 ptype, void *pdata)
403 {
404 	void *prop_data;
405 	int ret = 0;
406 
407 	if (!pkt || !cookie || !pdata)
408 		return -EINVAL;
409 
410 	prop_data = &pkt->data[1];
411 
412 	pkt->shdr.hdr.size = sizeof(*pkt);
413 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_SET_PROPERTY;
414 	pkt->shdr.session_id = hash32_ptr(cookie);
415 	pkt->num_properties = 1;
416 	pkt->data[0] = ptype;
417 
418 	switch (ptype) {
419 	case HFI_PROPERTY_CONFIG_FRAME_RATE: {
420 		struct hfi_framerate *in = pdata, *frate = prop_data;
421 
422 		frate->buffer_type = in->buffer_type;
423 		frate->framerate = in->framerate;
424 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*frate);
425 		break;
426 	}
427 	case HFI_PROPERTY_PARAM_UNCOMPRESSED_FORMAT_SELECT: {
428 		struct hfi_uncompressed_format_select *in = pdata;
429 		struct hfi_uncompressed_format_select *hfi = prop_data;
430 
431 		hfi->buffer_type = in->buffer_type;
432 		hfi->format = in->format;
433 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*hfi);
434 		break;
435 	}
436 	case HFI_PROPERTY_PARAM_FRAME_SIZE: {
437 		struct hfi_framesize *in = pdata, *fsize = prop_data;
438 
439 		fsize->buffer_type = in->buffer_type;
440 		fsize->height = in->height;
441 		fsize->width = in->width;
442 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*fsize);
443 		break;
444 	}
445 	case HFI_PROPERTY_CONFIG_REALTIME: {
446 		struct hfi_enable *in = pdata, *en = prop_data;
447 
448 		en->enable = in->enable;
449 		pkt->shdr.hdr.size += sizeof(u32) * 2;
450 		break;
451 	}
452 	case HFI_PROPERTY_PARAM_BUFFER_COUNT_ACTUAL: {
453 		struct hfi_buffer_count_actual *in = pdata, *count = prop_data;
454 
455 		count->count_actual = in->count_actual;
456 		count->type = in->type;
457 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*count);
458 		break;
459 	}
460 	case HFI_PROPERTY_PARAM_BUFFER_SIZE_ACTUAL: {
461 		struct hfi_buffer_size_actual *in = pdata, *sz = prop_data;
462 
463 		sz->size = in->size;
464 		sz->type = in->type;
465 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*sz);
466 		break;
467 	}
468 	case HFI_PROPERTY_PARAM_BUFFER_DISPLAY_HOLD_COUNT_ACTUAL: {
469 		struct hfi_buffer_display_hold_count_actual *in = pdata;
470 		struct hfi_buffer_display_hold_count_actual *count = prop_data;
471 
472 		count->hold_count = in->hold_count;
473 		count->type = in->type;
474 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*count);
475 		break;
476 	}
477 	case HFI_PROPERTY_PARAM_NAL_STREAM_FORMAT_SELECT: {
478 		struct hfi_nal_stream_format_select *in = pdata;
479 		struct hfi_nal_stream_format_select *fmt = prop_data;
480 
481 		fmt->format = in->format;
482 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*fmt);
483 		break;
484 	}
485 	case HFI_PROPERTY_PARAM_VDEC_OUTPUT_ORDER: {
486 		u32 *in = pdata;
487 
488 		switch (*in) {
489 		case HFI_OUTPUT_ORDER_DECODE:
490 		case HFI_OUTPUT_ORDER_DISPLAY:
491 			break;
492 		default:
493 			ret = -EINVAL;
494 			break;
495 		}
496 
497 		pkt->data[1] = *in;
498 		pkt->shdr.hdr.size += sizeof(u32) * 2;
499 		break;
500 	}
501 	case HFI_PROPERTY_PARAM_VDEC_PICTURE_TYPE_DECODE: {
502 		struct hfi_enable_picture *in = pdata, *en = prop_data;
503 
504 		en->picture_type = in->picture_type;
505 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
506 		break;
507 	}
508 	case HFI_PROPERTY_PARAM_VDEC_OUTPUT2_KEEP_ASPECT_RATIO: {
509 		struct hfi_enable *in = pdata, *en = prop_data;
510 
511 		en->enable = in->enable;
512 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
513 		break;
514 	}
515 	case HFI_PROPERTY_CONFIG_VDEC_POST_LOOP_DEBLOCKER: {
516 		struct hfi_enable *in = pdata;
517 		struct hfi_enable *en = prop_data;
518 
519 		en->enable = in->enable;
520 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
521 		break;
522 	}
523 	case HFI_PROPERTY_PARAM_VDEC_MULTI_STREAM: {
524 		struct hfi_multi_stream *in = pdata, *multi = prop_data;
525 
526 		multi->buffer_type = in->buffer_type;
527 		multi->enable = in->enable;
528 		multi->width = in->width;
529 		multi->height = in->height;
530 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*multi);
531 		break;
532 	}
533 	case HFI_PROPERTY_PARAM_VDEC_DISPLAY_PICTURE_BUFFER_COUNT: {
534 		struct hfi_display_picture_buffer_count *in = pdata;
535 		struct hfi_display_picture_buffer_count *count = prop_data;
536 
537 		count->count = in->count;
538 		count->enable = in->enable;
539 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*count);
540 		break;
541 	}
542 	case HFI_PROPERTY_PARAM_DIVX_FORMAT: {
543 		u32 *in = pdata;
544 
545 		switch (*in) {
546 		case HFI_DIVX_FORMAT_4:
547 		case HFI_DIVX_FORMAT_5:
548 		case HFI_DIVX_FORMAT_6:
549 			break;
550 		default:
551 			ret = -EINVAL;
552 			break;
553 		}
554 
555 		pkt->data[1] = *in;
556 		pkt->shdr.hdr.size += sizeof(u32) * 2;
557 		break;
558 	}
559 	case HFI_PROPERTY_CONFIG_VDEC_MB_ERROR_MAP_REPORTING: {
560 		struct hfi_enable *in = pdata, *en = prop_data;
561 
562 		en->enable = in->enable;
563 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
564 		break;
565 	}
566 	case HFI_PROPERTY_PARAM_VDEC_CONTINUE_DATA_TRANSFER: {
567 		struct hfi_enable *in = pdata, *en = prop_data;
568 
569 		en->enable = in->enable;
570 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
571 		break;
572 	}
573 	case HFI_PROPERTY_PARAM_VDEC_THUMBNAIL_MODE: {
574 		struct hfi_enable *in = pdata, *en = prop_data;
575 
576 		en->enable = in->enable;
577 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
578 		break;
579 	}
580 	case HFI_PROPERTY_CONFIG_VENC_SYNC_FRAME_SEQUENCE_HEADER: {
581 		struct hfi_enable *in = pdata, *en = prop_data;
582 
583 		en->enable = in->enable;
584 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
585 		break;
586 	}
587 	case HFI_PROPERTY_CONFIG_VENC_REQUEST_SYNC_FRAME:
588 		pkt->shdr.hdr.size += sizeof(u32);
589 		break;
590 	case HFI_PROPERTY_PARAM_VENC_MPEG4_SHORT_HEADER:
591 		break;
592 	case HFI_PROPERTY_PARAM_VENC_MPEG4_AC_PREDICTION:
593 		break;
594 	case HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE: {
595 		struct hfi_bitrate *in = pdata, *brate = prop_data;
596 
597 		brate->bitrate = in->bitrate;
598 		brate->layer_id = in->layer_id;
599 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*brate);
600 		break;
601 	}
602 	case HFI_PROPERTY_CONFIG_VENC_MAX_BITRATE: {
603 		struct hfi_bitrate *in = pdata, *hfi = prop_data;
604 
605 		hfi->bitrate = in->bitrate;
606 		hfi->layer_id = in->layer_id;
607 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*hfi);
608 		break;
609 	}
610 	case HFI_PROPERTY_PARAM_PROFILE_LEVEL_CURRENT: {
611 		struct hfi_profile_level *in = pdata, *pl = prop_data;
612 
613 		pl->level = in->level;
614 		pl->profile = in->profile;
615 		if (pl->profile <= 0)
616 			/* Profile not supported, falling back to high */
617 			pl->profile = HFI_H264_PROFILE_HIGH;
618 
619 		if (!pl->level)
620 			/* Level not supported, falling back to 1 */
621 			pl->level = 1;
622 
623 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*pl);
624 		break;
625 	}
626 	case HFI_PROPERTY_PARAM_VENC_H264_ENTROPY_CONTROL: {
627 		struct hfi_h264_entropy_control *in = pdata, *hfi = prop_data;
628 
629 		hfi->entropy_mode = in->entropy_mode;
630 		if (hfi->entropy_mode == HFI_H264_ENTROPY_CABAC)
631 			hfi->cabac_model = in->cabac_model;
632 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*hfi);
633 		break;
634 	}
635 	case HFI_PROPERTY_PARAM_VENC_RATE_CONTROL: {
636 		u32 *in = pdata;
637 
638 		switch (*in) {
639 		case HFI_RATE_CONTROL_OFF:
640 		case HFI_RATE_CONTROL_CBR_CFR:
641 		case HFI_RATE_CONTROL_CBR_VFR:
642 		case HFI_RATE_CONTROL_VBR_CFR:
643 		case HFI_RATE_CONTROL_VBR_VFR:
644 		case HFI_RATE_CONTROL_CQ:
645 			break;
646 		default:
647 			ret = -EINVAL;
648 			break;
649 		}
650 
651 		pkt->data[1] = *in;
652 		pkt->shdr.hdr.size += sizeof(u32) * 2;
653 		break;
654 	}
655 	case HFI_PROPERTY_PARAM_VENC_MPEG4_TIME_RESOLUTION: {
656 		struct hfi_mpeg4_time_resolution *in = pdata, *res = prop_data;
657 
658 		res->time_increment_resolution = in->time_increment_resolution;
659 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*res);
660 		break;
661 	}
662 	case HFI_PROPERTY_PARAM_VENC_MPEG4_HEADER_EXTENSION: {
663 		struct hfi_mpeg4_header_extension *in = pdata, *ext = prop_data;
664 
665 		ext->header_extension = in->header_extension;
666 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*ext);
667 		break;
668 	}
669 	case HFI_PROPERTY_PARAM_VENC_H264_DEBLOCK_CONTROL: {
670 		struct hfi_h264_db_control *in = pdata, *db = prop_data;
671 
672 		switch (in->mode) {
673 		case HFI_H264_DB_MODE_DISABLE:
674 		case HFI_H264_DB_MODE_SKIP_SLICE_BOUNDARY:
675 		case HFI_H264_DB_MODE_ALL_BOUNDARY:
676 			break;
677 		default:
678 			ret = -EINVAL;
679 			break;
680 		}
681 
682 		db->mode = in->mode;
683 		db->slice_alpha_offset = in->slice_alpha_offset;
684 		db->slice_beta_offset = in->slice_beta_offset;
685 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*db);
686 		break;
687 	}
688 	case HFI_PROPERTY_PARAM_VENC_SESSION_QP: {
689 		struct hfi_quantization *in = pdata, *quant = prop_data;
690 
691 		quant->qp_i = in->qp_i;
692 		quant->qp_p = in->qp_p;
693 		quant->qp_b = in->qp_b;
694 		quant->layer_id = in->layer_id;
695 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*quant);
696 		break;
697 	}
698 	case HFI_PROPERTY_PARAM_VENC_SESSION_QP_RANGE: {
699 		struct hfi_quantization_range *in = pdata, *range = prop_data;
700 		u32 min_qp, max_qp;
701 
702 		min_qp = in->min_qp;
703 		max_qp = in->max_qp;
704 
705 		/* We'll be packing in the qp, so make sure we
706 		 * won't be losing data when masking
707 		 */
708 		if (min_qp > 0xff || max_qp > 0xff) {
709 			ret = -ERANGE;
710 			break;
711 		}
712 
713 		/* When creating the packet, pack the qp value as
714 		 * 0xiippbb, where ii = qp range for I-frames,
715 		 * pp = qp range for P-frames, etc.
716 		 */
717 		range->min_qp = min_qp | min_qp << 8 | min_qp << 16;
718 		range->max_qp = max_qp | max_qp << 8 | max_qp << 16;
719 		range->layer_id = in->layer_id;
720 
721 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*range);
722 		break;
723 	}
724 	case HFI_PROPERTY_PARAM_VENC_VC1_PERF_CFG: {
725 		struct hfi_vc1e_perf_cfg_type *in = pdata, *perf = prop_data;
726 
727 		memcpy(perf->search_range_x_subsampled,
728 		       in->search_range_x_subsampled,
729 		       sizeof(perf->search_range_x_subsampled));
730 		memcpy(perf->search_range_y_subsampled,
731 		       in->search_range_y_subsampled,
732 		       sizeof(perf->search_range_y_subsampled));
733 
734 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*perf);
735 		break;
736 	}
737 	case HFI_PROPERTY_PARAM_VENC_MAX_NUM_B_FRAMES: {
738 		struct hfi_max_num_b_frames *bframes = prop_data;
739 		u32 *in = pdata;
740 
741 		bframes->max_num_b_frames = *in;
742 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*bframes);
743 		break;
744 	}
745 	case HFI_PROPERTY_CONFIG_VENC_INTRA_PERIOD: {
746 		struct hfi_intra_period *in = pdata, *intra = prop_data;
747 
748 		intra->pframes = in->pframes;
749 		intra->bframes = in->bframes;
750 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*intra);
751 		break;
752 	}
753 	case HFI_PROPERTY_CONFIG_VENC_IDR_PERIOD: {
754 		struct hfi_idr_period *in = pdata, *idr = prop_data;
755 
756 		idr->idr_period = in->idr_period;
757 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*idr);
758 		break;
759 	}
760 	case HFI_PROPERTY_PARAM_VDEC_CONCEAL_COLOR: {
761 		struct hfi_conceal_color *color = prop_data;
762 		u32 *in = pdata;
763 
764 		color->conceal_color = *in & 0xff;
765 		color->conceal_color |= ((*in >> 10) & 0xff) << 8;
766 		color->conceal_color |= ((*in >> 20) & 0xff) << 16;
767 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*color);
768 		break;
769 	}
770 	case HFI_PROPERTY_CONFIG_VPE_OPERATIONS: {
771 		struct hfi_operations_type *in = pdata, *ops = prop_data;
772 
773 		switch (in->rotation) {
774 		case HFI_ROTATE_NONE:
775 		case HFI_ROTATE_90:
776 		case HFI_ROTATE_180:
777 		case HFI_ROTATE_270:
778 			break;
779 		default:
780 			ret = -EINVAL;
781 			break;
782 		}
783 
784 		switch (in->flip) {
785 		case HFI_FLIP_NONE:
786 		case HFI_FLIP_HORIZONTAL:
787 		case HFI_FLIP_VERTICAL:
788 			break;
789 		default:
790 			ret = -EINVAL;
791 			break;
792 		}
793 
794 		ops->rotation = in->rotation;
795 		ops->flip = in->flip;
796 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*ops);
797 		break;
798 	}
799 	case HFI_PROPERTY_PARAM_VENC_INTRA_REFRESH: {
800 		struct hfi_intra_refresh *in = pdata, *intra = prop_data;
801 
802 		switch (in->mode) {
803 		case HFI_INTRA_REFRESH_NONE:
804 		case HFI_INTRA_REFRESH_ADAPTIVE:
805 		case HFI_INTRA_REFRESH_CYCLIC:
806 		case HFI_INTRA_REFRESH_CYCLIC_ADAPTIVE:
807 		case HFI_INTRA_REFRESH_RANDOM:
808 			break;
809 		default:
810 			ret = -EINVAL;
811 			break;
812 		}
813 
814 		intra->mode = in->mode;
815 		intra->air_mbs = in->air_mbs;
816 		intra->air_ref = in->air_ref;
817 		intra->cir_mbs = in->cir_mbs;
818 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*intra);
819 		break;
820 	}
821 	case HFI_PROPERTY_PARAM_VENC_MULTI_SLICE_CONTROL: {
822 		struct hfi_multi_slice_control *in = pdata, *multi = prop_data;
823 
824 		switch (in->multi_slice) {
825 		case HFI_MULTI_SLICE_OFF:
826 		case HFI_MULTI_SLICE_GOB:
827 		case HFI_MULTI_SLICE_BY_MB_COUNT:
828 		case HFI_MULTI_SLICE_BY_BYTE_COUNT:
829 			break;
830 		default:
831 			ret = -EINVAL;
832 			break;
833 		}
834 
835 		multi->multi_slice = in->multi_slice;
836 		multi->slice_size = in->slice_size;
837 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*multi);
838 		break;
839 	}
840 	case HFI_PROPERTY_PARAM_VENC_SLICE_DELIVERY_MODE: {
841 		struct hfi_enable *in = pdata, *en = prop_data;
842 
843 		en->enable = in->enable;
844 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
845 		break;
846 	}
847 	case HFI_PROPERTY_PARAM_VENC_H264_VUI_TIMING_INFO: {
848 		struct hfi_h264_vui_timing_info *in = pdata, *vui = prop_data;
849 
850 		vui->enable = in->enable;
851 		vui->fixed_framerate = in->fixed_framerate;
852 		vui->time_scale = in->time_scale;
853 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*vui);
854 		break;
855 	}
856 	case HFI_PROPERTY_CONFIG_VPE_DEINTERLACE: {
857 		struct hfi_enable *in = pdata, *en = prop_data;
858 
859 		en->enable = in->enable;
860 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
861 		break;
862 	}
863 	case HFI_PROPERTY_PARAM_VENC_H264_GENERATE_AUDNAL: {
864 		struct hfi_enable *in = pdata, *en = prop_data;
865 
866 		en->enable = in->enable;
867 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
868 		break;
869 	}
870 	case HFI_PROPERTY_PARAM_BUFFER_ALLOC_MODE: {
871 		struct hfi_buffer_alloc_mode *in = pdata, *mode = prop_data;
872 
873 		mode->type = in->type;
874 		mode->mode = in->mode;
875 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*mode);
876 		break;
877 	}
878 	case HFI_PROPERTY_PARAM_VDEC_FRAME_ASSEMBLY: {
879 		struct hfi_enable *in = pdata, *en = prop_data;
880 
881 		en->enable = in->enable;
882 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
883 		break;
884 	}
885 	case HFI_PROPERTY_PARAM_VENC_H264_VUI_BITSTREAM_RESTRC: {
886 		struct hfi_enable *in = pdata, *en = prop_data;
887 
888 		en->enable = in->enable;
889 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
890 		break;
891 	}
892 	case HFI_PROPERTY_PARAM_VENC_PRESERVE_TEXT_QUALITY: {
893 		struct hfi_enable *in = pdata, *en = prop_data;
894 
895 		en->enable = in->enable;
896 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
897 		break;
898 	}
899 	case HFI_PROPERTY_PARAM_VDEC_SCS_THRESHOLD: {
900 		struct hfi_scs_threshold *thres = prop_data;
901 		u32 *in = pdata;
902 
903 		thres->threshold_value = *in;
904 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*thres);
905 		break;
906 	}
907 	case HFI_PROPERTY_PARAM_MVC_BUFFER_LAYOUT: {
908 		struct hfi_mvc_buffer_layout_descp_type *in = pdata;
909 		struct hfi_mvc_buffer_layout_descp_type *mvc = prop_data;
910 
911 		switch (in->layout_type) {
912 		case HFI_MVC_BUFFER_LAYOUT_TOP_BOTTOM:
913 		case HFI_MVC_BUFFER_LAYOUT_SEQ:
914 			break;
915 		default:
916 			ret = -EINVAL;
917 			break;
918 		}
919 
920 		mvc->layout_type = in->layout_type;
921 		mvc->bright_view_first = in->bright_view_first;
922 		mvc->ngap = in->ngap;
923 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*mvc);
924 		break;
925 	}
926 	case HFI_PROPERTY_PARAM_VENC_LTRMODE: {
927 		struct hfi_ltr_mode *in = pdata, *ltr = prop_data;
928 
929 		switch (in->ltr_mode) {
930 		case HFI_LTR_MODE_DISABLE:
931 		case HFI_LTR_MODE_MANUAL:
932 		case HFI_LTR_MODE_PERIODIC:
933 			break;
934 		default:
935 			ret = -EINVAL;
936 			break;
937 		}
938 
939 		ltr->ltr_mode = in->ltr_mode;
940 		ltr->ltr_count = in->ltr_count;
941 		ltr->trust_mode = in->trust_mode;
942 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*ltr);
943 		break;
944 	}
945 	case HFI_PROPERTY_CONFIG_VENC_USELTRFRAME: {
946 		struct hfi_ltr_use *in = pdata, *ltr_use = prop_data;
947 
948 		ltr_use->frames = in->frames;
949 		ltr_use->ref_ltr = in->ref_ltr;
950 		ltr_use->use_constrnt = in->use_constrnt;
951 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*ltr_use);
952 		break;
953 	}
954 	case HFI_PROPERTY_CONFIG_VENC_MARKLTRFRAME: {
955 		struct hfi_ltr_mark *in = pdata, *ltr_mark = prop_data;
956 
957 		ltr_mark->mark_frame = in->mark_frame;
958 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*ltr_mark);
959 		break;
960 	}
961 	case HFI_PROPERTY_PARAM_VENC_HIER_P_MAX_NUM_ENH_LAYER: {
962 		u32 *in = pdata;
963 
964 		pkt->data[1] = *in;
965 		pkt->shdr.hdr.size += sizeof(u32) * 2;
966 		break;
967 	}
968 	case HFI_PROPERTY_CONFIG_VENC_HIER_P_ENH_LAYER: {
969 		u32 *in = pdata;
970 
971 		pkt->data[1] = *in;
972 		pkt->shdr.hdr.size += sizeof(u32) * 2;
973 		break;
974 	}
975 	case HFI_PROPERTY_PARAM_VENC_DISABLE_RC_TIMESTAMP: {
976 		struct hfi_enable *in = pdata, *en = prop_data;
977 
978 		en->enable = in->enable;
979 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
980 		break;
981 	}
982 	case HFI_PROPERTY_PARAM_VENC_INITIAL_QP: {
983 		struct hfi_initial_quantization *in = pdata, *quant = prop_data;
984 
985 		quant->init_qp_enable = in->init_qp_enable;
986 		quant->qp_i = in->qp_i;
987 		quant->qp_p = in->qp_p;
988 		quant->qp_b = in->qp_b;
989 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*quant);
990 		break;
991 	}
992 	case HFI_PROPERTY_PARAM_VPE_COLOR_SPACE_CONVERSION: {
993 		struct hfi_vpe_color_space_conversion *in = pdata;
994 		struct hfi_vpe_color_space_conversion *csc = prop_data;
995 
996 		memcpy(csc->csc_matrix, in->csc_matrix,
997 		       sizeof(csc->csc_matrix));
998 		memcpy(csc->csc_bias, in->csc_bias, sizeof(csc->csc_bias));
999 		memcpy(csc->csc_limit, in->csc_limit, sizeof(csc->csc_limit));
1000 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*csc);
1001 		break;
1002 	}
1003 	case HFI_PROPERTY_PARAM_VENC_VPX_ERROR_RESILIENCE_MODE: {
1004 		struct hfi_enable *in = pdata, *en = prop_data;
1005 
1006 		en->enable = in->enable;
1007 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
1008 		break;
1009 	}
1010 	case HFI_PROPERTY_PARAM_VENC_H264_NAL_SVC_EXT: {
1011 		struct hfi_enable *in = pdata, *en = prop_data;
1012 
1013 		en->enable = in->enable;
1014 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
1015 		break;
1016 	}
1017 	case HFI_PROPERTY_CONFIG_VENC_PERF_MODE: {
1018 		u32 *in = pdata;
1019 
1020 		pkt->data[1] = *in;
1021 		pkt->shdr.hdr.size += sizeof(u32) * 2;
1022 		break;
1023 	}
1024 	case HFI_PROPERTY_PARAM_VENC_HIER_B_MAX_NUM_ENH_LAYER: {
1025 		u32 *in = pdata;
1026 
1027 		pkt->data[1] = *in;
1028 		pkt->shdr.hdr.size += sizeof(u32) * 2;
1029 		break;
1030 	}
1031 	case HFI_PROPERTY_PARAM_VDEC_NONCP_OUTPUT2: {
1032 		struct hfi_enable *in = pdata, *en = prop_data;
1033 
1034 		en->enable = in->enable;
1035 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
1036 		break;
1037 	}
1038 	case HFI_PROPERTY_PARAM_VENC_HIER_P_HYBRID_MODE: {
1039 		struct hfi_hybrid_hierp *in = pdata, *hierp = prop_data;
1040 
1041 		hierp->layers = in->layers;
1042 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*hierp);
1043 		break;
1044 	}
1045 	case HFI_PROPERTY_PARAM_UNCOMPRESSED_PLANE_ACTUAL_INFO: {
1046 		struct hfi_uncompressed_plane_actual_info *in = pdata;
1047 		struct hfi_uncompressed_plane_actual_info *info = prop_data;
1048 
1049 		info->buffer_type = in->buffer_type;
1050 		info->num_planes = in->num_planes;
1051 		info->plane_format[0] = in->plane_format[0];
1052 		if (in->num_planes > 1)
1053 			info->plane_format[1] = in->plane_format[1];
1054 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*info);
1055 		break;
1056 	}
1057 	case HFI_PROPERTY_PARAM_VENC_HDR10_PQ_SEI:
1058 		return -ENOTSUPP;
1059 
1060 	/* FOLLOWING PROPERTIES ARE NOT IMPLEMENTED IN CORE YET */
1061 	case HFI_PROPERTY_CONFIG_BUFFER_REQUIREMENTS:
1062 	case HFI_PROPERTY_CONFIG_PRIORITY:
1063 	case HFI_PROPERTY_CONFIG_BATCH_INFO:
1064 	case HFI_PROPERTY_SYS_IDLE_INDICATOR:
1065 	case HFI_PROPERTY_PARAM_UNCOMPRESSED_FORMAT_SUPPORTED:
1066 	case HFI_PROPERTY_PARAM_INTERLACE_FORMAT_SUPPORTED:
1067 	case HFI_PROPERTY_PARAM_CHROMA_SITE:
1068 	case HFI_PROPERTY_PARAM_PROPERTIES_SUPPORTED:
1069 	case HFI_PROPERTY_PARAM_PROFILE_LEVEL_SUPPORTED:
1070 	case HFI_PROPERTY_PARAM_CAPABILITY_SUPPORTED:
1071 	case HFI_PROPERTY_PARAM_NAL_STREAM_FORMAT_SUPPORTED:
1072 	case HFI_PROPERTY_PARAM_MULTI_VIEW_FORMAT:
1073 	case HFI_PROPERTY_PARAM_MAX_SEQUENCE_HEADER_SIZE:
1074 	case HFI_PROPERTY_PARAM_CODEC_SUPPORTED:
1075 	case HFI_PROPERTY_PARAM_VDEC_MULTI_VIEW_SELECT:
1076 	case HFI_PROPERTY_PARAM_VDEC_MB_QUANTIZATION:
1077 	case HFI_PROPERTY_PARAM_VDEC_NUM_CONCEALED_MB:
1078 	case HFI_PROPERTY_PARAM_VDEC_H264_ENTROPY_SWITCHING:
1079 	case HFI_PROPERTY_PARAM_VENC_MULTI_SLICE_INFO:
1080 	default:
1081 		return -EINVAL;
1082 	}
1083 
1084 	return ret;
1085 }
1086 
1087 static int
1088 pkt_session_get_property_3xx(struct hfi_session_get_property_pkt *pkt,
1089 			     void *cookie, u32 ptype)
1090 {
1091 	int ret = 0;
1092 
1093 	if (!pkt || !cookie)
1094 		return -EINVAL;
1095 
1096 	pkt->shdr.hdr.size = sizeof(struct hfi_session_get_property_pkt);
1097 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_GET_PROPERTY;
1098 	pkt->shdr.session_id = hash32_ptr(cookie);
1099 	pkt->num_properties = 1;
1100 
1101 	switch (ptype) {
1102 	case HFI_PROPERTY_CONFIG_VDEC_ENTROPY:
1103 		pkt->data[0] = HFI_PROPERTY_CONFIG_VDEC_ENTROPY;
1104 		break;
1105 	default:
1106 		ret = pkt_session_get_property_1x(pkt, cookie, ptype);
1107 		break;
1108 	}
1109 
1110 	return ret;
1111 }
1112 
1113 static int
1114 pkt_session_set_property_3xx(struct hfi_session_set_property_pkt *pkt,
1115 			     void *cookie, u32 ptype, void *pdata)
1116 {
1117 	void *prop_data;
1118 	int ret = 0;
1119 
1120 	if (!pkt || !cookie || !pdata)
1121 		return -EINVAL;
1122 
1123 	prop_data = &pkt->data[1];
1124 
1125 	pkt->shdr.hdr.size = sizeof(*pkt);
1126 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_SET_PROPERTY;
1127 	pkt->shdr.session_id = hash32_ptr(cookie);
1128 	pkt->num_properties = 1;
1129 	pkt->data[0] = ptype;
1130 
1131 	/*
1132 	 * Any session set property which is different in 3XX packetization
1133 	 * should be added as a new case below. All unchanged session set
1134 	 * properties will be handled in the default case.
1135 	 */
1136 	switch (ptype) {
1137 	case HFI_PROPERTY_PARAM_VDEC_MULTI_STREAM: {
1138 		struct hfi_multi_stream *in = pdata;
1139 		struct hfi_multi_stream_3x *multi = prop_data;
1140 
1141 		multi->buffer_type = in->buffer_type;
1142 		multi->enable = in->enable;
1143 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*multi);
1144 		break;
1145 	}
1146 	case HFI_PROPERTY_PARAM_VENC_INTRA_REFRESH: {
1147 		struct hfi_intra_refresh *in = pdata;
1148 		struct hfi_intra_refresh_3x *intra = prop_data;
1149 
1150 		switch (in->mode) {
1151 		case HFI_INTRA_REFRESH_NONE:
1152 		case HFI_INTRA_REFRESH_ADAPTIVE:
1153 		case HFI_INTRA_REFRESH_CYCLIC:
1154 		case HFI_INTRA_REFRESH_CYCLIC_ADAPTIVE:
1155 		case HFI_INTRA_REFRESH_RANDOM:
1156 			break;
1157 		default:
1158 			ret = -EINVAL;
1159 			break;
1160 		}
1161 
1162 		intra->mode = in->mode;
1163 		intra->mbs = in->cir_mbs;
1164 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*intra);
1165 		break;
1166 	}
1167 	case HFI_PROPERTY_PARAM_VDEC_CONTINUE_DATA_TRANSFER:
1168 		/* for 3xx fw version session_continue is used */
1169 		break;
1170 	default:
1171 		ret = pkt_session_set_property_1x(pkt, cookie, ptype, pdata);
1172 		break;
1173 	}
1174 
1175 	return ret;
1176 }
1177 
1178 static int
1179 pkt_session_set_property_4xx(struct hfi_session_set_property_pkt *pkt,
1180 			     void *cookie, u32 ptype, void *pdata)
1181 {
1182 	void *prop_data;
1183 
1184 	if (!pkt || !cookie || !pdata)
1185 		return -EINVAL;
1186 
1187 	prop_data = &pkt->data[1];
1188 
1189 	pkt->shdr.hdr.size = sizeof(*pkt);
1190 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_SET_PROPERTY;
1191 	pkt->shdr.session_id = hash32_ptr(cookie);
1192 	pkt->num_properties = 1;
1193 	pkt->data[0] = ptype;
1194 
1195 	/*
1196 	 * Any session set property which is different in 3XX packetization
1197 	 * should be added as a new case below. All unchanged session set
1198 	 * properties will be handled in the default case.
1199 	 */
1200 	switch (ptype) {
1201 	case HFI_PROPERTY_PARAM_BUFFER_COUNT_ACTUAL: {
1202 		struct hfi_buffer_count_actual *in = pdata;
1203 		struct hfi_buffer_count_actual_4xx *count = prop_data;
1204 
1205 		count->count_actual = in->count_actual;
1206 		count->type = in->type;
1207 		count->count_min_host = in->count_actual;
1208 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*count);
1209 		break;
1210 	}
1211 	case HFI_PROPERTY_PARAM_WORK_MODE: {
1212 		struct hfi_video_work_mode *in = pdata, *wm = prop_data;
1213 
1214 		wm->video_work_mode = in->video_work_mode;
1215 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*wm);
1216 		break;
1217 	}
1218 	case HFI_PROPERTY_CONFIG_VIDEOCORES_USAGE: {
1219 		struct hfi_videocores_usage_type *in = pdata, *cu = prop_data;
1220 
1221 		cu->video_core_enable_mask = in->video_core_enable_mask;
1222 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*cu);
1223 		break;
1224 	}
1225 	case HFI_PROPERTY_PARAM_VENC_HDR10_PQ_SEI: {
1226 		struct hfi_hdr10_pq_sei *in = pdata, *hdr10 = prop_data;
1227 
1228 		memcpy(hdr10, in, sizeof(*hdr10));
1229 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*hdr10);
1230 		break;
1231 	}
1232 	case HFI_PROPERTY_PARAM_VDEC_CONCEAL_COLOR: {
1233 		struct hfi_conceal_color_v4 *color = prop_data;
1234 		u32 *in = pdata;
1235 
1236 		color->conceal_color_8bit = *in & 0xff;
1237 		color->conceal_color_8bit |= ((*in >> 10) & 0xff) << 8;
1238 		color->conceal_color_8bit |= ((*in >> 20) & 0xff) << 16;
1239 		color->conceal_color_10bit = *in;
1240 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*color);
1241 		break;
1242 	}
1243 
1244 	case HFI_PROPERTY_PARAM_VENC_H264_TRANSFORM_8X8: {
1245 		struct hfi_h264_8x8_transform *in = pdata, *tm = prop_data;
1246 
1247 		tm->enable_type = in->enable_type;
1248 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*tm);
1249 		break;
1250 	}
1251 
1252 	case HFI_PROPERTY_CONFIG_VENC_MAX_BITRATE:
1253 	case HFI_PROPERTY_CONFIG_VDEC_POST_LOOP_DEBLOCKER:
1254 	case HFI_PROPERTY_PARAM_BUFFER_ALLOC_MODE:
1255 	case HFI_PROPERTY_PARAM_VENC_SESSION_QP:
1256 	case HFI_PROPERTY_PARAM_VENC_SESSION_QP_RANGE:
1257 		/* not implemented on Venus 4xx */
1258 		return -ENOTSUPP;
1259 	default:
1260 		return pkt_session_set_property_3xx(pkt, cookie, ptype, pdata);
1261 	}
1262 
1263 	return 0;
1264 }
1265 
1266 static int
1267 pkt_session_set_property_6xx(struct hfi_session_set_property_pkt *pkt,
1268 			     void *cookie, u32 ptype, void *pdata)
1269 {
1270 	void *prop_data;
1271 
1272 	if (!pkt || !cookie || !pdata)
1273 		return -EINVAL;
1274 
1275 	prop_data = &pkt->data[1];
1276 
1277 	pkt->shdr.hdr.size = sizeof(*pkt);
1278 	pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_SET_PROPERTY;
1279 	pkt->shdr.session_id = hash32_ptr(cookie);
1280 	pkt->num_properties = 1;
1281 	pkt->data[0] = ptype;
1282 
1283 	switch (ptype) {
1284 	case HFI_PROPERTY_PARAM_UNCOMPRESSED_PLANE_ACTUAL_CONSTRAINTS_INFO: {
1285 		struct hfi_uncompressed_plane_actual_constraints_info *in = pdata;
1286 		struct hfi_uncompressed_plane_actual_constraints_info *info = prop_data;
1287 
1288 		info->buffer_type = in->buffer_type;
1289 		info->num_planes = in->num_planes;
1290 		info->plane_format[0] = in->plane_format[0];
1291 		if (in->num_planes > 1)
1292 			info->plane_format[1] = in->plane_format[1];
1293 
1294 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*info);
1295 		break;
1296 	}
1297 	case HFI_PROPERTY_CONFIG_HEIC_FRAME_QUALITY: {
1298 		struct hfi_heic_frame_quality *in = pdata, *cq = prop_data;
1299 
1300 		cq->frame_quality = in->frame_quality;
1301 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*cq);
1302 		break;
1303 	}
1304 	case HFI_PROPERTY_PARAM_WORK_ROUTE: {
1305 		struct hfi_video_work_route *in = pdata, *wr = prop_data;
1306 
1307 		wr->video_work_route = in->video_work_route;
1308 		pkt->shdr.hdr.size += sizeof(u32) + sizeof(*wr);
1309 		break;
1310 	}
1311 	default:
1312 		return pkt_session_set_property_4xx(pkt, cookie, ptype, pdata);
1313 	}
1314 
1315 	return 0;
1316 }
1317 
1318 int pkt_session_get_property(struct hfi_session_get_property_pkt *pkt,
1319 			     void *cookie, u32 ptype)
1320 {
1321 	if (hfi_ver == HFI_VERSION_1XX)
1322 		return pkt_session_get_property_1x(pkt, cookie, ptype);
1323 
1324 	return pkt_session_get_property_3xx(pkt, cookie, ptype);
1325 }
1326 
1327 int pkt_session_set_property(struct hfi_session_set_property_pkt *pkt,
1328 			     void *cookie, u32 ptype, void *pdata)
1329 {
1330 	if (hfi_ver == HFI_VERSION_1XX)
1331 		return pkt_session_set_property_1x(pkt, cookie, ptype, pdata);
1332 
1333 	if (hfi_ver == HFI_VERSION_3XX)
1334 		return pkt_session_set_property_3xx(pkt, cookie, ptype, pdata);
1335 
1336 	if (hfi_ver == HFI_VERSION_4XX)
1337 		return pkt_session_set_property_4xx(pkt, cookie, ptype, pdata);
1338 
1339 	return pkt_session_set_property_6xx(pkt, cookie, ptype, pdata);
1340 }
1341 
1342 void pkt_set_version(enum hfi_version version)
1343 {
1344 	hfi_ver = version;
1345 }
1346