drm: Create DEFINE_DRM_GEM_CMA_FOPS and roll it out to drivers
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Wed, 8 Mar 2017 14:12:56 +0000 (15:12 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Tue, 14 Mar 2017 13:38:34 +0000 (14:38 +0100)
Less code ftw.

This converts all drivers except the tinydrm helper module. That one
needs more work, since it gets the THIS_MODULE reference from
tinydrm.ko instead of the actual driver module like it should.
Probably needs a similar trick like I used here with generating the
entire struct with a macro.

Cc: Noralf Trønnes <noralf@tronnes.org>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Reviewed-by: Liviu Dudau <Liviu.Dudau@arm.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170308141257.12119-24-daniel.vetter@ffwll.ch
17 files changed:
drivers/gpu/drm/arm/hdlcd_drv.c
drivers/gpu/drm/arm/malidp_drv.c
drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c
drivers/gpu/drm/drm_file.c
drivers/gpu/drm/drm_gem_cma_helper.c
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
drivers/gpu/drm/imx/imx-drm-core.c
drivers/gpu/drm/meson/meson_drv.c
drivers/gpu/drm/mxsfb/mxsfb_drv.c
drivers/gpu/drm/rcar-du/rcar_du_drv.c
drivers/gpu/drm/shmobile/shmob_drm_drv.c
drivers/gpu/drm/sti/sti_drv.c
drivers/gpu/drm/sun4i/sun4i_drv.c
drivers/gpu/drm/tilcdc/tilcdc_drv.c
drivers/gpu/drm/zte/zx_drm_drv.c
include/drm/drm_gem_cma_helper.h

index 4840dc27733900edda44a2f42077ac3e9859086e..0e74880b5e94e98c41ba0aeb1893d560c0418263 100644 (file)
@@ -239,17 +239,7 @@ static int hdlcd_debugfs_init(struct drm_minor *minor)
 }
 #endif
 
-static const struct file_operations fops = {
-       .owner          = THIS_MODULE,
-       .open           = drm_open,
-       .release        = drm_release,
-       .unlocked_ioctl = drm_ioctl,
-       .compat_ioctl   = drm_compat_ioctl,
-       .poll           = drm_poll,
-       .read           = drm_read,
-       .llseek         = noop_llseek,
-       .mmap           = drm_gem_cma_mmap,
-};
+DEFINE_DRM_GEM_CMA_FOPS(fops);
 
 static struct drm_driver hdlcd_driver = {
        .driver_features = DRIVER_HAVE_IRQ | DRIVER_GEM |
index a9608a2e5a29896f251523939ac9dfc4da1c2241..ea2546f766c2fb0725d9aba28208f7a6e360ddeb 100644 (file)
@@ -178,17 +178,7 @@ static void malidp_lastclose(struct drm_device *drm)
        drm_fbdev_cma_restore_mode(malidp->fbdev);
 }
 
-static const struct file_operations fops = {
-       .owner = THIS_MODULE,
-       .open = drm_open,
-       .release = drm_release,
-       .unlocked_ioctl = drm_ioctl,
-       .compat_ioctl = drm_compat_ioctl,
-       .poll = drm_poll,
-       .read = drm_read,
-       .llseek = noop_llseek,
-       .mmap = drm_gem_cma_mmap,
-};
+DEFINE_DRM_GEM_CMA_FOPS(fops);
 
 static struct drm_driver malidp_driver = {
        .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC |
index 970bd87d7ccec26a8699eb5fb2f289c4b4cb2d69..178acbf5f6c53c3be897ad49df152bbd03a7f5f0 100644 (file)
@@ -724,17 +724,7 @@ static void atmel_hlcdc_dc_irq_uninstall(struct drm_device *dev)
        regmap_read(dc->hlcdc->regmap, ATMEL_HLCDC_ISR, &isr);
 }
 
-static const struct file_operations fops = {
-       .owner              = THIS_MODULE,
-       .open               = drm_open,
-       .release            = drm_release,
-       .unlocked_ioctl     = drm_ioctl,
-       .compat_ioctl       = drm_compat_ioctl,
-       .poll               = drm_poll,
-       .read               = drm_read,
-       .llseek             = no_llseek,
-       .mmap               = drm_gem_cma_mmap,
-};
+DEFINE_DRM_GEM_CMA_FOPS(fops);
 
 static struct drm_driver atmel_hlcdc_dc_driver = {
        .driver_features = DRIVER_HAVE_IRQ | DRIVER_GEM |
index 92848fe75ea6666353d7d4d0ac60551a29aaf0bd..b42c1334112c424d2309302cbc0973cb1a7a6c71 100644 (file)
@@ -89,6 +89,9 @@ DEFINE_MUTEX(drm_global_mutex);
  *             .mmap = drm_gem_mmap,
  *     };
  *
+ * For CMA based drivers there is the DEFINE_DRM_GEM_CMA_FOPS() macro to make
+ * this simpler.
+ *
  * FIXME: We should have a macro for this (and the CMA version) so that drivers
  * don't have to repeat it all the time.
  */
index 906984d4bec234dfd1de742f5cfb38ea7ec64860..f478a597cd792b25e1ed2d09c13860433701d32a 100644 (file)
@@ -338,6 +338,9 @@ static int drm_gem_cma_mmap_obj(struct drm_gem_cma_object *cma_obj,
  * as their ->mmap() handler in the DRM device file's file_operations
  * structure.
  *
+ * Instead of directly referencing this function, drivers should use the
+ * DEFINE_DRM_GEM_CMA_FOPS().macro.
+ *
  * Returns:
  * 0 on success or a negative error code on failure.
  */
index b5391c124c64787a100ed5af51e21685f67122ab..6e00f4b267f1742fa96763345cccd38e1ca84c26 100644 (file)
@@ -161,17 +161,7 @@ static void fsl_dcu_drm_lastclose(struct drm_device *dev)
        drm_fbdev_cma_restore_mode(fsl_dev->fbdev);
 }
 
-static const struct file_operations fsl_dcu_drm_fops = {
-       .owner          = THIS_MODULE,
-       .open           = drm_open,
-       .release        = drm_release,
-       .unlocked_ioctl = drm_ioctl,
-       .compat_ioctl   = drm_compat_ioctl,
-       .poll           = drm_poll,
-       .read           = drm_read,
-       .llseek         = no_llseek,
-       .mmap           = drm_gem_cma_mmap,
-};
+DEFINE_DRM_GEM_CMA_FOPS(fsl_dcu_drm_fops);
 
 static struct drm_driver fsl_dcu_drm_driver = {
        .driver_features        = DRIVER_HAVE_IRQ | DRIVER_GEM | DRIVER_MODESET
index 7ec93aec7e880ec524a1b1bc0eec21721b8311b9..df4f50713e54adade26cc5b95e230fd61851e46e 100644 (file)
@@ -146,17 +146,7 @@ err_mode_config_cleanup:
        return ret;
 }
 
-static const struct file_operations kirin_drm_fops = {
-       .owner          = THIS_MODULE,
-       .open           = drm_open,
-       .release        = drm_release,
-       .unlocked_ioctl = drm_ioctl,
-       .compat_ioctl   = drm_compat_ioctl,
-       .poll           = drm_poll,
-       .read           = drm_read,
-       .llseek         = no_llseek,
-       .mmap           = drm_gem_cma_mmap,
-};
+DEFINE_DRM_GEM_CMA_FOPS(kirin_drm_fops);
 
 static int kirin_gem_cma_dumb_create(struct drm_file *file,
                                     struct drm_device *dev,
index 4b7b92a7bcf7bdeb37aa5af08ecb336148c25d5d..70736615983c1360031bb3be6c73a2924efe3179 100644 (file)
@@ -57,16 +57,7 @@ static void imx_drm_driver_lastclose(struct drm_device *drm)
        drm_fbdev_cma_restore_mode(imxdrm->fbhelper);
 }
 
-static const struct file_operations imx_drm_driver_fops = {
-       .owner = THIS_MODULE,
-       .open = drm_open,
-       .release = drm_release,
-       .unlocked_ioctl = drm_ioctl,
-       .mmap = drm_gem_cma_mmap,
-       .poll = drm_poll,
-       .read = drm_read,
-       .llseek = noop_llseek,
-};
+DEFINE_DRM_GEM_CMA_FOPS(imx_drm_driver_fops);
 
 void imx_drm_connector_destroy(struct drm_connector *connector)
 {
index 8d17d0e59cbe12932a930e2ba5249306265113f1..bc562a07847b3e71591d4debb81c2f7b48210eef 100644 (file)
@@ -91,19 +91,7 @@ static irqreturn_t meson_irq(int irq, void *arg)
        return IRQ_HANDLED;
 }
 
-static const struct file_operations fops = {
-       .owner          = THIS_MODULE,
-       .open           = drm_open,
-       .release        = drm_release,
-       .unlocked_ioctl = drm_ioctl,
-#ifdef CONFIG_COMPAT
-       .compat_ioctl   = drm_compat_ioctl,
-#endif
-       .poll           = drm_poll,
-       .read           = drm_read,
-       .llseek         = no_llseek,
-       .mmap           = drm_gem_cma_mmap,
-};
+DEFINE_DRM_GEM_CMA_FOPS(fops);
 
 static struct drm_driver meson_driver = {
        .driver_features        = DRIVER_HAVE_IRQ | DRIVER_GEM |
index a4633ada8429d658f4362bbd4f8f18da55454462..5ac712325c758629869933f8246e3d400f7e4450 100644 (file)
@@ -319,19 +319,7 @@ static irqreturn_t mxsfb_irq_handler(int irq, void *data)
        return IRQ_HANDLED;
 }
 
-static const struct file_operations fops = {
-       .owner          = THIS_MODULE,
-       .open           = drm_open,
-       .release        = drm_release,
-       .unlocked_ioctl = drm_ioctl,
-#ifdef CONFIG_COMPAT
-       .compat_ioctl   = drm_compat_ioctl,
-#endif
-       .poll           = drm_poll,
-       .read           = drm_read,
-       .llseek         = noop_llseek,
-       .mmap           = drm_gem_cma_mmap,
-};
+DEFINE_DRM_GEM_CMA_FOPS(fops);
 
 static struct drm_driver mxsfb_driver = {
        .driver_features        = DRIVER_GEM | DRIVER_MODESET |
index 192346d4fb34a7eec178e20bf69d83561638248b..62a3b3e32153915844f0b3371720b944c9e716bd 100644 (file)
@@ -226,17 +226,7 @@ static void rcar_du_lastclose(struct drm_device *dev)
        drm_fbdev_cma_restore_mode(rcdu->fbdev);
 }
 
-static const struct file_operations rcar_du_fops = {
-       .owner          = THIS_MODULE,
-       .open           = drm_open,
-       .release        = drm_release,
-       .unlocked_ioctl = drm_ioctl,
-       .compat_ioctl   = drm_compat_ioctl,
-       .poll           = drm_poll,
-       .read           = drm_read,
-       .llseek         = no_llseek,
-       .mmap           = drm_gem_cma_mmap,
-};
+DEFINE_DRM_GEM_CMA_FOPS(rcar_du_fops);
 
 static struct drm_driver rcar_du_driver = {
        .driver_features        = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME
index 1c7b318b89980b713bb9e2174346e360e17f5c8a..800d1d2c435d0b7e4954728afc4d4bee9bae58cb 100644 (file)
@@ -127,17 +127,7 @@ static irqreturn_t shmob_drm_irq(int irq, void *arg)
        return IRQ_HANDLED;
 }
 
-static const struct file_operations shmob_drm_fops = {
-       .owner          = THIS_MODULE,
-       .open           = drm_open,
-       .release        = drm_release,
-       .unlocked_ioctl = drm_ioctl,
-       .compat_ioctl   = drm_compat_ioctl,
-       .poll           = drm_poll,
-       .read           = drm_read,
-       .llseek         = no_llseek,
-       .mmap           = drm_gem_cma_mmap,
-};
+DEFINE_DRM_GEM_CMA_FOPS(shmob_drm_fops);
 
 static struct drm_driver shmob_drm_driver = {
        .driver_features        = DRIVER_HAVE_IRQ | DRIVER_GEM | DRIVER_MODESET
index 6003c664ba0b26777eefd0e6ad7b96d2e6905695..a4b5742832690052c058a2898c2fc0492e8b7fcc 100644 (file)
@@ -167,16 +167,7 @@ static void sti_mode_config_init(struct drm_device *dev)
        dev->mode_config.funcs = &sti_mode_config_funcs;
 }
 
-static const struct file_operations sti_driver_fops = {
-       .owner = THIS_MODULE,
-       .open = drm_open,
-       .mmap = drm_gem_cma_mmap,
-       .poll = drm_poll,
-       .read = drm_read,
-       .unlocked_ioctl = drm_ioctl,
-       .compat_ioctl = drm_compat_ioctl,
-       .release = drm_release,
-};
+DEFINE_DRM_GEM_CMA_FOPS(sti_driver_fops);
 
 static struct drm_driver sti_driver = {
        .driver_features = DRIVER_MODESET |
index 9ccf7c4deb6d32e409a39562607abb4f8ed6617e..329ea56106a5c1e546d4dbd9b0f654884f0b3b6d 100644 (file)
 #include "sun4i_framebuffer.h"
 #include "sun4i_layer.h"
 
-static const struct file_operations sun4i_drv_fops = {
-       .owner          = THIS_MODULE,
-       .open           = drm_open,
-       .release        = drm_release,
-       .unlocked_ioctl = drm_ioctl,
-       .compat_ioctl   = drm_compat_ioctl,
-       .poll           = drm_poll,
-       .read           = drm_read,
-       .llseek         = no_llseek,
-       .mmap           = drm_gem_cma_mmap,
-};
+DEFINE_DRM_GEM_CMA_FOPS(sun4i_drv_fops);
 
 static struct drm_driver sun4i_drv_driver = {
        .driver_features        = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | DRIVER_ATOMIC,
index 5b4ed0ea77683ff375d8928b12c31820618428e7..d7ae5be56d12cf01a2c5b3686f7a754405d84f71 100644 (file)
@@ -529,17 +529,7 @@ static int tilcdc_debugfs_init(struct drm_minor *minor)
 }
 #endif
 
-static const struct file_operations fops = {
-       .owner              = THIS_MODULE,
-       .open               = drm_open,
-       .release            = drm_release,
-       .unlocked_ioctl     = drm_ioctl,
-       .compat_ioctl       = drm_compat_ioctl,
-       .poll               = drm_poll,
-       .read               = drm_read,
-       .llseek             = no_llseek,
-       .mmap               = drm_gem_cma_mmap,
-};
+DEFINE_DRM_GEM_CMA_FOPS(fops);
 
 static struct drm_driver tilcdc_driver = {
        .driver_features    = (DRIVER_HAVE_IRQ | DRIVER_GEM | DRIVER_MODESET |
index b24a70ba4b839fd488be2f0b9883b5c6d8418736..614e854f6be590f8f237de3e009db6367f875ffa 100644 (file)
@@ -53,19 +53,7 @@ static void zx_drm_lastclose(struct drm_device *drm)
        drm_fbdev_cma_restore_mode(priv->fbdev);
 }
 
-static const struct file_operations zx_drm_fops = {
-       .owner = THIS_MODULE,
-       .open = drm_open,
-       .release = drm_release,
-       .unlocked_ioctl = drm_ioctl,
-#ifdef CONFIG_COMPAT
-       .compat_ioctl = drm_compat_ioctl,
-#endif
-       .poll = drm_poll,
-       .read = drm_read,
-       .llseek = noop_llseek,
-       .mmap = drm_gem_cma_mmap,
-};
+DEFINE_DRM_GEM_CMA_FOPS(zx_drm_fops);
 
 static struct drm_driver zx_drm_driver = {
        .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME |
index 2abcd5190cc137f6e4714d2c0b7c3ae03459febd..f962d33667cff59a9af0e4287060911fd8904be3 100644 (file)
@@ -26,6 +26,32 @@ to_drm_gem_cma_obj(struct drm_gem_object *gem_obj)
        return container_of(gem_obj, struct drm_gem_cma_object, base);
 }
 
+/**
+ * DEFINE_DRM_GEM_CMA_FOPS() - macro to generate file operations for CMA drivers
+ * @name: name for the generated structure
+ *
+ * This macro autogenerates a suitable &struct file_operations for CMA based
+ * drivers, which can be assigned to &drm_driver.fops. Note that this structure
+ * cannot be shared between drivers, because it contains a reference to the
+ * current module using THIS_MODULE.
+ *
+ * Note that the declaration is already marked as static - if you need a
+ * non-static version of this you're probably doing it wrong and will break the
+ * THIS_MODULE reference by accident.
+ */
+#define DEFINE_DRM_GEM_CMA_FOPS(name) \
+       static const struct file_operations name = {\
+               .owner          = THIS_MODULE,\
+               .open           = drm_open,\
+               .release        = drm_release,\
+               .unlocked_ioctl = drm_ioctl,\
+               .compat_ioctl   = drm_compat_ioctl,\
+               .poll           = drm_poll,\
+               .read           = drm_read,\
+               .llseek         = noop_llseek,\
+               .mmap           = drm_gem_cma_mmap,\
+       }
+
 /* free GEM object */
 void drm_gem_cma_free_object(struct drm_gem_object *gem_obj);