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