Merge tag 'drm-intel-next-2018-09-06-2' of git://anongit.freedesktop.org/drm/drm...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / i915 / intel_display.c
index 775968fa204990ea97993a42a9f3a70e143bd02a..1bd14c61dab5fd8e5d51689241273dd03d0c0d3e 100644 (file)
@@ -2474,6 +2474,12 @@ intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
        }
 }
 
+bool is_ccs_modifier(u64 modifier)
+{
+       return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
+              modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
+}
+
 static int
 intel_fill_fb_info(struct drm_i915_private *dev_priv,
                   struct drm_framebuffer *fb)
@@ -2504,8 +2510,7 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
                        return ret;
                }
 
-               if ((fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
-                    fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) && i == 1) {
+               if (is_ccs_modifier(fb->modifier) && i == 1) {
                        int hsub = fb->format->hsub;
                        int vsub = fb->format->vsub;
                        int tile_width, tile_height;
@@ -3055,8 +3060,7 @@ static int skl_check_main_surface(const struct intel_crtc_state *crtc_state,
         * CCS AUX surface doesn't have its own x/y offsets, we must make sure
         * they match with the main surface x/y offsets.
         */
-       if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
-           fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) {
+       if (is_ccs_modifier(fb->modifier)) {
                while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
                        if (offset == 0)
                                break;
@@ -3190,8 +3194,7 @@ int skl_check_plane_surface(const struct intel_crtc_state *crtc_state,
                ret = skl_check_nv12_aux_surface(plane_state);
                if (ret)
                        return ret;
-       } else if (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
-                  fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS) {
+       } else if (is_ccs_modifier(fb->modifier)) {
                ret = skl_check_ccs_aux_surface(plane_state);
                if (ret)
                        return ret;
@@ -3552,11 +3555,11 @@ static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
        case I915_FORMAT_MOD_Y_TILED:
                return PLANE_CTL_TILED_Y;
        case I915_FORMAT_MOD_Y_TILED_CCS:
-               return PLANE_CTL_TILED_Y | PLANE_CTL_DECOMPRESSION_ENABLE;
+               return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
        case I915_FORMAT_MOD_Yf_TILED:
                return PLANE_CTL_TILED_YF;
        case I915_FORMAT_MOD_Yf_TILED_CCS:
-               return PLANE_CTL_TILED_YF | PLANE_CTL_DECOMPRESSION_ENABLE;
+               return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
        default:
                MISSING_CASE(fb_modifier);
        }
@@ -5079,10 +5082,14 @@ void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
                mutex_lock(&dev_priv->pcu_lock);
                WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
                mutex_unlock(&dev_priv->pcu_lock);
-               /* wait for pcode to finish disabling IPS, which may take up to 42ms */
+               /*
+                * Wait for PCODE to finish disabling IPS. The BSpec specified
+                * 42ms timeout value leads to occasional timeouts so use 100ms
+                * instead.
+                */
                if (intel_wait_for_register(dev_priv,
                                            IPS_CTL, IPS_ENABLE, 0,
-                                           42))
+                                           100))
                        DRM_ERROR("Timed out waiting for IPS disable\n");
        } else {
                I915_WRITE(IPS_CTL, 0);
@@ -8799,13 +8806,13 @@ skylake_get_initial_plane_config(struct intel_crtc *crtc,
                fb->modifier = I915_FORMAT_MOD_X_TILED;
                break;
        case PLANE_CTL_TILED_Y:
-               if (val & PLANE_CTL_DECOMPRESSION_ENABLE)
+               if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
                        fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
                else
                        fb->modifier = I915_FORMAT_MOD_Y_TILED;
                break;
        case PLANE_CTL_TILED_YF:
-               if (val & PLANE_CTL_DECOMPRESSION_ENABLE)
+               if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
                        fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
                else
                        fb->modifier = I915_FORMAT_MOD_Yf_TILED;
@@ -8974,7 +8981,7 @@ static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
                I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
                     pipe_name(crtc->pipe));
 
-       I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL)),
+       I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2),
                        "Display power well on\n");
        I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
        I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
@@ -9691,8 +9698,7 @@ static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
        return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
 }
 
-static int i845_check_cursor(struct intel_plane *plane,
-                            struct intel_crtc_state *crtc_state,
+static int i845_check_cursor(struct intel_crtc_state *crtc_state,
                             struct intel_plane_state *plane_state)
 {
        const struct drm_framebuffer *fb = plane_state->base.fb;
@@ -9882,10 +9888,10 @@ static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
        return true;
 }
 
-static int i9xx_check_cursor(struct intel_plane *plane,
-                            struct intel_crtc_state *crtc_state,
+static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
                             struct intel_plane_state *plane_state)
 {
+       struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
        struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
        const struct drm_framebuffer *fb = plane_state->base.fb;
        enum pipe pipe = plane->pipe;
@@ -12739,7 +12745,7 @@ static void intel_atomic_commit_tail(struct drm_atomic_state *state)
         * down.
         */
        INIT_WORK(&state->commit_work, intel_atomic_cleanup_work);
-       schedule_work(&state->commit_work);
+       queue_work(system_highpri_wq, &state->commit_work);
 }
 
 static void intel_atomic_commit_work(struct work_struct *work)
@@ -12969,8 +12975,11 @@ static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
            INTEL_INFO(dev_priv)->cursor_needs_physical) {
                struct drm_i915_gem_object *obj = intel_fb_obj(fb);
                const int align = intel_cursor_alignment(dev_priv);
+               int err;
 
-               return i915_gem_object_attach_phys(obj, align);
+               err = i915_gem_object_attach_phys(obj, align);
+               if (err)
+                       return err;
        }
 
        vma = intel_pin_and_fence_fb_obj(fb,
@@ -13189,10 +13198,10 @@ skl_max_scale(struct intel_crtc *intel_crtc,
 }
 
 static int
-intel_check_primary_plane(struct intel_plane *plane,
-                         struct intel_crtc_state *crtc_state,
+intel_check_primary_plane(struct intel_crtc_state *crtc_state,
                          struct intel_plane_state *state)
 {
+       struct intel_plane *plane = to_intel_plane(state->base.plane);
        struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
        struct drm_crtc *crtc = state->base.crtc;
        int min_scale = DRM_PLANE_HELPER_NO_SCALING;
@@ -13400,8 +13409,7 @@ static bool skl_plane_format_mod_supported(struct drm_plane *_plane,
        case DRM_FORMAT_XBGR8888:
        case DRM_FORMAT_ARGB8888:
        case DRM_FORMAT_ABGR8888:
-               if (modifier == I915_FORMAT_MOD_Yf_TILED_CCS ||
-                   modifier == I915_FORMAT_MOD_Y_TILED_CCS)
+               if (is_ccs_modifier(modifier))
                        return true;
                /* fall through */
        case DRM_FORMAT_RGB565:
@@ -13620,24 +13628,22 @@ static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv,
 bool skl_plane_has_planar(struct drm_i915_private *dev_priv,
                          enum pipe pipe, enum plane_id plane_id)
 {
-       if (plane_id == PLANE_PRIMARY) {
-               if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
-                       return false;
-               else if ((INTEL_GEN(dev_priv) == 9 && pipe == PIPE_C) &&
-                        !IS_GEMINILAKE(dev_priv))
-                       return false;
-       } else if (plane_id >= PLANE_SPRITE0) {
-               if (plane_id == PLANE_CURSOR)
-                       return false;
-               if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) == 10) {
-                       if (plane_id != PLANE_SPRITE0)
-                               return false;
-               } else {
-                       if (plane_id != PLANE_SPRITE0 || pipe == PIPE_C ||
-                           IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
-                               return false;
-               }
-       }
+       /*
+        * FIXME: ICL requires two hardware planes for scanning out NV12
+        * framebuffers. Do not advertize support until this is implemented.
+        */
+       if (INTEL_GEN(dev_priv) >= 11)
+               return false;
+
+       if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
+               return false;
+
+       if (INTEL_GEN(dev_priv) == 9 && !IS_GEMINILAKE(dev_priv) && pipe == PIPE_C)
+               return false;
+
+       if (plane_id != PLANE_PRIMARY && plane_id != PLANE_SPRITE0)
+               return false;
+
        return true;
 }
 
@@ -14131,6 +14137,9 @@ static void intel_setup_outputs(struct drm_i915_private *dev_priv)
 
        intel_pps_init(dev_priv);
 
+       if (INTEL_INFO(dev_priv)->num_pipes == 0)
+               return;
+
        /*
         * intel_edp_init_connector() depends on this completing first, to
         * prevent the registeration of both eDP and LVDS and the incorrect
@@ -14547,7 +14556,7 @@ static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
                break;
        case DRM_FORMAT_NV12:
                if (INTEL_GEN(dev_priv) < 9 || IS_SKYLAKE(dev_priv) ||
-                   IS_BROXTON(dev_priv)) {
+                   IS_BROXTON(dev_priv) || INTEL_GEN(dev_priv) >= 11) {
                        DRM_DEBUG_KMS("unsupported pixel format: %s\n",
                                      drm_get_format_name(mode_cmd->pixel_format,
                                                          &format_name));
@@ -14594,8 +14603,7 @@ static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
                 * potential runtime errors at plane configuration time.
                 */
                if (IS_GEN9(dev_priv) && i == 0 && fb->width > 3840 &&
-                   (fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
-                    fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS))
+                   is_ccs_modifier(fb->modifier))
                        stride_alignment *= 4;
 
                if (fb->pitches[i] & (stride_alignment - 1)) {
@@ -15131,12 +15139,61 @@ static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
        DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
 }
 
+static int intel_initial_commit(struct drm_device *dev)
+{
+       struct drm_atomic_state *state = NULL;
+       struct drm_modeset_acquire_ctx ctx;
+       struct drm_crtc *crtc;
+       struct drm_crtc_state *crtc_state;
+       int ret = 0;
+
+       state = drm_atomic_state_alloc(dev);
+       if (!state)
+               return -ENOMEM;
+
+       drm_modeset_acquire_init(&ctx, 0);
+
+retry:
+       state->acquire_ctx = &ctx;
+
+       drm_for_each_crtc(crtc, dev) {
+               crtc_state = drm_atomic_get_crtc_state(state, crtc);
+               if (IS_ERR(crtc_state)) {
+                       ret = PTR_ERR(crtc_state);
+                       goto out;
+               }
+
+               if (crtc_state->active) {
+                       ret = drm_atomic_add_affected_planes(state, crtc);
+                       if (ret)
+                               goto out;
+               }
+       }
+
+       ret = drm_atomic_commit(state);
+
+out:
+       if (ret == -EDEADLK) {
+               drm_atomic_state_clear(state);
+               drm_modeset_backoff(&ctx);
+               goto retry;
+       }
+
+       drm_atomic_state_put(state);
+
+       drm_modeset_drop_locks(&ctx);
+       drm_modeset_acquire_fini(&ctx);
+
+       return ret;
+}
+
 int intel_modeset_init(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = to_i915(dev);
        struct i915_ggtt *ggtt = &dev_priv->ggtt;
        enum pipe pipe;
        struct intel_crtc *crtc;
+       int ret;
 
        dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
 
@@ -15160,9 +15217,6 @@ int intel_modeset_init(struct drm_device *dev)
 
        intel_init_pm(dev_priv);
 
-       if (INTEL_INFO(dev_priv)->num_pipes == 0)
-               return 0;
-
        /*
         * There may be no VBT; and if the BIOS enabled SSC we can
         * just keep using it to avoid unnecessary flicker.  Whereas if the
@@ -15211,8 +15265,6 @@ int intel_modeset_init(struct drm_device *dev)
                      INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
 
        for_each_pipe(dev_priv, pipe) {
-               int ret;
-
                ret = intel_crtc_init(dev_priv, pipe);
                if (ret) {
                        drm_mode_config_cleanup(dev);
@@ -15268,6 +15320,16 @@ int intel_modeset_init(struct drm_device *dev)
        if (!HAS_GMCH_DISPLAY(dev_priv))
                sanitize_watermarks(dev);
 
+       /*
+        * Force all active planes to recompute their states. So that on
+        * mode_setcrtc after probe, all the intel_plane_state variables
+        * are already calculated and there is no assert_plane warnings
+        * during bootup.
+        */
+       ret = intel_initial_commit(dev);
+       if (ret)
+               DRM_DEBUG_KMS("Initial commit in probe failed.\n");
+
        return 0;
 }
 
@@ -15792,6 +15854,8 @@ intel_modeset_setup_hw_state(struct drm_device *dev,
        struct intel_encoder *encoder;
        int i;
 
+       intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
+
        intel_early_display_was(dev_priv);
        intel_modeset_readout_hw_state(dev);
 
@@ -15846,9 +15910,8 @@ intel_modeset_setup_hw_state(struct drm_device *dev,
                if (WARN_ON(put_domains))
                        modeset_put_power_domains(dev_priv, put_domains);
        }
-       intel_display_set_init_power(dev_priv, false);
 
-       intel_power_domains_verify_state(dev_priv);
+       intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
 
        intel_fbc_init_pipe_state(dev_priv);
 }
@@ -15937,8 +16000,6 @@ void intel_modeset_cleanup(struct drm_device *dev)
        flush_work(&dev_priv->atomic_helper.free_work);
        WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
 
-       intel_disable_gt_powersave(dev_priv);
-
        /*
         * Interrupts and polling as the first thing to avoid creating havoc.
         * Too much stuff here (turning of connectors, ...) would
@@ -15966,8 +16027,6 @@ void intel_modeset_cleanup(struct drm_device *dev)
 
        intel_cleanup_overlay(dev_priv);
 
-       intel_cleanup_gt_powersave(dev_priv);
-
        intel_teardown_gmbus(dev_priv);
 
        destroy_workqueue(dev_priv->modeset_wq);
@@ -16075,8 +16134,7 @@ intel_display_capture_error_state(struct drm_i915_private *dev_priv)
                return NULL;
 
        if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
-               error->power_well_driver =
-                       I915_READ(HSW_PWR_WELL_CTL_DRIVER(HSW_DISP_PW_GLOBAL));
+               error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
 
        for_each_pipe(dev_priv, i) {
                error->pipe[i].power_domain_on =