[PATCH] [rfc] drm: allow removal of legacy codepaths

Daniel Vetter daniel at ffwll.ch
Thu Apr 18 07:23:13 UTC 2019


On Thu, Apr 18, 2019 at 9:12 AM Dave Airlie <airlied at gmail.com> wrote:
>
> From: Dave Airlie <airlied at redhat.com>
>
> If you don't want the legacy drivers, then lets get rid of all the
> legacy codepaths from the core module.
>
> This drop the size of drm.ko for me by about 10%.
>  380515    7422    4192  392129   5fbc1 ../../drm-next-build/drivers/gpu/drm/drm.ko
>  356059    7346    4192  367597   59bed ../../drm-next-build/drivers/gpu/drm/drm.ko
>
> This could probably be done with less scattering of ifdefs

Just #ifdef in drm_legacy.h, they're all collected already. drm_lock.c
is also missing. And I for the ioctl stubs it would make sense to
return -EOPNOTSUPP, for consistency for what you get when legacy code
is still built in. Aside from these nits, I like.
-Daniel

>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  drivers/gpu/drm/Makefile        |  6 +++---
>  drivers/gpu/drm/drm_auth.c      |  4 ++--
>  drivers/gpu/drm/drm_drv.c       | 10 ++++++++++
>  drivers/gpu/drm/drm_file.c      | 12 ++++++++----
>  drivers/gpu/drm/drm_ioc32.c     | 13 ++++++++++++-
>  drivers/gpu/drm/drm_ioctl.c     | 14 ++++++++++----
>  drivers/gpu/drm/drm_irq.c       |  2 ++
>  drivers/gpu/drm/nouveau/Kconfig |  1 +
>  8 files changed, 48 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 7ebae3d45505..dcd11f623131 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -3,11 +3,10 @@
>  # Makefile for the drm device driver.  This driver provides support for the
>  # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
>
> -drm-y       := drm_auth.o drm_bufs.o drm_cache.o \
> -               drm_context.o drm_dma.o \
> +drm-y       := drm_auth.o drm_cache.o \
>                 drm_file.o drm_gem.o drm_ioctl.o drm_irq.o \
>                 drm_lock.o drm_memory.o drm_drv.o \
> -               drm_scatter.o drm_pci.o \
> +               drm_pci.o \
>                 drm_sysfs.o drm_hashtab.o drm_mm.o \
>                 drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o \
>                 drm_encoder_slave.o \
> @@ -21,6 +20,7 @@ drm-y       :=        drm_auth.o drm_bufs.o drm_cache.o \
>                 drm_syncobj.o drm_lease.o drm_writeback.o drm_client.o \
>                 drm_atomic_uapi.o
>
> +drm-$(CONFIG_DRM_LEGACY) += drm_bufs.o drm_context.o drm_dma.o drm_scatter.o
>  drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o
>  drm-$(CONFIG_DRM_VM) += drm_vm.o
>  drm-$(CONFIG_COMPAT) += drm_ioc32.o
> diff --git a/drivers/gpu/drm/drm_auth.c b/drivers/gpu/drm/drm_auth.c
> index 1669c42c40ed..a95982bc1e2b 100644
> --- a/drivers/gpu/drm/drm_auth.c
> +++ b/drivers/gpu/drm/drm_auth.c
> @@ -345,9 +345,9 @@ static void drm_master_destroy(struct kref *kref)
>
>         if (dev->driver->master_destroy)
>                 dev->driver->master_destroy(dev, master);
> -
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         drm_legacy_master_rmmaps(dev, master);
> -
> +#endif
>         idr_destroy(&master->magic_map);
>         idr_destroy(&master->leases);
>         idr_destroy(&master->lessee_idr);
> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
> index 50d849d1bc6e..54371d5a01b8 100644
> --- a/drivers/gpu/drm/drm_drv.c
> +++ b/drivers/gpu/drm/drm_drv.c
> @@ -696,7 +696,9 @@ int drm_dev_init(struct drm_device *dev,
>         if (ret)
>                 goto err_minors;
>
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         drm_legacy_ctxbitmap_init(dev);
> +#endif
>
>         if (drm_core_check_feature(dev, DRIVER_GEM)) {
>                 ret = drm_gem_init(dev);
> @@ -716,7 +718,9 @@ int drm_dev_init(struct drm_device *dev,
>         if (drm_core_check_feature(dev, DRIVER_GEM))
>                 drm_gem_destroy(dev);
>  err_ctxbitmap:
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         drm_legacy_ctxbitmap_cleanup(dev);
> +#endif
>         drm_ht_remove(&dev->map_hash);
>  err_minors:
>         drm_minor_free(dev, DRM_MINOR_PRIMARY);
> @@ -791,7 +795,9 @@ void drm_dev_fini(struct drm_device *dev)
>         if (drm_core_check_feature(dev, DRIVER_GEM))
>                 drm_gem_destroy(dev);
>
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         drm_legacy_ctxbitmap_cleanup(dev);
> +#endif
>         drm_ht_remove(&dev->map_hash);
>         drm_fs_inode_free(dev->anon_inode);
>
> @@ -1038,7 +1044,9 @@ EXPORT_SYMBOL(drm_dev_register);
>   */
>  void drm_dev_unregister(struct drm_device *dev)
>  {
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         struct drm_map_list *r_list, *list_temp;
> +#endif
>
>         if (drm_core_check_feature(dev, DRIVER_LEGACY))
>                 drm_lastclose(dev);
> @@ -1056,8 +1064,10 @@ void drm_dev_unregister(struct drm_device *dev)
>         if (dev->agp)
>                 drm_pci_agp_destroy(dev);
>
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head)
>                 drm_legacy_rmmap(dev, r_list->map);
> +#endif
>
>         remove_compat_control_link(dev);
>         drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
> diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c
> index 9701469a6e93..9e9064b54b3b 100644
> --- a/drivers/gpu/drm/drm_file.c
> +++ b/drivers/gpu/drm/drm_file.c
> @@ -228,10 +228,10 @@ void drm_file_free(struct drm_file *file)
>
>         if (drm_core_check_feature(dev, DRIVER_LEGACY))
>                 drm_legacy_lock_release(dev, file->filp);
> -
> +#if IS_ENABLED(CONFIG_DMA_LEGACY)
>         if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
>                 drm_legacy_reclaim_buffers(dev, file);
> -
> +#endif
>         drm_events_release(file);
>
>         if (drm_core_check_feature(dev, DRIVER_MODESET)) {
> @@ -245,7 +245,9 @@ void drm_file_free(struct drm_file *file)
>         if (drm_core_check_feature(dev, DRIVER_GEM))
>                 drm_gem_release(dev, file);
>
> +#if IS_ENABLED(CONFIG_DMA_LEGACY)
>         drm_legacy_ctxbitmap_flush(dev, file);
> +#endif
>
>         if (drm_is_primary_client(file))
>                 drm_master_release(file);
> @@ -284,11 +286,11 @@ static int drm_setup(struct drm_device * dev)
>                 if (ret != 0)
>                         return ret;
>         }
> -
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         ret = drm_legacy_dma_setup(dev);
>         if (ret < 0)
>                 return ret;
> -
> +#endif
>
>         DRM_DEBUG("\n");
>         return 0;
> @@ -434,9 +436,11 @@ static void drm_legacy_dev_reinit(struct drm_device *dev)
>
>         drm_legacy_agp_clear(dev);
>
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         drm_legacy_sg_cleanup(dev);
>         drm_legacy_vma_flush(dev);
>         drm_legacy_dma_takedown(dev);
> +#endif
>
>         mutex_unlock(&dev->struct_mutex);
>
> diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
> index 0e3043e08c69..374b372da58a 100644
> --- a/drivers/gpu/drm/drm_ioc32.c
> +++ b/drivers/gpu/drm/drm_ioc32.c
> @@ -156,6 +156,7 @@ static int compat_drm_setunique(struct file *file, unsigned int cmd,
>         return -EINVAL;
>  }
>
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>  typedef struct drm_map32 {
>         u32 offset;             /* Requested physical address (0 for SAREA) */
>         u32 size;               /* Requested physical size (bytes) */
> @@ -239,6 +240,7 @@ static int compat_drm_rmmap(struct file *file, unsigned int cmd,
>         map.handle = compat_ptr(handle);
>         return drm_ioctl_kernel(file, drm_legacy_rmmap_ioctl, &map, DRM_AUTH);
>  }
> +#endif
>
>  typedef struct drm_client32 {
>         int idx;        /* Which client desired? */
> @@ -301,6 +303,7 @@ static int compat_drm_getstats(struct file *file, unsigned int cmd,
>         return 0;
>  }
>
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>  typedef struct drm_buf_desc32 {
>         int count;               /* Number of buffers of this size */
>         int size;                /* Size in bytes */
> @@ -604,6 +607,7 @@ static int compat_drm_dma(struct file *file, unsigned int cmd,
>
>         return 0;
>  }
> +#endif
>
>  #if IS_ENABLED(CONFIG_AGP)
>  typedef struct drm_agp_mode32 {
> @@ -748,6 +752,7 @@ static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
>  }
>  #endif /* CONFIG_AGP */
>
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>  typedef struct drm_scatter_gather32 {
>         u32 size;       /**< In bytes -- will round to page boundary */
>         u32 handle;     /**< Used for mapping / unmapping */
> @@ -788,7 +793,7 @@ static int compat_drm_sg_free(struct file *file, unsigned int cmd,
>         return drm_ioctl_kernel(file, drm_legacy_sg_free, &request,
>                                 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
>  }
> -
> +#endif
>  #if defined(CONFIG_X86)
>  typedef struct drm_update_draw32 {
>         drm_drawable_t handle;
> @@ -903,10 +908,13 @@ static struct {
>  #define DRM_IOCTL32_DEF(n, f) [DRM_IOCTL_NR(n##32)] = {.fn = f, .name = #n}
>         DRM_IOCTL32_DEF(DRM_IOCTL_VERSION, compat_drm_version),
>         DRM_IOCTL32_DEF(DRM_IOCTL_GET_UNIQUE, compat_drm_getunique),
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         DRM_IOCTL32_DEF(DRM_IOCTL_GET_MAP, compat_drm_getmap),
> +#endif
>         DRM_IOCTL32_DEF(DRM_IOCTL_GET_CLIENT, compat_drm_getclient),
>         DRM_IOCTL32_DEF(DRM_IOCTL_GET_STATS, compat_drm_getstats),
>         DRM_IOCTL32_DEF(DRM_IOCTL_SET_UNIQUE, compat_drm_setunique),
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         DRM_IOCTL32_DEF(DRM_IOCTL_ADD_MAP, compat_drm_addmap),
>         DRM_IOCTL32_DEF(DRM_IOCTL_ADD_BUFS, compat_drm_addbufs),
>         DRM_IOCTL32_DEF(DRM_IOCTL_MARK_BUFS, compat_drm_markbufs),
> @@ -918,6 +926,7 @@ static struct {
>         DRM_IOCTL32_DEF(DRM_IOCTL_GET_SAREA_CTX, compat_drm_getsareactx),
>         DRM_IOCTL32_DEF(DRM_IOCTL_RES_CTX, compat_drm_resctx),
>         DRM_IOCTL32_DEF(DRM_IOCTL_DMA, compat_drm_dma),
> +#endif
>  #if IS_ENABLED(CONFIG_AGP)
>         DRM_IOCTL32_DEF(DRM_IOCTL_AGP_ENABLE, compat_drm_agp_enable),
>         DRM_IOCTL32_DEF(DRM_IOCTL_AGP_INFO, compat_drm_agp_info),
> @@ -926,8 +935,10 @@ static struct {
>         DRM_IOCTL32_DEF(DRM_IOCTL_AGP_BIND, compat_drm_agp_bind),
>         DRM_IOCTL32_DEF(DRM_IOCTL_AGP_UNBIND, compat_drm_agp_unbind),
>  #endif
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         DRM_IOCTL32_DEF(DRM_IOCTL_SG_ALLOC, compat_drm_sg_alloc),
>         DRM_IOCTL32_DEF(DRM_IOCTL_SG_FREE, compat_drm_sg_free),
> +#endif
>  #if defined(CONFIG_X86) || defined(CONFIG_IA64)
>         DRM_IOCTL32_DEF(DRM_IOCTL_UPDATE_DRAW, compat_drm_update_draw),
>  #endif
> diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> index ce8a70875bd5..7064d98df998 100644
> --- a/drivers/gpu/drm/drm_ioctl.c
> +++ b/drivers/gpu/drm/drm_ioctl.c
> @@ -560,7 +560,9 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
>         DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, DRM_UNLOCKED),
>         DRM_IOCTL_DEF(DRM_IOCTL_GET_MAGIC, drm_getmagic, DRM_UNLOCKED),
>         DRM_IOCTL_DEF(DRM_IOCTL_IRQ_BUSID, drm_irq_by_busid, DRM_MASTER|DRM_ROOT_ONLY),
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         DRM_IOCTL_DEF(DRM_IOCTL_GET_MAP, drm_legacy_getmap_ioctl, DRM_UNLOCKED),
> +#endif
>         DRM_IOCTL_DEF(DRM_IOCTL_GET_CLIENT, drm_getclient, DRM_UNLOCKED),
>         DRM_IOCTL_DEF(DRM_IOCTL_GET_STATS, drm_getstats, DRM_UNLOCKED),
>         DRM_IOCTL_DEF(DRM_IOCTL_GET_CAP, drm_getcap, DRM_UNLOCKED|DRM_RENDER_ALLOW),
> @@ -571,16 +573,16 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
>         DRM_IOCTL_DEF(DRM_IOCTL_BLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>         DRM_IOCTL_DEF(DRM_IOCTL_UNBLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>         DRM_IOCTL_DEF(DRM_IOCTL_AUTH_MAGIC, drm_authmagic, DRM_UNLOCKED|DRM_MASTER),
> -
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         DRM_IOCTL_DEF(DRM_IOCTL_ADD_MAP, drm_legacy_addmap_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>         DRM_IOCTL_DEF(DRM_IOCTL_RM_MAP, drm_legacy_rmmap_ioctl, DRM_AUTH),
>
>         DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_legacy_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>         DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_legacy_getsareactx, DRM_AUTH),
> -
> +#endif
>         DRM_IOCTL_DEF(DRM_IOCTL_SET_MASTER, drm_setmaster_ioctl, DRM_UNLOCKED|DRM_ROOT_ONLY),
>         DRM_IOCTL_DEF(DRM_IOCTL_DROP_MASTER, drm_dropmaster_ioctl, DRM_UNLOCKED|DRM_ROOT_ONLY),
> -
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         DRM_IOCTL_DEF(DRM_IOCTL_ADD_CTX, drm_legacy_addctx, DRM_AUTH|DRM_ROOT_ONLY),
>         DRM_IOCTL_DEF(DRM_IOCTL_RM_CTX, drm_legacy_rmctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>         DRM_IOCTL_DEF(DRM_IOCTL_MOD_CTX, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
> @@ -588,6 +590,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
>         DRM_IOCTL_DEF(DRM_IOCTL_SWITCH_CTX, drm_legacy_switchctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>         DRM_IOCTL_DEF(DRM_IOCTL_NEW_CTX, drm_legacy_newctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>         DRM_IOCTL_DEF(DRM_IOCTL_RES_CTX, drm_legacy_resctx, DRM_AUTH),
> +#endif
>
>         DRM_IOCTL_DEF(DRM_IOCTL_ADD_DRAW, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>         DRM_IOCTL_DEF(DRM_IOCTL_RM_DRAW, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
> @@ -597,14 +600,15 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
>
>         DRM_IOCTL_DEF(DRM_IOCTL_FINISH, drm_noop, DRM_AUTH),
>
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         DRM_IOCTL_DEF(DRM_IOCTL_ADD_BUFS, drm_legacy_addbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>         DRM_IOCTL_DEF(DRM_IOCTL_MARK_BUFS, drm_legacy_markbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>         DRM_IOCTL_DEF(DRM_IOCTL_INFO_BUFS, drm_legacy_infobufs, DRM_AUTH),
>         DRM_IOCTL_DEF(DRM_IOCTL_MAP_BUFS, drm_legacy_mapbufs, DRM_AUTH),
>         DRM_IOCTL_DEF(DRM_IOCTL_FREE_BUFS, drm_legacy_freebufs, DRM_AUTH),
>         DRM_IOCTL_DEF(DRM_IOCTL_DMA, drm_legacy_dma_ioctl, DRM_AUTH),
> -
>         DRM_IOCTL_DEF(DRM_IOCTL_CONTROL, drm_legacy_irq_control, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
> +#endif
>
>  #if IS_ENABLED(CONFIG_AGP)
>         DRM_IOCTL_DEF(DRM_IOCTL_AGP_ACQUIRE, drm_agp_acquire_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
> @@ -617,8 +621,10 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
>         DRM_IOCTL_DEF(DRM_IOCTL_AGP_UNBIND, drm_agp_unbind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>  #endif
>
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>         DRM_IOCTL_DEF(DRM_IOCTL_SG_ALLOC, drm_legacy_sg_alloc, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
>         DRM_IOCTL_DEF(DRM_IOCTL_SG_FREE, drm_legacy_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
> +#endif
>
>         DRM_IOCTL_DEF(DRM_IOCTL_WAIT_VBLANK, drm_wait_vblank_ioctl, DRM_UNLOCKED),
>
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index 9bd8908d5fd8..02f38cc9f468 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -213,6 +213,7 @@ int drm_irq_uninstall(struct drm_device *dev)
>  }
>  EXPORT_SYMBOL(drm_irq_uninstall);
>
> +#if IS_ENABLED(CONFIG_DRM_LEGACY)
>  int drm_legacy_irq_control(struct drm_device *dev, void *data,
>                            struct drm_file *file_priv)
>  {
> @@ -253,3 +254,4 @@ int drm_legacy_irq_control(struct drm_device *dev, void *data,
>                 return -EINVAL;
>         }
>  }
> +#endif
> diff --git a/drivers/gpu/drm/nouveau/Kconfig b/drivers/gpu/drm/nouveau/Kconfig
> index 688b6f618b65..e3865440839c 100644
> --- a/drivers/gpu/drm/nouveau/Kconfig
> +++ b/drivers/gpu/drm/nouveau/Kconfig
> @@ -23,6 +23,7 @@ config DRM_NOUVEAU
>
>  config NOUVEAU_LEGACY_CTX_SUPPORT
>         bool "Nouveau legacy context support"
> +       select DRM_LEGACY
>         default y
>         help
>           There was a version of the nouveau DDX that relied on legacy
> --
> 2.20.1
>
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel



-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch


More information about the dri-devel mailing list