From: Frank Li <Frank.li@nxp.com>
To: ming.qian@oss.nxp.com
Cc: linux-media@vger.kernel.org, mchehab@kernel.org,
hverkuil-cisco@xs4all.nl, nicolas@ndufresne.ca,
benjamin.gaignard@collabora.com, p.zabel@pengutronix.de,
sebastian.fricke@collabora.com, shawnguo@kernel.org,
ulf.hansson@linaro.org, s.hauer@pengutronix.de,
kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com,
l.stach@pengutronix.de, peng.fan@nxp.com, eagle.zhou@nxp.com,
imx@lists.linux.dev, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v3 1/3] media: v4l2-mem2mem: Add a kref to the v4l2_m2m_dev structure
Date: Thu, 4 Dec 2025 12:23:21 -0500 [thread overview]
Message-ID: <aTHDiVI6ZB3E7Anh@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20251204090813.595-1-ming.qian@oss.nxp.com>
On Thu, Dec 04, 2025 at 05:08:09PM +0800, ming.qian@oss.nxp.com wrote:
> From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
>
> Adding a reference count to the v4l2_m2m_dev structure allow safely
> sharing it across multiple hardware nodes. This can be used to prevent
> running jobs concurrently on m2m cores that have some internal resource
> sharing.
>
> Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Also need your s-o-b, or just said refer to other thread if it already
posted.
Frank
> ---
> drivers/media/v4l2-core/v4l2-mem2mem.c | 23 +++++++++++++++++++++++
> include/media/v4l2-mem2mem.h | 21 +++++++++++++++++++++
> 2 files changed, 44 insertions(+)
>
> diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
> index fec93c1a9231..ae0de54d4c3e 100644
> --- a/drivers/media/v4l2-core/v4l2-mem2mem.c
> +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
> @@ -90,6 +90,7 @@ static const char * const m2m_entity_name[] = {
> * @job_work: worker to run queued jobs.
> * @job_queue_flags: flags of the queue status, %QUEUE_PAUSED.
> * @m2m_ops: driver callbacks
> + * @kref: device reference count
> */
> struct v4l2_m2m_dev {
> struct v4l2_m2m_ctx *curr_ctx;
> @@ -109,6 +110,8 @@ struct v4l2_m2m_dev {
> unsigned long job_queue_flags;
>
> const struct v4l2_m2m_ops *m2m_ops;
> +
> + struct kref kref;
> };
>
> static struct v4l2_m2m_queue_ctx *get_queue_ctx(struct v4l2_m2m_ctx *m2m_ctx,
> @@ -1200,6 +1203,7 @@ struct v4l2_m2m_dev *v4l2_m2m_init(const struct v4l2_m2m_ops *m2m_ops)
> INIT_LIST_HEAD(&m2m_dev->job_queue);
> spin_lock_init(&m2m_dev->job_spinlock);
> INIT_WORK(&m2m_dev->job_work, v4l2_m2m_device_run_work);
> + kref_init(&m2m_dev->kref);
>
> return m2m_dev;
> }
> @@ -1211,6 +1215,25 @@ void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev)
> }
> EXPORT_SYMBOL_GPL(v4l2_m2m_release);
>
> +void v4l2_m2m_get(struct v4l2_m2m_dev *m2m_dev)
> +{
> + kref_get(&m2m_dev->kref);
> +}
> +EXPORT_SYMBOL_GPL(v4l2_m2m_get);
> +
> +static void v4l2_m2m_release_from_kref(struct kref *kref)
> +{
> + struct v4l2_m2m_dev *m2m_dev = container_of(kref, struct v4l2_m2m_dev, kref);
> +
> + v4l2_m2m_release(m2m_dev);
> +}
> +
> +void v4l2_m2m_put(struct v4l2_m2m_dev *m2m_dev)
> +{
> + kref_put(&m2m_dev->kref, v4l2_m2m_release_from_kref);
> +}
> +EXPORT_SYMBOL_GPL(v4l2_m2m_put);
> +
> struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(struct v4l2_m2m_dev *m2m_dev,
> void *drv_priv,
> int (*queue_init)(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq))
> diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h
> index bf6a09a04dcf..ca295c660c7f 100644
> --- a/include/media/v4l2-mem2mem.h
> +++ b/include/media/v4l2-mem2mem.h
> @@ -547,6 +547,27 @@ v4l2_m2m_register_media_controller(struct v4l2_m2m_dev *m2m_dev,
> */
> void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev);
>
> +/**
> + * v4l2_m2m_get() - take a reference to the m2m_dev structure
> + *
> + * @m2m_dev: opaque pointer to the internal data to handle M2M context
> + *
> + * This is used to share the M2M device across multiple devices. This
> + * can be used to avoid scheduling two hardware nodes concurrently.
> + */
> +void v4l2_m2m_get(struct v4l2_m2m_dev *m2m_dev);
> +
> +/**
> + * v4l2_m2m_put() - remove a reference to the m2m_dev structure
> + *
> + * @m2m_dev: opaque pointer to the internal data to handle M2M context
> + *
> + * Once the M2M device have no more references, v4l2_m2m_realse() will be
> + * called automatically. Users of this method should never call
> + * v4l2_m2m_release() directly. See v4l2_m2m_get() for more details.
> + */
> +void v4l2_m2m_put(struct v4l2_m2m_dev *m2m_dev);
> +
> /**
> * v4l2_m2m_ctx_init() - allocate and initialize a m2m context
> *
> --
> 2.52.0
>
prev parent reply other threads:[~2025-12-04 17:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-04 9:08 [PATCH v3 1/3] media: v4l2-mem2mem: Add a kref to the v4l2_m2m_dev structure ming.qian
2025-12-04 9:08 ` [PATCH v3 2/3] pmdomain: imx8m-blk-ctrl: Remove separate rst and clk mask for 8mq vpu ming.qian
2025-12-04 17:24 ` Frank Li
2025-12-04 9:08 ` [PATCH v3 3/3] media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC ming.qian
2025-12-04 17:34 ` Frank Li
2025-12-04 18:15 ` Nicolas Dufresne
2025-12-04 22:57 ` Frank Li
2025-12-05 0:05 ` Nicolas Dufresne
2025-12-05 15:07 ` Frank Li
2025-12-04 17:23 ` Frank Li [this message]
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=aTHDiVI6ZB3E7Anh@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=benjamin.gaignard@collabora.com \
--cc=eagle.zhou@nxp.com \
--cc=festevam@gmail.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=l.stach@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=ming.qian@oss.nxp.com \
--cc=nicolas@ndufresne.ca \
--cc=p.zabel@pengutronix.de \
--cc=peng.fan@nxp.com \
--cc=s.hauer@pengutronix.de \
--cc=sebastian.fricke@collabora.com \
--cc=shawnguo@kernel.org \
--cc=ulf.hansson@linaro.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