From: Michael Riesch <michael.riesch@collabora.com>
To: Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Kieran Bingham <kieran.bingham@ideasonboard.com>,
Nicolas Dufresne <nicolas.dufresne@collabora.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Tomasz Figa <tfiga@chromium.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Raspberry Pi Kernel Maintenance <kernel-list@raspberrypi.com>,
Florian Fainelli <florian.fainelli@broadcom.com>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
Hans Verkuil <hverkuil@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
linux-rpi-kernel@lists.infradead.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 03/27] media: media-entity: Introduce media_entity_context
Date: Wed, 1 Oct 2025 21:45:16 +0200 [thread overview]
Message-ID: <9f1dbc4d-d4c7-4c1c-b48a-355a83e18e5c@collabora.com> (raw)
In-Reply-To: <20250724-multicontext-mainline-2025-v2-3-c9b316773486@ideasonboard.com>
Hi Jacopo,
Thanks for your patch. Looks good to me, but found a few typos.
On 7/24/25 16:10, Jacopo Mondi wrote:
> Introduce the 'struct media_entity_context' type, which serves for
> reference counting and introduce two new media entity operations to
> allow drivers to allocate and free a media entity context.
>
> The newly introduced type will be used as a base type for the
> device context types (video_device_context and v4l2_subdevice_context)
> that will be introduced in the next patches.
>
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> ---
> drivers/media/mc/mc-entity.c | 46 ++++++++++++++++++++
> include/media/media-entity.h | 101 +++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 147 insertions(+)
>
> diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
> index 045590905582054c46656e20463271b1f93fa6b4..b4a9f0a0aa7353d7a3333f20903980956b3df4a7 100644
> --- a/drivers/media/mc/mc-entity.c
> +++ b/drivers/media/mc/mc-entity.c
> @@ -1673,3 +1673,49 @@ struct media_link *__media_entity_next_link(struct media_entity *entity,
> return NULL;
> }
> EXPORT_SYMBOL_GPL(__media_entity_next_link);
> +
> +static void media_entity_release_context(struct kref *refcount)
> +{
> + struct media_entity_context *ctx =
> + container_of(refcount, struct media_entity_context, refcount);
> +
> + ctx->entity->ops->destroy_context(ctx);
> +}
> +
> +struct media_entity_context *
> +media_entity_context_get(struct media_entity_context *ctx)
> +{
> + if (!ctx)
> + return ERR_PTR(-EINVAL);
> +
> + kref_get(&ctx->refcount);
> +
> + return ctx;
> +}
> +EXPORT_SYMBOL_GPL(media_entity_context_get);
> +
> +void media_entity_context_put(struct media_entity_context *ctx)
> +{
> + if (!ctx)
> + return;
> +
> + kref_put(&ctx->refcount, media_entity_release_context);
> +}
> +EXPORT_SYMBOL_GPL(media_entity_context_put);
> +
> +void media_entity_init_context(struct media_entity *entity,
> + struct media_entity_context *ctx)
> +{
> + if (!ctx)
> + return;
> +
> + ctx->entity = entity;
> + kref_init(&ctx->refcount);
> + INIT_LIST_HEAD(&ctx->list);
> +}
> +EXPORT_SYMBOL_GPL(media_entity_init_context);
> +
> +void media_entity_cleanup_context(struct media_entity_context *ctx)
> +{
> +}
> +EXPORT_SYMBOL_GPL(media_entity_cleanup_context);
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 64cf590b11343f68a456c5870ca2f32917c122f9..32298fe8a18c6ee3c1dbcff9ef869548904417a7 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -15,6 +15,7 @@
> #include <linux/bug.h>
> #include <linux/container_of.h>
> #include <linux/fwnode.h>
> +#include <linux/kref.h>
> #include <linux/list.h>
> #include <linux/media.h>
> #include <linux/minmax.h>
> @@ -248,6 +249,37 @@ struct media_pad {
> struct media_pipeline *pipe;
> };
>
> +/**
> + * struct media_entity_context - A media entity execution context
> + * @mdev_context: The media device context this media entity is bound to.
> + * The field is initialized when the entity is bound to a media
> + * device context.
> + * @entity: The media entity this context belongs to
> + * @refcount: The kref reference counter
> + * list: The list entry to link the entity context in the media device context
> + *
> + * This type represent the 'base class' used to implement execution context for
> + * video device contexts and subdevice contexts. Those types embedds an instance
Typo 'embedds' -> 'embed'?
> + * of 'struct media_entity_context' as their first member, allowing the MC core
> + * to implement type polymorphism and handle video device and subdevice contexts
> + * transparently.
> + *
> + * The main function of this type is to provide reference counting for the
> + * 'dervived' device context types. The video device and subdevice core
Typo 'dervived' -> 'derived'?
> + * populates the 'context_release' function pointer that implement specific
> + * clean-up operations, similar to what a 'virtual destructor' would do in C++.
> + *
> + * Drivers are not expected to use this type directly, but only the MC core
> + * will.
> + */
> +struct media_device_context;
> +struct media_entity_context {
> + struct media_device_context *mdev_context;
> + struct media_entity *entity;
> + struct kref refcount;
> + struct list_head list;
> +};
> +
> /**
> * struct media_entity_operations - Media entity operations
> * @get_fwnode_pad: Return the pad number based on a fwnode endpoint or
> @@ -269,6 +301,15 @@ struct media_pad {
> * media_entity_has_pad_interdep().
> * Optional: If the operation isn't implemented all pads
> * will be considered as interdependent.
> + * @alloc_context: Allocate a media entity context. Drivers are allowed to
> + * sub-class the entity context type by defining a driver
> + * specific type that embeds an instance of either a
> + * video_device_context or subdevice_context as first
> + * member, and allocate the size of a driver-specific type
> + * in the implementation of this operation. Returns 0 for
> + * success, or an error code < 0 otherwise.
> + * @destroy_context: Release a media entity context previously allocated by
> + * the driver.
> *
> * .. note::
> *
> @@ -284,6 +325,9 @@ struct media_entity_operations {
> int (*link_validate)(struct media_link *link);
> bool (*has_pad_interdep)(struct media_entity *entity, unsigned int pad0,
> unsigned int pad1);
> + int (*alloc_context)(struct media_entity *entity,
> + struct media_entity_context **context);
> + void (*destroy_context)(struct media_entity_context *context);
> };
>
> /**
> @@ -1448,3 +1492,60 @@ struct media_link *__media_entity_next_link(struct media_entity *entity,
> MEDIA_LNK_FL_DATA_LINK))
>
> #endif
> +
> +/**
> + * media_entity_context_get - Increase the media entity context reference count
> + * and return a reference to it
> + *
> + * @ctx: the media entity context
> + *
> + * Increase the media entity context reference count. The reference count
> + * is increased by the V4L2 core when:
> + *
> + * * a new context is allocated when bounding a media entity to a media device
> + * context (by kref_init())
> + * * the media pipeline the context is part of starts streaming
> + *
> + * The entity context gets automatically decreased by the V4L2 core when:
> + *
> + * * a context is unbound
> + * * the pipeline stops streaming
> + */
> +struct media_entity_context *
> +media_entity_context_get(struct media_entity_context *ctx);
> +
> +/**
> + * media_entity_context_put - Decrease the media entity context reference count
> + *
> + * @ctx: the media entity context
> + *
> + * Decrease the media entity context reference count. The reference count
> + * is decreased by the V4L2 core when:
> + *
> + * * the file handle the context is associated with is closed
> + * * the media pipeline the context is part of is stopped
> + */
> +void media_entity_context_put(struct media_entity_context *ctx);
> +
> +/**
> + * media_entity_init_context - Initialize the media entity context
> + *
> + * @entity: the media entity this context belongs to
> + * @ctx: the media entity context
> + *
> + * Initialize the media entity context by initializing the kref reference
> + * counter. The intended caller of this function are the video device context
> + * and subdevic context initialize functions.
Typo "subdevic" -> "subdevice"
> + */
> +void media_entity_init_context(struct media_entity *entity,
> + struct media_entity_context *ctx);
> +
> +/**
> + * media_entity_cleanup_context - Cleanup the media entity context
> + *
> + * @ctx: the media entity context
> + *
> + * Cleanup the media entity context. The intended caller of this function are
> + * the video device and subdevice context cleanup functions.
> + */
> +void media_entity_cleanup_context(struct media_entity_context *ctx);
>
Best regards,
Michael
next prev parent reply other threads:[~2025-10-01 19:45 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-24 14:10 [PATCH v2 00/27] media: Add support for multi-context operations Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 01/27] media: mc: Add per-file-handle data support Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 02/27] media: mc: Maintain a list of open file handles in a media device Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 03/27] media: media-entity: Introduce media_entity_context Jacopo Mondi
2025-10-01 19:45 ` Michael Riesch [this message]
2025-07-24 14:10 ` [PATCH v2 04/27] media: media-device: Introduce media device context Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 05/27] media: v4l2-dev: Introduce video " Jacopo Mondi
2026-08-20 16:51 ` John Cox
2025-07-24 14:10 ` [PATCH v2 06/27] media: v4l2-ioctl: Introduce VIDIOC_BIND_CONTEXT Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 07/27] media: Documentation: Add VIDIOC_BIND_CONTEXT Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 08/27] media: v4l2-dev: Introduce default contexts Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 09/27] media: v4l2-dev: Add video_device_context_from_file() Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 10/27] media: v4l2-dev: Add video_device_context_from_queue() Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 11/27] media: videobuf2-v4l2: Support vb2_queue embedded in a context Jacopo Mondi
2026-08-20 16:31 ` John Cox
2025-07-24 14:10 ` [PATCH v2 12/27] media: v4l2-subdev: Introduce v4l2 subdev context Jacopo Mondi
2025-09-25 10:55 ` Anthony McGivern
2026-08-20 16:47 ` John Cox
2025-07-24 14:10 ` [PATCH v2 13/27] media: v4l2-subdev: Introduce VIDIOC_SUBDEV_BIND_CONTEXT Jacopo Mondi
2026-08-20 16:23 ` John Cox
2025-07-24 14:10 ` [PATCH v2 14/27] media: Documentation: Add VIDIOC_SUBDEV_BIND_CONTEXT Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 15/27] media: v4l2_subdev: Introduce default context Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 16/27] media: v4l2-subdev: Add subdev state accessor helpers Jacopo Mondi
2026-08-20 16:35 ` John Cox
2025-07-24 14:10 ` [PATCH v2 17/27] media: v4l2-subdev: Get state from context Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 18/27] media: media-entity: Support context in pipeline_start Jacopo Mondi
2026-08-20 16:10 ` John Cox
2025-07-24 14:10 ` [PATCH v2 19/27] media: mc-entity: Add link_validate_context Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 20/27] media: v4l2-subdev: Validate media links with context Jacopo Mondi
2025-07-24 14:10 ` [PATCH v2 21/27] media: uapi: Add 'flags' to media_device_info Jacopo Mondi
2025-07-24 14:10 ` [PATCH DNI v2 22/27] media: pisp_be: Start and stop the media pipeline Jacopo Mondi
2025-07-24 14:10 ` [PATCH DNI v2 23/27] media: pisp_be: Add support for subdev state Jacopo Mondi
2025-07-24 14:10 ` [PATCH DNI v2 24/27] media: pisp_be: Implement set/get_pad_fmt Jacopo Mondi
2025-07-24 14:10 ` [PATCH DNI v2 25/27] media: pisp_be: Implement link validation Jacopo Mondi
2025-07-24 14:10 ` [PATCH DNI v2 26/27] media: pisp_be: Register devnode to userspace Jacopo Mondi
2025-07-24 14:10 ` [PATCH DNI v2 27/27] media: pisp_be: Add support for multi-context Jacopo Mondi
2026-08-20 16:09 ` [PATCH v2 00/27] media: Add support for multi-context operations John Cox
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=9f1dbc4d-d4c7-4c1c-b48a-355a83e18e5c@collabora.com \
--to=michael.riesch@collabora.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=florian.fainelli@broadcom.com \
--cc=hverkuil@kernel.org \
--cc=jacopo.mondi@ideasonboard.com \
--cc=kernel-list@raspberrypi.com \
--cc=kieran.bingham@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=sakari.ailus@linux.intel.com \
--cc=tfiga@chromium.org \
--cc=tomi.valkeinen@ideasonboard.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