Fix concurrency issues between G1 and G2 on
v4 cover Fix concurrency issues between G1 and G2 on
From: Ming Qian <[email protected]>
On the i.MX8MQ, we encountered some concurrency issues with H264 and HEVC decoding.
There are two main reasons:
1. The vpu blk-ctrl don't have separate reset and clock enable bits.
2. The g1 VPU and g2 VPU cannot decode simultaneously.
We attempted to make corresponding fix to address these two issues.
Ming Qian (2):
pmdomain: imx8m-blk-ctrl: Remove separate rst and clk mask for 8mq vpu
media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC
Nicolas Dufresne (1):
media: v4l2-mem2mem: Add a kref to the v4l2_m2m_dev structure
drivers/media/platform/verisilicon/hantro.h | 2 + .../media/platform/verisilicon/hantro_drv.c | 42 +++++++++++++++++-- .../media/platform/verisilicon/imx8m_vpu_hw.c | 8 ++++ drivers/media/v4l2-core/v4l2-mem2mem.c | 23 ++++++++++ drivers/pmdomain/imx/imx8m-blk-ctrl.c | 11 +++-- include/media/v4l2-mem2mem.h | 21 ++++++++++ 6 files changed, 100 insertions(+), 7 deletions(-)
Signature · 1 line
2.52.0
PATCH v4 1/3 media: v4l2-mem2mem: Add a kref to the v4l2_m2m_dev structure
From: Nicolas Dufresne <[email protected]>
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.
---
v4
- Add my Signed-off-by
drivers/media/v4l2-core/v4l2-mem2mem.c | 23 +++++++++++++++++++++++ include/media/v4l2-mem2mem.h | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+)
drivers/media/v4l2-core/v4l2-mem2mem.c +23 -0
@@ -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))
include/media/v4l2-mem2mem.h +21 -0
@@ -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 *
Signature · 1 line
2.52.0
Re: [PATCH v4 1/3] media: v4l2-mem2mem: Add a kref to the v4l2_m2m_dev structure
Quoted 10 lines · On Fri, Dec 05, 2025 at 09:54:24AM +0800, [email protected] wrote:
From: Nicolas Dufresne <[email protected]>
Adding a reference count to the
v4l2_m2m_devstructure 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 <[email protected]>Signed-off-by Ming Qian <[email protected]>---
Quoted 97 lines
v4
- Add my Signed-off-bydrivers/media/v4l2-core/v4l2-mem2mem.c | 23 +++++++++++++++++++++++ include/media/v4l2-mem2mem.h | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+)drivers/media/v4l2-core/v4l2-mem2mem.c +23
-0@@ -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))include/media/v4l2-mem2mem.h +21
-1@@ -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
Re: [PATCH v4 1/3] media: v4l2-mem2mem: Add a kref to the v4l2_m2m_dev structure
In reply to [email protected]Quoted 10 lines · On Fri, 5 Dec 2025 at 02:55, <[email protected]> wrote:
From: Nicolas Dufresne <[email protected]>
Adding a reference count to the
v4l2_m2m_devstructure 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 <[email protected]>Signed-off-by Ming Qian <[email protected]>
I certainly don't have the complete picture for how this needs to work.
However, I was thinking that rather than using a kref and having to share two specific functions to update it (v4l2_m2m_get|put), couldn't we just use a device-link instead?
Kind regards
Uffe
Quoted 98 lines
---
v4
- Add my Signed-off-bydrivers/media/v4l2-core/v4l2-mem2mem.c | 23 +++++++++++++++++++++++ include/media/v4l2-mem2mem.h | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+)drivers/media/v4l2-core/v4l2-mem2mem.c +23
-0@@ -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))include/media/v4l2-mem2mem.h +21
-1@@ -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
Re: [PATCH v4 1/3] media: v4l2-mem2mem: Add a kref to the v4l2_m2m_dev structure
Hi,
Le mardi 30 décembre 2025 à 14:39 +0100, Ulf Hansson a écrit :
Quoted 9 lines · On Fri, 5 Dec 2025 at 02:55, <[email protected]> wrote:
Quoted 8 lines
From: Nicolas Dufresne <[email protected]>
Adding a reference count to the
v4l2_m2m_devstructure 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.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Nicolas Dufresne <[email protected]>Signed-off-by Ming Qian <[email protected]>I certainly don't have the complete picture for how this needs to work.
However, I was thinking that rather than using a kref and having to share two specific functions to update it (v4l2_m2m_get|put), couldn't we just use a device-link instead?
The device link seems to be intended for power management, I'm effectively not familiar with it, so thanks for the information. However, my impression is that this is indented to describe power management dependencies on siblings, but this was done differently on this SoC (way before my time here), the DT seems to describe a block controller which is common to the two (defective) cores. So power management wise, its already handled.
Be aware that my intent is to rename v4l2_m2m_dev into v4l2_m2m_sched. Its not a dev wrapper, but a helper object that will schedule work coming from N v4l2_m2m_ctx (per open() calls). Making this helper object ref counted makes the live-time management a lot simpler, and since its not a dev wrapper, this patch is not creating a second refcount for the same object.
regards,
Nicolas
Quoted 108 lines
Kind regards
UffeQuoted 104 lines
---
v4
- Add my Signed-off-bydrivers/media/v4l2-core/v4l2-mem2mem.c | 23 +++++++++++++++++++++++ include/media/v4l2-mem2mem.h | 21 +++++++++++++++++++++
2 files changed, 44 insertions(+)drivers/media/v4l2- renamed from drivers/media/v4l2-core/v4l2-mem2mem.c +0
-0
core/v4l2-mem2mem.c
indexfec93c1a9231..ae0de54d4c3e100644drivers/media/v4l2-core/v4l2-mem2mem.c +3
-0@@ -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(structv4l2_m2m_ctx*m2m_ctx,drivers/media/v4l2-core/v4l2-mem2mem.c +1
-0@@ -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;}
drivers/media/v4l2-core/v4l2-mem2mem.c +19
-0@@ -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, structvb2_queue*dst_vq))include/media/v4l2-mem2mem.h +21
-0@@ -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
Re: [PATCH v4 1/3] media: v4l2-mem2mem: Add a kref to the v4l2_m2m_dev structure
Quoted 29 lines · Nicolas Dufresne
Hi,
Quoted 9 lines · Ulf Hansson
Quoted 8 lines · On Fri, 5 Dec 2025 at 02:55, <[email protected]> wrote:
From: Nicolas Dufresne <[email protected]>
Adding a reference count to the
v4l2_m2m_devstructure 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.Quoted 8 lines
Quoted 2 lines
Signed-off-by Nicolas Dufresne <[email protected]>Signed-off-by Ming Qian <[email protected]>I certainly don't have the complete picture for how this needs to work.
However, I was thinking that rather than using a kref and having to share two specific functions to update it (v4l2_m2m_get|put), couldn't we just use a device-link instead?
The device link seems to be intended for power management, I'm effectively not familiar with it, so thanks for the information. However, my impression is that this is indented to describe power management dependencies on siblings, but this was done differently on this SoC (way before my time here), the DT seems to describe a block controller which is common to the two (defective) cores. So power management wise, its already handled.
Quoted 5 lines
Be aware that my intent is to rename
v4l2_m2m_devintov4l2_m2m_sched. Its not a dev wrapper, but a helper object that will schedule work coming from Nv4l2_m2m_ctx(peropen()calls). Making this helper object ref counted makes the live-time management a lot simpler, and since its not a dev wrapper, this patch is not creating a second refcount for the same object.
Okay, fair enough. No objections from my side,
[...]
Kind regards
Uffe
PATCH v4 2/3 pmdomain: imx8m-blk-ctrl: Remove separate rst and clk mask for 8mq vpu
In reply to [email protected]From: Ming Qian <[email protected]>
For i.MX8MQ platform, the ADB in the VPUMIX domain has no separate reset and clock enable bits, but is ungated and reset together with the VPUs. So we can't reset G1 or G2 separately, it may led to the system hang. Remove rst_mask and clk_mask of imx8mq_vpu_blk_ctl_domain_data. Let imx8mq_vpu_power_notifier() do really vpu reset.
---
v3
- Add some comments
v2
- Update commit message
drivers/pmdomain/imx/imx8m-blk-ctrl.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/pmdomain/imx/imx8m-blk-ctrl.c +7 -4
@@ -846,22 +846,25 @@ static int imx8mq_vpu_power_notifier(struct notifier_block *nb,return NOTIFY_OK ; } +/* +* For i.MX8MQ, the ADB in the VPUMIX domain has no separate reset and clock +* enable bits, but is ungated and reset together with the VPUs. +* Resetting G1 or G2 separately may led to system hang. +* Remove the rst_mask and clk_mask from the domain data of G1 and G2, +* Let imx8mq_vpu_power_notifier() do really vpu reset. +*/ static const struct imx8m_blk_ctrl_domain_data imx8mq_vpu_blk_ctl_domain_data[] = { [IMX8MQ_VPUBLK_PD_G1 ] = { .name ="vpublk-g1" , .clk_names = (const char *[]){"g1" , }, .num_clks =1 , .gpc_name ="g1" , - .rst_mask =BIT (1 ), - .clk_mask =BIT (1 ), }, [IMX8MQ_VPUBLK_PD_G2 ] = { .name ="vpublk-g2" , .clk_names = (const char *[]){"g2" , }, .num_clks =1 , .gpc_name ="g2" , - .rst_mask =BIT (0 ), - .clk_mask =BIT (0 ), }, };
Signature · 1 line
2.52.0
Re: [PATCH v4 2/3] pmdomain: imx8m-blk-ctrl: Remove separate rst and clk mask for 8mq vpu
Quoted 9 lines · On Fri, 5 Dec 2025 at 02:55, <[email protected]> wrote:
From: Ming Qian <[email protected]>
For i.MX8MQ platform, the ADB in the VPUMIX domain has no separate reset and clock enable bits, but is ungated and reset together with the VPUs. So we can't reset G1 or G2 separately, it may led to the system hang. Remove
rst_maskandclk_maskofimx8mq_vpu_blk_ctl_domain_data. Letimx8mq_vpu_power_notifier()do really vpu reset.
Quoted 5 lines
Fixes 608d7c325e85 ("soc: imx: imx8m-blk-ctrl: add i.MX8MQ VPU blk-ctrl")Signed-off-by Ming Qian <[email protected]>Reviewed-by Benjamin Gaignard <[email protected]>Reviewed-by Peng Fan <[email protected]>Reviewed-by Frank Li <[email protected]>
Applied for fixes and by adding a stable tag, thanks!
Kind regards
Uffe
Quoted 46 lines
---
v3
- Add some comments
v2
- Update commit messagedrivers/pmdomain/imx/imx8m-blk-ctrl.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)drivers/pmdomain/imx/imx8m-blk-ctrl.c +7
-5@@ -846,22 +846,25 @@ static int imx8mq_vpu_power_notifier(struct notifier_block *nb,return NOTIFY_OK ; } +/* +* For i.MX8MQ, the ADB in the VPUMIX domain has no separate reset and clock +* enable bits, but is ungated and reset together with the VPUs. +* Resetting G1 or G2 separately may led to system hang. +* Remove the rst_mask and clk_mask from the domain data of G1 and G2, +* Let imx8mq_vpu_power_notifier() do really vpu reset. +*/ static const struct imx8m_blk_ctrl_domain_data imx8mq_vpu_blk_ctl_domain_data[] = { [IMX8MQ_VPUBLK_PD_G1 ] = { .name ="vpublk-g1" , .clk_names = (const char *[]){"g1" , }, .num_clks =1 , .gpc_name ="g1" , - .rst_mask =BIT (1 ), - .clk_mask =BIT (1 ), }, [IMX8MQ_VPUBLK_PD_G2 ] = { .name ="vpublk-g2" , .clk_names = (const char *[]){"g2" , }, .num_clks =1 , .gpc_name ="g2" , - .rst_mask =BIT (0 ), - .clk_mask =BIT (0 ), }, }; --2.52.0
PATCH v4 3/3 media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC
In reply to [email protected]From: Ming Qian <[email protected]>
For the i.MX8MQ platform, there is a hardware limitation: the g1 VPU and g2 VPU cannot decode simultaneously; otherwise, it will cause below bus error and produce corrupted pictures, even potentially lead to system hang.
[ 110.527986] hantro-vpu 38310000.video-codec: frame decode timed out. [ 110.583517] hantro-vpu 38310000.video-codec: bus error detected.
Therefore, it is necessary to ensure that g1 and g2 operate alternately. This allows for successful multi-instance decoding of H.264 and HEVC.
To achieve this, g1 and g2 share the same v4l2_m2m_dev, and then the v4l2_m2m_dev can handle the scheduling.
---
v4
- Avoid double put device node in for_each_matching_node v3
- Add some comments
v2
- Update commit message
drivers/media/platform/verisilicon/hantro.h | 2 + .../media/platform/verisilicon/hantro_drv.c | 42 +++++++++++++++++-- .../media/platform/verisilicon/imx8m_vpu_hw.c | 8 ++++ 3 files changed, 49 insertions(+), 3 deletions(-)
drivers/media/platform/verisilicon/hantro.h +2 -0
@@ -77,6 +77,7 @@ struct hantro_irq {* @double_buffer: core needs double buffering * @legacy_regs: core uses legacy register set * @late_postproc: postproc must be set up at the end of the job +* @shared_devices: an array of device ids that cannot run concurrently */ struct hantro_variant {unsigned int enc_offset;
@@ -101,6 +102,7 @@ struct hantro_variant { unsigned int double_buffer : 1; unsigned int legacy_regs : 1; unsigned int late_postproc : 1; +const struct of_device_id *shared_devices; };/**
drivers/media/platform/verisilicon/hantro_drv.c +39 -3
72 lines not on this page · raw message
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +8 -0
@@ -343,6 +343,12 @@ const struct hantro_variant imx8mq_vpu_variant = { .num_regs = ARRAY_SIZE(imx8mq_reg_names) }; +static const struct of_device_id imx8mq_vpu_shared_resources[]__initconst = { + { .compatible ="nxp,imx8mq-vpu-g1" , }, + { .compatible ="nxp,imx8mq-vpu-g2" , }, + {/* sentinel */ } +}; +const struct hantro_variant imx8mq_vpu_g1_variant = { .dec_fmts = imx8m_vpu_dec_fmts, .num_dec_fmts =ARRAY_SIZE (imx8m_vpu_dec_fmts),
@@ -356,6 +362,7 @@ const struct hantro_variant imx8mq_vpu_g1_variant = { .num_irqs = ARRAY_SIZE(imx8mq_irqs), .clk_names = imx8mq_g1_clk_names, .num_clocks = ARRAY_SIZE(imx8mq_g1_clk_names), + .shared_devices = imx8mq_vpu_shared_resources, };const struct hantro_variant imx8mq_vpu_g2_variant = {
@@ -371,6 +378,7 @@ const struct hantro_variant imx8mq_vpu_g2_variant = { .num_irqs = ARRAY_SIZE(imx8mq_g2_irqs), .clk_names = imx8mq_g2_clk_names, .num_clocks = ARRAY_SIZE(imx8mq_g2_clk_names), + .shared_devices = imx8mq_vpu_shared_resources, };const struct hantro_variant imx8mm_vpu_g1_variant = {
Signature · 1 line
2.52.0
Re: [PATCH v4 3/3] media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC
Quoted 12 lines · On Fri, Dec 05, 2025 at 09:54:26AM +0800, [email protected] wrote:
From: Ming Qian <[email protected]>
For the i.MX8MQ platform, there is a hardware limitation: the g1 VPU and g2 VPU cannot decode simultaneously; otherwise, it will cause below bus error and produce corrupted pictures, even potentially lead to system hang.
[ 110.527986] hantro-vpu 38310000.video-codec: frame decode timed out. [ 110.583517] hantro-vpu 38310000.video-codec: bus error detected.Therefore, it is necessary to ensure that g1 and g2 operate alternately. This allows for successful multi-instance decoding of H.264 and HEVC.
Quoted 8 lines
To achieve this, g1 and g2 share the same
v4l2_m2m_dev, and then thev4l2_m2m_devcan handle the scheduling.Fixes cb5dd5a0fa518 ("media: hantro: Introduce G2/HEVC decoder")Co-developed-by Nicolas Dufresne <[email protected]>Signed-off-by Nicolas Dufresne <[email protected]>Signed-off-by Ming Qian <[email protected]>---
Quoted 149 lines
v4
- Avoid double put device node infor_each_matching_nodev3
- Add some comments
v2
- Update commit messagedrivers/media/platform/verisilicon/hantro.h | 2 + .../media/platform/verisilicon/hantro_drv.c | 42 +++++++++++++++++-- .../media/platform/verisilicon/imx8m_vpu_hw.c | 8 ++++ 3 files changed, 49 insertions(+), 3 deletions(-)drivers/media/platform/verisilicon/hantro.h +2
-0@@ -77,6 +77,7 @@ struct hantro_irq {* @double_buffer: core needs double buffering * @legacy_regs: core uses legacy register set * @late_postproc: postproc must be set up at the end of the job +* @shared_devices: an array of device ids that cannot run concurrently */ struct hantro_variant {unsigned int enc_offset;@@ -101,6 +102,7 @@ struct hantro_variant { unsigned int double_buffer : 1; unsigned int legacy_regs : 1; unsigned int late_postproc : 1; +const struct of_device_id *shared_devices; };/** drivers/media/platform/verisilicon/hantro_drv.c +39
-3@@ -13,6 +13,7 @@#include <linux/clk.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/of_platform.h> #include <linux/platform_device.h> #include <linux/pm.h> #include <linux/pm_runtime.h> @@ -1035,6 +1036,41 @@ static int hantro_disable_multicore(struct hantro_dev *vpu)return 0 ; } +static struct v4l2_m2m_dev *hantro_get_v4l2_m2m_dev (struct hantro_dev *vpu) +{ +struct device_node *node; +struct hantro_dev *shared_vpu; + +if (!vpu->variant || !vpu->variant->shared_devices) + goto init_new_m2m_dev; + +for_each_matching_node (node, vpu->variant->shared_devices) { +struct platform_device *pdev; +struct v4l2_m2m_dev *m2m_dev; + + pdev =of_find_device_by_node (node); +if (!pdev) +continue ; + + shared_vpu =platform_get_drvdata (pdev); +if (IS_ERR_OR_NULL (shared_vpu) || shared_vpu == vpu) { +platform_device_put (pdev); +continue ; + } + +v4l2_m2m_get (shared_vpu->m2m_dev); + m2m_dev = shared_vpu->m2m_dev; +platform_device_put (pdev); + +of_node_put (node); + +return m2m_dev; + } + +init_new_m2m_dev: +return v4l2_m2m_init (&vpu_m2m_ops); +} +static int hantro_probe (struct platform_device *pdev) {const struct of_device_id *match;@@ -1186,7 +1222,7 @@ static int hantro_probe(struct platform_device *pdev) }platform_set_drvdata (pdev, vpu); - vpu->m2m_dev =v4l2_m2m_init (&vpu_m2m_ops); + vpu->m2m_dev =hantro_get_v4l2_m2m_dev (vpu);if (IS_ERR (vpu->m2m_dev)) {v4l2_err (&vpu->v4l2_dev,"Failed to init mem2mem device\n" ); ret =PTR_ERR (vpu->m2m_dev);@@ -1225,7 +1261,7 @@ static int hantro_probe(struct platform_device *pdev)hantro_remove_enc_func (vpu); err_m2m_rel:media_device_cleanup (&vpu->mdev); -v4l2_m2m_release (vpu->m2m_dev); +v4l2_m2m_put (vpu->m2m_dev); err_v4l2_unreg:v4l2_device_unregister (&vpu->v4l2_dev); err_clk_unprepare:@@ -1248,7 +1284,7 @@ static void hantro_remove(struct platform_device *pdev)hantro_remove_dec_func (vpu);hantro_remove_enc_func (vpu);media_device_cleanup (&vpu->mdev); -v4l2_m2m_release (vpu->m2m_dev); +v4l2_m2m_put (vpu->m2m_dev);v4l2_device_unregister (&vpu->v4l2_dev);clk_bulk_unprepare (vpu->variant->num_clocks, vpu->clocks);reset_control_assert (vpu->resets);drivers/media/platform/verisilicon/imx8m_vpu_hw.c +8
-1@@ -343,6 +343,12 @@ const struct hantro_variant imx8mq_vpu_variant = { .num_regs = ARRAY_SIZE(imx8mq_reg_names) }; +static const struct of_device_id imx8mq_vpu_shared_resources[]__initconst = { + { .compatible ="nxp,imx8mq-vpu-g1" , }, + { .compatible ="nxp,imx8mq-vpu-g2" , }, + {/* sentinel */ } +}; +const struct hantro_variant imx8mq_vpu_g1_variant = { .dec_fmts = imx8m_vpu_dec_fmts, .num_dec_fmts =ARRAY_SIZE (imx8m_vpu_dec_fmts),@@ -356,6 +362,7 @@ const struct hantro_variant imx8mq_vpu_g1_variant = { .num_irqs = ARRAY_SIZE(imx8mq_irqs), .clk_names = imx8mq_g1_clk_names, .num_clocks = ARRAY_SIZE(imx8mq_g1_clk_names), + .shared_devices = imx8mq_vpu_shared_resources, };const struct hantro_variant imx8mq_vpu_g2_variant = {@@ -371,6 +378,7 @@ const struct hantro_variant imx8mq_vpu_g2_variant = { .num_irqs = ARRAY_SIZE(imx8mq_g2_irqs), .clk_names = imx8mq_g2_clk_names, .num_clocks = ARRAY_SIZE(imx8mq_g2_clk_names), + .shared_devices = imx8mq_vpu_shared_resources, };const struct hantro_variant imx8mm_vpu_g1_variant = { --2.52.0
Quoted 19 lines · On Fri, 5 Dec 2025 at 02:55, <[email protected]> wrote:
From: Ming Qian <[email protected]>
On the i.MX8MQ, we encountered some concurrency issues with H264 and HEVC decoding.
There are two main reasons:
1. The vpu blk-ctrl don't have separate reset and clock enable bits.
2. The g1 VPU and g2 VPU cannot decode simultaneously.We attempted to make corresponding fix to address these two issues.
Ming Qian (2):
pmdomain: imx8m-blk-ctrl: Remove separate rst and clk mask for 8mq vpu
media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVCNicolas Dufresne (1):
media: v4l2-mem2mem: Add a kref to thev4l2_m2m_devstructure
Quoted 8 lines
drivers/media/platform/verisilicon/hantro.h | 2 + .../media/platform/verisilicon/hantro_drv.c | 42 +++++++++++++++++-- .../media/platform/verisilicon/imx8m_vpu_hw.c | 8 ++++ drivers/media/v4l2-core/v4l2-mem2mem.c | 23 ++++++++++ drivers/pmdomain/imx/imx8m-blk-ctrl.c | 11 +++-- include/media/v4l2-mem2mem.h | 21 ++++++++++ 6 files changed, 100 insertions(+), 7 deletions(-)
Can I pick the pmdomain patch separately from the others? Or does this need to go together?
Kind regards
Uffe
Hi Uffe,
Quoted 29 lines · Ulf Hansson
Quoted 19 lines · On Fri, 5 Dec 2025 at 02:55, <[email protected]> wrote:
From: Ming Qian <[email protected]>
On the i.MX8MQ, we encountered some concurrency issues with H264 and HEVC decoding.
There are two main reasons:
1. The vpu blk-ctrl don't have separate reset and clock enable bits.
2. The g1 VPU and g2 VPU cannot decode simultaneously.We attempted to make corresponding fix to address these two issues.
Ming Qian (2):
pmdomain: imx8m-blk-ctrl: Remove separate rst and clk mask for 8mq vpu
media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVCNicolas Dufresne (1):
media: v4l2-mem2mem: Add a kref to thev4l2_m2m_devstructureQuoted 8 lines
drivers/media/platform/verisilicon/hantro.h | 2 + .../media/platform/verisilicon/hantro_drv.c | 42 +++++++++++++++++-- .../media/platform/verisilicon/imx8m_vpu_hw.c | 8 ++++ drivers/media/v4l2-core/v4l2-mem2mem.c | 23 ++++++++++ drivers/pmdomain/imx/imx8m-blk-ctrl.c | 11 +++-- include/media/v4l2-mem2mem.h | 21 ++++++++++ 6 files changed, 100 insertions(+), 7 deletions(-)
Quoted 5 lines
Can I pick the pmdomain patch separately from the others? Or does this need to go together?
Kind regards
Uffe
I think you can pick the pmdomain patch separately.
Regards,
Ming
Hi,
Le mardi 30 décembre 2025 à 14:42 +0100, Ulf Hansson a écrit :
Quoted 29 lines · On Fri, 5 Dec 2025 at 02:55, <[email protected]> wrote:
Quoted 19 lines
From: Ming Qian <[email protected]>
On the i.MX8MQ, we encountered some concurrency issues with H264 and HEVC decoding.
There are two main reasons:
1. The vpu blk-ctrl don't have separate reset and clock enable bits.
2. The g1 VPU and g2 VPU cannot decode simultaneously.We attempted to make corresponding fix to address these two issues.
Ming Qian (2):
pmdomain: imx8m-blk-ctrl: Remove separate rst and clk mask for 8mq vpu
media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVCNicolas Dufresne (1):
media: v4l2-mem2mem: Add a kref to thev4l2_m2m_devstructureQuoted 8 lines
drivers/media/platform/verisilicon/hantro.h | 2 + .../media/platform/verisilicon/hantro_drv.c | 42 +++++++++++++++++--
.../media/platform/verisilicon/imx8m_vpu_hw.c| 8 ++++ drivers/media/v4l2-core/v4l2-mem2mem.c | 23 ++++++++++ drivers/pmdomain/imx/imx8m-blk-ctrl.c | 11 +++-- include/media/v4l2-mem2mem.h | 21 ++++++++++6 files changed, 100 insertions(+), 7 deletions(-)
Quoted 2 lines
Can I pick the pmdomain patch separately from the others? Or does this need to go together?
I believe you did already, and its perfect, we have picked the rest in the media tree now.
regards,
Nicolas