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@xxxxxxxxxxxx> > > > > Add MDP3 driver for MT8183 > > > > Signed-off-by: Moudy Ho <moudy.ho@xxxxxxxxxxxx> > > --- > > 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