Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
From: Dikshita Agarwal <quic_dikshita@quicinc.com>
To: Hans Verkuil <hverkuil@xs4all.nl>,
	Vikash Garodia <quic_vgarodia@quicinc.com>,
	Abhinav Kumar <quic_abhinavk@quicinc.com>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>
Cc: "Sebastian Fricke" <sebastian.fricke@collabora.com>,
	"Bryan O'Donoghue" <bryan.odonoghue@linaro.org>,
	"Dmitry Baryshkov" <dmitry.baryshkov@linaro.org>,
	"Neil Armstrong" <neil.armstrong@linaro.org>,
	"Nicolas Dufresne" <nicolas@ndufresne.ca>,
	"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
	"Jianhua Lu" <lujianhua000@gmail.com>,
	linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Vedang Nagar" <quic_vnagar@quicinc.com>
Subject: Re: [PATCH v5 10/28] media: iris: implement s_fmt, g_fmt and try_fmt ioctls
Date: Wed, 13 Nov 2024 10:55:44 +0530	[thread overview]
Message-ID: <25bd2b16-35ef-99ee-5b32-7c949cbcaf81@quicinc.com> (raw)
In-Reply-To: <8f941640-c2c3-4dc5-bb90-ccf8a6db98b2@xs4all.nl>



On 11/12/2024 3:48 PM, Hans Verkuil wrote:
> On 05/11/2024 07:55, Dikshita Agarwal wrote:
>> From: Vedang Nagar <quic_vnagar@quicinc.com>
>>
>> Implement s_fmt, g_fmt and try_fmt ioctl ops with necessary hooks.
>>
>> Signed-off-by: Vedang Nagar <quic_vnagar@quicinc.com>
>> Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
>> ---
>>  drivers/media/platform/qcom/iris/iris_vdec.c | 131 +++++++++++++++++++++++++++
>>  drivers/media/platform/qcom/iris/iris_vdec.h |   2 +
>>  drivers/media/platform/qcom/iris/iris_vidc.c |  48 ++++++++++
>>  3 files changed, 181 insertions(+)
>>
>> diff --git a/drivers/media/platform/qcom/iris/iris_vdec.c b/drivers/media/platform/qcom/iris/iris_vdec.c
>> index 7d1ef31c7c44..e807decdda2b 100644
>> --- a/drivers/media/platform/qcom/iris/iris_vdec.c
>> +++ b/drivers/media/platform/qcom/iris/iris_vdec.c
>> @@ -3,6 +3,8 @@
>>   * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
>>   */
>>  
>> +#include <media/v4l2-mem2mem.h>
>> +
>>  #include "iris_buffer.h"
>>  #include "iris_instance.h"
>>  #include "iris_vdec.h"
>> @@ -10,6 +12,7 @@
>>  
>>  #define DEFAULT_WIDTH 320
>>  #define DEFAULT_HEIGHT 240
>> +#define DEFAULT_CODEC_ALIGNMENT 16
>>  
>>  void iris_vdec_inst_init(struct iris_inst *inst)
>>  {
>> @@ -56,3 +59,131 @@ void iris_vdec_inst_deinit(struct iris_inst *inst)
>>  	kfree(inst->fmt_dst);
>>  	kfree(inst->fmt_src);
>>  }
>> +
>> +int iris_vdec_try_fmt(struct iris_inst *inst, struct v4l2_format *f)
>> +{
>> +	struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp;
>> +	struct v4l2_m2m_ctx *m2m_ctx = inst->m2m_ctx;
>> +	struct v4l2_format *f_inst;
>> +	struct vb2_queue *src_q;
>> +
>> +	memset(pixmp->reserved, 0, sizeof(pixmp->reserved));
>> +	switch (f->type) {
>> +	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
>> +		if (f->fmt.pix_mp.pixelformat != V4L2_PIX_FMT_H264) {
>> +			f_inst = inst->fmt_src;
>> +			f->fmt.pix_mp.width = f_inst->fmt.pix_mp.width;
>> +			f->fmt.pix_mp.height = f_inst->fmt.pix_mp.height;
>> +			f->fmt.pix_mp.pixelformat = f_inst->fmt.pix_mp.pixelformat;
>> +		}
>> +		break;
>> +	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
>> +		if (f->fmt.pix_mp.pixelformat != V4L2_PIX_FMT_NV12) {
>> +			f_inst = inst->fmt_dst;
>> +			f->fmt.pix_mp.pixelformat = f_inst->fmt.pix_mp.pixelformat;
>> +			f->fmt.pix_mp.width = f_inst->fmt.pix_mp.width;
>> +			f->fmt.pix_mp.height = f_inst->fmt.pix_mp.height;
>> +		}
>> +
>> +		src_q = v4l2_m2m_get_src_vq(m2m_ctx);
>> +		if (vb2_is_streaming(src_q)) {
>> +			f_inst = inst->fmt_src;
>> +			f->fmt.pix_mp.height = f_inst->fmt.pix_mp.height;
>> +			f->fmt.pix_mp.width = f_inst->fmt.pix_mp.width;
>> +		}
>> +		break;
>> +	default:
>> +		return -EINVAL;
>> +	}
>> +
>> +	if (pixmp->field == V4L2_FIELD_ANY)
>> +		pixmp->field = V4L2_FIELD_NONE;
>> +
>> +	pixmp->num_planes = 1;
>> +
>> +	return 0;
>> +}
>> +
>> +int iris_vdec_s_fmt(struct iris_inst *inst, struct v4l2_format *f)
>> +{
>> +	struct v4l2_format *fmt, *output_fmt;
>> +	struct vb2_queue *q;
>> +	u32 codec_align;
>> +
>> +	iris_vdec_try_fmt(inst, f);
>> +
>> +	switch (f->type) {
>> +	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
>> +		if (f->fmt.pix_mp.pixelformat != V4L2_PIX_FMT_H264)
>> +			return -EINVAL;
>> +
>> +		fmt = inst->fmt_src;
>> +		fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
>> +
>> +		codec_align = DEFAULT_CODEC_ALIGNMENT;
>> +		fmt->fmt.pix_mp.width = ALIGN(f->fmt.pix_mp.width, codec_align);
>> +		fmt->fmt.pix_mp.height = ALIGN(f->fmt.pix_mp.height, codec_align);
>> +		fmt->fmt.pix_mp.num_planes = 1;
>> +		fmt->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
>> +		fmt->fmt.pix_mp.plane_fmt[0].sizeimage = iris_get_buffer_size(inst, BUF_INPUT);
>> +		inst->buffers[BUF_INPUT].min_count = iris_vpu_buf_count(inst, BUF_INPUT);
>> +		if (inst->buffers[BUF_INPUT].actual_count < inst->buffers[BUF_INPUT].min_count)
>> +			inst->buffers[BUF_INPUT].actual_count = inst->buffers[BUF_INPUT].min_count;
>> +
>> +		inst->buffers[BUF_INPUT].size = fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
>> +
>> +		fmt->fmt.pix_mp.colorspace = f->fmt.pix_mp.colorspace;
>> +		fmt->fmt.pix_mp.xfer_func = f->fmt.pix_mp.xfer_func;
>> +		fmt->fmt.pix_mp.ycbcr_enc = f->fmt.pix_mp.ycbcr_enc;
>> +		fmt->fmt.pix_mp.quantization = f->fmt.pix_mp.quantization;
>> +
>> +		output_fmt = inst->fmt_dst;
>> +		output_fmt->fmt.pix_mp.colorspace = f->fmt.pix_mp.colorspace;
>> +		output_fmt->fmt.pix_mp.xfer_func = f->fmt.pix_mp.xfer_func;
>> +		output_fmt->fmt.pix_mp.ycbcr_enc = f->fmt.pix_mp.ycbcr_enc;
>> +		output_fmt->fmt.pix_mp.quantization = f->fmt.pix_mp.quantization;
>> +
>> +		inst->crop.left = 0;
>> +		inst->crop.top = 0;
>> +		inst->crop.width = f->fmt.pix_mp.width;
>> +		inst->crop.height = f->fmt.pix_mp.height;
>> +		break;
>> +	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
>> +		fmt = inst->fmt_dst;
>> +		fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
>> +		q = v4l2_m2m_get_vq(inst->m2m_ctx, f->type);
>> +		if (q->streaming) {
>> +			f->fmt.pix_mp.height = inst->fmt_src->fmt.pix_mp.height;
>> +			f->fmt.pix_mp.width = inst->fmt_src->fmt.pix_mp.width;
>> +		}
>> +		if (fmt->fmt.pix_mp.pixelformat != V4L2_PIX_FMT_NV12)
>> +			return -EINVAL;
>> +		fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
>> +		fmt->fmt.pix_mp.width = ALIGN(f->fmt.pix_mp.width, 128);
>> +		fmt->fmt.pix_mp.height = ALIGN(f->fmt.pix_mp.height, 32);
>> +		fmt->fmt.pix_mp.num_planes = 1;
>> +		fmt->fmt.pix_mp.plane_fmt[0].bytesperline = ALIGN(f->fmt.pix_mp.width, 128);
>> +		fmt->fmt.pix_mp.plane_fmt[0].sizeimage = iris_get_buffer_size(inst, BUF_OUTPUT);
>> +
>> +		if (!q->streaming)
>> +			inst->buffers[BUF_OUTPUT].min_count = iris_vpu_buf_count(inst, BUF_INPUT);
>> +		if (inst->buffers[BUF_OUTPUT].actual_count < inst->buffers[BUF_OUTPUT].min_count)
>> +			inst->buffers[BUF_OUTPUT].actual_count =
>> +				inst->buffers[BUF_OUTPUT].min_count;
>> +
>> +		inst->buffers[BUF_OUTPUT].size = fmt->fmt.pix_mp.plane_fmt[0].sizeimage;
>> +
>> +		if (!q->streaming) {
>> +			inst->crop.top = 0;
>> +			inst->crop.left = 0;
>> +			inst->crop.width = f->fmt.pix_mp.width;
>> +			inst->crop.height = f->fmt.pix_mp.height;
>> +		}
>> +		break;
>> +	default:
>> +		return -EINVAL;
>> +	}
>> +	memcpy(f, fmt, sizeof(*fmt));
>> +
>> +	return 0;
>> +}
>> diff --git a/drivers/media/platform/qcom/iris/iris_vdec.h b/drivers/media/platform/qcom/iris/iris_vdec.h
>> index 0324d7f796dd..4f2557d15ca2 100644
>> --- a/drivers/media/platform/qcom/iris/iris_vdec.h
>> +++ b/drivers/media/platform/qcom/iris/iris_vdec.h
>> @@ -10,5 +10,7 @@ struct iris_inst;
>>  
>>  void iris_vdec_inst_init(struct iris_inst *inst);
>>  void iris_vdec_inst_deinit(struct iris_inst *inst);
>> +int iris_vdec_try_fmt(struct iris_inst *inst, struct v4l2_format *f);
>> +int iris_vdec_s_fmt(struct iris_inst *inst, struct v4l2_format *f);
>>  
>>  #endif
>> diff --git a/drivers/media/platform/qcom/iris/iris_vidc.c b/drivers/media/platform/qcom/iris/iris_vidc.c
>> index ab3b63171c1d..6707eb9917fe 100644
>> --- a/drivers/media/platform/qcom/iris/iris_vidc.c
>> +++ b/drivers/media/platform/qcom/iris/iris_vidc.c
>> @@ -217,6 +217,48 @@ int iris_close(struct file *filp)
>>  	return 0;
>>  }
>>  
>> +static int iris_try_fmt_vid_mplane(struct file *filp, void *fh, struct v4l2_format *f)
>> +{
>> +	struct iris_inst *inst = iris_get_inst(filp, NULL);
>> +	int ret;
>> +
>> +	mutex_lock(&inst->lock);
> 
> This is a bit weird. Normally the ioctls are serialized through the
> lock specified in struct video_device. Only queuing related ioctls
> can use a different lock (and they do in this driver).
> 
> So I would expect that vdev->lock is set to &inst->lock in the probe
> function, and that these wrapper functions for these ioctls would
> disappear, since there is no longer a need for them.
> 
> Drivers should not, in principle, serialize ioctls themselves, and
> instead they should set the lock in video_device. Unless there are
> very good reasons for doing otherwise.
> 
The intention behind using inst->lock is not to serialize the ioctls, but
to serialize the forward (driver) and reverse (firmware) threads.
We are taking the lock here, bcoz reverse thread can also update the
memebers of inst struture.

Thanks,
Dikshita
>> +	ret = iris_vdec_try_fmt(inst, f);
>> +	mutex_unlock(&inst->lock);
>> +
>> +	return ret;
>> +}
>> +
>> +static int iris_s_fmt_vid_mplane(struct file *filp, void *fh, struct v4l2_format *f)
>> +{
>> +	struct iris_inst *inst = iris_get_inst(filp, NULL);
>> +	int ret;
>> +
>> +	mutex_lock(&inst->lock);
>> +	ret = iris_vdec_s_fmt(inst, f);
>> +	mutex_unlock(&inst->lock);
>> +
>> +	return ret;
>> +}
>> +
>> +static int iris_g_fmt_vid_mplane(struct file *filp, void *fh, struct v4l2_format *f)
>> +{
>> +	struct iris_inst *inst = iris_get_inst(filp, NULL);
>> +	int ret = 0;
>> +
>> +	mutex_lock(&inst->lock);
>> +	if (V4L2_TYPE_IS_OUTPUT(f->type))
>> +		memcpy(f, inst->fmt_src, sizeof(*f));
> 
> Just do: *f = inst->fmt_src, and do the same below.
> 
>> +	else if (V4L2_TYPE_IS_CAPTURE(f->type))
>> +		memcpy(f, inst->fmt_dst, sizeof(*f));
>> +	else
>> +		ret = -EINVAL;
>> +
>> +	mutex_unlock(&inst->lock);
>> +
>> +	return ret;
>> +}
>> +
>>  static struct v4l2_file_operations iris_v4l2_file_ops = {
>>  	.owner                          = THIS_MODULE,
>>  	.open                           = iris_open,
>> @@ -231,6 +273,12 @@ static const struct vb2_ops iris_vb2_ops = {
>>  };
>>  
>>  static const struct v4l2_ioctl_ops iris_v4l2_ioctl_ops = {
>> +	.vidioc_try_fmt_vid_cap_mplane  = iris_try_fmt_vid_mplane,
>> +	.vidioc_try_fmt_vid_out_mplane  = iris_try_fmt_vid_mplane,
>> +	.vidioc_s_fmt_vid_cap_mplane    = iris_s_fmt_vid_mplane,
>> +	.vidioc_s_fmt_vid_out_mplane    = iris_s_fmt_vid_mplane,
>> +	.vidioc_g_fmt_vid_cap_mplane    = iris_g_fmt_vid_mplane,
>> +	.vidioc_g_fmt_vid_out_mplane    = iris_g_fmt_vid_mplane,
>>  	.vidioc_reqbufs                 = v4l2_m2m_ioctl_reqbufs,
>>  };
>>  
>>
> 
> Regards,
> 
> 	Hans

  reply	other threads:[~2024-11-13  5:26 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05  6:55 [PATCH v5 00/28] Qualcomm iris video decoder driver Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 01/28] dt-bindings: media: Add video support for QCOM SM8550 SoC Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 02/28] media: iris: add platform driver for iris video device Dikshita Agarwal
2024-11-09 17:32   ` Bryan O'Donoghue
2024-11-13  5:07     ` Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 03/28] media: iris: implement iris v4l2 file ops Dikshita Agarwal
2024-11-10  3:10   ` Bryan O'Donoghue
2024-11-13  5:15     ` Dikshita Agarwal
2024-11-10  3:11   ` Bryan O'Donoghue
2024-11-05  6:55 ` [PATCH v5 04/28] media: iris: introduce iris core state management with shared queues Dikshita Agarwal
2024-11-10 21:37   ` Bryan O'Donoghue
2024-11-14  7:01     ` Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 05/28] media: iris: implement video firmware load/unload Dikshita Agarwal
2024-11-11  9:59   ` Bryan O'Donoghue
2024-11-13  5:20     ` Dikshita Agarwal
2024-11-13 15:56       ` Bryan O'Donoghue
2024-11-14  5:47         ` Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 06/28] media: iris: implement boot sequence of the firmware Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 07/28] imedia: iris: introduce host firmware interface with necessary hooks Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 08/28] media: iris: implement power management Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 09/28] media: iris: implement reqbuf ioctl with vb2_queue_setup Dikshita Agarwal
2024-11-12  9:50   ` Hans Verkuil
2024-11-13  6:19     ` Dikshita Agarwal
2024-11-13  7:48       ` Hans Verkuil
2024-11-13  9:00         ` Dikshita Agarwal
2024-11-13  9:22           ` Hans Verkuil
2024-11-13 10:32             ` Dikshita Agarwal
2024-11-13 11:15               ` Hans Verkuil
2024-11-13 11:20                 ` Dikshita Agarwal
2024-11-13 12:14                   ` Hans Verkuil
2024-11-13 12:44                     ` Dikshita Agarwal
2024-11-13 12:50                       ` Hans Verkuil
2024-11-13 13:05                         ` Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 10/28] media: iris: implement s_fmt, g_fmt and try_fmt ioctls Dikshita Agarwal
2024-11-12 10:18   ` Hans Verkuil
2024-11-13  5:25     ` Dikshita Agarwal [this message]
2024-11-05  6:55 ` [PATCH v5 11/28] media: iris: implement g_selection ioctl Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 12/28] media: iris: implement enum_fmt and enum_frameintervals ioctls Dikshita Agarwal
2024-11-12 10:23   ` Hans Verkuil
2024-11-13  5:27     ` Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 13/28] media: iris: implement subscribe_event and unsubscribe_event ioctls Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 14/28] media: iris: implement iris v4l2_ctrl_ops Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 15/28] media: iris: implement query_cap ioctl Dikshita Agarwal
2024-11-12 10:24   ` Hans Verkuil
2024-11-13  5:27     ` Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 16/28] media: iris: implement vb2 streaming ops Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 17/28] media: iris: implement set properties to firmware during streamon Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 18/28] media: iris: subscribe parameters and properties to firmware for hfi_gen2 Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 19/28] media: iris: allocate, initialize and queue internal buffers Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 20/28] media: iris: implement vb2 ops for buf_queue and firmware response Dikshita Agarwal
2024-11-12 10:49   ` Hans Verkuil
2024-11-13  5:30     ` Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 21/28] media: iris: add support for dynamic resolution change Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 22/28] media: iris: handle streamoff/on from client in " Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 23/28] media: iris: add support for drain sequence Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 24/28] media: iris: add check whether the video session is supported or not Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 25/28] media: iris: implement power scaling for vpu2 and vpu3 Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 26/28] media: iris: add check to allow sub states transitions Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 27/28] media: iris: enable video driver probe of SM8250 SoC Dikshita Agarwal
2024-11-05 14:22   ` Jianhua Lu
2024-11-05 14:34     ` Jianhua Lu
2024-11-13  6:40     ` Dikshita Agarwal
2024-11-05  6:55 ` [PATCH v5 28/28] media: MAINTAINERS: add Qualcomm iris video accelerator driver Dikshita Agarwal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=25bd2b16-35ef-99ee-5b32-7c949cbcaf81@quicinc.com \
    --to=quic_dikshita@quicinc.com \
    --cc=bryan.odonoghue@linaro.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=hverkuil@xs4all.nl \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=lujianhua000@gmail.com \
    --cc=mchehab@kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=nicolas@ndufresne.ca \
    --cc=p.zabel@pengutronix.de \
    --cc=quic_abhinavk@quicinc.com \
    --cc=quic_vgarodia@quicinc.com \
    --cc=quic_vnagar@quicinc.com \
    --cc=robh@kernel.org \
    --cc=sebastian.fricke@collabora.com \
    --cc=u.kleine-koenig@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox