Re: [PATCH v3 3/3] media: verisilicon: Avoid G2 bus error while decoding H.264 and HEVC

From: Nicolas Dufresne

Date: Thu Dec 04 2025 - 19:05:05 EST


Le jeudi 04 décembre 2025 à 17:57 -0500, Frank Li a écrit :
> On Thu, Dec 04, 2025 at 01:15:35PM -0500, Nicolas Dufresne wrote:
> > Hi Frank,
> >
> > Le jeudi 04 décembre 2025 à 12:34 -0500, Frank Li a écrit :
> > > > +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;
> > >
> > > I found only use shared_devices here, how to  ensure that g1 and g2 operate
> > > alternately by using shared_devices?
> >
> > shared_devices is an array of of_device_id we match against. All the matching
> > devices will share the same v4l2_m2m_dev (aka m2m scheduler). Typically, both
> > cores will be schedule as one. This achieve what alternate operations without
> > active polling or blocking locks/mutex.
>
> Okay, but this code require shared_devices==NULL's device probe firstly.
> generally not order guaranteed, if there are not depentance at DT.

shared_devices is a constant array that is set inside the variant. It is
normally NULL, except for the imx8mq SoC, for which its always set.

>
> Does VPU always probe before g1/g2?
>
> and if there are two VPU instances, what's happen?

Since there is two VPU, g1 and g2, we will enter this loop:

> + for_each_matching_node(node, vpu->variant->shared_devices) {

On imx8mq, this will match twice.

> + struct platform_device *pdev;
> + struct v4l2_m2m_dev *m2m_dev;
> +
> + pdev = of_find_device_by_node(node);
> + of_node_put(node);
> +
> + if (!pdev)
> + continue;

If the match does not have a device yet (not probe yet), we skip.

> +
> + shared_vpu = platform_get_drvdata(pdev);
> + if (IS_ERR_OR_NULL(shared_vpu) || shared_vpu == vpu) {
> + platform_device_put(pdev);
> + continue;
> + }

If its the current VPU, we also skip.

> +
> + v4l2_m2m_get(shared_vpu->m2m_dev);
> + m2m_dev = shared_vpu->m2m_dev;
> + platform_device_put(pdev);

Finally, if the other VPU was initialized, we ref the v4l2_m2m_dev. We will then
create m2m_ctx from it which will cause the two VPU to be scheduled one after
the other.

> +
> + return m2m_dev;
> + }

> +
> +init_new_m2m_dev:
> + return v4l2_m2m_init(&vpu_m2m_ops);

Otherwhise we create a fresh one.

Does it make sense now ?

Nicolas

Attachment: signature.asc
Description: This is a digitally signed message part