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