Merge tag 'v3.9-rc5' into drm-intel-next-queued
[cascardo/linux.git] / drivers / gpu / drm / i915 / intel_display.c
index b20d501..181bd0e 100644 (file)
@@ -71,8 +71,24 @@ typedef struct intel_limit intel_limit_t;
 struct intel_limit {
        intel_range_t   dot, vco, n, m, m1, m2, p, p1;
        intel_p2_t          p2;
-       bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
-                       int, int, intel_clock_t *, intel_clock_t *);
+       /**
+        * find_pll() - Find the best values for the PLL
+        * @limit: limits for the PLL
+        * @crtc: current CRTC
+        * @target: target frequency in kHz
+        * @refclk: reference clock frequency in kHz
+        * @match_clock: if provided, @best_clock P divider must
+        *               match the P divider from @match_clock
+        *               used for LVDS downclocking
+        * @best_clock: best PLL values found
+        *
+        * Returns true on success, false on failure.
+        */
+       bool (*find_pll)(const intel_limit_t *limit,
+                        struct drm_crtc *crtc,
+                        int target, int refclk,
+                        intel_clock_t *match_clock,
+                        intel_clock_t *best_clock);
 };
 
 /* FDI */
@@ -471,7 +487,6 @@ static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
 
        if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
                if (intel_is_dual_link_lvds(dev)) {
-                       /* LVDS dual channel */
                        if (refclk == 100000)
                                limit = &intel_limits_ironlake_dual_lvds_100m;
                        else
@@ -498,10 +513,8 @@ static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
 
        if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
                if (intel_is_dual_link_lvds(dev))
-                       /* LVDS with dual channel */
                        limit = &intel_limits_g4x_dual_channel_lvds;
                else
-                       /* LVDS with dual channel */
                        limit = &intel_limits_g4x_single_channel_lvds;
        } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
                   intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
@@ -1254,7 +1267,7 @@ static void assert_planes_disabled(struct drm_i915_private *dev_priv,
        int cur_pipe;
 
        /* Planes are fixed to pipes on ILK+ */
-       if (HAS_PCH_SPLIT(dev_priv->dev)) {
+       if (HAS_PCH_SPLIT(dev_priv->dev) || IS_VALLEYVIEW(dev_priv->dev)) {
                reg = DSPCNTR(pipe);
                val = I915_READ(reg);
                WARN((val & DISPLAY_PLANE_ENABLE),
@@ -1275,6 +1288,25 @@ static void assert_planes_disabled(struct drm_i915_private *dev_priv,
        }
 }
 
+static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
+                                   enum pipe pipe)
+{
+       int reg, i;
+       u32 val;
+
+       if (!IS_VALLEYVIEW(dev_priv->dev))
+               return;
+
+       /* Need to check both planes against the pipe */
+       for (i = 0; i < dev_priv->num_plane; i++) {
+               reg = SPCNTR(pipe, i);
+               val = I915_READ(reg);
+               WARN((val & SP_ENABLE),
+                    "sprite %d assertion failure, should be off on pipe %c but is still active\n",
+                    pipe * 2 + i, pipe_name(pipe));
+       }
+}
+
 static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
 {
        u32 val;
@@ -1327,14 +1359,14 @@ static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
 static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
                              enum pipe pipe, u32 val)
 {
-       if ((val & PORT_ENABLE) == 0)
+       if ((val & SDVO_ENABLE) == 0)
                return false;
 
        if (HAS_PCH_CPT(dev_priv->dev)) {
-               if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
+               if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
                        return false;
        } else {
-               if ((val & TRANSCODER_MASK) != TRANSCODER(pipe))
+               if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
                        return false;
        }
        return true;
@@ -1392,7 +1424,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",
             reg, pipe_name(pipe));
 
-       WARN(HAS_PCH_IBX(dev_priv->dev) && (val & PORT_ENABLE) == 0
+       WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
             && (val & SDVO_PIPE_B_SELECT),
             "IBX PCH hdmi port still using transcoder B\n");
 }
@@ -1419,9 +1451,9 @@ static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
             "PCH LVDS enabled on transcoder %c, should be disabled\n",
             pipe_name(pipe));
 
-       assert_pch_hdmi_disabled(dev_priv, pipe, HDMIB);
-       assert_pch_hdmi_disabled(dev_priv, pipe, HDMIC);
-       assert_pch_hdmi_disabled(dev_priv, pipe, HDMID);
+       assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
+       assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
+       assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
 }
 
 /**
@@ -1859,6 +1891,7 @@ static void intel_disable_pipe(struct drm_i915_private *dev_priv,
         * or we might hang the display.
         */
        assert_planes_disabled(dev_priv, pipe);
+       assert_sprites_disabled(dev_priv, pipe);
 
        /* Don't disable pipe A or pipe A PLLs if needed */
        if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
@@ -1937,6 +1970,15 @@ static void intel_disable_plane(struct drm_i915_private *dev_priv,
        intel_wait_for_vblank(dev_priv->dev, pipe);
 }
 
+static bool need_vtd_wa(struct drm_device *dev)
+{
+#ifdef CONFIG_INTEL_IOMMU
+       if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
+               return true;
+#endif
+       return false;
+}
+
 int
 intel_pin_and_fence_fb_obj(struct drm_device *dev,
                           struct drm_i915_gem_object *obj,
@@ -1967,6 +2009,14 @@ intel_pin_and_fence_fb_obj(struct drm_device *dev,
                BUG();
        }
 
+       /* Note that the w/a also requires 64 PTE of padding following the
+        * bo. We currently fill all unused PTE with the shadow page and so
+        * we should always have valid PTE following the scanout preventing
+        * the VT-d warning.
+        */
+       if (need_vtd_wa(dev) && alignment < 256 * 1024)
+               alignment = 256 * 1024;
+
        dev_priv->mm.interruptible = false;
        ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
        if (ret)
@@ -2083,8 +2133,7 @@ static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,
                dspcntr |= DISPPLANE_RGBX101010;
                break;
        default:
-               DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
-               return -EINVAL;
+               BUG();
        }
 
        if (INTEL_INFO(dev)->gen >= 4) {
@@ -2177,8 +2226,7 @@ static int ironlake_update_plane(struct drm_crtc *crtc,
                dspcntr |= DISPPLANE_RGBX101010;
                break;
        default:
-               DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
-               return -EINVAL;
+               BUG();
        }
 
        if (obj->tiling_mode != I915_TILING_NONE)
@@ -2229,6 +2277,44 @@ intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
        return dev_priv->display.update_plane(crtc, fb, x, y);
 }
 
+void intel_display_handle_reset(struct drm_device *dev)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct drm_crtc *crtc;
+
+       /*
+        * Flips in the rings have been nuked by the reset,
+        * so complete all pending flips so that user space
+        * will get its events and not get stuck.
+        *
+        * Also update the base address of all primary
+        * planes to the the last fb to make sure we're
+        * showing the correct fb after a reset.
+        *
+        * Need to make two loops over the crtcs so that we
+        * don't try to grab a crtc mutex before the
+        * pending_flip_queue really got woken up.
+        */
+
+       list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
+               struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+               enum plane plane = intel_crtc->plane;
+
+               intel_prepare_page_flip(dev, plane);
+               intel_finish_page_flip_plane(dev, plane);
+       }
+
+       list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
+               struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+
+               mutex_lock(&crtc->mutex);
+               if (intel_crtc->active)
+                       dev_priv->display.update_plane(crtc, crtc->fb,
+                                                      crtc->x, crtc->y);
+               mutex_unlock(&crtc->mutex);
+       }
+}
+
 static int
 intel_finish_fb(struct drm_framebuffer *old_fb)
 {
@@ -2295,10 +2381,10 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
                return 0;
        }
 
-       if(intel_crtc->plane > dev_priv->num_pipe) {
+       if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
                DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n",
                                intel_crtc->plane,
-                               dev_priv->num_pipe);
+                               INTEL_INFO(dev)->num_pipes);
                return -EINVAL;
        }
 
@@ -2312,9 +2398,6 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
                return ret;
        }
 
-       if (crtc->fb)
-               intel_finish_fb(crtc->fb);
-
        ret = dev_priv->display.update_plane(crtc, fb, x, y);
        if (ret) {
                intel_unpin_fb_obj(to_intel_framebuffer(fb)->obj);
@@ -2912,27 +2995,6 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
        mutex_unlock(&dev->struct_mutex);
 }
 
-static bool ironlake_crtc_driving_pch(struct drm_crtc *crtc)
-{
-       struct drm_device *dev = crtc->dev;
-       struct intel_encoder *intel_encoder;
-
-       /*
-        * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
-        * must be driven by its own crtc; no sharing is possible.
-        */
-       for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
-               switch (intel_encoder->type) {
-               case INTEL_OUTPUT_EDP:
-                       if (!intel_encoder_is_pch_edp(&intel_encoder->base))
-                               return false;
-                       continue;
-               }
-       }
-
-       return true;
-}
-
 static bool haswell_crtc_driving_pch(struct drm_crtc *crtc)
 {
        return intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG);
@@ -3273,7 +3335,6 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
        int pipe = intel_crtc->pipe;
        int plane = intel_crtc->plane;
        u32 temp;
-       bool is_pch_port;
 
        WARN_ON(!crtc->enabled);
 
@@ -3289,9 +3350,8 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
                        I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
        }
 
-       is_pch_port = ironlake_crtc_driving_pch(crtc);
 
-       if (is_pch_port) {
+       if (intel_crtc->config.has_pch_encoder) {
                /* Note: FDI PLL enabling _must_ be done before we enable the
                 * cpu pipes, hence this is separate from all the other fdi/pch
                 * enabling. */
@@ -3328,10 +3388,11 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
         */
        intel_crtc_load_lut(crtc);
 
-       intel_enable_pipe(dev_priv, pipe, is_pch_port);
+       intel_enable_pipe(dev_priv, pipe,
+                         intel_crtc->config.has_pch_encoder);
        intel_enable_plane(dev_priv, plane, pipe);
 
-       if (is_pch_port)
+       if (intel_crtc->config.has_pch_encoder)
                ironlake_pch_enable(crtc);
 
        mutex_lock(&dev->struct_mutex);
@@ -3365,7 +3426,6 @@ static void haswell_crtc_enable(struct drm_crtc *crtc)
        struct intel_encoder *encoder;
        int pipe = intel_crtc->pipe;
        int plane = intel_crtc->plane;
-       bool is_pch_port;
 
        WARN_ON(!crtc->enabled);
 
@@ -3375,9 +3435,7 @@ static void haswell_crtc_enable(struct drm_crtc *crtc)
        intel_crtc->active = true;
        intel_update_watermarks(dev);
 
-       is_pch_port = haswell_crtc_driving_pch(crtc);
-
-       if (is_pch_port)
+       if (intel_crtc->config.has_pch_encoder)
                dev_priv->display.fdi_link_train(crtc);
 
        for_each_encoder_on_crtc(dev, crtc, encoder)
@@ -3406,12 +3464,13 @@ static void haswell_crtc_enable(struct drm_crtc *crtc)
        intel_crtc_load_lut(crtc);
 
        intel_ddi_set_pipe_settings(crtc);
-       intel_ddi_enable_pipe_func(crtc);
+       intel_ddi_enable_transcoder_func(crtc);
 
-       intel_enable_pipe(dev_priv, pipe, is_pch_port);
+       intel_enable_pipe(dev_priv, pipe,
+                         intel_crtc->config.has_pch_encoder);
        intel_enable_plane(dev_priv, plane, pipe);
 
-       if (is_pch_port)
+       if (intel_crtc->config.has_pch_encoder)
                lpt_pch_enable(crtc);
 
        mutex_lock(&dev->struct_mutex);
@@ -3906,22 +3965,23 @@ bool intel_connector_get_hw_state(struct intel_connector *connector)
        return encoder->get_hw_state(encoder, &pipe);
 }
 
-static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
-                                 const struct drm_display_mode *mode,
-                                 struct drm_display_mode *adjusted_mode)
+static bool intel_crtc_compute_config(struct drm_crtc *crtc,
+                                     struct intel_crtc_config *pipe_config)
 {
        struct drm_device *dev = crtc->dev;
+       struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
 
        if (HAS_PCH_SPLIT(dev)) {
                /* FDI link clock is fixed at 2.7G */
-               if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
+               if (pipe_config->requested_mode.clock * 3
+                   > IRONLAKE_FDI_FREQ * 4)
                        return false;
        }
 
        /* All interlaced capable intel hw wants timings in frames. Note though
         * that intel_lvds_mode_fixup does some funny tricks with the crtc
         * timings, so we need to be careful not to clobber these.*/
-       if (!(adjusted_mode->private_flags & INTEL_MODE_CRTC_TIMINGS_SET))
+       if (!pipe_config->timings_set)
                drm_mode_set_crtcinfo(adjusted_mode, 0);
 
        /* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes
@@ -3931,6 +3991,14 @@ static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
                adjusted_mode->hsync_start == adjusted_mode->hdisplay)
                return false;
 
+       if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10) {
+               pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
+       } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8) {
+               /* only a 8bpc pipe, with 6bpc dither through the panel fitter
+                * for lvds. */
+               pipe_config->pipe_bpp = 8*3;
+       }
+
        return true;
 }
 
@@ -4034,142 +4102,6 @@ static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
                && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
 }
 
-/**
- * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send
- * @crtc: CRTC structure
- * @mode: requested mode
- *
- * A pipe may be connected to one or more outputs.  Based on the depth of the
- * attached framebuffer, choose a good color depth to use on the pipe.
- *
- * If possible, match the pipe depth to the fb depth.  In some cases, this
- * isn't ideal, because the connected output supports a lesser or restricted
- * set of depths.  Resolve that here:
- *    LVDS typically supports only 6bpc, so clamp down in that case
- *    HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc
- *    Displays may support a restricted set as well, check EDID and clamp as
- *      appropriate.
- *    DP may want to dither down to 6bpc to fit larger modes
- *
- * RETURNS:
- * Dithering requirement (i.e. false if display bpc and pipe bpc match,
- * true if they don't match).
- */
-static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
-                                        struct drm_framebuffer *fb,
-                                        unsigned int *pipe_bpp,
-                                        struct drm_display_mode *mode)
-{
-       struct drm_device *dev = crtc->dev;
-       struct drm_i915_private *dev_priv = dev->dev_private;
-       struct drm_connector *connector;
-       struct intel_encoder *intel_encoder;
-       unsigned int display_bpc = UINT_MAX, bpc;
-
-       /* Walk the encoders & connectors on this crtc, get min bpc */
-       for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
-
-               if (intel_encoder->type == INTEL_OUTPUT_LVDS) {
-                       unsigned int lvds_bpc;
-
-                       if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) ==
-                           LVDS_A3_POWER_UP)
-                               lvds_bpc = 8;
-                       else
-                               lvds_bpc = 6;
-
-                       if (lvds_bpc < display_bpc) {
-                               DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc);
-                               display_bpc = lvds_bpc;
-                       }
-                       continue;
-               }
-
-               /* Not one of the known troublemakers, check the EDID */
-               list_for_each_entry(connector, &dev->mode_config.connector_list,
-                                   head) {
-                       if (connector->encoder != &intel_encoder->base)
-                               continue;
-
-                       /* Don't use an invalid EDID bpc value */
-                       if (connector->display_info.bpc &&
-                           connector->display_info.bpc < display_bpc) {
-                               DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc);
-                               display_bpc = connector->display_info.bpc;
-                       }
-               }
-
-               if (intel_encoder->type == INTEL_OUTPUT_EDP) {
-                       /* Use VBT settings if we have an eDP panel */
-                       unsigned int edp_bpc = dev_priv->edp.bpp / 3;
-
-                       if (edp_bpc && edp_bpc < display_bpc) {
-                               DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
-                               display_bpc = edp_bpc;
-                       }
-                       continue;
-               }
-
-               /*
-                * HDMI is either 12 or 8, so if the display lets 10bpc sneak
-                * through, clamp it down.  (Note: >12bpc will be caught below.)
-                */
-               if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
-                       if (display_bpc > 8 && display_bpc < 12) {
-                               DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
-                               display_bpc = 12;
-                       } else {
-                               DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
-                               display_bpc = 8;
-                       }
-               }
-       }
-
-       if (mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
-               DRM_DEBUG_KMS("Dithering DP to 6bpc\n");
-               display_bpc = 6;
-       }
-
-       /*
-        * We could just drive the pipe at the highest bpc all the time and
-        * enable dithering as needed, but that costs bandwidth.  So choose
-        * the minimum value that expresses the full color range of the fb but
-        * also stays within the max display bpc discovered above.
-        */
-
-       switch (fb->depth) {
-       case 8:
-               bpc = 8; /* since we go through a colormap */
-               break;
-       case 15:
-       case 16:
-               bpc = 6; /* min is 18bpp */
-               break;
-       case 24:
-               bpc = 8;
-               break;
-       case 30:
-               bpc = 10;
-               break;
-       case 48:
-               bpc = 12;
-               break;
-       default:
-               DRM_DEBUG("unsupported depth, assuming 24 bits\n");
-               bpc = min((unsigned int)8, display_bpc);
-               break;
-       }
-
-       display_bpc = min(display_bpc, bpc);
-
-       DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n",
-                     bpc, display_bpc);
-
-       *pipe_bpp = display_bpc * 3;
-
-       return display_bpc != bpc;
-}
-
 static int vlv_get_refclk(struct drm_crtc *crtc)
 {
        struct drm_device *dev = crtc->dev;
@@ -4271,14 +4203,15 @@ static void i9xx_update_pll_dividers(struct drm_crtc *crtc,
 }
 
 static void vlv_update_pll(struct drm_crtc *crtc,
-                          struct drm_display_mode *mode,
-                          struct drm_display_mode *adjusted_mode,
                           intel_clock_t *clock, intel_clock_t *reduced_clock,
                           int num_connectors)
 {
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+       struct drm_display_mode *adjusted_mode =
+               &intel_crtc->config.adjusted_mode;
+       struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
        int pipe = intel_crtc->pipe;
        u32 dpll, mdiv, pdiv;
        u32 bestn, bestm1, bestm2, bestp1, bestp2;
@@ -4345,11 +4278,11 @@ static void vlv_update_pll(struct drm_crtc *crtc,
 
        temp = 0;
        if (is_sdvo) {
-               temp = intel_mode_get_pixel_multiplier(adjusted_mode);
-               if (temp > 1)
-                       temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
-               else
-                       temp = 0;
+               temp = 0;
+               if (intel_crtc->config.pixel_multiplier > 1) {
+                       temp = (intel_crtc->config.pixel_multiplier - 1)
+                               << DPLL_MD_UDI_MULTIPLIER_SHIFT;
+               }
        }
        I915_WRITE(DPLL_MD(pipe), temp);
        POSTING_READ(DPLL_MD(pipe));
@@ -4375,14 +4308,15 @@ static void vlv_update_pll(struct drm_crtc *crtc,
 }
 
 static void i9xx_update_pll(struct drm_crtc *crtc,
-                           struct drm_display_mode *mode,
-                           struct drm_display_mode *adjusted_mode,
                            intel_clock_t *clock, intel_clock_t *reduced_clock,
                            int num_connectors)
 {
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+       struct drm_display_mode *adjusted_mode =
+               &intel_crtc->config.adjusted_mode;
+       struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
        struct intel_encoder *encoder;
        int pipe = intel_crtc->pipe;
        u32 dpll;
@@ -4399,11 +4333,12 @@ static void i9xx_update_pll(struct drm_crtc *crtc,
                dpll |= DPLLB_MODE_LVDS;
        else
                dpll |= DPLLB_MODE_DAC_SERIAL;
+
        if (is_sdvo) {
-               int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
-               if (pixel_multiplier > 1) {
-                       if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
-                               dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
+               if ((intel_crtc->config.pixel_multiplier > 1) &&
+                   (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))) {
+                       dpll |= (intel_crtc->config.pixel_multiplier - 1)
+                               << SDVO_MULTIPLIER_SHIFT_HIRES;
                }
                dpll |= DPLL_DVO_HIGH_SPEED;
        }
@@ -4468,11 +4403,11 @@ static void i9xx_update_pll(struct drm_crtc *crtc,
        if (INTEL_INFO(dev)->gen >= 4) {
                u32 temp = 0;
                if (is_sdvo) {
-                       temp = intel_mode_get_pixel_multiplier(adjusted_mode);
-                       if (temp > 1)
-                               temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
-                       else
-                               temp = 0;
+                       temp = 0;
+                       if (intel_crtc->config.pixel_multiplier > 1) {
+                               temp = (intel_crtc->config.pixel_multiplier - 1)
+                                       << DPLL_MD_UDI_MULTIPLIER_SHIFT;
+                       }
                }
                I915_WRITE(DPLL_MD(pipe), temp);
        } else {
@@ -4512,11 +4447,7 @@ static void i8xx_update_pll(struct drm_crtc *crtc,
                        dpll |= PLL_P2_DIVIDE_BY_4;
        }
 
-       if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
-               /* XXX: just matching BIOS for now */
-               /*      dpll |= PLL_REF_INPUT_TVCLKINBC; */
-               dpll |= 3;
-       else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
+       if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
                 intel_panel_use_ssc(dev_priv) && num_connectors < 2)
                dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
        else
@@ -4604,14 +4535,15 @@ static void intel_set_pipe_timings(struct intel_crtc *intel_crtc,
 }
 
 static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
-                             struct drm_display_mode *mode,
-                             struct drm_display_mode *adjusted_mode,
                              int x, int y,
                              struct drm_framebuffer *fb)
 {
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+       struct drm_display_mode *adjusted_mode =
+               &intel_crtc->config.adjusted_mode;
+       struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
        int pipe = intel_crtc->pipe;
        int plane = intel_crtc->plane;
        int refclk, num_connectors = 0;
@@ -4685,11 +4617,11 @@ static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
                                has_reduced_clock ? &reduced_clock : NULL,
                                num_connectors);
        else if (IS_VALLEYVIEW(dev))
-               vlv_update_pll(crtc, mode, adjusted_mode, &clock,
+               vlv_update_pll(crtc, &clock,
                                has_reduced_clock ? &reduced_clock : NULL,
                                num_connectors);
        else
-               i9xx_update_pll(crtc, mode, adjusted_mode, &clock,
+               i9xx_update_pll(crtc, &clock,
                                has_reduced_clock ? &reduced_clock : NULL,
                                num_connectors);
 
@@ -4699,10 +4631,12 @@ static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
        /* Set up the display plane register */
        dspcntr = DISPPLANE_GAMMA_ENABLE;
 
-       if (pipe == 0)
-               dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
-       else
-               dspcntr |= DISPPLANE_SEL_PIPE_B;
+       if (!IS_VALLEYVIEW(dev)) {
+               if (pipe == 0)
+                       dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
+               else
+                       dspcntr |= DISPPLANE_SEL_PIPE_B;
+       }
 
        if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
                /* Enable pixel doubling when the dot clock is > 90% of the (display)
@@ -4721,7 +4655,7 @@ static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
        /* default to 8bpc */
        pipeconf &= ~(PIPECONF_BPC_MASK | PIPECONF_DITHER_EN);
        if (is_dp) {
-               if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
+               if (intel_crtc->config.dither) {
                        pipeconf |= PIPECONF_6BPC |
                                    PIPECONF_DITHER_EN |
                                    PIPECONF_DITHER_TYPE_SP;
@@ -4729,7 +4663,7 @@ static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
        }
 
        if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
-               if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
+               if (intel_crtc->config.dither) {
                        pipeconf |= PIPECONF_6BPC |
                                        PIPECONF_ENABLE |
                                        I965_PIPECONF_ACTIVE;
@@ -4787,7 +4721,7 @@ static void ironlake_init_pch_refclk(struct drm_device *dev)
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct drm_mode_config *mode_config = &dev->mode_config;
        struct intel_encoder *encoder;
-       u32 temp;
+       u32 val, final;
        bool has_lvds = false;
        bool has_cpu_edp = false;
        bool has_pch_edp = false;
@@ -4830,70 +4764,109 @@ static void ironlake_init_pch_refclk(struct drm_device *dev)
         * PCH B stepping, previous chipset stepping should be
         * ignoring this setting.
         */
-       temp = I915_READ(PCH_DREF_CONTROL);
+       val = I915_READ(PCH_DREF_CONTROL);
+
+       /* As we must carefully and slowly disable/enable each source in turn,
+        * compute the final state we want first and check if we need to
+        * make any changes at all.
+        */
+       final = val;
+       final &= ~DREF_NONSPREAD_SOURCE_MASK;
+       if (has_ck505)
+               final |= DREF_NONSPREAD_CK505_ENABLE;
+       else
+               final |= DREF_NONSPREAD_SOURCE_ENABLE;
+
+       final &= ~DREF_SSC_SOURCE_MASK;
+       final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
+       final &= ~DREF_SSC1_ENABLE;
+
+       if (has_panel) {
+               final |= DREF_SSC_SOURCE_ENABLE;
+
+               if (intel_panel_use_ssc(dev_priv) && can_ssc)
+                       final |= DREF_SSC1_ENABLE;
+
+               if (has_cpu_edp) {
+                       if (intel_panel_use_ssc(dev_priv) && can_ssc)
+                               final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
+                       else
+                               final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
+               } else
+                       final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
+       } else {
+               final |= DREF_SSC_SOURCE_DISABLE;
+               final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
+       }
+
+       if (final == val)
+               return;
+
        /* Always enable nonspread source */
-       temp &= ~DREF_NONSPREAD_SOURCE_MASK;
+       val &= ~DREF_NONSPREAD_SOURCE_MASK;
 
        if (has_ck505)
-               temp |= DREF_NONSPREAD_CK505_ENABLE;
+               val |= DREF_NONSPREAD_CK505_ENABLE;
        else
-               temp |= DREF_NONSPREAD_SOURCE_ENABLE;
+               val |= DREF_NONSPREAD_SOURCE_ENABLE;
 
        if (has_panel) {
-               temp &= ~DREF_SSC_SOURCE_MASK;
-               temp |= DREF_SSC_SOURCE_ENABLE;
+               val &= ~DREF_SSC_SOURCE_MASK;
+               val |= DREF_SSC_SOURCE_ENABLE;
 
                /* SSC must be turned on before enabling the CPU output  */
                if (intel_panel_use_ssc(dev_priv) && can_ssc) {
                        DRM_DEBUG_KMS("Using SSC on panel\n");
-                       temp |= DREF_SSC1_ENABLE;
+                       val |= DREF_SSC1_ENABLE;
                } else
-                       temp &= ~DREF_SSC1_ENABLE;
+                       val &= ~DREF_SSC1_ENABLE;
 
                /* Get SSC going before enabling the outputs */
-               I915_WRITE(PCH_DREF_CONTROL, temp);
+               I915_WRITE(PCH_DREF_CONTROL, val);
                POSTING_READ(PCH_DREF_CONTROL);
                udelay(200);
 
-               temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
+               val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
 
                /* Enable CPU source on CPU attached eDP */
                if (has_cpu_edp) {
                        if (intel_panel_use_ssc(dev_priv) && can_ssc) {
                                DRM_DEBUG_KMS("Using SSC on eDP\n");
-                               temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
+                               val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
                        }
                        else
-                               temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
+                               val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
                } else
-                       temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
+                       val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
 
-               I915_WRITE(PCH_DREF_CONTROL, temp);
+               I915_WRITE(PCH_DREF_CONTROL, val);
                POSTING_READ(PCH_DREF_CONTROL);
                udelay(200);
        } else {
                DRM_DEBUG_KMS("Disabling SSC entirely\n");
 
-               temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
+               val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
 
                /* Turn off CPU output */
-               temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
+               val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
 
-               I915_WRITE(PCH_DREF_CONTROL, temp);
+               I915_WRITE(PCH_DREF_CONTROL, val);
                POSTING_READ(PCH_DREF_CONTROL);
                udelay(200);
 
                /* Turn off the SSC source */
-               temp &= ~DREF_SSC_SOURCE_MASK;
-               temp |= DREF_SSC_SOURCE_DISABLE;
+               val &= ~DREF_SSC_SOURCE_MASK;
+               val |= DREF_SSC_SOURCE_DISABLE;
 
                /* Turn off SSC1 */
-               temp &= ~ DREF_SSC1_ENABLE;
+               val &= ~DREF_SSC1_ENABLE;
 
-               I915_WRITE(PCH_DREF_CONTROL, temp);
+               I915_WRITE(PCH_DREF_CONTROL, val);
                POSTING_READ(PCH_DREF_CONTROL);
                udelay(200);
        }
+
+       BUG_ON(val != final);
 }
 
 /* Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O. */
@@ -5118,7 +5091,7 @@ static void ironlake_set_pipeconf(struct drm_crtc *crtc,
        val = I915_READ(PIPECONF(pipe));
 
        val &= ~PIPECONF_BPC_MASK;
-       switch (intel_crtc->bpp) {
+       switch (intel_crtc->config.pipe_bpp) {
        case 18:
                val |= PIPECONF_6BPC;
                break;
@@ -5146,7 +5119,7 @@ static void ironlake_set_pipeconf(struct drm_crtc *crtc,
        else
                val |= PIPECONF_PROGRESSIVE;
 
-       if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
+       if (intel_crtc->config.limited_color_range)
                val |= PIPECONF_COLOR_RANGE_SELECT;
        else
                val &= ~PIPECONF_COLOR_RANGE_SELECT;
@@ -5162,8 +5135,7 @@ static void ironlake_set_pipeconf(struct drm_crtc *crtc,
  * is supported, but eventually this should handle various
  * RGB<->YCbCr scenarios as well.
  */
-static void intel_set_pipe_csc(struct drm_crtc *crtc,
-                              const struct drm_display_mode *adjusted_mode)
+static void intel_set_pipe_csc(struct drm_crtc *crtc)
 {
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -5178,7 +5150,7 @@ static void intel_set_pipe_csc(struct drm_crtc *crtc,
         * consideration.
         */
 
-       if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
+       if (intel_crtc->config.limited_color_range)
                coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
 
        /*
@@ -5202,7 +5174,7 @@ static void intel_set_pipe_csc(struct drm_crtc *crtc,
        if (INTEL_INFO(dev)->gen > 6) {
                uint16_t postoff = 0;
 
-               if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
+               if (intel_crtc->config.limited_color_range)
                        postoff = (16 * (1 << 13) / 255) & 0x1fff;
 
                I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
@@ -5213,7 +5185,7 @@ static void intel_set_pipe_csc(struct drm_crtc *crtc,
        } else {
                uint32_t mode = CSC_MODE_YUV_TO_RGB;
 
-               if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
+               if (intel_crtc->config.limited_color_range)
                        mode |= CSC_BLACK_SCREEN_OFFSET;
 
                I915_WRITE(PIPE_CSC_MODE(pipe), mode);
@@ -5344,7 +5316,7 @@ static bool ironlake_check_fdi_lanes(struct intel_crtc *intel_crtc)
                return false;
        }
 
-       if (dev_priv->num_pipe == 2)
+       if (INTEL_INFO(dev)->num_pipes == 2)
                return true;
 
        switch (intel_crtc->pipe) {
@@ -5401,17 +5373,18 @@ int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
        return bps / (link_bw * 8) + 1;
 }
 
-static void ironlake_set_m_n(struct drm_crtc *crtc,
-                            struct drm_display_mode *mode,
-                            struct drm_display_mode *adjusted_mode)
+static void ironlake_set_m_n(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);
+       struct drm_display_mode *adjusted_mode =
+               &intel_crtc->config.adjusted_mode;
+       struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
        enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
        struct intel_encoder *intel_encoder, *edp_encoder = NULL;
        struct intel_link_m_n m_n = {0};
-       int target_clock, pixel_multiplier, lane, link_bw;
+       int target_clock, lane, link_bw;
        bool is_dp = false, is_cpu_edp = false;
 
        for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
@@ -5429,7 +5402,6 @@ static void ironlake_set_m_n(struct drm_crtc *crtc,
        }
 
        /* FDI link */
-       pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
        lane = 0;
        /* CPU eDP doesn't require FDI link, so just set DP M/N
           according to current link config */
@@ -5456,13 +5428,14 @@ static void ironlake_set_m_n(struct drm_crtc *crtc,
 
        if (!lane)
                lane = ironlake_get_lanes_required(target_clock, link_bw,
-                                                  intel_crtc->bpp);
+                                                  intel_crtc->config.pipe_bpp);
 
        intel_crtc->fdi_lanes = lane;
 
-       if (pixel_multiplier > 1)
-               link_bw *= pixel_multiplier;
-       intel_link_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw, &m_n);
+       if (intel_crtc->config.pixel_multiplier > 1)
+               link_bw *= intel_crtc->config.pixel_multiplier;
+       intel_link_compute_m_n(intel_crtc->config.pipe_bpp, lane, target_clock,
+                              link_bw, &m_n);
 
        I915_WRITE(PIPE_DATA_M1(cpu_transcoder), TU_SIZE(m_n.tu) | m_n.gmch_m);
        I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n);
@@ -5471,7 +5444,6 @@ static void ironlake_set_m_n(struct drm_crtc *crtc,
 }
 
 static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
-                                     struct drm_display_mode *adjusted_mode,
                                      intel_clock_t *clock, u32 fp)
 {
        struct drm_crtc *crtc = &intel_crtc->base;
@@ -5479,7 +5451,7 @@ static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_encoder *intel_encoder;
        uint32_t dpll;
-       int factor, pixel_multiplier, num_connectors = 0;
+       int factor, num_connectors = 0;
        bool is_lvds = false, is_sdvo = false, is_tv = false;
        bool is_dp = false, is_cpu_edp = false;
 
@@ -5530,9 +5502,9 @@ static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
        else
                dpll |= DPLLB_MODE_DAC_SERIAL;
        if (is_sdvo) {
-               pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
-               if (pixel_multiplier > 1) {
-                       dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
+               if (intel_crtc->config.pixel_multiplier > 1) {
+                       dpll |= (intel_crtc->config.pixel_multiplier - 1)
+                               << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
                }
                dpll |= DPLL_DVO_HIGH_SPEED;
        }
@@ -5574,14 +5546,15 @@ static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
 }
 
 static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
-                                 struct drm_display_mode *mode,
-                                 struct drm_display_mode *adjusted_mode,
                                  int x, int y,
                                  struct drm_framebuffer *fb)
 {
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+       struct drm_display_mode *adjusted_mode =
+               &intel_crtc->config.adjusted_mode;
+       struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
        int pipe = intel_crtc->pipe;
        int plane = intel_crtc->plane;
        int num_connectors = 0;
@@ -5625,8 +5598,7 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
        intel_crtc_update_cursor(crtc, true);
 
        /* determine panel color depth */
-       dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
-                                             adjusted_mode);
+       dither = intel_crtc->config.dither;
        if (is_lvds && dev_priv->lvds_dither)
                dither = true;
 
@@ -5635,7 +5607,7 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
                fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
                        reduced_clock.m2;
 
-       dpll = ironlake_compute_dpll(intel_crtc, adjusted_mode, &clock, fp);
+       dpll = ironlake_compute_dpll(intel_crtc, &clock, fp);
 
        DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
        drm_mode_debug_printmodeline(mode);
@@ -5689,7 +5661,7 @@ static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
 
        /* Note, this also computes intel_crtc->fdi_lanes which is used below in
         * ironlake_check_fdi_lanes. */
-       ironlake_set_m_n(crtc, mode, adjusted_mode);
+       ironlake_set_m_n(crtc);
 
        fdi_config_ok = ironlake_check_fdi_lanes(intel_crtc);
 
@@ -5740,14 +5712,15 @@ static void haswell_modeset_global_resources(struct drm_device *dev)
 }
 
 static int haswell_crtc_mode_set(struct drm_crtc *crtc,
-                                struct drm_display_mode *mode,
-                                struct drm_display_mode *adjusted_mode,
                                 int x, int y,
                                 struct drm_framebuffer *fb)
 {
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+       struct drm_display_mode *adjusted_mode =
+               &intel_crtc->config.adjusted_mode;
+       struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
        int pipe = intel_crtc->pipe;
        int plane = intel_crtc->plane;
        int num_connectors = 0;
@@ -5795,8 +5768,7 @@ static int haswell_crtc_mode_set(struct drm_crtc *crtc,
        intel_crtc_update_cursor(crtc, true);
 
        /* determine panel color depth */
-       dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
-                                             adjusted_mode);
+       dither = intel_crtc->config.dither;
 
        DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
        drm_mode_debug_printmodeline(mode);
@@ -5809,11 +5781,11 @@ static int haswell_crtc_mode_set(struct drm_crtc *crtc,
        intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
 
        if (!is_dp || is_cpu_edp)
-               ironlake_set_m_n(crtc, mode, adjusted_mode);
+               ironlake_set_m_n(crtc);
 
        haswell_set_pipeconf(crtc, adjusted_mode, dither);
 
-       intel_set_pipe_csc(crtc, adjusted_mode);
+       intel_set_pipe_csc(crtc);
 
        /* Set up the display plane register */
        I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE | DISPPLANE_PIPE_CSC_ENABLE);
@@ -5829,8 +5801,6 @@ static int haswell_crtc_mode_set(struct drm_crtc *crtc,
 }
 
 static int intel_crtc_mode_set(struct drm_crtc *crtc,
-                              struct drm_display_mode *mode,
-                              struct drm_display_mode *adjusted_mode,
                               int x, int y,
                               struct drm_framebuffer *fb)
 {
@@ -5839,13 +5809,16 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
        struct drm_encoder_helper_funcs *encoder_funcs;
        struct intel_encoder *encoder;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+       struct drm_display_mode *adjusted_mode =
+               &intel_crtc->config.adjusted_mode;
+       struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
        int pipe = intel_crtc->pipe;
        int ret;
 
        drm_vblank_pre_modeset(dev, pipe);
 
-       ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
-                                             x, y, fb);
+       ret = dev_priv->display.crtc_mode_set(crtc, x, y, fb);
+
        drm_vblank_post_modeset(dev, pipe);
 
        if (ret != 0)
@@ -5856,8 +5829,12 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc,
                        encoder->base.base.id,
                        drm_get_encoder_name(&encoder->base),
                        mode->base.id, mode->name);
-               encoder_funcs = encoder->base.helper_private;
-               encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode);
+               if (encoder->mode_set) {
+                       encoder->mode_set(encoder);
+               } else {
+                       encoder_funcs = encoder->base.helper_private;
+                       encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode);
+               }
        }
 
        return 0;
@@ -6325,13 +6302,24 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc,
        /* we only need to pin inside GTT if cursor is non-phy */
        mutex_lock(&dev->struct_mutex);
        if (!dev_priv->info->cursor_needs_physical) {
+               unsigned alignment;
+
                if (obj->tiling_mode) {
                        DRM_ERROR("cursor cannot be tiled\n");
                        ret = -EINVAL;
                        goto fail_locked;
                }
 
-               ret = i915_gem_object_pin_to_display_plane(obj, 0, NULL);
+               /* Note that the w/a also requires 2 PTE of padding following
+                * the bo. We currently fill all unused PTE with the shadow
+                * page and so we should always have valid PTE following the
+                * cursor preventing the VT-d warning.
+                */
+               alignment = 0;
+               if (need_vtd_wa(dev))
+                       alignment = 64*1024;
+
+               ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL);
                if (ret) {
                        DRM_ERROR("failed to move cursor bo into the GTT\n");
                        goto fail_locked;
@@ -6436,20 +6424,6 @@ static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
        intel_crtc_load_lut(crtc);
 }
 
-/**
- * Get a pipe with a simple mode set on it for doing load-based monitor
- * detection.
- *
- * It will be up to the load-detect code to adjust the pipe as appropriate for
- * its requirements.  The pipe will be connected to no other encoders.
- *
- * Currently this code will only succeed if there is a pipe with no encoders
- * configured for it.  In the future, it could choose to temporarily disable
- * some outputs to free up a pipe for its use.
- *
- * \return crtc, or NULL if no pipes are available.
- */
-
 /* VESA 640x480x72Hz mode to set on the pipe */
 static struct drm_display_mode load_detect_mode = {
        DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
@@ -6954,7 +6928,6 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
        drm_i915_private_t *dev_priv = dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        struct intel_unpin_work *work;
-       struct drm_i915_gem_object *obj;
        unsigned long flags;
 
        /* Ignore early vblank irqs */
@@ -6984,8 +6957,6 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
 
        spin_unlock_irqrestore(&dev->event_lock, flags);
 
-       obj = work->old_fb_obj;
-
        wake_up_all(&dev_priv->pending_flip_queue);
 
        queue_work(dev_priv->wq, &work->work);
@@ -7473,19 +7444,93 @@ static void intel_modeset_commit_output_state(struct drm_device *dev)
        }
 }
 
-static struct drm_display_mode *
-intel_modeset_adjusted_mode(struct drm_crtc *crtc,
-                           struct drm_display_mode *mode)
+static int
+pipe_config_set_bpp(struct drm_crtc *crtc,
+                   struct drm_framebuffer *fb,
+                   struct intel_crtc_config *pipe_config)
+{
+       struct drm_device *dev = crtc->dev;
+       struct drm_connector *connector;
+       int bpp;
+
+       switch (fb->pixel_format) {
+       case DRM_FORMAT_C8:
+               bpp = 8*3; /* since we go through a colormap */
+               break;
+       case DRM_FORMAT_XRGB1555:
+       case DRM_FORMAT_ARGB1555:
+               /* checked in intel_framebuffer_init already */
+               if (WARN_ON(INTEL_INFO(dev)->gen > 3))
+                       return -EINVAL;
+       case DRM_FORMAT_RGB565:
+               bpp = 6*3; /* min is 18bpp */
+               break;
+       case DRM_FORMAT_XBGR8888:
+       case DRM_FORMAT_ABGR8888:
+               /* checked in intel_framebuffer_init already */
+               if (WARN_ON(INTEL_INFO(dev)->gen < 4))
+                       return -EINVAL;
+       case DRM_FORMAT_XRGB8888:
+       case DRM_FORMAT_ARGB8888:
+               bpp = 8*3;
+               break;
+       case DRM_FORMAT_XRGB2101010:
+       case DRM_FORMAT_ARGB2101010:
+       case DRM_FORMAT_XBGR2101010:
+       case DRM_FORMAT_ABGR2101010:
+               /* checked in intel_framebuffer_init already */
+               if (WARN_ON(INTEL_INFO(dev)->gen < 4))
+                       return -EINVAL;
+               bpp = 10*3;
+               break;
+       /* TODO: gen4+ supports 16 bpc floating point, too. */
+       default:
+               DRM_DEBUG_KMS("unsupported depth\n");
+               return -EINVAL;
+       }
+
+       pipe_config->pipe_bpp = bpp;
+
+       /* Clamp display bpp to EDID value */
+       list_for_each_entry(connector, &dev->mode_config.connector_list,
+                           head) {
+               if (connector->encoder && connector->encoder->crtc != crtc)
+                       continue;
+
+               /* Don't use an invalid EDID bpc value */
+               if (connector->display_info.bpc &&
+                   connector->display_info.bpc * 3 < bpp) {
+                       DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
+                                     bpp, connector->display_info.bpc*3);
+                       pipe_config->pipe_bpp = connector->display_info.bpc*3;
+               }
+       }
+
+       return bpp;
+}
+
+static struct intel_crtc_config *
+intel_modeset_pipe_config(struct drm_crtc *crtc,
+                         struct drm_framebuffer *fb,
+                         struct drm_display_mode *mode)
 {
        struct drm_device *dev = crtc->dev;
-       struct drm_display_mode *adjusted_mode;
        struct drm_encoder_helper_funcs *encoder_funcs;
        struct intel_encoder *encoder;
+       struct intel_crtc_config *pipe_config;
+       int plane_bpp;
 
-       adjusted_mode = drm_mode_duplicate(dev, mode);
-       if (!adjusted_mode)
+       pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
+       if (!pipe_config)
                return ERR_PTR(-ENOMEM);
 
+       drm_mode_copy(&pipe_config->adjusted_mode, mode);
+       drm_mode_copy(&pipe_config->requested_mode, mode);
+
+       plane_bpp = pipe_config_set_bpp(crtc, fb, pipe_config);
+       if (plane_bpp < 0)
+               goto fail;
+
        /* Pass our mode to the connectors and the CRTC to give them a chance to
         * adjust it according to limitations or connector properties, and also
         * a chance to reject the mode entirely.
@@ -7495,23 +7540,38 @@ intel_modeset_adjusted_mode(struct drm_crtc *crtc,
 
                if (&encoder->new_crtc->base != crtc)
                        continue;
+
+               if (encoder->compute_config) {
+                       if (!(encoder->compute_config(encoder, pipe_config))) {
+                               DRM_DEBUG_KMS("Encoder config failure\n");
+                               goto fail;
+                       }
+
+                       continue;
+               }
+
                encoder_funcs = encoder->base.helper_private;
-               if (!(encoder_funcs->mode_fixup(&encoder->base, mode,
-                                               adjusted_mode))) {
+               if (!(encoder_funcs->mode_fixup(&encoder->base,
+                                               &pipe_config->requested_mode,
+                                               &pipe_config->adjusted_mode))) {
                        DRM_DEBUG_KMS("Encoder fixup failed\n");
                        goto fail;
                }
        }
 
-       if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
+       if (!(intel_crtc_compute_config(crtc, pipe_config))) {
                DRM_DEBUG_KMS("CRTC fixup failed\n");
                goto fail;
        }
        DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
 
-       return adjusted_mode;
+       pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
+       DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
+                     plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
+
+       return pipe_config;
 fail:
-       drm_mode_destroy(dev, adjusted_mode);
+       kfree(pipe_config);
        return ERR_PTR(-EINVAL);
 }
 
@@ -7777,7 +7837,8 @@ int intel_set_mode(struct drm_crtc *crtc,
 {
        struct drm_device *dev = crtc->dev;
        drm_i915_private_t *dev_priv = dev->dev_private;
-       struct drm_display_mode *adjusted_mode, *saved_mode, *saved_hwmode;
+       struct drm_display_mode *saved_mode, *saved_hwmode;
+       struct intel_crtc_config *pipe_config = NULL;
        struct intel_crtc *intel_crtc;
        unsigned disable_pipes, prepare_pipes, modeset_pipes;
        int ret = 0;
@@ -7790,12 +7851,6 @@ int intel_set_mode(struct drm_crtc *crtc,
        intel_modeset_affected_pipes(crtc, &modeset_pipes,
                                     &prepare_pipes, &disable_pipes);
 
-       DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
-                     modeset_pipes, prepare_pipes, disable_pipes);
-
-       for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
-               intel_crtc_disable(&intel_crtc->base);
-
        *saved_hwmode = crtc->hwmode;
        *saved_mode = crtc->mode;
 
@@ -7804,15 +7859,22 @@ int intel_set_mode(struct drm_crtc *crtc,
         * Hence simply check whether any bit is set in modeset_pipes in all the
         * pieces of code that are not yet converted to deal with mutliple crtcs
         * changing their mode at the same time. */
-       adjusted_mode = NULL;
        if (modeset_pipes) {
-               adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
-               if (IS_ERR(adjusted_mode)) {
-                       ret = PTR_ERR(adjusted_mode);
+               pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
+               if (IS_ERR(pipe_config)) {
+                       ret = PTR_ERR(pipe_config);
+                       pipe_config = NULL;
+
                        goto out;
                }
        }
 
+       DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
+                     modeset_pipes, prepare_pipes, disable_pipes);
+
+       for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
+               intel_crtc_disable(&intel_crtc->base);
+
        for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
                if (intel_crtc->base.enabled)
                        dev_priv->display.crtc_disable(&intel_crtc->base);
@@ -7821,8 +7883,12 @@ int intel_set_mode(struct drm_crtc *crtc,
        /* crtc->mode is already used by the ->mode_set callbacks, hence we need
         * to set it here already despite that we pass it down the callchain.
         */
-       if (modeset_pipes)
+       if (modeset_pipes) {
                crtc->mode = *mode;
+               /* mode_set/enable/disable functions rely on a correct pipe
+                * config. */
+               to_intel_crtc(crtc)->config = *pipe_config;
+       }
 
        /* Only after disabling all output pipelines that will be changed can we
         * update the the output configuration. */
@@ -7836,7 +7902,6 @@ int intel_set_mode(struct drm_crtc *crtc,
         */
        for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
                ret = intel_crtc_mode_set(&intel_crtc->base,
-                                         mode, adjusted_mode,
                                          x, y, fb);
                if (ret)
                        goto done;
@@ -7848,7 +7913,7 @@ int intel_set_mode(struct drm_crtc *crtc,
 
        if (modeset_pipes) {
                /* Store real post-adjustment hardware mode. */
-               crtc->hwmode = *adjusted_mode;
+               crtc->hwmode = pipe_config->adjusted_mode;
 
                /* Calculate and store various constants which
                 * are later needed by vblank and swap-completion
@@ -7859,7 +7924,6 @@ int intel_set_mode(struct drm_crtc *crtc,
 
        /* FIXME: add subpixel order */
 done:
-       drm_mode_destroy(dev, adjusted_mode);
        if (ret && crtc->enabled) {
                crtc->hwmode = *saved_hwmode;
                crtc->mode = *saved_mode;
@@ -7868,6 +7932,7 @@ done:
        }
 
 out:
+       kfree(pipe_config);
        kfree(saved_mode);
        return ret;
 }
@@ -7959,10 +8024,8 @@ intel_set_config_compute_mode_changes(struct drm_mode_set *set,
                        config->mode_changed = true;
                } else if (set->fb == NULL) {
                        config->mode_changed = true;
-               } else if (set->fb->depth != set->crtc->fb->depth) {
-                       config->mode_changed = true;
-               } else if (set->fb->bits_per_pixel !=
-                          set->crtc->fb->bits_per_pixel) {
+               } else if (set->fb->pixel_format !=
+                          set->crtc->fb->pixel_format) {
                        config->mode_changed = true;
                } else
                        config->fb_changed = true;
@@ -8145,6 +8208,8 @@ static int intel_crtc_set_config(struct drm_mode_set *set)
                        goto fail;
                }
        } else if (config->fb_changed) {
+               intel_crtc_wait_for_pending_flips(set->crtc);
+
                ret = intel_pipe_set_base(set->crtc,
                                          set->x, set->y, set->fb);
        }
@@ -8232,8 +8297,6 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
        dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
        dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
 
-       intel_crtc->bpp = 24; /* default for pre-Ironlake */
-
        drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
 }
 
@@ -8343,20 +8406,20 @@ static void intel_setup_outputs(struct drm_device *dev)
                if (has_edp_a(dev))
                        intel_dp_init(dev, DP_A, PORT_A);
 
-               if (I915_READ(HDMIB) & PORT_DETECTED) {
+               if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
                        /* PCH SDVOB multiplex with HDMIB */
                        found = intel_sdvo_init(dev, PCH_SDVOB, true);
                        if (!found)
-                               intel_hdmi_init(dev, HDMIB, PORT_B);
+                               intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
                        if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
                                intel_dp_init(dev, PCH_DP_B, PORT_B);
                }
 
-               if (I915_READ(HDMIC) & PORT_DETECTED)
-                       intel_hdmi_init(dev, HDMIC, PORT_C);
+               if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
+                       intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
 
-               if (!dpd_is_edp && I915_READ(HDMID) & PORT_DETECTED)
-                       intel_hdmi_init(dev, HDMID, PORT_D);
+               if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
+                       intel_hdmi_init(dev, PCH_HDMID, PORT_D);
 
                if (I915_READ(PCH_DP_C) & DP_DETECTED)
                        intel_dp_init(dev, PCH_DP_C, PORT_C);
@@ -8368,24 +8431,21 @@ static void intel_setup_outputs(struct drm_device *dev)
                if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
                        intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
 
-               if (I915_READ(VLV_DISPLAY_BASE + SDVOB) & PORT_DETECTED) {
-                       intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOB, PORT_B);
+               if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED) {
+                       intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
+                                       PORT_B);
                        if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
                                intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
                }
-
-               if (I915_READ(VLV_DISPLAY_BASE + SDVOC) & PORT_DETECTED)
-                       intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOC, PORT_C);
-
        } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
                bool found = false;
 
-               if (I915_READ(SDVOB) & SDVO_DETECTED) {
+               if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
                        DRM_DEBUG_KMS("probing SDVOB\n");
-                       found = intel_sdvo_init(dev, SDVOB, true);
+                       found = intel_sdvo_init(dev, GEN3_SDVOB, true);
                        if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
                                DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
-                               intel_hdmi_init(dev, SDVOB, PORT_B);
+                               intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
                        }
 
                        if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
@@ -8396,16 +8456,16 @@ static void intel_setup_outputs(struct drm_device *dev)
 
                /* Before G4X SDVOC doesn't have its own detect register */
 
-               if (I915_READ(SDVOB) & SDVO_DETECTED) {
+               if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
                        DRM_DEBUG_KMS("probing SDVOC\n");
-                       found = intel_sdvo_init(dev, SDVOC, false);
+                       found = intel_sdvo_init(dev, GEN3_SDVOC, false);
                }
 
-               if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
+               if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
 
                        if (SUPPORTS_INTEGRATED_HDMI(dev)) {
                                DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
-                               intel_hdmi_init(dev, SDVOC, PORT_C);
+                               intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
                        }
                        if (SUPPORTS_INTEGRATED_DP(dev)) {
                                DRM_DEBUG_KMS("probing DP_C\n");
@@ -8572,7 +8632,6 @@ static void intel_init_display(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = dev->dev_private;
 
-       /* We always want a DPMS function */
        if (HAS_DDI(dev)) {
                dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
                dev_priv->display.crtc_enable = haswell_crtc_enable;
@@ -8828,7 +8887,7 @@ void intel_modeset_init_hw(struct drm_device *dev)
 void intel_modeset_init(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = dev->dev_private;
-       int i, ret;
+       int i, j, ret;
 
        drm_mode_config_init(dev);
 
@@ -8859,13 +8918,17 @@ void intel_modeset_init(struct drm_device *dev)
        dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
 
        DRM_DEBUG_KMS("%d display pipe%s available.\n",
-                     dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
+                     INTEL_INFO(dev)->num_pipes,
+                     INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
 
-       for (i = 0; i < dev_priv->num_pipe; i++) {
+       for (i = 0; i < INTEL_INFO(dev)->num_pipes; i++) {
                intel_crtc_init(dev, i);
-               ret = intel_plane_init(dev, i);
-               if (ret)
-                       DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret);
+               for (j = 0; j < dev_priv->num_plane; j++) {
+                       ret = intel_plane_init(dev, i, j);
+                       if (ret)
+                               DRM_DEBUG_KMS("pipe %d plane %d init failed: %d\n",
+                                             i, j, ret);
+               }
        }
 
        intel_cpu_pll_init(dev);
@@ -8918,10 +8981,11 @@ static void intel_enable_pipe_a(struct drm_device *dev)
 static bool
 intel_check_plane_mapping(struct intel_crtc *crtc)
 {
-       struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
+       struct drm_device *dev = crtc->base.dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
        u32 reg, val;
 
-       if (dev_priv->num_pipe == 1)
+       if (INTEL_INFO(dev)->num_pipes == 1)
                return true;
 
        reg = DSPCNTR(!crtc->plane);
@@ -9077,6 +9141,7 @@ void intel_modeset_setup_hw_state(struct drm_device *dev,
        struct drm_i915_private *dev_priv = dev->dev_private;
        enum pipe pipe;
        u32 tmp;
+       struct drm_plane *plane;
        struct intel_crtc *crtc;
        struct intel_encoder *encoder;
        struct intel_connector *connector;
@@ -9096,6 +9161,13 @@ void intel_modeset_setup_hw_state(struct drm_device *dev,
                        case TRANS_DDI_EDP_INPUT_C_ONOFF:
                                pipe = PIPE_C;
                                break;
+                       default:
+                               /* A bogus value has been programmed, disable
+                                * the transcoder */
+                               WARN(1, "Bogus eDP source %08x\n", tmp);
+                               intel_ddi_disable_transcoder_func(dev_priv,
+                                               TRANSCODER_EDP);
+                               goto setup_pipes;
                        }
 
                        crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
@@ -9106,6 +9178,7 @@ void intel_modeset_setup_hw_state(struct drm_device *dev,
                }
        }
 
+setup_pipes:
        for_each_pipe(pipe) {
                crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
 
@@ -9173,8 +9246,12 @@ void intel_modeset_setup_hw_state(struct drm_device *dev,
 
        if (force_restore) {
                for_each_pipe(pipe) {
-                       intel_crtc_restore_mode(dev_priv->pipe_to_crtc_mapping[pipe]);
+                       struct drm_crtc *crtc =
+                               dev_priv->pipe_to_crtc_mapping[pipe];
+                       intel_crtc_restore_mode(crtc);
                }
+               list_for_each_entry(plane, &dev->mode_config.plane_list, head)
+                       intel_plane_restore(plane);
 
                i915_redisable_vga(dev);
        } else {
@@ -9323,15 +9400,24 @@ intel_display_capture_error_state(struct drm_device *dev)
        for_each_pipe(i) {
                cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, i);
 
-               error->cursor[i].control = I915_READ(CURCNTR(i));
-               error->cursor[i].position = I915_READ(CURPOS(i));
-               error->cursor[i].base = I915_READ(CURBASE(i));
+               if (INTEL_INFO(dev)->gen <= 6 || IS_VALLEYVIEW(dev)) {
+                       error->cursor[i].control = I915_READ(CURCNTR(i));
+                       error->cursor[i].position = I915_READ(CURPOS(i));
+                       error->cursor[i].base = I915_READ(CURBASE(i));
+               } else {
+                       error->cursor[i].control = I915_READ(CURCNTR_IVB(i));
+                       error->cursor[i].position = I915_READ(CURPOS_IVB(i));
+                       error->cursor[i].base = I915_READ(CURBASE_IVB(i));
+               }
 
                error->plane[i].control = I915_READ(DSPCNTR(i));
                error->plane[i].stride = I915_READ(DSPSTRIDE(i));
-               error->plane[i].size = I915_READ(DSPSIZE(i));
-               error->plane[i].pos = I915_READ(DSPPOS(i));
-               error->plane[i].addr = I915_READ(DSPADDR(i));
+               if (INTEL_INFO(dev)->gen <= 3) {
+                       error->plane[i].size = I915_READ(DSPSIZE(i));
+                       error->plane[i].pos = I915_READ(DSPPOS(i));
+               }
+               if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
+                       error->plane[i].addr = I915_READ(DSPADDR(i));
                if (INTEL_INFO(dev)->gen >= 4) {
                        error->plane[i].surface = I915_READ(DSPSURF(i));
                        error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
@@ -9355,10 +9441,9 @@ intel_display_print_error_state(struct seq_file *m,
                                struct drm_device *dev,
                                struct intel_display_error_state *error)
 {
-       drm_i915_private_t *dev_priv = dev->dev_private;
        int i;
 
-       seq_printf(m, "Num Pipes: %d\n", dev_priv->num_pipe);
+       seq_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
        for_each_pipe(i) {
                seq_printf(m, "Pipe [%d]:\n", i);
                seq_printf(m, "  CONF: %08x\n", error->pipe[i].conf);
@@ -9373,9 +9458,12 @@ intel_display_print_error_state(struct seq_file *m,
                seq_printf(m, "Plane [%d]:\n", i);
                seq_printf(m, "  CNTR: %08x\n", error->plane[i].control);
                seq_printf(m, "  STRIDE: %08x\n", error->plane[i].stride);
-               seq_printf(m, "  SIZE: %08x\n", error->plane[i].size);
-               seq_printf(m, "  POS: %08x\n", error->plane[i].pos);
-               seq_printf(m, "  ADDR: %08x\n", error->plane[i].addr);
+               if (INTEL_INFO(dev)->gen <= 3) {
+                       seq_printf(m, "  SIZE: %08x\n", error->plane[i].size);
+                       seq_printf(m, "  POS: %08x\n", error->plane[i].pos);
+               }
+               if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
+                       seq_printf(m, "  ADDR: %08x\n", error->plane[i].addr);
                if (INTEL_INFO(dev)->gen >= 4) {
                        seq_printf(m, "  SURF: %08x\n", error->plane[i].surface);
                        seq_printf(m, "  TILEOFF: %08x\n", error->plane[i].tile_offset);