Merge drm/drm-next into drm-intel-next-queued
[linux-2.6-microblaze.git] / drivers / gpu / drm / i915 / display / intel_display.c
index a35ec8e..59c3758 100644 (file)
@@ -46,6 +46,7 @@
 #include "display/intel_crt.h"
 #include "display/intel_ddi.h"
 #include "display/intel_dp.h"
+#include "display/intel_dp_mst.h"
 #include "display/intel_dsi.h"
 #include "display/intel_dvo.h"
 #include "display/intel_gmbus.h"
@@ -145,8 +146,8 @@ static const u64 cursor_format_modifiers[] = {
 
 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
                                struct intel_crtc_state *pipe_config);
-static void ironlake_pch_clock_get(struct intel_crtc *crtc,
-                                  struct intel_crtc_state *pipe_config);
+static void ilk_pch_clock_get(struct intel_crtc *crtc,
+                             struct intel_crtc_state *pipe_config);
 
 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
                                  struct drm_i915_gem_object *obj,
@@ -157,20 +158,18 @@ static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_sta
                                         const struct intel_link_m_n *m_n,
                                         const struct intel_link_m_n *m2_n2);
 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
-static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state);
-static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state);
+static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state);
+static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state);
 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state);
 static void vlv_prepare_pll(struct intel_crtc *crtc,
                            const struct intel_crtc_state *pipe_config);
 static void chv_prepare_pll(struct intel_crtc *crtc,
                            const struct intel_crtc_state *pipe_config);
-static void intel_crtc_init_scalers(struct intel_crtc *crtc,
-                                   struct intel_crtc_state *crtc_state);
-static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state);
-static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state);
-static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state);
+static void skl_pfit_enable(const struct intel_crtc_state *crtc_state);
+static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state);
 static void intel_modeset_setup_hw_state(struct drm_device *dev,
                                         struct drm_modeset_acquire_ctx *ctx);
+static struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc);
 
 struct intel_limit {
        struct {
@@ -371,7 +370,7 @@ static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
        },
 };
 
-static const struct intel_limit intel_limits_pineview_sdvo = {
+static const struct intel_limit pnv_limits_sdvo = {
        .dot = { .min = 20000, .max = 400000},
        .vco = { .min = 1700000, .max = 3500000 },
        /* Pineview's Ncounter is a ring counter */
@@ -386,7 +385,7 @@ static const struct intel_limit intel_limits_pineview_sdvo = {
                .p2_slow = 10, .p2_fast = 5 },
 };
 
-static const struct intel_limit intel_limits_pineview_lvds = {
+static const struct intel_limit pnv_limits_lvds = {
        .dot = { .min = 20000, .max = 400000 },
        .vco = { .min = 1700000, .max = 3500000 },
        .n = { .min = 3, .max = 6 },
@@ -404,7 +403,7 @@ static const struct intel_limit intel_limits_pineview_lvds = {
  * We calculate clock using (register_value + 2) for N/M1/M2, so here
  * the range value for them is (actual_value - 2).
  */
-static const struct intel_limit intel_limits_ironlake_dac = {
+static const struct intel_limit ilk_limits_dac = {
        .dot = { .min = 25000, .max = 350000 },
        .vco = { .min = 1760000, .max = 3510000 },
        .n = { .min = 1, .max = 5 },
@@ -417,7 +416,7 @@ static const struct intel_limit intel_limits_ironlake_dac = {
                .p2_slow = 10, .p2_fast = 5 },
 };
 
-static const struct intel_limit intel_limits_ironlake_single_lvds = {
+static const struct intel_limit ilk_limits_single_lvds = {
        .dot = { .min = 25000, .max = 350000 },
        .vco = { .min = 1760000, .max = 3510000 },
        .n = { .min = 1, .max = 3 },
@@ -430,7 +429,7 @@ static const struct intel_limit intel_limits_ironlake_single_lvds = {
                .p2_slow = 14, .p2_fast = 14 },
 };
 
-static const struct intel_limit intel_limits_ironlake_dual_lvds = {
+static const struct intel_limit ilk_limits_dual_lvds = {
        .dot = { .min = 25000, .max = 350000 },
        .vco = { .min = 1760000, .max = 3510000 },
        .n = { .min = 1, .max = 3 },
@@ -444,7 +443,7 @@ static const struct intel_limit intel_limits_ironlake_dual_lvds = {
 };
 
 /* LVDS 100mhz refclk limits. */
-static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
+static const struct intel_limit ilk_limits_single_lvds_100m = {
        .dot = { .min = 25000, .max = 350000 },
        .vco = { .min = 1760000, .max = 3510000 },
        .n = { .min = 1, .max = 2 },
@@ -457,7 +456,7 @@ static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
                .p2_slow = 14, .p2_fast = 14 },
 };
 
-static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
+static const struct intel_limit ilk_limits_dual_lvds_100m = {
        .dot = { .min = 25000, .max = 350000 },
        .vco = { .min = 1760000, .max = 3510000 },
        .n = { .min = 1, .max = 3 },
@@ -554,13 +553,6 @@ is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
                crtc_state->sync_mode_slaves_mask);
 }
 
-static bool
-is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
-{
-       return (crtc_state->master_transcoder == INVALID_TRANSCODER &&
-               crtc_state->sync_mode_slaves_mask);
-}
-
 static bool
 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
 {
@@ -1045,33 +1037,6 @@ bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state,
                                  NULL, best_clock);
 }
 
-bool intel_crtc_active(struct intel_crtc *crtc)
-{
-       /* Be paranoid as we can arrive here with only partial
-        * state retrieved from the hardware during setup.
-        *
-        * We can ditch the adjusted_mode.crtc_clock check as soon
-        * as Haswell has gained clock readout/fastboot support.
-        *
-        * We can ditch the crtc->primary->state->fb check as soon as we can
-        * properly reconstruct framebuffers.
-        *
-        * FIXME: The intel_crtc->active here should be switched to
-        * crtc->state->active once we have proper CRTC states wired up
-        * for atomic.
-        */
-       return crtc->active && crtc->base.primary->state->fb &&
-               crtc->config->hw.adjusted_mode.crtc_clock;
-}
-
-enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
-                                            enum pipe pipe)
-{
-       struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
-
-       return crtc->config->cpu_transcoder;
-}
-
 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
                                    enum pipe pipe)
 {
@@ -1165,11 +1130,15 @@ static void assert_fdi_tx(struct drm_i915_private *dev_priv,
                          enum pipe pipe, bool state)
 {
        bool cur_state;
-       enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
-                                                                     pipe);
 
        if (HAS_DDI(dev_priv)) {
-               /* DDI does not have a specific FDI_TX register */
+               /*
+                * DDI does not have a specific FDI_TX register.
+                *
+                * FDI is never fed from EDP transcoder
+                * so pipe->transcoder cast is fine here.
+                */
+               enum transcoder cpu_transcoder = (enum transcoder)pipe;
                u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
                cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
        } else {
@@ -1286,11 +1255,9 @@ void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
 }
 
 void assert_pipe(struct drm_i915_private *dev_priv,
-                enum pipe pipe, bool state)
+                enum transcoder cpu_transcoder, bool state)
 {
        bool cur_state;
-       enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
-                                                                     pipe);
        enum intel_display_power_domain power_domain;
        intel_wakeref_t wakeref;
 
@@ -1310,8 +1277,9 @@ void assert_pipe(struct drm_i915_private *dev_priv,
        }
 
        I915_STATE_WARN(cur_state != state,
-            "pipe %c assertion failure (expected %s, current %s)\n",
-                       pipe_name(pipe), onoff(state), onoff(cur_state));
+                       "transcoder %s assertion failure (expected %s, current %s)\n",
+                       transcoder_name(cpu_transcoder),
+                       onoff(state), onoff(cur_state));
 }
 
 static void assert_plane(struct intel_plane *plane, bool state)
@@ -1438,7 +1406,7 @@ static void vlv_enable_pll(struct intel_crtc *crtc,
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
        enum pipe pipe = crtc->pipe;
 
-       assert_pipe_disabled(dev_priv, pipe);
+       assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
 
        /* PLL is protected by panel, make sure we can write it */
        assert_panel_unlocked(dev_priv, pipe);
@@ -1487,7 +1455,7 @@ static void chv_enable_pll(struct intel_crtc *crtc,
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
        enum pipe pipe = crtc->pipe;
 
-       assert_pipe_disabled(dev_priv, pipe);
+       assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
 
        /* PLL is protected by panel, make sure we can write it */
        assert_panel_unlocked(dev_priv, pipe);
@@ -1534,7 +1502,7 @@ static void i9xx_enable_pll(struct intel_crtc *crtc,
        u32 dpll = crtc_state->dpll_hw_state.dpll;
        int i;
 
-       assert_pipe_disabled(dev_priv, crtc->pipe);
+       assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
 
        /* PLL is protected by panel, make sure we can write it */
        if (i9xx_has_pps(dev_priv))
@@ -1583,7 +1551,7 @@ static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
                return;
 
        /* Make sure the pipe isn't still relying on us */
-       assert_pipe_disabled(dev_priv, pipe);
+       assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
 
        I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
        POSTING_READ(DPLL(pipe));
@@ -1594,7 +1562,7 @@ static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
        u32 val;
 
        /* Make sure the pipe isn't still relying on us */
-       assert_pipe_disabled(dev_priv, pipe);
+       assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
 
        val = DPLL_INTEGRATED_REF_CLK_VLV |
                DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
@@ -1611,7 +1579,7 @@ static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
        u32 val;
 
        /* Make sure the pipe isn't still relying on us */
-       assert_pipe_disabled(dev_priv, pipe);
+       assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
 
        val = DPLL_SSC_REF_CLK_CHV |
                DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
@@ -1663,7 +1631,7 @@ void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
                     I915_READ(dpll_reg) & port_mask, expected_mask);
 }
 
-static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
+static void ilk_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
 {
        struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
@@ -1761,8 +1729,8 @@ static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
                DRM_ERROR("Failed to enable PCH transcoder\n");
 }
 
-static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
-                                           enum pipe pipe)
+static void ilk_disable_pch_transcoder(struct drm_i915_private *dev_priv,
+                                      enum pipe pipe)
 {
        i915_reg_t reg;
        u32 val;
@@ -1849,8 +1817,10 @@ static void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state)
        drm_crtc_vblank_on(&crtc->base);
 }
 
-static void intel_crtc_vblank_off(struct intel_crtc *crtc)
+void intel_crtc_vblank_off(const struct intel_crtc_state *crtc_state)
 {
+       struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
+
        drm_crtc_vblank_off(&crtc->base);
        assert_vblank_disabled(&crtc->base);
 }
@@ -1913,7 +1883,7 @@ static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
                intel_wait_for_pipe_scanline_moving(crtc);
 }
 
-static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
+void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
 {
        struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
@@ -1958,6 +1928,74 @@ static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
        return IS_GEN(dev_priv, 2) ? 2048 : 4096;
 }
 
+static bool is_ccs_plane(const struct drm_framebuffer *fb, int plane)
+{
+       if (!is_ccs_modifier(fb->modifier))
+               return false;
+
+       return plane >= fb->format->num_planes / 2;
+}
+
+static bool is_gen12_ccs_modifier(u64 modifier)
+{
+       return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
+              modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
+
+}
+
+static bool is_gen12_ccs_plane(const struct drm_framebuffer *fb, int plane)
+{
+       return is_gen12_ccs_modifier(fb->modifier) && is_ccs_plane(fb, plane);
+}
+
+static bool is_aux_plane(const struct drm_framebuffer *fb, int plane)
+{
+       if (is_ccs_modifier(fb->modifier))
+               return is_ccs_plane(fb, plane);
+
+       return plane == 1;
+}
+
+static int main_to_ccs_plane(const struct drm_framebuffer *fb, int main_plane)
+{
+       WARN_ON(!is_ccs_modifier(fb->modifier) ||
+               (main_plane && main_plane >= fb->format->num_planes / 2));
+
+       return fb->format->num_planes / 2 + main_plane;
+}
+
+static int ccs_to_main_plane(const struct drm_framebuffer *fb, int ccs_plane)
+{
+       WARN_ON(!is_ccs_modifier(fb->modifier) ||
+               ccs_plane < fb->format->num_planes / 2);
+
+       return ccs_plane - fb->format->num_planes / 2;
+}
+
+/* Return either the main plane's CCS or - if not a CCS FB - UV plane */
+int intel_main_to_aux_plane(const struct drm_framebuffer *fb, int main_plane)
+{
+       if (is_ccs_modifier(fb->modifier))
+               return main_to_ccs_plane(fb, main_plane);
+
+       return 1;
+}
+
+bool
+intel_format_info_is_yuv_semiplanar(const struct drm_format_info *info,
+                                   uint64_t modifier)
+{
+       return info->is_yuv &&
+              info->num_planes == (is_ccs_modifier(modifier) ? 4 : 2);
+}
+
+static bool is_semiplanar_uv_plane(const struct drm_framebuffer *fb,
+                                  int color_plane)
+{
+       return intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) &&
+              color_plane == 1;
+}
+
 static unsigned int
 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
 {
@@ -1973,16 +2011,21 @@ intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
                else
                        return 512;
        case I915_FORMAT_MOD_Y_TILED_CCS:
-               if (color_plane == 1)
+               if (is_ccs_plane(fb, color_plane))
                        return 128;
                /* fall through */
+       case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
+       case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
+               if (is_ccs_plane(fb, color_plane))
+                       return 64;
+               /* fall through */
        case I915_FORMAT_MOD_Y_TILED:
                if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
                        return 128;
                else
                        return 512;
        case I915_FORMAT_MOD_Yf_TILED_CCS:
-               if (color_plane == 1)
+               if (is_ccs_plane(fb, color_plane))
                        return 128;
                /* fall through */
        case I915_FORMAT_MOD_Yf_TILED:
@@ -2009,6 +2052,9 @@ intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
 static unsigned int
 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
 {
+       if (is_gen12_ccs_plane(fb, color_plane))
+               return 1;
+
        return intel_tile_size(to_i915(fb->dev)) /
                intel_tile_width_bytes(fb, color_plane);
 }
@@ -2022,7 +2068,17 @@ static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
        unsigned int cpp = fb->format->cpp[color_plane];
 
        *tile_width = tile_width_bytes / cpp;
-       *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
+       *tile_height = intel_tile_height(fb, color_plane);
+}
+
+static unsigned int intel_tile_row_size(const struct drm_framebuffer *fb,
+                                       int color_plane)
+{
+       unsigned int tile_width, tile_height;
+
+       intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
+
+       return fb->pitches[color_plane] * tile_height;
 }
 
 unsigned int
@@ -2099,7 +2155,8 @@ static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
        struct drm_i915_private *dev_priv = to_i915(fb->dev);
 
        /* AUX_DIST needs only 4K alignment */
-       if (color_plane == 1)
+       if ((INTEL_GEN(dev_priv) < 12 && is_aux_plane(fb, color_plane)) ||
+           is_ccs_plane(fb, color_plane))
                return 4096;
 
        switch (fb->modifier) {
@@ -2109,9 +2166,19 @@ static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
                if (INTEL_GEN(dev_priv) >= 9)
                        return 256 * 1024;
                return 0;
+       case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
+               if (is_semiplanar_uv_plane(fb, color_plane))
+                       return intel_tile_row_size(fb, color_plane);
+               /* Fall-through */
+       case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
+               return 16 * 1024;
        case I915_FORMAT_MOD_Y_TILED_CCS:
        case I915_FORMAT_MOD_Yf_TILED_CCS:
        case I915_FORMAT_MOD_Y_TILED:
+               if (INTEL_GEN(dev_priv) >= 12 &&
+                   is_semiplanar_uv_plane(fb, color_plane))
+                       return intel_tile_row_size(fb, color_plane);
+               /* Fall-through */
        case I915_FORMAT_MOD_Yf_TILED:
                return 1 * 1024 * 1024;
        default:
@@ -2148,6 +2215,8 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
                return ERR_PTR(-EINVAL);
 
        alignment = intel_surf_alignment(fb, 0);
+       if (WARN_ON(alignment && !is_power_of_2(alignment)))
+               return ERR_PTR(-EINVAL);
 
        /* 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
@@ -2165,19 +2234,18 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
         * pin/unpin/fence and not more.
         */
        wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
-       i915_gem_object_lock(obj);
 
        atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
 
-       pinctl = 0;
-
-       /* Valleyview is definitely limited to scanning out the first
+       /*
+        * Valleyview is definitely limited to scanning out the first
         * 512MiB. Lets presume this behaviour was inherited from the
         * g4x display engine and that all earlier gen are similarly
         * limited. Testing suggests that it is a little more
         * complicated than this. For example, Cherryview appears quite
         * happy to scanout from anywhere within its global aperture.
         */
+       pinctl = 0;
        if (HAS_GMCH(dev_priv))
                pinctl |= PIN_MAPPABLE;
 
@@ -2189,7 +2257,8 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
        if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
                int ret;
 
-               /* Install a fence for tiled scan-out. Pre-i965 always needs a
+               /*
+                * Install a fence for tiled scan-out. Pre-i965 always needs a
                 * fence, whereas 965+ only requires a fence if using
                 * framebuffer compression.  For simplicity, we always, when
                 * possible, install a fence as the cost is not that onerous.
@@ -2219,8 +2288,6 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
        i915_vma_get(vma);
 err:
        atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
-
-       i915_gem_object_unlock(obj);
        intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
        return vma;
 }
@@ -2303,9 +2370,10 @@ static u32 intel_adjust_tile_offset(int *x, int *y,
        return new_offset;
 }
 
-static bool is_surface_linear(u64 modifier, int color_plane)
+static bool is_surface_linear(const struct drm_framebuffer *fb, int color_plane)
 {
-       return modifier == DRM_FORMAT_MOD_LINEAR;
+       return fb->modifier == DRM_FORMAT_MOD_LINEAR ||
+              is_gen12_ccs_plane(fb, color_plane);
 }
 
 static u32 intel_adjust_aligned_offset(int *x, int *y,
@@ -2320,7 +2388,7 @@ static u32 intel_adjust_aligned_offset(int *x, int *y,
 
        WARN_ON(new_offset > old_offset);
 
-       if (!is_surface_linear(fb->modifier, color_plane)) {
+       if (!is_surface_linear(fb, color_plane)) {
                unsigned int tile_size, tile_width, tile_height;
                unsigned int pitch_tiles;
 
@@ -2387,10 +2455,7 @@ static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
        unsigned int cpp = fb->format->cpp[color_plane];
        u32 offset, offset_aligned;
 
-       if (alignment)
-               alignment--;
-
-       if (!is_surface_linear(fb->modifier, color_plane)) {
+       if (!is_surface_linear(fb, color_plane)) {
                unsigned int tile_size, tile_width, tile_height;
                unsigned int tile_rows, tiles, pitch_tiles;
 
@@ -2411,17 +2476,24 @@ static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
                *x %= tile_width;
 
                offset = (tile_rows * pitch_tiles + tiles) * tile_size;
-               offset_aligned = offset & ~alignment;
+
+               offset_aligned = offset;
+               if (alignment)
+                       offset_aligned = rounddown(offset_aligned, alignment);
 
                intel_adjust_tile_offset(x, y, tile_width, tile_height,
                                         tile_size, pitch_tiles,
                                         offset, offset_aligned);
        } else {
                offset = *y * pitch + *x * cpp;
-               offset_aligned = offset & ~alignment;
-
-               *y = (offset & alignment) / pitch;
-               *x = ((offset & alignment) - *y * pitch) / cpp;
+               offset_aligned = offset;
+               if (alignment) {
+                       offset_aligned = rounddown(offset_aligned, alignment);
+                       *y = (offset % alignment) / pitch;
+                       *x = ((offset % alignment) - *y * pitch) / cpp;
+               } else {
+                       *y = *x = 0;
+               }
        }
 
        return offset_aligned;
@@ -2454,9 +2526,17 @@ static int intel_fb_offset_to_xy(int *x, int *y,
 {
        struct drm_i915_private *dev_priv = to_i915(fb->dev);
        unsigned int height;
+       u32 alignment;
+
+       if (INTEL_GEN(dev_priv) >= 12 &&
+           is_semiplanar_uv_plane(fb, color_plane))
+               alignment = intel_tile_row_size(fb, color_plane);
+       else if (fb->modifier != DRM_FORMAT_MOD_LINEAR)
+               alignment = intel_tile_size(dev_priv);
+       else
+               alignment = 0;
 
-       if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
-           fb->offsets[color_plane] % intel_tile_size(dev_priv)) {
+       if (alignment != 0 && fb->offsets[color_plane] % alignment) {
                DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
                              fb->offsets[color_plane], color_plane);
                return -EINVAL;
@@ -2492,6 +2572,8 @@ static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
                return I915_TILING_X;
        case I915_FORMAT_MOD_Y_TILED:
        case I915_FORMAT_MOD_Y_TILED_CCS:
+       case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
+       case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
                return I915_TILING_Y;
        default:
                return I915_TILING_NONE;
@@ -2512,7 +2594,7 @@ static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
  * us a ratio of one byte in the CCS for each 8x16 pixels in the
  * main surface.
  */
-static const struct drm_format_info ccs_formats[] = {
+static const struct drm_format_info skl_ccs_formats[] = {
        { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
          .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
        { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
@@ -2523,6 +2605,52 @@ static const struct drm_format_info ccs_formats[] = {
          .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
 };
 
+/*
+ * Gen-12 compression uses 4 bits of CCS data for each cache line pair in the
+ * main surface. And each 64B CCS cache line represents an area of 4x1 Y-tiles
+ * in the main surface. With 4 byte pixels and each Y-tile having dimensions of
+ * 32x32 pixels, the ratio turns out to 1B in the CCS for every 2x32 pixels in
+ * the main surface.
+ */
+static const struct drm_format_info gen12_ccs_formats[] = {
+       { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
+         .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
+         .hsub = 1, .vsub = 1, },
+       { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
+         .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
+         .hsub = 1, .vsub = 1, },
+       { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
+         .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
+         .hsub = 1, .vsub = 1, .has_alpha = true },
+       { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
+         .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
+         .hsub = 1, .vsub = 1, .has_alpha = true },
+       { .format = DRM_FORMAT_YUYV, .num_planes = 2,
+         .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
+         .hsub = 2, .vsub = 1, .is_yuv = true },
+       { .format = DRM_FORMAT_YVYU, .num_planes = 2,
+         .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
+         .hsub = 2, .vsub = 1, .is_yuv = true },
+       { .format = DRM_FORMAT_UYVY, .num_planes = 2,
+         .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
+         .hsub = 2, .vsub = 1, .is_yuv = true },
+       { .format = DRM_FORMAT_VYUY, .num_planes = 2,
+         .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
+         .hsub = 2, .vsub = 1, .is_yuv = true },
+       { .format = DRM_FORMAT_NV12, .num_planes = 4,
+         .char_per_block = { 1, 2, 1, 1 }, .block_w = { 1, 1, 4, 4 }, .block_h = { 1, 1, 1, 1 },
+         .hsub = 2, .vsub = 2, .is_yuv = true },
+       { .format = DRM_FORMAT_P010, .num_planes = 4,
+         .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
+         .hsub = 2, .vsub = 2, .is_yuv = true },
+       { .format = DRM_FORMAT_P012, .num_planes = 4,
+         .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
+         .hsub = 2, .vsub = 2, .is_yuv = true },
+       { .format = DRM_FORMAT_P016, .num_planes = 4,
+         .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
+         .hsub = 2, .vsub = 2, .is_yuv = true },
+};
+
 static const struct drm_format_info *
 lookup_format_info(const struct drm_format_info formats[],
                   int num_formats, u32 format)
@@ -2543,8 +2671,13 @@ intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
        switch (cmd->modifier[0]) {
        case I915_FORMAT_MOD_Y_TILED_CCS:
        case I915_FORMAT_MOD_Yf_TILED_CCS:
-               return lookup_format_info(ccs_formats,
-                                         ARRAY_SIZE(ccs_formats),
+               return lookup_format_info(skl_ccs_formats,
+                                         ARRAY_SIZE(skl_ccs_formats),
+                                         cmd->pixel_format);
+       case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
+       case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
+               return lookup_format_info(gen12_ccs_formats,
+                                         ARRAY_SIZE(gen12_ccs_formats),
                                          cmd->pixel_format);
        default:
                return NULL;
@@ -2553,10 +2686,18 @@ intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
 
 bool is_ccs_modifier(u64 modifier)
 {
-       return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
+       return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
+              modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS ||
+              modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
               modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
 }
 
+static int gen12_ccs_aux_stride(struct drm_framebuffer *fb, int ccs_plane)
+{
+       return DIV_ROUND_UP(fb->pitches[ccs_to_main_plane(fb, ccs_plane)],
+                           512) * 64;
+}
+
 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
                              u32 pixel_format, u64 modifier)
 {
@@ -2601,8 +2742,9 @@ static u32
 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
 {
        struct drm_i915_private *dev_priv = to_i915(fb->dev);
+       u32 tile_width;
 
-       if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
+       if (is_surface_linear(fb, color_plane)) {
                u32 max_stride = intel_plane_fb_max_stride(dev_priv,
                                                           fb->format->format,
                                                           fb->modifier);
@@ -2611,13 +2753,34 @@ intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
                 * To make remapping with linear generally feasible
                 * we need the stride to be page aligned.
                 */
-               if (fb->pitches[color_plane] > max_stride)
+               if (fb->pitches[color_plane] > max_stride &&
+                   !is_ccs_modifier(fb->modifier))
                        return intel_tile_size(dev_priv);
                else
                        return 64;
-       } else {
-               return intel_tile_width_bytes(fb, color_plane);
        }
+
+       tile_width = intel_tile_width_bytes(fb, color_plane);
+       if (is_ccs_modifier(fb->modifier)) {
+               /*
+                * Display WA #0531: skl,bxt,kbl,glk
+                *
+                * Render decompression and plane width > 3840
+                * combined with horizontal panning requires the
+                * plane stride to be a multiple of 4. We'll just
+                * require the entire fb to accommodate that to avoid
+                * potential runtime errors at plane configuration time.
+                */
+               if (IS_GEN(dev_priv, 9) && color_plane == 0 && fb->width > 3840)
+                       tile_width *= 4;
+               /*
+                * The main surface pitch must be padded to a multiple of four
+                * tile widths.
+                */
+               else if (INTEL_GEN(dev_priv) >= 12)
+                       tile_width *= 4;
+       }
+       return tile_width;
 }
 
 bool intel_plane_can_remap(const struct intel_plane_state *plane_state)
@@ -2688,12 +2851,171 @@ static bool intel_plane_needs_remap(const struct intel_plane_state *plane_state)
        return stride > max_stride;
 }
 
+static void
+intel_fb_plane_get_subsampling(int *hsub, int *vsub,
+                              const struct drm_framebuffer *fb,
+                              int color_plane)
+{
+       int main_plane;
+
+       if (color_plane == 0) {
+               *hsub = 1;
+               *vsub = 1;
+
+               return;
+       }
+
+       /*
+        * TODO: Deduct the subsampling from the char block for all CCS
+        * formats and planes.
+        */
+       if (!is_gen12_ccs_plane(fb, color_plane)) {
+               *hsub = fb->format->hsub;
+               *vsub = fb->format->vsub;
+
+               return;
+       }
+
+       main_plane = ccs_to_main_plane(fb, color_plane);
+       *hsub = drm_format_info_block_width(fb->format, color_plane) /
+               drm_format_info_block_width(fb->format, main_plane);
+
+       /*
+        * The min stride check in the core framebuffer_check() function
+        * assumes that format->hsub applies to every plane except for the
+        * first plane. That's incorrect for the CCS AUX plane of the first
+        * plane, but for the above check to pass we must define the block
+        * width with that subsampling applied to it. Adjust the width here
+        * accordingly, so we can calculate the actual subsampling factor.
+        */
+       if (main_plane == 0)
+               *hsub *= fb->format->hsub;
+
+       *vsub = 32;
+}
+static int
+intel_fb_check_ccs_xy(struct drm_framebuffer *fb, int ccs_plane, int x, int y)
+{
+       struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
+       int main_plane;
+       int hsub, vsub;
+       int tile_width, tile_height;
+       int ccs_x, ccs_y;
+       int main_x, main_y;
+
+       if (!is_ccs_plane(fb, ccs_plane))
+               return 0;
+
+       intel_tile_dims(fb, ccs_plane, &tile_width, &tile_height);
+       intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
+
+       tile_width *= hsub;
+       tile_height *= vsub;
+
+       ccs_x = (x * hsub) % tile_width;
+       ccs_y = (y * vsub) % tile_height;
+
+       main_plane = ccs_to_main_plane(fb, ccs_plane);
+       main_x = intel_fb->normal[main_plane].x % tile_width;
+       main_y = intel_fb->normal[main_plane].y % tile_height;
+
+       /*
+        * CCS doesn't have its own x/y offset register, so the intra CCS tile
+        * x/y offsets must match between CCS and the main surface.
+        */
+       if (main_x != ccs_x || main_y != ccs_y) {
+               DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
+                             main_x, main_y,
+                             ccs_x, ccs_y,
+                             intel_fb->normal[main_plane].x,
+                             intel_fb->normal[main_plane].y,
+                             x, y);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static void
+intel_fb_plane_dims(int *w, int *h, struct drm_framebuffer *fb, int color_plane)
+{
+       int main_plane = is_ccs_plane(fb, color_plane) ?
+                        ccs_to_main_plane(fb, color_plane) : 0;
+       int main_hsub, main_vsub;
+       int hsub, vsub;
+
+       intel_fb_plane_get_subsampling(&main_hsub, &main_vsub, fb, main_plane);
+       intel_fb_plane_get_subsampling(&hsub, &vsub, fb, color_plane);
+       *w = fb->width / main_hsub / hsub;
+       *h = fb->height / main_vsub / vsub;
+}
+
+/*
+ * Setup the rotated view for an FB plane and return the size the GTT mapping
+ * requires for this view.
+ */
+static u32
+setup_fb_rotation(int plane, const struct intel_remapped_plane_info *plane_info,
+                 u32 gtt_offset_rotated, int x, int y,
+                 unsigned int width, unsigned int height,
+                 unsigned int tile_size,
+                 unsigned int tile_width, unsigned int tile_height,
+                 struct drm_framebuffer *fb)
+{
+       struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
+       struct intel_rotation_info *rot_info = &intel_fb->rot_info;
+       unsigned int pitch_tiles;
+       struct drm_rect r;
+
+       /* Y or Yf modifiers required for 90/270 rotation */
+       if (fb->modifier != I915_FORMAT_MOD_Y_TILED &&
+           fb->modifier != I915_FORMAT_MOD_Yf_TILED)
+               return 0;
+
+       if (WARN_ON(plane >= ARRAY_SIZE(rot_info->plane)))
+               return 0;
+
+       rot_info->plane[plane] = *plane_info;
+
+       intel_fb->rotated[plane].pitch = plane_info->height * tile_height;
+
+       /* rotate the x/y offsets to match the GTT view */
+       drm_rect_init(&r, x, y, width, height);
+       drm_rect_rotate(&r,
+                       plane_info->width * tile_width,
+                       plane_info->height * tile_height,
+                       DRM_MODE_ROTATE_270);
+       x = r.x1;
+       y = r.y1;
+
+       /* rotate the tile dimensions to match the GTT view */
+       pitch_tiles = intel_fb->rotated[plane].pitch / tile_height;
+       swap(tile_width, tile_height);
+
+       /*
+        * We only keep the x/y offsets, so push all of the
+        * gtt offset into the x/y offsets.
+        */
+       intel_adjust_tile_offset(&x, &y,
+                                tile_width, tile_height,
+                                tile_size, pitch_tiles,
+                                gtt_offset_rotated * tile_size, 0);
+
+       /*
+        * First pixel of the framebuffer from
+        * the start of the rotated gtt mapping.
+        */
+       intel_fb->rotated[plane].x = x;
+       intel_fb->rotated[plane].y = y;
+
+       return plane_info->width * plane_info->height;
+}
+
 static int
 intel_fill_fb_info(struct drm_i915_private *dev_priv,
                   struct drm_framebuffer *fb)
 {
        struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
-       struct intel_rotation_info *rot_info = &intel_fb->rot_info;
        struct drm_i915_gem_object *obj = intel_fb_obj(fb);
        u32 gtt_offset_rotated = 0;
        unsigned int max_size = 0;
@@ -2708,8 +3030,7 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
                int ret;
 
                cpp = fb->format->cpp[i];
-               width = drm_framebuffer_plane_width(fb->width, fb, i);
-               height = drm_framebuffer_plane_height(fb->height, fb, i);
+               intel_fb_plane_dims(&width, &height, fb, i);
 
                ret = intel_fb_offset_to_xy(&x, &y, fb, i);
                if (ret) {
@@ -2718,36 +3039,9 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
                        return ret;
                }
 
-               if (is_ccs_modifier(fb->modifier) && i == 1) {
-                       int hsub = fb->format->hsub;
-                       int vsub = fb->format->vsub;
-                       int tile_width, tile_height;
-                       int main_x, main_y;
-                       int ccs_x, ccs_y;
-
-                       intel_tile_dims(fb, i, &tile_width, &tile_height);
-                       tile_width *= hsub;
-                       tile_height *= vsub;
-
-                       ccs_x = (x * hsub) % tile_width;
-                       ccs_y = (y * vsub) % tile_height;
-                       main_x = intel_fb->normal[0].x % tile_width;
-                       main_y = intel_fb->normal[0].y % tile_height;
-
-                       /*
-                        * CCS doesn't have its own x/y offset register, so the intra CCS tile
-                        * x/y offsets must match between CCS and the main surface.
-                        */
-                       if (main_x != ccs_x || main_y != ccs_y) {
-                               DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
-                                             main_x, main_y,
-                                             ccs_x, ccs_y,
-                                             intel_fb->normal[0].x,
-                                             intel_fb->normal[0].y,
-                                             x, y);
-                               return -EINVAL;
-                       }
-               }
+               ret = intel_fb_check_ccs_xy(fb, i, x, y);
+               if (ret)
+                       return ret;
 
                /*
                 * The fence (if used) is aligned to the start of the object
@@ -2778,23 +3072,21 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
                                                      tile_size);
                offset /= tile_size;
 
-               if (!is_surface_linear(fb->modifier, i)) {
+               if (!is_surface_linear(fb, i)) {
+                       struct intel_remapped_plane_info plane_info;
                        unsigned int tile_width, tile_height;
-                       unsigned int pitch_tiles;
-                       struct drm_rect r;
 
                        intel_tile_dims(fb, i, &tile_width, &tile_height);
 
-                       rot_info->plane[i].offset = offset;
-                       rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
-                       rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
-                       rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
-
-                       intel_fb->rotated[i].pitch =
-                               rot_info->plane[i].height * tile_height;
+                       plane_info.offset = offset;
+                       plane_info.stride = DIV_ROUND_UP(fb->pitches[i],
+                                                        tile_width * cpp);
+                       plane_info.width = DIV_ROUND_UP(x + width, tile_width);
+                       plane_info.height = DIV_ROUND_UP(y + height,
+                                                        tile_height);
 
                        /* how many tiles does this plane need */
-                       size = rot_info->plane[i].stride * rot_info->plane[i].height;
+                       size = plane_info.stride * plane_info.height;
                        /*
                         * If the plane isn't horizontally tile aligned,
                         * we need one more tile.
@@ -2802,36 +3094,13 @@ intel_fill_fb_info(struct drm_i915_private *dev_priv,
                        if (x != 0)
                                size++;
 
-                       /* rotate the x/y offsets to match the GTT view */
-                       drm_rect_init(&r, x, y, width, height);
-                       drm_rect_rotate(&r,
-                                       rot_info->plane[i].width * tile_width,
-                                       rot_info->plane[i].height * tile_height,
-                                       DRM_MODE_ROTATE_270);
-                       x = r.x1;
-                       y = r.y1;
-
-                       /* rotate the tile dimensions to match the GTT view */
-                       pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
-                       swap(tile_width, tile_height);
-
-                       /*
-                        * We only keep the x/y offsets, so push all of the
-                        * gtt offset into the x/y offsets.
-                        */
-                       intel_adjust_tile_offset(&x, &y,
-                                                tile_width, tile_height,
-                                                tile_size, pitch_tiles,
-                                                gtt_offset_rotated * tile_size, 0);
-
-                       gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
-
-                       /*
-                        * First pixel of the framebuffer from
-                        * the start of the rotated gtt mapping.
-                        */
-                       intel_fb->rotated[i].x = x;
-                       intel_fb->rotated[i].y = y;
+                       gtt_offset_rotated +=
+                               setup_fb_rotation(i, &plane_info,
+                                                 gtt_offset_rotated,
+                                                 x, y, width, height,
+                                                 tile_size,
+                                                 tile_width, tile_height,
+                                                 fb);
                } else {
                        size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
                                            x * cpp, tile_size);
@@ -2915,6 +3184,7 @@ intel_plane_remap_gtt(struct intel_plane_state *plane_state)
                                                      DRM_MODE_ROTATE_0, tile_size);
                offset /= tile_size;
 
+               WARN_ON(i >= ARRAY_SIZE(info->plane));
                info->plane[i].offset = offset;
                info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i],
                                                     tile_width * cpp);
@@ -3395,6 +3665,7 @@ static int skl_max_plane_width(const struct drm_framebuffer *fb,
                        return 5120;
        case I915_FORMAT_MOD_Y_TILED_CCS:
        case I915_FORMAT_MOD_Yf_TILED_CCS:
+       case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
                /* FIXME AUX plane? */
        case I915_FORMAT_MOD_Y_TILED:
        case I915_FORMAT_MOD_Yf_TILED:
@@ -3453,17 +3724,20 @@ static int icl_max_plane_height(void)
        return 4320;
 }
 
-static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
-                                          int main_x, int main_y, u32 main_offset)
+static bool
+skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
+                              int main_x, int main_y, u32 main_offset,
+                              int ccs_plane)
 {
        const struct drm_framebuffer *fb = plane_state->hw.fb;
-       int hsub = fb->format->hsub;
-       int vsub = fb->format->vsub;
-       int aux_x = plane_state->color_plane[1].x;
-       int aux_y = plane_state->color_plane[1].y;
-       u32 aux_offset = plane_state->color_plane[1].offset;
-       u32 alignment = intel_surf_alignment(fb, 1);
-
+       int aux_x = plane_state->color_plane[ccs_plane].x;
+       int aux_y = plane_state->color_plane[ccs_plane].y;
+       u32 aux_offset = plane_state->color_plane[ccs_plane].offset;
+       u32 alignment = intel_surf_alignment(fb, ccs_plane);
+       int hsub;
+       int vsub;
+
+       intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
        while (aux_offset >= main_offset && aux_y <= main_y) {
                int x, y;
 
@@ -3475,8 +3749,12 @@ static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state
 
                x = aux_x / hsub;
                y = aux_y / vsub;
-               aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
-                                                              aux_offset, aux_offset - alignment);
+               aux_offset = intel_plane_adjust_aligned_offset(&x, &y,
+                                                              plane_state,
+                                                              ccs_plane,
+                                                              aux_offset,
+                                                              aux_offset -
+                                                               alignment);
                aux_x = x * hsub + aux_x % hsub;
                aux_y = y * vsub + aux_y % vsub;
        }
@@ -3484,9 +3762,9 @@ static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state
        if (aux_x != main_x || aux_y != main_y)
                return false;
 
-       plane_state->color_plane[1].offset = aux_offset;
-       plane_state->color_plane[1].x = aux_x;
-       plane_state->color_plane[1].y = aux_y;
+       plane_state->color_plane[ccs_plane].offset = aux_offset;
+       plane_state->color_plane[ccs_plane].x = aux_x;
+       plane_state->color_plane[ccs_plane].y = aux_y;
 
        return true;
 }
@@ -3502,7 +3780,10 @@ static int skl_check_main_surface(struct intel_plane_state *plane_state)
        int h = drm_rect_height(&plane_state->uapi.src) >> 16;
        int max_width;
        int max_height;
-       u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
+       u32 alignment;
+       u32 offset;
+       int aux_plane = intel_main_to_aux_plane(fb, 0);
+       u32 aux_offset = plane_state->color_plane[aux_plane].offset;
 
        if (INTEL_GEN(dev_priv) >= 11)
                max_width = icl_max_plane_width(fb, 0, rotation);
@@ -3525,6 +3806,8 @@ static int skl_check_main_surface(struct intel_plane_state *plane_state)
        intel_add_fb_offsets(&x, &y, plane_state, 0);
        offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
        alignment = intel_surf_alignment(fb, 0);
+       if (WARN_ON(alignment && !is_power_of_2(alignment)))
+               return -EINVAL;
 
        /*
         * AUX surface offset is specified as the distance from the
@@ -3560,7 +3843,8 @@ static int skl_check_main_surface(struct intel_plane_state *plane_state)
         * they match with the main surface x/y offsets.
         */
        if (is_ccs_modifier(fb->modifier)) {
-               while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
+               while (!skl_check_main_ccs_coordinates(plane_state, x, y,
+                                                      offset, aux_plane)) {
                        if (offset == 0)
                                break;
 
@@ -3568,7 +3852,8 @@ static int skl_check_main_surface(struct intel_plane_state *plane_state)
                                                                   offset, offset - alignment);
                }
 
-               if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
+               if (x != plane_state->color_plane[aux_plane].x ||
+                   y != plane_state->color_plane[aux_plane].y) {
                        DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
                        return -EINVAL;
                }
@@ -3592,7 +3877,8 @@ static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
 {
        const struct drm_framebuffer *fb = plane_state->hw.fb;
        unsigned int rotation = plane_state->hw.rotation;
-       int max_width = skl_max_plane_width(fb, 1, rotation);
+       int uv_plane = 1;
+       int max_width = skl_max_plane_width(fb, uv_plane, rotation);
        int max_height = 4096;
        int x = plane_state->uapi.src.x1 >> 17;
        int y = plane_state->uapi.src.y1 >> 17;
@@ -3600,8 +3886,9 @@ static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
        int h = drm_rect_height(&plane_state->uapi.src) >> 17;
        u32 offset;
 
-       intel_add_fb_offsets(&x, &y, plane_state, 1);
-       offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
+       intel_add_fb_offsets(&x, &y, plane_state, uv_plane);
+       offset = intel_plane_compute_aligned_offset(&x, &y,
+                                                   plane_state, uv_plane);
 
        /* FIXME not quite sure how/if these apply to the chroma plane */
        if (w > max_width || h > max_height) {
@@ -3610,9 +3897,39 @@ static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
                return -EINVAL;
        }
 
-       plane_state->color_plane[1].offset = offset;
-       plane_state->color_plane[1].x = x;
-       plane_state->color_plane[1].y = y;
+       if (is_ccs_modifier(fb->modifier)) {
+               int ccs_plane = main_to_ccs_plane(fb, uv_plane);
+               int aux_offset = plane_state->color_plane[ccs_plane].offset;
+               int alignment = intel_surf_alignment(fb, uv_plane);
+
+               if (offset > aux_offset)
+                       offset = intel_plane_adjust_aligned_offset(&x, &y,
+                                                                  plane_state,
+                                                                  uv_plane,
+                                                                  offset,
+                                                                  aux_offset & ~(alignment - 1));
+
+               while (!skl_check_main_ccs_coordinates(plane_state, x, y,
+                                                      offset, ccs_plane)) {
+                       if (offset == 0)
+                               break;
+
+                       offset = intel_plane_adjust_aligned_offset(&x, &y,
+                                                                  plane_state,
+                                                                  uv_plane,
+                                                                  offset, offset - alignment);
+               }
+
+               if (x != plane_state->color_plane[ccs_plane].x ||
+                   y != plane_state->color_plane[ccs_plane].y) {
+                       DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
+                       return -EINVAL;
+               }
+       }
+
+       plane_state->color_plane[uv_plane].offset = offset;
+       plane_state->color_plane[uv_plane].x = x;
+       plane_state->color_plane[uv_plane].y = y;
 
        return 0;
 }
@@ -3622,18 +3939,40 @@ static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
        const struct drm_framebuffer *fb = plane_state->hw.fb;
        int src_x = plane_state->uapi.src.x1 >> 16;
        int src_y = plane_state->uapi.src.y1 >> 16;
-       int hsub = fb->format->hsub;
-       int vsub = fb->format->vsub;
-       int x = src_x / hsub;
-       int y = src_y / vsub;
        u32 offset;
+       int ccs_plane;
 
-       intel_add_fb_offsets(&x, &y, plane_state, 1);
-       offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
+       for (ccs_plane = 0; ccs_plane < fb->format->num_planes; ccs_plane++) {
+               int main_hsub, main_vsub;
+               int hsub, vsub;
+               int x, y;
+
+               if (!is_ccs_plane(fb, ccs_plane))
+                       continue;
+
+               intel_fb_plane_get_subsampling(&main_hsub, &main_vsub, fb,
+                                              ccs_to_main_plane(fb, ccs_plane));
+               intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
+
+               hsub *= main_hsub;
+               vsub *= main_vsub;
+               x = src_x / hsub;
+               y = src_y / vsub;
+
+               intel_add_fb_offsets(&x, &y, plane_state, ccs_plane);
+
+               offset = intel_plane_compute_aligned_offset(&x, &y,
+                                                           plane_state,
+                                                           ccs_plane);
 
-       plane_state->color_plane[1].offset = offset;
-       plane_state->color_plane[1].x = x * hsub + src_x % hsub;
-       plane_state->color_plane[1].y = y * vsub + src_y % vsub;
+               plane_state->color_plane[ccs_plane].offset = offset;
+               plane_state->color_plane[ccs_plane].x = (x * hsub +
+                                                        src_x % hsub) /
+                                                       main_hsub;
+               plane_state->color_plane[ccs_plane].y = (y * vsub +
+                                                        src_y % vsub) /
+                                                       main_vsub;
+       }
 
        return 0;
 }
@@ -3642,6 +3981,7 @@ int skl_check_plane_surface(struct intel_plane_state *plane_state)
 {
        const struct drm_framebuffer *fb = plane_state->hw.fb;
        int ret;
+       bool needs_aux = false;
 
        ret = intel_plane_compute_gtt(plane_state);
        if (ret)
@@ -3651,21 +3991,32 @@ int skl_check_plane_surface(struct intel_plane_state *plane_state)
                return 0;
 
        /*
-        * Handle the AUX surface first since
-        * the main surface setup depends on it.
+        * Handle the AUX surface first since the main surface setup depends on
+        * it.
         */
-       if (drm_format_info_is_yuv_semiplanar(fb->format)) {
-               ret = skl_check_nv12_aux_surface(plane_state);
+       if (is_ccs_modifier(fb->modifier)) {
+               needs_aux = true;
+               ret = skl_check_ccs_aux_surface(plane_state);
                if (ret)
                        return ret;
-       } else if (is_ccs_modifier(fb->modifier)) {
-               ret = skl_check_ccs_aux_surface(plane_state);
+       }
+
+       if (intel_format_info_is_yuv_semiplanar(fb->format,
+                                               fb->modifier)) {
+               needs_aux = true;
+               ret = skl_check_nv12_aux_surface(plane_state);
                if (ret)
                        return ret;
-       } else {
-               plane_state->color_plane[1].offset = ~0xfff;
-               plane_state->color_plane[1].x = 0;
-               plane_state->color_plane[1].y = 0;
+       }
+
+       if (!needs_aux) {
+               int i;
+
+               for (i = 1; i < fb->format->num_planes; i++) {
+                       plane_state->color_plane[i].offset = ~0xfff;
+                       plane_state->color_plane[i].x = 0;
+                       plane_state->color_plane[i].y = 0;
+               }
        }
 
        ret = skl_check_main_surface(plane_state);
@@ -4123,7 +4474,7 @@ static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
         * The stride is either expressed as a multiple of 64 bytes chunks for
         * linear buffers or in number of tiles for tiled buffers.
         */
-       if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
+       if (is_surface_linear(fb, color_plane))
                return 64;
        else if (drm_rotation_90_or_270(rotation))
                return intel_tile_height(fb, color_plane);
@@ -4251,6 +4602,12 @@ static u32 skl_plane_ctl_tiling(u64 fb_modifier)
                return PLANE_CTL_TILED_Y;
        case I915_FORMAT_MOD_Y_TILED_CCS:
                return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
+       case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
+               return PLANE_CTL_TILED_Y |
+                      PLANE_CTL_RENDER_DECOMPRESSION_ENABLE |
+                      PLANE_CTL_CLEAR_COLOR_DISABLE;
+       case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
+               return PLANE_CTL_TILED_Y | PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE;
        case I915_FORMAT_MOD_Yf_TILED:
                return PLANE_CTL_TILED_YF;
        case I915_FORMAT_MOD_Yf_TILED_CCS:
@@ -4606,25 +4963,6 @@ static void icl_enable_trans_port_sync(const struct intel_crtc_state *crtc_state
                   trans_ddi_func_ctl2_val);
 }
 
-static void icl_disable_transcoder_port_sync(const struct intel_crtc_state *old_crtc_state)
-{
-       struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
-       struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
-       i915_reg_t reg;
-       u32 trans_ddi_func_ctl2_val;
-
-       if (old_crtc_state->master_transcoder == INVALID_TRANSCODER)
-               return;
-
-       DRM_DEBUG_KMS("Disabling Transcoder Port Sync on Slave Transcoder %s\n",
-                     transcoder_name(old_crtc_state->cpu_transcoder));
-
-       reg = TRANS_DDI_FUNC_CTL2(old_crtc_state->cpu_transcoder);
-       trans_ddi_func_ctl2_val = ~(PORT_SYNC_MODE_ENABLE |
-                                   PORT_SYNC_MODE_MASTER_SELECT_MASK);
-       I915_WRITE(reg, trans_ddi_func_ctl2_val);
-}
-
 static void intel_fdi_normal_train(struct intel_crtc *crtc)
 {
        struct drm_device *dev = crtc->base.dev;
@@ -4667,8 +5005,8 @@ static void intel_fdi_normal_train(struct intel_crtc *crtc)
 }
 
 /* The FDI link training functions for ILK/Ibexpeak. */
-static void ironlake_fdi_link_train(struct intel_crtc *crtc,
-                                   const struct intel_crtc_state *crtc_state)
+static void ilk_fdi_link_train(struct intel_crtc *crtc,
+                              const struct intel_crtc_state *crtc_state)
 {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = to_i915(dev);
@@ -4677,7 +5015,7 @@ static void ironlake_fdi_link_train(struct intel_crtc *crtc,
        u32 temp, tries;
 
        /* FDI needs bits from pipe first */
-       assert_pipe_enabled(dev_priv, pipe);
+       assert_pipe_enabled(dev_priv, crtc_state->cpu_transcoder);
 
        /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
           for train result */
@@ -5020,7 +5358,7 @@ train_done:
        DRM_DEBUG_KMS("FDI train done.\n");
 }
 
-static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
+static void ilk_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
 {
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc);
        struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
@@ -5057,7 +5395,7 @@ static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
        }
 }
 
-static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
+static void ilk_fdi_pll_disable(struct intel_crtc *intel_crtc)
 {
        struct drm_device *dev = intel_crtc->base.dev;
        struct drm_i915_private *dev_priv = to_i915(dev);
@@ -5087,7 +5425,7 @@ static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
        udelay(100);
 }
 
-static void ironlake_fdi_disable(struct intel_crtc *crtc)
+static void ilk_fdi_disable(struct intel_crtc *crtc)
 {
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
        enum pipe pipe = crtc->pipe;
@@ -5294,8 +5632,8 @@ int lpt_get_iclkip(struct drm_i915_private *dev_priv)
                                 desired_divisor << auxdiv);
 }
 
-static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
-                                               enum pipe pch_transcoder)
+static void ilk_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
+                                          enum pipe pch_transcoder)
 {
        struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
@@ -5338,7 +5676,7 @@ static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool e
        POSTING_READ(SOUTH_CHICKEN1);
 }
 
-static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
+static void ivb_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
 {
        struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
@@ -5399,8 +5737,8 @@ intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
  *   - DP transcoding bits
  *   - transcoder
  */
-static void ironlake_pch_enable(const struct intel_atomic_state *state,
-                               const struct intel_crtc_state *crtc_state)
+static void ilk_pch_enable(const struct intel_atomic_state *state,
+                          const struct intel_crtc_state *crtc_state)
 {
        struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
        struct drm_device *dev = crtc->base.dev;
@@ -5411,7 +5749,7 @@ static void ironlake_pch_enable(const struct intel_atomic_state *state,
        assert_pch_transcoder_disabled(dev_priv, pipe);
 
        if (IS_IVYBRIDGE(dev_priv))
-               ivybridge_update_fdi_bc_bifurcation(crtc_state);
+               ivb_update_fdi_bc_bifurcation(crtc_state);
 
        /* Write the TU size bits before fdi link training, so that error
         * detection works. */
@@ -5448,7 +5786,7 @@ static void ironlake_pch_enable(const struct intel_atomic_state *state,
 
        /* set transcoder timing, panel must allow it */
        assert_panel_unlocked(dev_priv, pipe);
-       ironlake_pch_transcoder_set_timings(crtc_state, pipe);
+       ilk_pch_transcoder_set_timings(crtc_state, pipe);
 
        intel_fdi_normal_train(crtc);
 
@@ -5480,7 +5818,7 @@ static void ironlake_pch_enable(const struct intel_atomic_state *state,
                I915_WRITE(reg, temp);
        }
 
-       ironlake_enable_pch_transcoder(crtc_state);
+       ilk_enable_pch_transcoder(crtc_state);
 }
 
 static void lpt_pch_enable(const struct intel_atomic_state *state,
@@ -5495,7 +5833,7 @@ static void lpt_pch_enable(const struct intel_atomic_state *state,
        lpt_program_iclkip(crtc_state);
 
        /* Set transcoder timing. */
-       ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
+       ilk_pch_transcoder_set_timings(crtc_state, PIPE_A);
 
        lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
 }
@@ -5598,7 +5936,8 @@ static int
 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
                  unsigned int scaler_user, int *scaler_id,
                  int src_w, int src_h, int dst_w, int dst_h,
-                 const struct drm_format_info *format, bool need_scaler)
+                 const struct drm_format_info *format,
+                 u64 modifier, bool need_scaler)
 {
        struct intel_crtc_scaler_state *scaler_state =
                &crtc_state->scaler_state;
@@ -5652,7 +5991,7 @@ skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
                return 0;
        }
 
-       if (format && drm_format_info_is_yuv_semiplanar(format) &&
+       if (format && intel_format_info_is_yuv_semiplanar(format, modifier) &&
            (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
                DRM_DEBUG_KMS("Planar YUV: src dimensions not met\n");
                return -EINVAL;
@@ -5704,7 +6043,8 @@ int skl_update_scaler_crtc(struct intel_crtc_state *state)
                                 &state->scaler_state.scaler_id,
                                 state->pipe_src_w, state->pipe_src_h,
                                 adjusted_mode->crtc_hdisplay,
-                                adjusted_mode->crtc_vdisplay, NULL, need_scaler);
+                                adjusted_mode->crtc_vdisplay, NULL, 0,
+                                need_scaler);
 }
 
 /**
@@ -5729,7 +6069,7 @@ static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
 
        /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
        if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
-           fb && drm_format_info_is_yuv_semiplanar(fb->format))
+           fb && intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
                need_scaler = true;
 
        ret = skl_update_scaler(crtc_state, force_detach,
@@ -5739,7 +6079,9 @@ static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
                                drm_rect_height(&plane_state->uapi.src) >> 16,
                                drm_rect_width(&plane_state->uapi.dst),
                                drm_rect_height(&plane_state->uapi.dst),
-                               fb ? fb->format : NULL, need_scaler);
+                               fb ? fb->format : NULL,
+                               fb ? fb->modifier : 0,
+                               need_scaler);
 
        if (ret || plane_state->scaler_id < 0)
                return ret;
@@ -5795,15 +6137,16 @@ static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
        return 0;
 }
 
-static void skylake_scaler_disable(struct intel_crtc *crtc)
+void skl_scaler_disable(const struct intel_crtc_state *old_crtc_state)
 {
+       struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
        int i;
 
        for (i = 0; i < crtc->num_scalers; i++)
                skl_detach_scaler(crtc, i);
 }
 
-static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
+static void skl_pfit_enable(const struct intel_crtc_state *crtc_state)
 {
        struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
@@ -5840,7 +6183,7 @@ static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
        }
 }
 
-static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
+static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
 {
        struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
@@ -6084,8 +6427,9 @@ static void intel_pre_plane_update(struct intel_atomic_state *state,
        if (hsw_pre_update_disable_ips(old_crtc_state, new_crtc_state))
                hsw_disable_ips(old_crtc_state);
 
-       if (new_primary_state)
-               intel_fbc_pre_update(crtc, new_crtc_state, new_primary_state);
+       if (new_primary_state &&
+           intel_fbc_pre_update(crtc, new_crtc_state, new_primary_state))
+               intel_wait_for_vblank(dev_priv, pipe);
 
        /* Display WA 827 */
        if (!needs_nv12_wa(old_crtc_state) &&
@@ -6209,39 +6553,23 @@ intel_connector_primary_encoder(struct intel_connector *connector)
        return encoder;
 }
 
-static bool
-intel_connector_needs_modeset(struct intel_atomic_state *state,
-                             const struct drm_connector_state *old_conn_state,
-                             const struct drm_connector_state *new_conn_state)
-{
-       struct intel_crtc *old_crtc = old_conn_state->crtc ?
-                                     to_intel_crtc(old_conn_state->crtc) : NULL;
-       struct intel_crtc *new_crtc = new_conn_state->crtc ?
-                                     to_intel_crtc(new_conn_state->crtc) : NULL;
-
-       return new_crtc != old_crtc ||
-              (new_crtc &&
-               needs_modeset(intel_atomic_get_new_crtc_state(state, new_crtc)));
-}
-
 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
 {
-       struct drm_connector_state *old_conn_state;
        struct drm_connector_state *new_conn_state;
-       struct drm_connector *conn;
+       struct drm_connector *connector;
        int i;
 
-       for_each_oldnew_connector_in_state(&state->base, conn,
-                                          old_conn_state, new_conn_state, i) {
+       for_each_new_connector_in_state(&state->base, connector, new_conn_state,
+                                       i) {
+               struct intel_connector *intel_connector;
                struct intel_encoder *encoder;
                struct intel_crtc *crtc;
 
-               if (!intel_connector_needs_modeset(state,
-                                                  old_conn_state,
-                                                  new_conn_state))
+               if (!intel_connector_needs_modeset(state, connector))
                        continue;
 
-               encoder = intel_connector_primary_encoder(to_intel_connector(conn));
+               intel_connector = to_intel_connector(connector);
+               encoder = intel_connector_primary_encoder(intel_connector);
                if (!encoder->update_prepare)
                        continue;
 
@@ -6253,22 +6581,21 @@ static void intel_encoders_update_prepare(struct intel_atomic_state *state)
 
 static void intel_encoders_update_complete(struct intel_atomic_state *state)
 {
-       struct drm_connector_state *old_conn_state;
        struct drm_connector_state *new_conn_state;
-       struct drm_connector *conn;
+       struct drm_connector *connector;
        int i;
 
-       for_each_oldnew_connector_in_state(&state->base, conn,
-                                          old_conn_state, new_conn_state, i) {
+       for_each_new_connector_in_state(&state->base, connector, new_conn_state,
+                                       i) {
+               struct intel_connector *intel_connector;
                struct intel_encoder *encoder;
                struct intel_crtc *crtc;
 
-               if (!intel_connector_needs_modeset(state,
-                                                  old_conn_state,
-                                                  new_conn_state))
+               if (!intel_connector_needs_modeset(state, connector))
                        continue;
 
-               encoder = intel_connector_primary_encoder(to_intel_connector(conn));
+               intel_connector = to_intel_connector(connector);
+               encoder = intel_connector_primary_encoder(intel_connector);
                if (!encoder->update_complete)
                        continue;
 
@@ -6435,8 +6762,8 @@ static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_stat
        plane->disable_plane(plane, crtc_state);
 }
 
-static void ironlake_crtc_enable(struct intel_atomic_state *state,
-                                struct intel_crtc *crtc)
+static void ilk_crtc_enable(struct intel_atomic_state *state,
+                           struct intel_crtc *crtc)
 {
        const struct intel_crtc_state *new_crtc_state =
                intel_atomic_get_new_crtc_state(state, crtc);
@@ -6472,7 +6799,7 @@ static void ironlake_crtc_enable(struct intel_atomic_state *state,
                intel_cpu_transcoder_set_m_n(new_crtc_state,
                                             &new_crtc_state->fdi_m_n, NULL);
 
-       ironlake_set_pipeconf(new_crtc_state);
+       ilk_set_pipeconf(new_crtc_state);
 
        crtc->active = true;
 
@@ -6482,13 +6809,13 @@ static void ironlake_crtc_enable(struct intel_atomic_state *state,
                /* Note: FDI PLL enabling _must_ be done before we enable the
                 * cpu pipes, hence this is separate from all the other fdi/pch
                 * enabling. */
-               ironlake_fdi_pll_enable(new_crtc_state);
+               ilk_fdi_pll_enable(new_crtc_state);
        } else {
                assert_fdi_tx_disabled(dev_priv, pipe);
                assert_fdi_rx_disabled(dev_priv, pipe);
        }
 
-       ironlake_pfit_enable(new_crtc_state);
+       ilk_pfit_enable(new_crtc_state);
 
        /*
         * On ILK+ LUT must be loaded before the pipe is running but with
@@ -6504,7 +6831,7 @@ static void ironlake_crtc_enable(struct intel_atomic_state *state,
        intel_enable_pipe(new_crtc_state);
 
        if (new_crtc_state->has_pch_encoder)
-               ironlake_pch_enable(state, new_crtc_state);
+               ilk_pch_enable(state, new_crtc_state);
 
        intel_crtc_vblank_on(new_crtc_state);
 
@@ -6579,8 +6906,8 @@ static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
        I915_WRITE(reg, val);
 }
 
-static void haswell_crtc_enable(struct intel_atomic_state *state,
-                               struct intel_crtc *crtc)
+static void hsw_crtc_enable(struct intel_atomic_state *state,
+                           struct intel_crtc *crtc)
 {
        const struct intel_crtc_state *new_crtc_state =
                intel_atomic_get_new_crtc_state(state, crtc);
@@ -6621,7 +6948,7 @@ static void haswell_crtc_enable(struct intel_atomic_state *state,
 
        if (!transcoder_is_dsi(cpu_transcoder)) {
                hsw_set_frame_start_delay(new_crtc_state);
-               haswell_set_pipeconf(new_crtc_state);
+               hsw_set_pipeconf(new_crtc_state);
        }
 
        if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
@@ -6636,9 +6963,9 @@ static void haswell_crtc_enable(struct intel_atomic_state *state,
                glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
 
        if (INTEL_GEN(dev_priv) >= 9)
-               skylake_pfit_enable(new_crtc_state);
+               skl_pfit_enable(new_crtc_state);
        else
-               ironlake_pfit_enable(new_crtc_state);
+               ilk_pfit_enable(new_crtc_state);
 
        /*
         * On ILK+ LUT must be loaded before the pipe is running but with
@@ -6687,7 +7014,7 @@ static void haswell_crtc_enable(struct intel_atomic_state *state,
        }
 }
 
-static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
+void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
 {
        struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
@@ -6702,8 +7029,8 @@ static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
        }
 }
 
-static void ironlake_crtc_disable(struct intel_atomic_state *state,
-                                 struct intel_crtc *crtc)
+static void ilk_crtc_disable(struct intel_atomic_state *state,
+                            struct intel_crtc *crtc)
 {
        const struct intel_crtc_state *old_crtc_state =
                intel_atomic_get_old_crtc_state(state, crtc);
@@ -6720,19 +7047,19 @@ static void ironlake_crtc_disable(struct intel_atomic_state *state,
 
        intel_encoders_disable(state, crtc);
 
-       intel_crtc_vblank_off(crtc);
+       intel_crtc_vblank_off(old_crtc_state);
 
        intel_disable_pipe(old_crtc_state);
 
-       ironlake_pfit_disable(old_crtc_state);
+       ilk_pfit_disable(old_crtc_state);
 
        if (old_crtc_state->has_pch_encoder)
-               ironlake_fdi_disable(crtc);
+               ilk_fdi_disable(crtc);
 
        intel_encoders_post_disable(state, crtc);
 
        if (old_crtc_state->has_pch_encoder) {
-               ironlake_disable_pch_transcoder(dev_priv, pipe);
+               ilk_disable_pch_transcoder(dev_priv, pipe);
 
                if (HAS_PCH_CPT(dev_priv)) {
                        i915_reg_t reg;
@@ -6752,45 +7079,22 @@ static void ironlake_crtc_disable(struct intel_atomic_state *state,
                        I915_WRITE(PCH_DPLL_SEL, temp);
                }
 
-               ironlake_fdi_pll_disable(crtc);
+               ilk_fdi_pll_disable(crtc);
        }
 
        intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
        intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
 }
 
-static void haswell_crtc_disable(struct intel_atomic_state *state,
-                                struct intel_crtc *crtc)
+static void hsw_crtc_disable(struct intel_atomic_state *state,
+                            struct intel_crtc *crtc)
 {
-       const struct intel_crtc_state *old_crtc_state =
-               intel_atomic_get_old_crtc_state(state, crtc);
-       struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
-       enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
-
+       /*
+        * FIXME collapse everything to one hook.
+        * Need care with mst->ddi interactions.
+        */
        intel_encoders_disable(state, crtc);
-
-       intel_crtc_vblank_off(crtc);
-
-       /* XXX: Do the pipe assertions at the right place for BXT DSI. */
-       if (!transcoder_is_dsi(cpu_transcoder))
-               intel_disable_pipe(old_crtc_state);
-
-       if (INTEL_GEN(dev_priv) >= 11)
-               icl_disable_transcoder_port_sync(old_crtc_state);
-
-       if (!transcoder_is_dsi(cpu_transcoder))
-               intel_ddi_disable_transcoder_func(old_crtc_state);
-
-       intel_dsc_disable(old_crtc_state);
-
-       if (INTEL_GEN(dev_priv) >= 9)
-               skylake_scaler_disable(crtc);
-       else
-               ironlake_pfit_disable(old_crtc_state);
-
        intel_encoders_post_disable(state, crtc);
-
-       intel_encoders_post_pll_disable(state, crtc);
 }
 
 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
@@ -6806,7 +7110,7 @@ static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
         * according to register description and PRM.
         */
        WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
-       assert_pipe_disabled(dev_priv, crtc->pipe);
+       assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
 
        I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
        I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
@@ -7112,7 +7416,7 @@ static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
        if (!old_crtc_state->gmch_pfit.control)
                return;
 
-       assert_pipe_disabled(dev_priv, crtc->pipe);
+       assert_pipe_disabled(dev_priv, old_crtc_state->cpu_transcoder);
 
        DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
                      I915_READ(PFIT_CONTROL));
@@ -7136,7 +7440,7 @@ static void i9xx_crtc_disable(struct intel_atomic_state *state,
 
        intel_encoders_disable(state, crtc);
 
-       intel_crtc_vblank_off(crtc);
+       intel_crtc_vblank_off(old_crtc_state);
 
        intel_disable_pipe(old_crtc_state);
 
@@ -7320,8 +7624,8 @@ static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
        return 0;
 }
 
-static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
-                                    struct intel_crtc_state *pipe_config)
+static int ilk_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
+                              struct intel_crtc_state *pipe_config)
 {
        struct drm_i915_private *dev_priv = to_i915(dev);
        struct drm_atomic_state *state = pipe_config->uapi.state;
@@ -7393,8 +7697,8 @@ static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
 }
 
 #define RETRY 1
-static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
-                                      struct intel_crtc_state *pipe_config)
+static int ilk_fdi_compute_config(struct intel_crtc *intel_crtc,
+                                 struct intel_crtc_state *pipe_config)
 {
        struct drm_device *dev = intel_crtc->base.dev;
        const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
@@ -7413,15 +7717,15 @@ retry:
 
        fdi_dotclock = adjusted_mode->crtc_clock;
 
-       lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
-                                          pipe_config->pipe_bpp);
+       lane = ilk_get_lanes_required(fdi_dotclock, link_bw,
+                                     pipe_config->pipe_bpp);
 
        pipe_config->fdi_lanes = lane;
 
        intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
                               link_bw, &pipe_config->fdi_m_n, false, false);
 
-       ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
+       ret = ilk_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
        if (ret == -EDEADLK)
                return ret;
 
@@ -7627,7 +7931,7 @@ static int intel_crtc_compute_config(struct intel_crtc *crtc,
        intel_crtc_compute_pixel_rate(pipe_config);
 
        if (pipe_config->has_pch_encoder)
-               return ironlake_fdi_compute_config(crtc, pipe_config);
+               return ilk_fdi_compute_config(crtc, pipe_config);
 
        return 0;
 }
@@ -8118,11 +8422,11 @@ int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
        struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
        struct intel_crtc_state *pipe_config;
 
-       pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
+       pipe_config = intel_crtc_state_alloc(crtc);
        if (!pipe_config)
                return -ENOMEM;
 
-       pipe_config->uapi.crtc = &crtc->base;
+       pipe_config->cpu_transcoder = (enum transcoder)pipe;
        pipe_config->pixel_multiplier = 1;
        pipe_config->dpll = *dpll;
 
@@ -8610,9 +8914,9 @@ static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
                        DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
                }
 
-               limit = &intel_limits_pineview_lvds;
+               limit = &pnv_limits_lvds;
        } else {
-               limit = &intel_limits_pineview_sdvo;
+               limit = &pnv_limits_sdvo;
        }
 
        if (!crtc_state->clock_set &&
@@ -9039,7 +9343,7 @@ out:
        return ret;
 }
 
-static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
+static void ilk_init_pch_refclk(struct drm_i915_private *dev_priv)
 {
        struct intel_encoder *encoder;
        int i;
@@ -9537,12 +9841,12 @@ static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
 {
        if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
-               ironlake_init_pch_refclk(dev_priv);
+               ilk_init_pch_refclk(dev_priv);
        else if (HAS_PCH_LPT(dev_priv))
                lpt_init_pch_refclk(dev_priv);
 }
 
-static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
+static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
 {
        struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
@@ -9598,7 +9902,7 @@ static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
        POSTING_READ(PIPECONF(pipe));
 }
 
-static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
+static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state)
 {
        struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
@@ -9686,7 +9990,7 @@ int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
        }
 }
 
-int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
+int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
 {
        /*
         * Account for spread spectrum to avoid
@@ -9697,14 +10001,14 @@ int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
        return DIV_ROUND_UP(bps, link_bw * 8);
 }
 
-static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
+static bool ilk_needs_fb_cb_tune(struct dpll *dpll, int factor)
 {
        return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
 }
 
-static void ironlake_compute_dpll(struct intel_crtc *crtc,
-                                 struct intel_crtc_state *crtc_state,
-                                 struct dpll *reduced_clock)
+static void ilk_compute_dpll(struct intel_crtc *crtc,
+                            struct intel_crtc_state *crtc_state,
+                            struct dpll *reduced_clock)
 {
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
        u32 dpll, fp, fp2;
@@ -9724,7 +10028,7 @@ static void ironlake_compute_dpll(struct intel_crtc *crtc,
 
        fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
 
-       if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
+       if (ilk_needs_fb_cb_tune(&crtc_state->dpll, factor))
                fp |= FP_CB_TUNE;
 
        if (reduced_clock) {
@@ -9804,8 +10108,8 @@ static void ironlake_compute_dpll(struct intel_crtc *crtc,
        crtc_state->dpll_hw_state.fp1 = fp2;
 }
 
-static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
-                                      struct intel_crtc_state *crtc_state)
+static int ilk_crtc_compute_clock(struct intel_crtc *crtc,
+                                 struct intel_crtc_state *crtc_state)
 {
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
        struct intel_atomic_state *state =
@@ -9829,17 +10133,17 @@ static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
 
                if (intel_is_dual_link_lvds(dev_priv)) {
                        if (refclk == 100000)
-                               limit = &intel_limits_ironlake_dual_lvds_100m;
+                               limit = &ilk_limits_dual_lvds_100m;
                        else
-                               limit = &intel_limits_ironlake_dual_lvds;
+                               limit = &ilk_limits_dual_lvds;
                } else {
                        if (refclk == 100000)
-                               limit = &intel_limits_ironlake_single_lvds_100m;
+                               limit = &ilk_limits_single_lvds_100m;
                        else
-                               limit = &intel_limits_ironlake_single_lvds;
+                               limit = &ilk_limits_single_lvds;
                }
        } else {
-               limit = &intel_limits_ironlake_dac;
+               limit = &ilk_limits_dac;
        }
 
        if (!crtc_state->clock_set &&
@@ -9849,7 +10153,7 @@ static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
                return -EINVAL;
        }
 
-       ironlake_compute_dpll(crtc, crtc_state, NULL);
+       ilk_compute_dpll(crtc, crtc_state, NULL);
 
        if (!intel_reserve_shared_dplls(state, crtc, NULL)) {
                DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
@@ -9924,15 +10228,15 @@ void intel_dp_get_m_n(struct intel_crtc *crtc,
                                             &pipe_config->dp_m2_n2);
 }
 
-static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
-                                       struct intel_crtc_state *pipe_config)
+static void ilk_get_fdi_m_n_config(struct intel_crtc *crtc,
+                                  struct intel_crtc_state *pipe_config)
 {
        intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
                                     &pipe_config->fdi_m_n, NULL);
 }
 
-static void skylake_get_pfit_config(struct intel_crtc *crtc,
-                                   struct intel_crtc_state *pipe_config)
+static void skl_get_pfit_config(struct intel_crtc *crtc,
+                               struct intel_crtc_state *pipe_config)
 {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = to_i915(dev);
@@ -9963,8 +10267,8 @@ static void skylake_get_pfit_config(struct intel_crtc *crtc,
 }
 
 static void
-skylake_get_initial_plane_config(struct intel_crtc *crtc,
-                                struct intel_initial_plane_config *plane_config)
+skl_get_initial_plane_config(struct intel_crtc *crtc,
+                            struct intel_initial_plane_config *plane_config)
 {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = to_i915(dev);
@@ -10022,7 +10326,11 @@ skylake_get_initial_plane_config(struct intel_crtc *crtc,
        case PLANE_CTL_TILED_Y:
                plane_config->tiling = I915_TILING_Y;
                if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
-                       fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
+                       fb->modifier = INTEL_GEN(dev_priv) >= 12 ?
+                               I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS :
+                               I915_FORMAT_MOD_Y_TILED_CCS;
+               else if (val & PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE)
+                       fb->modifier = I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
                else
                        fb->modifier = I915_FORMAT_MOD_Y_TILED;
                break;
@@ -10089,8 +10397,8 @@ error:
        kfree(intel_fb);
 }
 
-static void ironlake_get_pfit_config(struct intel_crtc *crtc,
-                                    struct intel_crtc_state *pipe_config)
+static void ilk_get_pfit_config(struct intel_crtc *crtc,
+                               struct intel_crtc_state *pipe_config)
 {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = to_i915(dev);
@@ -10113,8 +10421,8 @@ static void ironlake_get_pfit_config(struct intel_crtc *crtc,
        }
 }
 
-static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
-                                    struct intel_crtc_state *pipe_config)
+static bool ilk_get_pipe_config(struct intel_crtc *crtc,
+                               struct intel_crtc_state *pipe_config)
 {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = to_i915(dev);
@@ -10185,7 +10493,7 @@ static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
                pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
                                          FDI_DP_PORT_WIDTH_SHIFT) + 1;
 
-               ironlake_get_fdi_m_n_config(crtc, pipe_config);
+               ilk_get_fdi_m_n_config(crtc, pipe_config);
 
                if (HAS_PCH_IBX(dev_priv)) {
                        /*
@@ -10213,7 +10521,7 @@ static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
                        ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
                         >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
 
-               ironlake_pch_clock_get(crtc, pipe_config);
+               ilk_pch_clock_get(crtc, pipe_config);
        } else {
                pipe_config->pixel_multiplier = 1;
        }
@@ -10221,7 +10529,7 @@ static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
        intel_get_pipe_timings(crtc, pipe_config);
        intel_get_pipe_src_size(crtc, pipe_config);
 
-       ironlake_get_pfit_config(crtc, pipe_config);
+       ilk_get_pfit_config(crtc, pipe_config);
 
        ret = true;
 
@@ -10230,8 +10538,9 @@ out:
 
        return ret;
 }
-static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
-                                     struct intel_crtc_state *crtc_state)
+
+static int hsw_crtc_compute_clock(struct intel_crtc *crtc,
+                                 struct intel_crtc_state *crtc_state)
 {
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
        struct intel_atomic_state *state =
@@ -10252,9 +10561,8 @@ static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
        return 0;
 }
 
-static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
-                                  enum port port,
-                                  struct intel_crtc_state *pipe_config)
+static void cnl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
+                           struct intel_crtc_state *pipe_config)
 {
        enum intel_dpll_id id;
        u32 temp;
@@ -10268,9 +10576,8 @@ static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
        pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
 }
 
-static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
-                               enum port port,
-                               struct intel_crtc_state *pipe_config)
+static void icl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
+                           struct intel_crtc_state *pipe_config)
 {
        enum phy phy = intel_port_to_phy(dev_priv, port);
        enum icl_port_dpll_id port_dpll_id;
@@ -10329,9 +10636,8 @@ static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
        pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
 }
 
-static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
-                               enum port port,
-                               struct intel_crtc_state *pipe_config)
+static void skl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
+                           struct intel_crtc_state *pipe_config)
 {
        enum intel_dpll_id id;
        u32 temp;
@@ -10345,9 +10651,8 @@ static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
        pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
 }
 
-static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
-                               enum port port,
-                               struct intel_crtc_state *pipe_config)
+static void hsw_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
+                           struct intel_crtc_state *pipe_config)
 {
        enum intel_dpll_id id;
        u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
@@ -10448,6 +10753,9 @@ static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
                case TRANS_DDI_EDP_INPUT_C_ONOFF:
                        trans_pipe = PIPE_C;
                        break;
+               case TRANS_DDI_EDP_INPUT_D_ONOFF:
+                       trans_pipe = PIPE_D;
+                       break;
                }
 
                if (trans_pipe == crtc->pipe) {
@@ -10532,8 +10840,8 @@ static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
        return transcoder_is_dsi(pipe_config->cpu_transcoder);
 }
 
-static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
-                                      struct intel_crtc_state *pipe_config)
+static void hsw_get_ddi_port_state(struct intel_crtc *crtc,
+                                  struct intel_crtc_state *pipe_config)
 {
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
        enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
@@ -10553,15 +10861,15 @@ static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
        }
 
        if (INTEL_GEN(dev_priv) >= 11)
-               icelake_get_ddi_pll(dev_priv, port, pipe_config);
+               icl_get_ddi_pll(dev_priv, port, pipe_config);
        else if (IS_CANNONLAKE(dev_priv))
-               cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
+               cnl_get_ddi_pll(dev_priv, port, pipe_config);
        else if (IS_GEN9_BC(dev_priv))
-               skylake_get_ddi_pll(dev_priv, port, pipe_config);
+               skl_get_ddi_pll(dev_priv, port, pipe_config);
        else if (IS_GEN9_LP(dev_priv))
                bxt_get_ddi_pll(dev_priv, port, pipe_config);
        else
-               haswell_get_ddi_pll(dev_priv, port, pipe_config);
+               hsw_get_ddi_pll(dev_priv, port, pipe_config);
 
        pll = pipe_config->shared_dpll;
        if (pll) {
@@ -10582,7 +10890,7 @@ static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
                pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
                                          FDI_DP_PORT_WIDTH_SHIFT) + 1;
 
-               ironlake_get_fdi_m_n_config(crtc, pipe_config);
+               ilk_get_fdi_m_n_config(crtc, pipe_config);
        }
 }
 
@@ -10604,7 +10912,7 @@ static enum transcoder transcoder_master_readout(struct drm_i915_private *dev_pr
                return master_select - 1;
 }
 
-static void icelake_get_trans_port_sync_config(struct intel_crtc_state *crtc_state)
+static void icl_get_trans_port_sync_config(struct intel_crtc_state *crtc_state)
 {
        struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
        u32 transcoders;
@@ -10639,8 +10947,8 @@ static void icelake_get_trans_port_sync_config(struct intel_crtc_state *crtc_sta
                crtc_state->sync_mode_slaves_mask);
 }
 
-static bool haswell_get_pipe_config(struct intel_crtc *crtc,
-                                   struct intel_crtc_state *pipe_config)
+static bool hsw_get_pipe_config(struct intel_crtc *crtc,
+                               struct intel_crtc_state *pipe_config)
 {
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
        intel_wakeref_t wakerefs[POWER_DOMAIN_NUM], wf;
@@ -10648,8 +10956,6 @@ static bool haswell_get_pipe_config(struct intel_crtc *crtc,
        u64 power_domain_mask;
        bool active;
 
-       intel_crtc_init_scalers(crtc, pipe_config);
-
        pipe_config->master_transcoder = INVALID_TRANSCODER;
 
        power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
@@ -10677,7 +10983,7 @@ static bool haswell_get_pipe_config(struct intel_crtc *crtc,
 
        if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
            INTEL_GEN(dev_priv) >= 11) {
-               haswell_get_ddi_port_state(crtc, pipe_config);
+               hsw_get_ddi_port_state(crtc, pipe_config);
                intel_get_pipe_timings(crtc, pipe_config);
        }
 
@@ -10734,9 +11040,9 @@ static bool haswell_get_pipe_config(struct intel_crtc *crtc,
                power_domain_mask |= BIT_ULL(power_domain);
 
                if (INTEL_GEN(dev_priv) >= 9)
-                       skylake_get_pfit_config(crtc, pipe_config);
+                       skl_get_pfit_config(crtc, pipe_config);
                else
-                       ironlake_get_pfit_config(crtc, pipe_config);
+                       ilk_get_pfit_config(crtc, pipe_config);
        }
 
        if (hsw_crtc_supports_ips(crtc)) {
@@ -10762,7 +11068,7 @@ static bool haswell_get_pipe_config(struct intel_crtc *crtc,
 
        if (INTEL_GEN(dev_priv) >= 11 &&
            !transcoder_is_dsi(pipe_config->cpu_transcoder))
-               icelake_get_trans_port_sync_config(pipe_config);
+               icl_get_trans_port_sync_config(pipe_config);
 
 out:
        for_each_power_domain(power_domain, power_domain_mask)
@@ -11679,8 +11985,8 @@ int intel_dotclock_calculate(int link_freq,
        return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
 }
 
-static void ironlake_pch_clock_get(struct intel_crtc *crtc,
-                                  struct intel_crtc_state *pipe_config)
+static void ilk_pch_clock_get(struct intel_crtc *crtc,
+                             struct intel_crtc_state *pipe_config)
 {
        struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
 
@@ -11697,6 +12003,33 @@ static void ironlake_pch_clock_get(struct intel_crtc *crtc,
                                         &pipe_config->fdi_m_n);
 }
 
+static void intel_crtc_state_reset(struct intel_crtc_state *crtc_state,
+                                  struct intel_crtc *crtc)
+{
+       memset(crtc_state, 0, sizeof(*crtc_state));
+
+       __drm_atomic_helper_crtc_state_reset(&crtc_state->uapi, &crtc->base);
+
+       crtc_state->cpu_transcoder = INVALID_TRANSCODER;
+       crtc_state->master_transcoder = INVALID_TRANSCODER;
+       crtc_state->hsw_workaround_pipe = INVALID_PIPE;
+       crtc_state->output_format = INTEL_OUTPUT_FORMAT_INVALID;
+       crtc_state->scaler_state.scaler_id = -1;
+       crtc_state->mst_master_transcoder = INVALID_TRANSCODER;
+}
+
+static struct intel_crtc_state *intel_crtc_state_alloc(struct intel_crtc *crtc)
+{
+       struct intel_crtc_state *crtc_state;
+
+       crtc_state = kmalloc(sizeof(*crtc_state), GFP_KERNEL);
+
+       if (crtc_state)
+               intel_crtc_state_reset(crtc_state, crtc);
+
+       return crtc_state;
+}
+
 /* Returns the currently programmed mode of the given encoder. */
 struct drm_display_mode *
 intel_encoder_current_mode(struct intel_encoder *encoder)
@@ -11716,14 +12049,12 @@ intel_encoder_current_mode(struct intel_encoder *encoder)
        if (!mode)
                return NULL;
 
-       crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
+       crtc_state = intel_crtc_state_alloc(crtc);
        if (!crtc_state) {
                kfree(mode);
                return NULL;
        }
 
-       crtc_state->uapi.crtc = &crtc->base;
-
        if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
                kfree(crtc_state);
                kfree(mode);
@@ -12035,7 +12366,8 @@ static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
                /* Copy parameters to slave plane */
                linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
                linked_state->color_ctl = plane_state->color_ctl;
-               linked_state->color_plane[0] = plane_state->color_plane[0];
+               memcpy(linked_state->color_plane, plane_state->color_plane,
+                      sizeof(linked_state->color_plane));
 
                intel_plane_copy_uapi_to_hw_state(linked_state, plane_state);
                linked_state->uapi.src = plane_state->uapi.src;
@@ -12065,88 +12397,121 @@ static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
        return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
 }
 
-static int icl_add_sync_mode_crtcs(struct intel_crtc_state *crtc_state)
+static bool
+intel_atomic_is_master_connector(struct intel_crtc_state *crtc_state)
+{
+       struct drm_crtc *crtc = crtc_state->uapi.crtc;
+       struct drm_atomic_state *state = crtc_state->uapi.state;
+       struct drm_connector *connector;
+       struct drm_connector_state *connector_state;
+       int i;
+
+       for_each_new_connector_in_state(state, connector, connector_state, i) {
+               if (connector_state->crtc != crtc)
+                       continue;
+               if (connector->has_tile &&
+                   connector->tile_h_loc == connector->num_h_tile - 1 &&
+                   connector->tile_v_loc == connector->num_v_tile - 1)
+                       return true;
+       }
+
+       return false;
+}
+
+static void reset_port_sync_mode_state(struct intel_crtc_state *crtc_state)
+{
+       crtc_state->master_transcoder = INVALID_TRANSCODER;
+       crtc_state->sync_mode_slaves_mask = 0;
+}
+
+static int icl_compute_port_sync_crtc_state(struct drm_connector *connector,
+                                           struct intel_crtc_state *crtc_state,
+                                           int num_tiled_conns)
 {
        struct drm_crtc *crtc = crtc_state->uapi.crtc;
        struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
        struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
-       struct drm_connector *master_connector, *connector;
-       struct drm_connector_state *connector_state;
+       struct drm_connector *master_connector;
        struct drm_connector_list_iter conn_iter;
        struct drm_crtc *master_crtc = NULL;
        struct drm_crtc_state *master_crtc_state;
        struct intel_crtc_state *master_pipe_config;
-       int i, tile_group_id;
 
        if (INTEL_GEN(dev_priv) < 11)
                return 0;
 
+       if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP))
+               return 0;
+
        /*
         * In case of tiled displays there could be one or more slaves but there is
         * only one master. Lets make the CRTC used by the connector corresponding
         * to the last horizonal and last vertical tile a master/genlock CRTC.
         * All the other CRTCs corresponding to other tiles of the same Tile group
         * are the slave CRTCs and hold a pointer to their genlock CRTC.
+        * If all tiles not present do not make master slave assignments.
         */
-       for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
-               if (connector_state->crtc != crtc)
-                       continue;
-               if (!connector->has_tile)
-                       continue;
-               if (crtc_state->hw.mode.hdisplay != connector->tile_h_size ||
-                   crtc_state->hw.mode.vdisplay != connector->tile_v_size)
-                       return 0;
-               if (connector->tile_h_loc == connector->num_h_tile - 1 &&
-                   connector->tile_v_loc == connector->num_v_tile - 1)
-                       continue;
-               crtc_state->sync_mode_slaves_mask = 0;
-               tile_group_id = connector->tile_group->id;
-               drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
-               drm_for_each_connector_iter(master_connector, &conn_iter) {
-                       struct drm_connector_state *master_conn_state = NULL;
+       if (!connector->has_tile ||
+           crtc_state->hw.mode.hdisplay != connector->tile_h_size ||
+           crtc_state->hw.mode.vdisplay != connector->tile_v_size ||
+           num_tiled_conns < connector->num_h_tile * connector->num_v_tile) {
+               reset_port_sync_mode_state(crtc_state);
+               return 0;
+       }
+       /* Last Horizontal and last vertical tile connector is a master
+        * Master's crtc state is already populated in slave for port sync
+        */
+       if (connector->tile_h_loc == connector->num_h_tile - 1 &&
+           connector->tile_v_loc == connector->num_v_tile - 1)
+               return 0;
 
-                       if (!master_connector->has_tile)
-                               continue;
-                       if (master_connector->tile_h_loc != master_connector->num_h_tile - 1 ||
-                           master_connector->tile_v_loc != master_connector->num_v_tile - 1)
-                               continue;
-                       if (master_connector->tile_group->id != tile_group_id)
-                               continue;
+       /* Loop through all connectors and configure the Slave crtc_state
+        * to point to the correct master.
+        */
+       drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
+       drm_for_each_connector_iter(master_connector, &conn_iter) {
+               struct drm_connector_state *master_conn_state = NULL;
 
-                       master_conn_state = drm_atomic_get_connector_state(&state->base,
-                                                                          master_connector);
-                       if (IS_ERR(master_conn_state)) {
-                               drm_connector_list_iter_end(&conn_iter);
-                               return PTR_ERR(master_conn_state);
-                       }
-                       if (master_conn_state->crtc) {
-                               master_crtc = master_conn_state->crtc;
-                               break;
-                       }
-               }
-               drm_connector_list_iter_end(&conn_iter);
+               if (!(master_connector->has_tile &&
+                     master_connector->tile_group->id == connector->tile_group->id))
+                       continue;
+               if (master_connector->tile_h_loc != master_connector->num_h_tile - 1 ||
+                   master_connector->tile_v_loc != master_connector->num_v_tile - 1)
+                       continue;
 
-               if (!master_crtc) {
-                       DRM_DEBUG_KMS("Could not find Master CRTC for Slave CRTC %d\n",
-                                     connector_state->crtc->base.id);
-                       return -EINVAL;
+               master_conn_state = drm_atomic_get_connector_state(&state->base,
+                                                                  master_connector);
+               if (IS_ERR(master_conn_state)) {
+                       drm_connector_list_iter_end(&conn_iter);
+                       return PTR_ERR(master_conn_state);
                }
+               if (master_conn_state->crtc) {
+                       master_crtc = master_conn_state->crtc;
+                       break;
+               }
+       }
+       drm_connector_list_iter_end(&conn_iter);
 
-               master_crtc_state = drm_atomic_get_crtc_state(&state->base,
-                                                             master_crtc);
-               if (IS_ERR(master_crtc_state))
-                       return PTR_ERR(master_crtc_state);
-
-               master_pipe_config = to_intel_crtc_state(master_crtc_state);
-               crtc_state->master_transcoder = master_pipe_config->cpu_transcoder;
-               master_pipe_config->sync_mode_slaves_mask |=
-                       BIT(crtc_state->cpu_transcoder);
-               DRM_DEBUG_KMS("Master Transcoder = %s added for Slave CRTC = %d, slave transcoder bitmask = %d\n",
-                             transcoder_name(crtc_state->master_transcoder),
-                             crtc_state->uapi.crtc->base.id,
-                             master_pipe_config->sync_mode_slaves_mask);
+       if (!master_crtc) {
+               DRM_DEBUG_KMS("Could not find Master CRTC for Slave CRTC %d\n",
+                             crtc->base.id);
+               return -EINVAL;
        }
 
+       master_crtc_state = drm_atomic_get_crtc_state(&state->base,
+                                                     master_crtc);
+       if (IS_ERR(master_crtc_state))
+               return PTR_ERR(master_crtc_state);
+
+       master_pipe_config = to_intel_crtc_state(master_crtc_state);
+       crtc_state->master_transcoder = master_pipe_config->cpu_transcoder;
+       master_pipe_config->sync_mode_slaves_mask |=
+               BIT(crtc_state->cpu_transcoder);
+       DRM_DEBUG_KMS("Master Transcoder = %s added for Slave CRTC = %d, slave transcoder bitmask = %d\n",
+                     transcoder_name(crtc_state->master_transcoder),
+                     crtc->base.id,
+                     master_pipe_config->sync_mode_slaves_mask);
+
        return 0;
 }
 
@@ -12349,7 +12714,7 @@ static void
 intel_dump_infoframe(struct drm_i915_private *dev_priv,
                     const union hdmi_infoframe *frame)
 {
-       if ((drm_debug & DRM_UT_KMS) == 0)
+       if (!drm_debug_enabled(DRM_UT_KMS))
                return;
 
        hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, frame);
@@ -12542,6 +12907,9 @@ static void intel_dump_pipe_config(const struct intel_crtc_state *pipe_config,
                              pipe_config->csc_mode, pipe_config->gamma_mode,
                              pipe_config->gamma_enable, pipe_config->csc_enable);
 
+       DRM_DEBUG_KMS("MST master transcoder: %s\n",
+                     transcoder_name(pipe_config->mst_master_transcoder));
+
 dump_planes:
        if (!state)
                return;
@@ -12660,11 +13028,11 @@ static void intel_crtc_copy_hw_to_uapi_state(struct intel_crtc_state *crtc_state
 static int
 intel_crtc_prepare_cleared_state(struct intel_crtc_state *crtc_state)
 {
-       struct drm_i915_private *dev_priv =
-               to_i915(crtc_state->uapi.crtc->dev);
+       struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
+       struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
        struct intel_crtc_state *saved_state;
 
-       saved_state = kzalloc(sizeof(*saved_state), GFP_KERNEL);
+       saved_state = intel_crtc_state_alloc(crtc);
        if (!saved_state)
                return -ENOMEM;
 
@@ -12688,9 +13056,11 @@ intel_crtc_prepare_cleared_state(struct intel_crtc_state *crtc_state)
                saved_state->wm = crtc_state->wm;
        /*
         * Save the slave bitmask which gets filled for master crtc state during
-        * slave atomic check call.
+        * slave atomic check call. For all other CRTCs reset the port sync variables
+        * crtc_state->master_transcoder needs to be set to INVALID
         */
-       if (is_trans_port_sync_master(crtc_state))
+       reset_port_sync_mode_state(saved_state);
+       if (intel_atomic_is_master_connector(crtc_state))
                saved_state->sync_mode_slaves_mask =
                        crtc_state->sync_mode_slaves_mask;
 
@@ -12711,7 +13081,7 @@ intel_modeset_pipe_config(struct intel_crtc_state *pipe_config)
        struct drm_connector *connector;
        struct drm_connector_state *connector_state;
        int base_bpp, ret;
-       int i;
+       int i, tile_group_id = -1, num_tiled_conns = 0;
        bool retry = true;
 
        pipe_config->cpu_transcoder =
@@ -12781,13 +13151,22 @@ encoder_retry:
        drm_mode_set_crtcinfo(&pipe_config->hw.adjusted_mode,
                              CRTC_STEREO_DOUBLE);
 
-       /* Set the crtc_state defaults for trans_port_sync */
-       pipe_config->master_transcoder = INVALID_TRANSCODER;
-       ret = icl_add_sync_mode_crtcs(pipe_config);
-       if (ret) {
-               DRM_DEBUG_KMS("Cannot assign Sync Mode CRTCs: %d\n",
-                             ret);
-               return ret;
+       /* Get tile_group_id of tiled connector */
+       for_each_new_connector_in_state(state, connector, connector_state, i) {
+               if (connector_state->crtc == crtc &&
+                   connector->has_tile) {
+                       tile_group_id = connector->tile_group->id;
+                       break;
+               }
+       }
+
+       /* Get total number of tiled connectors in state that belong to
+        * this tile group.
+        */
+       for_each_new_connector_in_state(state, connector, connector_state, i) {
+               if (connector->has_tile &&
+                   connector->tile_group->id == tile_group_id)
+                       num_tiled_conns++;
        }
 
        /* Pass our mode to the connectors and the CRTC to give them a chance to
@@ -12798,6 +13177,14 @@ encoder_retry:
                if (connector_state->crtc != crtc)
                        continue;
 
+               ret = icl_compute_port_sync_crtc_state(connector, pipe_config,
+                                                      num_tiled_conns);
+               if (ret) {
+                       DRM_DEBUG_KMS("Cannot assign Sync Mode CRTCs: %d\n",
+                                     ret);
+                       return ret;
+               }
+
                encoder = to_intel_encoder(connector_state->best_encoder);
                ret = encoder->compute_config(encoder, pipe_config,
                                              connector_state);
@@ -12925,7 +13312,7 @@ pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
                               const union hdmi_infoframe *b)
 {
        if (fastset) {
-               if ((drm_debug & DRM_UT_KMS) == 0)
+               if (!drm_debug_enabled(DRM_UT_KMS))
                        return;
 
                DRM_DEBUG_KMS("fastset mismatch in %s infoframe\n", name);
@@ -13318,6 +13705,12 @@ intel_pipe_config_compare(const struct intel_crtc_state *current_config,
        PIPE_CONF_CHECK_I(sync_mode_slaves_mask);
        PIPE_CONF_CHECK_I(master_transcoder);
 
+       PIPE_CONF_CHECK_I(dsc.compression_enable);
+       PIPE_CONF_CHECK_I(dsc.dsc_split);
+       PIPE_CONF_CHECK_I(dsc.compressed_bpp);
+
+       PIPE_CONF_CHECK_I(mst_master_transcoder);
+
 #undef PIPE_CONF_CHECK_X
 #undef PIPE_CONF_CHECK_I
 #undef PIPE_CONF_CHECK_BOOL
@@ -13570,18 +13963,14 @@ verify_crtc_state(struct intel_crtc *crtc,
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = to_i915(dev);
        struct intel_encoder *encoder;
-       struct intel_crtc_state *pipe_config;
-       struct drm_atomic_state *state;
+       struct intel_crtc_state *pipe_config = old_crtc_state;
+       struct drm_atomic_state *state = old_crtc_state->uapi.state;
        bool active;
 
-       state = old_crtc_state->uapi.state;
        __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->uapi);
        intel_crtc_free_hw_state(old_crtc_state);
-
-       pipe_config = old_crtc_state;
-       memset(pipe_config, 0, sizeof(*pipe_config));
-       pipe_config->uapi.crtc = &crtc->base;
-       pipe_config->uapi.state = state;
+       intel_crtc_state_reset(old_crtc_state, crtc);
+       old_crtc_state->uapi.state = state;
 
        DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.base.id, crtc->base.name);
 
@@ -13835,7 +14224,7 @@ static void intel_modeset_clear_plls(struct intel_atomic_state *state)
  * multiple pipes, and planes are enabled after the pipe, we need to wait at
  * least 2 vblanks on the first pipe before enabling planes on the second pipe.
  */
-static int haswell_mode_set_planes_workaround(struct intel_atomic_state *state)
+static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
 {
        struct intel_crtc_state *crtc_state;
        struct intel_crtc *crtc;
@@ -13930,7 +14319,7 @@ static int intel_modeset_checks(struct intel_atomic_state *state)
        intel_modeset_clear_plls(state);
 
        if (IS_HASWELL(dev_priv))
-               return haswell_mode_set_planes_workaround(state);
+               return hsw_mode_set_planes_workaround(state);
 
        return 0;
 }
@@ -13960,7 +14349,11 @@ static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_sta
 
        new_crtc_state->uapi.mode_changed = false;
        new_crtc_state->update_pipe = true;
+}
 
+static void intel_crtc_copy_fastset(const struct intel_crtc_state *old_crtc_state,
+                                   struct intel_crtc_state *new_crtc_state)
+{
        /*
         * If we're not doing the full modeset we want to
         * keep the current M/N values as they may be
@@ -14083,6 +14476,107 @@ static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
        return 0;
 }
 
+static bool intel_cpu_transcoder_needs_modeset(struct intel_atomic_state *state,
+                                              enum transcoder transcoder)
+{
+       struct intel_crtc_state *new_crtc_state;
+       struct intel_crtc *crtc;
+       int i;
+
+       for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
+               if (new_crtc_state->cpu_transcoder == transcoder)
+                       return needs_modeset(new_crtc_state);
+
+       return false;
+}
+
+static void
+intel_modeset_synced_crtcs(struct intel_atomic_state *state,
+                          u8 transcoders)
+{
+       struct intel_crtc_state *new_crtc_state;
+       struct intel_crtc *crtc;
+       int i;
+
+       for_each_new_intel_crtc_in_state(state, crtc,
+                                        new_crtc_state, i) {
+               if (transcoders & BIT(new_crtc_state->cpu_transcoder)) {
+                       new_crtc_state->uapi.mode_changed = true;
+                       new_crtc_state->update_pipe = false;
+               }
+       }
+}
+
+static int
+intel_modeset_all_tiles(struct intel_atomic_state *state, int tile_grp_id)
+{
+       struct drm_i915_private *dev_priv = to_i915(state->base.dev);
+       struct drm_connector *connector;
+       struct drm_connector_list_iter conn_iter;
+       int ret = 0;
+
+       drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
+       drm_for_each_connector_iter(connector, &conn_iter) {
+               struct drm_connector_state *conn_state;
+               struct drm_crtc_state *crtc_state;
+
+               if (!connector->has_tile ||
+                   connector->tile_group->id != tile_grp_id)
+                       continue;
+               conn_state = drm_atomic_get_connector_state(&state->base,
+                                                           connector);
+               if (IS_ERR(conn_state)) {
+                       ret =  PTR_ERR(conn_state);
+                       break;
+               }
+
+               if (!conn_state->crtc)
+                       continue;
+
+               crtc_state = drm_atomic_get_crtc_state(&state->base,
+                                                      conn_state->crtc);
+               if (IS_ERR(crtc_state)) {
+                       ret = PTR_ERR(crtc_state);
+                       break;
+               }
+               crtc_state->mode_changed = true;
+               ret = drm_atomic_add_affected_connectors(&state->base,
+                                                        conn_state->crtc);
+               if (ret)
+                       break;
+       }
+       drm_connector_list_iter_end(&conn_iter);
+
+       return ret;
+}
+
+static int
+intel_atomic_check_tiled_conns(struct intel_atomic_state *state)
+{
+       struct drm_i915_private *dev_priv = to_i915(state->base.dev);
+       struct drm_connector *connector;
+       struct drm_connector_state *old_conn_state, *new_conn_state;
+       int i, ret;
+
+       if (INTEL_GEN(dev_priv) < 11)
+               return 0;
+
+       /* Is tiled, mark all other tiled CRTCs as needing a modeset */
+       for_each_oldnew_connector_in_state(&state->base, connector,
+                                          old_conn_state, new_conn_state, i) {
+               if (!connector->has_tile)
+                       continue;
+               if (!intel_connector_needs_modeset(state, connector))
+                       continue;
+
+               ret = intel_modeset_all_tiles(state, connector->tile_group->id);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
 /**
  * intel_atomic_check - validate state object
  * @dev: drm device
@@ -14110,6 +14604,21 @@ static int intel_atomic_check(struct drm_device *dev,
        if (ret)
                goto fail;
 
+       /**
+        * This check adds all the connectors in current state that belong to
+        * the same tile group to a full modeset.
+        * This function directly sets the mode_changed to true and we also call
+        * drm_atomic_add_affected_connectors(). Hence we are not explicitly
+        * calling drm_atomic_helper_check_modeset() after this.
+        *
+        * Fixme: Handle some corner cases where one of the
+        * tiled connectors gets disconnected and tile info is lost but since it
+        * was previously synced to other conn, we need to add that to the modeset.
+        */
+       ret = intel_atomic_check_tiled_conns(state);
+       if (ret)
+               goto fail;
+
        for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
                                            new_crtc_state, i) {
                if (!needs_modeset(new_crtc_state)) {
@@ -14121,8 +14630,6 @@ static int intel_atomic_check(struct drm_device *dev,
 
                if (!new_crtc_state->uapi.enable) {
                        intel_crtc_copy_uapi_to_hw_state(new_crtc_state);
-
-                       any_ms = true;
                        continue;
                }
 
@@ -14135,9 +14642,49 @@ static int intel_atomic_check(struct drm_device *dev,
                        goto fail;
 
                intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
+       }
+
+       /**
+        * Check if fastset is allowed by external dependencies like other
+        * pipes and transcoders.
+        *
+        * Right now it only forces a fullmodeset when the MST master
+        * transcoder did not changed but the pipe of the master transcoder
+        * needs a fullmodeset so all slaves also needs to do a fullmodeset or
+        * in case of port synced crtcs, if one of the synced crtcs
+        * needs a full modeset, all other synced crtcs should be
+        * forced a full modeset.
+        */
+       for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
+               if (!new_crtc_state->hw.enable || needs_modeset(new_crtc_state))
+                       continue;
+
+               if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
+                       enum transcoder master = new_crtc_state->mst_master_transcoder;
+
+                       if (intel_cpu_transcoder_needs_modeset(state, master)) {
+                               new_crtc_state->uapi.mode_changed = true;
+                               new_crtc_state->update_pipe = false;
+                       }
+               } else if (is_trans_port_sync_mode(new_crtc_state)) {
+                       u8 trans = new_crtc_state->sync_mode_slaves_mask |
+                                  BIT(new_crtc_state->master_transcoder);
+
+                       intel_modeset_synced_crtcs(state, trans);
+               }
+       }
 
-               if (needs_modeset(new_crtc_state))
+       for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
+                                           new_crtc_state, i) {
+               if (needs_modeset(new_crtc_state)) {
                        any_ms = true;
+                       continue;
+               }
+
+               if (!new_crtc_state->update_pipe)
+                       continue;
+
+               intel_crtc_copy_fastset(old_crtc_state, new_crtc_state);
        }
 
        if (any_ms && !check_digital_port_conflicts(state)) {
@@ -14259,12 +14806,12 @@ static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
                skl_detach_scalers(new_crtc_state);
 
                if (new_crtc_state->pch_pfit.enabled)
-                       skylake_pfit_enable(new_crtc_state);
+                       skl_pfit_enable(new_crtc_state);
        } else if (HAS_PCH_SPLIT(dev_priv)) {
                if (new_crtc_state->pch_pfit.enabled)
-                       ironlake_pfit_enable(new_crtc_state);
+                       ilk_pfit_enable(new_crtc_state);
                else if (old_crtc_state->pch_pfit.enabled)
-                       ironlake_pfit_disable(old_crtc_state);
+                       ilk_pfit_disable(old_crtc_state);
        }
 
        if (INTEL_GEN(dev_priv) >= 11)
@@ -14406,7 +14953,7 @@ static void intel_commit_modeset_disables(struct intel_atomic_state *state)
        u32 handled = 0;
        int i;
 
-       /* Only disable port sync slaves */
+       /* Only disable port sync and MST slaves */
        for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
                                            new_crtc_state, i) {
                if (!needs_modeset(new_crtc_state))
@@ -14420,7 +14967,8 @@ static void intel_commit_modeset_disables(struct intel_atomic_state *state)
                 * slave CRTCs are disabled first and then master CRTC since
                 * Slave vblanks are masked till Master Vblanks.
                 */
-               if (!is_trans_port_sync_slave(old_crtc_state))
+               if (!is_trans_port_sync_slave(old_crtc_state) &&
+                   !intel_dp_mst_is_slave_trans(old_crtc_state))
                        continue;
 
                intel_pre_plane_update(state, crtc);
@@ -14485,6 +15033,10 @@ static void intel_set_dp_tp_ctl_normal(struct intel_crtc *crtc,
        intel_dp_stop_link_train(intel_dp);
 }
 
+/*
+ * TODO: This is only called from port sync and it is identical to what will be
+ * executed again in intel_update_crtc() over port sync pipes
+ */
 static void intel_post_crtc_enable_updates(struct intel_crtc *crtc,
                                           struct intel_atomic_state *state)
 {
@@ -14570,17 +15122,25 @@ static void skl_commit_modeset_enables(struct intel_atomic_state *state)
        struct drm_i915_private *dev_priv = to_i915(state->base.dev);
        struct intel_crtc *crtc;
        struct intel_crtc_state *old_crtc_state, *new_crtc_state;
-       unsigned int updated = 0;
-       bool progress;
-       int i;
        u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
        u8 required_slices = state->wm_results.ddb.enabled_slices;
        struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
+       const u8 num_pipes = INTEL_NUM_PIPES(dev_priv);
+       u8 update_pipes = 0, modeset_pipes = 0;
+       int i;
+
+       for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
+               if (!new_crtc_state->hw.active)
+                       continue;
 
-       for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
                /* ignore allocations for crtc's that have been turned off. */
-               if (!needs_modeset(new_crtc_state) && new_crtc_state->hw.active)
+               if (!needs_modeset(new_crtc_state)) {
                        entries[i] = old_crtc_state->wm.skl.ddb;
+                       update_pipes |= BIT(crtc->pipe);
+               } else {
+                       modeset_pipes |= BIT(crtc->pipe);
+               }
+       }
 
        /* If 2nd DBuf slice required, enable it here */
        if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
@@ -14589,27 +15149,29 @@ static void skl_commit_modeset_enables(struct intel_atomic_state *state)
        /*
         * Whenever the number of active pipes changes, we need to make sure we
         * update the pipes in the right order so that their ddb allocations
-        * never overlap with eachother inbetween CRTC updates. Otherwise we'll
+        * never overlap with each other between CRTC updates. Otherwise we'll
         * cause pipe underruns and other bad stuff.
+        *
+        * So first lets enable all pipes that do not need a fullmodeset as
+        * those don't have any external dependency.
         */
-       do {
-               progress = false;
-
-               for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
+       while (update_pipes) {
+               for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
+                                                   new_crtc_state, i) {
                        enum pipe pipe = crtc->pipe;
-                       bool vbl_wait = false;
-                       bool modeset = needs_modeset(new_crtc_state);
 
-                       if (updated & BIT(crtc->pipe) || !new_crtc_state->hw.active)
+                       if ((update_pipes & BIT(pipe)) == 0)
                                continue;
 
                        if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
-                                                       entries,
-                                                       INTEL_NUM_PIPES(dev_priv), i))
+                                                       entries, num_pipes, i))
                                continue;
 
-                       updated |= BIT(pipe);
                        entries[i] = new_crtc_state->wm.skl.ddb;
+                       update_pipes &= ~BIT(pipe);
+
+                       intel_update_crtc(crtc, state, old_crtc_state,
+                                         new_crtc_state);
 
                        /*
                         * If this is an already active pipe, it's DDB changed,
@@ -14619,29 +15181,71 @@ static void skl_commit_modeset_enables(struct intel_atomic_state *state)
                         */
                        if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
                                                 &old_crtc_state->wm.skl.ddb) &&
-                           !modeset &&
-                           state->wm_results.dirty_pipes != updated)
-                               vbl_wait = true;
-
-                       if (modeset && is_trans_port_sync_mode(new_crtc_state)) {
-                               if (is_trans_port_sync_master(new_crtc_state))
-                                       intel_update_trans_port_sync_crtcs(crtc,
-                                                                          state,
-                                                                          old_crtc_state,
-                                                                          new_crtc_state);
-                               else
-                                       continue;
-                       } else {
-                               intel_update_crtc(crtc, state, old_crtc_state,
-                                                 new_crtc_state);
-                       }
-
-                       if (vbl_wait)
+                           (update_pipes | modeset_pipes))
                                intel_wait_for_vblank(dev_priv, pipe);
+               }
+       }
 
-                       progress = true;
+       /*
+        * Enable all pipes that needs a modeset and do not depends on other
+        * pipes
+        */
+       for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
+                                           new_crtc_state, i) {
+               enum pipe pipe = crtc->pipe;
+
+               if ((modeset_pipes & BIT(pipe)) == 0)
+                       continue;
+
+               if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
+                   is_trans_port_sync_slave(new_crtc_state))
+                       continue;
+
+               WARN_ON(skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
+                                                   entries, num_pipes, i));
+
+               entries[i] = new_crtc_state->wm.skl.ddb;
+               modeset_pipes &= ~BIT(pipe);
+
+               if (is_trans_port_sync_mode(new_crtc_state)) {
+                       struct intel_crtc *slave_crtc;
+
+                       intel_update_trans_port_sync_crtcs(crtc, state,
+                                                          old_crtc_state,
+                                                          new_crtc_state);
+
+                       slave_crtc = intel_get_slave_crtc(new_crtc_state);
+                       /* TODO: update entries[] of slave */
+                       modeset_pipes &= ~BIT(slave_crtc->pipe);
+
+               } else {
+                       intel_update_crtc(crtc, state, old_crtc_state,
+                                         new_crtc_state);
                }
-       } while (progress);
+       }
+
+       /*
+        * Finally enable all pipes that needs a modeset and depends on
+        * other pipes, right now it is only MST slaves as both port sync slave
+        * and master are enabled together
+        */
+       for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
+                                           new_crtc_state, i) {
+               enum pipe pipe = crtc->pipe;
+
+               if ((modeset_pipes & BIT(pipe)) == 0)
+                       continue;
+
+               WARN_ON(skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
+                                                   entries, num_pipes, i));
+
+               entries[i] = new_crtc_state->wm.skl.ddb;
+               modeset_pipes &= ~BIT(pipe);
+
+               intel_update_crtc(crtc, state, old_crtc_state, new_crtc_state);
+       }
+
+       WARN_ON(modeset_pipes);
 
        /* If 2nd DBuf slice is no more required disable it */
        if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
@@ -15206,7 +15810,7 @@ intel_prepare_plane_fb(struct drm_plane *plane,
                return ret;
 
        fb_obj_bump_render_priority(obj);
-       intel_frontbuffer_flush(obj->frontbuffer, ORIGIN_DIRTYFB);
+       i915_gem_object_flush_frontbuffer(obj, ORIGIN_DIRTYFB);
 
        if (!new_plane_state->uapi.fence) { /* implicit fencing */
                struct dma_fence *fence;
@@ -15715,28 +16319,6 @@ fail:
        return ERR_PTR(ret);
 }
 
-static void intel_crtc_init_scalers(struct intel_crtc *crtc,
-                                   struct intel_crtc_state *crtc_state)
-{
-       struct intel_crtc_scaler_state *scaler_state =
-               &crtc_state->scaler_state;
-       struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
-       int i;
-
-       crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe];
-       if (!crtc->num_scalers)
-               return;
-
-       for (i = 0; i < crtc->num_scalers; i++) {
-               struct intel_scaler *scaler = &scaler_state->scalers[i];
-
-               scaler->in_use = 0;
-               scaler->mode = 0;
-       }
-
-       scaler_state->scaler_id = -1;
-}
-
 #define INTEL_CRTC_FUNCS \
        .gamma_set = drm_atomic_helper_legacy_gamma_set, \
        .set_config = drm_atomic_helper_set_config, \
@@ -15804,33 +16386,53 @@ static const struct drm_crtc_funcs i8xx_crtc_funcs = {
        .disable_vblank = i8xx_disable_vblank,
 };
 
+static struct intel_crtc *intel_crtc_alloc(void)
+{
+       struct intel_crtc_state *crtc_state;
+       struct intel_crtc *crtc;
+
+       crtc = kzalloc(sizeof(*crtc), GFP_KERNEL);
+       if (!crtc)
+               return ERR_PTR(-ENOMEM);
+
+       crtc_state = intel_crtc_state_alloc(crtc);
+       if (!crtc_state) {
+               kfree(crtc);
+               return ERR_PTR(-ENOMEM);
+       }
+
+       crtc->base.state = &crtc_state->uapi;
+       crtc->config = crtc_state;
+
+       return crtc;
+}
+
+static void intel_crtc_free(struct intel_crtc *crtc)
+{
+       intel_crtc_destroy_state(&crtc->base, crtc->base.state);
+       kfree(crtc);
+}
+
 static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
 {
+       struct intel_plane *primary, *cursor;
        const struct drm_crtc_funcs *funcs;
-       struct intel_crtc *intel_crtc;
-       struct intel_crtc_state *crtc_state = NULL;
-       struct intel_plane *primary = NULL;
-       struct intel_plane *cursor = NULL;
+       struct intel_crtc *crtc;
        int sprite, ret;
 
-       intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
-       if (!intel_crtc)
-               return -ENOMEM;
+       crtc = intel_crtc_alloc();
+       if (IS_ERR(crtc))
+               return PTR_ERR(crtc);
 
-       crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
-       if (!crtc_state) {
-               ret = -ENOMEM;
-               goto fail;
-       }
-       __drm_atomic_helper_crtc_reset(&intel_crtc->base, &crtc_state->uapi);
-       intel_crtc->config = crtc_state;
+       crtc->pipe = pipe;
+       crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[pipe];
 
        primary = intel_primary_plane_create(dev_priv, pipe);
        if (IS_ERR(primary)) {
                ret = PTR_ERR(primary);
                goto fail;
        }
-       intel_crtc->plane_ids_mask |= BIT(primary->id);
+       crtc->plane_ids_mask |= BIT(primary->id);
 
        for_each_sprite(dev_priv, pipe, sprite) {
                struct intel_plane *plane;
@@ -15840,7 +16442,7 @@ static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
                        ret = PTR_ERR(plane);
                        goto fail;
                }
-               intel_crtc->plane_ids_mask |= BIT(plane->id);
+               crtc->plane_ids_mask |= BIT(plane->id);
        }
 
        cursor = intel_cursor_plane_create(dev_priv, pipe);
@@ -15848,7 +16450,7 @@ static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
                ret = PTR_ERR(cursor);
                goto fail;
        }
-       intel_crtc->plane_ids_mask |= BIT(cursor->id);
+       crtc->plane_ids_mask |= BIT(cursor->id);
 
        if (HAS_GMCH(dev_priv)) {
                if (IS_CHERRYVIEW(dev_priv) ||
@@ -15869,42 +16471,32 @@ static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
                        funcs = &ilk_crtc_funcs;
        }
 
-       ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
+       ret = drm_crtc_init_with_planes(&dev_priv->drm, &crtc->base,
                                        &primary->base, &cursor->base,
                                        funcs, "pipe %c", pipe_name(pipe));
        if (ret)
                goto fail;
 
-       intel_crtc->pipe = pipe;
-
-       /* initialize shared scalers */
-       intel_crtc_init_scalers(intel_crtc, crtc_state);
-
        BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
               dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
-       dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
+       dev_priv->pipe_to_crtc_mapping[pipe] = crtc;
 
        if (INTEL_GEN(dev_priv) < 9) {
                enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
 
                BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
                       dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
-               dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
+               dev_priv->plane_to_crtc_mapping[i9xx_plane] = crtc;
        }
 
-       intel_color_init(intel_crtc);
+       intel_color_init(crtc);
 
-       WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
+       WARN_ON(drm_crtc_index(&crtc->base) != crtc->pipe);
 
        return 0;
 
 fail:
-       /*
-        * drm_mode_config_cleanup() will free up any
-        * crtcs/planes already initialized.
-        */
-       kfree(crtc_state);
-       kfree(intel_crtc);
+       intel_crtc_free(crtc);
 
        return ret;
 }
@@ -16391,8 +16983,11 @@ static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
        }
 
        /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
-       if (mode_cmd->offsets[0] != 0)
+       if (mode_cmd->offsets[0] != 0) {
+               DRM_DEBUG_KMS("plane 0 offset (0x%08x) must be 0\n",
+                             mode_cmd->offsets[0]);
                goto err;
+       }
 
        drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
 
@@ -16405,26 +17000,23 @@ static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
                }
 
                stride_alignment = intel_fb_stride_alignment(fb, i);
-
-               /*
-                * Display WA #0531: skl,bxt,kbl,glk
-                *
-                * Render decompression and plane width > 3840
-                * combined with horizontal panning requires the
-                * plane stride to be a multiple of 4. We'll just
-                * require the entire fb to accommodate that to avoid
-                * potential runtime errors at plane configuration time.
-                */
-               if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 &&
-                   is_ccs_modifier(fb->modifier))
-                       stride_alignment *= 4;
-
                if (fb->pitches[i] & (stride_alignment - 1)) {
                        DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
                                      i, fb->pitches[i], stride_alignment);
                        goto err;
                }
 
+               if (is_gen12_ccs_plane(fb, i)) {
+                       int ccs_aux_stride = gen12_ccs_aux_stride(fb, i);
+
+                       if (fb->pitches[i] != ccs_aux_stride) {
+                               DRM_DEBUG_KMS("ccs aux plane %d pitch (%d) must be %d\n",
+                                             i,
+                                             fb->pitches[i], ccs_aux_stride);
+                               goto err;
+                       }
+               }
+
                fb->obj[i] = &obj->base;
        }
 
@@ -16622,29 +17214,28 @@ void intel_init_display_hooks(struct drm_i915_private *dev_priv)
        intel_init_cdclk_hooks(dev_priv);
 
        if (INTEL_GEN(dev_priv) >= 9) {
-               dev_priv->display.get_pipe_config = haswell_get_pipe_config;
+               dev_priv->display.get_pipe_config = hsw_get_pipe_config;
                dev_priv->display.get_initial_plane_config =
-                       skylake_get_initial_plane_config;
-               dev_priv->display.crtc_compute_clock =
-                       haswell_crtc_compute_clock;
-               dev_priv->display.crtc_enable = haswell_crtc_enable;
-               dev_priv->display.crtc_disable = haswell_crtc_disable;
+                       skl_get_initial_plane_config;
+               dev_priv->display.crtc_compute_clock = hsw_crtc_compute_clock;
+               dev_priv->display.crtc_enable = hsw_crtc_enable;
+               dev_priv->display.crtc_disable = hsw_crtc_disable;
        } else if (HAS_DDI(dev_priv)) {
-               dev_priv->display.get_pipe_config = haswell_get_pipe_config;
+               dev_priv->display.get_pipe_config = hsw_get_pipe_config;
                dev_priv->display.get_initial_plane_config =
                        i9xx_get_initial_plane_config;
                dev_priv->display.crtc_compute_clock =
-                       haswell_crtc_compute_clock;
-               dev_priv->display.crtc_enable = haswell_crtc_enable;
-               dev_priv->display.crtc_disable = haswell_crtc_disable;
+                       hsw_crtc_compute_clock;
+               dev_priv->display.crtc_enable = hsw_crtc_enable;
+               dev_priv->display.crtc_disable = hsw_crtc_disable;
        } else if (HAS_PCH_SPLIT(dev_priv)) {
-               dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
+               dev_priv->display.get_pipe_config = ilk_get_pipe_config;
                dev_priv->display.get_initial_plane_config =
                        i9xx_get_initial_plane_config;
                dev_priv->display.crtc_compute_clock =
-                       ironlake_crtc_compute_clock;
-               dev_priv->display.crtc_enable = ironlake_crtc_enable;
-               dev_priv->display.crtc_disable = ironlake_crtc_disable;
+                       ilk_crtc_compute_clock;
+               dev_priv->display.crtc_enable = ilk_crtc_enable;
+               dev_priv->display.crtc_disable = ilk_crtc_disable;
        } else if (IS_CHERRYVIEW(dev_priv)) {
                dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
                dev_priv->display.get_initial_plane_config =
@@ -16690,14 +17281,12 @@ void intel_init_display_hooks(struct drm_i915_private *dev_priv)
        }
 
        if (IS_GEN(dev_priv, 5)) {
-               dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
+               dev_priv->display.fdi_link_train = ilk_fdi_link_train;
        } else if (IS_GEN(dev_priv, 6)) {
                dev_priv->display.fdi_link_train = gen6_fdi_link_train;
        } else if (IS_IVYBRIDGE(dev_priv)) {
                /* FIXME: detect B0+ stepping and use auto training */
                dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
-       } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
-               dev_priv->display.fdi_link_train = hsw_fdi_link_train;
        }
 
        if (INTEL_GEN(dev_priv) >= 9)
@@ -17430,8 +18019,7 @@ static void intel_modeset_readout_hw_state(struct drm_device *dev)
 
                __drm_atomic_helper_crtc_destroy_state(&crtc_state->uapi);
                intel_crtc_free_hw_state(crtc_state);
-               memset(crtc_state, 0, sizeof(*crtc_state));
-               __drm_atomic_helper_crtc_reset(&crtc->base, &crtc_state->uapi);
+               intel_crtc_state_reset(crtc_state, crtc);
 
                crtc_state->hw.active = crtc_state->hw.enable =
                        dev_priv->display.get_pipe_config(crtc, crtc_state);
@@ -17638,8 +18226,11 @@ get_encoder_power_domains(struct drm_i915_private *dev_priv)
 
 static void intel_early_display_was(struct drm_i915_private *dev_priv)
 {
-       /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
-       if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
+       /*
+        * Display WA #1185 WaDisableDARBFClkGating:cnl,glk,icl,ehl,tgl
+        * Also known as Wa_14010480278.
+        */
+       if (IS_GEN_RANGE(dev_priv, 10, 12) || IS_GEMINILAKE(dev_priv))
                I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
                           DARBF_GATING_DIS);
 
@@ -17768,7 +18359,7 @@ intel_modeset_setup_hw_state(struct drm_device *dev,
 
        for_each_intel_crtc(&dev_priv->drm, crtc) {
                struct intel_crtc_state *crtc_state =
-                       crtc_state = to_intel_crtc_state(crtc->base.state);
+                       to_intel_crtc_state(crtc->base.state);
 
                intel_sanitize_crtc(crtc, ctx);
                intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]");
@@ -17812,8 +18403,6 @@ intel_modeset_setup_hw_state(struct drm_device *dev,
        }
 
        intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
-
-       intel_fbc_init_pipe_state(dev_priv);
 }
 
 void intel_display_resume(struct drm_device *dev)
@@ -17914,6 +18503,8 @@ void intel_modeset_driver_remove(struct drm_i915_private *i915)
 
        intel_gmbus_teardown(i915);
 
+       intel_bw_cleanup(i915);
+
        destroy_workqueue(i915->flip_wq);
        destroy_workqueue(i915->modeset_wq);