Merge tag 'drm-intel-next-2016-10-24' of git://anongit.freedesktop.org/drm-intel...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / i915 / intel_display.c
index e07c34478e0956b33bc13f9e0619666f92e5517e..6f8f6ec5b27a34a7c28d1b9f46719cd79c9c0706 100644 (file)
@@ -849,7 +849,7 @@ static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
         * For CHV ignore the error and consider only the P value.
         * Prefer a bigger P value based on HW requirements.
         */
-       if (IS_CHERRYVIEW(dev)) {
+       if (IS_CHERRYVIEW(to_i915(dev))) {
                *error_ppm = 0;
 
                return calculated_clock->p > best_clock->p;
@@ -1045,7 +1045,7 @@ static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe)
        u32 line1, line2;
        u32 line_mask;
 
-       if (IS_GEN2(dev))
+       if (IS_GEN2(dev_priv))
                line_mask = DSL_LINEMASK_GEN2;
        else
                line_mask = DSL_LINEMASK_GEN3;
@@ -1332,7 +1332,7 @@ static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
                             "plane %d assertion failure, should be off on pipe %c but is still active\n",
                             sprite, pipe_name(pipe));
                }
-       } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
+       } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
                for_each_sprite(dev_priv, pipe, sprite) {
                        u32 val = I915_READ(SPCNTR(pipe, sprite));
                        I915_STATE_WARN(val & SP_ENABLE,
@@ -1926,6 +1926,18 @@ void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
        I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
 }
 
+enum transcoder intel_crtc_pch_transcoder(struct intel_crtc *crtc)
+{
+       struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
+
+       WARN_ON(!crtc->config->has_pch_encoder);
+
+       if (HAS_PCH_LPT(dev_priv))
+               return TRANSCODER_A;
+       else
+               return (enum transcoder) crtc->pipe;
+}
+
 /**
  * intel_enable_pipe - enable a pipe, asserting requirements
  * @crtc: crtc responsible for the pipe
@@ -1939,7 +1951,6 @@ static void intel_enable_pipe(struct intel_crtc *crtc)
        struct drm_i915_private *dev_priv = to_i915(dev);
        enum pipe pipe = crtc->pipe;
        enum transcoder cpu_transcoder = crtc->config->cpu_transcoder;
-       enum pipe pch_transcoder;
        i915_reg_t reg;
        u32 val;
 
@@ -1949,11 +1960,6 @@ static void intel_enable_pipe(struct intel_crtc *crtc)
        assert_cursor_disabled(dev_priv, pipe);
        assert_sprites_disabled(dev_priv, pipe);
 
-       if (HAS_PCH_LPT(dev_priv))
-               pch_transcoder = TRANSCODER_A;
-       else
-               pch_transcoder = pipe;
-
        /*
         * A pipe without a PLL won't actually be able to drive bits from
         * a plane.  On ILK+ the pipe PLLs are integrated, so we don't
@@ -1967,7 +1973,8 @@ static void intel_enable_pipe(struct intel_crtc *crtc)
        } else {
                if (crtc->config->has_pch_encoder) {
                        /* if driving the PCH, we need FDI enabled */
-                       assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
+                       assert_fdi_rx_pll_enabled(dev_priv,
+                                                 (enum pipe) intel_crtc_pch_transcoder(crtc));
                        assert_fdi_tx_pll_enabled(dev_priv,
                                                  (enum pipe) cpu_transcoder);
                }
@@ -2139,7 +2146,7 @@ intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
                        const struct drm_framebuffer *fb,
                        unsigned int rotation)
 {
-       if (intel_rotation_90_or_270(rotation)) {
+       if (drm_rotation_90_or_270(rotation)) {
                *view = i915_ggtt_view_rotated;
                view->params.rotated = to_intel_framebuffer(fb)->rot_info;
        } else {
@@ -2260,7 +2267,7 @@ void intel_unpin_fb_obj(struct drm_framebuffer *fb, unsigned int rotation)
 static int intel_fb_pitch(const struct drm_framebuffer *fb, int plane,
                          unsigned int rotation)
 {
-       if (intel_rotation_90_or_270(rotation))
+       if (drm_rotation_90_or_270(rotation))
                return to_intel_framebuffer(fb)->rotated[plane].pitch;
        else
                return fb->pitches[plane];
@@ -2296,7 +2303,7 @@ void intel_add_fb_offsets(int *x, int *y,
        const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
        unsigned int rotation = state->base.rotation;
 
-       if (intel_rotation_90_or_270(rotation)) {
+       if (drm_rotation_90_or_270(rotation)) {
                *x += intel_fb->rotated[plane].x;
                *y += intel_fb->rotated[plane].y;
        } else {
@@ -2360,7 +2367,7 @@ static u32 intel_adjust_tile_offset(int *x, int *y,
                intel_tile_dims(dev_priv, &tile_width, &tile_height,
                                fb->modifier[plane], cpp);
 
-               if (intel_rotation_90_or_270(rotation)) {
+               if (drm_rotation_90_or_270(rotation)) {
                        pitch_tiles = pitch / tile_height;
                        swap(tile_width, tile_height);
                } else {
@@ -2416,7 +2423,7 @@ static u32 _intel_compute_tile_offset(const struct drm_i915_private *dev_priv,
                intel_tile_dims(dev_priv, &tile_width, &tile_height,
                                fb_modifier, cpp);
 
-               if (intel_rotation_90_or_270(rotation)) {
+               if (drm_rotation_90_or_270(rotation)) {
                        pitch_tiles = pitch / tile_height;
                        swap(tile_width, tile_height);
                } else {
@@ -2976,7 +2983,7 @@ int skl_check_plane_surface(struct intel_plane_state *plane_state)
        int ret;
 
        /* Rotate src coordinates to match rotated GTT view */
-       if (intel_rotation_90_or_270(rotation))
+       if (drm_rotation_90_or_270(rotation))
                drm_rect_rotate(&plane_state->base.src,
                                fb->width, fb->height, DRM_ROTATE_270);
 
@@ -3033,7 +3040,7 @@ static void i9xx_update_primary_plane(struct drm_plane *primary,
                           ((crtc_state->pipe_src_h - 1) << 16) |
                           (crtc_state->pipe_src_w - 1));
                I915_WRITE(DSPPOS(plane), 0);
-       } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) {
+       } else if (IS_CHERRYVIEW(dev_priv) && plane == PLANE_B) {
                I915_WRITE(PRIMSIZE(plane),
                           ((crtc_state->pipe_src_h - 1) << 16) |
                           (crtc_state->pipe_src_w - 1));
@@ -3071,7 +3078,7 @@ static void i9xx_update_primary_plane(struct drm_plane *primary,
            fb->modifier[0] == I915_FORMAT_MOD_X_TILED)
                dspcntr |= DISPPLANE_TILED;
 
-       if (IS_G4X(dev))
+       if (IS_G4X(dev_priv))
                dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
 
        intel_add_fb_offsets(&x, &y, plane_state, 0);
@@ -3276,7 +3283,7 @@ u32 skl_plane_stride(const struct drm_framebuffer *fb, int plane,
         * The stride is either expressed as a multiple of 64 bytes chunks for
         * linear buffers or in number of tiles for tiled buffers.
         */
-       if (intel_rotation_90_or_270(rotation)) {
+       if (drm_rotation_90_or_270(rotation)) {
                int cpp = drm_format_plane_cpp(fb->pixel_format, plane);
 
                stride /= intel_tile_height(dev_priv, fb->modifier[0], cpp);
@@ -3378,6 +3385,8 @@ static void skylake_update_primary_plane(struct drm_plane *plane,
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
        struct drm_framebuffer *fb = plane_state->base.fb;
        const struct skl_wm_values *wm = &dev_priv->wm.skl_results;
+       const struct skl_plane_wm *p_wm =
+               &crtc_state->wm.skl.optimal.planes[0];
        int pipe = intel_crtc->pipe;
        u32 plane_ctl;
        unsigned int rotation = plane_state->base.rotation;
@@ -3414,7 +3423,7 @@ static void skylake_update_primary_plane(struct drm_plane *plane,
        intel_crtc->adjusted_y = src_y;
 
        if (wm->dirty_pipes & drm_crtc_mask(&intel_crtc->base))
-               skl_write_plane_wm(intel_crtc, wm, 0);
+               skl_write_plane_wm(intel_crtc, p_wm, &wm->ddb, 0);
 
        I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl);
        I915_WRITE(PLANE_OFFSET(pipe, 0), (src_y << 16) | src_x);
@@ -3448,6 +3457,8 @@ static void skylake_disable_primary_plane(struct drm_plane *primary,
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = to_i915(dev);
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+       struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->state);
+       const struct skl_plane_wm *p_wm = &cstate->wm.skl.optimal.planes[0];
        int pipe = intel_crtc->pipe;
 
        /*
@@ -3455,7 +3466,8 @@ static void skylake_disable_primary_plane(struct drm_plane *primary,
         * plane's visiblity isn't actually changing neither is its watermarks.
         */
        if (!crtc->primary->state->visible)
-               skl_write_plane_wm(intel_crtc, &dev_priv->wm.skl_results, 0);
+               skl_write_plane_wm(intel_crtc, p_wm,
+                                  &dev_priv->wm.skl_results.ddb, 0);
 
        I915_WRITE(PLANE_CTL(pipe, 0), 0);
        I915_WRITE(PLANE_SURF(pipe, 0), 0);
@@ -3584,7 +3596,7 @@ void intel_prepare_reset(struct drm_i915_private *dev_priv)
        return;
 
 err:
-       drm_atomic_state_free(state);
+       drm_atomic_state_put(state);
 }
 
 void intel_finish_reset(struct drm_i915_private *dev_priv)
@@ -3644,6 +3656,8 @@ void intel_finish_reset(struct drm_i915_private *dev_priv)
                intel_hpd_init(dev_priv);
        }
 
+       if (state)
+               drm_atomic_state_put(state);
        drm_modeset_drop_locks(ctx);
        drm_modeset_acquire_fini(ctx);
        mutex_unlock(&dev->mode_config.mutex);
@@ -3945,7 +3959,7 @@ static void gen6_fdi_link_train(struct drm_crtc *crtc)
        temp = I915_READ(reg);
        temp &= ~FDI_LINK_TRAIN_NONE;
        temp |= FDI_LINK_TRAIN_PATTERN_2;
-       if (IS_GEN6(dev)) {
+       if (IS_GEN6(dev_priv)) {
                temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
                /* SNB-B */
                temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
@@ -4666,7 +4680,7 @@ skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
                to_intel_crtc(crtc_state->base.crtc);
        int need_scaling;
 
-       need_scaling = intel_rotation_90_or_270(rotation) ?
+       need_scaling = drm_rotation_90_or_270(rotation) ?
                (src_h != dst_w || src_w != dst_h):
                (src_w != dst_w || src_h != dst_h);
 
@@ -4983,7 +4997,7 @@ intel_post_enable_primary(struct drm_crtc *crtc)
         * FIXME: Need to fix the logic to work when we turn off all planes
         * but leave the pipe running.
         */
-       if (IS_GEN2(dev))
+       if (IS_GEN2(dev_priv))
                intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
 
        /* Underruns don't always raise interrupts, so check manually. */
@@ -5006,7 +5020,7 @@ intel_pre_disable_primary(struct drm_crtc *crtc)
         * FIXME: Need to fix the logic to work when we turn off all planes
         * but leave the pipe running.
         */
-       if (IS_GEN2(dev))
+       if (IS_GEN2(dev_priv))
                intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
 
        /*
@@ -5872,9 +5886,9 @@ static void intel_update_max_cdclk(struct drm_device *dev)
                        dev_priv->max_cdclk_freq = 540000;
                else
                        dev_priv->max_cdclk_freq = 675000;
-       } else if (IS_CHERRYVIEW(dev)) {
+       } else if (IS_CHERRYVIEW(dev_priv)) {
                dev_priv->max_cdclk_freq = 320000;
-       } else if (IS_VALLEYVIEW(dev)) {
+       } else if (IS_VALLEYVIEW(dev_priv)) {
                dev_priv->max_cdclk_freq = 400000;
        } else {
                /* otherwise assume cdclk is fixed */
@@ -6674,7 +6688,7 @@ static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state)
         */
        intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A);
 
-       if (IS_CHERRYVIEW(dev))
+       if (IS_CHERRYVIEW(dev_priv))
                cherryview_set_cdclk(dev, req_cdclk);
        else
                valleyview_set_cdclk(dev, req_cdclk);
@@ -6702,7 +6716,7 @@ static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
        intel_set_pipe_timings(intel_crtc);
        intel_set_pipe_src_size(intel_crtc);
 
-       if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) {
+       if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
                struct drm_i915_private *dev_priv = to_i915(dev);
 
                I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
@@ -6717,7 +6731,7 @@ static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
 
        intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
 
-       if (IS_CHERRYVIEW(dev)) {
+       if (IS_CHERRYVIEW(dev_priv)) {
                chv_prepare_pll(intel_crtc, intel_crtc->config);
                chv_enable_pll(intel_crtc, intel_crtc->config);
        } else {
@@ -6773,7 +6787,7 @@ static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
 
        intel_crtc->active = true;
 
-       if (!IS_GEN2(dev))
+       if (!IS_GEN2(dev_priv))
                intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
 
        intel_encoders_pre_enable(crtc, pipe_config, old_state);
@@ -6821,7 +6835,7 @@ static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
         * On gen2 planes are double buffered but the pipe isn't, so we must
         * wait for planes to fully turn off before disabling the pipe.
         */
-       if (IS_GEN2(dev))
+       if (IS_GEN2(dev_priv))
                intel_wait_for_vblank(dev, pipe);
 
        intel_encoders_disable(crtc, old_crtc_state, old_state);
@@ -6836,9 +6850,9 @@ static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
        intel_encoders_post_disable(crtc, old_crtc_state, old_state);
 
        if (!intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DSI)) {
-               if (IS_CHERRYVIEW(dev))
+               if (IS_CHERRYVIEW(dev_priv))
                        chv_disable_pll(dev_priv, pipe);
-               else if (IS_VALLEYVIEW(dev))
+               else if (IS_VALLEYVIEW(dev_priv))
                        vlv_disable_pll(dev_priv, pipe);
                else
                        i9xx_disable_pll(intel_crtc);
@@ -6846,7 +6860,7 @@ static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
 
        intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
 
-       if (!IS_GEN2(dev))
+       if (!IS_GEN2(dev_priv))
                intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
 }
 
@@ -6884,7 +6898,7 @@ static void intel_crtc_disable_noatomic(struct drm_crtc *crtc)
 
        dev_priv->display.crtc_disable(crtc_state, state);
 
-       drm_atomic_state_free(state);
+       drm_atomic_state_put(state);
 
        DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
                      crtc->base.id, crtc->name);
@@ -7224,7 +7238,7 @@ static int intel_crtc_compute_config(struct intel_crtc *crtc,
        /* Cantiga+ cannot handle modes with a hsync front porch of 0.
         * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
         */
-       if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
+       if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
                adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
                return -EINVAL;
 
@@ -7538,7 +7552,7 @@ static unsigned int intel_hpll_vco(struct drm_device *dev)
        /* FIXME other chipsets? */
        if (IS_GM45(dev_priv))
                vco_table = ctg_vco;
-       else if (IS_G4X(dev))
+       else if (IS_G4X(dev_priv))
                vco_table = elk_vco;
        else if (IS_CRESTLINE(dev))
                vco_table = cl_vco;
@@ -7803,8 +7817,8 @@ static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
                 * for gen < 8) and if DRRS is supported (to make sure the
                 * registers are not unnecessarily accessed).
                 */
-               if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) &&
-                       crtc->config->has_drrs) {
+               if (m2_n2 && (IS_CHERRYVIEW(dev_priv) ||
+                   INTEL_GEN(dev_priv) < 8) && crtc->config->has_drrs) {
                        I915_WRITE(PIPE_DATA_M2(transcoder),
                                        TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
                        I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
@@ -8106,7 +8120,7 @@ int vlv_force_pll_on(struct drm_device *dev, enum pipe pipe,
        pipe_config->pixel_multiplier = 1;
        pipe_config->dpll = *dpll;
 
-       if (IS_CHERRYVIEW(dev)) {
+       if (IS_CHERRYVIEW(to_i915(dev))) {
                chv_compute_dpll(crtc, pipe_config);
                chv_prepare_pll(crtc, pipe_config);
                chv_enable_pll(crtc, pipe_config);
@@ -8131,7 +8145,7 @@ int vlv_force_pll_on(struct drm_device *dev, enum pipe pipe,
  */
 void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe)
 {
-       if (IS_CHERRYVIEW(dev))
+       if (IS_CHERRYVIEW(to_i915(dev)))
                chv_disable_pll(to_i915(dev), pipe);
        else
                vlv_disable_pll(to_i915(dev), pipe);
@@ -8172,7 +8186,7 @@ static void i9xx_compute_dpll(struct intel_crtc *crtc,
                dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
        else {
                dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
-               if (IS_G4X(dev) && reduced_clock)
+               if (IS_G4X(dev_priv) && reduced_clock)
                        dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
        }
        switch (clock->p2) {
@@ -8414,7 +8428,8 @@ static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
                pipeconf |= PIPECONF_DOUBLE_WIDE;
 
        /* only g4x and later have fancy bpc/dither controls */
-       if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
+       if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
+           IS_CHERRYVIEW(dev_priv)) {
                /* Bspec claims that we can't use dithering for 30bpp pipes. */
                if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30)
                        pipeconf |= PIPECONF_DITHER_EN |
@@ -8454,7 +8469,7 @@ static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
        } else
                pipeconf |= PIPECONF_PROGRESSIVE;
 
-       if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
+       if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
             intel_crtc->config->limited_color_range)
                pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
 
@@ -8831,7 +8846,8 @@ static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
        if (!(tmp & PIPECONF_ENABLE))
                goto out;
 
-       if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
+       if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
+           IS_CHERRYVIEW(dev_priv)) {
                switch (tmp & PIPECONF_BPC_MASK) {
                case PIPECONF_6BPC:
                        pipe_config->pipe_bpp = 18;
@@ -8847,7 +8863,7 @@ static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
                }
        }
 
-       if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
+       if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
            (tmp & PIPECONF_COLOR_RANGE_SELECT))
                pipe_config->limited_color_range = true;
 
@@ -8861,7 +8877,7 @@ static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
 
        if (INTEL_INFO(dev)->gen >= 4) {
                /* No way to read it out on pipes B and C */
-               if (IS_CHERRYVIEW(dev) && crtc->pipe != PIPE_A)
+               if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
                        tmp = dev_priv->chv_dpll_md[crtc->pipe];
                else
                        tmp = I915_READ(DPLL_MD(crtc->pipe));
@@ -8882,7 +8898,7 @@ static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
                pipe_config->pixel_multiplier = 1;
        }
        pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
-       if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) {
+       if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
                /*
                 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
                 * on 830. Filter it out here so that we don't
@@ -8900,9 +8916,9 @@ static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
                                                     DPLL_PORTB_READY_MASK);
        }
 
-       if (IS_CHERRYVIEW(dev))
+       if (IS_CHERRYVIEW(dev_priv))
                chv_crtc_clock_get(crtc, pipe_config);
-       else if (IS_VALLEYVIEW(dev))
+       else if (IS_VALLEYVIEW(dev_priv))
                vlv_crtc_clock_get(crtc, pipe_config);
        else
                i9xx_crtc_clock_get(crtc, pipe_config);
@@ -9842,7 +9858,7 @@ static void ironlake_get_pfit_config(struct intel_crtc *crtc,
                /* We currently do not free assignements of panel fitters on
                 * ivb/hsw (since we don't use the higher upscaling modes which
                 * differentiates them) so just WARN about this case for now. */
-               if (IS_GEN7(dev)) {
+               if (IS_GEN7(dev_priv)) {
                        WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
                                PF_PIPE_SEL_IVB(crtc->pipe));
                }
@@ -10824,12 +10840,15 @@ static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base,
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = to_i915(dev);
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+       struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->state);
        const struct skl_wm_values *wm = &dev_priv->wm.skl_results;
+       const struct skl_plane_wm *p_wm =
+               &cstate->wm.skl.optimal.planes[PLANE_CURSOR];
        int pipe = intel_crtc->pipe;
        uint32_t cntl = 0;
 
        if (INTEL_GEN(dev_priv) >= 9 && wm->dirty_pipes & drm_crtc_mask(crtc))
-               skl_write_cursor_wm(intel_crtc, wm);
+               skl_write_cursor_wm(intel_crtc, p_wm, &wm->ddb);
 
        if (plane_state && plane_state->base.visible) {
                cntl = MCURSOR_GAMMA_ENABLE;
@@ -11272,9 +11291,14 @@ found:
        return true;
 
 fail:
-       drm_atomic_state_free(state);
-       drm_atomic_state_free(restore_state);
-       restore_state = state = NULL;
+       if (state) {
+               drm_atomic_state_put(state);
+               state = NULL;
+       }
+       if (restore_state) {
+               drm_atomic_state_put(restore_state);
+               restore_state = NULL;
+       }
 
        if (ret == -EDEADLK) {
                drm_modeset_backoff(ctx);
@@ -11302,10 +11326,9 @@ void intel_release_load_detect_pipe(struct drm_connector *connector,
                return;
 
        ret = drm_atomic_commit(state);
-       if (ret) {
+       if (ret)
                DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
-               drm_atomic_state_free(state);
-       }
+       drm_atomic_state_put(state);
 }
 
 static int i9xx_pll_refclk(struct drm_device *dev,
@@ -11318,7 +11341,7 @@ static int i9xx_pll_refclk(struct drm_device *dev,
                return dev_priv->vbt.lvds_ssc_freq;
        else if (HAS_PCH_SPLIT(dev_priv))
                return 120000;
-       else if (!IS_GEN2(dev))
+       else if (!IS_GEN2(dev_priv))
                return 96000;
        else
                return 48000;
@@ -11351,7 +11374,7 @@ static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
                clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
        }
 
-       if (!IS_GEN2(dev)) {
+       if (!IS_GEN2(dev_priv)) {
                if (IS_PINEVIEW(dev))
                        clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
                                DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
@@ -11580,7 +11603,7 @@ static bool __pageflip_finished_cs(struct intel_crtc *crtc,
         * really needed there. But since ctg has the registers,
         * include it in the check anyway.
         */
-       if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev))
+       if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
                return true;
 
        /*
@@ -11850,6 +11873,7 @@ static int intel_gen7_queue_flip(struct drm_device *dev,
                                 struct drm_i915_gem_request *req,
                                 uint32_t flags)
 {
+       struct drm_i915_private *dev_priv = to_i915(dev);
        struct intel_ring *ring = req->ring;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        uint32_t plane_bit = 0;
@@ -11878,7 +11902,7 @@ static int intel_gen7_queue_flip(struct drm_device *dev,
                 * 48bits addresses, and we need a NOOP for the batch size to
                 * stay even.
                 */
-               if (IS_GEN8(dev))
+               if (IS_GEN8(dev_priv))
                        len += 2;
        }
 
@@ -11915,7 +11939,7 @@ static int intel_gen7_queue_flip(struct drm_device *dev,
                intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
                                          DERRMR_PIPEB_PRI_FLIP_DONE |
                                          DERRMR_PIPEC_PRI_FLIP_DONE));
-               if (IS_GEN8(dev))
+               if (IS_GEN8(dev_priv))
                        intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8 |
                                              MI_SRM_LRM_GLOBAL_GTT);
                else
@@ -11924,7 +11948,7 @@ static int intel_gen7_queue_flip(struct drm_device *dev,
                intel_ring_emit_reg(ring, DERRMR);
                intel_ring_emit(ring,
                                i915_ggtt_offset(req->engine->scratch) + 256);
-               if (IS_GEN8(dev)) {
+               if (IS_GEN8(dev_priv)) {
                        intel_ring_emit(ring, 0);
                        intel_ring_emit(ring, MI_NOOP);
                }
@@ -12243,10 +12267,10 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
 
        atomic_inc(&intel_crtc->unpin_work_count);
 
-       if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
+       if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
                work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1;
 
-       if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
+       if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
                engine = dev_priv->engine[BCS];
                if (fb->modifier[0] != old_fb->modifier[0])
                        /* vlv: DISPLAY_FLIP fails to change tiling */
@@ -12373,8 +12397,7 @@ retry:
                        goto retry;
                }
 
-               if (ret)
-                       drm_atomic_state_free(state);
+               drm_atomic_state_put(state);
 
                if (ret == 0 && event) {
                        spin_lock_irq(&dev->event_lock);
@@ -12448,7 +12471,7 @@ int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state,
        struct drm_framebuffer *fb = plane_state->fb;
        int ret;
 
-       if (INTEL_GEN(dev) >= 9 && plane->type != DRM_PLANE_TYPE_CURSOR) {
+       if (INTEL_GEN(dev_priv) >= 9 && plane->type != DRM_PLANE_TYPE_CURSOR) {
                ret = skl_update_scaler_plane(
                        to_intel_crtc_state(crtc_state),
                        to_intel_plane_state(plane_state));
@@ -12703,15 +12726,16 @@ static int
 compute_baseline_pipe_bpp(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(crtc->base.dev);
        struct drm_atomic_state *state;
        struct drm_connector *connector;
        struct drm_connector_state *connector_state;
        int bpp, i;
 
-       if ((IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)))
+       if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
+           IS_CHERRYVIEW(dev_priv)))
                bpp = 10*3;
-       else if (INTEL_INFO(dev)->gen >= 5)
+       else if (INTEL_GEN(dev_priv) >= 5)
                bpp = 12*3;
        else
                bpp = 8*3;
@@ -13343,7 +13367,7 @@ intel_pipe_config_compare(struct drm_device *dev,
        PIPE_CONF_CHECK_I(pixel_multiplier);
        PIPE_CONF_CHECK_I(has_hdmi_sink);
        if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
-           IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
+           IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
                PIPE_CONF_CHECK_I(limited_color_range);
        PIPE_CONF_CHECK_I(has_infoframe);
 
@@ -13402,7 +13426,7 @@ intel_pipe_config_compare(struct drm_device *dev,
        PIPE_CONF_CHECK_X(dsi_pll.ctrl);
        PIPE_CONF_CHECK_X(dsi_pll.div);
 
-       if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
+       if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
                PIPE_CONF_CHECK_I(pipe_bpp);
 
        PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
@@ -13443,30 +13467,65 @@ static void verify_wm_state(struct drm_crtc *crtc,
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = to_i915(dev);
        struct skl_ddb_allocation hw_ddb, *sw_ddb;
-       struct skl_ddb_entry *hw_entry, *sw_entry;
+       struct skl_pipe_wm hw_wm, *sw_wm;
+       struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
+       struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        const enum pipe pipe = intel_crtc->pipe;
-       int plane;
+       int plane, level, max_level = ilk_wm_max_level(dev_priv);
 
        if (INTEL_INFO(dev)->gen < 9 || !new_state->active)
                return;
 
+       skl_pipe_wm_get_hw_state(crtc, &hw_wm);
+       sw_wm = &intel_crtc->wm.active.skl;
+
        skl_ddb_get_hw_state(dev_priv, &hw_ddb);
        sw_ddb = &dev_priv->wm.skl_hw.ddb;
 
        /* planes */
        for_each_plane(dev_priv, pipe, plane) {
-               hw_entry = &hw_ddb.plane[pipe][plane];
-               sw_entry = &sw_ddb->plane[pipe][plane];
+               hw_plane_wm = &hw_wm.planes[plane];
+               sw_plane_wm = &sw_wm->planes[plane];
 
-               if (skl_ddb_entry_equal(hw_entry, sw_entry))
-                       continue;
+               /* Watermarks */
+               for (level = 0; level <= max_level; level++) {
+                       if (skl_wm_level_equals(&hw_plane_wm->wm[level],
+                                               &sw_plane_wm->wm[level]))
+                               continue;
+
+                       DRM_ERROR("mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
+                                 pipe_name(pipe), plane + 1, level,
+                                 sw_plane_wm->wm[level].plane_en,
+                                 sw_plane_wm->wm[level].plane_res_b,
+                                 sw_plane_wm->wm[level].plane_res_l,
+                                 hw_plane_wm->wm[level].plane_en,
+                                 hw_plane_wm->wm[level].plane_res_b,
+                                 hw_plane_wm->wm[level].plane_res_l);
+               }
 
-               DRM_ERROR("mismatch in DDB state pipe %c plane %d "
-                         "(expected (%u,%u), found (%u,%u))\n",
-                         pipe_name(pipe), plane + 1,
-                         sw_entry->start, sw_entry->end,
-                         hw_entry->start, hw_entry->end);
+               if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
+                                        &sw_plane_wm->trans_wm)) {
+                       DRM_ERROR("mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
+                                 pipe_name(pipe), plane + 1,
+                                 sw_plane_wm->trans_wm.plane_en,
+                                 sw_plane_wm->trans_wm.plane_res_b,
+                                 sw_plane_wm->trans_wm.plane_res_l,
+                                 hw_plane_wm->trans_wm.plane_en,
+                                 hw_plane_wm->trans_wm.plane_res_b,
+                                 hw_plane_wm->trans_wm.plane_res_l);
+               }
+
+               /* DDB */
+               hw_ddb_entry = &hw_ddb.plane[pipe][plane];
+               sw_ddb_entry = &sw_ddb->plane[pipe][plane];
+
+               if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
+                       DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
+                                 pipe_name(pipe), plane + 1,
+                                 sw_ddb_entry->start, sw_ddb_entry->end,
+                                 hw_ddb_entry->start, hw_ddb_entry->end);
+               }
        }
 
        /*
@@ -13476,15 +13535,46 @@ static void verify_wm_state(struct drm_crtc *crtc,
         * once the plane becomes visible, we can skip this check
         */
        if (intel_crtc->cursor_addr) {
-               hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
-               sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
+               hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
+               sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
 
-               if (!skl_ddb_entry_equal(hw_entry, sw_entry)) {
-                       DRM_ERROR("mismatch in DDB state pipe %c cursor "
-                                 "(expected (%u,%u), found (%u,%u))\n",
+               /* Watermarks */
+               for (level = 0; level <= max_level; level++) {
+                       if (skl_wm_level_equals(&hw_plane_wm->wm[level],
+                                               &sw_plane_wm->wm[level]))
+                               continue;
+
+                       DRM_ERROR("mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
+                                 pipe_name(pipe), level,
+                                 sw_plane_wm->wm[level].plane_en,
+                                 sw_plane_wm->wm[level].plane_res_b,
+                                 sw_plane_wm->wm[level].plane_res_l,
+                                 hw_plane_wm->wm[level].plane_en,
+                                 hw_plane_wm->wm[level].plane_res_b,
+                                 hw_plane_wm->wm[level].plane_res_l);
+               }
+
+               if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
+                                        &sw_plane_wm->trans_wm)) {
+                       DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
+                                 pipe_name(pipe),
+                                 sw_plane_wm->trans_wm.plane_en,
+                                 sw_plane_wm->trans_wm.plane_res_b,
+                                 sw_plane_wm->trans_wm.plane_res_l,
+                                 hw_plane_wm->trans_wm.plane_en,
+                                 hw_plane_wm->trans_wm.plane_res_b,
+                                 hw_plane_wm->trans_wm.plane_res_l);
+               }
+
+               /* DDB */
+               hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR];
+               sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR];
+
+               if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
+                       DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
                                  pipe_name(pipe),
-                                 sw_entry->start, sw_entry->end,
-                                 hw_entry->start, hw_entry->end);
+                                 sw_ddb_entry->start, sw_ddb_entry->end,
+                                 hw_ddb_entry->start, hw_ddb_entry->end);
                }
        }
 }
@@ -14242,12 +14332,11 @@ static void skl_update_crtcs(struct drm_atomic_state *state,
                             unsigned int *crtc_vblank_mask)
 {
        struct drm_device *dev = state->dev;
-       struct drm_i915_private *dev_priv = to_i915(dev);
        struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
        struct drm_crtc *crtc;
+       struct intel_crtc *intel_crtc;
        struct drm_crtc_state *old_crtc_state;
-       struct skl_ddb_allocation *new_ddb = &intel_state->wm_results.ddb;
-       struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb;
+       struct intel_crtc_state *cstate;
        unsigned int updated = 0;
        bool progress;
        enum pipe pipe;
@@ -14265,12 +14354,14 @@ static void skl_update_crtcs(struct drm_atomic_state *state,
                for_each_crtc_in_state(state, crtc, old_crtc_state, i) {
                        bool vbl_wait = false;
                        unsigned int cmask = drm_crtc_mask(crtc);
-                       pipe = to_intel_crtc(crtc)->pipe;
+
+                       intel_crtc = to_intel_crtc(crtc);
+                       cstate = to_intel_crtc_state(crtc->state);
+                       pipe = intel_crtc->pipe;
 
                        if (updated & cmask || !crtc->state->active)
                                continue;
-                       if (skl_ddb_allocation_overlaps(state, cur_ddb, new_ddb,
-                                                       pipe))
+                       if (skl_ddb_allocation_overlaps(state, intel_crtc))
                                continue;
 
                        updated |= cmask;
@@ -14281,7 +14372,8 @@ static void skl_update_crtcs(struct drm_atomic_state *state,
                         * then we need to wait for a vblank to pass for the
                         * new ddb allocation to take effect.
                         */
-                       if (!skl_ddb_allocation_equals(cur_ddb, new_ddb, pipe) &&
+                       if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
+                                                &intel_crtc->hw_ddb) &&
                            !crtc->state->active_changed &&
                            intel_state->wm_results.dirty_pipes != updated)
                                vbl_wait = true;
@@ -14461,7 +14553,7 @@ static void intel_atomic_commit_tail(struct drm_atomic_state *state)
 
        drm_atomic_helper_commit_cleanup_done(state);
 
-       drm_atomic_state_free(state);
+       drm_atomic_state_put(state);
 
        /* As one of the primary mmio accessors, KMS has a high likelihood
         * of triggering bugs in unclaimed access. After we finish
@@ -14544,6 +14636,7 @@ static int intel_atomic_commit(struct drm_device *dev,
        intel_shared_dpll_commit(state);
        intel_atomic_track_fbs(state);
 
+       drm_atomic_state_get(state);
        if (nonblock)
                queue_work(system_unbound_wq, &state->commit_work);
        else
@@ -14585,9 +14678,8 @@ retry:
                goto retry;
        }
 
-       if (ret)
 out:
-               drm_atomic_state_free(state);
+       drm_atomic_state_put(state);
 }
 
 /*
@@ -14838,6 +14930,8 @@ static void intel_begin_crtc_commit(struct drm_crtc *crtc,
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = to_i915(dev);
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+       struct intel_crtc_state *intel_cstate =
+               to_intel_crtc_state(crtc->state);
        struct intel_crtc_state *old_intel_state =
                to_intel_crtc_state(old_crtc_state);
        bool modeset = needs_modeset(crtc->state);
@@ -14854,13 +14948,13 @@ static void intel_begin_crtc_commit(struct drm_crtc *crtc,
                intel_color_load_luts(crtc->state);
        }
 
-       if (to_intel_crtc_state(crtc->state)->update_pipe)
+       if (intel_cstate->update_pipe) {
                intel_update_pipe_config(intel_crtc, old_intel_state);
-       else if (INTEL_GEN(dev_priv) >= 9) {
+       else if (INTEL_GEN(dev_priv) >= 9) {
                skl_detach_scalers(intel_crtc);
 
                I915_WRITE(PIPE_WM_LINETIME(pipe),
-                          dev_priv->wm.skl_hw.wm_linetime[pipe]);
+                          intel_cstate->wm.skl.optimal.linetime);
        }
 }
 
@@ -14907,6 +15001,7 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
        struct intel_plane *primary = NULL;
        struct intel_plane_state *state = NULL;
        const uint32_t *intel_primary_formats;
+       unsigned int supported_rotations;
        unsigned int num_formats;
        int ret;
 
@@ -14964,7 +15059,7 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
                                               intel_primary_formats, num_formats,
                                               DRM_PLANE_TYPE_PRIMARY,
                                               "plane 1%c", pipe_name(pipe));
-       else if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
+       else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
                ret = drm_universal_plane_init(dev, &primary->base, 0,
                                               &intel_plane_funcs,
                                               intel_primary_formats, num_formats,
@@ -14979,8 +15074,21 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
        if (ret)
                goto fail;
 
-       if (INTEL_INFO(dev)->gen >= 4)
-               intel_create_rotation_property(dev, primary);
+       if (INTEL_GEN(dev_priv) >= 9) {
+               supported_rotations =
+                       DRM_ROTATE_0 | DRM_ROTATE_90 |
+                       DRM_ROTATE_180 | DRM_ROTATE_270;
+       } else if (INTEL_GEN(dev_priv) >= 4) {
+               supported_rotations =
+                       DRM_ROTATE_0 | DRM_ROTATE_180;
+       } else {
+               supported_rotations = DRM_ROTATE_0;
+       }
+
+       if (INTEL_GEN(dev_priv) >= 4)
+               drm_plane_create_rotation_property(&primary->base,
+                                                  DRM_ROTATE_0,
+                                                  supported_rotations);
 
        drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
 
@@ -14993,24 +15101,6 @@ fail:
        return NULL;
 }
 
-void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane)
-{
-       if (!dev->mode_config.rotation_property) {
-               unsigned long flags = DRM_ROTATE_0 |
-                       DRM_ROTATE_180;
-
-               if (INTEL_INFO(dev)->gen >= 9)
-                       flags |= DRM_ROTATE_90 | DRM_ROTATE_270;
-
-               dev->mode_config.rotation_property =
-                       drm_mode_create_rotation_property(dev, flags);
-       }
-       if (dev->mode_config.rotation_property)
-               drm_object_attach_property(&plane->base.base,
-                               dev->mode_config.rotation_property,
-                               plane->base.state->rotation);
-}
-
 static int
 intel_check_cursor_plane(struct drm_plane *plane,
                         struct intel_crtc_state *crtc_state,
@@ -15063,7 +15153,7 @@ intel_check_cursor_plane(struct drm_plane *plane,
         * display power well must be turned off and on again.
         * Refuse the put the cursor into that compromised position.
         */
-       if (IS_CHERRYVIEW(plane->dev) && pipe == PIPE_C &&
+       if (IS_CHERRYVIEW(to_i915(plane->dev)) && pipe == PIPE_C &&
            state->base.visible && state->base.crtc_x < 0) {
                DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
                return -EINVAL;
@@ -15107,6 +15197,7 @@ intel_update_cursor_plane(struct drm_plane *plane,
 static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
                                                   int pipe)
 {
+       struct drm_i915_private *dev_priv = to_i915(dev);
        struct intel_plane *cursor = NULL;
        struct intel_plane_state *state = NULL;
        int ret;
@@ -15138,17 +15229,11 @@ static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
        if (ret)
                goto fail;
 
-       if (INTEL_INFO(dev)->gen >= 4) {
-               if (!dev->mode_config.rotation_property)
-                       dev->mode_config.rotation_property =
-                               drm_mode_create_rotation_property(dev,
-                                                       DRM_ROTATE_0 |
-                                                       DRM_ROTATE_180);
-               if (dev->mode_config.rotation_property)
-                       drm_object_attach_property(&cursor->base.base,
-                               dev->mode_config.rotation_property,
-                               state->base.rotation);
-       }
+       if (INTEL_GEN(dev_priv) >= 4)
+               drm_plane_create_rotation_property(&cursor->base,
+                                                  DRM_ROTATE_0,
+                                                  DRM_ROTATE_0 |
+                                                  DRM_ROTATE_180);
 
        if (INTEL_INFO(dev)->gen >=9)
                state->scaler_id = -1;
@@ -15317,7 +15402,7 @@ static bool has_edp_a(struct drm_device *dev)
        if ((I915_READ(DP_A) & DP_DETECTED) == 0)
                return false;
 
-       if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
+       if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
                return false;
 
        return true;
@@ -15333,7 +15418,7 @@ static bool intel_crt_present(struct drm_device *dev)
        if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
                return false;
 
-       if (IS_CHERRYVIEW(dev))
+       if (IS_CHERRYVIEW(dev_priv))
                return false;
 
        if (HAS_PCH_LPT_H(dev_priv) &&
@@ -15474,7 +15559,7 @@ static void intel_setup_outputs(struct drm_device *dev)
 
                if (I915_READ(PCH_DP_D) & DP_DETECTED)
                        intel_dp_init(dev, PCH_DP_D, PORT_D);
-       } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
+       } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
                bool has_edp, has_port;
 
                /*
@@ -15506,7 +15591,7 @@ static void intel_setup_outputs(struct drm_device *dev)
                if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
                        intel_hdmi_init(dev, VLV_HDMIC, PORT_C);
 
-               if (IS_CHERRYVIEW(dev)) {
+               if (IS_CHERRYVIEW(dev_priv)) {
                        /*
                         * eDP not supported on port D,
                         * so no need to worry about it
@@ -15519,18 +15604,18 @@ static void intel_setup_outputs(struct drm_device *dev)
                }
 
                intel_dsi_init(dev);
-       } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) {
+       } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) {
                bool found = false;
 
                if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
                        DRM_DEBUG_KMS("probing SDVOB\n");
                        found = intel_sdvo_init(dev, GEN3_SDVOB, PORT_B);
-                       if (!found && IS_G4X(dev)) {
+                       if (!found && IS_G4X(dev_priv)) {
                                DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
                                intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
                        }
 
-                       if (!found && IS_G4X(dev))
+                       if (!found && IS_G4X(dev_priv))
                                intel_dp_init(dev, DP_B, PORT_B);
                }
 
@@ -15543,18 +15628,17 @@ static void intel_setup_outputs(struct drm_device *dev)
 
                if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
 
-                       if (IS_G4X(dev)) {
+                       if (IS_G4X(dev_priv)) {
                                DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
                                intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
                        }
-                       if (IS_G4X(dev))
+                       if (IS_G4X(dev_priv))
                                intel_dp_init(dev, DP_C, PORT_C);
                }
 
-               if (IS_G4X(dev) &&
-                   (I915_READ(DP_D) & DP_DETECTED))
+               if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
                        intel_dp_init(dev, DP_D, PORT_D);
-       } else if (IS_GEN2(dev))
+       } else if (IS_GEN2(dev_priv))
                intel_dvo_init(dev);
 
        if (SUPPORTS_TV(dev))
@@ -15625,10 +15709,10 @@ static const struct drm_framebuffer_funcs intel_fb_funcs = {
 };
 
 static
-u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier,
-                        uint32_t pixel_format)
+u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
+                        uint64_t fb_modifier, uint32_t pixel_format)
 {
-       u32 gen = INTEL_INFO(dev)->gen;
+       u32 gen = INTEL_INFO(dev_priv)->gen;
 
        if (gen >= 9) {
                int cpp = drm_format_plane_cpp(pixel_format, 0);
@@ -15637,7 +15721,8 @@ u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier,
                 *  pixels and 32K bytes."
                 */
                return min(8192 * cpp, 32768);
-       } else if (gen >= 5 && !IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) {
+       } else if (gen >= 5 && !IS_VALLEYVIEW(dev_priv) &&
+                  !IS_CHERRYVIEW(dev_priv)) {
                return 32*1024;
        } else if (gen >= 4) {
                if (fb_modifier == I915_FORMAT_MOD_X_TILED)
@@ -15724,7 +15809,7 @@ static int intel_framebuffer_init(struct drm_device *dev,
                return -EINVAL;
        }
 
-       pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0],
+       pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0],
                                           mode_cmd->pixel_format);
        if (mode_cmd->pitches[0] > pitch_limit) {
                DRM_DEBUG("%s pitch (%u) must be at less than %d\n",
@@ -15762,7 +15847,7 @@ static int intel_framebuffer_init(struct drm_device *dev,
                }
                break;
        case DRM_FORMAT_ABGR8888:
-               if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) &&
+               if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
                    INTEL_INFO(dev)->gen < 9) {
                        format_name = drm_get_format_name(mode_cmd->pixel_format);
                        DRM_DEBUG("unsupported pixel format: %s\n", format_name);
@@ -15781,7 +15866,7 @@ static int intel_framebuffer_init(struct drm_device *dev,
                }
                break;
        case DRM_FORMAT_ABGR2101010:
-               if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) {
+               if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
                        format_name = drm_get_format_name(mode_cmd->pixel_format);
                        DRM_DEBUG("unsupported pixel format: %s\n", format_name);
                        kfree(format_name);
@@ -16228,7 +16313,7 @@ static void i915_disable_vga(struct drm_device *dev)
        struct drm_i915_private *dev_priv = to_i915(dev);
        struct pci_dev *pdev = dev_priv->drm.pdev;
        u8 sr1;
-       i915_reg_t vga_reg = i915_vgacntrl_reg(dev);
+       i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
 
        /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
        vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
@@ -16316,7 +16401,7 @@ retry:
                 * BIOS-programmed watermarks untouched and hope for the best.
                 */
                WARN(true, "Could not determine valid watermarks for inherited state\n");
-               goto fail;
+               goto put_state;
        }
 
        /* Write calculated watermark values back */
@@ -16327,7 +16412,8 @@ retry:
                dev_priv->display.optimize_watermarks(cs);
        }
 
-       drm_atomic_state_free(state);
+put_state:
+       drm_atomic_state_put(state);
 fail:
        drm_modeset_drop_locks(&ctx);
        drm_modeset_acquire_fini(&ctx);
@@ -16378,10 +16464,10 @@ void intel_modeset_init(struct drm_device *dev)
                }
        }
 
-       if (IS_GEN2(dev)) {
+       if (IS_GEN2(dev_priv)) {
                dev->mode_config.max_width = 2048;
                dev->mode_config.max_height = 2048;
-       } else if (IS_GEN3(dev)) {
+       } else if (IS_GEN3(dev_priv)) {
                dev->mode_config.max_width = 4096;
                dev->mode_config.max_height = 4096;
        } else {
@@ -16392,7 +16478,7 @@ void intel_modeset_init(struct drm_device *dev)
        if (IS_845G(dev_priv) || IS_I865G(dev_priv)) {
                dev->mode_config.cursor_width = IS_845G(dev_priv) ? 64 : 512;
                dev->mode_config.cursor_height = 1023;
-       } else if (IS_GEN2(dev)) {
+       } else if (IS_GEN2(dev_priv)) {
                dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
                dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
        } else {
@@ -16673,7 +16759,7 @@ static void intel_sanitize_encoder(struct intel_encoder *encoder)
 void i915_redisable_vga_power_on(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = to_i915(dev);
-       i915_reg_t vga_reg = i915_vgacntrl_reg(dev);
+       i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
 
        if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
                DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
@@ -16911,9 +16997,9 @@ intel_modeset_setup_hw_state(struct drm_device *dev)
                pll->on = false;
        }
 
-       if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
+       if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
                vlv_wm_get_hw_state(dev);
-       else if (IS_GEN9(dev))
+       else if (IS_GEN9(dev_priv))
                skl_wm_get_hw_state(dev);
        else if (HAS_PCH_SPLIT(dev_priv))
                ilk_wm_get_hw_state(dev);
@@ -16965,10 +17051,9 @@ void intel_display_resume(struct drm_device *dev)
        drm_modeset_acquire_fini(&ctx);
        mutex_unlock(&dev->mode_config.mutex);
 
-       if (ret) {
+       if (ret)
                DRM_ERROR("Restoring old state failed with %i\n", ret);
-               drm_atomic_state_free(state);
-       }
+       drm_atomic_state_put(state);
 }
 
 void intel_modeset_gem_init(struct drm_device *dev)