drm: refcnt drm_framebuffer (v4.1)
[cascardo/linux.git] / include / drm / drm_crtc.h
index eb91d52..68fdb29 100644 (file)
@@ -218,6 +218,7 @@ struct drm_display_info {
 };
 
 struct drm_framebuffer_funcs {
+       /* note: use drm_framebuffer_remove() */
        void (*destroy)(struct drm_framebuffer *framebuffer);
        int (*create_handle)(struct drm_framebuffer *fb,
                             struct drm_file *file_priv,
@@ -242,6 +243,16 @@ struct drm_framebuffer_funcs {
 
 struct drm_framebuffer {
        struct drm_device *dev;
+       /*
+        * Note that the fb is refcounted for the benefit of driver internals,
+        * for example some hw, disabling a CRTC/plane is asynchronous, and
+        * scanout does not actually complete until the next vblank.  So some
+        * cleanup (like releasing the reference(s) on the backing GEM bo(s))
+        * should be deferred.  In cases like this, the driver would like to
+        * hold a ref to the fb even though it has already been removed from
+        * userspace perspective.
+        */
+       struct kref refcount;
        struct list_head head;
        struct drm_mode_object base;
        const struct drm_framebuffer_funcs *funcs;
@@ -919,6 +930,9 @@ extern void drm_framebuffer_set_object(struct drm_device *dev,
 extern int drm_framebuffer_init(struct drm_device *dev,
                                struct drm_framebuffer *fb,
                                const struct drm_framebuffer_funcs *funcs);
+extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
+extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
+extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
 extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
 extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);