Re: [PATCH 5/6] drm/mediatek: Convert to use CMA helpers

2019-12-16 Thread Laurent Pinchart
Hi Rob,

On Thu, Oct 24, 2019 at 03:02:57PM +0800, CK Hu wrote:
> On Wed, 2019-10-23 at 17:56 -0500, Rob Herring wrote:
> > On Wed, Oct 23, 2019 at 4:06 PM CK Hu wrote:
> > > On Wed, 2019-10-23 at 12:42 -0500, Rob Herring wrote:
> > > > On Tue, Oct 22, 2019 at 12:07 PM Matthias Brugger wrote:
> > > > > On 21/10/2019 23:45, Rob Herring wrote:
> > > > > > The only reason the Mediatek driver doesn't use the CMA helpers is 
> > > > > > it
> > > > > > sets DMA_ATTR_NO_KERNEL_MAPPING and does a vmap() on demand. Using
> > > > > > vmap() is not even guaranteed to work as DMA buffers may not have a
> > > > > > struct page. Now that the CMA helpers support setting
> > > > > > DMA_ATTR_NO_KERNEL_MAPPING as needed or not, convert Mediatek 
> > > > > > driver to
> > > > > > use CMA helpers.
> > > > > >
> > > > > > Cc: CK Hu 
> > > > > > Cc: Philipp Zabel 
> > > > > > Cc: David Airlie 
> > > > > > Cc: Daniel Vetter 
> > > > > > Cc: Matthias Brugger 
> > > > > > Cc: linux-arm-ker...@lists.infradead.org
> > > > > > Cc: linux-media...@lists.infradead.org
> > > > > > Signed-off-by: Rob Herring 
> > > > > > ---
> > > > >
> > > > > I tested this on my Chromebook with some patches on top of v5.4-rc1 
> > > > > [1], which
> > > > > work. If I add your patches on top of that, the system does not boot 
> > > > > up.
> > > > > Unfortunately I don't have a serial console, so I wasn't able to see 
> > > > > if there is
> > > > > any error message.
> > > >
> > > > Thanks for testing. I'm based on drm-misc-next, but don't see anything
> > > > obvious there that would matter. There are some mmap changes, but I
> > > > think they shouldn't matter.
> > > >
> > > > Did you have fbcon enabled? That may give more clues about where the 
> > > > problem is.
> > >
> > > There are priv->dma_dev for dma device, but it is not drm device. In
> > > mt8173.dtsi [1], there are mmsys device and ovl device, mmsys device is
> > > drm device and ovl device is mmsys's sub device which provide dma
> > > function, so ovl is the priv->dma_dev. I think your patch directly use
> > > drm device for dma operation and this would cause dma function fail.
> > > Please use priv->dma_dev for dma operation.
> > 
> > Right, thanks for catching that. Either we'll need to make CMA GEM
> > object have a struct device ptr or adjust the drm_device.dev to have
> > the necessary DMA setup.
> > 
> > One question though, why do you use CMA when you have an IOMMU? That's
> > not optimal as CMA size may be limited. Or you don't always have an
> > IOMMU?

Please note that the DRM GEM CMA helpers are misnamed, they use the DMA
coherent allocation API, and thus don't use CMA if the device is backed
by an IOMMU. They should really have been named DRM GEM DMA helpers.

> For all upstreamed mediatek SoC, all has IOMMU, so it does not need CMA.
> I think we use CMA just because we refer to other drm driver to
> implement mediatek drm driver and we misused CMA helper function but it
> works. I think we should change to more accurate implementation. If you
> want, you could modify it in this series.
> 

-- 
Regards,

Laurent Pinchart
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 5/6] drm/mediatek: Convert to use CMA helpers

2019-10-24 Thread CK Hu
Hi, Rob:

On Wed, 2019-10-23 at 17:56 -0500, Rob Herring wrote:
> On Wed, Oct 23, 2019 at 4:06 PM CK Hu  wrote:
> >
> > Hi, Rob:
> >
> > On Wed, 2019-10-23 at 12:42 -0500, Rob Herring wrote:
> > > On Tue, Oct 22, 2019 at 12:07 PM Matthias Brugger
> > >  wrote:
> > > >
> > > > Hi Rob,
> > > >
> > > > On 21/10/2019 23:45, Rob Herring wrote:
> > > > > The only reason the Mediatek driver doesn't use the CMA helpers is it
> > > > > sets DMA_ATTR_NO_KERNEL_MAPPING and does a vmap() on demand. Using
> > > > > vmap() is not even guaranteed to work as DMA buffers may not have a
> > > > > struct page. Now that the CMA helpers support setting
> > > > > DMA_ATTR_NO_KERNEL_MAPPING as needed or not, convert Mediatek driver 
> > > > > to
> > > > > use CMA helpers.
> > > > >
> > > > > Cc: CK Hu 
> > > > > Cc: Philipp Zabel 
> > > > > Cc: David Airlie 
> > > > > Cc: Daniel Vetter 
> > > > > Cc: Matthias Brugger 
> > > > > Cc: linux-arm-ker...@lists.infradead.org
> > > > > Cc: linux-media...@lists.infradead.org
> > > > > Signed-off-by: Rob Herring 
> > > > > ---
> > > >
> > > > I tested this on my Chromebook with some patches on top of v5.4-rc1 
> > > > [1], which
> > > > work. If I add your patches on top of that, the system does not boot up.
> > > > Unfortunately I don't have a serial console, so I wasn't able to see if 
> > > > there is
> > > > any error message.
> > >
> > > Thanks for testing. I'm based on drm-misc-next, but don't see anything
> > > obvious there that would matter. There are some mmap changes, but I
> > > think they shouldn't matter.
> > >
> > > Did you have fbcon enabled? That may give more clues about where the 
> > > problem is.
> >
> > There are priv->dma_dev for dma device, but it is not drm device. In
> > mt8173.dtsi [1], there are mmsys device and ovl device, mmsys device is
> > drm device and ovl device is mmsys's sub device which provide dma
> > function, so ovl is the priv->dma_dev. I think your patch directly use
> > drm device for dma operation and this would cause dma function fail.
> > Please use priv->dma_dev for dma operation.
> 
> Right, thanks for catching that. Either we'll need to make CMA GEM
> object have a struct device ptr or adjust the drm_device.dev to have
> the necessary DMA setup.
> 
> One question though, why do you use CMA when you have an IOMMU? That's
> not optimal as CMA size may be limited. Or you don't always have an
> IOMMU?

For all upstreamed mediatek SoC, all has IOMMU, so it does not need CMA.
I think we use CMA just because we refer to other drm driver to
implement mediatek drm driver and we misused CMA helper function but it
works. I think we should change to more accurate implementation. If you
want, you could modify it in this series.

Regards,
CK

> 
> Rob


___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH 5/6] drm/mediatek: Convert to use CMA helpers

2019-10-23 Thread Rob Herring
On Wed, Oct 23, 2019 at 4:06 PM CK Hu  wrote:
>
> Hi, Rob:
>
> On Wed, 2019-10-23 at 12:42 -0500, Rob Herring wrote:
> > On Tue, Oct 22, 2019 at 12:07 PM Matthias Brugger
> >  wrote:
> > >
> > > Hi Rob,
> > >
> > > On 21/10/2019 23:45, Rob Herring wrote:
> > > > The only reason the Mediatek driver doesn't use the CMA helpers is it
> > > > sets DMA_ATTR_NO_KERNEL_MAPPING and does a vmap() on demand. Using
> > > > vmap() is not even guaranteed to work as DMA buffers may not have a
> > > > struct page. Now that the CMA helpers support setting
> > > > DMA_ATTR_NO_KERNEL_MAPPING as needed or not, convert Mediatek driver to
> > > > use CMA helpers.
> > > >
> > > > Cc: CK Hu 
> > > > Cc: Philipp Zabel 
> > > > Cc: David Airlie 
> > > > Cc: Daniel Vetter 
> > > > Cc: Matthias Brugger 
> > > > Cc: linux-arm-ker...@lists.infradead.org
> > > > Cc: linux-media...@lists.infradead.org
> > > > Signed-off-by: Rob Herring 
> > > > ---
> > >
> > > I tested this on my Chromebook with some patches on top of v5.4-rc1 [1], 
> > > which
> > > work. If I add your patches on top of that, the system does not boot up.
> > > Unfortunately I don't have a serial console, so I wasn't able to see if 
> > > there is
> > > any error message.
> >
> > Thanks for testing. I'm based on drm-misc-next, but don't see anything
> > obvious there that would matter. There are some mmap changes, but I
> > think they shouldn't matter.
> >
> > Did you have fbcon enabled? That may give more clues about where the 
> > problem is.
>
> There are priv->dma_dev for dma device, but it is not drm device. In
> mt8173.dtsi [1], there are mmsys device and ovl device, mmsys device is
> drm device and ovl device is mmsys's sub device which provide dma
> function, so ovl is the priv->dma_dev. I think your patch directly use
> drm device for dma operation and this would cause dma function fail.
> Please use priv->dma_dev for dma operation.

Right, thanks for catching that. Either we'll need to make CMA GEM
object have a struct device ptr or adjust the drm_device.dev to have
the necessary DMA setup.

One question though, why do you use CMA when you have an IOMMU? That's
not optimal as CMA size may be limited. Or you don't always have an
IOMMU?

Rob
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH 5/6] drm/mediatek: Convert to use CMA helpers

2019-10-23 Thread CK Hu
Hi, Rob:

On Wed, 2019-10-23 at 12:42 -0500, Rob Herring wrote:
> On Tue, Oct 22, 2019 at 12:07 PM Matthias Brugger
>  wrote:
> >
> > Hi Rob,
> >
> > On 21/10/2019 23:45, Rob Herring wrote:
> > > The only reason the Mediatek driver doesn't use the CMA helpers is it
> > > sets DMA_ATTR_NO_KERNEL_MAPPING and does a vmap() on demand. Using
> > > vmap() is not even guaranteed to work as DMA buffers may not have a
> > > struct page. Now that the CMA helpers support setting
> > > DMA_ATTR_NO_KERNEL_MAPPING as needed or not, convert Mediatek driver to
> > > use CMA helpers.
> > >
> > > Cc: CK Hu 
> > > Cc: Philipp Zabel 
> > > Cc: David Airlie 
> > > Cc: Daniel Vetter 
> > > Cc: Matthias Brugger 
> > > Cc: linux-arm-ker...@lists.infradead.org
> > > Cc: linux-media...@lists.infradead.org
> > > Signed-off-by: Rob Herring 
> > > ---
> >
> > I tested this on my Chromebook with some patches on top of v5.4-rc1 [1], 
> > which
> > work. If I add your patches on top of that, the system does not boot up.
> > Unfortunately I don't have a serial console, so I wasn't able to see if 
> > there is
> > any error message.
> 
> Thanks for testing. I'm based on drm-misc-next, but don't see anything
> obvious there that would matter. There are some mmap changes, but I
> think they shouldn't matter.
> 
> Did you have fbcon enabled? That may give more clues about where the problem 
> is.

There are priv->dma_dev for dma device, but it is not drm device. In
mt8173.dtsi [1], there are mmsys device and ovl device, mmsys device is
drm device and ovl device is mmsys's sub device which provide dma
function, so ovl is the priv->dma_dev. I think your patch directly use
drm device for dma operation and this would cause dma function fail.
Please use priv->dma_dev for dma operation.

Regards,
CK

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/mediatek/mt8173.dtsi?h=v5.4-rc4
> 
> Rob


___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH 5/6] drm/mediatek: Convert to use CMA helpers

2019-10-23 Thread Rob Herring
On Tue, Oct 22, 2019 at 12:07 PM Matthias Brugger
 wrote:
>
> Hi Rob,
>
> On 21/10/2019 23:45, Rob Herring wrote:
> > The only reason the Mediatek driver doesn't use the CMA helpers is it
> > sets DMA_ATTR_NO_KERNEL_MAPPING and does a vmap() on demand. Using
> > vmap() is not even guaranteed to work as DMA buffers may not have a
> > struct page. Now that the CMA helpers support setting
> > DMA_ATTR_NO_KERNEL_MAPPING as needed or not, convert Mediatek driver to
> > use CMA helpers.
> >
> > Cc: CK Hu 
> > Cc: Philipp Zabel 
> > Cc: David Airlie 
> > Cc: Daniel Vetter 
> > Cc: Matthias Brugger 
> > Cc: linux-arm-ker...@lists.infradead.org
> > Cc: linux-media...@lists.infradead.org
> > Signed-off-by: Rob Herring 
> > ---
>
> I tested this on my Chromebook with some patches on top of v5.4-rc1 [1], which
> work. If I add your patches on top of that, the system does not boot up.
> Unfortunately I don't have a serial console, so I wasn't able to see if there 
> is
> any error message.

Thanks for testing. I'm based on drm-misc-next, but don't see anything
obvious there that would matter. There are some mmap changes, but I
think they shouldn't matter.

Did you have fbcon enabled? That may give more clues about where the problem is.

Rob
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH 5/6] drm/mediatek: Convert to use CMA helpers

2019-10-22 Thread Matthias Brugger
Hi Rob,

On 21/10/2019 23:45, Rob Herring wrote:
> The only reason the Mediatek driver doesn't use the CMA helpers is it
> sets DMA_ATTR_NO_KERNEL_MAPPING and does a vmap() on demand. Using
> vmap() is not even guaranteed to work as DMA buffers may not have a
> struct page. Now that the CMA helpers support setting
> DMA_ATTR_NO_KERNEL_MAPPING as needed or not, convert Mediatek driver to
> use CMA helpers.
> 
> Cc: CK Hu 
> Cc: Philipp Zabel 
> Cc: David Airlie 
> Cc: Daniel Vetter 
> Cc: Matthias Brugger 
> Cc: linux-arm-ker...@lists.infradead.org
> Cc: linux-media...@lists.infradead.org
> Signed-off-by: Rob Herring 
> ---

I tested this on my Chromebook with some patches on top of v5.4-rc1 [1], which
work. If I add your patches on top of that, the system does not boot up.
Unfortunately I don't have a serial console, so I wasn't able to see if there is
any error message.

I checked the config and didn't see any suspicious

I added Uli and some guys from chromium, maybe someone can provide some
logs/insights.

Regards,
Matthias

[1] https://github.com/uli/kernel/tree/elm-working-5.4

>  drivers/gpu/drm/mediatek/Makefile|   1 -
>  drivers/gpu/drm/mediatek/mtk_drm_crtc.c  |   2 +-
>  drivers/gpu/drm/mediatek/mtk_drm_drv.c   |  28 +--
>  drivers/gpu/drm/mediatek/mtk_drm_fb.c|   1 -
>  drivers/gpu/drm/mediatek/mtk_drm_gem.c   | 289 ---
>  drivers/gpu/drm/mediatek/mtk_drm_gem.h   |  51 
>  drivers/gpu/drm/mediatek/mtk_drm_plane.c |   7 +-
>  7 files changed, 15 insertions(+), 364 deletions(-)
>  delete mode 100644 drivers/gpu/drm/mediatek/mtk_drm_gem.c
>  delete mode 100644 drivers/gpu/drm/mediatek/mtk_drm_gem.h
> 
> diff --git a/drivers/gpu/drm/mediatek/Makefile 
> b/drivers/gpu/drm/mediatek/Makefile
> index 82ae49c64221..50a50e86738f 100644
> --- a/drivers/gpu/drm/mediatek/Makefile
> +++ b/drivers/gpu/drm/mediatek/Makefile
> @@ -8,7 +8,6 @@ mediatek-drm-y := mtk_disp_color.o \
> mtk_drm_ddp_comp.o \
> mtk_drm_drv.o \
> mtk_drm_fb.o \
> -   mtk_drm_gem.o \
> mtk_drm_plane.o \
> mtk_dsi.o \
> mtk_mipi_tx.o \
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c 
> b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> index 34a731755791..638d57e8ac12 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> @@ -11,6 +11,7 @@
>  
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  
> @@ -18,7 +19,6 @@
>  #include "mtk_drm_crtc.h"
>  #include "mtk_drm_ddp.h"
>  #include "mtk_drm_ddp_comp.h"
> -#include "mtk_drm_gem.h"
>  #include "mtk_drm_plane.h"
>  
>  /**
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c 
> b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> index 352b81a7a670..36f32507e5fb 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> @@ -28,7 +28,6 @@
>  #include "mtk_drm_ddp_comp.h"
>  #include "mtk_drm_drv.h"
>  #include "mtk_drm_fb.h"
> -#include "mtk_drm_gem.h"
>  
>  #define DRIVER_NAME "mediatek"
>  #define DRIVER_DESC "Mediatek SoC DRM"
> @@ -335,16 +334,14 @@ static void mtk_drm_kms_deinit(struct drm_device *drm)
>   drm_mode_config_cleanup(drm);
>  }
>  
> -static const struct file_operations mtk_drm_fops = {
> - .owner = THIS_MODULE,
> - .open = drm_open,
> - .release = drm_release,
> - .unlocked_ioctl = drm_ioctl,
> - .mmap = mtk_drm_gem_mmap,
> - .poll = drm_poll,
> - .read = drm_read,
> - .compat_ioctl = drm_compat_ioctl,
> -};
> +DEFINE_DRM_GEM_CMA_FOPS(mtk_drm_fops);
> +
> +static int mtk_drm_gem_dumb_create(struct drm_file *file_priv,
> +struct drm_device *dev,
> +struct drm_mode_create_dumb *args)
> +{
> + return drm_gem_cma_dumb_create_internal(file_priv, dev, args);
> +}
>  
>  /*
>   * We need to override this because the device used to import the memory is
> @@ -361,18 +358,15 @@ struct drm_gem_object *mtk_drm_gem_prime_import(struct 
> drm_device *dev,
>  static struct drm_driver mtk_drm_driver = {
>   .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
>  
> - .gem_free_object_unlocked = mtk_drm_gem_free_object,
>   .gem_vm_ops = _gem_cma_vm_ops,
> + .gem_create_object = drm_cma_gem_create_object_default_funcs,
>   .dumb_create = mtk_drm_gem_dumb_create,
>  
>   .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
>   .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
>   .gem_prime_import = mtk_drm_gem_prime_import,
> - .gem_prime_get_sg_table = mtk_gem_prime_get_sg_table,
> - .gem_prime_import_sg_table = mtk_gem_prime_import_sg_table,
> - .gem_prime_mmap = mtk_drm_gem_mmap_buf,
> - .gem_prime_vmap = mtk_drm_gem_prime_vmap,
> - .gem_prime_vunmap = mtk_drm_gem_prime_vunmap,
> + .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table_vmap,
> + .gem_prime_mmap = 

[PATCH 5/6] drm/mediatek: Convert to use CMA helpers

2019-10-21 Thread Rob Herring
The only reason the Mediatek driver doesn't use the CMA helpers is it
sets DMA_ATTR_NO_KERNEL_MAPPING and does a vmap() on demand. Using
vmap() is not even guaranteed to work as DMA buffers may not have a
struct page. Now that the CMA helpers support setting
DMA_ATTR_NO_KERNEL_MAPPING as needed or not, convert Mediatek driver to
use CMA helpers.

Cc: CK Hu 
Cc: Philipp Zabel 
Cc: David Airlie 
Cc: Daniel Vetter 
Cc: Matthias Brugger 
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-media...@lists.infradead.org
Signed-off-by: Rob Herring 
---
 drivers/gpu/drm/mediatek/Makefile|   1 -
 drivers/gpu/drm/mediatek/mtk_drm_crtc.c  |   2 +-
 drivers/gpu/drm/mediatek/mtk_drm_drv.c   |  28 +--
 drivers/gpu/drm/mediatek/mtk_drm_fb.c|   1 -
 drivers/gpu/drm/mediatek/mtk_drm_gem.c   | 289 ---
 drivers/gpu/drm/mediatek/mtk_drm_gem.h   |  51 
 drivers/gpu/drm/mediatek/mtk_drm_plane.c |   7 +-
 7 files changed, 15 insertions(+), 364 deletions(-)
 delete mode 100644 drivers/gpu/drm/mediatek/mtk_drm_gem.c
 delete mode 100644 drivers/gpu/drm/mediatek/mtk_drm_gem.h

diff --git a/drivers/gpu/drm/mediatek/Makefile 
b/drivers/gpu/drm/mediatek/Makefile
index 82ae49c64221..50a50e86738f 100644
--- a/drivers/gpu/drm/mediatek/Makefile
+++ b/drivers/gpu/drm/mediatek/Makefile
@@ -8,7 +8,6 @@ mediatek-drm-y := mtk_disp_color.o \
  mtk_drm_ddp_comp.o \
  mtk_drm_drv.o \
  mtk_drm_fb.o \
- mtk_drm_gem.o \
  mtk_drm_plane.o \
  mtk_dsi.o \
  mtk_mipi_tx.o \
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c 
b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
index 34a731755791..638d57e8ac12 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
@@ -11,6 +11,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -18,7 +19,6 @@
 #include "mtk_drm_crtc.h"
 #include "mtk_drm_ddp.h"
 #include "mtk_drm_ddp_comp.h"
-#include "mtk_drm_gem.h"
 #include "mtk_drm_plane.h"
 
 /**
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c 
b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index 352b81a7a670..36f32507e5fb 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -28,7 +28,6 @@
 #include "mtk_drm_ddp_comp.h"
 #include "mtk_drm_drv.h"
 #include "mtk_drm_fb.h"
-#include "mtk_drm_gem.h"
 
 #define DRIVER_NAME "mediatek"
 #define DRIVER_DESC "Mediatek SoC DRM"
@@ -335,16 +334,14 @@ static void mtk_drm_kms_deinit(struct drm_device *drm)
drm_mode_config_cleanup(drm);
 }
 
-static const struct file_operations mtk_drm_fops = {
-   .owner = THIS_MODULE,
-   .open = drm_open,
-   .release = drm_release,
-   .unlocked_ioctl = drm_ioctl,
-   .mmap = mtk_drm_gem_mmap,
-   .poll = drm_poll,
-   .read = drm_read,
-   .compat_ioctl = drm_compat_ioctl,
-};
+DEFINE_DRM_GEM_CMA_FOPS(mtk_drm_fops);
+
+static int mtk_drm_gem_dumb_create(struct drm_file *file_priv,
+  struct drm_device *dev,
+  struct drm_mode_create_dumb *args)
+{
+   return drm_gem_cma_dumb_create_internal(file_priv, dev, args);
+}
 
 /*
  * We need to override this because the device used to import the memory is
@@ -361,18 +358,15 @@ struct drm_gem_object *mtk_drm_gem_prime_import(struct 
drm_device *dev,
 static struct drm_driver mtk_drm_driver = {
.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
 
-   .gem_free_object_unlocked = mtk_drm_gem_free_object,
.gem_vm_ops = _gem_cma_vm_ops,
+   .gem_create_object = drm_cma_gem_create_object_default_funcs,
.dumb_create = mtk_drm_gem_dumb_create,
 
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_prime_import = mtk_drm_gem_prime_import,
-   .gem_prime_get_sg_table = mtk_gem_prime_get_sg_table,
-   .gem_prime_import_sg_table = mtk_gem_prime_import_sg_table,
-   .gem_prime_mmap = mtk_drm_gem_mmap_buf,
-   .gem_prime_vmap = mtk_drm_gem_prime_vmap,
-   .gem_prime_vunmap = mtk_drm_gem_prime_vunmap,
+   .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table_vmap,
+   .gem_prime_mmap = drm_gem_prime_mmap,
.fops = _drm_fops,
 
.name = DRIVER_NAME,
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_fb.c 
b/drivers/gpu/drm/mediatek/mtk_drm_fb.c
index 3f230a28a2dc..596b4d5ed002 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_fb.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_fb.c
@@ -14,7 +14,6 @@
 
 #include "mtk_drm_drv.h"
 #include "mtk_drm_fb.h"
-#include "mtk_drm_gem.h"
 
 static const struct drm_framebuffer_funcs mtk_drm_fb_funcs = {
.create_handle = drm_gem_fb_create_handle,
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c 
b/drivers/gpu/drm/mediatek/mtk_drm_gem.c
deleted file mode 100644
index ca672f1d140d..
---