drm/i915: Refactor work that can sleep out of commit (v7)
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / i915 / intel_sprite.c
index 7d9c340f7693a8ff950541213e7a0d4e8f61aa06..3e6e95fe46ae30b3fce8ca584d3d5cd2d931db71 100644 (file)
@@ -771,9 +771,8 @@ ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
         * Avoid underruns when disabling the sprite.
         * FIXME remove once watermark updates are done properly.
         */
-       intel_wait_for_vblank(dev, pipe);
-
-       intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false);
+       intel_crtc->atomic.wait_vblank = true;
+       intel_crtc->atomic.update_sprite_watermarks |= (1 << drm_plane_index(plane));
 }
 
 static int
@@ -976,12 +975,21 @@ ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
         * Avoid underruns when disabling the sprite.
         * FIXME remove once watermark updates are done properly.
         */
-       intel_wait_for_vblank(dev, pipe);
-
-       intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false);
+       intel_crtc->atomic.wait_vblank = true;
+       intel_crtc->atomic.update_sprite_watermarks |= (1 << drm_plane_index(plane));
 }
 
-static void
+/**
+ * intel_post_enable_primary - Perform operations after enabling primary plane
+ * @crtc: the CRTC whose primary plane was just enabled
+ *
+ * Performs potentially sleeping operations that must be done after the primary
+ * plane is enabled, such as updating FBC and IPS.  Note that this may be
+ * called due to an explicit primary plane update, or due to an implicit
+ * re-enable that is caused when a sprite plane is updated to no longer
+ * completely hide the primary plane.
+ */
+void
 intel_post_enable_primary(struct drm_crtc *crtc)
 {
        struct drm_device *dev = crtc->dev;
@@ -1004,11 +1012,21 @@ intel_post_enable_primary(struct drm_crtc *crtc)
        hsw_enable_ips(intel_crtc);
 
        mutex_lock(&dev->struct_mutex);
-       intel_update_fbc(dev);
+       intel_fbc_update(dev);
        mutex_unlock(&dev->struct_mutex);
 }
 
-static void
+/**
+ * intel_pre_disable_primary - Perform operations before disabling primary plane
+ * @crtc: the CRTC whose primary plane is to be disabled
+ *
+ * Performs potentially sleeping operations that must be done before the
+ * primary plane is enabled, such as updating FBC and IPS.  Note that this may
+ * be called due to an explicit primary plane update, or due to an implicit
+ * disable that is caused when a sprite plane completely hides the primary
+ * plane.
+ */
+void
 intel_pre_disable_primary(struct drm_crtc *crtc)
 {
        struct drm_device *dev = crtc->dev;
@@ -1017,7 +1035,7 @@ intel_pre_disable_primary(struct drm_crtc *crtc)
 
        mutex_lock(&dev->struct_mutex);
        if (dev_priv->fbc.plane == intel_crtc->plane)
-               intel_disable_fbc(dev);
+               intel_fbc_disable(dev);
        mutex_unlock(&dev->struct_mutex);
 
        /*
@@ -1096,9 +1114,9 @@ static int
 intel_check_sprite_plane(struct drm_plane *plane,
                         struct intel_plane_state *state)
 {
-       struct intel_crtc *intel_crtc = to_intel_crtc(state->crtc);
+       struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc);
        struct intel_plane *intel_plane = to_intel_plane(plane);
-       struct drm_framebuffer *fb = state->fb;
+       struct drm_framebuffer *fb = state->base.fb;
        struct drm_i915_gem_object *obj = intel_fb_obj(fb);
        int crtc_x, crtc_y;
        unsigned int crtc_w, crtc_h;
@@ -1109,7 +1127,12 @@ intel_check_sprite_plane(struct drm_plane *plane,
        const struct drm_rect *clip = &state->clip;
        int hscale, vscale;
        int max_scale, min_scale;
-       int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
+       int pixel_size;
+
+       if (!fb) {
+               state->visible = false;
+               goto finish;
+       }
 
        /* Don't modify another pipe's plane */
        if (intel_plane->pipe != intel_crtc->pipe) {
@@ -1232,6 +1255,7 @@ intel_check_sprite_plane(struct drm_plane *plane,
                if (src_w < 3 || src_h < 3)
                        state->visible = false;
 
+               pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
                width_bytes = ((src_x * pixel_size) & 63) +
                                        src_w * pixel_size;
 
@@ -1254,39 +1278,27 @@ intel_check_sprite_plane(struct drm_plane *plane,
        dst->y1 = crtc_y;
        dst->y2 = crtc_y + crtc_h;
 
-       return 0;
-}
+finish:
+       /*
+        * If the sprite is completely covering the primary plane,
+        * we can disable the primary and save power.
+        */
+       state->hides_primary = fb != NULL && drm_rect_equals(dst, clip) &&
+               !colorkey_enabled(intel_plane);
+       WARN_ON(state->hides_primary && !state->visible && intel_crtc->active);
 
-static int
-intel_prepare_sprite_plane(struct drm_plane *plane,
-                          struct intel_plane_state *state)
-{
-       struct drm_device *dev = plane->dev;
-       struct drm_crtc *crtc = state->crtc;
-       struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-       struct intel_plane *intel_plane = to_intel_plane(plane);
-       enum pipe pipe = intel_crtc->pipe;
-       struct drm_framebuffer *fb = state->fb;
-       struct drm_i915_gem_object *obj = intel_fb_obj(fb);
-       struct drm_i915_gem_object *old_obj = intel_plane->obj;
-       int ret;
+       if (intel_crtc->active) {
+               if (intel_crtc->primary_enabled == state->hides_primary)
+                       intel_crtc->atomic.wait_for_flips = true;
 
-       if (old_obj != obj) {
-               mutex_lock(&dev->struct_mutex);
+               if (intel_crtc->primary_enabled && state->hides_primary)
+                       intel_crtc->atomic.pre_disable_primary = true;
 
-               /* Note that this will apply the VT-d workaround for scanouts,
-                * which is more restrictive than required for sprites. (The
-                * primary plane requires 256KiB alignment with 64 PTE padding,
-                * the sprite planes only require 128KiB alignment and 32 PTE
-                * padding.
-                */
-               ret = intel_pin_and_fence_fb_obj(plane, fb, NULL);
-               if (ret == 0)
-                       i915_gem_track_fb(old_obj, obj,
-                                         INTEL_FRONTBUFFER_SPRITE(pipe));
-               mutex_unlock(&dev->struct_mutex);
-               if (ret)
-                       return ret;
+               intel_crtc->atomic.fb_bits |=
+                       INTEL_FRONTBUFFER_SPRITE(intel_crtc->pipe);
+
+               if (!intel_crtc->primary_enabled && !state->hides_primary)
+                       intel_crtc->atomic.post_enable_primary = true;
        }
 
        return 0;
@@ -1296,27 +1308,14 @@ static void
 intel_commit_sprite_plane(struct drm_plane *plane,
                          struct intel_plane_state *state)
 {
-       struct drm_device *dev = plane->dev;
-       struct drm_crtc *crtc = state->crtc;
+       struct drm_crtc *crtc = state->base.crtc;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        struct intel_plane *intel_plane = to_intel_plane(plane);
-       enum pipe pipe = intel_crtc->pipe;
-       struct drm_framebuffer *fb = state->fb;
+       struct drm_framebuffer *fb = state->base.fb;
        struct drm_i915_gem_object *obj = intel_fb_obj(fb);
-       struct drm_i915_gem_object *old_obj = intel_plane->obj;
        int crtc_x, crtc_y;
        unsigned int crtc_w, crtc_h;
        uint32_t src_x, src_y, src_w, src_h;
-       struct drm_rect *dst = &state->dst;
-       const struct drm_rect *clip = &state->clip;
-       bool primary_enabled;
-
-       /*
-        * If the sprite is completely covering the primary plane,
-        * we can disable the primary and save power.
-        */
-       primary_enabled = !drm_rect_equals(dst, clip) || colorkey_enabled(intel_plane);
-       WARN_ON(!primary_enabled && !state->visible && intel_crtc->active);
 
        intel_plane->crtc_x = state->orig_dst.x1;
        intel_plane->crtc_y = state->orig_dst.y1;
@@ -1329,15 +1328,7 @@ intel_commit_sprite_plane(struct drm_plane *plane,
        intel_plane->obj = obj;
 
        if (intel_crtc->active) {
-               bool primary_was_enabled = intel_crtc->primary_enabled;
-
-               intel_crtc->primary_enabled = primary_enabled;
-
-               if (primary_was_enabled != primary_enabled)
-                       intel_crtc_wait_for_pending_flips(crtc);
-
-               if (primary_was_enabled && !primary_enabled)
-                       intel_pre_disable_primary(crtc);
+               intel_crtc->primary_enabled = !state->hides_primary;
 
                if (state->visible) {
                        crtc_x = state->dst.x1;
@@ -1354,119 +1345,7 @@ intel_commit_sprite_plane(struct drm_plane *plane,
                } else {
                        intel_plane->disable_plane(plane, crtc);
                }
-
-
-               intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_SPRITE(pipe));
-
-               if (!primary_was_enabled && primary_enabled)
-                       intel_post_enable_primary(crtc);
        }
-
-       /* Unpin old obj after new one is active to avoid ugliness */
-       if (old_obj && old_obj != obj) {
-
-               /*
-                * It's fairly common to simply update the position of
-                * an existing object.  In that case, we don't need to
-                * wait for vblank to avoid ugliness, we only need to
-                * do the pin & ref bookkeeping.
-                */
-               if (intel_crtc->active)
-                       intel_wait_for_vblank(dev, intel_crtc->pipe);
-
-               mutex_lock(&dev->struct_mutex);
-               intel_unpin_fb_obj(old_obj);
-               mutex_unlock(&dev->struct_mutex);
-       }
-}
-
-static int
-intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
-                  struct drm_framebuffer *fb, int crtc_x, int crtc_y,
-                  unsigned int crtc_w, unsigned int crtc_h,
-                  uint32_t src_x, uint32_t src_y,
-                  uint32_t src_w, uint32_t src_h)
-{
-       struct intel_plane_state state;
-       struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-       int ret;
-
-       state.crtc = crtc;
-       state.fb = fb;
-
-       /* sample coordinates in 16.16 fixed point */
-       state.src.x1 = src_x;
-       state.src.x2 = src_x + src_w;
-       state.src.y1 = src_y;
-       state.src.y2 = src_y + src_h;
-
-       /* integer pixels */
-       state.dst.x1 = crtc_x;
-       state.dst.x2 = crtc_x + crtc_w;
-       state.dst.y1 = crtc_y;
-       state.dst.y2 = crtc_y + crtc_h;
-
-       state.clip.x1 = 0;
-       state.clip.y1 = 0;
-       state.clip.x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0;
-       state.clip.y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0;
-       state.orig_src = state.src;
-       state.orig_dst = state.dst;
-
-       ret = intel_check_sprite_plane(plane, &state);
-       if (ret)
-               return ret;
-
-       ret = intel_prepare_sprite_plane(plane, &state);
-       if (ret)
-               return ret;
-
-       intel_commit_sprite_plane(plane, &state);
-       return 0;
-}
-
-static int
-intel_disable_plane(struct drm_plane *plane)
-{
-       struct drm_device *dev = plane->dev;
-       struct intel_plane *intel_plane = to_intel_plane(plane);
-       struct intel_crtc *intel_crtc;
-       enum pipe pipe;
-
-       if (!plane->fb)
-               return 0;
-
-       if (WARN_ON(!plane->crtc))
-               return -EINVAL;
-
-       intel_crtc = to_intel_crtc(plane->crtc);
-       pipe = intel_crtc->pipe;
-
-       if (intel_crtc->active) {
-               bool primary_was_enabled = intel_crtc->primary_enabled;
-
-               intel_crtc->primary_enabled = true;
-
-               intel_plane->disable_plane(plane, plane->crtc);
-
-               if (!primary_was_enabled && intel_crtc->primary_enabled)
-                       intel_post_enable_primary(plane->crtc);
-       }
-
-       if (intel_plane->obj) {
-               if (intel_crtc->active)
-                       intel_wait_for_vblank(dev, intel_plane->pipe);
-
-               mutex_lock(&dev->struct_mutex);
-               intel_unpin_fb_obj(intel_plane->obj);
-               i915_gem_track_fb(intel_plane->obj, NULL,
-                                 INTEL_FRONTBUFFER_SPRITE(pipe));
-               mutex_unlock(&dev->struct_mutex);
-
-               intel_plane->obj = NULL;
-       }
-
-       return 0;
 }
 
 static void intel_destroy_plane(struct drm_plane *plane)
@@ -1576,14 +1455,6 @@ int intel_plane_restore(struct drm_plane *plane)
                                  intel_plane->src_w, intel_plane->src_h);
 }
 
-void intel_plane_disable(struct drm_plane *plane)
-{
-       if (!plane->crtc || !plane->fb)
-               return;
-
-       intel_disable_plane(plane);
-}
-
 static const struct drm_plane_funcs intel_plane_funcs = {
        .update_plane = intel_update_plane,
        .disable_plane = intel_disable_plane,
@@ -1720,6 +1591,8 @@ intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
        intel_plane->pipe = pipe;
        intel_plane->plane = plane;
        intel_plane->rotation = BIT(DRM_ROTATE_0);
+       intel_plane->check_plane = intel_check_sprite_plane;
+       intel_plane->commit_plane = intel_commit_sprite_plane;
        possible_crtcs = (1 << pipe);
        ret = drm_universal_plane_init(dev, &intel_plane->base, possible_crtcs,
                                       &intel_plane_funcs,