drm/i915: Setup DPLL/DPLLMD for DSI too on VLV/CHV
[deliverable/linux.git] / drivers / gpu / drm / i915 / intel_display.c
index cf16bdbbda47089b0905e3cef15245e9e2083eb7..d9266f9a185ed349c5bc04e1ac610478087aba8f 100644 (file)
@@ -147,15 +147,12 @@ static int valleyview_get_vco(struct drm_i915_private *dev_priv)
        return vco_freq[hpll_freq] * 1000;
 }
 
-static int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
-                                 const char *name, u32 reg)
+int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
+                     const char *name, u32 reg, int ref_freq)
 {
        u32 val;
        int divider;
 
-       if (dev_priv->hpll_freq == 0)
-               dev_priv->hpll_freq = valleyview_get_vco(dev_priv);
-
        mutex_lock(&dev_priv->sb_lock);
        val = vlv_cck_read(dev_priv, reg);
        mutex_unlock(&dev_priv->sb_lock);
@@ -166,7 +163,17 @@ static int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
             (divider << CCK_FREQUENCY_STATUS_SHIFT),
             "%s change in progress\n", name);
 
-       return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1);
+       return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
+}
+
+static int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
+                                 const char *name, u32 reg)
+{
+       if (dev_priv->hpll_freq == 0)
+               dev_priv->hpll_freq = valleyview_get_vco(dev_priv);
+
+       return vlv_get_cck_clock(dev_priv, name, reg,
+                                dev_priv->hpll_freq);
 }
 
 static int
@@ -1160,7 +1167,7 @@ static void assert_fdi_tx(struct drm_i915_private *dev_priv,
        enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
                                                                      pipe);
 
-       if (HAS_DDI(dev_priv->dev)) {
+       if (HAS_DDI(dev_priv)) {
                /* DDI does not have a specific FDI_TX register */
                u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
                cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
@@ -1196,11 +1203,11 @@ static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
        u32 val;
 
        /* ILK FDI PLL is always enabled */
-       if (INTEL_INFO(dev_priv->dev)->gen == 5)
+       if (INTEL_INFO(dev_priv)->gen == 5)
                return;
 
        /* On Haswell, DDI ports are responsible for the FDI PLL setup */
-       if (HAS_DDI(dev_priv->dev))
+       if (HAS_DDI(dev_priv))
                return;
 
        val = I915_READ(FDI_TX_CTL(pipe));
@@ -1408,11 +1415,11 @@ static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
        if ((val & DP_PORT_EN) == 0)
                return false;
 
-       if (HAS_PCH_CPT(dev_priv->dev)) {
+       if (HAS_PCH_CPT(dev_priv)) {
                u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe));
                if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
                        return false;
-       } else if (IS_CHERRYVIEW(dev_priv->dev)) {
+       } else if (IS_CHERRYVIEW(dev_priv)) {
                if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
                        return false;
        } else {
@@ -1428,10 +1435,10 @@ static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
        if ((val & SDVO_ENABLE) == 0)
                return false;
 
-       if (HAS_PCH_CPT(dev_priv->dev)) {
+       if (HAS_PCH_CPT(dev_priv)) {
                if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
                        return false;
-       } else if (IS_CHERRYVIEW(dev_priv->dev)) {
+       } else if (IS_CHERRYVIEW(dev_priv)) {
                if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
                        return false;
        } else {
@@ -1447,7 +1454,7 @@ static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
        if ((val & LVDS_PORT_EN) == 0)
                return false;
 
-       if (HAS_PCH_CPT(dev_priv->dev)) {
+       if (HAS_PCH_CPT(dev_priv)) {
                if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
                        return false;
        } else {
@@ -1462,7 +1469,7 @@ static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
 {
        if ((val & ADPA_DAC_ENABLE) == 0)
                return false;
-       if (HAS_PCH_CPT(dev_priv->dev)) {
+       if (HAS_PCH_CPT(dev_priv)) {
                if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
                        return false;
        } else {
@@ -1481,7 +1488,7 @@ static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
             "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
             i915_mmio_reg_offset(reg), pipe_name(pipe));
 
-       I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
+       I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & DP_PORT_EN) == 0
             && (val & DP_PIPEB_SELECT),
             "IBX PCH dp port still using transcoder B\n");
 }
@@ -1494,7 +1501,7 @@ static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
             "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
             i915_mmio_reg_offset(reg), pipe_name(pipe));
 
-       I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
+       I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & SDVO_ENABLE) == 0
             && (val & SDVO_PIPE_B_SELECT),
             "IBX PCH hdmi port still using transcoder B\n");
 }
@@ -1523,45 +1530,47 @@ static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
        assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
 }
 
+static void _vlv_enable_pll(struct intel_crtc *crtc,
+                           const struct intel_crtc_state *pipe_config)
+{
+       struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
+       enum pipe pipe = crtc->pipe;
+
+       I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
+       POSTING_READ(DPLL(pipe));
+       udelay(150);
+
+       if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
+               DRM_ERROR("DPLL %d failed to lock\n", pipe);
+}
+
 static void vlv_enable_pll(struct intel_crtc *crtc,
                           const struct intel_crtc_state *pipe_config)
 {
-       struct drm_device *dev = crtc->base.dev;
-       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
        enum pipe pipe = crtc->pipe;
-       i915_reg_t reg = DPLL(pipe);
-       u32 dpll = pipe_config->dpll_hw_state.dpll;
 
        assert_pipe_disabled(dev_priv, pipe);
 
        /* PLL is protected by panel, make sure we can write it */
        assert_panel_unlocked(dev_priv, pipe);
 
-       I915_WRITE(reg, dpll);
-       POSTING_READ(reg);
-       udelay(150);
-
-       if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
-               DRM_ERROR("DPLL %d failed to lock\n", pipe);
+       if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
+               _vlv_enable_pll(crtc, pipe_config);
 
        I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
        POSTING_READ(DPLL_MD(pipe));
 }
 
-static void chv_enable_pll(struct intel_crtc *crtc,
-                          const struct intel_crtc_state *pipe_config)
+
+static void _chv_enable_pll(struct intel_crtc *crtc,
+                           const struct intel_crtc_state *pipe_config)
 {
-       struct drm_device *dev = crtc->base.dev;
-       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
        enum pipe pipe = crtc->pipe;
        enum dpio_channel port = vlv_pipe_to_channel(pipe);
        u32 tmp;
 
-       assert_pipe_disabled(dev_priv, pipe);
-
-       /* PLL is protected by panel, make sure we can write it */
-       assert_panel_unlocked(dev_priv, pipe);
-
        mutex_lock(&dev_priv->sb_lock);
 
        /* Enable back the 10bit clock to display controller */
@@ -1582,6 +1591,21 @@ static void chv_enable_pll(struct intel_crtc *crtc,
        /* Check PLL is locked */
        if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
                DRM_ERROR("PLL %d failed to lock\n", pipe);
+}
+
+static void chv_enable_pll(struct intel_crtc *crtc,
+                          const struct intel_crtc_state *pipe_config)
+{
+       struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
+       enum pipe pipe = crtc->pipe;
+
+       assert_pipe_disabled(dev_priv, pipe);
+
+       /* PLL is protected by panel, make sure we can write it */
+       assert_panel_unlocked(dev_priv, pipe);
+
+       if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
+               _chv_enable_pll(crtc, pipe_config);
 
        if (pipe != PIPE_A) {
                /*
@@ -1819,7 +1843,7 @@ static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
        val = I915_READ(reg);
        pipeconf_val = I915_READ(PIPECONF(pipe));
 
-       if (HAS_PCH_IBX(dev_priv->dev)) {
+       if (HAS_PCH_IBX(dev_priv)) {
                /*
                 * Make the BPC in transcoder be consistent with
                 * that in pipeconf reg. For HDMI we must use 8bpc
@@ -1834,7 +1858,7 @@ static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
 
        val &= ~TRANS_INTERLACE_MASK;
        if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
-               if (HAS_PCH_IBX(dev_priv->dev) &&
+               if (HAS_PCH_IBX(dev_priv) &&
                    intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO))
                        val |= TRANS_LEGACY_INTERLACED_ILK;
                else
@@ -1946,7 +1970,7 @@ static void intel_enable_pipe(struct intel_crtc *crtc)
        assert_cursor_disabled(dev_priv, pipe);
        assert_sprites_disabled(dev_priv, pipe);
 
-       if (HAS_PCH_LPT(dev_priv->dev))
+       if (HAS_PCH_LPT(dev_priv))
                pch_transcoder = TRANSCODER_A;
        else
                pch_transcoder = pipe;
@@ -1956,7 +1980,7 @@ static void intel_enable_pipe(struct intel_crtc *crtc)
         * a plane.  On ILK+ the pipe PLLs are integrated, so we don't
         * need the check.
         */
-       if (HAS_GMCH_DISPLAY(dev_priv->dev))
+       if (HAS_GMCH_DISPLAY(dev_priv))
                if (crtc->config->has_dsi_encoder)
                        assert_dsi_pll_enabled(dev_priv);
                else
@@ -3191,12 +3215,12 @@ void intel_finish_reset(struct drm_device *dev)
 static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
 {
        struct drm_device *dev = crtc->dev;
-       struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+       unsigned reset_counter;
        bool pending;
 
-       if (i915_reset_in_progress(&dev_priv->gpu_error) ||
-           intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
+       reset_counter = i915_reset_counter(&to_i915(dev)->gpu_error);
+       if (intel_crtc->reset_counter != reset_counter)
                return false;
 
        spin_lock_irq(&dev->event_lock);
@@ -3798,9 +3822,7 @@ static void page_flip_completed(struct intel_crtc *intel_crtc)
        intel_crtc->unpin_work = NULL;
 
        if (work->event)
-               drm_send_vblank_event(intel_crtc->base.dev,
-                                     intel_crtc->pipe,
-                                     work->event);
+               drm_crtc_send_vblank_event(&intel_crtc->base, work->event);
 
        drm_crtc_vblank_put(&intel_crtc->base);
 
@@ -4081,12 +4103,6 @@ static void ironlake_pch_enable(struct drm_crtc *crtc)
        I915_WRITE(FDI_RX_TUSIZE1(pipe),
                   I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
 
-       /*
-        * Sometimes spurious CPU pipe underruns happen during FDI
-        * training, at least with VGA+HDMI cloning. Suppress them.
-        */
-       intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
-
        /* For PCH output, training FDI link */
        dev_priv->display.fdi_link_train(crtc);
 
@@ -4121,8 +4137,6 @@ static void ironlake_pch_enable(struct drm_crtc *crtc)
 
        intel_fdi_normal_train(crtc);
 
-       intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
-
        /* For PCH DP, enable TRANS_DP_CTL */
        if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) {
                const struct drm_display_mode *adjusted_mode =
@@ -4725,6 +4739,18 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
        if (WARN_ON(intel_crtc->active))
                return;
 
+       /*
+        * Sometimes spurious CPU pipe underruns happen during FDI
+        * training, at least with VGA+HDMI cloning. Suppress them.
+        *
+        * On ILK we get an occasional spurious CPU pipe underruns
+        * between eDP port A enable and vdd enable. Also PCH port
+        * enable seems to result in the occasional CPU pipe underrun.
+        *
+        * Spurious PCH underruns also occur during PCH enabling.
+        */
+       if (intel_crtc->config->has_pch_encoder || IS_GEN5(dev_priv))
+               intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
        if (intel_crtc->config->has_pch_encoder)
                intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
 
@@ -4746,8 +4772,6 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
 
        intel_crtc->active = true;
 
-       intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
-
        for_each_encoder_on_crtc(dev, crtc, encoder)
                if (encoder->pre_enable)
                        encoder->pre_enable(encoder);
@@ -4789,6 +4813,7 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
        /* Must wait for vblank to avoid spurious PCH FIFO underruns */
        if (intel_crtc->config->has_pch_encoder)
                intel_wait_for_vblank(dev, pipe);
+       intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
        intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
 }
 
@@ -4941,8 +4966,15 @@ static void ironlake_crtc_disable(struct drm_crtc *crtc)
        struct intel_encoder *encoder;
        int pipe = intel_crtc->pipe;
 
-       if (intel_crtc->config->has_pch_encoder)
+       /*
+        * Sometimes spurious CPU pipe underruns happen when the
+        * pipe is already disabled, but FDI RX/TX is still enabled.
+        * Happens at least with VGA+HDMI cloning. Suppress them.
+        */
+       if (intel_crtc->config->has_pch_encoder) {
+               intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
                intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
+       }
 
        for_each_encoder_on_crtc(dev, crtc, encoder)
                encoder->disable(encoder);
@@ -4950,22 +4982,12 @@ static void ironlake_crtc_disable(struct drm_crtc *crtc)
        drm_crtc_vblank_off(crtc);
        assert_vblank_disabled(crtc);
 
-       /*
-        * Sometimes spurious CPU pipe underruns happen when the
-        * pipe is already disabled, but FDI RX/TX is still enabled.
-        * Happens at least with VGA+HDMI cloning. Suppress them.
-        */
-       if (intel_crtc->config->has_pch_encoder)
-               intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
-
        intel_disable_pipe(intel_crtc);
 
        ironlake_pfit_disable(intel_crtc, false);
 
-       if (intel_crtc->config->has_pch_encoder) {
+       if (intel_crtc->config->has_pch_encoder)
                ironlake_fdi_disable(crtc);
-               intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
-       }
 
        for_each_encoder_on_crtc(dev, crtc, encoder)
                if (encoder->post_disable)
@@ -4995,6 +5017,7 @@ static void ironlake_crtc_disable(struct drm_crtc *crtc)
                ironlake_fdi_pll_disable(intel_crtc);
        }
 
+       intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
        intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
 }
 
@@ -5261,6 +5284,8 @@ static void intel_update_max_cdclk(struct drm_device *dev)
                        dev_priv->max_cdclk_freq = 450000;
                else
                        dev_priv->max_cdclk_freq = 337500;
+       } else if (IS_BROXTON(dev)) {
+               dev_priv->max_cdclk_freq = 624000;
        } else if (IS_BROADWELL(dev))  {
                /*
                 * FIXME with extra cooling we can allow
@@ -5320,9 +5345,8 @@ static void intel_update_cdclk(struct drm_device *dev)
                intel_update_max_cdclk(dev);
 }
 
-static void broxton_set_cdclk(struct drm_device *dev, int frequency)
+static void broxton_set_cdclk(struct drm_i915_private *dev_priv, int frequency)
 {
-       struct drm_i915_private *dev_priv = dev->dev_private;
        uint32_t divider;
        uint32_t ratio;
        uint32_t current_freq;
@@ -5436,33 +5460,46 @@ static void broxton_set_cdclk(struct drm_device *dev, int frequency)
                return;
        }
 
-       intel_update_cdclk(dev);
+       intel_update_cdclk(dev_priv->dev);
 }
 
-void broxton_init_cdclk(struct drm_device *dev)
+static bool broxton_cdclk_is_enabled(struct drm_i915_private *dev_priv)
 {
-       struct drm_i915_private *dev_priv = dev->dev_private;
-       uint32_t val;
+       if (!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE))
+               return false;
 
-       /*
-        * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
-        * or else the reset will hang because there is no PCH to respond.
-        * Move the handshake programming to initialization sequence.
-        * Previously was left up to BIOS.
-        */
-       val = I915_READ(HSW_NDE_RSTWRN_OPT);
-       val &= ~RESET_PCH_HANDSHAKE_ENABLE;
-       I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
+       /* TODO: Check for a valid CDCLK rate */
 
-       /* Enable PG1 for cdclk */
-       intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
+       if (!(I915_READ(DBUF_CTL) & DBUF_POWER_REQUEST)) {
+               DRM_DEBUG_DRIVER("CDCLK enabled, but DBUF power not requested\n");
 
+               return false;
+       }
+
+       if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) {
+               DRM_DEBUG_DRIVER("CDCLK enabled, but DBUF power hasn't settled\n");
+
+               return false;
+       }
+
+       return true;
+}
+
+bool broxton_cdclk_verify_state(struct drm_i915_private *dev_priv)
+{
+       return broxton_cdclk_is_enabled(dev_priv);
+}
+
+void broxton_init_cdclk(struct drm_i915_private *dev_priv)
+{
        /* check if cd clock is enabled */
-       if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) {
-               DRM_DEBUG_KMS("Display already initialized\n");
+       if (broxton_cdclk_is_enabled(dev_priv)) {
+               DRM_DEBUG_KMS("CDCLK already enabled, won't reprogram it\n");
                return;
        }
 
+       DRM_DEBUG_KMS("CDCLK not enabled, enabling it\n");
+
        /*
         * FIXME:
         * - The initial CDCLK needs to be read from VBT.
@@ -5470,7 +5507,7 @@ void broxton_init_cdclk(struct drm_device *dev)
         * - check if setting the max (or any) cdclk freq is really necessary
         *   here, it belongs to modeset time
         */
-       broxton_set_cdclk(dev, 624000);
+       broxton_set_cdclk(dev_priv, 624000);
 
        I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
        POSTING_READ(DBUF_CTL);
@@ -5481,10 +5518,8 @@ void broxton_init_cdclk(struct drm_device *dev)
                DRM_ERROR("DBuf power enable timeout!\n");
 }
 
-void broxton_uninit_cdclk(struct drm_device *dev)
+void broxton_uninit_cdclk(struct drm_i915_private *dev_priv)
 {
-       struct drm_i915_private *dev_priv = dev->dev_private;
-
        I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
        POSTING_READ(DBUF_CTL);
 
@@ -5494,9 +5529,7 @@ void broxton_uninit_cdclk(struct drm_device *dev)
                DRM_ERROR("DBuf power disable timeout!\n");
 
        /* Set minimum (bypass) frequency, in effect turning off the DE PLL */
-       broxton_set_cdclk(dev, 19200);
-
-       intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS);
+       broxton_set_cdclk(dev_priv, 19200);
 }
 
 static const struct skl_cdclk_entry {
@@ -6063,14 +6096,12 @@ static void valleyview_crtc_enable(struct drm_crtc *crtc)
                if (encoder->pre_pll_enable)
                        encoder->pre_pll_enable(encoder);
 
-       if (!intel_crtc->config->has_dsi_encoder) {
-               if (IS_CHERRYVIEW(dev)) {
-                       chv_prepare_pll(intel_crtc, intel_crtc->config);
-                       chv_enable_pll(intel_crtc, intel_crtc->config);
-               } else {
-                       vlv_prepare_pll(intel_crtc, intel_crtc->config);
-                       vlv_enable_pll(intel_crtc, intel_crtc->config);
-               }
+       if (IS_CHERRYVIEW(dev)) {
+               chv_prepare_pll(intel_crtc, intel_crtc->config);
+               chv_enable_pll(intel_crtc, intel_crtc->config);
+       } else {
+               vlv_prepare_pll(intel_crtc, intel_crtc->config);
+               vlv_enable_pll(intel_crtc, intel_crtc->config);
        }
 
        for_each_encoder_on_crtc(dev, crtc, encoder)
@@ -6108,7 +6139,7 @@ static void i9xx_crtc_enable(struct drm_crtc *crtc)
        struct intel_encoder *encoder;
        struct intel_crtc_state *pipe_config =
                to_intel_crtc_state(crtc->state);
-       int pipe = intel_crtc->pipe;
+       enum pipe pipe = intel_crtc->pipe;
 
        if (WARN_ON(intel_crtc->active))
                return;
@@ -6286,7 +6317,7 @@ void intel_encoder_destroy(struct drm_encoder *encoder)
 
 /* Cross check the actual hw state with our own modeset state tracking (and it's
  * internal consistency). */
-static void intel_connector_check_state(struct intel_connector *connector)
+static void intel_connector_verify_state(struct intel_connector *connector)
 {
        struct drm_crtc *crtc = connector->base.state->crtc;
 
@@ -6492,7 +6523,7 @@ static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv,
                return false;
 
        /* HSW can handle pixel rate up to cdclk? */
-       if (IS_HASWELL(dev_priv->dev))
+       if (IS_HASWELL(dev_priv))
                return true;
 
        /*
@@ -7164,11 +7195,15 @@ static void vlv_compute_dpll(struct intel_crtc *crtc,
                             struct intel_crtc_state *pipe_config)
 {
        pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
-               DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
-               DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV;
+               DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
        if (crtc->pipe != PIPE_A)
                pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
 
+       /* DPLL not used with DSI, but still need the rest set up */
+       if (!intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_DSI))
+               pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
+                       DPLL_EXT_BUFFER_ENABLE_VLV;
+
        pipe_config->dpll_hw_state.dpll_md =
                (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
 }
@@ -7177,11 +7212,14 @@ static void chv_compute_dpll(struct intel_crtc *crtc,
                             struct intel_crtc_state *pipe_config)
 {
        pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
-               DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
-               DPLL_VCO_ENABLE;
+               DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
        if (crtc->pipe != PIPE_A)
                pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
 
+       /* DPLL not used with DSI, but still need the rest set up */
+       if (!intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_DSI))
+               pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
+
        pipe_config->dpll_hw_state.dpll_md =
                (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
 }
@@ -7191,11 +7229,20 @@ static void vlv_prepare_pll(struct intel_crtc *crtc,
 {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
-       int pipe = crtc->pipe;
+       enum pipe pipe = crtc->pipe;
        u32 mdiv;
        u32 bestn, bestm1, bestm2, bestp1, bestp2;
        u32 coreclk, reg_val;
 
+       /* Enable Refclk */
+       I915_WRITE(DPLL(pipe),
+                  pipe_config->dpll_hw_state.dpll &
+                  ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
+
+       /* No need to actually set up the DPLL with DSI */
+       if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
+               return;
+
        mutex_lock(&dev_priv->sb_lock);
 
        bestn = pipe_config->dpll.n;
@@ -7282,14 +7329,21 @@ static void chv_prepare_pll(struct intel_crtc *crtc,
 {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
-       int pipe = crtc->pipe;
-       i915_reg_t dpll_reg = DPLL(crtc->pipe);
+       enum pipe pipe = crtc->pipe;
        enum dpio_channel port = vlv_pipe_to_channel(pipe);
        u32 loopfilter, tribuf_calcntr;
        u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
        u32 dpio_val;
        int vco;
 
+       /* Enable Refclk and SSC */
+       I915_WRITE(DPLL(pipe),
+                  pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
+
+       /* No need to actually set up the DPLL with DSI */
+       if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
+               return;
+
        bestn = pipe_config->dpll.n;
        bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
        bestm1 = pipe_config->dpll.m1;
@@ -7300,12 +7354,6 @@ static void chv_prepare_pll(struct intel_crtc *crtc,
        dpio_val = 0;
        loopfilter = 0;
 
-       /*
-        * Enable Refclk and SSC
-        */
-       I915_WRITE(dpll_reg,
-                  pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
-
        mutex_lock(&dev_priv->sb_lock);
 
        /* p1 and p2 divider */
@@ -7920,9 +7968,6 @@ static int chv_crtc_compute_clock(struct intel_crtc *crtc,
        memset(&crtc_state->dpll_hw_state, 0,
               sizeof(crtc_state->dpll_hw_state));
 
-       if (crtc_state->has_dsi_encoder)
-               return 0;
-
        if (!crtc_state->clock_set &&
            !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
                                refclk, NULL, &crtc_state->dpll)) {
@@ -7944,9 +7989,6 @@ static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
        memset(&crtc_state->dpll_hw_state, 0,
               sizeof(crtc_state->dpll_hw_state));
 
-       if (crtc_state->has_dsi_encoder)
-               return 0;
-
        if (!crtc_state->clock_set &&
            !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
                                refclk, NULL, &crtc_state->dpll)) {
@@ -7999,8 +8041,8 @@ static void vlv_crtc_clock_get(struct intel_crtc *crtc,
        u32 mdiv;
        int refclk = 100000;
 
-       /* In case of MIPI DPLL will not even be used */
-       if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE))
+       /* In case of DSI, DPLL will not be used */
+       if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
                return;
 
        mutex_lock(&dev_priv->sb_lock);
@@ -8096,6 +8138,10 @@ static void chv_crtc_clock_get(struct intel_crtc *crtc,
        u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
        int refclk = 100000;
 
+       /* In case of DSI, DPLL will not be used */
+       if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
+               return;
+
        mutex_lock(&dev_priv->sb_lock);
        cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
        pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
@@ -9256,7 +9302,7 @@ static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
 
                ironlake_get_fdi_m_n_config(crtc, pipe_config);
 
-               if (HAS_PCH_IBX(dev_priv->dev)) {
+               if (HAS_PCH_IBX(dev_priv)) {
                        pll_id = (enum intel_dpll_id) crtc->pipe;
                } else {
                        tmp = I915_READ(PCH_DPLL_SEL);
@@ -9524,7 +9570,7 @@ static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state)
                to_intel_atomic_state(old_state);
        unsigned int req_cdclk = old_intel_state->dev_cdclk;
 
-       broxton_set_cdclk(dev, req_cdclk);
+       broxton_set_cdclk(to_i915(dev), req_cdclk);
 }
 
 /* compute the max rate for new configuration */
@@ -10894,9 +10940,10 @@ static bool page_flip_finished(struct intel_crtc *crtc)
 {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
+       unsigned reset_counter;
 
-       if (i915_reset_in_progress(&dev_priv->gpu_error) ||
-           crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
+       reset_counter = i915_reset_counter(&dev_priv->gpu_error);
+       if (crtc->reset_counter != reset_counter)
                return true;
 
        /*
@@ -11350,7 +11397,6 @@ static void intel_mmio_flip_work_func(struct work_struct *work)
 
        if (mmio_flip->req) {
                WARN_ON(__i915_wait_request(mmio_flip->req,
-                                           mmio_flip->crtc->reset_counter,
                                            false, NULL,
                                            &mmio_flip->i915->rps.mmioflips));
                i915_gem_request_unreference__unlocked(mmio_flip->req);
@@ -11558,8 +11604,13 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
        if (ret)
                goto cleanup;
 
+       intel_crtc->reset_counter = i915_reset_counter(&dev_priv->gpu_error);
+       if (__i915_reset_in_progress_or_wedged(intel_crtc->reset_counter)) {
+               ret = -EIO;
+               goto cleanup;
+       }
+
        atomic_inc(&intel_crtc->unpin_work_count);
-       intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
 
        if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
                work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1;
@@ -11645,7 +11696,7 @@ cleanup_unpin:
        intel_unpin_fb_obj(fb, crtc->primary->state->rotation);
 cleanup_pending:
        if (!IS_ERR_OR_NULL(request))
-               i915_gem_request_cancel(request);
+               i915_add_request_no_flush(request);
        atomic_dec(&intel_crtc->unpin_work_count);
        mutex_unlock(&dev->struct_mutex);
 cleanup:
@@ -11695,7 +11746,7 @@ retry:
 
                if (ret == 0 && event) {
                        spin_lock_irq(&dev->event_lock);
-                       drm_send_vblank_event(dev, pipe, event);
+                       drm_crtc_send_vblank_event(crtc, event);
                        spin_unlock_irq(&dev->event_lock);
                }
        }
@@ -12677,7 +12728,7 @@ intel_pipe_config_compare(struct drm_device *dev,
        PIPE_CONF_CHECK_X(gmch_pfit.control);
        /* pfit ratios are autocomputed by the hw on gen4+ */
        if (INTEL_INFO(dev)->gen < 4)
-               PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
+               PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
        PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
 
        if (!adjust) {
@@ -12747,48 +12798,43 @@ static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
        }
 }
 
-static void check_wm_state(struct drm_device *dev)
+static void verify_wm_state(struct drm_crtc *crtc,
+                           struct drm_crtc_state *new_state)
 {
+       struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct skl_ddb_allocation hw_ddb, *sw_ddb;
-       struct intel_crtc *intel_crtc;
+       struct skl_ddb_entry *hw_entry, *sw_entry;
+       struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+       const enum pipe pipe = intel_crtc->pipe;
        int plane;
 
-       if (INTEL_INFO(dev)->gen < 9)
+       if (INTEL_INFO(dev)->gen < 9 || !new_state->active)
                return;
 
        skl_ddb_get_hw_state(dev_priv, &hw_ddb);
        sw_ddb = &dev_priv->wm.skl_hw.ddb;
 
-       for_each_intel_crtc(dev, intel_crtc) {
-               struct skl_ddb_entry *hw_entry, *sw_entry;
-               const enum pipe pipe = intel_crtc->pipe;
+       /* planes */
+       for_each_plane(dev_priv, pipe, plane) {
+               hw_entry = &hw_ddb.plane[pipe][plane];
+               sw_entry = &sw_ddb->plane[pipe][plane];
 
-               if (!intel_crtc->active)
+               if (skl_ddb_entry_equal(hw_entry, sw_entry))
                        continue;
 
-               /* planes */
-               for_each_plane(dev_priv, pipe, plane) {
-                       hw_entry = &hw_ddb.plane[pipe][plane];
-                       sw_entry = &sw_ddb->plane[pipe][plane];
-
-                       if (skl_ddb_entry_equal(hw_entry, sw_entry))
-                               continue;
-
-                       DRM_ERROR("mismatch in DDB state pipe %c plane %d "
-                                 "(expected (%u,%u), found (%u,%u))\n",
-                                 pipe_name(pipe), plane + 1,
-                                 sw_entry->start, sw_entry->end,
-                                 hw_entry->start, hw_entry->end);
-               }
-
-               /* cursor */
-               hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
-               sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
+               DRM_ERROR("mismatch in DDB state pipe %c plane %d "
+                         "(expected (%u,%u), found (%u,%u))\n",
+                         pipe_name(pipe), plane + 1,
+                         sw_entry->start, sw_entry->end,
+                         hw_entry->start, hw_entry->end);
+       }
 
-               if (skl_ddb_entry_equal(hw_entry, sw_entry))
-                       continue;
+       /* cursor */
+       hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
+       sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
 
+       if (!skl_ddb_entry_equal(hw_entry, sw_entry)) {
                DRM_ERROR("mismatch in DDB state pipe %c cursor "
                          "(expected (%u,%u), found (%u,%u))\n",
                          pipe_name(pipe),
@@ -12798,20 +12844,18 @@ static void check_wm_state(struct drm_device *dev)
 }
 
 static void
-check_connector_state(struct drm_device *dev,
-                     struct drm_atomic_state *old_state)
+verify_connector_state(struct drm_device *dev, struct drm_crtc *crtc)
 {
-       struct drm_connector_state *old_conn_state;
        struct drm_connector *connector;
-       int i;
 
-       for_each_connector_in_state(old_state, connector, old_conn_state, i) {
+       drm_for_each_connector(connector, dev) {
                struct drm_encoder *encoder = connector->encoder;
                struct drm_connector_state *state = connector->state;
 
-               /* This also checks the encoder/connector hw state with the
-                * ->get_hw_state callbacks. */
-               intel_connector_check_state(to_intel_connector(connector));
+               if (state->crtc != crtc)
+                       continue;
+
+               intel_connector_verify_state(to_intel_connector(connector));
 
                I915_STATE_WARN(state->best_encoder != encoder,
                     "connector's atomic encoder doesn't match legacy encoder\n");
@@ -12819,7 +12863,7 @@ check_connector_state(struct drm_device *dev,
 }
 
 static void
-check_encoder_state(struct drm_device *dev)
+verify_encoder_state(struct drm_device *dev)
 {
        struct intel_encoder *encoder;
        struct intel_connector *connector;
@@ -12859,144 +12903,186 @@ check_encoder_state(struct drm_device *dev)
 }
 
 static void
-check_crtc_state(struct drm_device *dev, struct drm_atomic_state *old_state)
+verify_crtc_state(struct drm_crtc *crtc,
+                 struct drm_crtc_state *old_crtc_state,
+                 struct drm_crtc_state *new_crtc_state)
 {
+       struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_encoder *encoder;
-       struct drm_crtc_state *old_crtc_state;
-       struct drm_crtc *crtc;
-       int i;
-
-       for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
-               struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-               struct intel_crtc_state *pipe_config, *sw_config;
-               bool active;
-
-               if (!needs_modeset(crtc->state) &&
-                   !to_intel_crtc_state(crtc->state)->update_pipe)
-                       continue;
+       struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+       struct intel_crtc_state *pipe_config, *sw_config;
+       struct drm_atomic_state *old_state;
+       bool active;
 
-               __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state);
-               pipe_config = to_intel_crtc_state(old_crtc_state);
-               memset(pipe_config, 0, sizeof(*pipe_config));
-               pipe_config->base.crtc = crtc;
-               pipe_config->base.state = old_state;
+       old_state = old_crtc_state->state;
+       __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state);
+       pipe_config = to_intel_crtc_state(old_crtc_state);
+       memset(pipe_config, 0, sizeof(*pipe_config));
+       pipe_config->base.crtc = crtc;
+       pipe_config->base.state = old_state;
 
-               DRM_DEBUG_KMS("[CRTC:%d]\n",
-                             crtc->base.id);
+       DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
 
-               active = dev_priv->display.get_pipe_config(intel_crtc,
-                                                          pipe_config);
+       active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
 
-               /* hw state is inconsistent with the pipe quirk */
-               if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
-                   (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
-                       active = crtc->state->active;
+       /* hw state is inconsistent with the pipe quirk */
+       if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
+           (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
+               active = new_crtc_state->active;
 
-               I915_STATE_WARN(crtc->state->active != active,
-                    "crtc active state doesn't match with hw state "
-                    "(expected %i, found %i)\n", crtc->state->active, active);
+       I915_STATE_WARN(new_crtc_state->active != active,
+            "crtc active state doesn't match with hw state "
+            "(expected %i, found %i)\n", new_crtc_state->active, active);
 
-               I915_STATE_WARN(intel_crtc->active != crtc->state->active,
-                    "transitional active state does not match atomic hw state "
-                    "(expected %i, found %i)\n", crtc->state->active, intel_crtc->active);
+       I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
+            "transitional active state does not match atomic hw state "
+            "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
 
-               for_each_encoder_on_crtc(dev, crtc, encoder) {
-                       enum pipe pipe;
+       for_each_encoder_on_crtc(dev, crtc, encoder) {
+               enum pipe pipe;
 
-                       active = encoder->get_hw_state(encoder, &pipe);
-                       I915_STATE_WARN(active != crtc->state->active,
-                               "[ENCODER:%i] active %i with crtc active %i\n",
-                               encoder->base.base.id, active, crtc->state->active);
+               active = encoder->get_hw_state(encoder, &pipe);
+               I915_STATE_WARN(active != new_crtc_state->active,
+                       "[ENCODER:%i] active %i with crtc active %i\n",
+                       encoder->base.base.id, active, new_crtc_state->active);
 
-                       I915_STATE_WARN(active && intel_crtc->pipe != pipe,
-                                       "Encoder connected to wrong pipe %c\n",
-                                       pipe_name(pipe));
+               I915_STATE_WARN(active && intel_crtc->pipe != pipe,
+                               "Encoder connected to wrong pipe %c\n",
+                               pipe_name(pipe));
 
-                       if (active)
-                               encoder->get_config(encoder, pipe_config);
-               }
+               if (active)
+                       encoder->get_config(encoder, pipe_config);
+       }
 
-               if (!crtc->state->active)
-                       continue;
+       if (!new_crtc_state->active)
+               return;
 
-               intel_pipe_config_sanity_check(dev_priv, pipe_config);
+       intel_pipe_config_sanity_check(dev_priv, pipe_config);
 
-               sw_config = to_intel_crtc_state(crtc->state);
-               if (!intel_pipe_config_compare(dev, sw_config,
-                                              pipe_config, false)) {
-                       I915_STATE_WARN(1, "pipe state doesn't match!\n");
-                       intel_dump_pipe_config(intel_crtc, pipe_config,
-                                              "[hw state]");
-                       intel_dump_pipe_config(intel_crtc, sw_config,
-                                              "[sw state]");
-               }
+       sw_config = to_intel_crtc_state(crtc->state);
+       if (!intel_pipe_config_compare(dev, sw_config,
+                                      pipe_config, false)) {
+               I915_STATE_WARN(1, "pipe state doesn't match!\n");
+               intel_dump_pipe_config(intel_crtc, pipe_config,
+                                      "[hw state]");
+               intel_dump_pipe_config(intel_crtc, sw_config,
+                                      "[sw state]");
        }
 }
 
 static void
-check_shared_dpll_state(struct drm_device *dev)
+verify_single_dpll_state(struct drm_i915_private *dev_priv,
+                        struct intel_shared_dpll *pll,
+                        struct drm_crtc *crtc,
+                        struct drm_crtc_state *new_state)
 {
-       struct drm_i915_private *dev_priv = dev->dev_private;
-       struct intel_crtc *crtc;
        struct intel_dpll_hw_state dpll_hw_state;
-       int i;
+       unsigned crtc_mask;
+       bool active;
 
-       for (i = 0; i < dev_priv->num_shared_dpll; i++) {
-               struct intel_shared_dpll *pll =
-                       intel_get_shared_dpll_by_id(dev_priv, i);
-               unsigned enabled_crtcs = 0, active_crtcs = 0;
-               bool active;
+       memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
 
-               memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
+       DRM_DEBUG_KMS("%s\n", pll->name);
 
-               DRM_DEBUG_KMS("%s\n", pll->name);
+       active = pll->funcs.get_hw_state(dev_priv, pll, &dpll_hw_state);
 
-               active = pll->funcs.get_hw_state(dev_priv, pll, &dpll_hw_state);
+       if (!(pll->flags & INTEL_DPLL_ALWAYS_ON)) {
+               I915_STATE_WARN(!pll->on && pll->active_mask,
+                    "pll in active use but not on in sw tracking\n");
+               I915_STATE_WARN(pll->on && !pll->active_mask,
+                    "pll is on but not used by any active crtc\n");
+               I915_STATE_WARN(pll->on != active,
+                    "pll on state mismatch (expected %i, found %i)\n",
+                    pll->on, active);
+       }
 
+       if (!crtc) {
                I915_STATE_WARN(pll->active_mask & ~pll->config.crtc_mask,
-                    "more active pll users than references: %x vs %x\n",
-                    pll->active_mask, pll->config.crtc_mask);
+                               "more active pll users than references: %x vs %x\n",
+                               pll->active_mask, pll->config.crtc_mask);
 
-               if (!(pll->flags & INTEL_DPLL_ALWAYS_ON)) {
-                       I915_STATE_WARN(!pll->on && pll->active_mask,
-                            "pll in active use but not on in sw tracking\n");
-                       I915_STATE_WARN(pll->on && !pll->active_mask,
-                            "pll is on but not used by any active crtc\n");
-                       I915_STATE_WARN(pll->on != active,
-                            "pll on state mismatch (expected %i, found %i)\n",
-                            pll->on, active);
-               }
+               return;
+       }
 
-               for_each_intel_crtc(dev, crtc) {
-                       if (crtc->base.state->enable && crtc->config->shared_dpll == pll)
-                               enabled_crtcs |= 1 << drm_crtc_index(&crtc->base);
-                       if (crtc->base.state->active && crtc->config->shared_dpll == pll)
-                               active_crtcs |= 1 << drm_crtc_index(&crtc->base);
-               }
+       crtc_mask = 1 << drm_crtc_index(crtc);
+
+       if (new_state->active)
+               I915_STATE_WARN(!(pll->active_mask & crtc_mask),
+                               "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
+                               pipe_name(drm_crtc_index(crtc)), pll->active_mask);
+       else
+               I915_STATE_WARN(pll->active_mask & crtc_mask,
+                               "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
+                               pipe_name(drm_crtc_index(crtc)), pll->active_mask);
+
+       I915_STATE_WARN(!(pll->config.crtc_mask & crtc_mask),
+                       "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
+                       crtc_mask, pll->config.crtc_mask);
+
+       I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state,
+                                         &dpll_hw_state,
+                                         sizeof(dpll_hw_state)),
+                       "pll hw state mismatch\n");
+}
+
+static void
+verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
+                        struct drm_crtc_state *old_crtc_state,
+                        struct drm_crtc_state *new_crtc_state)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
+       struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
 
-               I915_STATE_WARN(pll->active_mask != active_crtcs,
-                    "pll active crtcs mismatch (expected %x, found %x)\n",
-                    pll->active_mask, active_crtcs);
-               I915_STATE_WARN(pll->config.crtc_mask != enabled_crtcs,
-                    "pll enabled crtcs mismatch (expected %x, found %x)\n",
-                    pll->config.crtc_mask, enabled_crtcs);
+       if (new_state->shared_dpll)
+               verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
 
-               I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state,
-                                      sizeof(dpll_hw_state)),
-                    "pll hw state mismatch\n");
+       if (old_state->shared_dpll &&
+           old_state->shared_dpll != new_state->shared_dpll) {
+               unsigned crtc_mask = 1 << drm_crtc_index(crtc);
+               struct intel_shared_dpll *pll = old_state->shared_dpll;
+
+               I915_STATE_WARN(pll->active_mask & crtc_mask,
+                               "pll active mismatch (didn't expect pipe %c in active mask)\n",
+                               pipe_name(drm_crtc_index(crtc)));
+               I915_STATE_WARN(pll->config.crtc_mask & crtc_mask,
+                               "pll enabled crtcs mismatch (found %x in enabled mask)\n",
+                               pipe_name(drm_crtc_index(crtc)));
        }
 }
 
 static void
-intel_modeset_check_state(struct drm_device *dev,
-                         struct drm_atomic_state *old_state)
+intel_modeset_verify_crtc(struct drm_crtc *crtc,
+                        struct drm_crtc_state *old_state,
+                        struct drm_crtc_state *new_state)
 {
-       check_wm_state(dev);
-       check_connector_state(dev, old_state);
-       check_encoder_state(dev);
-       check_crtc_state(dev, old_state);
-       check_shared_dpll_state(dev);
+       if (!needs_modeset(new_state) &&
+           !to_intel_crtc_state(new_state)->update_pipe)
+               return;
+
+       verify_wm_state(crtc, new_state);
+       verify_connector_state(crtc->dev, crtc);
+       verify_crtc_state(crtc, old_state, new_state);
+       verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
+}
+
+static void
+verify_disabled_dpll_state(struct drm_device *dev)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       int i;
+
+       for (i = 0; i < dev_priv->num_shared_dpll; i++)
+               verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
+}
+
+static void
+intel_modeset_verify_disabled(struct drm_device *dev)
+{
+       verify_encoder_state(dev);
+       verify_connector_state(dev, NULL);
+       verify_disabled_dpll_state(dev);
 }
 
 static void update_scanline_offset(struct intel_crtc *crtc)
@@ -13370,12 +13456,9 @@ static int intel_atomic_prepare_commit(struct drm_device *dev,
                return ret;
 
        ret = drm_atomic_helper_prepare_planes(dev, state);
-       if (!ret && !async && !i915_reset_in_progress(&dev_priv->gpu_error)) {
-               u32 reset_counter;
-
-               reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
-               mutex_unlock(&dev->struct_mutex);
+       mutex_unlock(&dev->struct_mutex);
 
+       if (!ret && !async) {
                for_each_plane_in_state(state, plane, plane_state, i) {
                        struct intel_plane_state *intel_plane_state =
                                to_intel_plane_state(plane_state);
@@ -13384,25 +13467,18 @@ static int intel_atomic_prepare_commit(struct drm_device *dev,
                                continue;
 
                        ret = __i915_wait_request(intel_plane_state->wait_req,
-                                                 reset_counter, true,
-                                                 NULL, NULL);
-
-                       /* Swallow -EIO errors to allow updates during hw lockup. */
-                       if (ret == -EIO)
-                               ret = 0;
-
-                       if (ret)
+                                                 true, NULL, NULL);
+                       if (ret) {
+                               /* Any hang should be swallowed by the wait */
+                               WARN_ON(ret == -EIO);
+                               mutex_lock(&dev->struct_mutex);
+                               drm_atomic_helper_cleanup_planes(dev, state);
+                               mutex_unlock(&dev->struct_mutex);
                                break;
+                       }
                }
-
-               if (!ret)
-                       return 0;
-
-               mutex_lock(&dev->struct_mutex);
-               drm_atomic_helper_cleanup_planes(dev, state);
        }
 
-       mutex_unlock(&dev->struct_mutex);
        return ret;
 }
 
@@ -13566,6 +13642,8 @@ static int intel_atomic_commit(struct drm_device *dev,
                if (dev_priv->display.modeset_commit_cdclk &&
                    intel_state->dev_cdclk != dev_priv->cdclk_freq)
                        dev_priv->display.modeset_commit_cdclk(state);
+
+               intel_modeset_verify_disabled(dev);
        }
 
        /* Now enable the clocks, plane, pipe, and connectors that we set up. */
@@ -13620,6 +13698,8 @@ static int intel_atomic_commit(struct drm_device *dev,
 
                if (put_domains[i])
                        modeset_put_power_domains(dev_priv, put_domains[i]);
+
+               intel_modeset_verify_crtc(crtc, old_crtc_state, crtc->state);
        }
 
        if (intel_state->modeset)
@@ -13629,9 +13709,6 @@ static int intel_atomic_commit(struct drm_device *dev,
        drm_atomic_helper_cleanup_planes(dev, state);
        mutex_unlock(&dev->struct_mutex);
 
-       if (hw_check)
-               intel_modeset_check_state(dev, state);
-
        drm_atomic_state_free(state);
 
        /* As one of the primary mmio accessors, KMS has a high likelihood
@@ -13745,10 +13822,11 @@ intel_prepare_plane_fb(struct drm_plane *plane,
                 */
                if (needs_modeset(crtc_state))
                        ret = i915_gem_object_wait_rendering(old_obj, true);
-
-               /* Swallow -EIO errors to allow updates during hw lockup. */
-               if (ret && ret != -EIO)
+               if (ret) {
+                       /* GPU hangs should have been swallowed by the wait */
+                       WARN_ON(ret == -EIO);
                        return ret;
+               }
        }
 
        /* For framebuffer backed by dmabuf, wait for fence */
@@ -13947,20 +14025,19 @@ const struct drm_plane_funcs intel_plane_funcs = {
 static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
                                                    int pipe)
 {
-       struct intel_plane *primary;
-       struct intel_plane_state *state;
+       struct intel_plane *primary = NULL;
+       struct intel_plane_state *state = NULL;
        const uint32_t *intel_primary_formats;
        unsigned int num_formats;
+       int ret;
 
        primary = kzalloc(sizeof(*primary), GFP_KERNEL);
-       if (primary == NULL)
-               return NULL;
+       if (!primary)
+               goto fail;
 
        state = intel_create_plane_state(&primary->base);
-       if (!state) {
-               kfree(primary);
-               return NULL;
-       }
+       if (!state)
+               goto fail;
        primary->base.state = &state->base;
 
        primary->can_scale = false;
@@ -14002,10 +14079,12 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
                primary->disable_plane = i9xx_disable_primary_plane;
        }
 
-       drm_universal_plane_init(dev, &primary->base, 0,
-                                &intel_plane_funcs,
-                                intel_primary_formats, num_formats,
-                                DRM_PLANE_TYPE_PRIMARY, NULL);
+       ret = drm_universal_plane_init(dev, &primary->base, 0,
+                                      &intel_plane_funcs,
+                                      intel_primary_formats, num_formats,
+                                      DRM_PLANE_TYPE_PRIMARY, NULL);
+       if (ret)
+               goto fail;
 
        if (INTEL_INFO(dev)->gen >= 4)
                intel_create_rotation_property(dev, primary);
@@ -14013,6 +14092,12 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
        drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
 
        return &primary->base;
+
+fail:
+       kfree(state);
+       kfree(primary);
+
+       return NULL;
 }
 
 void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane)
@@ -14129,18 +14214,17 @@ intel_update_cursor_plane(struct drm_plane *plane,
 static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
                                                   int pipe)
 {
-       struct intel_plane *cursor;
-       struct intel_plane_state *state;
+       struct intel_plane *cursor = NULL;
+       struct intel_plane_state *state = NULL;
+       int ret;
 
        cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
-       if (cursor == NULL)
-               return NULL;
+       if (!cursor)
+               goto fail;
 
        state = intel_create_plane_state(&cursor->base);
-       if (!state) {
-               kfree(cursor);
-               return NULL;
-       }
+       if (!state)
+               goto fail;
        cursor->base.state = &state->base;
 
        cursor->can_scale = false;
@@ -14152,11 +14236,13 @@ static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
        cursor->update_plane = intel_update_cursor_plane;
        cursor->disable_plane = intel_disable_cursor_plane;
 
-       drm_universal_plane_init(dev, &cursor->base, 0,
-                                &intel_plane_funcs,
-                                intel_cursor_formats,
-                                ARRAY_SIZE(intel_cursor_formats),
-                                DRM_PLANE_TYPE_CURSOR, NULL);
+       ret = drm_universal_plane_init(dev, &cursor->base, 0,
+                                      &intel_plane_funcs,
+                                      intel_cursor_formats,
+                                      ARRAY_SIZE(intel_cursor_formats),
+                                      DRM_PLANE_TYPE_CURSOR, NULL);
+       if (ret)
+               goto fail;
 
        if (INTEL_INFO(dev)->gen >= 4) {
                if (!dev->mode_config.rotation_property)
@@ -14176,6 +14262,12 @@ static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
        drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
 
        return &cursor->base;
+
+fail:
+       kfree(state);
+       kfree(cursor);
+
+       return NULL;
 }
 
 static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc,
@@ -16151,7 +16243,7 @@ intel_display_capture_error_state(struct drm_device *dev)
 
        /* Note: this does not include DSI transcoders. */
        error->num_transcoders = INTEL_INFO(dev)->num_pipes;
-       if (HAS_DDI(dev_priv->dev))
+       if (HAS_DDI(dev_priv))
                error->num_transcoders++; /* Account for eDP. */
 
        for (i = 0; i < error->num_transcoders; i++) {
This page took 0.046292 seconds and 5 git commands to generate.