Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: iris: Add support for G/S_PARM for encoder video device

Add supports for the G/S_PARM V4L2 ioctls for encoder video device with
necessary hooks. This allows userspace to query the current streaming
parameters such as frame intervals and set desired streaming parameters
primarily the frame rate.

Tested-by: Vikash Garodia <quic_vgarodia@quicinc.com> # X1E80100
Reviewed-by: Vikash Garodia <quic_vgarodia@quicinc.com>
Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-HDK
Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8650-HDK
Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
Tested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # x1e80100-crd
Signed-off-by: Bryan O'Donoghue <bod@kernel.org>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Dikshita Agarwal and committed by
Hans Verkuil
4ff586ff bed072b4

+177 -17
+5
drivers/media/platform/qcom/iris/iris_instance.h
··· 61 61 * @metadata_idx: index for metadata buffer 62 62 * @codec: codec type 63 63 * @last_buffer_dequeued: a flag to indicate that last buffer is sent by driver 64 + * @frame_rate: frame rate of current instance 65 + * @operating_rate: operating rate of current instance 66 + 64 67 */ 65 68 66 69 struct iris_inst { ··· 99 96 u32 metadata_idx; 100 97 u32 codec; 101 98 bool last_buffer_dequeued; 99 + u32 frame_rate; 100 + u32 operating_rate; 102 101 }; 103 102 104 103 #endif
+2
drivers/media/platform/qcom/iris/iris_platform_common.h
··· 83 83 u32 mb_cycles_fw; 84 84 u32 mb_cycles_fw_vpp; 85 85 u32 num_comv; 86 + u32 max_frame_rate; 87 + u32 max_operating_rate; 86 88 }; 87 89 88 90 enum platform_inst_fw_cap_type {
+2
drivers/media/platform/qcom/iris/iris_platform_gen2.c
··· 211 211 .mb_cycles_fw = 489583, 212 212 .mb_cycles_fw_vpp = 66234, 213 213 .num_comv = 0, 214 + .max_frame_rate = MAXIMUM_FPS, 215 + .max_operating_rate = MAXIMUM_FPS, 214 216 }; 215 217 216 218 static void iris_set_sm8550_preset_registers(struct iris_core *core)
+2
drivers/media/platform/qcom/iris/iris_platform_qcs8300.h
··· 197 197 .mb_cycles_fw = 326389, 198 198 .mb_cycles_fw_vpp = 44156, 199 199 .num_comv = 0, 200 + .max_frame_rate = MAXIMUM_FPS, 201 + .max_operating_rate = MAXIMUM_FPS, 200 202 };
+2
drivers/media/platform/qcom/iris/iris_platform_sm8250.c
··· 40 40 .max_mbpf = 138240, 41 41 .mb_cycles_vsp = 25, 42 42 .mb_cycles_vpp = 200, 43 + .max_frame_rate = MAXIMUM_FPS, 44 + .max_operating_rate = MAXIMUM_FPS, 43 45 }; 44 46 45 47 static void iris_set_sm8250_preset_registers(struct iris_core *core)
+36
drivers/media/platform/qcom/iris/iris_utils.c
··· 88 88 mutex_unlock(&core->lock); 89 89 return NULL; 90 90 } 91 + 92 + int iris_check_core_mbpf(struct iris_inst *inst) 93 + { 94 + struct iris_core *core = inst->core; 95 + struct iris_inst *instance; 96 + u32 total_mbpf = 0; 97 + 98 + mutex_lock(&core->lock); 99 + list_for_each_entry(instance, &core->instances, list) 100 + total_mbpf += iris_get_mbpf(instance); 101 + mutex_unlock(&core->lock); 102 + 103 + if (total_mbpf > core->iris_platform_data->max_core_mbpf) 104 + return -ENOMEM; 105 + 106 + return 0; 107 + } 108 + 109 + int iris_check_core_mbps(struct iris_inst *inst) 110 + { 111 + struct iris_core *core = inst->core; 112 + struct iris_inst *instance; 113 + u32 total_mbps = 0, fps = 0; 114 + 115 + mutex_lock(&core->lock); 116 + list_for_each_entry(instance, &core->instances, list) { 117 + fps = max(instance->frame_rate, instance->operating_rate); 118 + total_mbps += iris_get_mbpf(instance) * fps; 119 + } 120 + mutex_unlock(&core->lock); 121 + 122 + if (total_mbps > core->iris_platform_data->max_core_mbps) 123 + return -ENOMEM; 124 + 125 + return 0; 126 + }
+2
drivers/media/platform/qcom/iris/iris_utils.h
··· 49 49 void iris_helper_buffers_done(struct iris_inst *inst, unsigned int type, 50 50 enum vb2_buffer_state state); 51 51 int iris_wait_for_session_response(struct iris_inst *inst, bool is_flush); 52 + int iris_check_core_mbpf(struct iris_inst *inst); 53 + int iris_check_core_mbps(struct iris_inst *inst); 52 54 53 55 #endif
-17
drivers/media/platform/qcom/iris/iris_vb2.c
··· 12 12 #include "iris_vdec.h" 13 13 #include "iris_power.h" 14 14 15 - static int iris_check_core_mbpf(struct iris_inst *inst) 16 - { 17 - struct iris_core *core = inst->core; 18 - struct iris_inst *instance; 19 - u32 total_mbpf = 0; 20 - 21 - mutex_lock(&core->lock); 22 - list_for_each_entry(instance, &core->instances, list) 23 - total_mbpf += iris_get_mbpf(instance); 24 - mutex_unlock(&core->lock); 25 - 26 - if (total_mbpf > core->iris_platform_data->max_core_mbpf) 27 - return -ENOMEM; 28 - 29 - return 0; 30 - } 31 - 32 15 static int iris_check_inst_mbpf(struct iris_inst *inst) 33 16 { 34 17 struct platform_inst_caps *caps;
+94
drivers/media/platform/qcom/iris/iris_venc.c
··· 61 61 inst->crop.width = f->fmt.pix_mp.width; 62 62 inst->crop.height = f->fmt.pix_mp.height; 63 63 64 + inst->operating_rate = DEFAULT_FPS; 65 + inst->frame_rate = DEFAULT_FPS; 66 + 64 67 return 0; 65 68 } 66 69 ··· 328 325 default: 329 326 return -EINVAL; 330 327 } 328 + } 329 + 330 + int iris_venc_s_param(struct iris_inst *inst, struct v4l2_streamparm *s_parm) 331 + { 332 + struct platform_inst_caps *caps = inst->core->iris_platform_data->inst_caps; 333 + struct vb2_queue *src_q = v4l2_m2m_get_src_vq(inst->m2m_ctx); 334 + struct vb2_queue *dst_q = v4l2_m2m_get_dst_vq(inst->m2m_ctx); 335 + struct v4l2_fract *timeperframe = NULL; 336 + u32 default_rate = DEFAULT_FPS; 337 + bool is_frame_rate = false; 338 + u64 us_per_frame, fps; 339 + u32 max_rate; 340 + 341 + int ret = 0; 342 + 343 + if (s_parm->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { 344 + timeperframe = &s_parm->parm.output.timeperframe; 345 + max_rate = caps->max_operating_rate; 346 + s_parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME; 347 + } else { 348 + timeperframe = &s_parm->parm.capture.timeperframe; 349 + is_frame_rate = true; 350 + max_rate = caps->max_frame_rate; 351 + s_parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; 352 + } 353 + 354 + if (!timeperframe->denominator || !timeperframe->numerator) { 355 + if (!timeperframe->numerator) 356 + timeperframe->numerator = 1; 357 + if (!timeperframe->denominator) 358 + timeperframe->denominator = default_rate; 359 + } 360 + 361 + us_per_frame = timeperframe->numerator * (u64)USEC_PER_SEC; 362 + do_div(us_per_frame, timeperframe->denominator); 363 + 364 + if (!us_per_frame) 365 + return -EINVAL; 366 + 367 + fps = (u64)USEC_PER_SEC; 368 + do_div(fps, us_per_frame); 369 + if (fps > max_rate) { 370 + ret = -ENOMEM; 371 + goto reset_rate; 372 + } 373 + 374 + if (is_frame_rate) 375 + inst->frame_rate = (u32)fps; 376 + else 377 + inst->operating_rate = (u32)fps; 378 + 379 + if ((s_parm->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE && vb2_is_streaming(src_q)) || 380 + (s_parm->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && vb2_is_streaming(dst_q))) { 381 + ret = iris_check_core_mbpf(inst); 382 + if (ret) 383 + goto reset_rate; 384 + ret = iris_check_core_mbps(inst); 385 + if (ret) 386 + goto reset_rate; 387 + } 388 + 389 + return 0; 390 + 391 + reset_rate: 392 + if (ret) { 393 + if (is_frame_rate) 394 + inst->frame_rate = default_rate; 395 + else 396 + inst->operating_rate = default_rate; 397 + } 398 + 399 + return ret; 400 + } 401 + 402 + int iris_venc_g_param(struct iris_inst *inst, struct v4l2_streamparm *s_parm) 403 + { 404 + struct v4l2_fract *timeperframe = NULL; 405 + 406 + if (s_parm->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { 407 + timeperframe = &s_parm->parm.output.timeperframe; 408 + timeperframe->numerator = 1; 409 + timeperframe->denominator = inst->operating_rate; 410 + s_parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME; 411 + } else { 412 + timeperframe = &s_parm->parm.capture.timeperframe; 413 + timeperframe->numerator = 1; 414 + timeperframe->denominator = inst->frame_rate; 415 + s_parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; 416 + } 417 + 418 + return 0; 331 419 }
+2
drivers/media/platform/qcom/iris/iris_venc.h
··· 16 16 int iris_venc_validate_format(struct iris_inst *inst, u32 pixelformat); 17 17 int iris_venc_subscribe_event(struct iris_inst *inst, const struct v4l2_event_subscription *sub); 18 18 int iris_venc_s_selection(struct iris_inst *inst, struct v4l2_selection *s); 19 + int iris_venc_g_param(struct iris_inst *inst, struct v4l2_streamparm *s_parm); 20 + int iris_venc_s_param(struct iris_inst *inst, struct v4l2_streamparm *s_parm); 19 21 20 22 #endif
+30
drivers/media/platform/qcom/iris/iris_vidc.c
··· 530 530 return -EINVAL; 531 531 } 532 532 533 + static int iris_s_parm(struct file *filp, void *fh, struct v4l2_streamparm *a) 534 + { 535 + struct iris_inst *inst = iris_get_inst(filp); 536 + 537 + if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && 538 + a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 539 + return -EINVAL; 540 + 541 + if (inst->domain == ENCODER) 542 + return iris_venc_s_param(inst, a); 543 + else 544 + return -EINVAL; 545 + } 546 + 547 + static int iris_g_parm(struct file *filp, void *fh, struct v4l2_streamparm *a) 548 + { 549 + struct iris_inst *inst = iris_get_inst(filp); 550 + 551 + if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE && 552 + a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 553 + return -EINVAL; 554 + 555 + if (inst->domain == ENCODER) 556 + return iris_venc_g_param(inst, a); 557 + else 558 + return -EINVAL; 559 + } 560 + 533 561 static int iris_dec_cmd(struct file *filp, void *fh, 534 562 struct v4l2_decoder_cmd *dec) 535 563 { ··· 654 626 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 655 627 .vidioc_g_selection = iris_g_selection, 656 628 .vidioc_s_selection = iris_s_selection, 629 + .vidioc_s_parm = iris_s_parm, 630 + .vidioc_g_parm = iris_g_parm, 657 631 }; 658 632 659 633 void iris_init_ops(struct iris_core *core)