drm: Wire up proper acquire ctx for plane functions
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Wed, 22 Mar 2017 21:50:40 +0000 (22:50 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Wed, 29 Mar 2017 07:13:44 +0000 (09:13 +0200)
This is just prep work to get an acquire ctx into every place where we
call ->update_plane or ->disable_plane.

v2: Keep the hidden acquire_ctx pointers valid while transitioning.

Reviewed-by: Harry Wentland <harry.wentland@amd.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170322215058.8671-2-daniel.vetter@ffwll.ch
drivers/gpu/drm/drm_plane.c

index a22e76837065a04f64e67654da3c6419e8066508..0d04888172a78ce891660f6877d8c342914e720d 100644 (file)
@@ -457,7 +457,8 @@ static int __setplane_internal(struct drm_plane *plane,
                               uint32_t crtc_w, uint32_t crtc_h,
                               /* src_{x,y,w,h} values are 16.16 fixed point */
                               uint32_t src_x, uint32_t src_y,
-                              uint32_t src_w, uint32_t src_h)
+                              uint32_t src_w, uint32_t src_h,
+                              struct drm_modeset_acquire_ctx *ctx)
 {
        int ret = 0;
 
@@ -537,13 +538,26 @@ static int setplane_internal(struct drm_plane *plane,
                             uint32_t src_x, uint32_t src_y,
                             uint32_t src_w, uint32_t src_h)
 {
+       struct drm_modeset_acquire_ctx ctx;
        int ret;
 
-       drm_modeset_lock_all(plane->dev);
+       drm_modeset_acquire_init(&ctx, 0);
+retry:
+       ret = drm_modeset_lock_all_ctx(plane->dev, &ctx);
+       if (ret)
+               goto fail;
+       plane->dev->mode_config.acquire_ctx = &ctx;
        ret = __setplane_internal(plane, crtc, fb,
                                  crtc_x, crtc_y, crtc_w, crtc_h,
-                                 src_x, src_y, src_w, src_h);
-       drm_modeset_unlock_all(plane->dev);
+                                 src_x, src_y, src_w, src_h, &ctx);
+
+fail:
+       if (ret == -EDEADLK) {
+               drm_modeset_backoff(&ctx);
+               goto retry;
+       }
+       drm_modeset_drop_locks(&ctx);
+       drm_modeset_acquire_fini(&ctx);
 
        return ret;
 }
@@ -613,11 +627,22 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc,
        int32_t crtc_x, crtc_y;
        uint32_t crtc_w = 0, crtc_h = 0;
        uint32_t src_w = 0, src_h = 0;
+       struct drm_modeset_acquire_ctx ctx;
        int ret = 0;
 
        BUG_ON(!crtc->cursor);
        WARN_ON(crtc->cursor->crtc != crtc && crtc->cursor->crtc != NULL);
 
+       drm_modeset_acquire_init(&ctx, 0);
+retry:
+       ret = drm_modeset_lock(&crtc->mutex, &ctx);
+       if (ret)
+               goto fail;
+       ret = drm_modeset_lock(&crtc->cursor->mutex, &ctx);
+       if (ret)
+               goto fail;
+       crtc->acquire_ctx = &ctx;
+
        /*
         * Obtain fb we'll be using (either new or existing) and take an extra
         * reference to it if fb != null.  setplane will take care of dropping
@@ -662,7 +687,7 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc,
         */
        ret = __setplane_internal(crtc->cursor, crtc, fb,
                                crtc_x, crtc_y, crtc_w, crtc_h,
-                               0, 0, src_w, src_h);
+                               0, 0, src_w, src_h, &ctx);
 
        /* Update successful; save new cursor position, if necessary */
        if (ret == 0 && req->flags & DRM_MODE_CURSOR_MOVE) {
@@ -670,6 +695,15 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc,
                crtc->cursor_y = req->y;
        }
 
+fail:
+       if (ret == -EDEADLK) {
+               drm_modeset_backoff(&ctx);
+               goto retry;
+       }
+
+       drm_modeset_drop_locks(&ctx);
+       drm_modeset_acquire_fini(&ctx);
+
        return ret;
 }
 
@@ -696,12 +730,10 @@ static int drm_mode_cursor_common(struct drm_device *dev,
         * If this crtc has a universal cursor plane, call that plane's update
         * handler rather than using legacy cursor handlers.
         */
-       drm_modeset_lock_crtc(crtc, crtc->cursor);
-       if (crtc->cursor) {
-               ret = drm_mode_cursor_universal(crtc, req, file_priv);
-               goto out;
-       }
+       if (crtc->cursor)
+               return drm_mode_cursor_universal(crtc, req, file_priv);
 
+       drm_modeset_lock_crtc(crtc, crtc->cursor);
        if (req->flags & DRM_MODE_CURSOR_BO) {
                if (!crtc->funcs->cursor_set && !crtc->funcs->cursor_set2) {
                        ret = -ENXIO;