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