linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Courbot <acourbot@chromium.org>
To: CK Hu <ck.hu@mediatek.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>,
	Tomasz Figa <tfiga@chromium.org>, David Airlie <airlied@linux.ie>,
	Daniel Vetter <daniel@ffwll.ch>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	dri-devel@lists.freedesktop.org,
	"moderated list:ARM/Mediatek SoC support" 
	<linux-arm-kernel@lists.infradead.org>,
	"moderated list:ARM/Mediatek SoC support" 
	<linux-mediatek@lists.infradead.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] drm/mediatek: make imported PRIME buffers contiguous
Date: Mon, 29 Jul 2019 14:34:22 +0900	[thread overview]
Message-ID: <CAPBb6MV1_7PfvxhGFHQsTSh24gLTHyZWVG4ZXKsLCEqWDQb8-A@mail.gmail.com> (raw)
In-Reply-To: <1563947367.1070.7.camel@mtksdaap41>

On Wed, Jul 24, 2019 at 2:49 PM CK Hu <ck.hu@mediatek.com> wrote:
>
> Hi, Alexandre:
>
> On Tue, 2019-07-23 at 14:34 +0900, Alexandre Courbot wrote:
> > This driver requires imported PRIME buffers to appear contiguously in
> > its IO address space. Make sure this is the case by setting the maximum
> > DMA segment size to a better value than the default 64K on the DMA
> > device, and use said DMA device when importing PRIME buffers.
> >
> > Signed-off-by: Alexandre Courbot <acourbot@chromium.org>
> > ---
> >  drivers/gpu/drm/mediatek/mtk_drm_drv.c | 47 ++++++++++++++++++++++++--
> >  drivers/gpu/drm/mediatek/mtk_drm_drv.h |  2 ++
> >  2 files changed, 46 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> > index 95fdbd0fbcac..4ad4770fab13 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> > @@ -213,6 +213,7 @@ static int mtk_drm_kms_init(struct drm_device *drm)
> >       struct mtk_drm_private *private = drm->dev_private;
> >       struct platform_device *pdev;
> >       struct device_node *np;
> > +     struct device *dma_dev;
> >       int ret;
> >
> >       if (!iommu_present(&platform_bus_type))
> > @@ -275,7 +276,27 @@ static int mtk_drm_kms_init(struct drm_device *drm)
> >               goto err_component_unbind;
> >       }
> >
> > -     private->dma_dev = &pdev->dev;
> > +     dma_dev = &pdev->dev;
> > +     private->dma_dev = dma_dev;
> > +
> > +     /*
> > +      * Configure the DMA segment size to make sure we get contiguous IOVA
> > +      * when importing PRIME buffers.
> > +      */
> > +     if (!dma_dev->dma_parms) {
> > +             private->dma_parms_allocated = true;
> > +             dma_dev->dma_parms =
> > +                     devm_kzalloc(drm->dev, sizeof(*dma_dev->dma_parms),
> > +                                  GFP_KERNEL);
> > +     }
> > +     if (!dma_dev->dma_parms)
> > +             goto err_component_unbind;
>
> return with ret = 0?

Oops, indeed.

>
> > +
> > +     ret = dma_set_max_seg_size(dma_dev, (unsigned int)DMA_BIT_MASK(32));
> > +     if (ret) {
> > +             dev_err(dma_dev, "Failed to set DMA segment size\n");
> > +             goto err_unset_dma_parms;
> > +     }
> >
> >       /*
> >        * We don't use the drm_irq_install() helpers provided by the DRM
> > @@ -285,13 +306,16 @@ static int mtk_drm_kms_init(struct drm_device *drm)
> >       drm->irq_enabled = true;
> >       ret = drm_vblank_init(drm, MAX_CRTC);
> >       if (ret < 0)
> > -             goto err_component_unbind;
> > +             goto err_unset_dma_parms;
> >
> >       drm_kms_helper_poll_init(drm);
> >       drm_mode_config_reset(drm);
> >
> >       return 0;
> >
> > +err_unset_dma_parms:
> > +     if (private->dma_parms_allocated)
> > +             dma_dev->dma_parms = NULL;
> >  err_component_unbind:
> >       component_unbind_all(drm->dev, drm);
> >  err_config_cleanup:
> > @@ -302,9 +326,14 @@ static int mtk_drm_kms_init(struct drm_device *drm)
> >
> >  static void mtk_drm_kms_deinit(struct drm_device *drm)
> >  {
> > +     struct mtk_drm_private *private = drm->dev_private;
> > +
> >       drm_kms_helper_poll_fini(drm);
> >       drm_atomic_helper_shutdown(drm);
> >
> > +     if (private->dma_parms_allocated)
> > +             private->dma_dev->dma_parms = NULL;
> > +
> >       component_unbind_all(drm->dev, drm);
> >       drm_mode_config_cleanup(drm);
> >  }
> > @@ -320,6 +349,18 @@ static const struct file_operations mtk_drm_fops = {
> >       .compat_ioctl = drm_compat_ioctl,
> >  };
> >
> > +/*
> > + * We need to override this because the device used to import the memory is
> > + * not dev->dev, as drm_gem_prime_import() expects.
> > + */
> > +struct drm_gem_object *mtk_drm_gem_prime_import(struct drm_device *dev,
> > +                                             struct dma_buf *dma_buf)
> > +{
> > +     struct mtk_drm_private *private = dev->dev_private;
> > +
> > +     return drm_gem_prime_import_dev(dev, dma_buf, private->dma_dev);
> > +}
> > +
>
> I think this part should be an independent patch which fixup
> 119f5173628aa ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.")

I have split this patch and sent a v2.

Thanks,
Alex.

      reply	other threads:[~2019-07-29  5:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23  5:34 [PATCH] drm/mediatek: make imported PRIME buffers contiguous Alexandre Courbot
2019-07-24  4:22 ` Tomasz Figa
2019-07-24  5:49 ` CK Hu
2019-07-29  5:34   ` Alexandre Courbot [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=CAPBb6MV1_7PfvxhGFHQsTSh24gLTHyZWVG4ZXKsLCEqWDQb8-A@mail.gmail.com \
    --to=acourbot@chromium.org \
    --cc=airlied@linux.ie \
    --cc=ck.hu@mediatek.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=p.zabel@pengutronix.de \
    --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).