mbox series

[v2,00/21] Convert all remaining drivers to GEM object functions

Message ID 20200915145958.19993-1-tzimmermann@suse.de
Headers show
Series Convert all remaining drivers to GEM object functions | expand

Message

Thomas Zimmermann Sept. 15, 2020, 2:59 p.m. UTC
The GEM and PRIME related callbacks in struct drm_driver are deprecated in
favor of GEM object functions in struct drm_gem_object_funcs. This patchset
converts the remaining drivers to object functions and removes most of the
obsolete interfaces.

Patches #1 to #16 and #18 to #19 convert DRM drivers to GEM object functions,
one by one. Each patch moves existing callbacks from struct drm_driver to an
instance of struct drm_gem_object_funcs, and sets these funcs when the GEM
object is initialized. The expection is .gem_prime_mmap. There are different
ways of how drivers implement the callback, and moving it to GEM object
functions requires a closer review for each.

Patch #17 fixes virtgpu to use GEM object functions where possible. The
driver recently introduced a function for one of the deprecated callbacks.

Patch #20 converts xlnx to CMA helper macros. There's no apparent reason
why the driver does the GEM setup on it's own. Using CMA helper macros
adds GEM object functions implicitly.

With most of the GEM and PRIME moved to GEM object functions, related code
in struct drm_driver and in the DRM core/helpers is being removed by patch
#21.

Further testing is welcome. I tested the drivers for which I have HW
available. These are gma500, i915, nouveau, radeon and vc4. The console,
Weston and Xorg apparently work with the patches applied.

v2:
	* moved code in amdgpu and radeon
	* made several functions static in various drivers
	* updated TODO-list item
	* fix virtgpu

Thomas Zimmermann (21):
  drm/amdgpu: Introduce GEM object functions
  drm/armada: Introduce GEM object functions
  drm/etnaviv: Introduce GEM object functions
  drm/exynos: Introduce GEM object functions
  drm/gma500: Introduce GEM object functions
  drm/i915: Introduce GEM object functions
  drm/mediatek: Introduce GEM object functions
  drm/msm: Introduce GEM object funcs
  drm/nouveau: Introduce GEM object functions
  drm/omapdrm: Introduce GEM object functions
  drm/pl111: Introduce GEM object functions
  drm/radeon: Introduce GEM object functions
  drm/rockchip: Convert to drm_gem_object_funcs
  drm/tegra: Introduce GEM object functions
  drm/vc4: Introduce GEM object functions
  drm/vgem: Introduce GEM object functions
  drm/virtgpu: Set PRIME export function in struct drm_gem_object_funcs
  drm/vkms: Introduce GEM object functions
  drm/xen: Introduce GEM object functions
  drm/xlnx: Initialize DRM driver instance with CMA helper macro
  drm: Remove obsolete GEM and PRIME callbacks from struct drm_driver

 Documentation/gpu/todo.rst                    |  7 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  6 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       | 23 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h       |  5 --
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c    |  1 +
 drivers/gpu/drm/armada/armada_drv.c           |  3 -
 drivers/gpu/drm/armada/armada_gem.c           | 12 ++-
 drivers/gpu/drm/armada/armada_gem.h           |  2 -
 drivers/gpu/drm/drm_gem.c                     | 35 ++------
 drivers/gpu/drm/drm_gem_cma_helper.c          |  6 +-
 drivers/gpu/drm/drm_prime.c                   | 17 ++--
 drivers/gpu/drm/etnaviv/etnaviv_drv.c         | 13 ---
 drivers/gpu/drm/etnaviv/etnaviv_drv.h         |  1 -
 drivers/gpu/drm/etnaviv/etnaviv_gem.c         | 19 ++++-
 drivers/gpu/drm/exynos/exynos_drm_drv.c       | 10 ---
 drivers/gpu/drm/exynos/exynos_drm_gem.c       | 15 ++++
 drivers/gpu/drm/gma500/framebuffer.c          |  2 +
 drivers/gpu/drm/gma500/gem.c                  | 18 +++-
 drivers/gpu/drm/gma500/gem.h                  |  3 +
 drivers/gpu/drm/gma500/psb_drv.c              |  9 --
 drivers/gpu/drm/gma500/psb_drv.h              |  2 -
 drivers/gpu/drm/i915/gem/i915_gem_object.c    | 21 ++++-
 drivers/gpu/drm/i915/gem/i915_gem_object.h    |  3 -
 drivers/gpu/drm/i915/i915_drv.c               |  4 -
 .../gpu/drm/i915/selftests/mock_gem_device.c  |  3 -
 drivers/gpu/drm/mediatek/mtk_drm_drv.c        |  5 --
 drivers/gpu/drm/mediatek/mtk_drm_gem.c        | 11 +++
 drivers/gpu/drm/msm/msm_drv.c                 | 13 ---
 drivers/gpu/drm/msm/msm_drv.h                 |  1 -
 drivers/gpu/drm/msm/msm_gem.c                 | 19 ++++-
 drivers/gpu/drm/nouveau/nouveau_drm.c         |  9 --
 drivers/gpu/drm/nouveau/nouveau_gem.c         | 13 +++
 drivers/gpu/drm/nouveau/nouveau_gem.h         |  2 +
 drivers/gpu/drm/nouveau/nouveau_prime.c       |  2 +
 drivers/gpu/drm/omapdrm/omap_drv.c            |  9 --
 drivers/gpu/drm/omapdrm/omap_gem.c            | 18 +++-
 drivers/gpu/drm/omapdrm/omap_gem.h            |  2 -
 drivers/gpu/drm/pl111/pl111_drv.c             |  5 +-
 drivers/gpu/drm/radeon/radeon_drv.c           | 23 +----
 drivers/gpu/drm/radeon/radeon_gem.c           | 31 ++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_drv.c   |  5 --
 drivers/gpu/drm/rockchip/rockchip_drm_gem.c   | 10 +++
 drivers/gpu/drm/tegra/drm.c                   |  4 -
 drivers/gpu/drm/tegra/gem.c                   |  8 ++
 drivers/gpu/drm/vc4/vc4_bo.c                  | 21 ++++-
 drivers/gpu/drm/vc4/vc4_drv.c                 | 12 ---
 drivers/gpu/drm/vc4/vc4_drv.h                 |  1 -
 drivers/gpu/drm/vgem/vgem_drv.c               | 21 +++--
 drivers/gpu/drm/virtio/virtgpu_drv.c          |  1 -
 drivers/gpu/drm/virtio/virtgpu_object.c       |  1 +
 drivers/gpu/drm/vkms/vkms_drv.c               |  8 --
 drivers/gpu/drm/vkms/vkms_gem.c               | 13 +++
 drivers/gpu/drm/xen/xen_drm_front.c           | 44 ++++------
 drivers/gpu/drm/xen/xen_drm_front.h           |  2 +
 drivers/gpu/drm/xen/xen_drm_front_gem.c       | 15 ++++
 drivers/gpu/drm/xlnx/zynqmp_dpsub.c           | 14 +--
 include/drm/drm_drv.h                         | 85 +------------------
 57 files changed, 319 insertions(+), 349 deletions(-)

--
2.28.0

Comments

Christian König Sept. 15, 2020, 3:08 p.m. UTC | #1
Am 15.09.20 um 16:59 schrieb Thomas Zimmermann:
> GEM object functions deprecate several similar callback interfaces in
> struct drm_driver. This patch replaces the per-driver callbacks with
> per-instance callbacks in radeon.
>
> v2:
> 	* move object-function instance to radeon_gem.c (Christian)
> 	* set callbacks in radeon_gem_object_create() (Christian)
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/radeon/radeon_drv.c | 23 +--------------------
>   drivers/gpu/drm/radeon/radeon_gem.c | 31 +++++++++++++++++++++++++----
>   2 files changed, 28 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
> index 4cd30613fa1d..65061c949aee 100644
> --- a/drivers/gpu/drm/radeon/radeon_drv.c
> +++ b/drivers/gpu/drm/radeon/radeon_drv.c
> @@ -124,13 +124,6 @@ void radeon_driver_irq_preinstall_kms(struct drm_device *dev);
>   int radeon_driver_irq_postinstall_kms(struct drm_device *dev);
>   void radeon_driver_irq_uninstall_kms(struct drm_device *dev);
>   irqreturn_t radeon_driver_irq_handler_kms(int irq, void *arg);
> -void radeon_gem_object_free(struct drm_gem_object *obj);
> -int radeon_gem_object_open(struct drm_gem_object *obj,
> -				struct drm_file *file_priv);
> -void radeon_gem_object_close(struct drm_gem_object *obj,
> -				struct drm_file *file_priv);
> -struct dma_buf *radeon_gem_prime_export(struct drm_gem_object *gobj,
> -					int flags);
>   extern int radeon_get_crtc_scanoutpos(struct drm_device *dev, unsigned int crtc,
>   				      unsigned int flags, int *vpos, int *hpos,
>   				      ktime_t *stime, ktime_t *etime,
> @@ -145,14 +138,9 @@ int radeon_mode_dumb_mmap(struct drm_file *filp,
>   int radeon_mode_dumb_create(struct drm_file *file_priv,
>   			    struct drm_device *dev,
>   			    struct drm_mode_create_dumb *args);
> -struct sg_table *radeon_gem_prime_get_sg_table(struct drm_gem_object *obj);
>   struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device *dev,
>   							struct dma_buf_attachment *,
>   							struct sg_table *sg);
> -int radeon_gem_prime_pin(struct drm_gem_object *obj);
> -void radeon_gem_prime_unpin(struct drm_gem_object *obj);
> -void *radeon_gem_prime_vmap(struct drm_gem_object *obj);
> -void radeon_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
>   
>   /* atpx handler */
>   #if defined(CONFIG_VGA_SWITCHEROO)
> @@ -550,7 +538,7 @@ long radeon_drm_ioctl(struct file *filp,
>   	}
>   
>   	ret = drm_ioctl(filp, cmd, arg);
> -	
> +
>   	pm_runtime_mark_last_busy(dev->dev);
>   	pm_runtime_put_autosuspend(dev->dev);
>   	return ret;
> @@ -609,22 +597,13 @@ static struct drm_driver kms_driver = {
>   	.irq_uninstall = radeon_driver_irq_uninstall_kms,
>   	.irq_handler = radeon_driver_irq_handler_kms,
>   	.ioctls = radeon_ioctls_kms,
> -	.gem_free_object_unlocked = radeon_gem_object_free,
> -	.gem_open_object = radeon_gem_object_open,
> -	.gem_close_object = radeon_gem_object_close,
>   	.dumb_create = radeon_mode_dumb_create,
>   	.dumb_map_offset = radeon_mode_dumb_mmap,
>   	.fops = &radeon_driver_kms_fops,
>   
>   	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
>   	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
> -	.gem_prime_export = radeon_gem_prime_export,
> -	.gem_prime_pin = radeon_gem_prime_pin,
> -	.gem_prime_unpin = radeon_gem_prime_unpin,
> -	.gem_prime_get_sg_table = radeon_gem_prime_get_sg_table,
>   	.gem_prime_import_sg_table = radeon_gem_prime_import_sg_table,
> -	.gem_prime_vmap = radeon_gem_prime_vmap,
> -	.gem_prime_vunmap = radeon_gem_prime_vunmap,
>   
>   	.name = DRIVER_NAME,
>   	.desc = DRIVER_DESC,
> diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
> index e5c4271e64ed..0ccd7213e41f 100644
> --- a/drivers/gpu/drm/radeon/radeon_gem.c
> +++ b/drivers/gpu/drm/radeon/radeon_gem.c
> @@ -35,7 +35,17 @@
>   
>   #include "radeon.h"
>   
> -void radeon_gem_object_free(struct drm_gem_object *gobj)
> +struct dma_buf *radeon_gem_prime_export(struct drm_gem_object *gobj,
> +					int flags);
> +struct sg_table *radeon_gem_prime_get_sg_table(struct drm_gem_object *obj);
> +int radeon_gem_prime_pin(struct drm_gem_object *obj);
> +void radeon_gem_prime_unpin(struct drm_gem_object *obj);
> +void *radeon_gem_prime_vmap(struct drm_gem_object *obj);
> +void radeon_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
> +
> +static const struct drm_gem_object_funcs radeon_gem_object_funcs;
> +
> +static void radeon_gem_object_free(struct drm_gem_object *gobj)
>   {
>   	struct radeon_bo *robj = gem_to_radeon_bo(gobj);
>   
> @@ -85,6 +95,7 @@ int radeon_gem_object_create(struct radeon_device *rdev, unsigned long size,
>   		return r;
>   	}
>   	*obj = &robj->tbo.base;
> +	(*obj)->funcs = &radeon_gem_object_funcs;
>   	robj->pid = task_pid_nr(current);
>   
>   	mutex_lock(&rdev->gem.mutex);
> @@ -146,7 +157,7 @@ void radeon_gem_fini(struct radeon_device *rdev)
>    * Call from drm_gem_handle_create which appear in both new and open ioctl
>    * case.
>    */
> -int radeon_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_priv)
> +static int radeon_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_priv)
>   {
>   	struct radeon_bo *rbo = gem_to_radeon_bo(obj);
>   	struct radeon_device *rdev = rbo->rdev;
> @@ -176,8 +187,8 @@ int radeon_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_pri
>   	return 0;
>   }
>   
> -void radeon_gem_object_close(struct drm_gem_object *obj,
> -			     struct drm_file *file_priv)
> +static void radeon_gem_object_close(struct drm_gem_object *obj,
> +				    struct drm_file *file_priv)
>   {
>   	struct radeon_bo *rbo = gem_to_radeon_bo(obj);
>   	struct radeon_device *rdev = rbo->rdev;
> @@ -216,6 +227,18 @@ static int radeon_gem_handle_lockup(struct radeon_device *rdev, int r)
>   	return r;
>   }
>   
> +static const struct drm_gem_object_funcs radeon_gem_object_funcs = {
> +	.free = radeon_gem_object_free,
> +	.open = radeon_gem_object_open,
> +	.close = radeon_gem_object_close,
> +	.export = radeon_gem_prime_export,
> +	.pin = radeon_gem_prime_pin,
> +	.unpin = radeon_gem_prime_unpin,
> +	.get_sg_table = radeon_gem_prime_get_sg_table,
> +	.vmap = radeon_gem_prime_vmap,
> +	.vunmap = radeon_gem_prime_vunmap,
> +};
> +
>   /*
>    * GEM ioctls.
>    */
Christian König Sept. 15, 2020, 3:25 p.m. UTC | #2
Added my rb to the amdgpu and radeon patches.

Should we pick those up through the amd branches or do you want to push 
everything to drm-misc-next?

I think the later since this should result in much merge clash.

Christian.

Am 15.09.20 um 16:59 schrieb Thomas Zimmermann:
> The GEM and PRIME related callbacks in struct drm_driver are deprecated in
> favor of GEM object functions in struct drm_gem_object_funcs. This patchset
> converts the remaining drivers to object functions and removes most of the
> obsolete interfaces.
>
> Patches #1 to #16 and #18 to #19 convert DRM drivers to GEM object functions,
> one by one. Each patch moves existing callbacks from struct drm_driver to an
> instance of struct drm_gem_object_funcs, and sets these funcs when the GEM
> object is initialized. The expection is .gem_prime_mmap. There are different
> ways of how drivers implement the callback, and moving it to GEM object
> functions requires a closer review for each.
>
> Patch #17 fixes virtgpu to use GEM object functions where possible. The
> driver recently introduced a function for one of the deprecated callbacks.
>
> Patch #20 converts xlnx to CMA helper macros. There's no apparent reason
> why the driver does the GEM setup on it's own. Using CMA helper macros
> adds GEM object functions implicitly.
>
> With most of the GEM and PRIME moved to GEM object functions, related code
> in struct drm_driver and in the DRM core/helpers is being removed by patch
> #21.
>
> Further testing is welcome. I tested the drivers for which I have HW
> available. These are gma500, i915, nouveau, radeon and vc4. The console,
> Weston and Xorg apparently work with the patches applied.
>
> v2:
> 	* moved code in amdgpu and radeon
> 	* made several functions static in various drivers
> 	* updated TODO-list item
> 	* fix virtgpu
>
> Thomas Zimmermann (21):
>    drm/amdgpu: Introduce GEM object functions
>    drm/armada: Introduce GEM object functions
>    drm/etnaviv: Introduce GEM object functions
>    drm/exynos: Introduce GEM object functions
>    drm/gma500: Introduce GEM object functions
>    drm/i915: Introduce GEM object functions
>    drm/mediatek: Introduce GEM object functions
>    drm/msm: Introduce GEM object funcs
>    drm/nouveau: Introduce GEM object functions
>    drm/omapdrm: Introduce GEM object functions
>    drm/pl111: Introduce GEM object functions
>    drm/radeon: Introduce GEM object functions
>    drm/rockchip: Convert to drm_gem_object_funcs
>    drm/tegra: Introduce GEM object functions
>    drm/vc4: Introduce GEM object functions
>    drm/vgem: Introduce GEM object functions
>    drm/virtgpu: Set PRIME export function in struct drm_gem_object_funcs
>    drm/vkms: Introduce GEM object functions
>    drm/xen: Introduce GEM object functions
>    drm/xlnx: Initialize DRM driver instance with CMA helper macro
>    drm: Remove obsolete GEM and PRIME callbacks from struct drm_driver
>
>   Documentation/gpu/todo.rst                    |  7 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  6 --
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       | 23 +++--
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h       |  5 --
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c    |  1 +
>   drivers/gpu/drm/armada/armada_drv.c           |  3 -
>   drivers/gpu/drm/armada/armada_gem.c           | 12 ++-
>   drivers/gpu/drm/armada/armada_gem.h           |  2 -
>   drivers/gpu/drm/drm_gem.c                     | 35 ++------
>   drivers/gpu/drm/drm_gem_cma_helper.c          |  6 +-
>   drivers/gpu/drm/drm_prime.c                   | 17 ++--
>   drivers/gpu/drm/etnaviv/etnaviv_drv.c         | 13 ---
>   drivers/gpu/drm/etnaviv/etnaviv_drv.h         |  1 -
>   drivers/gpu/drm/etnaviv/etnaviv_gem.c         | 19 ++++-
>   drivers/gpu/drm/exynos/exynos_drm_drv.c       | 10 ---
>   drivers/gpu/drm/exynos/exynos_drm_gem.c       | 15 ++++
>   drivers/gpu/drm/gma500/framebuffer.c          |  2 +
>   drivers/gpu/drm/gma500/gem.c                  | 18 +++-
>   drivers/gpu/drm/gma500/gem.h                  |  3 +
>   drivers/gpu/drm/gma500/psb_drv.c              |  9 --
>   drivers/gpu/drm/gma500/psb_drv.h              |  2 -
>   drivers/gpu/drm/i915/gem/i915_gem_object.c    | 21 ++++-
>   drivers/gpu/drm/i915/gem/i915_gem_object.h    |  3 -
>   drivers/gpu/drm/i915/i915_drv.c               |  4 -
>   .../gpu/drm/i915/selftests/mock_gem_device.c  |  3 -
>   drivers/gpu/drm/mediatek/mtk_drm_drv.c        |  5 --
>   drivers/gpu/drm/mediatek/mtk_drm_gem.c        | 11 +++
>   drivers/gpu/drm/msm/msm_drv.c                 | 13 ---
>   drivers/gpu/drm/msm/msm_drv.h                 |  1 -
>   drivers/gpu/drm/msm/msm_gem.c                 | 19 ++++-
>   drivers/gpu/drm/nouveau/nouveau_drm.c         |  9 --
>   drivers/gpu/drm/nouveau/nouveau_gem.c         | 13 +++
>   drivers/gpu/drm/nouveau/nouveau_gem.h         |  2 +
>   drivers/gpu/drm/nouveau/nouveau_prime.c       |  2 +
>   drivers/gpu/drm/omapdrm/omap_drv.c            |  9 --
>   drivers/gpu/drm/omapdrm/omap_gem.c            | 18 +++-
>   drivers/gpu/drm/omapdrm/omap_gem.h            |  2 -
>   drivers/gpu/drm/pl111/pl111_drv.c             |  5 +-
>   drivers/gpu/drm/radeon/radeon_drv.c           | 23 +----
>   drivers/gpu/drm/radeon/radeon_gem.c           | 31 ++++++-
>   drivers/gpu/drm/rockchip/rockchip_drm_drv.c   |  5 --
>   drivers/gpu/drm/rockchip/rockchip_drm_gem.c   | 10 +++
>   drivers/gpu/drm/tegra/drm.c                   |  4 -
>   drivers/gpu/drm/tegra/gem.c                   |  8 ++
>   drivers/gpu/drm/vc4/vc4_bo.c                  | 21 ++++-
>   drivers/gpu/drm/vc4/vc4_drv.c                 | 12 ---
>   drivers/gpu/drm/vc4/vc4_drv.h                 |  1 -
>   drivers/gpu/drm/vgem/vgem_drv.c               | 21 +++--
>   drivers/gpu/drm/virtio/virtgpu_drv.c          |  1 -
>   drivers/gpu/drm/virtio/virtgpu_object.c       |  1 +
>   drivers/gpu/drm/vkms/vkms_drv.c               |  8 --
>   drivers/gpu/drm/vkms/vkms_gem.c               | 13 +++
>   drivers/gpu/drm/xen/xen_drm_front.c           | 44 ++++------
>   drivers/gpu/drm/xen/xen_drm_front.h           |  2 +
>   drivers/gpu/drm/xen/xen_drm_front_gem.c       | 15 ++++
>   drivers/gpu/drm/xlnx/zynqmp_dpsub.c           | 14 +--
>   include/drm/drm_drv.h                         | 85 +------------------
>   57 files changed, 319 insertions(+), 349 deletions(-)
>
> --
> 2.28.0
>
Hyun Kwon Sept. 15, 2020, 6:39 p.m. UTC | #3
Hi Tomas,

Thanks for the patch.

On Tue, Sep 15, 2020 at 08:53:46AM -0700, Laurent Pinchart wrote:
> Hi Thomas,
> 
> Thank you for the patch.
> 
> On Tue, Sep 15, 2020 at 04:59:57PM +0200, Thomas Zimmermann wrote:
> > The xlnx driver uses CMA helpers with default callback functions.
> > Initialize the driver structure with the rsp CMA helper macro. The
> > driver is being converted to use GEM object functions as part of
> > this change.
> > 
> > Two callbacks, .dumb_destroy and .gem_prime_import, were initialized
> > to their default implementations, so they are just kept empty now.
> > 
> > v2:
> > 	* initialize with DRM_GEM_CMA_DRIVER_OPS_WITH_DUMB_CREATE (Laurent)
> > 
> > Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 

Reviewed-by: Hyun Kwon <hyun.kwon@xilinx.com>

Thanks,
-hyun

> > ---
> >  drivers/gpu/drm/xlnx/zynqmp_dpsub.c | 14 +-------------
> >  1 file changed, 1 insertion(+), 13 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/xlnx/zynqmp_dpsub.c b/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
> > index 8e69303aad3f..f3ffc3703a0e 100644
> > --- a/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
> > +++ b/drivers/gpu/drm/xlnx/zynqmp_dpsub.c
> > @@ -80,19 +80,7 @@ static struct drm_driver zynqmp_dpsub_drm_driver = {
> >  	.driver_features		= DRIVER_MODESET | DRIVER_GEM |
> >  					  DRIVER_ATOMIC,
> >  
> > -	.prime_handle_to_fd		= drm_gem_prime_handle_to_fd,
> > -	.prime_fd_to_handle		= drm_gem_prime_fd_to_handle,
> > -	.gem_prime_export		= drm_gem_prime_export,
> > -	.gem_prime_import		= drm_gem_prime_import,
> > -	.gem_prime_get_sg_table		= drm_gem_cma_prime_get_sg_table,
> > -	.gem_prime_import_sg_table	= drm_gem_cma_prime_import_sg_table,
> > -	.gem_prime_vmap			= drm_gem_cma_prime_vmap,
> > -	.gem_prime_vunmap		= drm_gem_cma_prime_vunmap,
> > -	.gem_prime_mmap			= drm_gem_cma_prime_mmap,
> > -	.gem_free_object_unlocked	= drm_gem_cma_free_object,
> > -	.gem_vm_ops			= &drm_gem_cma_vm_ops,
> > -	.dumb_create			= zynqmp_dpsub_dumb_create,
> > -	.dumb_destroy			= drm_gem_dumb_destroy,
> > +	DRM_GEM_CMA_DRIVER_OPS_WITH_DUMB_CREATE(zynqmp_dpsub_dumb_create),
> >  
> >  	.fops				= &zynqmp_dpsub_drm_fops,
> >  
> 
> -- 
> Regards,
> 
> Laurent Pinchart
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Daniel Vetter Sept. 16, 2020, 10:03 a.m. UTC | #4
On Tue, Sep 15, 2020 at 04:59:41PM +0200, Thomas Zimmermann wrote:
> GEM object functions deprecate several similar callback interfaces in
> struct drm_driver. This patch replaces the per-driver callbacks with
> per-instance callbacks in exynos. The only exception is gem_prime_mmap,
> which is non-trivial to convert.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
>  drivers/gpu/drm/exynos/exynos_drm_drv.c | 10 ----------
>  drivers/gpu/drm/exynos/exynos_drm_gem.c | 15 +++++++++++++++
>  2 files changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
> index dbd80f1e4c78..fe46680ca208 100644
> --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
> +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
> @@ -75,11 +75,6 @@ static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
>  	file->driver_priv = NULL;
>  }
>  
> -static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
> -	.open = drm_gem_vm_open,
> -	.close = drm_gem_vm_close,
> -};
> -
>  static const struct drm_ioctl_desc exynos_ioctls[] = {
>  	DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
>  			DRM_RENDER_ALLOW),
> @@ -124,16 +119,11 @@ static struct drm_driver exynos_drm_driver = {
>  	.open			= exynos_drm_open,
>  	.lastclose		= drm_fb_helper_lastclose,
>  	.postclose		= exynos_drm_postclose,
> -	.gem_free_object_unlocked = exynos_drm_gem_free_object,
> -	.gem_vm_ops		= &exynos_drm_gem_vm_ops,
>  	.dumb_create		= exynos_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	= exynos_drm_gem_prime_import,
> -	.gem_prime_get_sg_table	= exynos_drm_gem_prime_get_sg_table,
>  	.gem_prime_import_sg_table	= exynos_drm_gem_prime_import_sg_table,
> -	.gem_prime_vmap		= exynos_drm_gem_prime_vmap,
> -	.gem_prime_vunmap	= exynos_drm_gem_prime_vunmap,
>  	.gem_prime_mmap		= exynos_drm_gem_prime_mmap,
>  	.ioctls			= exynos_ioctls,
>  	.num_ioctls		= ARRAY_SIZE(exynos_ioctls),
> diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c
> index efa476858db5..69a5cf28b4ae 100644
> --- a/drivers/gpu/drm/exynos/exynos_drm_gem.c
> +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c
> @@ -129,6 +129,19 @@ void exynos_drm_gem_destroy(struct exynos_drm_gem *exynos_gem)
>  	kfree(exynos_gem);
>  }
>  
> +static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
> +	.open = drm_gem_vm_open,
> +	.close = drm_gem_vm_close,
> +};

Hm moving the drm_gem_cma_vm_ops into drm_gem.h or so and maybe calling
them drm_gem_simple_ops or so would remove a pile of these. But perhaps a
quick follow up series.

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

> +
> +static const struct drm_gem_object_funcs exynos_drm_gem_object_funcs = {
> +	.free = exynos_drm_gem_free_object,
> +	.get_sg_table = exynos_drm_gem_prime_get_sg_table,
> +	.vmap = exynos_drm_gem_prime_vmap,
> +	.vunmap	= exynos_drm_gem_prime_vunmap,
> +	.vm_ops = &exynos_drm_gem_vm_ops,
> +};
> +
>  static struct exynos_drm_gem *exynos_drm_gem_init(struct drm_device *dev,
>  						  unsigned long size)
>  {
> @@ -143,6 +156,8 @@ static struct exynos_drm_gem *exynos_drm_gem_init(struct drm_device *dev,
>  	exynos_gem->size = size;
>  	obj = &exynos_gem->base;
>  
> +	obj->funcs = &exynos_drm_gem_object_funcs;
> +
>  	ret = drm_gem_object_init(dev, obj, size);
>  	if (ret < 0) {
>  		DRM_DEV_ERROR(dev->dev, "failed to initialize gem object\n");
> -- 
> 2.28.0
>
Thomas Zimmermann Sept. 16, 2020, 10:36 a.m. UTC | #5
Hi

Am 16.09.20 um 12:03 schrieb Daniel Vetter:
> On Tue, Sep 15, 2020 at 04:59:41PM +0200, Thomas Zimmermann wrote:
>> GEM object functions deprecate several similar callback interfaces in
>> struct drm_driver. This patch replaces the per-driver callbacks with
>> per-instance callbacks in exynos. The only exception is gem_prime_mmap,
>> which is non-trivial to convert.
>>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>> ---
>>  drivers/gpu/drm/exynos/exynos_drm_drv.c | 10 ----------
>>  drivers/gpu/drm/exynos/exynos_drm_gem.c | 15 +++++++++++++++
>>  2 files changed, 15 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
>> index dbd80f1e4c78..fe46680ca208 100644
>> --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
>> +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
>> @@ -75,11 +75,6 @@ static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
>>  	file->driver_priv = NULL;
>>  }
>>  
>> -static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
>> -	.open = drm_gem_vm_open,
>> -	.close = drm_gem_vm_close,
>> -};
>> -
>>  static const struct drm_ioctl_desc exynos_ioctls[] = {
>>  	DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
>>  			DRM_RENDER_ALLOW),
>> @@ -124,16 +119,11 @@ static struct drm_driver exynos_drm_driver = {
>>  	.open			= exynos_drm_open,
>>  	.lastclose		= drm_fb_helper_lastclose,
>>  	.postclose		= exynos_drm_postclose,
>> -	.gem_free_object_unlocked = exynos_drm_gem_free_object,
>> -	.gem_vm_ops		= &exynos_drm_gem_vm_ops,
>>  	.dumb_create		= exynos_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	= exynos_drm_gem_prime_import,
>> -	.gem_prime_get_sg_table	= exynos_drm_gem_prime_get_sg_table,
>>  	.gem_prime_import_sg_table	= exynos_drm_gem_prime_import_sg_table,
>> -	.gem_prime_vmap		= exynos_drm_gem_prime_vmap,
>> -	.gem_prime_vunmap	= exynos_drm_gem_prime_vunmap,
>>  	.gem_prime_mmap		= exynos_drm_gem_prime_mmap,
>>  	.ioctls			= exynos_ioctls,
>>  	.num_ioctls		= ARRAY_SIZE(exynos_ioctls),
>> diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c
>> index efa476858db5..69a5cf28b4ae 100644
>> --- a/drivers/gpu/drm/exynos/exynos_drm_gem.c
>> +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c
>> @@ -129,6 +129,19 @@ void exynos_drm_gem_destroy(struct exynos_drm_gem *exynos_gem)
>>  	kfree(exynos_gem);
>>  }
>>  
>> +static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
>> +	.open = drm_gem_vm_open,
>> +	.close = drm_gem_vm_close,
>> +};
> 
> Hm moving the drm_gem_cma_vm_ops into drm_gem.h or so and maybe calling
> them drm_gem_simple_ops or so would remove a pile of these. But perhaps a
> quick follow up series.

Good idea. Several interfaces use the term 'default' in their name, so
something like drm_gem_default_vm_ops seems appropriate.

BTW is there a reason why we have file operations like
DEFINE_DRM_GEM_CMA_FOPS() in each module? It seems like this could also
be provided by the rsp memory-manager library.

Best regards
Thomas

> 
> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> 
>> +
>> +static const struct drm_gem_object_funcs exynos_drm_gem_object_funcs = {
>> +	.free = exynos_drm_gem_free_object,
>> +	.get_sg_table = exynos_drm_gem_prime_get_sg_table,
>> +	.vmap = exynos_drm_gem_prime_vmap,
>> +	.vunmap	= exynos_drm_gem_prime_vunmap,
>> +	.vm_ops = &exynos_drm_gem_vm_ops,
>> +};
>> +
>>  static struct exynos_drm_gem *exynos_drm_gem_init(struct drm_device *dev,
>>  						  unsigned long size)
>>  {
>> @@ -143,6 +156,8 @@ static struct exynos_drm_gem *exynos_drm_gem_init(struct drm_device *dev,
>>  	exynos_gem->size = size;
>>  	obj = &exynos_gem->base;
>>  
>> +	obj->funcs = &exynos_drm_gem_object_funcs;
>> +
>>  	ret = drm_gem_object_init(dev, obj, size);
>>  	if (ret < 0) {
>>  		DRM_DEV_ERROR(dev->dev, "failed to initialize gem object\n");
>> -- 
>> 2.28.0
>>
>
Daniel Vetter Sept. 16, 2020, 11:21 a.m. UTC | #6
On Tue, Sep 15, 2020 at 04:59:40PM +0200, Thomas Zimmermann wrote:
> GEM object functions deprecate several similar callback interfaces in
> struct drm_driver. This patch replaces the per-driver callbacks with
> per-instance callbacks in etnaviv. The only exception is gem_prime_mmap,
> which is non-trivial to convert.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
>  drivers/gpu/drm/etnaviv/etnaviv_drv.c | 13 -------------
>  drivers/gpu/drm/etnaviv/etnaviv_drv.h |  1 -
>  drivers/gpu/drm/etnaviv/etnaviv_gem.c | 19 ++++++++++++++++++-
>  3 files changed, 18 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
> index a9a3afaef9a1..aa270b79e585 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
> @@ -468,12 +468,6 @@ static const struct drm_ioctl_desc etnaviv_ioctls[] = {
>  	ETNA_IOCTL(PM_QUERY_SIG, pm_query_sig, DRM_RENDER_ALLOW),
>  };
>  
> -static const struct vm_operations_struct vm_ops = {
> -	.fault = etnaviv_gem_fault,
> -	.open = drm_gem_vm_open,
> -	.close = drm_gem_vm_close,
> -};
> -
>  static const struct file_operations fops = {
>  	.owner              = THIS_MODULE,
>  	.open               = drm_open,
> @@ -490,16 +484,9 @@ static struct drm_driver etnaviv_drm_driver = {
>  	.driver_features    = DRIVER_GEM | DRIVER_RENDER,
>  	.open               = etnaviv_open,
>  	.postclose           = etnaviv_postclose,
> -	.gem_free_object_unlocked = etnaviv_gem_free_object,
> -	.gem_vm_ops         = &vm_ops,
>  	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
>  	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
> -	.gem_prime_pin      = etnaviv_gem_prime_pin,
> -	.gem_prime_unpin    = etnaviv_gem_prime_unpin,
> -	.gem_prime_get_sg_table = etnaviv_gem_prime_get_sg_table,
>  	.gem_prime_import_sg_table = etnaviv_gem_prime_import_sg_table,
> -	.gem_prime_vmap     = etnaviv_gem_prime_vmap,
> -	.gem_prime_vunmap   = etnaviv_gem_prime_vunmap,
>  	.gem_prime_mmap     = etnaviv_gem_prime_mmap,
>  #ifdef CONFIG_DEBUG_FS
>  	.debugfs_init       = etnaviv_debugfs_init,
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h
> index 4d8dc9236e5f..914f0867ff71 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h
> @@ -49,7 +49,6 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
>  		struct drm_file *file);
>  
>  int etnaviv_gem_mmap(struct file *filp, struct vm_area_struct *vma);
> -vm_fault_t etnaviv_gem_fault(struct vm_fault *vmf);
>  int etnaviv_gem_mmap_offset(struct drm_gem_object *obj, u64 *offset);
>  struct sg_table *etnaviv_gem_prime_get_sg_table(struct drm_gem_object *obj);
>  void *etnaviv_gem_prime_vmap(struct drm_gem_object *obj);
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
> index ea19f1d27275..312e9d58d5a7 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c
> @@ -171,7 +171,7 @@ int etnaviv_gem_mmap(struct file *filp, struct vm_area_struct *vma)
>  	return obj->ops->mmap(obj, vma);
>  }
>  
> -vm_fault_t etnaviv_gem_fault(struct vm_fault *vmf)
> +static vm_fault_t etnaviv_gem_fault(struct vm_fault *vmf)
>  {
>  	struct vm_area_struct *vma = vmf->vma;
>  	struct drm_gem_object *obj = vma->vm_private_data;
> @@ -561,6 +561,22 @@ void etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj)
>  	mutex_unlock(&priv->gem_lock);
>  }
>  
> +static const struct vm_operations_struct vm_ops = {
> +	.fault = etnaviv_gem_fault,
> +	.open = drm_gem_vm_open,
> +	.close = drm_gem_vm_close,
> +};
> +
> +static const struct drm_gem_object_funcs etnaviv_gem_object_funcs = {
> +	.free = etnaviv_gem_free_object,
> +	.pin = etnaviv_gem_prime_pin,
> +	.unpin = etnaviv_gem_prime_unpin,
> +	.get_sg_table = etnaviv_gem_prime_get_sg_table,
> +	.vmap = etnaviv_gem_prime_vmap,
> +	.vunmap = etnaviv_gem_prime_vunmap,
> +	.vm_ops = &vm_ops,
> +};

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

> +
>  static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags,
>  	const struct etnaviv_gem_ops *ops, struct drm_gem_object **obj)
>  {
> @@ -595,6 +611,7 @@ static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags,
>  	INIT_LIST_HEAD(&etnaviv_obj->vram_list);
>  
>  	*obj = &etnaviv_obj->base;
> +	(*obj)->funcs = &etnaviv_gem_object_funcs;
>  
>  	return 0;
>  }
> -- 
> 2.28.0
>
Daniel Vetter Sept. 16, 2020, 11:31 a.m. UTC | #7
On Tue, Sep 15, 2020 at 04:59:42PM +0200, Thomas Zimmermann wrote:
> GEM object functions deprecate several similar callback interfaces in
> struct drm_driver. This patch replaces the per-driver callbacks with
> per-instance callbacks in gma500.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

> ---
>  drivers/gpu/drm/gma500/framebuffer.c |  2 ++
>  drivers/gpu/drm/gma500/gem.c         | 18 ++++++++++++++++--
>  drivers/gpu/drm/gma500/gem.h         |  3 +++
>  drivers/gpu/drm/gma500/psb_drv.c     |  9 ---------
>  drivers/gpu/drm/gma500/psb_drv.h     |  2 --
>  5 files changed, 21 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/gpu/drm/gma500/framebuffer.c b/drivers/gpu/drm/gma500/framebuffer.c
> index 54d9876b5305..5ede24fb44ae 100644
> --- a/drivers/gpu/drm/gma500/framebuffer.c
> +++ b/drivers/gpu/drm/gma500/framebuffer.c
> @@ -24,6 +24,7 @@
>  #include <drm/drm_gem_framebuffer_helper.h>
>  
>  #include "framebuffer.h"
> +#include "gem.h"
>  #include "gtt.h"
>  #include "psb_drv.h"
>  #include "psb_intel_drv.h"
> @@ -285,6 +286,7 @@ static struct gtt_range *psbfb_alloc(struct drm_device *dev, int aligned_size)
>  	/* Begin by trying to use stolen memory backing */
>  	backing = psb_gtt_alloc_range(dev, aligned_size, "fb", 1, PAGE_SIZE);
>  	if (backing) {
> +		backing->gem.funcs = &psb_gem_object_funcs;
>  		drm_gem_private_object_init(dev, &backing->gem, aligned_size);
>  		return backing;
>  	}
> diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c
> index f9c4b1d76f56..8f07de83b6fb 100644
> --- a/drivers/gpu/drm/gma500/gem.c
> +++ b/drivers/gpu/drm/gma500/gem.c
> @@ -18,7 +18,9 @@
>  
>  #include "psb_drv.h"
>  
> -void psb_gem_free_object(struct drm_gem_object *obj)
> +static vm_fault_t psb_gem_fault(struct vm_fault *vmf);
> +
> +static void psb_gem_free_object(struct drm_gem_object *obj)
>  {
>  	struct gtt_range *gtt = container_of(obj, struct gtt_range, gem);
>  
> @@ -36,6 +38,17 @@ int psb_gem_get_aperture(struct drm_device *dev, void *data,
>  	return -EINVAL;
>  }
>  
> +static const struct vm_operations_struct psb_gem_vm_ops = {
> +	.fault = psb_gem_fault,
> +	.open = drm_gem_vm_open,
> +	.close = drm_gem_vm_close,
> +};
> +
> +const struct drm_gem_object_funcs psb_gem_object_funcs = {
> +	.free = psb_gem_free_object,
> +	.vm_ops = &psb_gem_vm_ops,
> +};
> +
>  /**
>   *	psb_gem_create		-	create a mappable object
>   *	@file: the DRM file of the client
> @@ -63,6 +76,7 @@ int psb_gem_create(struct drm_file *file, struct drm_device *dev, u64 size,
>  		dev_err(dev->dev, "no memory for %lld byte GEM object\n", size);
>  		return -ENOSPC;
>  	}
> +	r->gem.funcs = &psb_gem_object_funcs;
>  	/* Initialize the extra goodies GEM needs to do all the hard work */
>  	if (drm_gem_object_init(dev, &r->gem, size) != 0) {
>  		psb_gtt_free_range(dev, r);
> @@ -123,7 +137,7 @@ int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
>   *	vma->vm_private_data points to the GEM object that is backing this
>   *	mapping.
>   */
> -vm_fault_t psb_gem_fault(struct vm_fault *vmf)
> +static vm_fault_t psb_gem_fault(struct vm_fault *vmf)
>  {
>  	struct vm_area_struct *vma = vmf->vma;
>  	struct drm_gem_object *obj;
> diff --git a/drivers/gpu/drm/gma500/gem.h b/drivers/gpu/drm/gma500/gem.h
> index 4a74dc623b6b..3741a711b9fd 100644
> --- a/drivers/gpu/drm/gma500/gem.h
> +++ b/drivers/gpu/drm/gma500/gem.h
> @@ -8,6 +8,9 @@
>  #ifndef _GEM_H
>  #define _GEM_H
>  
> +extern const struct drm_gem_object_funcs psb_gem_object_funcs;
> +
>  extern int psb_gem_create(struct drm_file *file, struct drm_device *dev,
>  			  u64 size, u32 *handlep, int stolen, u32 align);
> +
>  #endif
> diff --git a/drivers/gpu/drm/gma500/psb_drv.c b/drivers/gpu/drm/gma500/psb_drv.c
> index 34b4aae9a15e..b13376a6fb91 100644
> --- a/drivers/gpu/drm/gma500/psb_drv.c
> +++ b/drivers/gpu/drm/gma500/psb_drv.c
> @@ -480,12 +480,6 @@ static const struct dev_pm_ops psb_pm_ops = {
>  	.runtime_idle = psb_runtime_idle,
>  };
>  
> -static const struct vm_operations_struct psb_gem_vm_ops = {
> -	.fault = psb_gem_fault,
> -	.open = drm_gem_vm_open,
> -	.close = drm_gem_vm_close,
> -};
> -
>  static const struct file_operations psb_gem_fops = {
>  	.owner = THIS_MODULE,
>  	.open = drm_open,
> @@ -507,9 +501,6 @@ static struct drm_driver driver = {
>  	.irq_uninstall = psb_irq_uninstall,
>  	.irq_handler = psb_irq_handler,
>  
> -	.gem_free_object_unlocked = psb_gem_free_object,
> -	.gem_vm_ops = &psb_gem_vm_ops,
> -
>  	.dumb_create = psb_gem_dumb_create,
>  	.ioctls = psb_ioctls,
>  	.fops = &psb_gem_fops,
> diff --git a/drivers/gpu/drm/gma500/psb_drv.h b/drivers/gpu/drm/gma500/psb_drv.h
> index 956926341316..c71a5a4e912c 100644
> --- a/drivers/gpu/drm/gma500/psb_drv.h
> +++ b/drivers/gpu/drm/gma500/psb_drv.h
> @@ -735,12 +735,10 @@ extern const struct drm_connector_helper_funcs
>  extern const struct drm_connector_funcs psb_intel_lvds_connector_funcs;
>  
>  /* gem.c */
> -extern void psb_gem_free_object(struct drm_gem_object *obj);
>  extern int psb_gem_get_aperture(struct drm_device *dev, void *data,
>  			struct drm_file *file);
>  extern int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
>  			struct drm_mode_create_dumb *args);
> -extern vm_fault_t psb_gem_fault(struct vm_fault *vmf);
>  
>  /* psb_device.c */
>  extern const struct psb_ops psb_chip_ops;
> -- 
> 2.28.0
>
Daniel Vetter Sept. 16, 2020, 12:09 p.m. UTC | #8
On Tue, Sep 15, 2020 at 04:59:54PM +0200, Thomas Zimmermann wrote:
> GEM object functions deprecate several similar callback interfaces in
> struct drm_driver. This patch replaces virtgpu's per-driver PRIME export
> function with a per-object function.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

> ---
>  drivers/gpu/drm/virtio/virtgpu_drv.c    | 1 -
>  drivers/gpu/drm/virtio/virtgpu_object.c | 1 +
>  2 files changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.c b/drivers/gpu/drm/virtio/virtgpu_drv.c
> index b039f493bda9..1f8d6ed11d21 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_drv.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_drv.c
> @@ -203,7 +203,6 @@ static struct drm_driver driver = {
>  	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
>  	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
>  	.gem_prime_mmap = drm_gem_prime_mmap,
> -	.gem_prime_export = virtgpu_gem_prime_export,
>  	.gem_prime_import = virtgpu_gem_prime_import,
>  	.gem_prime_import_sg_table = virtgpu_gem_prime_import_sg_table,
>  
> diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c
> index 842f8b61aa89..4f7d7ea8194c 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_object.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_object.c
> @@ -108,6 +108,7 @@ static const struct drm_gem_object_funcs virtio_gpu_shmem_funcs = {
>  	.close = virtio_gpu_gem_object_close,
>  
>  	.print_info = drm_gem_shmem_print_info,
> +	.export = virtgpu_gem_prime_export,
>  	.pin = drm_gem_shmem_pin,
>  	.unpin = drm_gem_shmem_unpin,
>  	.get_sg_table = drm_gem_shmem_get_sg_table,
> -- 
> 2.28.0
>
Thomas Zimmermann Sept. 17, 2020, 7:05 a.m. UTC | #9
Hi

Am 15.09.20 um 17:25 schrieb Christian König:
> Added my rb to the amdgpu and radeon patches.
> 
> Should we pick those up through the amd branches or do you want to push
> everything to drm-misc-next?
> 
> I think the later since this should result in much merge clash.

Yes, preferable, I'd merge it all through drm-misc.

Best regards
Thomas

> 
> Christian.
> 
> Am 15.09.20 um 16:59 schrieb Thomas Zimmermann:
>> The GEM and PRIME related callbacks in struct drm_driver are
>> deprecated in
>> favor of GEM object functions in struct drm_gem_object_funcs. This
>> patchset
>> converts the remaining drivers to object functions and removes most of
>> the
>> obsolete interfaces.
>>
>> Patches #1 to #16 and #18 to #19 convert DRM drivers to GEM object
>> functions,
>> one by one. Each patch moves existing callbacks from struct drm_driver
>> to an
>> instance of struct drm_gem_object_funcs, and sets these funcs when the
>> GEM
>> object is initialized. The expection is .gem_prime_mmap. There are
>> different
>> ways of how drivers implement the callback, and moving it to GEM object
>> functions requires a closer review for each.
>>
>> Patch #17 fixes virtgpu to use GEM object functions where possible. The
>> driver recently introduced a function for one of the deprecated
>> callbacks.
>>
>> Patch #20 converts xlnx to CMA helper macros. There's no apparent reason
>> why the driver does the GEM setup on it's own. Using CMA helper macros
>> adds GEM object functions implicitly.
>>
>> With most of the GEM and PRIME moved to GEM object functions, related
>> code
>> in struct drm_driver and in the DRM core/helpers is being removed by
>> patch
>> #21.
>>
>> Further testing is welcome. I tested the drivers for which I have HW
>> available. These are gma500, i915, nouveau, radeon and vc4. The console,
>> Weston and Xorg apparently work with the patches applied.
>>
>> v2:
>>     * moved code in amdgpu and radeon
>>     * made several functions static in various drivers
>>     * updated TODO-list item
>>     * fix virtgpu
>>
>> Thomas Zimmermann (21):
>>    drm/amdgpu: Introduce GEM object functions
>>    drm/armada: Introduce GEM object functions
>>    drm/etnaviv: Introduce GEM object functions
>>    drm/exynos: Introduce GEM object functions
>>    drm/gma500: Introduce GEM object functions
>>    drm/i915: Introduce GEM object functions
>>    drm/mediatek: Introduce GEM object functions
>>    drm/msm: Introduce GEM object funcs
>>    drm/nouveau: Introduce GEM object functions
>>    drm/omapdrm: Introduce GEM object functions
>>    drm/pl111: Introduce GEM object functions
>>    drm/radeon: Introduce GEM object functions
>>    drm/rockchip: Convert to drm_gem_object_funcs
>>    drm/tegra: Introduce GEM object functions
>>    drm/vc4: Introduce GEM object functions
>>    drm/vgem: Introduce GEM object functions
>>    drm/virtgpu: Set PRIME export function in struct drm_gem_object_funcs
>>    drm/vkms: Introduce GEM object functions
>>    drm/xen: Introduce GEM object functions
>>    drm/xlnx: Initialize DRM driver instance with CMA helper macro
>>    drm: Remove obsolete GEM and PRIME callbacks from struct drm_driver
>>
>>   Documentation/gpu/todo.rst                    |  7 +-
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |  6 --
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       | 23 +++--
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h       |  5 --
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c    |  1 +
>>   drivers/gpu/drm/armada/armada_drv.c           |  3 -
>>   drivers/gpu/drm/armada/armada_gem.c           | 12 ++-
>>   drivers/gpu/drm/armada/armada_gem.h           |  2 -
>>   drivers/gpu/drm/drm_gem.c                     | 35 ++------
>>   drivers/gpu/drm/drm_gem_cma_helper.c          |  6 +-
>>   drivers/gpu/drm/drm_prime.c                   | 17 ++--
>>   drivers/gpu/drm/etnaviv/etnaviv_drv.c         | 13 ---
>>   drivers/gpu/drm/etnaviv/etnaviv_drv.h         |  1 -
>>   drivers/gpu/drm/etnaviv/etnaviv_gem.c         | 19 ++++-
>>   drivers/gpu/drm/exynos/exynos_drm_drv.c       | 10 ---
>>   drivers/gpu/drm/exynos/exynos_drm_gem.c       | 15 ++++
>>   drivers/gpu/drm/gma500/framebuffer.c          |  2 +
>>   drivers/gpu/drm/gma500/gem.c                  | 18 +++-
>>   drivers/gpu/drm/gma500/gem.h                  |  3 +
>>   drivers/gpu/drm/gma500/psb_drv.c              |  9 --
>>   drivers/gpu/drm/gma500/psb_drv.h              |  2 -
>>   drivers/gpu/drm/i915/gem/i915_gem_object.c    | 21 ++++-
>>   drivers/gpu/drm/i915/gem/i915_gem_object.h    |  3 -
>>   drivers/gpu/drm/i915/i915_drv.c               |  4 -
>>   .../gpu/drm/i915/selftests/mock_gem_device.c  |  3 -
>>   drivers/gpu/drm/mediatek/mtk_drm_drv.c        |  5 --
>>   drivers/gpu/drm/mediatek/mtk_drm_gem.c        | 11 +++
>>   drivers/gpu/drm/msm/msm_drv.c                 | 13 ---
>>   drivers/gpu/drm/msm/msm_drv.h                 |  1 -
>>   drivers/gpu/drm/msm/msm_gem.c                 | 19 ++++-
>>   drivers/gpu/drm/nouveau/nouveau_drm.c         |  9 --
>>   drivers/gpu/drm/nouveau/nouveau_gem.c         | 13 +++
>>   drivers/gpu/drm/nouveau/nouveau_gem.h         |  2 +
>>   drivers/gpu/drm/nouveau/nouveau_prime.c       |  2 +
>>   drivers/gpu/drm/omapdrm/omap_drv.c            |  9 --
>>   drivers/gpu/drm/omapdrm/omap_gem.c            | 18 +++-
>>   drivers/gpu/drm/omapdrm/omap_gem.h            |  2 -
>>   drivers/gpu/drm/pl111/pl111_drv.c             |  5 +-
>>   drivers/gpu/drm/radeon/radeon_drv.c           | 23 +----
>>   drivers/gpu/drm/radeon/radeon_gem.c           | 31 ++++++-
>>   drivers/gpu/drm/rockchip/rockchip_drm_drv.c   |  5 --
>>   drivers/gpu/drm/rockchip/rockchip_drm_gem.c   | 10 +++
>>   drivers/gpu/drm/tegra/drm.c                   |  4 -
>>   drivers/gpu/drm/tegra/gem.c                   |  8 ++
>>   drivers/gpu/drm/vc4/vc4_bo.c                  | 21 ++++-
>>   drivers/gpu/drm/vc4/vc4_drv.c                 | 12 ---
>>   drivers/gpu/drm/vc4/vc4_drv.h                 |  1 -
>>   drivers/gpu/drm/vgem/vgem_drv.c               | 21 +++--
>>   drivers/gpu/drm/virtio/virtgpu_drv.c          |  1 -
>>   drivers/gpu/drm/virtio/virtgpu_object.c       |  1 +
>>   drivers/gpu/drm/vkms/vkms_drv.c               |  8 --
>>   drivers/gpu/drm/vkms/vkms_gem.c               | 13 +++
>>   drivers/gpu/drm/xen/xen_drm_front.c           | 44 ++++------
>>   drivers/gpu/drm/xen/xen_drm_front.h           |  2 +
>>   drivers/gpu/drm/xen/xen_drm_front_gem.c       | 15 ++++
>>   drivers/gpu/drm/xlnx/zynqmp_dpsub.c           | 14 +--
>>   include/drm/drm_drv.h                         | 85 +------------------
>>   57 files changed, 319 insertions(+), 349 deletions(-)
>>
>> -- 
>> 2.28.0
>>
>