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
pkt_sys_init(struct hfi_sys_init_pkt * pkt,u32 arch_type)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
pkt_sys_pc_prep(struct hfi_sys_pc_prep_pkt * pkt)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
pkt_sys_idle_indicator(struct hfi_sys_set_property_pkt * pkt,u32 enable)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
pkt_sys_debug_config(struct hfi_sys_set_property_pkt * pkt,u32 mode,u32 config)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
pkt_sys_coverage_config(struct hfi_sys_set_property_pkt * pkt,u32 mode)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
pkt_sys_set_resource(struct hfi_sys_set_resource_pkt * pkt,u32 id,u32 size,u32 addr,void * cookie)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
pkt_sys_unset_resource(struct hfi_sys_release_resource_pkt * pkt,u32 id,u32 size,void * cookie)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
pkt_sys_ping(struct hfi_sys_ping_pkt * pkt,u32 cookie)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
pkt_sys_power_control(struct hfi_sys_set_property_pkt * pkt,u32 enable)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
pkt_sys_ssr_cmd(struct hfi_sys_test_ssr_pkt * pkt,u32 trigger_type)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
pkt_sys_image_version(struct hfi_sys_get_property_pkt * pkt)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
pkt_session_init(struct hfi_session_init_pkt * pkt,void * cookie,u32 session_type,u32 codec)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
pkt_session_cmd(struct hfi_session_pkt * pkt,u32 pkt_type,void * cookie)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
pkt_session_set_buffers(struct hfi_session_set_buffers_pkt * pkt,void * cookie,struct hfi_buffer_desc * bd)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
pkt_session_unset_buffers(struct hfi_session_release_buffer_pkt * pkt,void * cookie,struct hfi_buffer_desc * bd)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
pkt_session_etb_decoder(struct hfi_session_empty_buffer_compressed_pkt * pkt,void * cookie,struct hfi_frame_data * in_frame)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
pkt_session_etb_encoder(struct hfi_session_empty_buffer_uncompressed_plane0_pkt * pkt,void * cookie,struct hfi_frame_data * in_frame)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
pkt_session_ftb(struct hfi_session_fill_buffer_pkt * pkt,void * cookie,struct hfi_frame_data * out_frame)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
pkt_session_parse_seq_header(struct hfi_session_parse_sequence_header_pkt * pkt,void * cookie,u32 seq_hdr,u32 seq_hdr_len)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
pkt_session_get_seq_hdr(struct hfi_session_get_sequence_header_pkt * pkt,void * cookie,u32 seq_hdr,u32 seq_hdr_len)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
pkt_session_flush(struct hfi_session_flush_pkt * pkt,void * cookie,u32 type)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
pkt_session_get_property_1x(struct hfi_session_get_property_pkt * pkt,void * cookie,u32 ptype)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
pkt_session_set_property_1x(struct hfi_session_set_property_pkt * pkt,void * cookie,u32 ptype,void * pdata)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 case HFI_RATE_CONTROL_CQ:
644 break;
645 default:
646 ret = -EINVAL;
647 break;
648 }
649
650 pkt->data[1] = *in;
651 pkt->shdr.hdr.size += sizeof(u32) * 2;
652 break;
653 }
654 case HFI_PROPERTY_PARAM_VENC_MPEG4_TIME_RESOLUTION: {
655 struct hfi_mpeg4_time_resolution *in = pdata, *res = prop_data;
656
657 res->time_increment_resolution = in->time_increment_resolution;
658 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*res);
659 break;
660 }
661 case HFI_PROPERTY_PARAM_VENC_MPEG4_HEADER_EXTENSION: {
662 struct hfi_mpeg4_header_extension *in = pdata, *ext = prop_data;
663
664 ext->header_extension = in->header_extension;
665 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*ext);
666 break;
667 }
668 case HFI_PROPERTY_PARAM_VENC_H264_DEBLOCK_CONTROL: {
669 struct hfi_h264_db_control *in = pdata, *db = prop_data;
670
671 switch (in->mode) {
672 case HFI_H264_DB_MODE_DISABLE:
673 case HFI_H264_DB_MODE_SKIP_SLICE_BOUNDARY:
674 case HFI_H264_DB_MODE_ALL_BOUNDARY:
675 break;
676 default:
677 ret = -EINVAL;
678 break;
679 }
680
681 db->mode = in->mode;
682 db->slice_alpha_offset = in->slice_alpha_offset;
683 db->slice_beta_offset = in->slice_beta_offset;
684 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*db);
685 break;
686 }
687 case HFI_PROPERTY_PARAM_VENC_SESSION_QP: {
688 struct hfi_quantization *in = pdata, *quant = prop_data;
689
690 quant->qp_i = in->qp_i;
691 quant->qp_p = in->qp_p;
692 quant->qp_b = in->qp_b;
693 quant->layer_id = in->layer_id;
694 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*quant);
695 break;
696 }
697 case HFI_PROPERTY_PARAM_VENC_SESSION_QP_RANGE: {
698 struct hfi_quantization_range *in = pdata, *range = prop_data;
699 u32 min_qp, max_qp;
700
701 min_qp = in->min_qp;
702 max_qp = in->max_qp;
703
704 /* We'll be packing in the qp, so make sure we
705 * won't be losing data when masking
706 */
707 if (min_qp > 0xff || max_qp > 0xff) {
708 ret = -ERANGE;
709 break;
710 }
711
712 /* When creating the packet, pack the qp value as
713 * 0xiippbb, where ii = qp range for I-frames,
714 * pp = qp range for P-frames, etc.
715 */
716 range->min_qp = min_qp | min_qp << 8 | min_qp << 16;
717 range->max_qp = max_qp | max_qp << 8 | max_qp << 16;
718 range->layer_id = in->layer_id;
719
720 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*range);
721 break;
722 }
723 case HFI_PROPERTY_PARAM_VENC_VC1_PERF_CFG: {
724 struct hfi_vc1e_perf_cfg_type *in = pdata, *perf = prop_data;
725
726 memcpy(perf->search_range_x_subsampled,
727 in->search_range_x_subsampled,
728 sizeof(perf->search_range_x_subsampled));
729 memcpy(perf->search_range_y_subsampled,
730 in->search_range_y_subsampled,
731 sizeof(perf->search_range_y_subsampled));
732
733 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*perf);
734 break;
735 }
736 case HFI_PROPERTY_PARAM_VENC_MAX_NUM_B_FRAMES: {
737 struct hfi_max_num_b_frames *bframes = prop_data;
738 u32 *in = pdata;
739
740 bframes->max_num_b_frames = *in;
741 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*bframes);
742 break;
743 }
744 case HFI_PROPERTY_CONFIG_VENC_INTRA_PERIOD: {
745 struct hfi_intra_period *in = pdata, *intra = prop_data;
746
747 intra->pframes = in->pframes;
748 intra->bframes = in->bframes;
749 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*intra);
750 break;
751 }
752 case HFI_PROPERTY_CONFIG_VENC_IDR_PERIOD: {
753 struct hfi_idr_period *in = pdata, *idr = prop_data;
754
755 idr->idr_period = in->idr_period;
756 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*idr);
757 break;
758 }
759 case HFI_PROPERTY_PARAM_VDEC_CONCEAL_COLOR: {
760 struct hfi_conceal_color *color = prop_data;
761 u32 *in = pdata;
762
763 color->conceal_color = *in;
764 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*color);
765 break;
766 }
767 case HFI_PROPERTY_CONFIG_VPE_OPERATIONS: {
768 struct hfi_operations_type *in = pdata, *ops = prop_data;
769
770 switch (in->rotation) {
771 case HFI_ROTATE_NONE:
772 case HFI_ROTATE_90:
773 case HFI_ROTATE_180:
774 case HFI_ROTATE_270:
775 break;
776 default:
777 ret = -EINVAL;
778 break;
779 }
780
781 switch (in->flip) {
782 case HFI_FLIP_NONE:
783 case HFI_FLIP_HORIZONTAL:
784 case HFI_FLIP_VERTICAL:
785 break;
786 default:
787 ret = -EINVAL;
788 break;
789 }
790
791 ops->rotation = in->rotation;
792 ops->flip = in->flip;
793 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*ops);
794 break;
795 }
796 case HFI_PROPERTY_PARAM_VENC_INTRA_REFRESH: {
797 struct hfi_intra_refresh *in = pdata, *intra = prop_data;
798
799 switch (in->mode) {
800 case HFI_INTRA_REFRESH_NONE:
801 case HFI_INTRA_REFRESH_ADAPTIVE:
802 case HFI_INTRA_REFRESH_CYCLIC:
803 case HFI_INTRA_REFRESH_CYCLIC_ADAPTIVE:
804 case HFI_INTRA_REFRESH_RANDOM:
805 break;
806 default:
807 ret = -EINVAL;
808 break;
809 }
810
811 intra->mode = in->mode;
812 intra->air_mbs = in->air_mbs;
813 intra->air_ref = in->air_ref;
814 intra->cir_mbs = in->cir_mbs;
815 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*intra);
816 break;
817 }
818 case HFI_PROPERTY_PARAM_VENC_MULTI_SLICE_CONTROL: {
819 struct hfi_multi_slice_control *in = pdata, *multi = prop_data;
820
821 switch (in->multi_slice) {
822 case HFI_MULTI_SLICE_OFF:
823 case HFI_MULTI_SLICE_GOB:
824 case HFI_MULTI_SLICE_BY_MB_COUNT:
825 case HFI_MULTI_SLICE_BY_BYTE_COUNT:
826 break;
827 default:
828 ret = -EINVAL;
829 break;
830 }
831
832 multi->multi_slice = in->multi_slice;
833 multi->slice_size = in->slice_size;
834 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*multi);
835 break;
836 }
837 case HFI_PROPERTY_PARAM_VENC_SLICE_DELIVERY_MODE: {
838 struct hfi_enable *in = pdata, *en = prop_data;
839
840 en->enable = in->enable;
841 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
842 break;
843 }
844 case HFI_PROPERTY_PARAM_VENC_H264_VUI_TIMING_INFO: {
845 struct hfi_h264_vui_timing_info *in = pdata, *vui = prop_data;
846
847 vui->enable = in->enable;
848 vui->fixed_framerate = in->fixed_framerate;
849 vui->time_scale = in->time_scale;
850 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*vui);
851 break;
852 }
853 case HFI_PROPERTY_CONFIG_VPE_DEINTERLACE: {
854 struct hfi_enable *in = pdata, *en = prop_data;
855
856 en->enable = in->enable;
857 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
858 break;
859 }
860 case HFI_PROPERTY_PARAM_VENC_H264_GENERATE_AUDNAL: {
861 struct hfi_enable *in = pdata, *en = prop_data;
862
863 en->enable = in->enable;
864 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
865 break;
866 }
867 case HFI_PROPERTY_PARAM_BUFFER_ALLOC_MODE: {
868 struct hfi_buffer_alloc_mode *in = pdata, *mode = prop_data;
869
870 mode->type = in->type;
871 mode->mode = in->mode;
872 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*mode);
873 break;
874 }
875 case HFI_PROPERTY_PARAM_VDEC_FRAME_ASSEMBLY: {
876 struct hfi_enable *in = pdata, *en = prop_data;
877
878 en->enable = in->enable;
879 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
880 break;
881 }
882 case HFI_PROPERTY_PARAM_VENC_H264_VUI_BITSTREAM_RESTRC: {
883 struct hfi_enable *in = pdata, *en = prop_data;
884
885 en->enable = in->enable;
886 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
887 break;
888 }
889 case HFI_PROPERTY_PARAM_VENC_PRESERVE_TEXT_QUALITY: {
890 struct hfi_enable *in = pdata, *en = prop_data;
891
892 en->enable = in->enable;
893 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
894 break;
895 }
896 case HFI_PROPERTY_PARAM_VDEC_SCS_THRESHOLD: {
897 struct hfi_scs_threshold *thres = prop_data;
898 u32 *in = pdata;
899
900 thres->threshold_value = *in;
901 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*thres);
902 break;
903 }
904 case HFI_PROPERTY_PARAM_MVC_BUFFER_LAYOUT: {
905 struct hfi_mvc_buffer_layout_descp_type *in = pdata;
906 struct hfi_mvc_buffer_layout_descp_type *mvc = prop_data;
907
908 switch (in->layout_type) {
909 case HFI_MVC_BUFFER_LAYOUT_TOP_BOTTOM:
910 case HFI_MVC_BUFFER_LAYOUT_SEQ:
911 break;
912 default:
913 ret = -EINVAL;
914 break;
915 }
916
917 mvc->layout_type = in->layout_type;
918 mvc->bright_view_first = in->bright_view_first;
919 mvc->ngap = in->ngap;
920 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*mvc);
921 break;
922 }
923 case HFI_PROPERTY_PARAM_VENC_LTRMODE: {
924 struct hfi_ltr_mode *in = pdata, *ltr = prop_data;
925
926 switch (in->ltr_mode) {
927 case HFI_LTR_MODE_DISABLE:
928 case HFI_LTR_MODE_MANUAL:
929 case HFI_LTR_MODE_PERIODIC:
930 break;
931 default:
932 ret = -EINVAL;
933 break;
934 }
935
936 ltr->ltr_mode = in->ltr_mode;
937 ltr->ltr_count = in->ltr_count;
938 ltr->trust_mode = in->trust_mode;
939 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*ltr);
940 break;
941 }
942 case HFI_PROPERTY_CONFIG_VENC_USELTRFRAME: {
943 struct hfi_ltr_use *in = pdata, *ltr_use = prop_data;
944
945 ltr_use->frames = in->frames;
946 ltr_use->ref_ltr = in->ref_ltr;
947 ltr_use->use_constrnt = in->use_constrnt;
948 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*ltr_use);
949 break;
950 }
951 case HFI_PROPERTY_CONFIG_VENC_MARKLTRFRAME: {
952 struct hfi_ltr_mark *in = pdata, *ltr_mark = prop_data;
953
954 ltr_mark->mark_frame = in->mark_frame;
955 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*ltr_mark);
956 break;
957 }
958 case HFI_PROPERTY_PARAM_VENC_HIER_P_MAX_NUM_ENH_LAYER: {
959 u32 *in = pdata;
960
961 pkt->data[1] = *in;
962 pkt->shdr.hdr.size += sizeof(u32) * 2;
963 break;
964 }
965 case HFI_PROPERTY_CONFIG_VENC_HIER_P_ENH_LAYER: {
966 u32 *in = pdata;
967
968 pkt->data[1] = *in;
969 pkt->shdr.hdr.size += sizeof(u32) * 2;
970 break;
971 }
972 case HFI_PROPERTY_PARAM_VENC_DISABLE_RC_TIMESTAMP: {
973 struct hfi_enable *in = pdata, *en = prop_data;
974
975 en->enable = in->enable;
976 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
977 break;
978 }
979 case HFI_PROPERTY_PARAM_VENC_INITIAL_QP: {
980 struct hfi_initial_quantization *in = pdata, *quant = prop_data;
981
982 quant->init_qp_enable = in->init_qp_enable;
983 quant->qp_i = in->qp_i;
984 quant->qp_p = in->qp_p;
985 quant->qp_b = in->qp_b;
986 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*quant);
987 break;
988 }
989 case HFI_PROPERTY_PARAM_VPE_COLOR_SPACE_CONVERSION: {
990 struct hfi_vpe_color_space_conversion *in = pdata;
991 struct hfi_vpe_color_space_conversion *csc = prop_data;
992
993 memcpy(csc->csc_matrix, in->csc_matrix,
994 sizeof(csc->csc_matrix));
995 memcpy(csc->csc_bias, in->csc_bias, sizeof(csc->csc_bias));
996 memcpy(csc->csc_limit, in->csc_limit, sizeof(csc->csc_limit));
997 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*csc);
998 break;
999 }
1000 case HFI_PROPERTY_PARAM_VENC_VPX_ERROR_RESILIENCE_MODE: {
1001 struct hfi_enable *in = pdata, *en = prop_data;
1002
1003 en->enable = in->enable;
1004 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
1005 break;
1006 }
1007 case HFI_PROPERTY_PARAM_VENC_H264_NAL_SVC_EXT: {
1008 struct hfi_enable *in = pdata, *en = prop_data;
1009
1010 en->enable = in->enable;
1011 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
1012 break;
1013 }
1014 case HFI_PROPERTY_CONFIG_VENC_PERF_MODE: {
1015 u32 *in = pdata;
1016
1017 pkt->data[1] = *in;
1018 pkt->shdr.hdr.size += sizeof(u32) * 2;
1019 break;
1020 }
1021 case HFI_PROPERTY_PARAM_VENC_HIER_B_MAX_NUM_ENH_LAYER: {
1022 u32 *in = pdata;
1023
1024 pkt->data[1] = *in;
1025 pkt->shdr.hdr.size += sizeof(u32) * 2;
1026 break;
1027 }
1028 case HFI_PROPERTY_PARAM_VDEC_NONCP_OUTPUT2: {
1029 struct hfi_enable *in = pdata, *en = prop_data;
1030
1031 en->enable = in->enable;
1032 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*en);
1033 break;
1034 }
1035 case HFI_PROPERTY_PARAM_VENC_HIER_P_HYBRID_MODE: {
1036 struct hfi_hybrid_hierp *in = pdata, *hierp = prop_data;
1037
1038 hierp->layers = in->layers;
1039 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*hierp);
1040 break;
1041 }
1042
1043 /* FOLLOWING PROPERTIES ARE NOT IMPLEMENTED IN CORE YET */
1044 case HFI_PROPERTY_CONFIG_BUFFER_REQUIREMENTS:
1045 case HFI_PROPERTY_CONFIG_PRIORITY:
1046 case HFI_PROPERTY_CONFIG_BATCH_INFO:
1047 case HFI_PROPERTY_SYS_IDLE_INDICATOR:
1048 case HFI_PROPERTY_PARAM_UNCOMPRESSED_FORMAT_SUPPORTED:
1049 case HFI_PROPERTY_PARAM_INTERLACE_FORMAT_SUPPORTED:
1050 case HFI_PROPERTY_PARAM_CHROMA_SITE:
1051 case HFI_PROPERTY_PARAM_PROPERTIES_SUPPORTED:
1052 case HFI_PROPERTY_PARAM_PROFILE_LEVEL_SUPPORTED:
1053 case HFI_PROPERTY_PARAM_CAPABILITY_SUPPORTED:
1054 case HFI_PROPERTY_PARAM_NAL_STREAM_FORMAT_SUPPORTED:
1055 case HFI_PROPERTY_PARAM_MULTI_VIEW_FORMAT:
1056 case HFI_PROPERTY_PARAM_MAX_SEQUENCE_HEADER_SIZE:
1057 case HFI_PROPERTY_PARAM_CODEC_SUPPORTED:
1058 case HFI_PROPERTY_PARAM_VDEC_MULTI_VIEW_SELECT:
1059 case HFI_PROPERTY_PARAM_VDEC_MB_QUANTIZATION:
1060 case HFI_PROPERTY_PARAM_VDEC_NUM_CONCEALED_MB:
1061 case HFI_PROPERTY_PARAM_VDEC_H264_ENTROPY_SWITCHING:
1062 case HFI_PROPERTY_PARAM_VENC_MULTI_SLICE_INFO:
1063 default:
1064 return -EINVAL;
1065 }
1066
1067 return ret;
1068 }
1069
1070 static int
pkt_session_get_property_3xx(struct hfi_session_get_property_pkt * pkt,void * cookie,u32 ptype)1071 pkt_session_get_property_3xx(struct hfi_session_get_property_pkt *pkt,
1072 void *cookie, u32 ptype)
1073 {
1074 int ret = 0;
1075
1076 if (!pkt || !cookie)
1077 return -EINVAL;
1078
1079 pkt->shdr.hdr.size = sizeof(struct hfi_session_get_property_pkt);
1080 pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_GET_PROPERTY;
1081 pkt->shdr.session_id = hash32_ptr(cookie);
1082 pkt->num_properties = 1;
1083
1084 switch (ptype) {
1085 case HFI_PROPERTY_CONFIG_VDEC_ENTROPY:
1086 pkt->data[0] = HFI_PROPERTY_CONFIG_VDEC_ENTROPY;
1087 break;
1088 default:
1089 ret = pkt_session_get_property_1x(pkt, cookie, ptype);
1090 break;
1091 }
1092
1093 return ret;
1094 }
1095
1096 static int
pkt_session_set_property_3xx(struct hfi_session_set_property_pkt * pkt,void * cookie,u32 ptype,void * pdata)1097 pkt_session_set_property_3xx(struct hfi_session_set_property_pkt *pkt,
1098 void *cookie, u32 ptype, void *pdata)
1099 {
1100 void *prop_data;
1101 int ret = 0;
1102
1103 if (!pkt || !cookie || !pdata)
1104 return -EINVAL;
1105
1106 prop_data = &pkt->data[1];
1107
1108 pkt->shdr.hdr.size = sizeof(*pkt);
1109 pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_SET_PROPERTY;
1110 pkt->shdr.session_id = hash32_ptr(cookie);
1111 pkt->num_properties = 1;
1112 pkt->data[0] = ptype;
1113
1114 /*
1115 * Any session set property which is different in 3XX packetization
1116 * should be added as a new case below. All unchanged session set
1117 * properties will be handled in the default case.
1118 */
1119 switch (ptype) {
1120 case HFI_PROPERTY_PARAM_VDEC_MULTI_STREAM: {
1121 struct hfi_multi_stream *in = pdata;
1122 struct hfi_multi_stream_3x *multi = prop_data;
1123
1124 multi->buffer_type = in->buffer_type;
1125 multi->enable = in->enable;
1126 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*multi);
1127 break;
1128 }
1129 case HFI_PROPERTY_PARAM_VENC_INTRA_REFRESH: {
1130 struct hfi_intra_refresh *in = pdata;
1131 struct hfi_intra_refresh_3x *intra = prop_data;
1132
1133 switch (in->mode) {
1134 case HFI_INTRA_REFRESH_NONE:
1135 case HFI_INTRA_REFRESH_ADAPTIVE:
1136 case HFI_INTRA_REFRESH_CYCLIC:
1137 case HFI_INTRA_REFRESH_CYCLIC_ADAPTIVE:
1138 case HFI_INTRA_REFRESH_RANDOM:
1139 break;
1140 default:
1141 ret = -EINVAL;
1142 break;
1143 }
1144
1145 intra->mode = in->mode;
1146 intra->mbs = in->cir_mbs;
1147 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*intra);
1148 break;
1149 }
1150 case HFI_PROPERTY_PARAM_VDEC_CONTINUE_DATA_TRANSFER:
1151 /* for 3xx fw version session_continue is used */
1152 break;
1153 default:
1154 ret = pkt_session_set_property_1x(pkt, cookie, ptype, pdata);
1155 break;
1156 }
1157
1158 return ret;
1159 }
1160
1161 static int
pkt_session_set_property_4xx(struct hfi_session_set_property_pkt * pkt,void * cookie,u32 ptype,void * pdata)1162 pkt_session_set_property_4xx(struct hfi_session_set_property_pkt *pkt,
1163 void *cookie, u32 ptype, void *pdata)
1164 {
1165 void *prop_data;
1166
1167 if (!pkt || !cookie || !pdata)
1168 return -EINVAL;
1169
1170 prop_data = &pkt->data[1];
1171
1172 pkt->shdr.hdr.size = sizeof(*pkt);
1173 pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_SET_PROPERTY;
1174 pkt->shdr.session_id = hash32_ptr(cookie);
1175 pkt->num_properties = 1;
1176 pkt->data[0] = ptype;
1177
1178 /*
1179 * Any session set property which is different in 3XX packetization
1180 * should be added as a new case below. All unchanged session set
1181 * properties will be handled in the default case.
1182 */
1183 switch (ptype) {
1184 case HFI_PROPERTY_PARAM_BUFFER_COUNT_ACTUAL: {
1185 struct hfi_buffer_count_actual *in = pdata;
1186 struct hfi_buffer_count_actual_4xx *count = prop_data;
1187
1188 count->count_actual = in->count_actual;
1189 count->type = in->type;
1190 count->count_min_host = in->count_actual;
1191 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*count);
1192 break;
1193 }
1194 case HFI_PROPERTY_PARAM_WORK_MODE: {
1195 struct hfi_video_work_mode *in = pdata, *wm = prop_data;
1196
1197 wm->video_work_mode = in->video_work_mode;
1198 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*wm);
1199 break;
1200 }
1201 case HFI_PROPERTY_CONFIG_VIDEOCORES_USAGE: {
1202 struct hfi_videocores_usage_type *in = pdata, *cu = prop_data;
1203
1204 cu->video_core_enable_mask = in->video_core_enable_mask;
1205 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*cu);
1206 break;
1207 }
1208 case HFI_PROPERTY_CONFIG_VENC_MAX_BITRATE:
1209 case HFI_PROPERTY_CONFIG_VDEC_POST_LOOP_DEBLOCKER:
1210 case HFI_PROPERTY_PARAM_BUFFER_ALLOC_MODE:
1211 case HFI_PROPERTY_PARAM_VENC_SESSION_QP:
1212 case HFI_PROPERTY_PARAM_VENC_SESSION_QP_RANGE:
1213 /* not implemented on Venus 4xx */
1214 return -ENOTSUPP;
1215 default:
1216 return pkt_session_set_property_3xx(pkt, cookie, ptype, pdata);
1217 }
1218
1219 return 0;
1220 }
1221
1222 static int
pkt_session_set_property_6xx(struct hfi_session_set_property_pkt * pkt,void * cookie,u32 ptype,void * pdata)1223 pkt_session_set_property_6xx(struct hfi_session_set_property_pkt *pkt,
1224 void *cookie, u32 ptype, void *pdata)
1225 {
1226 void *prop_data;
1227
1228 if (!pkt || !cookie || !pdata)
1229 return -EINVAL;
1230
1231 prop_data = &pkt->data[1];
1232
1233 pkt->shdr.hdr.size = sizeof(*pkt);
1234 pkt->shdr.hdr.pkt_type = HFI_CMD_SESSION_SET_PROPERTY;
1235 pkt->shdr.session_id = hash32_ptr(cookie);
1236 pkt->num_properties = 1;
1237 pkt->data[0] = ptype;
1238
1239 switch (ptype) {
1240 case HFI_PROPERTY_CONFIG_HEIC_FRAME_QUALITY: {
1241 struct hfi_heic_frame_quality *in = pdata, *cq = prop_data;
1242
1243 cq->frame_quality = in->frame_quality;
1244 pkt->shdr.hdr.size += sizeof(u32) + sizeof(*cq);
1245 break;
1246 } default:
1247 return pkt_session_set_property_4xx(pkt, cookie, ptype, pdata);
1248 }
1249
1250 return 0;
1251 }
1252
pkt_session_get_property(struct hfi_session_get_property_pkt * pkt,void * cookie,u32 ptype)1253 int pkt_session_get_property(struct hfi_session_get_property_pkt *pkt,
1254 void *cookie, u32 ptype)
1255 {
1256 if (hfi_ver == HFI_VERSION_1XX)
1257 return pkt_session_get_property_1x(pkt, cookie, ptype);
1258
1259 return pkt_session_get_property_3xx(pkt, cookie, ptype);
1260 }
1261
pkt_session_set_property(struct hfi_session_set_property_pkt * pkt,void * cookie,u32 ptype,void * pdata)1262 int pkt_session_set_property(struct hfi_session_set_property_pkt *pkt,
1263 void *cookie, u32 ptype, void *pdata)
1264 {
1265 if (hfi_ver == HFI_VERSION_1XX)
1266 return pkt_session_set_property_1x(pkt, cookie, ptype, pdata);
1267
1268 if (hfi_ver == HFI_VERSION_3XX)
1269 return pkt_session_set_property_3xx(pkt, cookie, ptype, pdata);
1270
1271 if (hfi_ver == HFI_VERSION_4XX)
1272 return pkt_session_set_property_4xx(pkt, cookie, ptype, pdata);
1273
1274 return pkt_session_set_property_6xx(pkt, cookie, ptype, pdata);
1275 }
1276
pkt_set_version(enum hfi_version version)1277 void pkt_set_version(enum hfi_version version)
1278 {
1279 hfi_ver = version;
1280 }
1281