]> git.ipfire.org Git - thirdparty/kernel/stable.git/blobdiff - drivers/gpu/drm/drm_atomic_helper.c
drm: don't block fb changes for async plane updates
[thirdparty/kernel/stable.git] / drivers / gpu / drm / drm_atomic_helper.c
index 0028591f3f959ced1ad520ee280fb481d7a52898..331478bd2ff860753b8aff75d114ad172c0c8471 100644 (file)
@@ -1462,6 +1462,8 @@ EXPORT_SYMBOL(drm_atomic_helper_async_check);
  * drm_atomic_async_check() succeeds. Async commits are not supposed to swap
  * the states like normal sync commits, but just do in-place changes on the
  * current state.
+ *
+ * TODO: Implement full swap instead of doing in-place changes.
  */
 void drm_atomic_helper_async_commit(struct drm_device *dev,
                                    struct drm_atomic_state *state)
@@ -1472,8 +1474,16 @@ void drm_atomic_helper_async_commit(struct drm_device *dev,
        int i;
 
        for_each_new_plane_in_state(state, plane, plane_state, i) {
+               struct drm_framebuffer *old_fb = plane->state->fb;
+
                funcs = plane->helper_private;
                funcs->atomic_async_update(plane, plane_state);
+
+               /*
+                * Make sure the FBs have been swapped so that cleanups in the
+                * new_state performs a cleanup in the old FB.
+                */
+               WARN_ON_ONCE(plane_state->fb != old_fb);
        }
 }
 EXPORT_SYMBOL(drm_atomic_helper_async_commit);
@@ -2683,31 +2693,9 @@ commit:
        return 0;
 }
 
-/**
- * drm_atomic_helper_disable_all - disable all currently active outputs
- * @dev: DRM device
- * @ctx: lock acquisition context
- *
- * Loops through all connectors, finding those that aren't turned off and then
- * turns them off by setting their DPMS mode to OFF and deactivating the CRTC
- * that they are connected to.
- *
- * This is used for example in suspend/resume to disable all currently active
- * functions when suspending. If you just want to shut down everything at e.g.
- * driver unload, look at drm_atomic_helper_shutdown().
- *
- * Note that if callers haven't already acquired all modeset locks this might
- * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
- *
- * Returns:
- * 0 on success or a negative error code on failure.
- *
- * See also:
- * drm_atomic_helper_suspend(), drm_atomic_helper_resume() and
- * drm_atomic_helper_shutdown().
- */
-int drm_atomic_helper_disable_all(struct drm_device *dev,
-                                 struct drm_modeset_acquire_ctx *ctx)
+static int __drm_atomic_helper_disable_all(struct drm_device *dev,
+                                          struct drm_modeset_acquire_ctx *ctx,
+                                          bool clean_old_fbs)
 {
        struct drm_atomic_state *state;
        struct drm_connector_state *conn_state;
@@ -2759,8 +2747,11 @@ int drm_atomic_helper_disable_all(struct drm_device *dev,
                        goto free;
 
                drm_atomic_set_fb_for_plane(plane_state, NULL);
-               plane_mask |= BIT(drm_plane_index(plane));
-               plane->old_fb = plane->fb;
+
+               if (clean_old_fbs) {
+                       plane->old_fb = plane->fb;
+                       plane_mask |= BIT(drm_plane_index(plane));
+               }
        }
 
        ret = drm_atomic_commit(state);
@@ -2771,6 +2762,34 @@ free:
        return ret;
 }
 
+/**
+ * drm_atomic_helper_disable_all - disable all currently active outputs
+ * @dev: DRM device
+ * @ctx: lock acquisition context
+ *
+ * Loops through all connectors, finding those that aren't turned off and then
+ * turns them off by setting their DPMS mode to OFF and deactivating the CRTC
+ * that they are connected to.
+ *
+ * This is used for example in suspend/resume to disable all currently active
+ * functions when suspending. If you just want to shut down everything at e.g.
+ * driver unload, look at drm_atomic_helper_shutdown().
+ *
+ * Note that if callers haven't already acquired all modeset locks this might
+ * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
+ *
+ * Returns:
+ * 0 on success or a negative error code on failure.
+ *
+ * See also:
+ * drm_atomic_helper_suspend(), drm_atomic_helper_resume() and
+ * drm_atomic_helper_shutdown().
+ */
+int drm_atomic_helper_disable_all(struct drm_device *dev,
+                                 struct drm_modeset_acquire_ctx *ctx)
+{
+       return __drm_atomic_helper_disable_all(dev, ctx, false);
+}
 EXPORT_SYMBOL(drm_atomic_helper_disable_all);
 
 /**
@@ -2793,7 +2812,7 @@ void drm_atomic_helper_shutdown(struct drm_device *dev)
        while (1) {
                ret = drm_modeset_lock_all_ctx(dev, &ctx);
                if (!ret)
-                       ret = drm_atomic_helper_disable_all(dev, &ctx);
+                       ret = __drm_atomic_helper_disable_all(dev, &ctx, true);
 
                if (ret != -EDEADLK)
                        break;
@@ -2890,23 +2909,18 @@ EXPORT_SYMBOL(drm_atomic_helper_suspend);
 int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state,
                                              struct drm_modeset_acquire_ctx *ctx)
 {
-       int i;
+       int i, ret;
        struct drm_plane *plane;
        struct drm_plane_state *new_plane_state;
        struct drm_connector *connector;
        struct drm_connector_state *new_conn_state;
        struct drm_crtc *crtc;
        struct drm_crtc_state *new_crtc_state;
-       unsigned plane_mask = 0;
-       struct drm_device *dev = state->dev;
-       int ret;
 
        state->acquire_ctx = ctx;
 
-       for_each_new_plane_in_state(state, plane, new_plane_state, i) {
-               plane_mask |= BIT(drm_plane_index(plane));
+       for_each_new_plane_in_state(state, plane, new_plane_state, i)
                state->planes[i].old_state = plane->state;
-       }
 
        for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
                state->crtcs[i].old_state = crtc->state;
@@ -2915,8 +2929,8 @@ int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state,
                state->connectors[i].old_state = connector->state;
 
        ret = drm_atomic_commit(state);
-       if (plane_mask)
-               drm_atomic_clean_old_fb(dev, plane_mask, ret);
+
+       state->acquire_ctx = NULL;
 
        return ret;
 }