mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Charvi Mehta <charvi.mehta@arm.com>
To: Nicolas Dufresne <nicolas@ndufresne.ca>,
	linux-media@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: 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>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Rathinavel Sankaralingam <rath.sankaralingam@arm.com>,
	Shobhit Pandey <shobhit.pandey@arm.com>
Subject: Re: [RFC PATCH 07/28] media: mali-vpu: implement TRY_FMT and S_FMT ioctls
Date: Mon, 23 Nov 2026 17:26:14 +0000	[thread overview]
Message-ID: <162bf4ec-c23a-49c6-ad7d-7485a5cce2b7@arm.com> (raw)
In-Reply-To: <3415e7b52c3d05214ec125b2b4f8612129c53ae0.camel@ndufresne.ca>


On 11/19/26 20:44, Nicolas Dufresne wrote:
>> +int mali_vpu_fill_pixmp_fmt(const struct mali_vpu_format_desc *fmt,
>> +			    u32 width, u32 height,
>> +			    struct v4l2_pix_format_mplane *pix_mp)
>> +{
>> +	u32 sizeimage;
>> +	int ret;
>> +
>> +	memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved));
>> +	memset(pix_mp->plane_fmt, 0, sizeof(pix_mp->plane_fmt));
>> +	pix_mp->flags = 0;
>> +
>> +	if (fmt->flags & V4L2_FMT_FLAG_COMPRESSED) {
>> +		pix_mp->width = width;
>> +		pix_mp->height = height;
>> +		pix_mp->pixelformat = fmt->fourcc;
>> +		pix_mp->num_planes = 1;
>> +		pix_mp->plane_fmt[0].bytesperline = 0;
>> +
>> +		/*
>> +		 * Use one byte per pixel as the default compressed sizeimage,
>> +		 * with a minimum of one page, aligned to a page boundary.
>> +		 */
>> +		if (check_mul_overflow(width, height, &sizeimage))
>> +			return -EOVERFLOW;
>> +
>> +		sizeimage = max_t(u32, PAGE_SIZE, sizeimage);
>> +
>> +		if (sizeimage > U32_MAX - (PAGE_SIZE - 1))
>> +			return -EOVERFLOW;
> The "moved" code is not exactly identical, and this is not said in the commit
> message. Depending on you max_width/height, this might all be exaggerated.
The checks were intended as defensive handling in a common helper for future
variants. However, given the frame-size constraints applied before this
calculation, they are overly defensive. I’ll remove them and preserve the
original calculation.

>>   
>> -	switch (type) {
>> -	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
>> -		fmt_list = sess->port_src.supported_fmts.fmts;
>> -		num_fmts = sess->port_src.supported_fmts.num_fmts;
>> -		break;
>> -	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
>> -		fmt_list = sess->port_dst.supported_fmts.fmts;
>> -		num_fmts = sess->port_dst.supported_fmts.num_fmts;
>> -		break;
>> -	default:
>> -		return NULL;
>> +	vpu_fmt = mali_vpu_find_format(sess, pix_mp->pixelformat, fmt->type);
>> +	if (!vpu_fmt) {
>> +		port_fmt = mali_vpu_get_port_fmt(sess, fmt->type);
> Maybe it would be better called get_default_port_fmt() ?
This helper actually returns the current port format, and it is also used by
`G_FMT`. On a fresh session that contains the defaults, but it subsequently
contains the negotiated format. I’ll rename it to
`mali_vpu_get_current_port_fmt()` to make that clear.

>> +		if (!port_fmt)
>> +			return -EINVAL;
>> +
>> +		*pix_mp = port_fmt->fmt.pix_mp;
>> +		return 0;
>> +	}
>> +
>> +	/* Requested format found, validate other fields */
>> +	w = pix_mp->width ? pix_mp->width : fmsz->width_default;
>> +	h = pix_mp->height ? pix_mp->height : fmsz->height_default;
> No, width = 0 should return min_width, same for height, just drop, and let the
> below function do that. The default width/height are what you set on a fresh
> session.
Agreed. In v2, I’ll pass the requested width and height directly to
`v4l2_apply_frmsize_constraints()`, and let it adjust zero to the supported
minimum.

>> +
>> +	v4l2_apply_frmsize_constraints(&w, &h, &fmsz->stepwise);
>> +
>> +	/* Decode CAPTURE queue: lock geometry to input if streaming */
>> +	if (sess->role == MALI_VPU_DECODER && fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
>> +		src_q = v4l2_m2m_get_src_vq(sess->m2m_ctx);
>> +		if (vb2_is_streaming(src_q)) {
>> +			port_fmt_dec = &sess->port_src.curr_fmt;
>> +			w = port_fmt_dec->fmt.pix_mp.width;
>> +			h = port_fmt_dec->fmt.pix_mp.height;
>> +		}
> This is try_fmt, it should not care if you are streaming or not.
The intention was to use the parsed CAPTURE dimensions once available, but
OUTPUT streaming does not guarantee that parsing has completed. I’ll track
whether firmware has supplied the parameters instead I'll keep the 
adjustment
logic shared with `S_FMT`, so both return the same format for the same
request and known stream parameters.

>> +	}
>> +
>> +	ret = mali_vpu_fill_pixmp_fmt(vpu_fmt, w, h, pix_mp);
>> +	if (ret)
>> +		return ret;
>> +
>> +	if (pix_mp->field == V4L2_FIELD_ANY)
>> +		pix_mp->field = V4L2_FIELD_NONE;
> Well, only if you support interlaced.
Since I’m adding interlaced decoding support in v2, I’ll normalize 
`field` to
`V4L2_FIELD_NONE` on the compressed OUTPUT queue and derive the CAPTURE 
field
layout from the stream information reported by firmware.

>> +static int mali_vpu_try_fmt(struct file *filp, void *fh, struct v4l2_format *fmt)
>> +{
>> +	struct mali_vpu_session *sess = mali_vpu_get_session(filp);
>> +	int ret;
>> +
>> +	mutex_lock(&sess->vq_lock);
> This is suspicious, the vb queue already do some locking in most of the vidioc
> call.
Both queues assign `&sess->vq_lock` to `vb2_queue::lock`, but 
`video_device::lock`
is unset. The V4L2 core acquires it for queue-management ioctls marked
INFO_FL_QUEUE, but not for G_FMT, TRY_FMT or S_FMT.

video_device::lock is unset, as this driver uses per-session locking and
format ioctls are not required to be serialized among different sessions.
The explicit locks therefore protect format access against queue operations
and asynchronous firmware updates, which use the same mutex. They do not
reacquire a lock already held by the ioctl core.


Regards,
Charvi

  reply	other threads:[~2026-11-23 17:26 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 15:37 [RFC PATCH 00/28] media: add arm Mali-V76 video decoder driver Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 01/28] dt-bindings: media: add Arm Mali-V76 VPU Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 02/28] media: mali-vpu: add Mali VPU platform driver Charvi Mehta
2026-11-19 20:04   ` Nicolas Dufresne
2026-11-20 11:48   ` Uwe Kleine-König
2026-11-19 15:37 ` [RFC PATCH 03/28] media: mali-vpu: register V4L2 decoder device and add querycap ioctl Charvi Mehta
2026-11-19 20:10   ` Nicolas Dufresne
2026-11-19 15:37 ` [RFC PATCH 04/28] media: mali-vpu: initialize decoder format state Charvi Mehta
2026-11-19 20:30   ` Nicolas Dufresne
2026-11-19 15:37 ` [RFC PATCH 05/28] media: mali-vpu: add V4L2 mem2mem and VB2 queue support Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 06/28] media: mali-vpu: implement format query ioctls Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 07/28] media: mali-vpu: implement TRY_FMT and S_FMT ioctls Charvi Mehta
2026-11-19 20:44   ` Nicolas Dufresne
2026-11-23 17:26     ` Charvi Mehta [this message]
2026-11-19 15:37 ` [RFC PATCH 08/28] media: mali-vpu: register V76 decoder controls and introduce UAPI controls Charvi Mehta
2026-11-19 21:06   ` Nicolas Dufresne
2026-11-19 15:37 ` [RFC PATCH 09/28] media: mali-vpu: add MMU software page table manager Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 10/28] media: mali-vpu: add firmware cache infrastructure Charvi Mehta
2026-11-19 21:34   ` Nicolas Dufresne
2026-11-19 15:37 ` [RFC PATCH 11/28] media: mali-vpu: load firmware for decoder sessions Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 12/28] media: mali-vpu: prepare firmware address space Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 13/28] media: mali-vpu: add firmware message transport Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 14/28] media: mali-vpu: route decoder controls to firmware Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 15/28] media: mali-vpu: handle firmware RPC requests Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 16/28] media: mali-vpu: add LSID hardware support Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 17/28] media: mali-vpu: add single session scheduler Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 18/28] media: mali-vpu: handle firmware interrupts Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 19/28] media: mali-vpu: start decoder firmware through LSID scheduling Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 20/28] media: mali-vpu: implement vb2 buffer queue handling Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 21/28] media: mali-vpu: handle firmware buffer exchange Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 22/28] media: mali-vpu: handle fatal firmware error Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 23/28] media: mali-vpu: propagate buffer metadata Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 24/28] media: mali-vpu: add decoder EOS and DRC handling Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 25/28] media: mali-vpu: handle firmware buffer parameters Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 26/28] media: mali-vpu: handle firmware event responses Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 27/28] media: mali-vpu: add stateful decoder state machine Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 28/28] media: MAINTAINERS: add Arm Mali-V76 VPU driver Charvi Mehta
2026-11-19 19:44 ` [RFC PATCH 00/28] media: add arm Mali-V76 video decoder driver Nicolas Dufresne
2026-11-23 15:57   ` Charvi Mehta

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=162bf4ec-c23a-49c6-ad7d-7485a5cce2b7@arm.com \
    --to=charvi.mehta@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=nicolas@ndufresne.ca \
    --cc=p.zabel@pengutronix.de \
    --cc=rath.sankaralingam@arm.com \
    --cc=robh@kernel.org \
    --cc=shobhit.pandey@arm.com \
    --cc=vincenzo.frascino@arm.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

all inboxes | Powered by JetHome®