drm/mode: use _object_find to find framebuffers.
[linux-2.6-block.git] / drivers / gpu / drm / drm_crtc.c
index f6191215b2cbc97c11fbfda5eeadb9f61b2387e8..0e4e25509c3d5c5bb9f821ba66d6c58c642b69de 100644 (file)
@@ -275,7 +275,8 @@ EXPORT_SYMBOL(drm_get_format_name);
 static int drm_mode_object_get_reg(struct drm_device *dev,
                                   struct drm_mode_object *obj,
                                   uint32_t obj_type,
-                                  bool register_obj)
+                                  bool register_obj,
+                                  void (*obj_free_cb)(struct kref *kref))
 {
        int ret;
 
@@ -288,6 +289,10 @@ static int drm_mode_object_get_reg(struct drm_device *dev,
                 */
                obj->id = ret;
                obj->type = obj_type;
+               if (obj_free_cb) {
+                       obj->free_cb = obj_free_cb;
+                       kref_init(&obj->refcount);
+               }
        }
        mutex_unlock(&dev->mode_config.idr_mutex);
 
@@ -311,7 +316,7 @@ static int drm_mode_object_get_reg(struct drm_device *dev,
 int drm_mode_object_get(struct drm_device *dev,
                        struct drm_mode_object *obj, uint32_t obj_type)
 {
-       return drm_mode_object_get_reg(dev, obj, obj_type, true);
+       return drm_mode_object_get_reg(dev, obj, obj_type, true, NULL);
 }
 
 static void drm_mode_object_register(struct drm_device *dev,
@@ -323,19 +328,24 @@ static void drm_mode_object_register(struct drm_device *dev,
 }
 
 /**
- * drm_mode_object_put - free a modeset identifer
+ * drm_mode_object_unregister - free a modeset identifer
  * @dev: DRM device
  * @object: object to free
  *
- * Free @id from @dev's unique identifier pool. Note that despite the _get
- * postfix modeset identifiers are _not_ reference counted. Hence don't use this
+ * Free @id from @dev's unique identifier pool.
+ * This function can be called multiple times, and guards against
+ * multiple removals.
+ * These modeset identifiers are _not_ reference counted. Hence don't use this
  * for reference counted modeset objects like framebuffers.
  */
-void drm_mode_object_put(struct drm_device *dev,
+void drm_mode_object_unregister(struct drm_device *dev,
                         struct drm_mode_object *object)
 {
        mutex_lock(&dev->mode_config.idr_mutex);
-       idr_remove(&dev->mode_config.crtc_idr, object->id);
+       if (object->id) {
+               idr_remove(&dev->mode_config.crtc_idr, object->id);
+               object->id = 0;
+       }
        mutex_unlock(&dev->mode_config.idr_mutex);
 }
 
@@ -352,8 +362,7 @@ static struct drm_mode_object *_object_find(struct drm_device *dev,
                obj = NULL;
        /* don't leak out unref'd fb's */
        if (obj &&
-           (obj->type == DRM_MODE_OBJECT_FB ||
-            obj->type == DRM_MODE_OBJECT_BLOB))
+           obj->type == DRM_MODE_OBJECT_BLOB)
                obj = NULL;
        mutex_unlock(&dev->mode_config.idr_mutex);
 
@@ -384,6 +393,48 @@ struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drm_mode_object_find);
 
+void drm_mode_object_unreference(struct drm_mode_object *obj)
+{
+       if (obj->free_cb) {
+               DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount));
+               kref_put(&obj->refcount, obj->free_cb);
+       }
+}
+EXPORT_SYMBOL(drm_mode_object_unreference);
+
+/**
+ * drm_mode_object_reference - incr the fb refcnt
+ * @obj: mode_object
+ *
+ * This function operates only on refcounted objects.
+ * This functions increments the object's refcount.
+ */
+void drm_mode_object_reference(struct drm_mode_object *obj)
+{
+       if (obj->free_cb) {
+               DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount));
+               kref_get(&obj->refcount);
+       }
+}
+EXPORT_SYMBOL(drm_mode_object_reference);
+
+static void drm_framebuffer_free(struct kref *kref)
+{
+       struct drm_framebuffer *fb =
+                       container_of(kref, struct drm_framebuffer, base.refcount);
+       struct drm_device *dev = fb->dev;
+
+       /*
+        * The lookup idr holds a weak reference, which has not necessarily been
+        * removed at this point. Check for that.
+        */
+       mutex_lock(&dev->mode_config.fb_lock);
+       drm_mode_object_unregister(dev, &fb->base);
+       mutex_unlock(&dev->mode_config.fb_lock);
+
+       fb->funcs->destroy(fb);
+}
+
 /**
  * drm_framebuffer_init - initialize a framebuffer
  * @dev: DRM device
@@ -408,12 +459,12 @@ int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
        int ret;
 
        mutex_lock(&dev->mode_config.fb_lock);
-       kref_init(&fb->refcount);
        INIT_LIST_HEAD(&fb->filp_head);
        fb->dev = dev;
        fb->funcs = funcs;
 
-       ret = drm_mode_object_get(dev, &fb->base, DRM_MODE_OBJECT_FB);
+       ret = drm_mode_object_get_reg(dev, &fb->base, DRM_MODE_OBJECT_FB,
+                                     true, drm_framebuffer_free);
        if (ret)
                goto out;
 
@@ -426,54 +477,6 @@ out:
 }
 EXPORT_SYMBOL(drm_framebuffer_init);
 
-/* dev->mode_config.fb_lock must be held! */
-static void __drm_framebuffer_unregister(struct drm_device *dev,
-                                        struct drm_framebuffer *fb)
-{
-       mutex_lock(&dev->mode_config.idr_mutex);
-       idr_remove(&dev->mode_config.crtc_idr, fb->base.id);
-       mutex_unlock(&dev->mode_config.idr_mutex);
-
-       fb->base.id = 0;
-}
-
-static void drm_framebuffer_free(struct kref *kref)
-{
-       struct drm_framebuffer *fb =
-                       container_of(kref, struct drm_framebuffer, refcount);
-       struct drm_device *dev = fb->dev;
-
-       /*
-        * The lookup idr holds a weak reference, which has not necessarily been
-        * removed at this point. Check for that.
-        */
-       mutex_lock(&dev->mode_config.fb_lock);
-       if (fb->base.id) {
-               /* Mark fb as reaped and drop idr ref. */
-               __drm_framebuffer_unregister(dev, fb);
-       }
-       mutex_unlock(&dev->mode_config.fb_lock);
-
-       fb->funcs->destroy(fb);
-}
-
-static struct drm_framebuffer *__drm_framebuffer_lookup(struct drm_device *dev,
-                                                       uint32_t id)
-{
-       struct drm_mode_object *obj = NULL;
-       struct drm_framebuffer *fb;
-
-       mutex_lock(&dev->mode_config.idr_mutex);
-       obj = idr_find(&dev->mode_config.crtc_idr, id);
-       if (!obj || (obj->type != DRM_MODE_OBJECT_FB) || (obj->id != id))
-               fb = NULL;
-       else
-               fb = obj_to_fb(obj);
-       mutex_unlock(&dev->mode_config.idr_mutex);
-
-       return fb;
-}
-
 /**
  * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference
  * @dev: drm device
@@ -486,12 +489,14 @@ static struct drm_framebuffer *__drm_framebuffer_lookup(struct drm_device *dev,
 struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
                                               uint32_t id)
 {
-       struct drm_framebuffer *fb;
+       struct drm_mode_object *obj;
+       struct drm_framebuffer *fb = NULL;
 
        mutex_lock(&dev->mode_config.fb_lock);
-       fb = __drm_framebuffer_lookup(dev, id);
-       if (fb) {
-               if (!kref_get_unless_zero(&fb->refcount))
+       obj = _object_find(dev, id, DRM_MODE_OBJECT_FB);
+       if (obj) {
+               fb = obj_to_fb(obj);
+               if (!kref_get_unless_zero(&fb->base.refcount))
                        fb = NULL;
        }
        mutex_unlock(&dev->mode_config.fb_lock);
@@ -500,32 +505,6 @@ struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drm_framebuffer_lookup);
 
-/**
- * drm_framebuffer_unreference - unref a framebuffer
- * @fb: framebuffer to unref
- *
- * This functions decrements the fb's refcount and frees it if it drops to zero.
- */
-void drm_framebuffer_unreference(struct drm_framebuffer *fb)
-{
-       DRM_DEBUG("%p: FB ID: %d (%d)\n", fb, fb->base.id, atomic_read(&fb->refcount.refcount));
-       kref_put(&fb->refcount, drm_framebuffer_free);
-}
-EXPORT_SYMBOL(drm_framebuffer_unreference);
-
-/**
- * drm_framebuffer_reference - incr the fb refcnt
- * @fb: framebuffer
- *
- * This functions increments the fb's refcount.
- */
-void drm_framebuffer_reference(struct drm_framebuffer *fb)
-{
-       DRM_DEBUG("%p: FB ID: %d (%d)\n", fb, fb->base.id, atomic_read(&fb->refcount.refcount));
-       kref_get(&fb->refcount);
-}
-EXPORT_SYMBOL(drm_framebuffer_reference);
-
 /**
  * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr
  * @fb: fb to unregister
@@ -546,7 +525,7 @@ void drm_framebuffer_unregister_private(struct drm_framebuffer *fb)
 
        mutex_lock(&dev->mode_config.fb_lock);
        /* Mark fb as reaped and drop idr ref. */
-       __drm_framebuffer_unregister(dev, fb);
+       drm_mode_object_unregister(dev, &fb->base);
        mutex_unlock(&dev->mode_config.fb_lock);
 }
 EXPORT_SYMBOL(drm_framebuffer_unregister_private);
@@ -621,7 +600,7 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb)
         * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot
         * in this manner.
         */
-       if (atomic_read(&fb->refcount.refcount) > 1) {
+       if (drm_framebuffer_read_refcount(fb) > 1) {
                drm_modeset_lock_all(dev);
                /* remove from any CRTC */
                drm_for_each_crtc(crtc, dev) {
@@ -707,7 +686,7 @@ int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
                                       drm_num_crtcs(dev));
        }
        if (!crtc->name) {
-               drm_mode_object_put(dev, &crtc->base);
+               drm_mode_object_unregister(dev, &crtc->base);
                return -ENOMEM;
        }
 
@@ -749,7 +728,7 @@ void drm_crtc_cleanup(struct drm_crtc *crtc)
 
        drm_modeset_lock_fini(&crtc->mutex);
 
-       drm_mode_object_put(dev, &crtc->base);
+       drm_mode_object_unregister(dev, &crtc->base);
        list_del(&crtc->head);
        dev->mode_config.num_crtc--;
 
@@ -911,7 +890,7 @@ int drm_connector_init(struct drm_device *dev,
 
        drm_modeset_lock_all(dev);
 
-       ret = drm_mode_object_get_reg(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR, false);
+       ret = drm_mode_object_get_reg(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR, false, NULL);
        if (ret)
                goto out_unlock;
 
@@ -974,7 +953,7 @@ out_put_id:
                ida_remove(&config->connector_ida, connector->connector_id);
 out_put:
        if (ret)
-               drm_mode_object_put(dev, &connector->base);
+               drm_mode_object_unregister(dev, &connector->base);
 
 out_unlock:
        drm_modeset_unlock_all(dev);
@@ -1012,7 +991,7 @@ void drm_connector_cleanup(struct drm_connector *connector)
                   connector->connector_id);
 
        kfree(connector->display_info.bus_formats);
-       drm_mode_object_put(dev, &connector->base);
+       drm_mode_object_unregister(dev, &connector->base);
        kfree(connector->name);
        connector->name = NULL;
        list_del(&connector->head);
@@ -1069,25 +1048,65 @@ void drm_connector_unregister(struct drm_connector *connector)
 }
 EXPORT_SYMBOL(drm_connector_unregister);
 
+/**
+ * drm_connector_register_all - register all connectors
+ * @dev: drm device
+ *
+ * This function registers all connectors in sysfs and other places so that
+ * userspace can start to access them. Drivers can call it after calling
+ * drm_dev_register() to complete the device registration, if they don't call
+ * drm_connector_register() on each connector individually.
+ *
+ * When a device is unplugged and should be removed from userspace access,
+ * call drm_connector_unregister_all(), which is the inverse of this
+ * function.
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ */
+int drm_connector_register_all(struct drm_device *dev)
+{
+       struct drm_connector *connector;
+       int ret;
+
+       mutex_lock(&dev->mode_config.mutex);
+
+       drm_for_each_connector(connector, dev) {
+               ret = drm_connector_register(connector);
+               if (ret)
+                       goto err;
+       }
+
+       mutex_unlock(&dev->mode_config.mutex);
+
+       return 0;
+
+err:
+       mutex_unlock(&dev->mode_config.mutex);
+       drm_connector_unregister_all(dev);
+       return ret;
+}
+EXPORT_SYMBOL(drm_connector_register_all);
 
 /**
- * drm_connector_unplug_all - unregister connector userspace interfaces
+ * drm_connector_unregister_all - unregister connector userspace interfaces
  * @dev: drm device
  *
- * This function unregisters all connector userspace interfaces in sysfs. Should
- * be call when the device is disconnected, e.g. from an usb driver's
- * ->disconnect callback.
+ * This functions unregisters all connectors from sysfs and other places so
+ * that userspace can no longer access them. Drivers should call this as the
+ * first step tearing down the device instace, or when the underlying
+ * physical device disappeared (e.g. USB unplug), right before calling
+ * drm_dev_unregister().
  */
-void drm_connector_unplug_all(struct drm_device *dev)
+void drm_connector_unregister_all(struct drm_device *dev)
 {
        struct drm_connector *connector;
 
        /* FIXME: taking the mode config mutex ends up in a clash with sysfs */
        list_for_each_entry(connector, &dev->mode_config.connector_list, head)
                drm_connector_unregister(connector);
-
 }
-EXPORT_SYMBOL(drm_connector_unplug_all);
+EXPORT_SYMBOL(drm_connector_unregister_all);
 
 /**
  * drm_encoder_init - Init a preallocated encoder
@@ -1140,7 +1159,7 @@ int drm_encoder_init(struct drm_device *dev,
 
 out_put:
        if (ret)
-               drm_mode_object_put(dev, &encoder->base);
+               drm_mode_object_unregister(dev, &encoder->base);
 
 out_unlock:
        drm_modeset_unlock_all(dev);
@@ -1149,6 +1168,29 @@ out_unlock:
 }
 EXPORT_SYMBOL(drm_encoder_init);
 
+/**
+ * drm_encoder_index - find the index of a registered encoder
+ * @encoder: encoder to find index for
+ *
+ * Given a registered encoder, return the index of that encoder within a DRM
+ * device's list of encoders.
+ */
+unsigned int drm_encoder_index(struct drm_encoder *encoder)
+{
+       unsigned int index = 0;
+       struct drm_encoder *tmp;
+
+       drm_for_each_encoder(tmp, encoder->dev) {
+               if (tmp == encoder)
+                       return index;
+
+               index++;
+       }
+
+       BUG();
+}
+EXPORT_SYMBOL(drm_encoder_index);
+
 /**
  * drm_encoder_cleanup - cleans up an initialised encoder
  * @encoder: encoder to cleanup
@@ -1160,7 +1202,7 @@ void drm_encoder_cleanup(struct drm_encoder *encoder)
        struct drm_device *dev = encoder->dev;
 
        drm_modeset_lock_all(dev);
-       drm_mode_object_put(dev, &encoder->base);
+       drm_mode_object_unregister(dev, &encoder->base);
        kfree(encoder->name);
        list_del(&encoder->head);
        dev->mode_config.num_encoder--;
@@ -1221,7 +1263,7 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
                                            GFP_KERNEL);
        if (!plane->format_types) {
                DRM_DEBUG_KMS("out of memory when allocating plane\n");
-               drm_mode_object_put(dev, &plane->base);
+               drm_mode_object_unregister(dev, &plane->base);
                return -ENOMEM;
        }
 
@@ -1237,7 +1279,7 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
        }
        if (!plane->name) {
                kfree(plane->format_types);
-               drm_mode_object_put(dev, &plane->base);
+               drm_mode_object_unregister(dev, &plane->base);
                return -ENOMEM;
        }
 
@@ -1317,7 +1359,7 @@ void drm_plane_cleanup(struct drm_plane *plane)
 
        drm_modeset_lock_all(dev);
        kfree(plane->format_types);
-       drm_mode_object_put(dev, &plane->base);
+       drm_mode_object_unregister(dev, &plane->base);
 
        BUG_ON(list_empty(&plane->head));
 
@@ -1531,6 +1573,41 @@ static int drm_mode_create_standard_properties(struct drm_device *dev)
                return -ENOMEM;
        dev->mode_config.prop_mode_id = prop;
 
+       prop = drm_property_create(dev,
+                       DRM_MODE_PROP_BLOB,
+                       "DEGAMMA_LUT", 0);
+       if (!prop)
+               return -ENOMEM;
+       dev->mode_config.degamma_lut_property = prop;
+
+       prop = drm_property_create_range(dev,
+                       DRM_MODE_PROP_IMMUTABLE,
+                       "DEGAMMA_LUT_SIZE", 0, UINT_MAX);
+       if (!prop)
+               return -ENOMEM;
+       dev->mode_config.degamma_lut_size_property = prop;
+
+       prop = drm_property_create(dev,
+                       DRM_MODE_PROP_BLOB,
+                       "CTM", 0);
+       if (!prop)
+               return -ENOMEM;
+       dev->mode_config.ctm_property = prop;
+
+       prop = drm_property_create(dev,
+                       DRM_MODE_PROP_BLOB,
+                       "GAMMA_LUT", 0);
+       if (!prop)
+               return -ENOMEM;
+       dev->mode_config.gamma_lut_property = prop;
+
+       prop = drm_property_create_range(dev,
+                       DRM_MODE_PROP_IMMUTABLE,
+                       "GAMMA_LUT_SIZE", 0, UINT_MAX);
+       if (!prop)
+               return -ENOMEM;
+       dev->mode_config.gamma_lut_size_property = prop;
+
        return 0;
 }
 
@@ -3396,6 +3473,7 @@ int drm_mode_rmfb(struct drm_device *dev,
 {
        struct drm_framebuffer *fb = NULL;
        struct drm_framebuffer *fbl = NULL;
+       struct drm_mode_object *obj;
        uint32_t *id = data;
        int found = 0;
 
@@ -3404,10 +3482,10 @@ int drm_mode_rmfb(struct drm_device *dev,
 
        mutex_lock(&file_priv->fbs_lock);
        mutex_lock(&dev->mode_config.fb_lock);
-       fb = __drm_framebuffer_lookup(dev, *id);
-       if (!fb)
+       obj = _object_find(dev, *id, DRM_MODE_OBJECT_FB);
+       if (!obj)
                goto fail_lookup;
-
+       fb = obj_to_fb(obj);
        list_for_each_entry(fbl, &file_priv->fbs, filp_head)
                if (fb == fbl)
                        found = 1;
@@ -3973,7 +4051,7 @@ void drm_property_destroy(struct drm_device *dev, struct drm_property *property)
 
        if (property->num_values)
                kfree(property->values);
-       drm_mode_object_put(dev, &property->base);
+       drm_mode_object_unregister(dev, &property->base);
        list_del(&property->head);
        kfree(property);
 }
@@ -4251,7 +4329,7 @@ static void drm_property_free_blob(struct kref *kref)
 
        list_del(&blob->head_global);
        list_del(&blob->head_file);
-       drm_mode_object_put(blob->dev, &blob->base);
+       drm_mode_object_unregister(blob->dev, &blob->base);
 
        kfree(blob);
 }
@@ -5254,7 +5332,6 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
        struct drm_crtc *crtc;
        struct drm_framebuffer *fb = NULL;
        struct drm_pending_vblank_event *e = NULL;
-       unsigned long flags;
        int ret = -EINVAL;
 
        if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS ||
@@ -5305,41 +5382,26 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
        }
 
        if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
-               ret = -ENOMEM;
-               spin_lock_irqsave(&dev->event_lock, flags);
-               if (file_priv->event_space < sizeof(e->event)) {
-                       spin_unlock_irqrestore(&dev->event_lock, flags);
-                       goto out;
-               }
-               file_priv->event_space -= sizeof(e->event);
-               spin_unlock_irqrestore(&dev->event_lock, flags);
-
-               e = kzalloc(sizeof(*e), GFP_KERNEL);
-               if (e == NULL) {
-                       spin_lock_irqsave(&dev->event_lock, flags);
-                       file_priv->event_space += sizeof(e->event);
-                       spin_unlock_irqrestore(&dev->event_lock, flags);
+               e = kzalloc(sizeof *e, GFP_KERNEL);
+               if (!e) {
+                       ret = -ENOMEM;
                        goto out;
                }
-
                e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
                e->event.base.length = sizeof(e->event);
                e->event.user_data = page_flip->user_data;
-               e->base.event = &e->event.base;
-               e->base.file_priv = file_priv;
-               e->base.destroy =
-                       (void (*) (struct drm_pending_event *)) kfree;
+               ret = drm_event_reserve_init(dev, file_priv, &e->base, &e->event.base);
+               if (ret) {
+                       kfree(e);
+                       goto out;
+               }
        }
 
        crtc->primary->old_fb = crtc->primary->fb;
        ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags);
        if (ret) {
-               if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
-                       spin_lock_irqsave(&dev->event_lock, flags);
-                       file_priv->event_space += sizeof(e->event);
-                       spin_unlock_irqrestore(&dev->event_lock, flags);
-                       kfree(e);
-               }
+               if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT)
+                       drm_event_cancel_free(dev, &e->base);
                /* Keep the old fb, don't unref it. */
                crtc->primary->old_fb = NULL;
        } else {
@@ -5719,6 +5781,48 @@ int drm_format_vert_chroma_subsampling(uint32_t format)
 }
 EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
 
+/**
+ * drm_format_plane_width - width of the plane given the first plane
+ * @width: width of the first plane
+ * @format: pixel format
+ * @plane: plane index
+ *
+ * Returns:
+ * The width of @plane, given that the width of the first plane is @width.
+ */
+int drm_format_plane_width(int width, uint32_t format, int plane)
+{
+       if (plane >= drm_format_num_planes(format))
+               return 0;
+
+       if (plane == 0)
+               return width;
+
+       return width / drm_format_horz_chroma_subsampling(format);
+}
+EXPORT_SYMBOL(drm_format_plane_width);
+
+/**
+ * drm_format_plane_height - height of the plane given the first plane
+ * @height: height of the first plane
+ * @format: pixel format
+ * @plane: plane index
+ *
+ * Returns:
+ * The height of @plane, given that the height of the first plane is @height.
+ */
+int drm_format_plane_height(int height, uint32_t format, int plane)
+{
+       if (plane >= drm_format_num_planes(format))
+               return 0;
+
+       if (plane == 0)
+               return height;
+
+       return height / drm_format_vert_chroma_subsampling(format);
+}
+EXPORT_SYMBOL(drm_format_plane_height);
+
 /**
  * drm_rotation_simplify() - Try to simplify the rotation
  * @rotation: Rotation to be simplified
@@ -5832,6 +5936,15 @@ void drm_mode_config_cleanup(struct drm_device *dev)
                drm_property_destroy(dev, property);
        }
 
+       list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list,
+                                head) {
+               plane->funcs->destroy(plane);
+       }
+
+       list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
+               crtc->funcs->destroy(crtc);
+       }
+
        list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list,
                                 head_global) {
                drm_property_unreference_blob(blob);
@@ -5847,16 +5960,7 @@ void drm_mode_config_cleanup(struct drm_device *dev)
         */
        WARN_ON(!list_empty(&dev->mode_config.fb_list));
        list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) {
-               drm_framebuffer_free(&fb->refcount);
-       }
-
-       list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list,
-                                head) {
-               plane->funcs->destroy(plane);
-       }
-
-       list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
-               crtc->funcs->destroy(crtc);
+               drm_framebuffer_free(&fb->base.refcount);
        }
 
        ida_destroy(&dev->mode_config.connector_ida);