Revert "drm/vc4: kms: Remove async modeset semaphore"
authorDom Cobley <popcornmix@gmail.com>
Mon, 26 Jul 2021 17:02:11 +0000 (18:02 +0100)
committerPhil Elwell <8911409+pelwell@users.noreply.github.com>
Mon, 26 Jul 2021 19:59:02 +0000 (20:59 +0100)
This reverts commit a28f2f0df6da70dec509b965635f0d5f71f9a9f7.

drivers/gpu/drm/vc4/vc4_crtc.c
drivers/gpu/drm/vc4/vc4_drv.h
drivers/gpu/drm/vc4/vc4_kms.c

index 0771fd91aee78c1630d42f8fe3575b9c485ee229..008d264cc372882ebc0dcdcc0ac276854e1ec5ed 100644 (file)
@@ -766,6 +766,7 @@ vc4_async_page_flip_complete(struct vc4_seqno_cb *cb)
                container_of(cb, struct vc4_async_flip_state, cb);
        struct drm_crtc *crtc = flip_state->crtc;
        struct drm_device *dev = crtc->dev;
+       struct vc4_dev *vc4 = to_vc4_dev(dev);
        struct drm_plane *plane = crtc->primary;
 
        vc4_plane_async_set_fb(plane, flip_state->fb);
@@ -797,6 +798,8 @@ vc4_async_page_flip_complete(struct vc4_seqno_cb *cb)
        }
 
        kfree(flip_state);
+
+       up(&vc4->async_modeset);
 }
 
 /* Implements async (non-vblank-synced) page flips.
@@ -811,6 +814,7 @@ static int vc4_async_page_flip(struct drm_crtc *crtc,
                               uint32_t flags)
 {
        struct drm_device *dev = crtc->dev;
+       struct vc4_dev *vc4 = to_vc4_dev(dev);
        struct drm_plane *plane = crtc->primary;
        int ret = 0;
        struct vc4_async_flip_state *flip_state;
@@ -839,6 +843,15 @@ static int vc4_async_page_flip(struct drm_crtc *crtc,
        flip_state->crtc = crtc;
        flip_state->event = event;
 
+       /* Make sure all other async modesetes have landed. */
+       ret = down_interruptible(&vc4->async_modeset);
+       if (ret) {
+               drm_framebuffer_put(fb);
+               vc4_bo_dec_usecnt(bo);
+               kfree(flip_state);
+               return ret;
+       }
+
        /* Save the current FB before it's replaced by the new one in
         * drm_atomic_set_fb_for_plane(). We'll need the old FB in
         * vc4_async_page_flip_complete() to decrement the BO usecnt and keep
index 9d7e0ee768e623901bd3b49494151b94516c7123..f73f0a6a7df820d4b185e2ce54d4877f4cf21e77 100644 (file)
@@ -216,6 +216,8 @@ struct vc4_dev {
                struct work_struct reset_work;
        } hangcheck;
 
+       struct semaphore async_modeset;
+
        struct drm_modeset_lock ctm_state_lock;
        struct drm_private_obj ctm_manager;
        struct drm_private_obj hvs_channels;
index 24dea3acb9de1ce9cc13b307c2250541140ab3f7..7b02bff7d9398b4c5138cb04f57258ebd84f2467 100644 (file)
@@ -424,6 +424,8 @@ vc4_atomic_complete_commit(struct drm_atomic_state *state)
                clk_request_done(core_req);
 
        drm_atomic_state_put(state);
+
+       up(&vc4->async_modeset);
 }
 
 static void commit_work(struct work_struct *work)
@@ -481,17 +483,26 @@ static int vc4_atomic_commit(struct drm_device *dev,
                             struct drm_atomic_state *state,
                             bool nonblock)
 {
+       struct vc4_dev *vc4 = to_vc4_dev(dev);
        int ret;
 
        if (state->async_update) {
-               ret = drm_atomic_helper_prepare_planes(dev, state);
+               ret = down_interruptible(&vc4->async_modeset);
                if (ret)
                        return ret;
 
+               ret = drm_atomic_helper_prepare_planes(dev, state);
+               if (ret) {
+                       up(&vc4->async_modeset);
+                       return ret;
+               }
+
                drm_atomic_helper_async_commit(dev, state);
 
                drm_atomic_helper_cleanup_planes(dev, state);
 
+               up(&vc4->async_modeset);
+
                return 0;
        }
 
@@ -508,14 +519,21 @@ static int vc4_atomic_commit(struct drm_device *dev,
 
        INIT_WORK(&state->commit_work, commit_work);
 
-       ret = drm_atomic_helper_prepare_planes(dev, state);
+       ret = down_interruptible(&vc4->async_modeset);
        if (ret)
                return ret;
 
+       ret = drm_atomic_helper_prepare_planes(dev, state);
+       if (ret) {
+               up(&vc4->async_modeset);
+               return ret;
+       }
+
        if (!nonblock) {
                ret = drm_atomic_helper_wait_for_fences(dev, state, true);
                if (ret) {
                        drm_atomic_helper_cleanup_planes(dev, state);
+                       up(&vc4->async_modeset);
                        return ret;
                }
        }
@@ -995,6 +1013,8 @@ int vc4_kms_load(struct drm_device *dev)
                vc4->load_tracker_enabled = true;
        }
 
+       sema_init(&vc4->async_modeset, 1);
+
        /* Set support for vblank irq fast disable, before drm_vblank_init() */
        dev->vblank_disable_immediate = true;