drm/i915/skl: Restrict the ring frequency table programming to SKL
[linux-2.6-block.git] / drivers / gpu / drm / i915 / intel_display.c
index df6f6adc7881d05736bea3870090bd4cdf71508e..00c60c1c5162eff6bab32df1ed4306efecdd53c3 100644 (file)
@@ -409,7 +409,7 @@ static const intel_limit_t intel_limits_chv = {
 static const intel_limit_t intel_limits_bxt = {
        /* FIXME: find real dot limits */
        .dot = { .min = 0, .max = INT_MAX },
-       .vco = { .min = 4800000, .max = 6480000 },
+       .vco = { .min = 4800000, .max = 6700000 },
        .n = { .min = 1, .max = 1 },
        .m1 = { .min = 2, .max = 2 },
        /* FIXME: find real m2 limits */
@@ -418,16 +418,6 @@ static const intel_limit_t intel_limits_bxt = {
        .p2 = { .p2_slow = 1, .p2_fast = 20 },
 };
 
-static void vlv_clock(int refclk, intel_clock_t *clock)
-{
-       clock->m = clock->m1 * clock->m2;
-       clock->p = clock->p1 * clock->p2;
-       if (WARN_ON(clock->n == 0 || clock->p == 0))
-               return;
-       clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
-       clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
-}
-
 static bool
 needs_modeset(struct drm_crtc_state *state)
 {
@@ -563,15 +553,25 @@ intel_limit(struct intel_crtc_state *crtc_state, int refclk)
        return limit;
 }
 
+/*
+ * Platform specific helpers to calculate the port PLL loopback- (clock.m),
+ * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
+ * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
+ * The helpers' return value is the rate of the clock that is fed to the
+ * display engine's pipe which can be the above fast dot clock rate or a
+ * divided-down version of it.
+ */
 /* m1 is reserved as 0 in Pineview, n is a ring counter */
-static void pineview_clock(int refclk, intel_clock_t *clock)
+static int pnv_calc_dpll_params(int refclk, intel_clock_t *clock)
 {
        clock->m = clock->m2 + 2;
        clock->p = clock->p1 * clock->p2;
        if (WARN_ON(clock->n == 0 || clock->p == 0))
-               return;
+               return 0;
        clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
        clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
+
+       return clock->dot;
 }
 
 static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
@@ -579,25 +579,41 @@ static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
        return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
 }
 
-static void i9xx_clock(int refclk, intel_clock_t *clock)
+static int i9xx_calc_dpll_params(int refclk, intel_clock_t *clock)
 {
        clock->m = i9xx_dpll_compute_m(clock);
        clock->p = clock->p1 * clock->p2;
        if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
-               return;
+               return 0;
        clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
        clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
+
+       return clock->dot;
 }
 
-static void chv_clock(int refclk, intel_clock_t *clock)
+static int vlv_calc_dpll_params(int refclk, intel_clock_t *clock)
 {
        clock->m = clock->m1 * clock->m2;
        clock->p = clock->p1 * clock->p2;
        if (WARN_ON(clock->n == 0 || clock->p == 0))
-               return;
+               return 0;
+       clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
+       clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
+
+       return clock->dot / 5;
+}
+
+int chv_calc_dpll_params(int refclk, intel_clock_t *clock)
+{
+       clock->m = clock->m1 * clock->m2;
+       clock->p = clock->p1 * clock->p2;
+       if (WARN_ON(clock->n == 0 || clock->p == 0))
+               return 0;
        clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
                        clock->n << 22);
        clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
+
+       return clock->dot / 5;
 }
 
 #define INTELPllInvalid(s)   do { /* DRM_DEBUG(s); */ return false; } while (0)
@@ -692,7 +708,7 @@ i9xx_find_best_dpll(const intel_limit_t *limit,
                                        clock.p1 <= limit->p1.max; clock.p1++) {
                                        int this_err;
 
-                                       i9xx_clock(refclk, &clock);
+                                       i9xx_calc_dpll_params(refclk, &clock);
                                        if (!intel_PLL_is_valid(dev, limit,
                                                                &clock))
                                                continue;
@@ -737,7 +753,7 @@ pnv_find_best_dpll(const intel_limit_t *limit,
                                        clock.p1 <= limit->p1.max; clock.p1++) {
                                        int this_err;
 
-                                       pineview_clock(refclk, &clock);
+                                       pnv_calc_dpll_params(refclk, &clock);
                                        if (!intel_PLL_is_valid(dev, limit,
                                                                &clock))
                                                continue;
@@ -787,7 +803,7 @@ g4x_find_best_dpll(const intel_limit_t *limit,
                                     clock.p1 >= limit->p1.min; clock.p1--) {
                                        int this_err;
 
-                                       i9xx_clock(refclk, &clock);
+                                       i9xx_calc_dpll_params(refclk, &clock);
                                        if (!intel_PLL_is_valid(dev, limit,
                                                                &clock))
                                                continue;
@@ -877,7 +893,7 @@ vlv_find_best_dpll(const intel_limit_t *limit,
                                        clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
                                                                     refclk * clock.m1);
 
-                                       vlv_clock(refclk, &clock);
+                                       vlv_calc_dpll_params(refclk, &clock);
 
                                        if (!intel_PLL_is_valid(dev, limit,
                                                                &clock))
@@ -940,7 +956,7 @@ chv_find_best_dpll(const intel_limit_t *limit,
 
                        clock.m2 = m2;
 
-                       chv_clock(refclk, &clock);
+                       chv_calc_dpll_params(refclk, &clock);
 
                        if (!intel_PLL_is_valid(dev, limit, &clock))
                                continue;
@@ -1010,7 +1026,7 @@ static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe)
                line_mask = DSL_LINEMASK_GEN3;
 
        line1 = I915_READ(reg) & line_mask;
-       mdelay(5);
+       msleep(5);
        line2 = I915_READ(reg) & line_mask;
 
        return line1 == line2;
@@ -1774,13 +1790,13 @@ static void i9xx_disable_pll(struct intel_crtc *crtc)
        /* Make sure the pipe isn't still relying on us */
        assert_pipe_disabled(dev_priv, pipe);
 
-       I915_WRITE(DPLL(pipe), 0);
+       I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
        POSTING_READ(DPLL(pipe));
 }
 
 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
 {
-       u32 val = 0;
+       u32 val;
 
        /* Make sure the pipe isn't still relying on us */
        assert_pipe_disabled(dev_priv, pipe);
@@ -1789,8 +1805,9 @@ static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
         * Leave integrated clock source and reference clock enabled for pipe B.
         * The latter is needed for VGA hotplug / manual detection.
         */
+       val = DPLL_VGA_MODE_DIS;
        if (pipe == PIPE_B)
-               val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV;
+               val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REF_CLK_ENABLE_VLV;
        I915_WRITE(DPLL(pipe), val);
        POSTING_READ(DPLL(pipe));
 
@@ -1805,7 +1822,8 @@ static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
        assert_pipe_disabled(dev_priv, pipe);
 
        /* Set PLL en = 0 */
-       val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV;
+       val = DPLL_SSC_REF_CLK_CHV |
+               DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
        if (pipe != PIPE_A)
                val |= DPLL_INTEGRATED_CRI_CLK_VLV;
        I915_WRITE(DPLL(pipe), val);
@@ -2110,6 +2128,8 @@ static void intel_enable_pipe(struct intel_crtc *crtc)
        int reg;
        u32 val;
 
+       DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
+
        assert_planes_disabled(dev_priv, pipe);
        assert_cursor_disabled(dev_priv, pipe);
        assert_sprites_disabled(dev_priv, pipe);
@@ -2169,6 +2189,8 @@ static void intel_disable_pipe(struct intel_crtc *crtc)
        int reg;
        u32 val;
 
+       DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
+
        /*
         * Make sure planes won't keep trying to pump pixels to us,
         * or we might hang the display.
@@ -2268,6 +2290,7 @@ intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb,
                        const struct drm_plane_state *plane_state)
 {
        struct intel_rotation_info *info = &view->rotation_info;
+       unsigned int tile_height, tile_pitch;
 
        *view = i915_ggtt_view_normal;
 
@@ -2284,6 +2307,13 @@ intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb,
        info->pitch = fb->pitches[0];
        info->fb_modifier = fb->modifier[0];
 
+       tile_height = intel_tile_height(fb->dev, fb->pixel_format,
+                                       fb->modifier[0]);
+       tile_pitch = PAGE_SIZE / tile_height;
+       info->width_pages = DIV_ROUND_UP(fb->pitches[0], tile_pitch);
+       info->height_pages = DIV_ROUND_UP(fb->height, tile_height);
+       info->size = info->width_pages * info->height_pages * PAGE_SIZE;
+
        return 0;
 }
 
@@ -2304,7 +2334,8 @@ int
 intel_pin_and_fence_fb_obj(struct drm_plane *plane,
                           struct drm_framebuffer *fb,
                           const struct drm_plane_state *plane_state,
-                          struct intel_engine_cs *pipelined)
+                          struct intel_engine_cs *pipelined,
+                          struct drm_i915_gem_request **pipelined_request)
 {
        struct drm_device *dev = fb->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -2362,7 +2393,7 @@ intel_pin_and_fence_fb_obj(struct drm_plane *plane,
 
        dev_priv->mm.interruptible = false;
        ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined,
-                                                  &view);
+                                                  pipelined_request, &view);
        if (ret)
                goto err_interruptible;
 
@@ -2604,7 +2635,7 @@ valid_fb:
        primary->crtc = primary->state->crtc = &intel_crtc->base;
        update_state_fb(primary);
        intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary));
-       obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
+       obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit;
 }
 
 static void i9xx_update_primary_plane(struct drm_crtc *crtc,
@@ -3105,8 +3136,8 @@ intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
 
-       if (dev_priv->display.disable_fbc)
-               dev_priv->display.disable_fbc(dev);
+       if (dev_priv->fbc.disable_fbc)
+               dev_priv->fbc.disable_fbc(dev_priv);
 
        dev_priv->display.update_primary_plane(crtc, fb, x, y);
 
@@ -4351,7 +4382,7 @@ int skl_update_scaler_crtc(struct intel_crtc_state *state, int force_detach)
        return skl_update_scaler(state, force_detach, SKL_CRTC_INDEX,
                &state->scaler_state.scaler_id, DRM_ROTATE_0,
                state->pipe_src_w, state->pipe_src_h,
-               adjusted_mode->hdisplay, adjusted_mode->hdisplay);
+               adjusted_mode->hdisplay, adjusted_mode->vdisplay);
 }
 
 /**
@@ -4686,8 +4717,11 @@ intel_pre_disable_primary(struct drm_crtc *crtc)
         * event which is after the vblank start event, so we need to have a
         * wait-for-vblank between disabling the plane and the pipe.
         */
-       if (HAS_GMCH_DISPLAY(dev))
+       if (HAS_GMCH_DISPLAY(dev)) {
                intel_set_memory_cxsr(dev_priv, false);
+               dev_priv->wm.vlv.cxsr = false;
+               intel_wait_for_vblank(dev, pipe);
+       }
 
        /*
         * FIXME IPS should be fine as long as one plane is
@@ -4702,6 +4736,7 @@ static void intel_post_plane_update(struct intel_crtc *crtc)
 {
        struct intel_crtc_atomic_commit *atomic = &crtc->atomic;
        struct drm_device *dev = crtc->base.dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
        struct drm_plane *plane;
 
        if (atomic->wait_vblank)
@@ -4709,11 +4744,14 @@ static void intel_post_plane_update(struct intel_crtc *crtc)
 
        intel_frontbuffer_flip(dev, atomic->fb_bits);
 
-       if (atomic->update_fbc) {
-               mutex_lock(&dev->struct_mutex);
-               intel_fbc_update(dev);
-               mutex_unlock(&dev->struct_mutex);
-       }
+       if (atomic->disable_cxsr)
+               crtc->wm.cxsr_allowed = true;
+
+       if (crtc->atomic.update_wm_post)
+               intel_update_watermarks(&crtc->base);
+
+       if (atomic->update_fbc)
+               intel_fbc_update(dev_priv);
 
        if (atomic->post_enable_primary)
                intel_post_enable_primary(&crtc->base);
@@ -4733,41 +4771,31 @@ static void intel_pre_plane_update(struct intel_crtc *crtc)
        struct drm_plane *p;
 
        /* Track fb's for any planes being disabled */
-
        drm_for_each_plane_mask(p, dev, atomic->disabled_planes) {
                struct intel_plane *plane = to_intel_plane(p);
-               unsigned fb_bits = 0;
-
-               switch (p->type) {
-               case DRM_PLANE_TYPE_PRIMARY:
-                       fb_bits = INTEL_FRONTBUFFER_PRIMARY(plane->pipe);
-                       break;
-               case DRM_PLANE_TYPE_CURSOR:
-                       fb_bits = INTEL_FRONTBUFFER_CURSOR(plane->pipe);
-                       break;
-               case DRM_PLANE_TYPE_OVERLAY:
-                       fb_bits = INTEL_FRONTBUFFER_SPRITE(plane->pipe);
-                       break;
-               }
 
                mutex_lock(&dev->struct_mutex);
-               i915_gem_track_fb(intel_fb_obj(plane->base.fb), NULL, fb_bits);
+               i915_gem_track_fb(intel_fb_obj(plane->base.fb), NULL,
+                                 plane->frontbuffer_bit);
                mutex_unlock(&dev->struct_mutex);
        }
 
        if (atomic->wait_for_flips)
                intel_crtc_wait_for_pending_flips(&crtc->base);
 
-       if (atomic->disable_fbc &&
-           dev_priv->fbc.crtc == crtc) {
-               mutex_lock(&dev->struct_mutex);
-               if (dev_priv->fbc.crtc == crtc)
-                       intel_fbc_disable(dev);
-               mutex_unlock(&dev->struct_mutex);
-       }
+       if (atomic->disable_fbc)
+               intel_fbc_disable_crtc(crtc);
+
+       if (crtc->atomic.disable_ips)
+               hsw_disable_ips(crtc);
 
        if (atomic->pre_disable_primary)
                intel_pre_disable_primary(&crtc->base);
+
+       if (atomic->disable_cxsr) {
+               crtc->wm.cxsr_allowed = false;
+               intel_set_memory_cxsr(dev_priv, false);
+       }
 }
 
 static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask)
@@ -5021,6 +5049,9 @@ static void ironlake_crtc_disable(struct drm_crtc *crtc)
 
                ironlake_fdi_pll_disable(intel_crtc);
        }
+
+       intel_crtc->active = false;
+       intel_update_watermarks(crtc);
 }
 
 static void haswell_crtc_disable(struct drm_crtc *crtc)
@@ -5066,6 +5097,9 @@ static void haswell_crtc_disable(struct drm_crtc *crtc)
        for_each_encoder_on_crtc(dev, crtc, encoder)
                if (encoder->post_disable)
                        encoder->post_disable(encoder);
+
+       intel_crtc->active = false;
+       intel_update_watermarks(crtc);
 }
 
 static void i9xx_pfit_enable(struct intel_crtc *crtc)
@@ -6011,7 +6045,6 @@ static void valleyview_crtc_enable(struct drm_crtc *crtc)
 
        intel_crtc_load_lut(crtc);
 
-       intel_update_watermarks(crtc);
        intel_enable_pipe(intel_crtc);
 
        assert_vblank_disabled(crtc);
@@ -6131,6 +6164,9 @@ static void i9xx_crtc_disable(struct drm_crtc *crtc)
 
        if (!IS_GEN2(dev))
                intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
+
+       intel_crtc->active = false;
+       intel_update_watermarks(crtc);
 }
 
 static void intel_crtc_disable_noatomic(struct drm_crtc *crtc)
@@ -6615,6 +6651,34 @@ static int skylake_get_display_clock_speed(struct drm_device *dev)
        return 24000;
 }
 
+static int broxton_get_display_clock_speed(struct drm_device *dev)
+{
+       struct drm_i915_private *dev_priv = to_i915(dev);
+       uint32_t cdctl = I915_READ(CDCLK_CTL);
+       uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK;
+       uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE);
+       int cdclk;
+
+       if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE))
+               return 19200;
+
+       cdclk = 19200 * pll_ratio / 2;
+
+       switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) {
+       case BXT_CDCLK_CD2X_DIV_SEL_1:
+               return cdclk;  /* 576MHz or 624MHz */
+       case BXT_CDCLK_CD2X_DIV_SEL_1_5:
+               return cdclk * 2 / 3; /* 384MHz */
+       case BXT_CDCLK_CD2X_DIV_SEL_2:
+               return cdclk / 2; /* 288MHz */
+       case BXT_CDCLK_CD2X_DIV_SEL_4:
+               return cdclk / 4; /* 144MHz */
+       }
+
+       /* error case, do as if DE PLL isn't enabled */
+       return 19200;
+}
+
 static int broadwell_get_display_clock_speed(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -7159,8 +7223,8 @@ void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n)
                intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2);
 }
 
-static void vlv_update_pll(struct intel_crtc *crtc,
-                          struct intel_crtc_state *pipe_config)
+static void vlv_compute_dpll(struct intel_crtc *crtc,
+                            struct intel_crtc_state *pipe_config)
 {
        u32 dpll, dpll_md;
 
@@ -7169,8 +7233,8 @@ static void vlv_update_pll(struct intel_crtc *crtc,
         * clock for pipe B, since VGA hotplug / manual detection depends
         * on it.
         */
-       dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV |
-               DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV;
+       dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REF_CLK_ENABLE_VLV |
+               DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_REF_CLK_VLV;
        /* We should never disable this, set it here for state tracking */
        if (crtc->pipe == PIPE_B)
                dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
@@ -7273,11 +7337,11 @@ static void vlv_prepare_pll(struct intel_crtc *crtc,
        mutex_unlock(&dev_priv->sb_lock);
 }
 
-static void chv_update_pll(struct intel_crtc *crtc,
-                          struct intel_crtc_state *pipe_config)
+static void chv_compute_dpll(struct intel_crtc *crtc,
+                            struct intel_crtc_state *pipe_config)
 {
-       pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV |
-               DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
+       pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
+               DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
                DPLL_VCO_ENABLE;
        if (crtc->pipe != PIPE_A)
                pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
@@ -7413,11 +7477,11 @@ void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe,
        };
 
        if (IS_CHERRYVIEW(dev)) {
-               chv_update_pll(crtc, &pipe_config);
+               chv_compute_dpll(crtc, &pipe_config);
                chv_prepare_pll(crtc, &pipe_config);
                chv_enable_pll(crtc, &pipe_config);
        } else {
-               vlv_update_pll(crtc, &pipe_config);
+               vlv_compute_dpll(crtc, &pipe_config);
                vlv_prepare_pll(crtc, &pipe_config);
                vlv_enable_pll(crtc, &pipe_config);
        }
@@ -7439,10 +7503,10 @@ void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe)
                vlv_disable_pll(to_i915(dev), pipe);
 }
 
-static void i9xx_update_pll(struct intel_crtc *crtc,
-                           struct intel_crtc_state *crtc_state,
-                           intel_clock_t *reduced_clock,
-                           int num_connectors)
+static void i9xx_compute_dpll(struct intel_crtc *crtc,
+                             struct intel_crtc_state *crtc_state,
+                             intel_clock_t *reduced_clock,
+                             int num_connectors)
 {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -7516,10 +7580,10 @@ static void i9xx_update_pll(struct intel_crtc *crtc,
        }
 }
 
-static void i8xx_update_pll(struct intel_crtc *crtc,
-                           struct intel_crtc_state *crtc_state,
-                           intel_clock_t *reduced_clock,
-                           int num_connectors)
+static void i8xx_compute_dpll(struct intel_crtc *crtc,
+                             struct intel_crtc_state *crtc_state,
+                             intel_clock_t *reduced_clock,
+                             int num_connectors)
 {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -7753,9 +7817,9 @@ static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
        int refclk, num_connectors = 0;
-       intel_clock_t clock, reduced_clock;
-       bool ok, has_reduced_clock = false;
-       bool is_lvds = false, is_dsi = false;
+       intel_clock_t clock;
+       bool ok;
+       bool is_dsi = false;
        struct intel_encoder *encoder;
        const intel_limit_t *limit;
        struct drm_atomic_state *state = crtc_state->base.state;
@@ -7773,9 +7837,6 @@ static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
                encoder = to_intel_encoder(connector_state->best_encoder);
 
                switch (encoder->type) {
-               case INTEL_OUTPUT_LVDS:
-                       is_lvds = true;
-                       break;
                case INTEL_OUTPUT_DSI:
                        is_dsi = true;
                        break;
@@ -7807,19 +7868,6 @@ static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
                        return -EINVAL;
                }
 
-               if (is_lvds && dev_priv->lvds_downclock_avail) {
-                       /*
-                        * Ensure we match the reduced clock's P to the target
-                        * clock.  If the clocks don't match, we can't switch
-                        * the display clock by using the FP0/FP1. In such case
-                        * we will disable the LVDS downclock feature.
-                        */
-                       has_reduced_clock =
-                               dev_priv->display.find_dpll(limit, crtc_state,
-                                                           dev_priv->lvds_downclock,
-                                                           refclk, &clock,
-                                                           &reduced_clock);
-               }
                /* Compat-code for transition, will disappear. */
                crtc_state->dpll.n = clock.n;
                crtc_state->dpll.m1 = clock.m1;
@@ -7829,17 +7877,15 @@ static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
        }
 
        if (IS_GEN2(dev)) {
-               i8xx_update_pll(crtc, crtc_state,
-                               has_reduced_clock ? &reduced_clock : NULL,
-                               num_connectors);
+               i8xx_compute_dpll(crtc, crtc_state, NULL,
+                                 num_connectors);
        } else if (IS_CHERRYVIEW(dev)) {
-               chv_update_pll(crtc, crtc_state);
+               chv_compute_dpll(crtc, crtc_state);
        } else if (IS_VALLEYVIEW(dev)) {
-               vlv_update_pll(crtc, crtc_state);
+               vlv_compute_dpll(crtc, crtc_state);
        } else {
-               i9xx_update_pll(crtc, crtc_state,
-                               has_reduced_clock ? &reduced_clock : NULL,
-                               num_connectors);
+               i9xx_compute_dpll(crtc, crtc_state, NULL,
+                                 num_connectors);
        }
 
        return 0;
@@ -7899,10 +7945,7 @@ static void vlv_crtc_clock_get(struct intel_crtc *crtc,
        clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
        clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
 
-       vlv_clock(refclk, &clock);
-
-       /* clock.dot is the fast clock */
-       pipe_config->port_clock = clock.dot / 5;
+       pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
 }
 
 static void
@@ -7998,10 +8041,7 @@ static void chv_crtc_clock_get(struct intel_crtc *crtc,
        clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
        clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
 
-       chv_clock(refclk, &clock);
-
-       /* clock.dot is the fast clock */
-       pipe_config->port_clock = clock.dot / 5;
+       pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
 }
 
 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
@@ -8650,9 +8690,7 @@ static bool ironlake_compute_clocks(struct drm_crtc *crtc,
        struct drm_i915_private *dev_priv = dev->dev_private;
        int refclk;
        const intel_limit_t *limit;
-       bool ret, is_lvds = false;
-
-       is_lvds = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS);
+       bool ret;
 
        refclk = ironlake_get_refclk(crtc_state);
 
@@ -8668,20 +8706,6 @@ static bool ironlake_compute_clocks(struct drm_crtc *crtc,
        if (!ret)
                return false;
 
-       if (is_lvds && dev_priv->lvds_downclock_avail) {
-               /*
-                * Ensure we match the reduced clock's P to the target clock.
-                * If the clocks don't match, we can't switch the display clock
-                * by using the FP0/FP1. In such case we will disable the LVDS
-                * downclock feature.
-               */
-               *has_reduced_clock =
-                       dev_priv->display.find_dpll(limit, crtc_state,
-                                                   dev_priv->lvds_downclock,
-                                                   refclk, clock,
-                                                   reduced_clock);
-       }
-
        return true;
 }
 
@@ -10454,6 +10478,7 @@ static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
        u32 dpll = pipe_config->dpll_hw_state.dpll;
        u32 fp;
        intel_clock_t clock;
+       int port_clock;
        int refclk = i9xx_pll_refclk(dev, pipe_config);
 
        if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
@@ -10494,9 +10519,9 @@ static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
                }
 
                if (IS_PINEVIEW(dev))
-                       pineview_clock(refclk, &clock);
+                       port_clock = pnv_calc_dpll_params(refclk, &clock);
                else
-                       i9xx_clock(refclk, &clock);
+                       port_clock = i9xx_calc_dpll_params(refclk, &clock);
        } else {
                u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
                bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
@@ -10522,7 +10547,7 @@ static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
                                clock.p2 = 2;
                }
 
-               i9xx_clock(refclk, &clock);
+               port_clock = i9xx_calc_dpll_params(refclk, &clock);
        }
 
        /*
@@ -10530,7 +10555,7 @@ static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
         * port_clock to compute adjusted_mode.crtc_clock in the
         * encoder's get_config() function.
         */
-       pipe_config->port_clock = clock.dot;
+       pipe_config->port_clock = port_clock;
 }
 
 int intel_dotclock_calculate(int link_freq,
@@ -10619,42 +10644,6 @@ struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
        return mode;
 }
 
-static void intel_decrease_pllclock(struct drm_crtc *crtc)
-{
-       struct drm_device *dev = crtc->dev;
-       struct drm_i915_private *dev_priv = dev->dev_private;
-       struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-
-       if (!HAS_GMCH_DISPLAY(dev))
-               return;
-
-       if (!dev_priv->lvds_downclock_avail)
-               return;
-
-       /*
-        * Since this is called by a timer, we should never get here in
-        * the manual case.
-        */
-       if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
-               int pipe = intel_crtc->pipe;
-               int dpll_reg = DPLL(pipe);
-               int dpll;
-
-               DRM_DEBUG_DRIVER("downclocking LVDS\n");
-
-               assert_panel_unlocked(dev_priv, pipe);
-
-               dpll = I915_READ(dpll_reg);
-               dpll |= DISPLAY_RATE_SELECT_FPA1;
-               I915_WRITE(dpll_reg, dpll);
-               intel_wait_for_vblank(dev, pipe);
-               dpll = I915_READ(dpll_reg);
-               if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
-                       DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
-       }
-
-}
-
 void intel_mark_busy(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -10672,20 +10661,12 @@ void intel_mark_busy(struct drm_device *dev)
 void intel_mark_idle(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = dev->dev_private;
-       struct drm_crtc *crtc;
 
        if (!dev_priv->mm.busy)
                return;
 
        dev_priv->mm.busy = false;
 
-       for_each_crtc(dev, crtc) {
-               if (!crtc->primary->fb)
-                       continue;
-
-               intel_decrease_pllclock(crtc);
-       }
-
        if (INTEL_INFO(dev)->gen >= 6)
                gen6_rps_idle(dev->dev_private);
 
@@ -10717,24 +10698,26 @@ static void intel_unpin_work_fn(struct work_struct *__work)
 {
        struct intel_unpin_work *work =
                container_of(__work, struct intel_unpin_work, work);
-       struct drm_device *dev = work->crtc->dev;
-       enum pipe pipe = to_intel_crtc(work->crtc)->pipe;
+       struct intel_crtc *crtc = to_intel_crtc(work->crtc);
+       struct drm_device *dev = crtc->base.dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct drm_plane *primary = crtc->base.primary;
 
        mutex_lock(&dev->struct_mutex);
-       intel_unpin_fb_obj(work->old_fb, work->crtc->primary->state);
+       intel_unpin_fb_obj(work->old_fb, primary->state);
        drm_gem_object_unreference(&work->pending_flip_obj->base);
 
-       intel_fbc_update(dev);
+       intel_fbc_update(dev_priv);
 
        if (work->flip_queued_req)
                i915_gem_request_assign(&work->flip_queued_req, NULL);
        mutex_unlock(&dev->struct_mutex);
 
-       intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
+       intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit);
        drm_framebuffer_unreference(work->old_fb);
 
-       BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
-       atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
+       BUG_ON(atomic_read(&crtc->unpin_work_count) == 0);
+       atomic_dec(&crtc->unpin_work_count);
 
        kfree(work);
 }
@@ -10867,14 +10850,15 @@ static int intel_gen2_queue_flip(struct drm_device *dev,
                                 struct drm_crtc *crtc,
                                 struct drm_framebuffer *fb,
                                 struct drm_i915_gem_object *obj,
-                                struct intel_engine_cs *ring,
+                                struct drm_i915_gem_request *req,
                                 uint32_t flags)
 {
+       struct intel_engine_cs *ring = req->ring;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        u32 flip_mask;
        int ret;
 
-       ret = intel_ring_begin(ring, 6);
+       ret = intel_ring_begin(req, 6);
        if (ret)
                return ret;
 
@@ -10894,7 +10878,6 @@ static int intel_gen2_queue_flip(struct drm_device *dev,
        intel_ring_emit(ring, 0); /* aux display base address, unused */
 
        intel_mark_page_flip_active(intel_crtc);
-       __intel_ring_advance(ring);
        return 0;
 }
 
@@ -10902,14 +10885,15 @@ static int intel_gen3_queue_flip(struct drm_device *dev,
                                 struct drm_crtc *crtc,
                                 struct drm_framebuffer *fb,
                                 struct drm_i915_gem_object *obj,
-                                struct intel_engine_cs *ring,
+                                struct drm_i915_gem_request *req,
                                 uint32_t flags)
 {
+       struct intel_engine_cs *ring = req->ring;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        u32 flip_mask;
        int ret;
 
-       ret = intel_ring_begin(ring, 6);
+       ret = intel_ring_begin(req, 6);
        if (ret)
                return ret;
 
@@ -10926,7 +10910,6 @@ static int intel_gen3_queue_flip(struct drm_device *dev,
        intel_ring_emit(ring, MI_NOOP);
 
        intel_mark_page_flip_active(intel_crtc);
-       __intel_ring_advance(ring);
        return 0;
 }
 
@@ -10934,15 +10917,16 @@ static int intel_gen4_queue_flip(struct drm_device *dev,
                                 struct drm_crtc *crtc,
                                 struct drm_framebuffer *fb,
                                 struct drm_i915_gem_object *obj,
-                                struct intel_engine_cs *ring,
+                                struct drm_i915_gem_request *req,
                                 uint32_t flags)
 {
+       struct intel_engine_cs *ring = req->ring;
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        uint32_t pf, pipesrc;
        int ret;
 
-       ret = intel_ring_begin(ring, 4);
+       ret = intel_ring_begin(req, 4);
        if (ret)
                return ret;
 
@@ -10965,7 +10949,6 @@ static int intel_gen4_queue_flip(struct drm_device *dev,
        intel_ring_emit(ring, pf | pipesrc);
 
        intel_mark_page_flip_active(intel_crtc);
-       __intel_ring_advance(ring);
        return 0;
 }
 
@@ -10973,15 +10956,16 @@ static int intel_gen6_queue_flip(struct drm_device *dev,
                                 struct drm_crtc *crtc,
                                 struct drm_framebuffer *fb,
                                 struct drm_i915_gem_object *obj,
-                                struct intel_engine_cs *ring,
+                                struct drm_i915_gem_request *req,
                                 uint32_t flags)
 {
+       struct intel_engine_cs *ring = req->ring;
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        uint32_t pf, pipesrc;
        int ret;
 
-       ret = intel_ring_begin(ring, 4);
+       ret = intel_ring_begin(req, 4);
        if (ret)
                return ret;
 
@@ -11001,7 +10985,6 @@ static int intel_gen6_queue_flip(struct drm_device *dev,
        intel_ring_emit(ring, pf | pipesrc);
 
        intel_mark_page_flip_active(intel_crtc);
-       __intel_ring_advance(ring);
        return 0;
 }
 
@@ -11009,9 +10992,10 @@ static int intel_gen7_queue_flip(struct drm_device *dev,
                                 struct drm_crtc *crtc,
                                 struct drm_framebuffer *fb,
                                 struct drm_i915_gem_object *obj,
-                                struct intel_engine_cs *ring,
+                                struct drm_i915_gem_request *req,
                                 uint32_t flags)
 {
+       struct intel_engine_cs *ring = req->ring;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        uint32_t plane_bit = 0;
        int len, ret;
@@ -11053,11 +11037,11 @@ static int intel_gen7_queue_flip(struct drm_device *dev,
         * then do the cacheline alignment, and finally emit the
         * MI_DISPLAY_FLIP.
         */
-       ret = intel_ring_cacheline_align(ring);
+       ret = intel_ring_cacheline_align(req);
        if (ret)
                return ret;
 
-       ret = intel_ring_begin(ring, len);
+       ret = intel_ring_begin(req, len);
        if (ret)
                return ret;
 
@@ -11096,7 +11080,6 @@ static int intel_gen7_queue_flip(struct drm_device *dev,
        intel_ring_emit(ring, (MI_NOOP));
 
        intel_mark_page_flip_active(intel_crtc);
-       __intel_ring_advance(ring);
        return 0;
 }
 
@@ -11266,7 +11249,7 @@ static int intel_default_queue_flip(struct drm_device *dev,
                                    struct drm_crtc *crtc,
                                    struct drm_framebuffer *fb,
                                    struct drm_i915_gem_object *obj,
-                                   struct intel_engine_cs *ring,
+                                   struct drm_i915_gem_request *req,
                                    uint32_t flags)
 {
        return -ENODEV;
@@ -11352,6 +11335,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
        struct intel_unpin_work *work;
        struct intel_engine_cs *ring;
        bool mmio_flip;
+       struct drm_i915_gem_request *request = NULL;
        int ret;
 
        /*
@@ -11458,7 +11442,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
         */
        ret = intel_pin_and_fence_fb_obj(crtc->primary, fb,
                                         crtc->primary->state,
-                                        mmio_flip ? i915_gem_request_get_ring(obj->last_write_req) : ring);
+                                        mmio_flip ? i915_gem_request_get_ring(obj->last_write_req) : ring, &request);
        if (ret)
                goto cleanup_pending;
 
@@ -11474,31 +11458,34 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
                i915_gem_request_assign(&work->flip_queued_req,
                                        obj->last_write_req);
        } else {
-               if (obj->last_write_req) {
-                       ret = i915_gem_check_olr(obj->last_write_req);
+               if (!request) {
+                       ret = i915_gem_request_alloc(ring, ring->default_context, &request);
                        if (ret)
                                goto cleanup_unpin;
                }
 
-               ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring,
+               ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request,
                                                   page_flip_flags);
                if (ret)
                        goto cleanup_unpin;
 
-               i915_gem_request_assign(&work->flip_queued_req,
-                                       intel_ring_get_request(ring));
+               i915_gem_request_assign(&work->flip_queued_req, request);
        }
 
+       if (request)
+               i915_add_request_no_flush(request);
+
        work->flip_queued_vblank = drm_crtc_vblank_count(crtc);
        work->enable_stall_check = true;
 
        i915_gem_track_fb(intel_fb_obj(work->old_fb), obj,
-                         INTEL_FRONTBUFFER_PRIMARY(pipe));
-
-       intel_fbc_disable(dev);
-       intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
+                         to_intel_plane(primary)->frontbuffer_bit);
        mutex_unlock(&dev->struct_mutex);
 
+       intel_fbc_disable(dev_priv);
+       intel_frontbuffer_flip_prepare(dev,
+                                      to_intel_plane(primary)->frontbuffer_bit);
+
        trace_i915_flip_request(intel_crtc->plane, obj);
 
        return 0;
@@ -11506,6 +11493,8 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
 cleanup_unpin:
        intel_unpin_fb_obj(fb, crtc->primary->state);
 cleanup_pending:
+       if (request)
+               i915_gem_request_cancel(request);
        atomic_dec(&intel_crtc->unpin_work_count);
        mutex_unlock(&dev->struct_mutex);
 cleanup:
@@ -11646,21 +11635,50 @@ int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state,
                         plane->base.id, was_visible, visible,
                         turn_off, turn_on, mode_changed);
 
-       if (intel_wm_need_update(plane, plane_state))
-               intel_crtc->atomic.update_wm = true;
+       if (turn_on) {
+               intel_crtc->atomic.update_wm_pre = true;
+               /* must disable cxsr around plane enable/disable */
+               if (plane->type != DRM_PLANE_TYPE_CURSOR) {
+                       intel_crtc->atomic.disable_cxsr = true;
+                       /* to potentially re-enable cxsr */
+                       intel_crtc->atomic.wait_vblank = true;
+                       intel_crtc->atomic.update_wm_post = true;
+               }
+       } else if (turn_off) {
+               intel_crtc->atomic.update_wm_post = true;
+               /* must disable cxsr around plane enable/disable */
+               if (plane->type != DRM_PLANE_TYPE_CURSOR) {
+                       if (is_crtc_enabled)
+                               intel_crtc->atomic.wait_vblank = true;
+                       intel_crtc->atomic.disable_cxsr = true;
+               }
+       } else if (intel_wm_need_update(plane, plane_state)) {
+               intel_crtc->atomic.update_wm_pre = true;
+       }
+
+       if (visible)
+               intel_crtc->atomic.fb_bits |=
+                       to_intel_plane(plane)->frontbuffer_bit;
 
        switch (plane->type) {
        case DRM_PLANE_TYPE_PRIMARY:
-               if (visible)
-                       intel_crtc->atomic.fb_bits |=
-                           INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
-
                intel_crtc->atomic.wait_for_flips = true;
                intel_crtc->atomic.pre_disable_primary = turn_off;
                intel_crtc->atomic.post_enable_primary = turn_on;
 
-               if (turn_off)
+               if (turn_off) {
+                       /*
+                        * FIXME: Actually if we will still have any other
+                        * plane enabled on the pipe we could let IPS enabled
+                        * still, but for now lets consider that when we make
+                        * primary invisible by setting DSPCNTR to 0 on
+                        * update_primary_plane function IPS needs to be
+                        * disable.
+                        */
+                       intel_crtc->atomic.disable_ips = true;
+
                        intel_crtc->atomic.disable_fbc = true;
+               }
 
                /*
                 * FBC does not work on some platforms for rotated
@@ -11690,25 +11708,13 @@ int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state,
                intel_crtc->atomic.update_fbc |= visible || mode_changed;
                break;
        case DRM_PLANE_TYPE_CURSOR:
-               if (visible)
-                       intel_crtc->atomic.fb_bits |=
-                           INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe);
                break;
        case DRM_PLANE_TYPE_OVERLAY:
-               /*
-                * 'prepare' is never called when plane is being disabled, so
-                * we need to handle frontbuffer tracking as a special case
-                */
-               if (visible)
-                       intel_crtc->atomic.fb_bits |=
-                           INTEL_FRONTBUFFER_SPRITE(intel_crtc->pipe);
-
                if (turn_off && !mode_changed) {
                        intel_crtc->atomic.wait_vblank = true;
                        intel_crtc->atomic.update_sprite_watermarks |=
                                1 << i;
                }
-               break;
        }
        return 0;
 }
@@ -11816,8 +11822,8 @@ static int intel_crtc_atomic_check(struct drm_crtc *crtc,
        if (pipe_config->quirks & PIPE_CONFIG_QUIRK_INITIAL_PLANES)
                intel_crtc_check_initial_planes(crtc, crtc_state);
 
-       if (mode_changed)
-               intel_crtc->atomic.update_wm = !crtc_state->active;
+       if (mode_changed && !crtc_state->active)
+               intel_crtc->atomic.update_wm_post = true;
 
        if (mode_changed && crtc_state->enable &&
            dev_priv->display.crtc_compute_clock &&
@@ -12022,17 +12028,20 @@ static void intel_dump_pipe_config(struct intel_crtc *crtc,
        DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
 
        if (IS_BROXTON(dev)) {
-               DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, "
+               DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x,"
                              "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, "
-                             "pll6: 0x%x, pll8: 0x%x, pcsdw12: 0x%x\n",
+                             "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n",
                              pipe_config->ddi_pll_sel,
                              pipe_config->dpll_hw_state.ebb0,
+                             pipe_config->dpll_hw_state.ebb4,
                              pipe_config->dpll_hw_state.pll0,
                              pipe_config->dpll_hw_state.pll1,
                              pipe_config->dpll_hw_state.pll2,
                              pipe_config->dpll_hw_state.pll3,
                              pipe_config->dpll_hw_state.pll6,
                              pipe_config->dpll_hw_state.pll8,
+                             pipe_config->dpll_hw_state.pll9,
+                             pipe_config->dpll_hw_state.pll10,
                              pipe_config->dpll_hw_state.pcsdw12);
        } else if (IS_SKYLAKE(dev)) {
                DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: "
@@ -13203,7 +13212,6 @@ void intel_crtc_restore_mode(struct drm_crtc *crtc)
 {
        struct drm_device *dev = crtc->dev;
        struct drm_atomic_state *state;
-       struct intel_crtc *intel_crtc;
        struct intel_encoder *encoder;
        struct intel_connector *connector;
        struct drm_connector_state *connector_state;
@@ -13246,24 +13254,18 @@ void intel_crtc_restore_mode(struct drm_crtc *crtc)
                }
        }
 
-       for_each_intel_crtc(dev, intel_crtc) {
-               if (intel_crtc->new_enabled == intel_crtc->base.enabled)
-                       continue;
-
-               crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
-               if (IS_ERR(crtc_state)) {
-                       DRM_DEBUG_KMS("Failed to add [CRTC:%d] to state: %ld\n",
-                                     intel_crtc->base.base.id,
-                                     PTR_ERR(crtc_state));
-                       continue;
-               }
+       crtc_state = intel_atomic_get_crtc_state(state, to_intel_crtc(crtc));
+       if (IS_ERR(crtc_state)) {
+               DRM_DEBUG_KMS("Failed to add [CRTC:%d] to state: %ld\n",
+                             crtc->base.id, PTR_ERR(crtc_state));
+               drm_atomic_state_free(state);
+               return;
+       }
 
-               crtc_state->base.active = crtc_state->base.enable =
-                       intel_crtc->new_enabled;
+       crtc_state->base.active = crtc_state->base.enable =
+               to_intel_crtc(crtc)->new_enabled;
 
-               if (&intel_crtc->base == crtc)
-                       drm_mode_copy(&crtc_state->base.mode, &crtc->mode);
-       }
+       drm_mode_copy(&crtc_state->base.mode, &crtc->mode);
 
        intel_modeset_setup_plane_state(state, crtc, &crtc->mode,
                                        crtc->primary->fb, crtc->x, crtc->y);
@@ -13597,27 +13599,13 @@ intel_prepare_plane_fb(struct drm_plane *plane,
 {
        struct drm_device *dev = plane->dev;
        struct intel_plane *intel_plane = to_intel_plane(plane);
-       enum pipe pipe = intel_plane->pipe;
        struct drm_i915_gem_object *obj = intel_fb_obj(fb);
        struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
-       unsigned frontbuffer_bits = 0;
        int ret = 0;
 
        if (!obj)
                return 0;
 
-       switch (plane->type) {
-       case DRM_PLANE_TYPE_PRIMARY:
-               frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(pipe);
-               break;
-       case DRM_PLANE_TYPE_CURSOR:
-               frontbuffer_bits = INTEL_FRONTBUFFER_CURSOR(pipe);
-               break;
-       case DRM_PLANE_TYPE_OVERLAY:
-               frontbuffer_bits = INTEL_FRONTBUFFER_SPRITE(pipe);
-               break;
-       }
-
        mutex_lock(&dev->struct_mutex);
 
        if (plane->type == DRM_PLANE_TYPE_CURSOR &&
@@ -13627,11 +13615,11 @@ intel_prepare_plane_fb(struct drm_plane *plane,
                if (ret)
                        DRM_DEBUG_KMS("failed to attach phys object\n");
        } else {
-               ret = intel_pin_and_fence_fb_obj(plane, fb, new_state, NULL);
+               ret = intel_pin_and_fence_fb_obj(plane, fb, new_state, NULL, NULL);
        }
 
        if (ret == 0)
-               i915_gem_track_fb(old_obj, obj, frontbuffer_bits);
+               i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit);
 
        mutex_unlock(&dev->struct_mutex);
 
@@ -13767,7 +13755,7 @@ static void intel_begin_crtc_commit(struct drm_crtc *crtc)
        if (!needs_modeset(crtc->state))
                intel_pre_plane_update(intel_crtc);
 
-       if (intel_crtc->atomic.update_wm)
+       if (intel_crtc->atomic.update_wm_pre)
                intel_update_watermarks(crtc);
 
        intel_runtime_pm_get(dev_priv);
@@ -13850,6 +13838,7 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
        }
        primary->pipe = pipe;
        primary->plane = pipe;
+       primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe);
        primary->check_plane = intel_check_primary_plane;
        primary->commit_plane = intel_commit_primary_plane;
        primary->disable_plane = intel_disable_primary_plane;
@@ -14005,6 +13994,7 @@ static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
        cursor->max_downscale = 1;
        cursor->pipe = pipe;
        cursor->plane = pipe;
+       cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe);
        cursor->check_plane = intel_check_cursor_plane;
        cursor->commit_plane = intel_commit_cursor_plane;
        cursor->disable_plane = intel_disable_cursor_plane;
@@ -14116,6 +14106,8 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
        intel_crtc->cursor_cntl = ~0;
        intel_crtc->cursor_size = ~0;
 
+       intel_crtc->wm.cxsr_allowed = true;
+
        BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
               dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
        dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
@@ -14327,18 +14319,18 @@ static void intel_setup_outputs(struct drm_device *dev)
                }
 
                intel_dsi_init(dev);
-       } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
+       } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) {
                bool found = false;
 
                if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
                        DRM_DEBUG_KMS("probing SDVOB\n");
                        found = intel_sdvo_init(dev, GEN3_SDVOB, true);
-                       if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
+                       if (!found && IS_G4X(dev)) {
                                DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
                                intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
                        }
 
-                       if (!found && SUPPORTS_INTEGRATED_DP(dev))
+                       if (!found && IS_G4X(dev))
                                intel_dp_init(dev, DP_B, PORT_B);
                }
 
@@ -14351,15 +14343,15 @@ static void intel_setup_outputs(struct drm_device *dev)
 
                if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
 
-                       if (SUPPORTS_INTEGRATED_HDMI(dev)) {
+                       if (IS_G4X(dev)) {
                                DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
                                intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
                        }
-                       if (SUPPORTS_INTEGRATED_DP(dev))
+                       if (IS_G4X(dev))
                                intel_dp_init(dev, DP_C, PORT_C);
                }
 
-               if (SUPPORTS_INTEGRATED_DP(dev) &&
+               if (IS_G4X(dev) &&
                    (I915_READ(DP_D) & DP_DETECTED))
                        intel_dp_init(dev, DP_D, PORT_D);
        } else if (IS_GEN2(dev))
@@ -14404,9 +14396,27 @@ static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
        return drm_gem_handle_create(file, &obj->base, handle);
 }
 
+static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
+                                       struct drm_file *file,
+                                       unsigned flags, unsigned color,
+                                       struct drm_clip_rect *clips,
+                                       unsigned num_clips)
+{
+       struct drm_device *dev = fb->dev;
+       struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
+       struct drm_i915_gem_object *obj = intel_fb->obj;
+
+       mutex_lock(&dev->struct_mutex);
+       intel_fb_obj_flush(obj, false, ORIGIN_GTT);
+       mutex_unlock(&dev->struct_mutex);
+
+       return 0;
+}
+
 static const struct drm_framebuffer_funcs intel_fb_funcs = {
        .destroy = intel_user_framebuffer_destroy,
        .create_handle = intel_user_framebuffer_create_handle,
+       .dirty = intel_user_framebuffer_dirty,
 };
 
 static
@@ -14686,6 +14696,9 @@ static void intel_init_display(struct drm_device *dev)
        if (IS_SKYLAKE(dev))
                dev_priv->display.get_display_clock_speed =
                        skylake_get_display_clock_speed;
+       else if (IS_BROXTON(dev))
+               dev_priv->display.get_display_clock_speed =
+                       broxton_get_display_clock_speed;
        else if (IS_BROADWELL(dev))
                dev_priv->display.get_display_clock_speed =
                        broadwell_get_display_clock_speed;
@@ -15063,7 +15076,7 @@ void intel_modeset_init(struct drm_device *dev)
        intel_setup_outputs(dev);
 
        /* Just in case the BIOS is doing something questionable. */
-       intel_fbc_disable(dev);
+       intel_fbc_disable(dev_priv);
 
        drm_modeset_lock_all(dev);
        intel_modeset_setup_hw_state(dev, false);
@@ -15503,7 +15516,9 @@ void intel_modeset_setup_hw_state(struct drm_device *dev,
                pll->on = false;
        }
 
-       if (IS_GEN9(dev))
+       if (IS_VALLEYVIEW(dev))
+               vlv_wm_get_hw_state(dev);
+       else if (IS_GEN9(dev))
                skl_wm_get_hw_state(dev);
        else if (HAS_PCH_SPLIT(dev))
                ilk_wm_get_hw_state(dev);
@@ -15567,7 +15582,7 @@ void intel_modeset_gem_init(struct drm_device *dev)
                ret = intel_pin_and_fence_fb_obj(c->primary,
                                                 c->primary->fb,
                                                 c->primary->state,
-                                                NULL);
+                                                NULL, NULL);
                mutex_unlock(&dev->struct_mutex);
                if (ret) {
                        DRM_ERROR("failed to pin boot fb on pipe %d\n",
@@ -15613,13 +15628,9 @@ void intel_modeset_cleanup(struct drm_device *dev)
         */
        drm_kms_helper_poll_fini(dev);
 
-       mutex_lock(&dev->struct_mutex);
-
        intel_unregister_dsm_handler();
 
-       intel_fbc_disable(dev);
-
-       mutex_unlock(&dev->struct_mutex);
+       intel_fbc_disable(dev_priv);
 
        /* flush any delayed tasks or pending work */
        flush_scheduled_work();