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)
committerRaspbian kernel package updater <root@raspbian.org>
Sat, 31 Mar 2018 14:54:29 +0000 (15:54 +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>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Acked-by: Liviu Dudau <Liviu.Dudau@arm.com>
Reviewed-by: Liviu Dudau <Liviu.Dudau@arm.com>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
[rebased on 4.9, only macro no driver changes]
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
include/drm/drm_gem_cma_helper.h

index acd6af8a8e675b5b58856651f18f788257bcc868..0ba18f33752ea7a639c81a2c567d39bddbd6b4a0 100644 (file)
@@ -26,6 +26,46 @@ 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.
+ */
+#ifdef CONFIG_COMPAT
+#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,\
+       }
+#else
+#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,\
+               .poll           = drm_poll,\
+               .read           = drm_read,\
+               .llseek         = noop_llseek,\
+               .mmap           = drm_gem_cma_mmap,\
+       }
+#endif
+
 /* free GEM object */
 void drm_gem_cma_free_object(struct drm_gem_object *gem_obj);