drm/i915: s/PIPE_FRMCOUNT_GM45/PIPE_FRMCOUNT_G4X/ etc.
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / i915 / intel_display.c
index 91dba4f65d2b63389e8c1cf0ecf01a2db411bb5c..b2232ed36937778e1e4bc2981175e8801e12b1cf 100644 (file)
@@ -132,6 +132,42 @@ struct intel_limit {
        intel_p2_t          p2;
 };
 
+/* returns HPLL frequency in kHz */
+static int valleyview_get_vco(struct drm_i915_private *dev_priv)
+{
+       int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
+
+       /* Obtain SKU information */
+       mutex_lock(&dev_priv->sb_lock);
+       hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
+               CCK_FUSE_HPLL_FREQ_MASK;
+       mutex_unlock(&dev_priv->sb_lock);
+
+       return vco_freq[hpll_freq] * 1000;
+}
+
+static int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
+                                 const char *name, u32 reg)
+{
+       u32 val;
+       int divider;
+
+       if (dev_priv->hpll_freq == 0)
+               dev_priv->hpll_freq = valleyview_get_vco(dev_priv);
+
+       mutex_lock(&dev_priv->sb_lock);
+       val = vlv_cck_read(dev_priv, reg);
+       mutex_unlock(&dev_priv->sb_lock);
+
+       divider = val & CCK_FREQUENCY_VALUES;
+
+       WARN((val & CCK_FREQUENCY_STATUS) !=
+            (divider << CCK_FREQUENCY_STATUS_SHIFT),
+            "%s change in progress\n", name);
+
+       return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1);
+}
+
 int
 intel_pch_rawclk(struct drm_device *dev)
 {
@@ -175,6 +211,17 @@ int intel_hrawclk(struct drm_device *dev)
        }
 }
 
+static void intel_update_czclk(struct drm_i915_private *dev_priv)
+{
+       if (!IS_VALLEYVIEW(dev_priv))
+               return;
+
+       dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
+                                                     CCK_CZ_CLOCK_CONTROL);
+
+       DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
+}
+
 static inline u32 /* units of 100MHz */
 intel_fdi_link_freq(struct drm_device *dev)
 {
@@ -2003,9 +2050,9 @@ static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
        assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
 
        /* Workaround: set timing override bit. */
-       val = I915_READ(_TRANSA_CHICKEN2);
+       val = I915_READ(TRANS_CHICKEN2(PIPE_A));
        val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
-       I915_WRITE(_TRANSA_CHICKEN2, val);
+       I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
 
        val = TRANS_ENABLE;
        pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
@@ -2063,9 +2110,9 @@ static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
                DRM_ERROR("Failed to disable PCH transcoder\n");
 
        /* Workaround: clear timing override bit. */
-       val = I915_READ(_TRANSA_CHICKEN2);
+       val = I915_READ(TRANS_CHICKEN2(PIPE_A));
        val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
-       I915_WRITE(_TRANSA_CHICKEN2, val);
+       I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
 }
 
 /**
@@ -2498,6 +2545,7 @@ intel_alloc_initial_plane_obj(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);
        struct drm_i915_gem_object *obj = NULL;
        struct drm_mode_fb_cmd2 mode_cmd = { 0 };
        struct drm_framebuffer *fb = &plane_config->fb->base;
@@ -2510,6 +2558,12 @@ intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
        if (plane_config->size == 0)
                return false;
 
+       /* If the FB is too big, just don't use it since fbdev is not very
+        * important and we should probably use that space with FBC or other
+        * features. */
+       if (size_aligned * 2 > dev_priv->gtt.stolen_usable_size)
+               return false;
+
        obj = i915_gem_object_create_stolen_for_preallocated(dev,
                                                             base_aligned,
                                                             base_aligned,
@@ -3077,27 +3131,19 @@ static void skylake_update_primary_plane(struct drm_crtc *crtc,
                                               fb->pixel_format);
        surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj, 0);
 
-       /*
-        * FIXME: intel_plane_state->src, dst aren't set when transitional
-        * update_plane helpers are called from legacy paths.
-        * Once full atomic crtc is available, below check can be avoided.
-        */
-       if (drm_rect_width(&plane_state->src)) {
-               scaler_id = plane_state->scaler_id;
-               src_x = plane_state->src.x1 >> 16;
-               src_y = plane_state->src.y1 >> 16;
-               src_w = drm_rect_width(&plane_state->src) >> 16;
-               src_h = drm_rect_height(&plane_state->src) >> 16;
-               dst_x = plane_state->dst.x1;
-               dst_y = plane_state->dst.y1;
-               dst_w = drm_rect_width(&plane_state->dst);
-               dst_h = drm_rect_height(&plane_state->dst);
-
-               WARN_ON(x != src_x || y != src_y);
-       } else {
-               src_w = intel_crtc->config->pipe_src_w;
-               src_h = intel_crtc->config->pipe_src_h;
-       }
+       WARN_ON(drm_rect_width(&plane_state->src) == 0);
+
+       scaler_id = plane_state->scaler_id;
+       src_x = plane_state->src.x1 >> 16;
+       src_y = plane_state->src.y1 >> 16;
+       src_w = drm_rect_width(&plane_state->src) >> 16;
+       src_h = drm_rect_height(&plane_state->src) >> 16;
+       dst_x = plane_state->dst.x1;
+       dst_y = plane_state->dst.y1;
+       dst_w = drm_rect_width(&plane_state->dst);
+       dst_h = drm_rect_height(&plane_state->dst);
+
+       WARN_ON(x != src_x || y != src_y);
 
        if (intel_rotation_90_or_270(rotation)) {
                /* stride = Surface height in tiles */
@@ -4758,7 +4804,6 @@ 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)
                intel_wait_for_vblank(dev, crtc->pipe);
@@ -4777,10 +4822,6 @@ static void intel_post_plane_update(struct intel_crtc *crtc)
        if (atomic->post_enable_primary)
                intel_post_enable_primary(&crtc->base);
 
-       drm_for_each_plane_mask(plane, dev, atomic->update_sprite_watermarks)
-               intel_update_sprite_watermarks(plane, &crtc->base,
-                                              0, 0, 0, false, false);
-
        memset(atomic, 0, sizeof(*atomic));
 }
 
@@ -4923,6 +4964,7 @@ static void haswell_crtc_enable(struct drm_crtc *crtc)
        int pipe = intel_crtc->pipe, hsw_workaround_pipe;
        struct intel_crtc_state *pipe_config =
                to_intel_crtc_state(crtc->state);
+       bool is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI);
 
        if (WARN_ON(intel_crtc->active))
                return;
@@ -4952,9 +4994,12 @@ static void haswell_crtc_enable(struct drm_crtc *crtc)
        intel_crtc->active = true;
 
        intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
-       for_each_encoder_on_crtc(dev, crtc, encoder)
+       for_each_encoder_on_crtc(dev, crtc, encoder) {
+               if (encoder->pre_pll_enable)
+                       encoder->pre_pll_enable(encoder);
                if (encoder->pre_enable)
                        encoder->pre_enable(encoder);
+       }
 
        if (intel_crtc->config->has_pch_encoder) {
                intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A,
@@ -4962,7 +5007,8 @@ static void haswell_crtc_enable(struct drm_crtc *crtc)
                dev_priv->display.fdi_link_train(crtc);
        }
 
-       intel_ddi_enable_pipe_clock(intel_crtc);
+       if (!is_dsi)
+               intel_ddi_enable_pipe_clock(intel_crtc);
 
        if (INTEL_INFO(dev)->gen >= 9)
                skylake_pfit_enable(intel_crtc);
@@ -4976,7 +5022,8 @@ static void haswell_crtc_enable(struct drm_crtc *crtc)
        intel_crtc_load_lut(crtc);
 
        intel_ddi_set_pipe_settings(crtc);
-       intel_ddi_enable_transcoder_func(crtc);
+       if (!is_dsi)
+               intel_ddi_enable_transcoder_func(crtc);
 
        intel_update_watermarks(crtc);
        intel_enable_pipe(intel_crtc);
@@ -4984,7 +5031,7 @@ static void haswell_crtc_enable(struct drm_crtc *crtc)
        if (intel_crtc->config->has_pch_encoder)
                lpt_pch_enable(crtc);
 
-       if (intel_crtc->config->dp_encoder_is_mst)
+       if (intel_crtc->config->dp_encoder_is_mst && !is_dsi)
                intel_ddi_set_vc_payload_alloc(crtc, true);
 
        assert_vblank_disabled(crtc);
@@ -5068,9 +5115,6 @@ 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)
@@ -5080,6 +5124,7 @@ static void haswell_crtc_disable(struct drm_crtc *crtc)
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        struct intel_encoder *encoder;
        enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
+       bool is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI);
 
        for_each_encoder_on_crtc(dev, crtc, encoder) {
                intel_opregion_notify_encoder(encoder, false);
@@ -5097,14 +5142,16 @@ static void haswell_crtc_disable(struct drm_crtc *crtc)
        if (intel_crtc->config->dp_encoder_is_mst)
                intel_ddi_set_vc_payload_alloc(crtc, false);
 
-       intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
+       if (!is_dsi)
+               intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
 
        if (INTEL_INFO(dev)->gen >= 9)
                skylake_scaler_disable(intel_crtc);
        else
                ironlake_pfit_disable(intel_crtc, false);
 
-       intel_ddi_disable_pipe_clock(intel_crtc);
+       if (!is_dsi)
+               intel_ddi_disable_pipe_clock(intel_crtc);
 
        if (intel_crtc->config->has_pch_encoder) {
                lpt_disable_pch_transcoder(dev_priv);
@@ -5114,9 +5161,6 @@ 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)
@@ -5756,20 +5800,6 @@ void skl_init_cdclk(struct drm_i915_private *dev_priv)
                DRM_ERROR("DBuf power enable timeout\n");
 }
 
-/* returns HPLL frequency in kHz */
-static int valleyview_get_vco(struct drm_i915_private *dev_priv)
-{
-       int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
-
-       /* Obtain SKU information */
-       mutex_lock(&dev_priv->sb_lock);
-       hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
-               CCK_FUSE_HPLL_FREQ_MASK;
-       mutex_unlock(&dev_priv->sb_lock);
-
-       return vco_freq[hpll_freq] * 1000;
-}
-
 /* Adjust CDclk dividers to allow high res or save power if possible */
 static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
 {
@@ -5807,12 +5837,12 @@ static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
 
                /* adjust cdclk divider */
                val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
-               val &= ~DISPLAY_FREQUENCY_VALUES;
+               val &= ~CCK_FREQUENCY_VALUES;
                val |= divider;
                vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
 
                if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) &
-                             DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
+                             CCK_FREQUENCY_STATUS) == (divider << CCK_FREQUENCY_STATUS_SHIFT),
                             50))
                        DRM_ERROR("timed out waiting for CDclk change\n");
        }
@@ -5990,7 +6020,7 @@ static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv)
        else
                default_credits = PFI_CREDIT(8);
 
-       if (DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 1000) >= dev_priv->rps.cz_freq) {
+       if (dev_priv->cdclk_freq >= dev_priv->czclk_freq) {
                /* CHV suggested value is 31 or 63 */
                if (IS_CHERRYVIEW(dev_priv))
                        credits = PFI_CREDIT_63;
@@ -6221,9 +6251,6 @@ 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)
@@ -6243,6 +6270,8 @@ static void intel_crtc_disable_noatomic(struct drm_crtc *crtc)
 
        intel_crtc_disable_planes(crtc, crtc->state->plane_mask);
        dev_priv->display.crtc_disable(crtc);
+       intel_crtc->active = false;
+       intel_update_watermarks(crtc);
        intel_disable_shared_dpll(intel_crtc);
 
        domains = intel_crtc->enabled_power_domains;
@@ -6722,24 +6751,8 @@ static int haswell_get_display_clock_speed(struct drm_device *dev)
 
 static int valleyview_get_display_clock_speed(struct drm_device *dev)
 {
-       struct drm_i915_private *dev_priv = dev->dev_private;
-       u32 val;
-       int divider;
-
-       if (dev_priv->hpll_freq == 0)
-               dev_priv->hpll_freq = valleyview_get_vco(dev_priv);
-
-       mutex_lock(&dev_priv->sb_lock);
-       val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
-       mutex_unlock(&dev_priv->sb_lock);
-
-       divider = val & DISPLAY_FREQUENCY_VALUES;
-
-       WARN((val & DISPLAY_FREQUENCY_STATUS) !=
-            (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
-            "cdclk change in progress\n");
-
-       return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1);
+       return vlv_get_cck_clock_hpll(to_i915(dev), "cdclk",
+                                     CCK_DISPLAY_CLOCK_CONTROL);
 }
 
 static int ilk_get_display_clock_speed(struct drm_device *dev)
@@ -10809,7 +10822,7 @@ static bool page_flip_finished(struct intel_crtc *crtc)
         */
        return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) ==
                crtc->unpin_work->gtt_offset &&
-               g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)),
+               g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc->pipe)),
                                    crtc->unpin_work->flip_count);
 }
 
@@ -10835,11 +10848,11 @@ void intel_prepare_page_flip(struct drm_device *dev, int plane)
        spin_unlock_irqrestore(&dev->event_lock, flags);
 }
 
-static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
+static inline void intel_mark_page_flip_active(struct intel_unpin_work *work)
 {
        /* Ensure that the work item is consistent when activating it ... */
        smp_wmb();
-       atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
+       atomic_set(&work->pending, INTEL_FLIP_PENDING);
        /* and that it is marked active as soon as the irq could fire. */
        smp_wmb();
 }
@@ -10875,7 +10888,7 @@ static int intel_gen2_queue_flip(struct drm_device *dev,
        intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
        intel_ring_emit(ring, 0); /* aux display base address, unused */
 
-       intel_mark_page_flip_active(intel_crtc);
+       intel_mark_page_flip_active(intel_crtc->unpin_work);
        return 0;
 }
 
@@ -10907,7 +10920,7 @@ static int intel_gen3_queue_flip(struct drm_device *dev,
        intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
        intel_ring_emit(ring, MI_NOOP);
 
-       intel_mark_page_flip_active(intel_crtc);
+       intel_mark_page_flip_active(intel_crtc->unpin_work);
        return 0;
 }
 
@@ -10946,7 +10959,7 @@ static int intel_gen4_queue_flip(struct drm_device *dev,
        pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
        intel_ring_emit(ring, pf | pipesrc);
 
-       intel_mark_page_flip_active(intel_crtc);
+       intel_mark_page_flip_active(intel_crtc->unpin_work);
        return 0;
 }
 
@@ -10982,7 +10995,7 @@ static int intel_gen6_queue_flip(struct drm_device *dev,
        pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
        intel_ring_emit(ring, pf | pipesrc);
 
-       intel_mark_page_flip_active(intel_crtc);
+       intel_mark_page_flip_active(intel_crtc->unpin_work);
        return 0;
 }
 
@@ -11077,7 +11090,7 @@ static int intel_gen7_queue_flip(struct drm_device *dev,
        intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
        intel_ring_emit(ring, (MI_NOOP));
 
-       intel_mark_page_flip_active(intel_crtc);
+       intel_mark_page_flip_active(intel_crtc->unpin_work);
        return 0;
 }
 
@@ -11108,7 +11121,8 @@ static bool use_mmio_flip(struct intel_engine_cs *ring,
                return ring != i915_gem_request_get_ring(obj->last_write_req);
 }
 
-static void skl_do_mmio_flip(struct intel_crtc *intel_crtc)
+static void skl_do_mmio_flip(struct intel_crtc *intel_crtc,
+                            struct intel_unpin_work *work)
 {
        struct drm_device *dev = intel_crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -11149,11 +11163,12 @@ static void skl_do_mmio_flip(struct intel_crtc *intel_crtc)
        I915_WRITE(PLANE_CTL(pipe, 0), ctl);
        I915_WRITE(PLANE_STRIDE(pipe, 0), stride);
 
-       I915_WRITE(PLANE_SURF(pipe, 0), intel_crtc->unpin_work->gtt_offset);
+       I915_WRITE(PLANE_SURF(pipe, 0), work->gtt_offset);
        POSTING_READ(PLANE_SURF(pipe, 0));
 }
 
-static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc)
+static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc,
+                            struct intel_unpin_work *work)
 {
        struct drm_device *dev = intel_crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -11173,31 +11188,36 @@ static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc)
 
        I915_WRITE(reg, dspcntr);
 
-       I915_WRITE(DSPSURF(intel_crtc->plane),
-                  intel_crtc->unpin_work->gtt_offset);
+       I915_WRITE(DSPSURF(intel_crtc->plane), work->gtt_offset);
        POSTING_READ(DSPSURF(intel_crtc->plane));
-
 }
 
 /*
  * XXX: This is the temporary way to update the plane registers until we get
  * around to using the usual plane update functions for MMIO flips
  */
-static void intel_do_mmio_flip(struct intel_crtc *intel_crtc)
+static void intel_do_mmio_flip(struct intel_mmio_flip *mmio_flip)
 {
-       struct drm_device *dev = intel_crtc->base.dev;
+       struct intel_crtc *crtc = mmio_flip->crtc;
+       struct intel_unpin_work *work;
 
-       intel_mark_page_flip_active(intel_crtc);
+       spin_lock_irq(&crtc->base.dev->event_lock);
+       work = crtc->unpin_work;
+       spin_unlock_irq(&crtc->base.dev->event_lock);
+       if (work == NULL)
+               return;
 
-       intel_pipe_update_start(intel_crtc);
+       intel_mark_page_flip_active(work);
 
-       if (INTEL_INFO(dev)->gen >= 9)
-               skl_do_mmio_flip(intel_crtc);
+       intel_pipe_update_start(crtc);
+
+       if (INTEL_INFO(mmio_flip->i915)->gen >= 9)
+               skl_do_mmio_flip(crtc, work);
        else
                /* use_mmio_flip() retricts MMIO flips to ilk+ */
-               ilk_do_mmio_flip(intel_crtc);
+               ilk_do_mmio_flip(crtc, work);
 
-       intel_pipe_update_end(intel_crtc);
+       intel_pipe_update_end(crtc);
 }
 
 static void intel_mmio_flip_work_func(struct work_struct *work)
@@ -11205,15 +11225,15 @@ static void intel_mmio_flip_work_func(struct work_struct *work)
        struct intel_mmio_flip *mmio_flip =
                container_of(work, struct intel_mmio_flip, work);
 
-       if (mmio_flip->req)
+       if (mmio_flip->req) {
                WARN_ON(__i915_wait_request(mmio_flip->req,
                                            mmio_flip->crtc->reset_counter,
                                            false, NULL,
                                            &mmio_flip->i915->rps.mmioflips));
+               i915_gem_request_unreference__unlocked(mmio_flip->req);
+       }
 
-       intel_do_mmio_flip(mmio_flip->crtc);
-
-       i915_gem_request_unreference__unlocked(mmio_flip->req);
+       intel_do_mmio_flip(mmio_flip);
        kfree(mmio_flip);
 }
 
@@ -11414,7 +11434,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
        intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
 
        if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
-               work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1;
+               work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1;
 
        if (IS_VALLEYVIEW(dev)) {
                ring = &dev_priv->ring[BCS];
@@ -11564,18 +11584,32 @@ retry:
 static bool intel_wm_need_update(struct drm_plane *plane,
                                 struct drm_plane_state *state)
 {
-       /* Update watermarks on tiling changes. */
+       struct intel_plane_state *new = to_intel_plane_state(state);
+       struct intel_plane_state *cur = to_intel_plane_state(plane->state);
+
+       /* Update watermarks on tiling or size changes. */
        if (!plane->state->fb || !state->fb ||
            plane->state->fb->modifier[0] != state->fb->modifier[0] ||
-           plane->state->rotation != state->rotation)
-               return true;
-
-       if (plane->state->crtc_w != state->crtc_w)
+           plane->state->rotation != state->rotation ||
+           drm_rect_width(&new->src) != drm_rect_width(&cur->src) ||
+           drm_rect_height(&new->src) != drm_rect_height(&cur->src) ||
+           drm_rect_width(&new->dst) != drm_rect_width(&cur->dst) ||
+           drm_rect_height(&new->dst) != drm_rect_height(&cur->dst))
                return true;
 
        return false;
 }
 
+static bool needs_scaling(struct intel_plane_state *state)
+{
+       int src_w = drm_rect_width(&state->src) >> 16;
+       int src_h = drm_rect_height(&state->src) >> 16;
+       int dst_w = drm_rect_width(&state->dst);
+       int dst_h = drm_rect_height(&state->dst);
+
+       return (src_w != dst_w || src_h != dst_h);
+}
+
 int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state,
                                    struct drm_plane_state *plane_state)
 {
@@ -11591,7 +11625,6 @@ int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state,
        bool mode_changed = needs_modeset(crtc_state);
        bool was_crtc_enabled = crtc->state->active;
        bool is_crtc_enabled = crtc_state->active;
-
        bool turn_off, turn_on, visible, was_visible;
        struct drm_framebuffer *fb = plane_state->fb;
 
@@ -11709,11 +11742,23 @@ int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state,
        case DRM_PLANE_TYPE_CURSOR:
                break;
        case DRM_PLANE_TYPE_OVERLAY:
-               if (turn_off && !mode_changed) {
+               /*
+                * WaCxSRDisabledForSpriteScaling:ivb
+                *
+                * cstate->update_wm was already set above, so this flag will
+                * take effect when we commit and program watermarks.
+                */
+               if (IS_IVYBRIDGE(dev) &&
+                   needs_scaling(to_intel_plane_state(plane_state)) &&
+                   !needs_scaling(old_plane_state)) {
+                       to_intel_crtc_state(crtc_state)->disable_lp_wm = true;
+               } else if (turn_off && !mode_changed) {
                        intel_crtc->atomic.wait_vblank = true;
                        intel_crtc->atomic.update_sprite_watermarks |=
                                1 << i;
                }
+
+               break;
        }
        return 0;
 }
@@ -12577,8 +12622,8 @@ static void check_wm_state(struct drm_device *dev)
                }
 
                /* cursor */
-               hw_entry = &hw_ddb.cursor[pipe];
-               sw_entry = &sw_ddb->cursor[pipe];
+               hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
+               sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
 
                if (skl_ddb_entry_equal(hw_entry, sw_entry))
                        continue;
@@ -13329,8 +13374,6 @@ static void intel_shared_dpll_init(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = dev->dev_private;
 
-       intel_update_cdclk(dev);
-
        if (HAS_DDI(dev))
                intel_ddi_pll_init(dev);
        else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
@@ -13989,7 +14032,7 @@ static void intel_setup_outputs(struct drm_device *dev)
                 * On SKL pre-D0 the strap isn't connected, so we assume
                 * it's there.
                 */
-               found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
+               found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
                /* WaIgnoreDDIAStrap: skl */
                if (found || IS_SKYLAKE(dev))
                        intel_ddi_init(dev, PORT_A);
@@ -14560,8 +14603,6 @@ static void intel_init_display(struct drm_device *dev)
                dev_priv->display.queue_flip = intel_default_queue_flip;
        }
 
-       intel_panel_init_backlight_funcs(dev);
-
        mutex_init(&dev_priv->pps_mutex);
 }
 
@@ -14839,6 +14880,9 @@ void intel_modeset_init(struct drm_device *dev)
                }
        }
 
+       intel_update_czclk(dev_priv);
+       intel_update_cdclk(dev);
+
        intel_shared_dpll_init(dev);
 
        /* Just disable it once at startup */