From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Cc: Daniel Scally <dan.scally@ideasonboard.com>,
linux-media@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, Anthony.McGivern@arm.com,
nayden.kanchev@arm.com, robh+dt@kernel.org, mchehab@kernel.org,
krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
jerome.forissier@linaro.org, kieran.bingham@ideasonboard.com,
laurent.pinchart@ideasonboard.com
Subject: Re: [PATCH v10 16/17] media: platform: Add mali-c55 parameters video node
Date: Mon, 30 Jun 2025 17:52:49 +0300 [thread overview]
Message-ID: <aGKkwXjQH0H1ghG1@svinhufvud> (raw)
In-Reply-To: <5zbhnrplppbnrapyvcz2pviavbwsmqy5reofmkas7ouil5o6mr@62xlfol4ld7d>
Hi Jacopo,
On Mon, Jun 30, 2025 at 03:59:42PM +0200, Jacopo Mondi wrote:
> Hi Sakari, Dan
> >
> > On 6/24/25 13:21, Daniel Scally wrote:
> > > +static void mali_c55_params_buf_queue(struct vb2_buffer *vb)
> > > +{
> > > + struct mali_c55_params *params = vb2_get_drv_priv(vb->vb2_queue);
> > > + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
> > > + struct mali_c55_params_buf *buf = to_mali_c55_params_buf(vbuf);
> > > + struct mali_c55 *mali_c55 = params->mali_c55;
> > > + struct mali_c55_params_buffer *config;
> > > + struct list_head *queue;
> > > + size_t block_offset = 0;
> > > + size_t max_offset;
> > > +
> > > + /*
> > > + * Before accepting the buffer we should check that the data within it
> > > + * is valid.
> > > + */
> > > + config = vb2_plane_vaddr(vb, 0);
> > > +
> > > + if (config->total_size > MALI_C55_PARAMS_MAX_SIZE) {
> > > + dev_dbg(mali_c55->dev, "Invalid parameters buffer size %u\n",
> > > + config->total_size);
> > > + goto err_buffer_done;
> > > + }
> > > +
> > > + /* Currently only v1 is supported */
> > > + if (config->version != MALI_C55_PARAM_BUFFER_V1) {
> > > + dev_dbg(mali_c55->dev, "Invalid parameters version\n");
> > > + goto err_buffer_done;
> > > + }
> > > +
> > > + max_offset = config->total_size - sizeof(struct mali_c55_params_block_header);
> > > + while (block_offset < max_offset) {
> > > + const struct mali_c55_block_handler *block_handler;
> > > + union mali_c55_params_block block;
> > > +
> > > + block = (union mali_c55_params_block)
> > > + &config->data[block_offset];
> > > +
> > > + if (block.header->type >= ARRAY_SIZE(mali_c55_block_handlers)) {
> > > + dev_dbg(mali_c55->dev, "Invalid parameters block type\n");
> > > + goto err_buffer_done;
> > > + }
> > > +
> > > + if (block_offset + block.header->size > config->total_size) {
> > > + dev_dbg(mali_c55->dev, "Parameters block too large\n");
> > > + goto err_buffer_done;
> > > + }
> > > +
> > > + block_handler = &mali_c55_block_handlers[block.header->type];
> > > +
> > > + /*
> > > + * Userspace can optionally omit all but the header of a block
> > > + * if it only intends to disable the block.
> > > + */
> > > + if (block.header->size != block_handler->size &&
> > > + block.header->size != sizeof(*block.header)) {
> > > + dev_dbg(mali_c55->dev, "Invalid parameters block size\n");
> > > + goto err_buffer_done;
> > > + }
> > > +
> > > + block_offset += block.header->size;
> >
> > I recall discussing with Jacopo in the context of another ISP driver
> > (Rockchip?) that this piece of non-trivial code should make it into the
>
> I think it was in the context of the recent Amlogic C3 ISP review
>
> and yes, c3_isp_params_vb2_buf_prepare() and
> rkisp1_params_prepare_ext_params() are identical.
>
> The here introduced mali_c55_params_buf_queue() is indeed very
> similar (*). I guess it has been developed before the RkISP1
> implementation (from which the Amlogic one was copied) was refined.
>
> *) The Mali C55 implementation happens at .buf_queue time and not at
> .buf_prepare time, not sure if it's intentional (and doesn't probably
> make much difference anyway). It also copies the parameters buffer
> -after- having validated the content, creating a tiny window between
> validation and copy where userspace can modify the buffer, Very
> unlikely but possible.
>
> Understanding if the rkisp1/c3 routines can be copied in the mali c55
> implementation would make sure that yes, we should defintely move the
> validation to the core.
>
>
> > framework side before a next driver using it has been added. What's the
> > status of that? Same for other related bits.
> >
>
> Yes, three users (if confirmed that mali can use the same validation
> code as the other two) are enough as indication we should move this to
> the framework. Problem is how to better design this.
>
> My first thought would be to provide a .buf_prepare helper specific
> for extensible parameters that drivers can use. It would however need
> to receive some configuration parameters the validation code would
> need to know about: the version flags, the enable/disable flags, the
> expected sizes etc
>
> Looking at other parts of the code that could be facotrized out,
> indeed the rkisp1_ext_params_config() and c3_isp_params_cfg_blocks()
> functions are very similar. The RkISP1 is a bit more complex
> (supports 'group' and 'features') and the handlers function
> signatures are slightly different. With some type punning and macro
> magic I'm sure we could factorize t out as well, but I would indeed
> start with validation...
>
> Time for a drivers/media/v4l2-core/v4l2_extensible_params.c ?
I'd call this v4l2-params.c or something alike. Feel free to post an RFC.
:-)
If there are details that require different handling, it's possible to
have callbacks as well.
--
Kind regards,
Sakari Ailus
next prev parent reply other threads:[~2025-06-30 14:52 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-24 10:21 [PATCH v10 00/17] Add Arm Mali-C55 Image Signal Processor Driver Daniel Scally
2025-06-24 10:21 ` [PATCH v10 01/17] media: uapi: Add MEDIA_BUS_FMT_RGB202020_1X60 format code Daniel Scally
2025-06-24 10:21 ` [PATCH v10 02/17] media: uapi: Add 20-bit bayer formats Daniel Scally
2025-06-24 10:21 ` [PATCH v10 03/17] media: v4l2-common: Add RAW16 format info Daniel Scally
2025-06-24 10:21 ` [PATCH v10 04/17] media: v4l2-common: Add RAW14 " Daniel Scally
2025-06-24 10:21 ` [PATCH v10 05/17] dt-bindings: media: Add bindings for ARM mali-c55 Daniel Scally
2025-06-25 3:27 ` Rob Herring
2025-06-25 9:05 ` Krzysztof Kozlowski
2025-06-25 9:08 ` Krzysztof Kozlowski
2025-06-25 9:46 ` Dan Scally
2025-07-10 15:19 ` Dan Scally
2025-06-24 10:21 ` [PATCH v10 06/17] media: uapi: Add controls for Mali-C55 ISP Daniel Scally
2025-06-28 19:29 ` Sakari Ailus
2025-06-24 10:21 ` [PATCH v10 07/17] media: mali-c55: Add Mali-C55 ISP driver Daniel Scally
2025-06-28 20:06 ` Sakari Ailus
2025-06-29 18:35 ` Laurent Pinchart
2025-06-30 7:37 ` Sakari Ailus
2025-06-30 8:35 ` Laurent Pinchart
2025-06-30 10:16 ` Dan Scally
2025-06-30 10:29 ` Sakari Ailus
2025-06-30 10:14 ` Dan Scally
2025-06-24 10:21 ` [PATCH v10 08/17] media: Documentation: Add Mali-C55 ISP Documentation Daniel Scally
2025-06-24 10:21 ` [PATCH v10 09/17] MAINTAINERS: Add entry for mali-c55 driver Daniel Scally
2025-06-24 10:21 ` [PATCH v10 10/17] media: Add MALI_C55_3A_STATS meta format Daniel Scally
2025-06-24 10:21 ` [PATCH v10 11/17] media: uapi: Add 3a stats buffer for mali-c55 Daniel Scally
2025-06-24 10:21 ` [PATCH v10 12/17] media: platform: Add mali-c55 3a stats devnode Daniel Scally
2025-06-24 10:21 ` [PATCH v10 13/17] Documentation: mali-c55: Add Statistics documentation Daniel Scally
2025-06-24 10:21 ` [PATCH v10 14/17] media: mali-c55: Add image formats for Mali-C55 parameters buffer Daniel Scally
2025-06-24 10:21 ` [PATCH v10 15/17] media: uapi: Add parameters structs to mali-c55-config.h Daniel Scally
2025-06-24 10:21 ` [PATCH v10 16/17] media: platform: Add mali-c55 parameters video node Daniel Scally
2025-06-29 11:27 ` Sakari Ailus
2025-06-30 10:40 ` Dan Scally
2025-06-30 13:59 ` Jacopo Mondi
2025-06-30 14:52 ` Sakari Ailus [this message]
2025-06-24 10:21 ` [PATCH v10 17/17] Documentation: mali-c55: Document the mali-c55 parameter setting Daniel Scally
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=aGKkwXjQH0H1ghG1@svinhufvud \
--to=sakari.ailus@linux.intel.com \
--cc=Anthony.McGivern@arm.com \
--cc=conor+dt@kernel.org \
--cc=dan.scally@ideasonboard.com \
--cc=devicetree@vger.kernel.org \
--cc=jacopo.mondi@ideasonboard.com \
--cc=jerome.forissier@linaro.org \
--cc=kieran.bingham@ideasonboard.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=nayden.kanchev@arm.com \
--cc=robh+dt@kernel.org \
/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