linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Nicolas Dufresne <nicolas@ndufresne.ca>
Cc: Moudy Ho <moudy.ho@mediatek.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Jernej Skrabec <jernej.skrabec@siol.net>,
	Maoguang Meng <maoguang.meng@mediatek.com>,
	Hsin-Yi Wang <hsinyi@google.com>,
	daoyuan huang <daoyuan.huang@mediatek.com>,
	Ping-Hsun Wu <ping-hsun.wu@mediatek.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Rob Landley <rob@landley.net>,
	linux-media@vger.kernel.org, devicetree@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
	tfiga@chromium.org, drinkcat@chromium.org, acourbot@chromium.org,
	pihsun@chromium.org, menghui.lin@mediatek.com,
	sj.huang@mediatek.com, ben.lok@mediatek.com,
	randy.wu@mediatek.com, srv_heupstream@mediatek.com,
	Rex-BC Chen <Rex-BC.Chen@mediatek.com>
Subject: Re: [V1] media: mtk-mdp3: Add Mediatek MDP3 Driver
Date: Wed, 15 Jun 2022 23:16:08 +0300	[thread overview]
Message-ID: <Yqo+CPSNDeqFLPGB@pendragon.ideasonboard.com> (raw)
In-Reply-To: <2735b66aef88ef5dc623702d27efc3a931d2fdd3.camel@ndufresne.ca>

On Wed, Jun 15, 2022 at 03:55:14PM -0400, Nicolas Dufresne wrote:
> Le mercredi 23 juin 2021 à 17:14 +0800, Moudy Ho a écrit :
> > From: mtk18742 <moudy.ho@mediatek.com>
> > 
> > Add MDP3 driver for MT8183
> > 
> > Signed-off-by: Moudy Ho <moudy.ho@mediatek.com>
> > ---
> >  drivers/media/platform/Kconfig                |   17 +
> >  drivers/media/platform/Makefile               |    2 +
> >  drivers/media/platform/mtk-mdp3/Makefile      |    9 +
> >  drivers/media/platform/mtk-mdp3/isp_reg.h     |   37 +
> >  .../media/platform/mtk-mdp3/mdp-platform.h    |   58 +
> >  .../media/platform/mtk-mdp3/mdp_reg_ccorr.h   |   75 +
> >  .../media/platform/mtk-mdp3/mdp_reg_rdma.h    |  206 +++
> >  drivers/media/platform/mtk-mdp3/mdp_reg_rsz.h |  109 ++
> >  .../media/platform/mtk-mdp3/mdp_reg_wdma.h    |  125 ++
> >  .../media/platform/mtk-mdp3/mdp_reg_wrot.h    |  115 ++
> >  .../media/platform/mtk-mdp3/mmsys_config.h    |  188 +++
> >  drivers/media/platform/mtk-mdp3/mmsys_mutex.h |   35 +
> >  .../media/platform/mtk-mdp3/mmsys_reg_base.h  |   38 +
> >  drivers/media/platform/mtk-mdp3/mtk-img-ipi.h |  282 ++++
> >  .../media/platform/mtk-mdp3/mtk-mdp3-cmdq.c   |  538 ++++++
> >  .../media/platform/mtk-mdp3/mtk-mdp3-cmdq.h   |   53 +
> >  .../media/platform/mtk-mdp3/mtk-mdp3-comp.c   | 1437 +++++++++++++++++
> >  .../media/platform/mtk-mdp3/mtk-mdp3-comp.h   |  157 ++
> >  .../media/platform/mtk-mdp3/mtk-mdp3-core.c   |  266 +++
> >  .../media/platform/mtk-mdp3/mtk-mdp3-core.h   |   86 +
> >  .../media/platform/mtk-mdp3/mtk-mdp3-debug.c  |  973 +++++++++++
> >  .../media/platform/mtk-mdp3/mtk-mdp3-debug.h  |   39 +
> >  .../media/platform/mtk-mdp3/mtk-mdp3-m2m.c    |  803 +++++++++
> >  .../media/platform/mtk-mdp3/mtk-mdp3-m2m.h    |   42 +
> >  .../media/platform/mtk-mdp3/mtk-mdp3-regs.c   |  748 +++++++++
> >  .../media/platform/mtk-mdp3/mtk-mdp3-regs.h   |  373 +++++
> >  .../media/platform/mtk-mdp3/mtk-mdp3-vpu.c    |  313 ++++
> >  .../media/platform/mtk-mdp3/mtk-mdp3-vpu.h    |   79 +
> >  28 files changed, 7203 insertions(+)
> >  create mode 100644 drivers/media/platform/mtk-mdp3/Makefile
> >  create mode 100644 drivers/media/platform/mtk-mdp3/isp_reg.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mdp-platform.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mdp_reg_ccorr.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mdp_reg_rdma.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mdp_reg_rsz.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mdp_reg_wdma.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mdp_reg_wrot.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mmsys_config.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mmsys_mutex.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mmsys_reg_base.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-img-ipi.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-cmdq.c
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-cmdq.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-comp.c
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-comp.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-core.c
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-core.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-debug.c
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-debug.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-m2m.c
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-m2m.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-regs.c
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-regs.h
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-vpu.c
> >  create mode 100644 drivers/media/platform/mtk-mdp3/mtk-mdp3-vpu.h

[snip]

> > diff --git a/drivers/media/platform/mtk-mdp3/mtk-mdp3-regs.c b/drivers/media/platform/mtk-mdp3/mtk-mdp3-regs.c
> > new file mode 100644
> > index 000000000000..0c4c942b5f9c
> > --- /dev/null
> > +++ b/drivers/media/platform/mtk-mdp3/mtk-mdp3-regs.c
> > @@ -0,0 +1,748 @@

[snip]

> > +static void mdp_prepare_buffer(struct img_image_buffer *b,
> > +			       struct mdp_frame *frame, struct vb2_buffer *vb)
> > +{
> > +	struct v4l2_pix_format_mplane *pix_mp = &frame->format.fmt.pix_mp;
> > +	unsigned int i;
> > +
> > +	b->format.colorformat = frame->mdp_fmt->mdp_color;
> > +	b->format.ycbcr_prof = frame->ycbcr_prof;
> > +	for (i = 0; i < pix_mp->num_planes; ++i) {
> > +		u32 stride = mdp_fmt_get_stride(frame->mdp_fmt,
> > +			pix_mp->plane_fmt[i].bytesperline, i);
> > +
> > +		b->format.plane_fmt[i].stride = stride;
> > +		/*
> > +		 * TODO(crbug.com/901264): The way to pass an offset within a
> > +		 * DMA-buf is not defined in V4L2 specification, so we abuse
> > +		 * data_offset for now. Fix it when we have the right interface,
> > +		 * including any necessary validation and potential alignment
> > +		 * issues.
> > +		 */
> > +		b->format.plane_fmt[i].size =
> > +			mdp_fmt_get_plane_size(frame->mdp_fmt, stride,
> > +					       pix_mp->height, i) -
> > +					       vb->planes[i].data_offset;
> > +		b->iova[i] = vb2_dma_contig_plane_dma_addr(vb, i) +
> > +			     vb->planes[i].data_offset;
> 
> As the comment says, data_offset is not valdiated at all for capture devices and
> is only validated so that (length - data_offset > 0) for OUTPUT devices. So this
> is going out of spec and leave the door open for buffer overflow triggered by
> users.

And as documented by the TODO comment, it's clearly an API abuse. This
can't go in as-is, we need to revive the v4l2_buffer extended API that
Boris used to work on.

> > +	}
> > +	for (; i < MDP_COLOR_GET_PLANE_COUNT(b->format.colorformat); ++i) {
> > +		u32 stride = mdp_fmt_get_stride_contig(frame->mdp_fmt,
> > +			b->format.plane_fmt[0].stride, i);
> > +
> > +		b->format.plane_fmt[i].stride = stride;
> > +		b->format.plane_fmt[i].size =
> > +			mdp_fmt_get_plane_size(frame->mdp_fmt, stride,
> > +					       pix_mp->height, i);
> > +		b->iova[i] = b->iova[i - 1] + b->format.plane_fmt[i - 1].size;
> > +	}
> > +	b->usage = frame->usage;
> > +}

-- 
Regards,

Laurent Pinchart

      reply	other threads:[~2022-06-15 20:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-23  9:14 [V1] media: mtk-mdp3: Add Mediatek MDP3 Driver Moudy Ho
2021-07-06  6:09 ` Hsin-Yi Wang
2022-06-15 19:55 ` Nicolas Dufresne
2022-06-15 20:16   ` Laurent Pinchart [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=Yqo+CPSNDeqFLPGB@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=Rex-BC.Chen@mediatek.com \
    --cc=acourbot@chromium.org \
    --cc=ben.lok@mediatek.com \
    --cc=daoyuan.huang@mediatek.com \
    --cc=devicetree@vger.kernel.org \
    --cc=drinkcat@chromium.org \
    --cc=geert+renesas@glider.be \
    --cc=hsinyi@google.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jernej.skrabec@siol.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=maoguang.meng@mediatek.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mchehab@kernel.org \
    --cc=menghui.lin@mediatek.com \
    --cc=moudy.ho@mediatek.com \
    --cc=nicolas@ndufresne.ca \
    --cc=pihsun@chromium.org \
    --cc=ping-hsun.wu@mediatek.com \
    --cc=randy.wu@mediatek.com \
    --cc=rob@landley.net \
    --cc=robh+dt@kernel.org \
    --cc=sj.huang@mediatek.com \
    --cc=srv_heupstream@mediatek.com \
    --cc=tfiga@chromium.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;
as well as URLs for NNTP newsgroup(s).