Merge tag 'drm-intel-next-2015-02-27' of git://anongit.freedesktop.org/drm-intel...
authorDave Airlie <airlied@redhat.com>
Mon, 9 Mar 2015 09:41:15 +0000 (19:41 +1000)
committerDave Airlie <airlied@redhat.com>
Mon, 9 Mar 2015 09:41:15 +0000 (19:41 +1000)
- Y tiling support for scanout from Tvrtko&Damien
- Remove more UMS support
- some small prep patches for OLR removal from John Harrison
- first few patches for dynamic pagetable allocation from Ben Widawsky, rebased
  by tons of other people
- DRRS support patches (Sonika&Vandana)
- fbc patches from Paulo
- make sure our vblank callbacks aren't called when the pipes are off
- various patches all over

* tag 'drm-intel-next-2015-02-27' of git://anongit.freedesktop.org/drm-intel: (61 commits)
  drm/i915: Update DRIVER_DATE to 20150227
  drm/i915: Clarify obj->map_and_fenceable
  drm/i915/skl: Allow Y (and Yf) frame buffer creation
  drm/i915/skl: Update watermarks for Y tiling
  drm/i915/skl: Updated watermark programming
  drm/i915/skl: Adjust get_plane_config() to support Yb/Yf tiling
  drm/i915/skl: Teach pin_and_fence_fb_obj() about Y tiling constraints
  drm/i915/skl: Adjust intel_fb_align_height() for Yb/Yf tiling
  drm/i915/skl: Allow scanning out Y and Yf fbs
  drm/i915/skl: Add new displayable tiling formats
  drm/i915: Remove DRIVER_MODESET checks from modeset code
  drm/i915: Remove regfile code&data for UMS suspend/resume
  drm/i915: Remove DRIVER_MODESET checks from gem code
  drm/i915: Remove DRIVER_MODESET checks in the gpu reset code
  drm/i915: Remove DRIVER_MODESET checks from suspend/resume code
  drm/i915: Remove DRIVER_MODESET checks in load/unload/close code
  drm/i915: fix a printk format
  drm/i915: Add media rc6 residency file to sysfs
  drm/i915: Add missing description to parameter in alloc_pt_range
  drm/i915: Removed the read of RP_STATE_CAP from sysfs/debugfs functions
  ...

14 files changed:
1  2 
drivers/gpu/drm/drm_irq.c
drivers/gpu/drm/i915/i915_debugfs.c
drivers/gpu/drm/i915/i915_drv.c
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_gem.c
drivers/gpu/drm/i915/intel_display.c
drivers/gpu/drm/i915/intel_dp.c
drivers/gpu/drm/i915/intel_drv.h
drivers/gpu/drm/i915/intel_lrc.c
drivers/gpu/drm/i915/intel_pm.c
drivers/gpu/drm/i915/intel_ringbuffer.c
drivers/gpu/drm/i915/intel_uncore.c
include/drm/drmP.h
include/uapi/drm/drm_fourcc.h

@@@ -185,15 -185,8 +185,15 @@@ static void vblank_disable_and_save(str
                return;
        }
  
 -      dev->driver->disable_vblank(dev, crtc);
 -      vblank->enabled = false;
 +      /*
 +       * Only disable vblank interrupts if they're enabled. This avoids
 +       * calling the ->disable_vblank() operation in atomic context with the
 +       * hardware potentially runtime suspended.
 +       */
 +      if (vblank->enabled) {
 +              dev->driver->disable_vblank(dev, crtc);
 +              vblank->enabled = false;
 +      }
  
        /* No further vblank irq's will be processed after
         * this point. Get current hardware vblank count and
@@@ -276,7 -269,6 +276,6 @@@ static void vblank_disable_fn(unsigned 
  void drm_vblank_cleanup(struct drm_device *dev)
  {
        int crtc;
-       unsigned long irqflags;
  
        /* Bail if the driver didn't call drm_vblank_init() */
        if (dev->num_crtcs == 0)
        for (crtc = 0; crtc < dev->num_crtcs; crtc++) {
                struct drm_vblank_crtc *vblank = &dev->vblank[crtc];
  
-               del_timer_sync(&vblank->disable_timer);
+               WARN_ON(vblank->enabled &&
+                       drm_core_check_feature(dev, DRIVER_MODESET));
  
-               spin_lock_irqsave(&dev->vbl_lock, irqflags);
-               vblank_disable_and_save(dev, crtc);
-               spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
+               del_timer_sync(&vblank->disable_timer);
        }
  
        kfree(dev->vblank);
@@@ -475,17 -466,23 +473,23 @@@ int drm_irq_uninstall(struct drm_devic
        dev->irq_enabled = false;
  
        /*
-        * Wake up any waiters so they don't hang.
+        * Wake up any waiters so they don't hang. This is just to paper over
+        * isssues for UMS drivers which aren't in full control of their
+        * vblank/irq handling. KMS drivers must ensure that vblanks are all
+        * disabled when uninstalling the irq handler.
         */
        if (dev->num_crtcs) {
                spin_lock_irqsave(&dev->vbl_lock, irqflags);
                for (i = 0; i < dev->num_crtcs; i++) {
                        struct drm_vblank_crtc *vblank = &dev->vblank[i];
  
+                       if (!vblank->enabled)
+                               continue;
+                       WARN_ON(drm_core_check_feature(dev, DRIVER_MODESET));
+                       vblank_disable_and_save(dev, i);
                        wake_up(&vblank->queue);
-                       vblank->enabled = false;
-                       vblank->last =
-                               dev->driver->get_vblank_counter(dev, i);
                }
                spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
        }
@@@ -1052,7 -1049,7 +1056,7 @@@ EXPORT_SYMBOL(drm_vblank_get)
   * Acquire a reference count on vblank events to avoid having them disabled
   * while in use.
   *
 - * This is the native kms version of drm_vblank_off().
 + * This is the native kms version of drm_vblank_get().
   *
   * Returns:
   * Zero on success, nonzero on failure.
@@@ -1232,6 -1229,38 +1236,38 @@@ void drm_crtc_vblank_off(struct drm_crt
  }
  EXPORT_SYMBOL(drm_crtc_vblank_off);
  
+ /**
+  * drm_crtc_vblank_reset - reset vblank state to off on a CRTC
+  * @crtc: CRTC in question
+  *
+  * Drivers can use this function to reset the vblank state to off at load time.
+  * Drivers should use this together with the drm_crtc_vblank_off() and
+  * drm_crtc_vblank_on() functions. The difference compared to
+  * drm_crtc_vblank_off() is that this function doesn't save the vblank counter
+  * and hence doesn't need to call any driver hooks.
+  */
+ void drm_crtc_vblank_reset(struct drm_crtc *drm_crtc)
+ {
+       struct drm_device *dev = drm_crtc->dev;
+       unsigned long irqflags;
+       int crtc = drm_crtc_index(drm_crtc);
+       struct drm_vblank_crtc *vblank = &dev->vblank[crtc];
+       spin_lock_irqsave(&dev->vbl_lock, irqflags);
+       /*
+        * Prevent subsequent drm_vblank_get() from enabling the vblank
+        * interrupt by bumping the refcount.
+        */
+       if (!vblank->inmodeset) {
+               atomic_inc(&vblank->refcount);
+               vblank->inmodeset = 1;
+       }
+       spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
+       WARN_ON(!list_empty(&dev->vblank_event_list));
+ }
+ EXPORT_SYMBOL(drm_crtc_vblank_reset);
  /**
   * drm_vblank_on - enable vblank events on a CRTC
   * @dev: DRM device
@@@ -1653,7 -1682,7 +1689,7 @@@ bool drm_handle_vblank(struct drm_devic
        struct timeval tvblank;
        unsigned long irqflags;
  
-       if (!dev->num_crtcs)
+       if (WARN_ON_ONCE(!dev->num_crtcs))
                return false;
  
        if (WARN_ON(crtc >= dev->num_crtcs))
@@@ -139,10 -139,11 +139,11 @@@ describe_obj(struct seq_file *m, struc
                   obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
        if (obj->base.name)
                seq_printf(m, " (name: %d)", obj->base.name);
-       list_for_each_entry(vma, &obj->vma_list, vma_link)
+       list_for_each_entry(vma, &obj->vma_list, vma_link) {
                if (vma->pin_count > 0)
                        pin_count++;
-               seq_printf(m, " (pinned x %d)", pin_count);
+       }
+       seq_printf(m, " (pinned x %d)", pin_count);
        if (obj->pin_display)
                seq_printf(m, " (display)");
        if (obj->fence_reg != I915_FENCE_REG_NONE)
@@@ -580,7 -581,7 +581,7 @@@ static int i915_gem_pageflip_info(struc
                        seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
                                   work->flip_queued_vblank,
                                   work->flip_ready_vblank,
-                                  drm_vblank_count(dev, crtc->pipe));
+                                  drm_crtc_vblank_count(&crtc->base));
                        if (work->enable_stall_check)
                                seq_puts(m, "Stall check enabled, ");
                        else
  static int i915_hangcheck_info(struct seq_file *m, void *unused)
  {
        struct drm_info_node *node = m->private;
 -      struct drm_i915_private *dev_priv = to_i915(node->minor->dev);
 +      struct drm_device *dev = node->minor->dev;
 +      struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_engine_cs *ring;
 +      u64 acthd[I915_NUM_RINGS];
 +      u32 seqno[I915_NUM_RINGS];
        int i;
  
        if (!i915.enable_hangcheck) {
                return 0;
        }
  
 +      intel_runtime_pm_get(dev_priv);
 +
 +      for_each_ring(ring, dev_priv, i) {
 +              seqno[i] = ring->get_seqno(ring, false);
 +              acthd[i] = intel_ring_get_active_head(ring);
 +      }
 +
 +      intel_runtime_pm_put(dev_priv);
 +
        if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
                seq_printf(m, "Hangcheck active, fires in %dms\n",
                           jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
        for_each_ring(ring, dev_priv, i) {
                seq_printf(m, "%s:\n", ring->name);
                seq_printf(m, "\tseqno = %x [current %x]\n",
 -                         ring->hangcheck.seqno, ring->get_seqno(ring, false));
 -              seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
 -              seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
 +                         ring->hangcheck.seqno, seqno[i]);
                seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
                           (long long)ring->hangcheck.acthd,
 -                         (long long)intel_ring_get_active_head(ring));
 +                         (long long)acthd[i]);
                seq_printf(m, "\tmax ACTHD = 0x%08llx\n",
                           (long long)ring->hangcheck.max_acthd);
 +              seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
 +              seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
        }
  
        return 0;
@@@ -2185,7 -2174,7 +2186,7 @@@ static void gen6_ppgtt_info(struct seq_
                struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
  
                seq_puts(m, "aliasing PPGTT:\n");
-               seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
+               seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.pd_offset);
  
                ppgtt->debug_dump(ppgtt, m);
        }
@@@ -4191,7 -4180,7 +4192,7 @@@ i915_max_freq_set(void *data, u64 val
  {
        struct drm_device *dev = data;
        struct drm_i915_private *dev_priv = dev->dev_private;
-       u32 rp_state_cap, hw_max, hw_min;
+       u32 hw_max, hw_min;
        int ret;
  
        if (INTEL_INFO(dev)->gen < 6)
        /*
         * Turbo will still be enabled, but won't go above the set value.
         */
-       if (IS_VALLEYVIEW(dev)) {
-               val = intel_freq_opcode(dev_priv, val);
+       val = intel_freq_opcode(dev_priv, val);
  
-               hw_max = dev_priv->rps.max_freq;
-               hw_min = dev_priv->rps.min_freq;
-       } else {
-               val = intel_freq_opcode(dev_priv, val);
-               rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
-               hw_max = dev_priv->rps.max_freq;
-               hw_min = (rp_state_cap >> 16) & 0xff;
-       }
+       hw_max = dev_priv->rps.max_freq;
+       hw_min = dev_priv->rps.min_freq;
  
        if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
                mutex_unlock(&dev_priv->rps.hw_lock);
@@@ -4266,7 -4247,7 +4259,7 @@@ i915_min_freq_set(void *data, u64 val
  {
        struct drm_device *dev = data;
        struct drm_i915_private *dev_priv = dev->dev_private;
-       u32 rp_state_cap, hw_max, hw_min;
+       u32 hw_max, hw_min;
        int ret;
  
        if (INTEL_INFO(dev)->gen < 6)
        /*
         * Turbo will still be enabled, but won't go below the set value.
         */
-       if (IS_VALLEYVIEW(dev)) {
-               val = intel_freq_opcode(dev_priv, val);
+       val = intel_freq_opcode(dev_priv, val);
  
-               hw_max = dev_priv->rps.max_freq;
-               hw_min = dev_priv->rps.min_freq;
-       } else {
-               val = intel_freq_opcode(dev_priv, val);
-               rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
-               hw_max = dev_priv->rps.max_freq;
-               hw_min = (rp_state_cap >> 16) & 0xff;
-       }
+       hw_max = dev_priv->rps.max_freq;
+       hw_min = dev_priv->rps.min_freq;
  
        if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
                mutex_unlock(&dev_priv->rps.hw_lock);
@@@ -4370,6 -4343,85 +4355,85 @@@ DEFINE_SIMPLE_ATTRIBUTE(i915_cache_shar
                        i915_cache_sharing_get, i915_cache_sharing_set,
                        "%llu\n");
  
+ static int i915_sseu_status(struct seq_file *m, void *unused)
+ {
+       struct drm_info_node *node = (struct drm_info_node *) m->private;
+       struct drm_device *dev = node->minor->dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       unsigned int s_tot = 0, ss_tot = 0, ss_per = 0, eu_tot = 0, eu_per = 0;
+       if (INTEL_INFO(dev)->gen < 9)
+               return -ENODEV;
+       seq_puts(m, "SSEU Device Info\n");
+       seq_printf(m, "  Available Slice Total: %u\n",
+                  INTEL_INFO(dev)->slice_total);
+       seq_printf(m, "  Available Subslice Total: %u\n",
+                  INTEL_INFO(dev)->subslice_total);
+       seq_printf(m, "  Available Subslice Per Slice: %u\n",
+                  INTEL_INFO(dev)->subslice_per_slice);
+       seq_printf(m, "  Available EU Total: %u\n",
+                  INTEL_INFO(dev)->eu_total);
+       seq_printf(m, "  Available EU Per Subslice: %u\n",
+                  INTEL_INFO(dev)->eu_per_subslice);
+       seq_printf(m, "  Has Slice Power Gating: %s\n",
+                  yesno(INTEL_INFO(dev)->has_slice_pg));
+       seq_printf(m, "  Has Subslice Power Gating: %s\n",
+                  yesno(INTEL_INFO(dev)->has_subslice_pg));
+       seq_printf(m, "  Has EU Power Gating: %s\n",
+                  yesno(INTEL_INFO(dev)->has_eu_pg));
+       seq_puts(m, "SSEU Device Status\n");
+       if (IS_SKYLAKE(dev)) {
+               const int s_max = 3, ss_max = 4;
+               int s, ss;
+               u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
+               s_reg[0] = I915_READ(GEN9_SLICE0_PGCTL_ACK);
+               s_reg[1] = I915_READ(GEN9_SLICE1_PGCTL_ACK);
+               s_reg[2] = I915_READ(GEN9_SLICE2_PGCTL_ACK);
+               eu_reg[0] = I915_READ(GEN9_SLICE0_SS01_EU_PGCTL_ACK);
+               eu_reg[1] = I915_READ(GEN9_SLICE0_SS23_EU_PGCTL_ACK);
+               eu_reg[2] = I915_READ(GEN9_SLICE1_SS01_EU_PGCTL_ACK);
+               eu_reg[3] = I915_READ(GEN9_SLICE1_SS23_EU_PGCTL_ACK);
+               eu_reg[4] = I915_READ(GEN9_SLICE2_SS01_EU_PGCTL_ACK);
+               eu_reg[5] = I915_READ(GEN9_SLICE2_SS23_EU_PGCTL_ACK);
+               eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
+                            GEN9_PGCTL_SSA_EU19_ACK |
+                            GEN9_PGCTL_SSA_EU210_ACK |
+                            GEN9_PGCTL_SSA_EU311_ACK;
+               eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
+                            GEN9_PGCTL_SSB_EU19_ACK |
+                            GEN9_PGCTL_SSB_EU210_ACK |
+                            GEN9_PGCTL_SSB_EU311_ACK;
+               for (s = 0; s < s_max; s++) {
+                       if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
+                               /* skip disabled slice */
+                               continue;
+                       s_tot++;
+                       ss_per = INTEL_INFO(dev)->subslice_per_slice;
+                       ss_tot += ss_per;
+                       for (ss = 0; ss < ss_max; ss++) {
+                               unsigned int eu_cnt;
+                               eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
+                                                      eu_mask[ss%2]);
+                               eu_tot += eu_cnt;
+                               eu_per = max(eu_per, eu_cnt);
+                       }
+               }
+       }
+       seq_printf(m, "  Enabled Slice Total: %u\n", s_tot);
+       seq_printf(m, "  Enabled Subslice Total: %u\n", ss_tot);
+       seq_printf(m, "  Enabled Subslice Per Slice: %u\n", ss_per);
+       seq_printf(m, "  Enabled EU Total: %u\n", eu_tot);
+       seq_printf(m, "  Enabled EU Per Subslice: %u\n", eu_per);
+       return 0;
+ }
  static int i915_forcewake_open(struct inode *inode, struct file *file)
  {
        struct drm_device *dev = inode->i_private;
@@@ -4483,6 -4535,7 +4547,7 @@@ static const struct drm_info_list i915_
        {"i915_dp_mst_info", i915_dp_mst_info, 0},
        {"i915_wa_registers", i915_wa_registers, 0},
        {"i915_ddb_info", i915_ddb_info, 0},
+       {"i915_sseu_status", i915_sseu_status, 0},
  };
  #define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
  
@@@ -477,13 -477,19 +477,13 @@@ void intel_detect_pch(struct drm_devic
                        } else if (id == INTEL_PCH_LPT_DEVICE_ID_TYPE) {
                                dev_priv->pch_type = PCH_LPT;
                                DRM_DEBUG_KMS("Found LynxPoint PCH\n");
 -                              WARN_ON(!IS_HASWELL(dev));
 -                              WARN_ON(IS_HSW_ULT(dev));
 -                      } else if (IS_BROADWELL(dev)) {
 -                              dev_priv->pch_type = PCH_LPT;
 -                              dev_priv->pch_id =
 -                                      INTEL_PCH_LPT_LP_DEVICE_ID_TYPE;
 -                              DRM_DEBUG_KMS("This is Broadwell, assuming "
 -                                            "LynxPoint LP PCH\n");
 +                              WARN_ON(!IS_HASWELL(dev) && !IS_BROADWELL(dev));
 +                              WARN_ON(IS_HSW_ULT(dev) || IS_BDW_ULT(dev));
                        } else if (id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
                                dev_priv->pch_type = PCH_LPT;
                                DRM_DEBUG_KMS("Found LynxPoint LP PCH\n");
 -                              WARN_ON(!IS_HASWELL(dev));
 -                              WARN_ON(!IS_HSW_ULT(dev));
 +                              WARN_ON(!IS_HASWELL(dev) && !IS_BROADWELL(dev));
 +                              WARN_ON(!IS_HSW_ULT(dev) && !IS_BDW_ULT(dev));
                        } else if (id == INTEL_PCH_SPT_DEVICE_ID_TYPE) {
                                dev_priv->pch_type = PCH_SPT;
                                DRM_DEBUG_KMS("Found SunrisePoint PCH\n");
@@@ -568,6 -574,7 +568,7 @@@ static int i915_drm_suspend(struct drm_
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct drm_crtc *crtc;
        pci_power_t opregion_target_state;
+       int error;
  
        /* ignore lid events during suspend */
        mutex_lock(&dev_priv->modeset_restore_lock);
  
        pci_save_state(dev->pdev);
  
-       /* If KMS is active, we do the leavevt stuff here */
-       if (drm_core_check_feature(dev, DRIVER_MODESET)) {
-               int error;
+       error = i915_gem_suspend(dev);
+       if (error) {
+               dev_err(&dev->pdev->dev,
+                       "GEM idle failed, resume might fail\n");
+               return error;
+       }
  
-               error = i915_gem_suspend(dev);
-               if (error) {
-                       dev_err(&dev->pdev->dev,
-                               "GEM idle failed, resume might fail\n");
-                       return error;
-               }
+       intel_suspend_gt_powersave(dev);
  
-               intel_suspend_gt_powersave(dev);
+       /*
+        * Disable CRTCs directly since we want to preserve sw state
+        * for _thaw. Also, power gate the CRTC power wells.
+        */
+       drm_modeset_lock_all(dev);
+       for_each_crtc(dev, crtc)
+               intel_crtc_control(crtc, false);
+       drm_modeset_unlock_all(dev);
  
-               /*
-                * Disable CRTCs directly since we want to preserve sw state
-                * for _thaw. Also, power gate the CRTC power wells.
-                */
-               drm_modeset_lock_all(dev);
-               for_each_crtc(dev, crtc)
-                       intel_crtc_control(crtc, false);
-               drm_modeset_unlock_all(dev);
+       intel_dp_mst_suspend(dev);
  
-               intel_dp_mst_suspend(dev);
+       intel_runtime_pm_disable_interrupts(dev_priv);
+       intel_hpd_cancel_work(dev_priv);
  
-               intel_runtime_pm_disable_interrupts(dev_priv);
-               intel_hpd_cancel_work(dev_priv);
+       intel_suspend_encoders(dev_priv);
  
-               intel_suspend_encoders(dev_priv);
-               intel_suspend_hw(dev);
-       }
+       intel_suspend_hw(dev);
  
        i915_gem_suspend_gtt_mappings(dev);
  
@@@ -684,53 -686,48 +680,48 @@@ static int i915_drm_resume(struct drm_d
  {
        struct drm_i915_private *dev_priv = dev->dev_private;
  
-       if (drm_core_check_feature(dev, DRIVER_MODESET)) {
-               mutex_lock(&dev->struct_mutex);
-               i915_gem_restore_gtt_mappings(dev);
-               mutex_unlock(&dev->struct_mutex);
-       }
+       mutex_lock(&dev->struct_mutex);
+       i915_gem_restore_gtt_mappings(dev);
+       mutex_unlock(&dev->struct_mutex);
  
        i915_restore_state(dev);
        intel_opregion_setup(dev);
  
-       /* KMS EnterVT equivalent */
-       if (drm_core_check_feature(dev, DRIVER_MODESET)) {
-               intel_init_pch_refclk(dev);
-               drm_mode_config_reset(dev);
+       intel_init_pch_refclk(dev);
+       drm_mode_config_reset(dev);
  
-               mutex_lock(&dev->struct_mutex);
-               if (i915_gem_init_hw(dev)) {
-                       DRM_ERROR("failed to re-initialize GPU, declaring wedged!\n");
-                       atomic_set_mask(I915_WEDGED, &dev_priv->gpu_error.reset_counter);
-               }
-               mutex_unlock(&dev->struct_mutex);
+       mutex_lock(&dev->struct_mutex);
+       if (i915_gem_init_hw(dev)) {
+               DRM_ERROR("failed to re-initialize GPU, declaring wedged!\n");
+               atomic_set_mask(I915_WEDGED, &dev_priv->gpu_error.reset_counter);
+       }
+       mutex_unlock(&dev->struct_mutex);
  
-               /* We need working interrupts for modeset enabling ... */
-               intel_runtime_pm_enable_interrupts(dev_priv);
+       /* We need working interrupts for modeset enabling ... */
+       intel_runtime_pm_enable_interrupts(dev_priv);
  
-               intel_modeset_init_hw(dev);
+       intel_modeset_init_hw(dev);
  
-               spin_lock_irq(&dev_priv->irq_lock);
-               if (dev_priv->display.hpd_irq_setup)
-                       dev_priv->display.hpd_irq_setup(dev);
-               spin_unlock_irq(&dev_priv->irq_lock);
+       spin_lock_irq(&dev_priv->irq_lock);
+       if (dev_priv->display.hpd_irq_setup)
+               dev_priv->display.hpd_irq_setup(dev);
+       spin_unlock_irq(&dev_priv->irq_lock);
  
-               drm_modeset_lock_all(dev);
-               intel_modeset_setup_hw_state(dev, true);
-               drm_modeset_unlock_all(dev);
+       drm_modeset_lock_all(dev);
+       intel_modeset_setup_hw_state(dev, true);
+       drm_modeset_unlock_all(dev);
  
-               intel_dp_mst_resume(dev);
+       intel_dp_mst_resume(dev);
  
-               /*
-                * ... but also need to make sure that hotplug processing
-                * doesn't cause havoc. Like in the driver load code we don't
-                * bother with the tiny race here where we might loose hotplug
-                * notifications.
-                * */
-               intel_hpd_init(dev_priv);
-               /* Config may have changed between suspend and resume */
-               drm_helper_hpd_irq_event(dev);
-       }
+       /*
+        * ... but also need to make sure that hotplug processing
+        * doesn't cause havoc. Like in the driver load code we don't
+        * bother with the tiny race here where we might loose hotplug
+        * notifications.
+        * */
+       intel_hpd_init(dev_priv);
+       /* Config may have changed between suspend and resume */
+       drm_helper_hpd_irq_event(dev);
  
        intel_opregion_init(dev);
  
@@@ -866,38 -863,35 +857,35 @@@ int i915_reset(struct drm_device *dev
         * was running at the time of the reset (i.e. we weren't VT
         * switched away).
         */
-       if (drm_core_check_feature(dev, DRIVER_MODESET)) {
-               /* Used to prevent gem_check_wedged returning -EAGAIN during gpu reset */
-               dev_priv->gpu_error.reload_in_reset = true;
  
-               ret = i915_gem_init_hw(dev);
+       /* Used to prevent gem_check_wedged returning -EAGAIN during gpu reset */
+       dev_priv->gpu_error.reload_in_reset = true;
  
-               dev_priv->gpu_error.reload_in_reset = false;
+       ret = i915_gem_init_hw(dev);
  
-               mutex_unlock(&dev->struct_mutex);
-               if (ret) {
-                       DRM_ERROR("Failed hw init on reset %d\n", ret);
-                       return ret;
-               }
+       dev_priv->gpu_error.reload_in_reset = false;
  
-               /*
-                * FIXME: This races pretty badly against concurrent holders of
-                * ring interrupts. This is possible since we've started to drop
-                * dev->struct_mutex in select places when waiting for the gpu.
-                */
-               /*
-                * rps/rc6 re-init is necessary to restore state lost after the
-                * reset and the re-install of gt irqs. Skip for ironlake per
-                * previous concerns that it doesn't respond well to some forms
-                * of re-init after reset.
-                */
-               if (INTEL_INFO(dev)->gen > 5)
-                       intel_enable_gt_powersave(dev);
-       } else {
-               mutex_unlock(&dev->struct_mutex);
+       mutex_unlock(&dev->struct_mutex);
+       if (ret) {
+               DRM_ERROR("Failed hw init on reset %d\n", ret);
+               return ret;
        }
  
+       /*
+        * FIXME: This races pretty badly against concurrent holders of
+        * ring interrupts. This is possible since we've started to drop
+        * dev->struct_mutex in select places when waiting for the gpu.
+        */
+       /*
+        * rps/rc6 re-init is necessary to restore state lost after the
+        * reset and the re-install of gt irqs. Skip for ironlake per
+        * previous concerns that it doesn't respond well to some forms
+        * of re-init after reset.
+        */
+       if (INTEL_INFO(dev)->gen > 5)
+               intel_enable_gt_powersave(dev);
        return 0;
  }
  
@@@ -56,7 -56,7 +56,7 @@@
  
  #define DRIVER_NAME           "i915"
  #define DRIVER_DESC           "Intel Graphics"
- #define DRIVER_DATE           "20150214"
+ #define DRIVER_DATE           "20150227"
  
  #undef WARN_ON
  /* Many gcc seem to no see through this and fall over :( */
@@@ -693,7 -693,18 +693,18 @@@ struct intel_device_info 
        int trans_offsets[I915_MAX_TRANSCODERS];
        int palette_offsets[I915_MAX_PIPES];
        int cursor_offsets[I915_MAX_PIPES];
-       unsigned int eu_total;
+       /* Slice/subslice/EU info */
+       u8 slice_total;
+       u8 subslice_total;
+       u8 subslice_per_slice;
+       u8 eu_total;
+       u8 eu_per_subslice;
+       /* For each slice, which subslice(s) has(have) 7 EUs (bitfield)? */
+       u8 subslice_7eu[3];
+       u8 has_slice_pg:1;
+       u8 has_subslice_pg:1;
+       u8 has_eu_pg:1;
  };
  
  #undef DEFINE_FLAG
@@@ -889,150 -900,21 +900,21 @@@ struct intel_gmbus 
  };
  
  struct i915_suspend_saved_registers {
-       u8 saveLBB;
-       u32 saveDSPACNTR;
-       u32 saveDSPBCNTR;
        u32 saveDSPARB;
-       u32 savePIPEACONF;
-       u32 savePIPEBCONF;
-       u32 savePIPEASRC;
-       u32 savePIPEBSRC;
-       u32 saveFPA0;
-       u32 saveFPA1;
-       u32 saveDPLL_A;
-       u32 saveDPLL_A_MD;
-       u32 saveHTOTAL_A;
-       u32 saveHBLANK_A;
-       u32 saveHSYNC_A;
-       u32 saveVTOTAL_A;
-       u32 saveVBLANK_A;
-       u32 saveVSYNC_A;
-       u32 saveBCLRPAT_A;
-       u32 saveTRANSACONF;
-       u32 saveTRANS_HTOTAL_A;
-       u32 saveTRANS_HBLANK_A;
-       u32 saveTRANS_HSYNC_A;
-       u32 saveTRANS_VTOTAL_A;
-       u32 saveTRANS_VBLANK_A;
-       u32 saveTRANS_VSYNC_A;
-       u32 savePIPEASTAT;
-       u32 saveDSPASTRIDE;
-       u32 saveDSPASIZE;
-       u32 saveDSPAPOS;
-       u32 saveDSPAADDR;
-       u32 saveDSPASURF;
-       u32 saveDSPATILEOFF;
-       u32 savePFIT_PGM_RATIOS;
-       u32 saveBLC_HIST_CTL;
-       u32 saveBLC_PWM_CTL;
-       u32 saveBLC_PWM_CTL2;
-       u32 saveBLC_CPU_PWM_CTL;
-       u32 saveBLC_CPU_PWM_CTL2;
-       u32 saveFPB0;
-       u32 saveFPB1;
-       u32 saveDPLL_B;
-       u32 saveDPLL_B_MD;
-       u32 saveHTOTAL_B;
-       u32 saveHBLANK_B;
-       u32 saveHSYNC_B;
-       u32 saveVTOTAL_B;
-       u32 saveVBLANK_B;
-       u32 saveVSYNC_B;
-       u32 saveBCLRPAT_B;
-       u32 saveTRANSBCONF;
-       u32 saveTRANS_HTOTAL_B;
-       u32 saveTRANS_HBLANK_B;
-       u32 saveTRANS_HSYNC_B;
-       u32 saveTRANS_VTOTAL_B;
-       u32 saveTRANS_VBLANK_B;
-       u32 saveTRANS_VSYNC_B;
-       u32 savePIPEBSTAT;
-       u32 saveDSPBSTRIDE;
-       u32 saveDSPBSIZE;
-       u32 saveDSPBPOS;
-       u32 saveDSPBADDR;
-       u32 saveDSPBSURF;
-       u32 saveDSPBTILEOFF;
-       u32 saveVGA0;
-       u32 saveVGA1;
-       u32 saveVGA_PD;
-       u32 saveVGACNTRL;
-       u32 saveADPA;
        u32 saveLVDS;
        u32 savePP_ON_DELAYS;
        u32 savePP_OFF_DELAYS;
-       u32 saveDVOA;
-       u32 saveDVOB;
-       u32 saveDVOC;
        u32 savePP_ON;
        u32 savePP_OFF;
        u32 savePP_CONTROL;
        u32 savePP_DIVISOR;
-       u32 savePFIT_CONTROL;
-       u32 save_palette_a[256];
-       u32 save_palette_b[256];
        u32 saveFBC_CONTROL;
-       u32 saveIER;
-       u32 saveIIR;
-       u32 saveIMR;
-       u32 saveDEIER;
-       u32 saveDEIMR;
-       u32 saveGTIER;
-       u32 saveGTIMR;
-       u32 saveFDI_RXA_IMR;
-       u32 saveFDI_RXB_IMR;
        u32 saveCACHE_MODE_0;
        u32 saveMI_ARB_STATE;
        u32 saveSWF0[16];
        u32 saveSWF1[16];
        u32 saveSWF2[3];
-       u8 saveMSR;
-       u8 saveSR[8];
-       u8 saveGR[25];
-       u8 saveAR_INDEX;
-       u8 saveAR[21];
-       u8 saveDACMASK;
-       u8 saveCR[37];
        uint64_t saveFENCE[I915_MAX_NUM_FENCES];
-       u32 saveCURACNTR;
-       u32 saveCURAPOS;
-       u32 saveCURABASE;
-       u32 saveCURBCNTR;
-       u32 saveCURBPOS;
-       u32 saveCURBBASE;
-       u32 saveCURSIZE;
-       u32 saveDP_B;
-       u32 saveDP_C;
-       u32 saveDP_D;
-       u32 savePIPEA_GMCH_DATA_M;
-       u32 savePIPEB_GMCH_DATA_M;
-       u32 savePIPEA_GMCH_DATA_N;
-       u32 savePIPEB_GMCH_DATA_N;
-       u32 savePIPEA_DP_LINK_M;
-       u32 savePIPEB_DP_LINK_M;
-       u32 savePIPEA_DP_LINK_N;
-       u32 savePIPEB_DP_LINK_N;
-       u32 saveFDI_RXA_CTL;
-       u32 saveFDI_TXA_CTL;
-       u32 saveFDI_RXB_CTL;
-       u32 saveFDI_TXB_CTL;
-       u32 savePFA_CTL_1;
-       u32 savePFB_CTL_1;
-       u32 savePFA_WIN_SZ;
-       u32 savePFB_WIN_SZ;
-       u32 savePFA_WIN_POS;
-       u32 savePFB_WIN_POS;
-       u32 savePCH_DREF_CONTROL;
-       u32 saveDISP_ARB_CTL;
-       u32 savePIPEA_DATA_M1;
-       u32 savePIPEA_DATA_N1;
-       u32 savePIPEA_LINK_M1;
-       u32 savePIPEA_LINK_N1;
-       u32 savePIPEB_DATA_M1;
-       u32 savePIPEB_DATA_N1;
-       u32 savePIPEB_LINK_M1;
-       u32 savePIPEB_LINK_N1;
-       u32 saveMCHBAR_RENDER_STANDBY;
        u32 savePCH_PORT_HOTPLUG;
        u16 saveGCDGMBUS;
  };
@@@ -1455,6 -1337,7 +1337,7 @@@ struct intel_vbt_data 
        bool edp_initialized;
        bool edp_support;
        int edp_bpp;
+       bool edp_low_vswing;
        struct edp_power_seq edp_pps;
  
        struct {
@@@ -2144,8 -2027,9 +2027,9 @@@ struct drm_i915_gem_request 
        /** Position in the ringbuffer of the end of the whole request */
        u32 tail;
  
-       /** Context related to this request */
+       /** Context and ring buffer related to this request */
        struct intel_context *ctx;
+       struct intel_ringbuffer *ringbuf;
  
        /** Batch buffer related to this request if any */
        struct drm_i915_gem_object *batch_obj;
@@@ -2381,7 -2265,8 +2265,7 @@@ struct drm_i915_cmd_table 
  #define IS_HSW_EARLY_SDV(dev) (IS_HASWELL(dev) && \
                                 (INTEL_DEVID(dev) & 0xFF00) == 0x0C00)
  #define IS_BDW_ULT(dev)               (IS_BROADWELL(dev) && \
 -                               ((INTEL_DEVID(dev) & 0xf) == 0x2  || \
 -                               (INTEL_DEVID(dev) & 0xf) == 0x6 || \
 +                               ((INTEL_DEVID(dev) & 0xf) == 0x6 ||    \
                                 (INTEL_DEVID(dev) & 0xf) == 0xe))
  #define IS_BDW_GT3(dev)               (IS_BROADWELL(dev) && \
                                 (INTEL_DEVID(dev) & 0x00F0) == 0x0020)
@@@ -3123,10 -3008,6 +3007,6 @@@ int i915_parse_cmds(struct intel_engine
  extern int i915_save_state(struct drm_device *dev);
  extern int i915_restore_state(struct drm_device *dev);
  
- /* i915_ums.c */
- void i915_save_display_reg(struct drm_device *dev);
- void i915_restore_display_reg(struct drm_device *dev);
  /* i915_sysfs.c */
  void i915_setup_sysfs(struct drm_device *dev_priv);
  void i915_teardown_sysfs(struct drm_device *dev_priv);
@@@ -2763,7 -2763,6 +2763,6 @@@ i915_gem_retire_requests_ring(struct in
  
        while (!list_empty(&ring->request_list)) {
                struct drm_i915_gem_request *request;
-               struct intel_ringbuffer *ringbuf;
  
                request = list_first_entry(&ring->request_list,
                                           struct drm_i915_gem_request,
  
                trace_i915_gem_request_retire(request);
  
-               /* This is one of the few common intersection points
-                * between legacy ringbuffer submission and execlists:
-                * we need to tell them apart in order to find the correct
-                * ringbuffer to which the request belongs to.
-                */
-               if (i915.enable_execlists) {
-                       struct intel_context *ctx = request->ctx;
-                       ringbuf = ctx->engine[ring->id].ringbuf;
-               } else
-                       ringbuf = ring->buffer;
                /* We know the GPU must have read the request to have
                 * sent us the seqno + interrupt, so use the position
                 * of tail of the request to update the last known position
                 * of the GPU head.
                 */
-               ringbuf->last_retired_head = request->postfix;
+               request->ringbuf->last_retired_head = request->postfix;
  
                i915_gem_free_request(request);
        }
@@@ -3174,13 -3162,6 +3162,13 @@@ static void i965_write_fence_reg(struc
                u32 size = i915_gem_obj_ggtt_size(obj);
                uint64_t val;
  
 +              /* Adjust fence size to match tiled area */
 +              if (obj->tiling_mode != I915_TILING_NONE) {
 +                      uint32_t row_size = obj->stride *
 +                              (obj->tiling_mode == I915_TILING_Y ? 32 : 8);
 +                      size = (size / row_size) * row_size;
 +              }
 +
                val = (uint64_t)((i915_gem_obj_ggtt_offset(obj) + size - 4096) &
                                 0xfffff000) << 32;
                val |= i915_gem_obj_ggtt_offset(obj) & 0xfffff000;
@@@ -4238,7 -4219,7 +4226,7 @@@ i915_gem_object_pin_view(struct drm_i91
                fenceable = (vma->node.size == fence_size &&
                             (vma->node.start & (fence_alignment - 1)) == 0);
  
-               mappable = (vma->node.start + obj->base.size <=
+               mappable = (vma->node.start + fence_size <=
                            dev_priv->gtt.mappable_end);
  
                obj->map_and_fenceable = mappable && fenceable;
@@@ -4613,10 -4594,6 +4601,6 @@@ i915_gem_suspend(struct drm_device *dev
  
        i915_gem_retire_requests(dev);
  
-       /* Under UMS, be paranoid and evict. */
-       if (!drm_core_check_feature(dev, DRIVER_MODESET))
-               i915_gem_evict_everything(dev);
        i915_gem_stop_ringbuffers(dev);
        mutex_unlock(&dev->struct_mutex);
  
@@@ -4836,18 -4813,25 +4820,18 @@@ i915_gem_init_hw(struct drm_device *dev
        for (i = 0; i < NUM_L3_SLICES(dev); i++)
                i915_gem_l3_remap(&dev_priv->ring[RCS], i);
  
 -      /*
 -       * XXX: Contexts should only be initialized once. Doing a switch to the
 -       * default context switch however is something we'd like to do after
 -       * reset or thaw (the latter may not actually be necessary for HW, but
 -       * goes with our code better). Context switching requires rings (for
 -       * the do_switch), but before enabling PPGTT. So don't move this.
 -       */
 -      ret = i915_gem_context_enable(dev_priv);
 +      ret = i915_ppgtt_init_hw(dev);
        if (ret && ret != -EIO) {
 -              DRM_ERROR("Context enable failed %d\n", ret);
 +              DRM_ERROR("PPGTT enable failed %d\n", ret);
                i915_gem_cleanup_ringbuffer(dev);
 -
 -              return ret;
        }
  
 -      ret = i915_ppgtt_init_hw(dev);
 +      ret = i915_gem_context_enable(dev_priv);
        if (ret && ret != -EIO) {
 -              DRM_ERROR("PPGTT enable failed %d\n", ret);
 +              DRM_ERROR("Context enable failed %d\n", ret);
                i915_gem_cleanup_ringbuffer(dev);
 +
 +              return ret;
        }
  
        return ret;
@@@ -4973,18 -4957,8 +4957,8 @@@ i915_gem_load(struct drm_device *dev
                          i915_gem_idle_work_handler);
        init_waitqueue_head(&dev_priv->gpu_error.reset_queue);
  
-       /* On GEN3 we really need to make sure the ARB C3 LP bit is set */
-       if (!drm_core_check_feature(dev, DRIVER_MODESET) && IS_GEN3(dev)) {
-               I915_WRITE(MI_ARB_STATE,
-                          _MASKED_BIT_ENABLE(MI_ARB_C3_LP_WRITE_ENABLE));
-       }
        dev_priv->relative_constants_mode = I915_EXEC_CONSTANTS_REL_GENERAL;
  
-       /* Old X drivers will take 0-2 for front, back, depth buffers */
-       if (!drm_core_check_feature(dev, DRIVER_MODESET))
-               dev_priv->fence_reg_start = 3;
        if (INTEL_INFO(dev)->gen >= 7 && !IS_VALLEYVIEW(dev))
                dev_priv->num_fence_regs = 32;
        else if (INTEL_INFO(dev)->gen >= 4 || IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
@@@ -390,7 -390,7 +390,7 @@@ static const intel_limit_t intel_limits
         * them would make no difference.
         */
        .dot = { .min = 25000 * 5, .max = 540000 * 5},
-       .vco = { .min = 4860000, .max = 6700000 },
+       .vco = { .min = 4860000, .max = 6480000 },
        .n = { .min = 1, .max = 1 },
        .m1 = { .min = 2, .max = 2 },
        .m2 = { .min = 24 << 22, .max = 175 << 22 },
@@@ -2195,9 -2195,44 +2195,44 @@@ intel_fb_align_height(struct drm_devic
                      uint64_t fb_format_modifier)
  {
        int tile_height;
+       uint32_t bits_per_pixel;
  
-       tile_height = fb_format_modifier == I915_FORMAT_MOD_X_TILED ?
-               (IS_GEN2(dev) ? 16 : 8) : 1;
+       switch (fb_format_modifier) {
+       case DRM_FORMAT_MOD_NONE:
+               tile_height = 1;
+               break;
+       case I915_FORMAT_MOD_X_TILED:
+               tile_height = IS_GEN2(dev) ? 16 : 8;
+               break;
+       case I915_FORMAT_MOD_Y_TILED:
+               tile_height = 32;
+               break;
+       case I915_FORMAT_MOD_Yf_TILED:
+               bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8;
+               switch (bits_per_pixel) {
+               default:
+               case 8:
+                       tile_height = 64;
+                       break;
+               case 16:
+               case 32:
+                       tile_height = 32;
+                       break;
+               case 64:
+                       tile_height = 16;
+                       break;
+               case 128:
+                       WARN_ONCE(1,
+                                 "128-bit pixels are not supported for display!");
+                       tile_height = 16;
+                       break;
+               }
+               break;
+       default:
+               MISSING_CASE(fb_format_modifier);
+               tile_height = 1;
+               break;
+       }
  
        return ALIGN(height, tile_height);
  }
@@@ -2235,8 -2270,12 +2270,12 @@@ intel_pin_and_fence_fb_obj(struct drm_p
                }
                break;
        case I915_FORMAT_MOD_Y_TILED:
-               WARN(1, "Y tiled bo slipped through, driver bug!\n");
-               return -EINVAL;
+       case I915_FORMAT_MOD_Yf_TILED:
+               if (WARN_ONCE(INTEL_INFO(dev)->gen < 9,
+                         "Y tiling bo slipped through, driver bug!\n"))
+                       return -EINVAL;
+               alignment = 1 * 1024 * 1024;
+               break;
        default:
                MISSING_CASE(fb->modifier[0]);
                return -EINVAL;
@@@ -2728,6 -2767,40 +2767,40 @@@ static void ironlake_update_primary_pla
        POSTING_READ(reg);
  }
  
+ u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier,
+                             uint32_t pixel_format)
+ {
+       u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8;
+       /*
+        * The stride is either expressed as a multiple of 64 bytes
+        * chunks for linear buffers or in number of tiles for tiled
+        * buffers.
+        */
+       switch (fb_modifier) {
+       case DRM_FORMAT_MOD_NONE:
+               return 64;
+       case I915_FORMAT_MOD_X_TILED:
+               if (INTEL_INFO(dev)->gen == 2)
+                       return 128;
+               return 512;
+       case I915_FORMAT_MOD_Y_TILED:
+               /* No need to check for old gens and Y tiling since this is
+                * about the display engine and those will be blocked before
+                * we get here.
+                */
+               return 128;
+       case I915_FORMAT_MOD_Yf_TILED:
+               if (bits_per_pixel == 8)
+                       return 64;
+               else
+                       return 128;
+       default:
+               MISSING_CASE(fb_modifier);
+               return 64;
+       }
+ }
  static void skylake_update_primary_plane(struct drm_crtc *crtc,
                                         struct drm_framebuffer *fb,
                                         int x, int y)
        struct drm_device *dev = crtc->dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-       struct intel_framebuffer *intel_fb;
        struct drm_i915_gem_object *obj;
        int pipe = intel_crtc->pipe;
-       u32 plane_ctl, stride;
+       u32 plane_ctl, stride_div;
  
        if (!intel_crtc->primary_enabled) {
                I915_WRITE(PLANE_CTL(pipe, 0), 0);
                BUG();
        }
  
-       intel_fb = to_intel_framebuffer(fb);
-       obj = intel_fb->obj;
-       /*
-        * The stride is either expressed as a multiple of 64 bytes chunks for
-        * linear buffers or in number of tiles for tiled buffers.
-        */
        switch (fb->modifier[0]) {
        case DRM_FORMAT_MOD_NONE:
-               stride = fb->pitches[0] >> 6;
                break;
        case I915_FORMAT_MOD_X_TILED:
                plane_ctl |= PLANE_CTL_TILED_X;
-               stride = fb->pitches[0] >> 9;
+               break;
+       case I915_FORMAT_MOD_Y_TILED:
+               plane_ctl |= PLANE_CTL_TILED_Y;
+               break;
+       case I915_FORMAT_MOD_Yf_TILED:
+               plane_ctl |= PLANE_CTL_TILED_YF;
                break;
        default:
-               BUG();
+               MISSING_CASE(fb->modifier[0]);
        }
  
        plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
        if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180))
                plane_ctl |= PLANE_CTL_ROTATE_180;
  
+       obj = intel_fb_obj(fb);
+       stride_div = intel_fb_stride_alignment(dev, fb->modifier[0],
+                                              fb->pixel_format);
        I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl);
  
        DRM_DEBUG_KMS("Writing base %08lX %d,%d,%d,%d pitch=%d\n",
        I915_WRITE(PLANE_SIZE(pipe, 0),
                   (intel_crtc->config->pipe_src_h - 1) << 16 |
                   (intel_crtc->config->pipe_src_w - 1));
-       I915_WRITE(PLANE_STRIDE(pipe, 0), stride);
+       I915_WRITE(PLANE_STRIDE(pipe, 0), fb->pitches[0] / stride_div);
        I915_WRITE(PLANE_SURF(pipe, 0), i915_gem_obj_ggtt_offset(obj));
  
        POSTING_READ(PLANE_SURF(pipe, 0));
@@@ -3062,7 -3135,7 +3135,7 @@@ static void intel_fdi_normal_train(stru
  
  static bool pipe_has_enabled_pch(struct intel_crtc *crtc)
  {
-       return crtc->base.enabled && crtc->active &&
+       return crtc->base.state->enable && crtc->active &&
                crtc->config->has_pch_encoder;
  }
  
@@@ -4200,7 -4273,7 +4273,7 @@@ static void intel_crtc_load_lut(struct 
        bool reenable_ips = false;
  
        /* The clocks have to be on to load the palette. */
-       if (!crtc->enabled || !intel_crtc->active)
+       if (!crtc->state->enable || !intel_crtc->active)
                return;
  
        if (!HAS_PCH_SPLIT(dev_priv->dev)) {
@@@ -4313,7 -4386,7 +4386,7 @@@ static void ironlake_crtc_enable(struc
        struct intel_encoder *encoder;
        int pipe = intel_crtc->pipe;
  
-       WARN_ON(!crtc->enabled);
+       WARN_ON(!crtc->state->enable);
  
        if (intel_crtc->active)
                return;
                intel_prepare_shared_dpll(intel_crtc);
  
        if (intel_crtc->config->has_dp_encoder)
-               intel_dp_set_m_n(intel_crtc);
+               intel_dp_set_m_n(intel_crtc, M1_N1);
  
        intel_set_pipe_timings(intel_crtc);
  
@@@ -4421,7 -4494,7 +4494,7 @@@ static void haswell_crtc_enable(struct 
        struct intel_encoder *encoder;
        int pipe = intel_crtc->pipe;
  
-       WARN_ON(!crtc->enabled);
+       WARN_ON(!crtc->state->enable);
  
        if (intel_crtc->active)
                return;
                intel_enable_shared_dpll(intel_crtc);
  
        if (intel_crtc->config->has_dp_encoder)
-               intel_dp_set_m_n(intel_crtc);
+               intel_dp_set_m_n(intel_crtc, M1_N1);
  
        intel_set_pipe_timings(intel_crtc);
  
@@@ -4768,7 -4841,7 +4841,7 @@@ static void modeset_update_crtc_power_d
        for_each_intel_crtc(dev, crtc) {
                enum intel_display_power_domain domain;
  
-               if (!crtc->base.enabled)
+               if (!crtc->base.state->enable)
                        continue;
  
                pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base);
@@@ -4989,7 -5062,7 +5062,7 @@@ static void valleyview_modeset_global_p
  
        /* disable/enable all currently active pipes while we change cdclk */
        for_each_intel_crtc(dev, intel_crtc)
-               if (intel_crtc->base.enabled)
+               if (intel_crtc->base.state->enable)
                        *prepare_pipes |= (1 << intel_crtc->pipe);
  }
  
@@@ -5029,7 -5102,7 +5102,7 @@@ static void valleyview_crtc_enable(stru
        int pipe = intel_crtc->pipe;
        bool is_dsi;
  
-       WARN_ON(!crtc->enabled);
+       WARN_ON(!crtc->state->enable);
  
        if (intel_crtc->active)
                return;
        }
  
        if (intel_crtc->config->has_dp_encoder)
-               intel_dp_set_m_n(intel_crtc);
+               intel_dp_set_m_n(intel_crtc, M1_N1);
  
        intel_set_pipe_timings(intel_crtc);
  
@@@ -5112,7 -5185,7 +5185,7 @@@ static void i9xx_crtc_enable(struct drm
        struct intel_encoder *encoder;
        int pipe = intel_crtc->pipe;
  
-       WARN_ON(!crtc->enabled);
+       WARN_ON(!crtc->state->enable);
  
        if (intel_crtc->active)
                return;
        i9xx_set_pll_dividers(intel_crtc);
  
        if (intel_crtc->config->has_dp_encoder)
-               intel_dp_set_m_n(intel_crtc);
+               intel_dp_set_m_n(intel_crtc, M1_N1);
  
        intel_set_pipe_timings(intel_crtc);
  
@@@ -5311,7 -5384,7 +5384,7 @@@ static void intel_crtc_disable(struct d
        struct drm_i915_private *dev_priv = dev->dev_private;
  
        /* crtc should still be enabled when we disable it. */
-       WARN_ON(!crtc->enabled);
+       WARN_ON(!crtc->state->enable);
  
        dev_priv->display.crtc_disable(crtc);
        dev_priv->display.off(crtc);
@@@ -5389,7 -5462,8 +5462,8 @@@ static void intel_connector_check_state
  
                        crtc = encoder->base.crtc;
  
-                       I915_STATE_WARN(!crtc->enabled, "crtc not enabled\n");
+                       I915_STATE_WARN(!crtc->state->enable,
+                                       "crtc not enabled\n");
                        I915_STATE_WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
                        I915_STATE_WARN(pipe != to_intel_crtc(crtc)->pipe,
                             "encoder active on the wrong pipe\n");
@@@ -5576,7 -5650,7 +5650,7 @@@ static int intel_crtc_compute_config(st
         * - LVDS dual channel mode
         * - Double wide pipe
         */
-       if ((intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
+       if ((intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS) &&
             intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
                pipe_config->pipe_src_w &= ~1;
  
@@@ -5879,7 -5953,7 +5953,7 @@@ static void intel_cpu_transcoder_set_m_
                 * for gen < 8) and if DRRS is supported (to make sure the
                 * registers are not unnecessarily accessed).
                 */
-               if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
+               if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) &&
                        crtc->config->has_drrs) {
                        I915_WRITE(PIPE_DATA_M2(transcoder),
                                        TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
        }
  }
  
- void intel_dp_set_m_n(struct intel_crtc *crtc)
+ void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n)
  {
+       struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
+       if (m_n == M1_N1) {
+               dp_m_n = &crtc->config->dp_m_n;
+               dp_m2_n2 = &crtc->config->dp_m2_n2;
+       } else if (m_n == M2_N2) {
+               /*
+                * M2_N2 registers are not supported. Hence m2_n2 divider value
+                * needs to be programmed into M1_N1.
+                */
+               dp_m_n = &crtc->config->dp_m2_n2;
+       } else {
+               DRM_ERROR("Unsupported divider value\n");
+               return;
+       }
        if (crtc->config->has_pch_encoder)
                intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n);
        else
-               intel_cpu_transcoder_set_m_n(crtc, &crtc->config->dp_m_n,
-                                                  &crtc->config->dp_m2_n2);
+               intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2);
  }
  
  static void vlv_update_pll(struct intel_crtc *crtc,
@@@ -7650,7 -7740,7 +7740,7 @@@ skylake_get_initial_plane_config(struc
  {
        struct drm_device *dev = crtc->base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
-       u32 val, base, offset, stride_mult;
+       u32 val, base, offset, stride_mult, tiling;
        int pipe = crtc->pipe;
        int fourcc, pixel_format;
        int aligned_height;
        if (!(val & PLANE_CTL_ENABLE))
                goto error;
  
-       if (val & PLANE_CTL_TILED_MASK) {
-               plane_config->tiling = I915_TILING_X;
-               fb->modifier[0] = I915_FORMAT_MOD_X_TILED;
-       }
        pixel_format = val & PLANE_CTL_FORMAT_MASK;
        fourcc = skl_format_to_fourcc(pixel_format,
                                      val & PLANE_CTL_ORDER_RGBX,
        fb->pixel_format = fourcc;
        fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8;
  
+       tiling = val & PLANE_CTL_TILED_MASK;
+       switch (tiling) {
+       case PLANE_CTL_TILED_LINEAR:
+               fb->modifier[0] = DRM_FORMAT_MOD_NONE;
+               break;
+       case PLANE_CTL_TILED_X:
+               plane_config->tiling = I915_TILING_X;
+               fb->modifier[0] = I915_FORMAT_MOD_X_TILED;
+               break;
+       case PLANE_CTL_TILED_Y:
+               fb->modifier[0] = I915_FORMAT_MOD_Y_TILED;
+               break;
+       case PLANE_CTL_TILED_YF:
+               fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED;
+               break;
+       default:
+               MISSING_CASE(tiling);
+               goto error;
+       }
        base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000;
        plane_config->base = base;
  
        fb->width = ((val >> 0) & 0x1fff) + 1;
  
        val = I915_READ(PLANE_STRIDE(pipe, 0));
-       switch (plane_config->tiling) {
-       case I915_TILING_NONE:
-               stride_mult = 64;
-               break;
-       case I915_TILING_X:
-               stride_mult = 512;
-               break;
-       default:
-               MISSING_CASE(plane_config->tiling);
-               goto error;
-       }
+       stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0],
+                                               fb->pixel_format);
        fb->pitches[0] = (val & 0x3ff) * stride_mult;
  
        aligned_height = intel_fb_align_height(dev, fb->height,
@@@ -8686,7 -8782,7 +8782,7 @@@ retry
                i++;
                if (!(encoder->possible_crtcs & (1 << i)))
                        continue;
-               if (possible_crtc->enabled)
+               if (possible_crtc->state->enable)
                        continue;
                /* This can occur when applying the pipe A quirk on resume. */
                if (to_intel_crtc(possible_crtc)->new_enabled)
        return true;
  
   fail:
-       intel_crtc->new_enabled = crtc->enabled;
+       intel_crtc->new_enabled = crtc->state->enable;
        if (intel_crtc->new_enabled)
                intel_crtc->new_config = intel_crtc->config;
        else
@@@ -9661,10 -9757,10 +9757,10 @@@ static bool __intel_pageflip_stall_chec
                    !i915_gem_request_completed(work->flip_queued_req, true))
                        return false;
  
-               work->flip_ready_vblank = drm_vblank_count(dev, intel_crtc->pipe);
+               work->flip_ready_vblank = drm_crtc_vblank_count(crtc);
        }
  
-       if (drm_vblank_count(dev, intel_crtc->pipe) - work->flip_ready_vblank < 3)
+       if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3)
                return false;
  
        /* Potential stall - if we see that the flip has happened,
@@@ -9695,7 -9791,8 +9791,8 @@@ void intel_check_page_flip(struct drm_d
        spin_lock(&dev->event_lock);
        if (intel_crtc->unpin_work && __intel_pageflip_stall_check(dev, crtc)) {
                WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
-                        intel_crtc->unpin_work->flip_queued_vblank, drm_vblank_count(dev, pipe));
+                        intel_crtc->unpin_work->flip_queued_vblank,
+                        drm_vblank_count(dev, pipe));
                page_flip_completed(intel_crtc);
        }
        spin_unlock(&dev->event_lock);
@@@ -9837,7 -9934,7 +9934,7 @@@ static int intel_crtc_page_flip(struct 
                                        intel_ring_get_request(ring));
        }
  
-       work->flip_queued_vblank = drm_vblank_count(dev, intel_crtc->pipe);
+       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,
@@@ -9913,7 -10010,7 +10010,7 @@@ static void intel_modeset_update_staged
        }
  
        for_each_intel_crtc(dev, crtc) {
-               crtc->new_enabled = crtc->base.enabled;
+               crtc->new_enabled = crtc->base.state->enable;
  
                if (crtc->new_enabled)
                        crtc->new_config = crtc->config;
@@@ -9943,6 -10040,7 +10040,7 @@@ static void intel_modeset_commit_output
        }
  
        for_each_intel_crtc(dev, crtc) {
+               crtc->base.state->enable = crtc->new_enabled;
                crtc->base.enabled = crtc->new_enabled;
        }
  }
@@@ -10206,6 -10304,7 +10304,7 @@@ intel_modeset_pipe_config(struct drm_cr
        if (!pipe_config)
                return ERR_PTR(-ENOMEM);
  
+       pipe_config->base.crtc = crtc;
        drm_mode_copy(&pipe_config->base.adjusted_mode, mode);
        drm_mode_copy(&pipe_config->base.mode, mode);
  
@@@ -10354,7 -10453,7 +10453,7 @@@ intel_modeset_affected_pipes(struct drm
  
        /* Check for pipes that will be enabled/disabled ... */
        for_each_intel_crtc(dev, intel_crtc) {
-               if (intel_crtc->base.enabled == intel_crtc->new_enabled)
+               if (intel_crtc->base.state->enable == intel_crtc->new_enabled)
                        continue;
  
                if (!intel_crtc->new_enabled)
@@@ -10429,10 -10528,10 +10528,10 @@@ intel_modeset_update_state(struct drm_d
  
        /* Double check state. */
        for_each_intel_crtc(dev, intel_crtc) {
-               WARN_ON(intel_crtc->base.enabled != intel_crtc_in_use(&intel_crtc->base));
+               WARN_ON(intel_crtc->base.state->enable != intel_crtc_in_use(&intel_crtc->base));
                WARN_ON(intel_crtc->new_config &&
                        intel_crtc->new_config != intel_crtc->config);
-               WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config);
+               WARN_ON(intel_crtc->base.state->enable != !!intel_crtc->new_config);
        }
  
        list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
@@@ -10819,7 -10918,7 +10918,7 @@@ check_crtc_state(struct drm_device *dev
                DRM_DEBUG_KMS("[CRTC:%d]\n",
                              crtc->base.base.id);
  
-               I915_STATE_WARN(crtc->active && !crtc->base.enabled,
+               I915_STATE_WARN(crtc->active && !crtc->base.state->enable,
                     "active crtc, but not enabled in sw tracking\n");
  
                for_each_intel_encoder(dev, encoder) {
                I915_STATE_WARN(active != crtc->active,
                     "crtc's computed active state doesn't match tracked active state "
                     "(expected %i, found %i)\n", active, crtc->active);
-               I915_STATE_WARN(enabled != crtc->base.enabled,
+               I915_STATE_WARN(enabled != crtc->base.state->enable,
                     "crtc's computed enabled state doesn't match tracked enabled state "
-                    "(expected %i, found %i)\n", enabled, crtc->base.enabled);
+                    "(expected %i, found %i)\n", enabled,
+                               crtc->base.state->enable);
  
                active = dev_priv->display.get_pipe_config(crtc,
                                                           &pipe_config);
@@@ -10899,7 -10999,7 +10999,7 @@@ check_shared_dpll_state(struct drm_devi
                     pll->on, active);
  
                for_each_intel_crtc(dev, crtc) {
-                       if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll)
+                       if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll)
                                enabled_crtcs++;
                        if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
                                active_crtcs++;
@@@ -11085,7 -11185,7 +11185,7 @@@ static int __intel_set_mode(struct drm_
                intel_crtc_disable(&intel_crtc->base);
  
        for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
-               if (intel_crtc->base.enabled)
+               if (intel_crtc->base.state->enable)
                        dev_priv->display.crtc_disable(&intel_crtc->base);
        }
  
  
        /* FIXME: add subpixel order */
  done:
-       if (ret && crtc->enabled)
+       if (ret && crtc->state->enable)
                crtc->mode = *saved_mode;
  
        kfree(saved_mode);
@@@ -11237,7 -11337,7 +11337,7 @@@ static int intel_set_config_save_state(
         */
        count = 0;
        for_each_crtc(dev, crtc) {
-               config->save_crtc_enabled[count++] = crtc->enabled;
+               config->save_crtc_enabled[count++] = crtc->state->enable;
        }
  
        count = 0;
@@@ -11471,7 -11571,7 +11571,7 @@@ intel_modeset_stage_output_state(struc
                        }
                }
  
-               if (crtc->new_enabled != crtc->base.enabled) {
+               if (crtc->new_enabled != crtc->base.state->enable) {
                        DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
                                      crtc->new_enabled ? "en" : "dis");
                        config->mode_changed = true;
@@@ -11776,8 -11876,7 +11876,8 @@@ static void intel_shared_dpll_init(stru
   */
  int
  intel_prepare_plane_fb(struct drm_plane *plane,
 -                     struct drm_framebuffer *fb)
 +                     struct drm_framebuffer *fb,
 +                     const struct drm_plane_state *new_state)
  {
        struct drm_device *dev = plane->dev;
        struct intel_plane *intel_plane = to_intel_plane(plane);
   */
  void
  intel_cleanup_plane_fb(struct drm_plane *plane,
 -                     struct drm_framebuffer *fb)
 +                     struct drm_framebuffer *fb,
 +                     const struct drm_plane_state *old_state)
  {
        struct drm_device *dev = plane->dev;
        struct drm_i915_gem_object *obj = intel_fb_obj(fb);
@@@ -11907,6 -12005,12 +12007,12 @@@ intel_check_primary_plane(struct drm_pl
                        INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
  
                intel_crtc->atomic.update_fbc = true;
+               /* Update watermarks on tiling changes. */
+               if (!plane->state->fb || !state->base.fb ||
+                   plane->state->fb->modifier[0] !=
+                   state->base.fb->modifier[0])
+                       intel_crtc->atomic.update_wm = true;
        }
  
        return 0;
@@@ -12297,6 -12401,7 +12403,7 @@@ static void intel_crtc_init(struct drm_
        if (!crtc_state)
                goto fail;
        intel_crtc_set_state(intel_crtc, crtc_state);
+       crtc_state->base.crtc = &intel_crtc->base;
  
        primary = intel_primary_plane_create(dev, pipe);
        if (!primary)
@@@ -12374,9 -12479,6 +12481,6 @@@ int intel_get_pipe_from_crtc_id(struct 
        struct drm_crtc *drmmode_crtc;
        struct intel_crtc *crtc;
  
-       if (!drm_core_check_feature(dev, DRIVER_MODESET))
-               return -ENODEV;
        drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id);
  
        if (!drmmode_crtc) {
@@@ -12649,14 -12751,43 +12753,43 @@@ static const struct drm_framebuffer_fun
        .create_handle = intel_user_framebuffer_create_handle,
  };
  
+ static
+ u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier,
+                        uint32_t pixel_format)
+ {
+       u32 gen = INTEL_INFO(dev)->gen;
+       if (gen >= 9) {
+               /* "The stride in bytes must not exceed the of the size of 8K
+                *  pixels and 32K bytes."
+                */
+                return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768);
+       } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) {
+               return 32*1024;
+       } else if (gen >= 4) {
+               if (fb_modifier == I915_FORMAT_MOD_X_TILED)
+                       return 16*1024;
+               else
+                       return 32*1024;
+       } else if (gen >= 3) {
+               if (fb_modifier == I915_FORMAT_MOD_X_TILED)
+                       return 8*1024;
+               else
+                       return 16*1024;
+       } else {
+               /* XXX DSPC is limited to 4k tiled */
+               return 8*1024;
+       }
+ }
  static int intel_framebuffer_init(struct drm_device *dev,
                                  struct intel_framebuffer *intel_fb,
                                  struct drm_mode_fb_cmd2 *mode_cmd,
                                  struct drm_i915_gem_object *obj)
  {
        int aligned_height;
-       int pitch_limit;
        int ret;
+       u32 pitch_limit, stride_alignment;
  
        WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  
                }
        }
  
-       if (mode_cmd->modifier[0] == I915_FORMAT_MOD_Y_TILED) {
-               DRM_DEBUG("hardware does not support tiling Y\n");
+       /* Passed in modifier sanity checking. */
+       switch (mode_cmd->modifier[0]) {
+       case I915_FORMAT_MOD_Y_TILED:
+       case I915_FORMAT_MOD_Yf_TILED:
+               if (INTEL_INFO(dev)->gen < 9) {
+                       DRM_DEBUG("Unsupported tiling 0x%llx!\n",
+                                 mode_cmd->modifier[0]);
+                       return -EINVAL;
+               }
+       case DRM_FORMAT_MOD_NONE:
+       case I915_FORMAT_MOD_X_TILED:
+               break;
+       default:
+               DRM_ERROR("Unsupported fb modifier 0x%llx!\n",
+                               mode_cmd->modifier[0]);
                return -EINVAL;
        }
  
-       if (mode_cmd->pitches[0] & 63) {
-               DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
-                         mode_cmd->pitches[0]);
+       stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0],
+                                                    mode_cmd->pixel_format);
+       if (mode_cmd->pitches[0] & (stride_alignment - 1)) {
+               DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n",
+                         mode_cmd->pitches[0], stride_alignment);
                return -EINVAL;
        }
  
-       if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) {
-               pitch_limit = 32*1024;
-       } else if (INTEL_INFO(dev)->gen >= 4) {
-               if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)
-                       pitch_limit = 16*1024;
-               else
-                       pitch_limit = 32*1024;
-       } else if (INTEL_INFO(dev)->gen >= 3) {
-               if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)
-                       pitch_limit = 8*1024;
-               else
-                       pitch_limit = 16*1024;
-       } else
-               /* XXX DSPC is limited to 4k tiled */
-               pitch_limit = 8*1024;
+       pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0],
+                                          mode_cmd->pixel_format);
        if (mode_cmd->pitches[0] > pitch_limit) {
-               DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
-                         mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED ?
+               DRM_DEBUG("%s pitch (%u) must be at less than %d\n",
+                         mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ?
                          "tiled" : "linear",
                          mode_cmd->pitches[0], pitch_limit);
                return -EINVAL;
@@@ -13318,11 -13450,11 +13452,11 @@@ static void intel_sanitize_crtc(struct 
        I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  
        /* restore vblank interrupts to correct state */
+       drm_crtc_vblank_reset(&crtc->base);
        if (crtc->active) {
                update_scanline_offset(crtc);
-               drm_vblank_on(dev, crtc->pipe);
-       } else
-               drm_vblank_off(dev, crtc->pipe);
+               drm_crtc_vblank_on(&crtc->base);
+       }
  
        /* We need to sanitize the plane -> pipe mapping first because this will
         * disable the crtc (and hence change the state) if it is wrong. Note
                        }
  
                WARN_ON(crtc->active);
+               crtc->base.state->enable = false;
                crtc->base.enabled = false;
        }
  
         * have active connectors/encoders. */
        intel_crtc_update_dpms(&crtc->base);
  
-       if (crtc->active != crtc->base.enabled) {
+       if (crtc->active != crtc->base.state->enable) {
                struct intel_encoder *encoder;
  
                /* This can happen either due to bugs in the get_hw_state
                 * pipe A quirk. */
                DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
                              crtc->base.base.id,
-                             crtc->base.enabled ? "enabled" : "disabled",
+                             crtc->base.state->enable ? "enabled" : "disabled",
                              crtc->active ? "enabled" : "disabled");
  
+               crtc->base.state->enable = crtc->active;
                crtc->base.enabled = crtc->active;
  
                /* Because we only establish the connector -> encoder ->
@@@ -13525,6 -13659,7 +13661,7 @@@ static void intel_modeset_readout_hw_st
                crtc->active = dev_priv->display.get_pipe_config(crtc,
                                                                 crtc->config);
  
+               crtc->base.state->enable = crtc->active;
                crtc->base.enabled = crtc->active;
                crtc->primary_enabled = primary_get_hw_state(crtc);
  
@@@ -2691,11 -2691,14 +2691,14 @@@ static uint8_
  intel_dp_voltage_max(struct intel_dp *intel_dp)
  {
        struct drm_device *dev = intel_dp_to_dev(intel_dp);
+       struct drm_i915_private *dev_priv = dev->dev_private;
        enum port port = dp_to_dig_port(intel_dp)->port;
  
-       if (INTEL_INFO(dev)->gen >= 9)
+       if (INTEL_INFO(dev)->gen >= 9) {
+               if (dev_priv->vbt.edp_low_vswing && port == PORT_A)
+                       return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
                return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
-       else if (IS_VALLEYVIEW(dev))
+       else if (IS_VALLEYVIEW(dev))
                return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
        else if (IS_GEN7(dev) && port == PORT_A)
                return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
@@@ -2719,6 -2722,8 +2722,8 @@@ intel_dp_pre_emphasis_max(struct intel_
                        return DP_TRAIN_PRE_EMPH_LEVEL_2;
                case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
                        return DP_TRAIN_PRE_EMPH_LEVEL_1;
+               case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
+                       return DP_TRAIN_PRE_EMPH_LEVEL_0;
                default:
                        return DP_TRAIN_PRE_EMPH_LEVEL_0;
                }
@@@ -3201,6 -3206,9 +3206,9 @@@ intel_hsw_signal_levels(uint8_t train_s
                return DDI_BUF_TRANS_SELECT(7);
        case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
                return DDI_BUF_TRANS_SELECT(8);
+       case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
+               return DDI_BUF_TRANS_SELECT(9);
        default:
                DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
                              "0x%x\n", signal_levels);
@@@ -3521,6 -3529,8 +3529,6 @@@ intel_dp_link_down(struct intel_dp *int
        enum port port = intel_dig_port->port;
        struct drm_device *dev = intel_dig_port->base.base.dev;
        struct drm_i915_private *dev_priv = dev->dev_private;
 -      struct intel_crtc *intel_crtc =
 -              to_intel_crtc(intel_dig_port->base.base.crtc);
        uint32_t DP = intel_dp->DP;
  
        if (WARN_ON(HAS_DDI(dev)))
  
        if (HAS_PCH_IBX(dev) &&
            I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
 -              struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
 -
                /* Hardware workaround: leaving our transcoder select
                 * set to transcoder B while it's off will prevent the
                 * corresponding HDMI output on transcoder A.
                 */
                DP &= ~DP_PIPEB_SELECT;
                I915_WRITE(intel_dp->output_reg, DP);
 -
 -              /* Changes to enable or select take place the vblank
 -               * after being written.
 -               */
 -              if (WARN_ON(crtc == NULL)) {
 -                      /* We should never try to disable a port without a crtc
 -                       * attached. For paranoia keep the code around for a
 -                       * bit. */
 -                      POSTING_READ(intel_dp->output_reg);
 -                      msleep(50);
 -              } else
 -                      intel_wait_for_vblank(dev, intel_crtc->pipe);
 +              POSTING_READ(intel_dp->output_reg);
        }
  
        DP &= ~DP_AUDIO_OUTPUT_ENABLE;
@@@ -4431,7 -4454,7 +4439,7 @@@ intel_dp_hpd_pulse(struct intel_digital
                 */
                DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
                              port_name(intel_dig_port->port));
 -              return false;
 +              return IRQ_HANDLED;
        }
  
        DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
@@@ -4736,6 -4759,18 +4744,18 @@@ intel_dp_init_panel_power_sequencer_reg
                      I915_READ(pp_div_reg));
  }
  
+ /**
+  * intel_dp_set_drrs_state - program registers for RR switch to take effect
+  * @dev: DRM device
+  * @refresh_rate: RR to be programmed
+  *
+  * This function gets called when refresh rate (RR) has to be changed from
+  * one frequency to another. Switches can be between high and low RR
+  * supported by the panel or to any other RR based on media playback (in
+  * this case, RR value needs to be passed from user space).
+  *
+  * The caller of this function needs to take a lock on dev_priv->drrs.
+  */
  static void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate)
  {
        struct drm_i915_private *dev_priv = dev->dev_private;
                return;
        }
  
-       if (INTEL_INFO(dev)->gen > 6 && INTEL_INFO(dev)->gen < 8) {
+       if (INTEL_INFO(dev)->gen >= 8 && !IS_CHERRYVIEW(dev)) {
+               switch (index) {
+               case DRRS_HIGH_RR:
+                       intel_dp_set_m_n(intel_crtc, M1_N1);
+                       break;
+               case DRRS_LOW_RR:
+                       intel_dp_set_m_n(intel_crtc, M2_N2);
+                       break;
+               case DRRS_MAX_RR:
+               default:
+                       DRM_ERROR("Unsupported refreshrate type\n");
+               }
+       } else if (INTEL_INFO(dev)->gen > 6) {
                reg = PIPECONF(intel_crtc->config->cpu_transcoder);
                val = I915_READ(reg);
                if (index > DRRS_HIGH_RR) {
-                       val |= PIPECONF_EDP_RR_MODE_SWITCH;
-                       intel_dp_set_m_n(intel_crtc);
+                       if (IS_VALLEYVIEW(dev))
+                               val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
+                       else
+                               val |= PIPECONF_EDP_RR_MODE_SWITCH;
                } else {
-                       val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
+                       if (IS_VALLEYVIEW(dev))
+                               val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
+                       else
+                               val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
                }
                I915_WRITE(reg, val);
        }
        DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
  }
  
+ /**
+  * intel_edp_drrs_enable - init drrs struct if supported
+  * @intel_dp: DP struct
+  *
+  * Initializes frontbuffer_bits and drrs.dp
+  */
  void intel_edp_drrs_enable(struct intel_dp *intel_dp)
  {
        struct drm_device *dev = intel_dp_to_dev(intel_dp);
@@@ -4837,6 -4896,11 +4881,11 @@@ unlock
        mutex_unlock(&dev_priv->drrs.mutex);
  }
  
+ /**
+  * intel_edp_drrs_disable - Disable DRRS
+  * @intel_dp: DP struct
+  *
+  */
  void intel_edp_drrs_disable(struct intel_dp *intel_dp)
  {
        struct drm_device *dev = intel_dp_to_dev(intel_dp);
@@@ -4896,6 -4960,17 +4945,17 @@@ unlock
        mutex_unlock(&dev_priv->drrs.mutex);
  }
  
+ /**
+  * intel_edp_drrs_invalidate - Invalidate DRRS
+  * @dev: DRM device
+  * @frontbuffer_bits: frontbuffer plane tracking bits
+  *
+  * When there is a disturbance on screen (due to cursor movement/time
+  * update etc), DRRS needs to be invalidated, i.e. need to switch to
+  * high RR.
+  *
+  * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
+  */
  void intel_edp_drrs_invalidate(struct drm_device *dev,
                unsigned frontbuffer_bits)
  {
        mutex_unlock(&dev_priv->drrs.mutex);
  }
  
+ /**
+  * intel_edp_drrs_flush - Flush DRRS
+  * @dev: DRM device
+  * @frontbuffer_bits: frontbuffer plane tracking bits
+  *
+  * When there is no movement on screen, DRRS work can be scheduled.
+  * This DRRS work is responsible for setting relevant registers after a
+  * timeout of 1 second.
+  *
+  * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
+  */
  void intel_edp_drrs_flush(struct drm_device *dev,
                unsigned frontbuffer_bits)
  {
        mutex_unlock(&dev_priv->drrs.mutex);
  }
  
+ /**
+  * DOC: Display Refresh Rate Switching (DRRS)
+  *
+  * Display Refresh Rate Switching (DRRS) is a power conservation feature
+  * which enables swtching between low and high refresh rates,
+  * dynamically, based on the usage scenario. This feature is applicable
+  * for internal panels.
+  *
+  * Indication that the panel supports DRRS is given by the panel EDID, which
+  * would list multiple refresh rates for one resolution.
+  *
+  * DRRS is of 2 types - static and seamless.
+  * Static DRRS involves changing refresh rate (RR) by doing a full modeset
+  * (may appear as a blink on screen) and is used in dock-undock scenario.
+  * Seamless DRRS involves changing RR without any visual effect to the user
+  * and can be used during normal system usage. This is done by programming
+  * certain registers.
+  *
+  * Support for static/seamless DRRS may be indicated in the VBT based on
+  * inputs from the panel spec.
+  *
+  * DRRS saves power by switching to low RR based on usage scenarios.
+  *
+  * eDP DRRS:-
+  *        The implementation is based on frontbuffer tracking implementation.
+  * When there is a disturbance on the screen triggered by user activity or a
+  * periodic system activity, DRRS is disabled (RR is changed to high RR).
+  * When there is no movement on screen, after a timeout of 1 second, a switch
+  * to low RR is made.
+  *        For integration with frontbuffer tracking code,
+  * intel_edp_drrs_invalidate() and intel_edp_drrs_flush() are called.
+  *
+  * DRRS can be further extended to support other internal panels and also
+  * the scenario of video playback wherein RR is set based on the rate
+  * requested by userspace.
+  */
+ /**
+  * intel_dp_drrs_init - Init basic DRRS work and mutex.
+  * @intel_connector: eDP connector
+  * @fixed_mode: preferred mode of panel
+  *
+  * This function is  called only once at driver load to initialize basic
+  * DRRS stuff.
+  *
+  * Returns:
+  * Downclock mode if panel supports it, else return NULL.
+  * DRRS support is determined by the presence of downclock mode (apart
+  * from VBT setting).
+  */
  static struct drm_display_mode *
  intel_dp_drrs_init(struct intel_connector *intel_connector,
                struct drm_display_mode *fixed_mode)
                                        (dev, fixed_mode, connector);
  
        if (!downclock_mode) {
-               DRM_DEBUG_KMS("DRRS not supported\n");
+               DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
                return NULL;
        }
  
@@@ -501,6 -501,7 +501,7 @@@ struct intel_plane_wm_parameters 
        uint8_t bytes_per_pixel;
        bool enabled;
        bool scaled;
+       u64 tiling;
  };
  
  struct intel_plane {
@@@ -593,6 -594,26 +594,26 @@@ struct intel_hdmi 
  struct intel_dp_mst_encoder;
  #define DP_MAX_DOWNSTREAM_PORTS               0x10
  
+ /*
+  * enum link_m_n_set:
+  *    When platform provides two set of M_N registers for dp, we can
+  *    program them and switch between them incase of DRRS.
+  *    But When only one such register is provided, we have to program the
+  *    required divider value on that registers itself based on the DRRS state.
+  *
+  * M1_N1      : Program dp_m_n on M1_N1 registers
+  *                      dp_m2_n2 on M2_N2 registers (If supported)
+  *
+  * M2_N2      : Program dp_m2_n2 on M1_N1 registers
+  *                      M2_N2 registers are not supported
+  */
+ enum link_m_n_set {
+       /* Sets the m1_n1 and m2_n2 */
+       M1_N1 = 0,
+       M2_N2
+ };
  struct intel_dp {
        uint32_t output_reg;
        uint32_t aux_ch_ctl_reg;
@@@ -883,6 -904,8 +904,8 @@@ int intel_fb_align_height(struct drm_de
                          uint64_t fb_format_modifier);
  void intel_fb_obj_flush(struct drm_i915_gem_object *obj, bool retire);
  
+ u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier,
+                             uint32_t pixel_format);
  
  /* intel_audio.c */
  void intel_init_audio(struct drm_device *dev);
@@@ -943,11 -966,9 +966,11 @@@ void intel_finish_page_flip(struct drm_
  void intel_finish_page_flip_plane(struct drm_device *dev, int plane);
  void intel_check_page_flip(struct drm_device *dev, int pipe);
  int intel_prepare_plane_fb(struct drm_plane *plane,
 -                         struct drm_framebuffer *fb);
 +                         struct drm_framebuffer *fb,
 +                         const struct drm_plane_state *new_state);
  void intel_cleanup_plane_fb(struct drm_plane *plane,
 -                          struct drm_framebuffer *fb);
 +                          struct drm_framebuffer *fb,
 +                          const struct drm_plane_state *old_state);
  int intel_plane_atomic_get_property(struct drm_plane *plane,
                                    const struct drm_plane_state *state,
                                    struct drm_property *property,
@@@ -996,7 -1017,7 +1019,7 @@@ void hsw_enable_pc8(struct drm_i915_pri
  void hsw_disable_pc8(struct drm_i915_private *dev_priv);
  void intel_dp_get_m_n(struct intel_crtc *crtc,
                      struct intel_crtc_state *pipe_config);
- void intel_dp_set_m_n(struct intel_crtc *crtc);
+ void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n);
  int intel_dotclock_calculate(int link_freq, const struct intel_link_m_n *m_n);
  void
  ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config,
@@@ -620,7 -620,7 +620,7 @@@ static int execlists_move_to_gpu(struc
   * @vmas: list of vmas.
   * @batch_obj: the batchbuffer to submit.
   * @exec_start: batchbuffer start virtual address pointer.
-  * @flags: translated execbuffer call flags.
+  * @dispatch_flags: translated execbuffer call flags.
   *
   * This is the evil twin version of i915_gem_ringbuffer_submission. It abstracts
   * away the submission details of the execbuffer ioctl call.
@@@ -633,7 -633,7 +633,7 @@@ int intel_execlists_submission(struct d
                               struct drm_i915_gem_execbuffer2 *args,
                               struct list_head *vmas,
                               struct drm_i915_gem_object *batch_obj,
-                              u64 exec_start, u32 flags)
+                              u64 exec_start, u32 dispatch_flags)
  {
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct intel_ringbuffer *ringbuf = ctx->engine[ring->id].ringbuf;
                dev_priv->relative_constants_mode = instp_mode;
        }
  
-       ret = ring->emit_bb_start(ringbuf, ctx, exec_start, flags);
+       ret = ring->emit_bb_start(ringbuf, ctx, exec_start, dispatch_flags);
        if (ret)
                return ret;
  
+       trace_i915_gem_ring_dispatch(intel_ring_get_request(ring), dispatch_flags);
        i915_gem_execbuffer_move_to_active(vmas, ring);
        i915_gem_execbuffer_retire_commands(dev, file, ring, batch_obj);
  
@@@ -886,12 -888,9 +888,9 @@@ static int logical_ring_alloc_request(s
                return ret;
        }
  
-       /* Hold a reference to the context this request belongs to
-        * (we will need it when the time comes to emit/retire the
-        * request).
-        */
        request->ctx = ctx;
        i915_gem_context_reference(request->ctx);
+       request->ringbuf = ctx->engine[ring->id].ringbuf;
  
        ring->outstanding_lazy_request = request;
        return 0;
@@@ -1163,9 -1162,9 +1162,9 @@@ static int gen9_init_render_ring(struc
  
  static int gen8_emit_bb_start(struct intel_ringbuffer *ringbuf,
                              struct intel_context *ctx,
-                             u64 offset, unsigned flags)
+                             u64 offset, unsigned dispatch_flags)
  {
-       bool ppgtt = !(flags & I915_DISPATCH_SECURE);
+       bool ppgtt = !(dispatch_flags & I915_DISPATCH_SECURE);
        int ret;
  
        ret = intel_logical_ring_begin(ringbuf, ctx, 4);
@@@ -1232,17 -1231,15 +1231,17 @@@ static int gen8_emit_flush(struct intel
  
        cmd = MI_FLUSH_DW + 1;
  
 -      if (ring == &dev_priv->ring[VCS]) {
 -              if (invalidate_domains & I915_GEM_GPU_DOMAINS)
 -                      cmd |= MI_INVALIDATE_TLB | MI_INVALIDATE_BSD |
 -                              MI_FLUSH_DW_STORE_INDEX |
 -                              MI_FLUSH_DW_OP_STOREDW;
 -      } else {
 -              if (invalidate_domains & I915_GEM_DOMAIN_RENDER)
 -                      cmd |= MI_INVALIDATE_TLB | MI_FLUSH_DW_STORE_INDEX |
 -                              MI_FLUSH_DW_OP_STOREDW;
 +      /* We always require a command barrier so that subsequent
 +       * commands, such as breadcrumb interrupts, are strictly ordered
 +       * wrt the contents of the write cache being flushed to memory
 +       * (and thus being coherent from the CPU).
 +       */
 +      cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW;
 +
 +      if (invalidate_domains & I915_GEM_GPU_DOMAINS) {
 +              cmd |= MI_INVALIDATE_TLB;
 +              if (ring == &dev_priv->ring[VCS])
 +                      cmd |= MI_INVALIDATE_BSD;
        }
  
        intel_logical_ring_emit(ringbuf, cmd);
@@@ -1638,6 -1635,49 +1637,49 @@@ cleanup_render_ring
        return ret;
  }
  
+ static u32
+ make_rpcs(struct drm_device *dev)
+ {
+       u32 rpcs = 0;
+       /*
+        * No explicit RPCS request is needed to ensure full
+        * slice/subslice/EU enablement prior to Gen9.
+       */
+       if (INTEL_INFO(dev)->gen < 9)
+               return 0;
+       /*
+        * Starting in Gen9, render power gating can leave
+        * slice/subslice/EU in a partially enabled state. We
+        * must make an explicit request through RPCS for full
+        * enablement.
+       */
+       if (INTEL_INFO(dev)->has_slice_pg) {
+               rpcs |= GEN8_RPCS_S_CNT_ENABLE;
+               rpcs |= INTEL_INFO(dev)->slice_total <<
+                       GEN8_RPCS_S_CNT_SHIFT;
+               rpcs |= GEN8_RPCS_ENABLE;
+       }
+       if (INTEL_INFO(dev)->has_subslice_pg) {
+               rpcs |= GEN8_RPCS_SS_CNT_ENABLE;
+               rpcs |= INTEL_INFO(dev)->subslice_per_slice <<
+                       GEN8_RPCS_SS_CNT_SHIFT;
+               rpcs |= GEN8_RPCS_ENABLE;
+       }
+       if (INTEL_INFO(dev)->has_eu_pg) {
+               rpcs |= INTEL_INFO(dev)->eu_per_subslice <<
+                       GEN8_RPCS_EU_MIN_SHIFT;
+               rpcs |= INTEL_INFO(dev)->eu_per_subslice <<
+                       GEN8_RPCS_EU_MAX_SHIFT;
+               rpcs |= GEN8_RPCS_ENABLE;
+       }
+       return rpcs;
+ }
  static int
  populate_lr_context(struct intel_context *ctx, struct drm_i915_gem_object *ctx_obj,
                    struct intel_engine_cs *ring, struct intel_ringbuffer *ringbuf)
        reg_state[CTX_PDP1_LDW] = GEN8_RING_PDP_LDW(ring, 1);
        reg_state[CTX_PDP0_UDW] = GEN8_RING_PDP_UDW(ring, 0);
        reg_state[CTX_PDP0_LDW] = GEN8_RING_PDP_LDW(ring, 0);
-       reg_state[CTX_PDP3_UDW+1] = upper_32_bits(ppgtt->pd_dma_addr[3]);
-       reg_state[CTX_PDP3_LDW+1] = lower_32_bits(ppgtt->pd_dma_addr[3]);
-       reg_state[CTX_PDP2_UDW+1] = upper_32_bits(ppgtt->pd_dma_addr[2]);
-       reg_state[CTX_PDP2_LDW+1] = lower_32_bits(ppgtt->pd_dma_addr[2]);
-       reg_state[CTX_PDP1_UDW+1] = upper_32_bits(ppgtt->pd_dma_addr[1]);
-       reg_state[CTX_PDP1_LDW+1] = lower_32_bits(ppgtt->pd_dma_addr[1]);
-       reg_state[CTX_PDP0_UDW+1] = upper_32_bits(ppgtt->pd_dma_addr[0]);
-       reg_state[CTX_PDP0_LDW+1] = lower_32_bits(ppgtt->pd_dma_addr[0]);
+       reg_state[CTX_PDP3_UDW+1] = upper_32_bits(ppgtt->pdp.page_directory[3]->daddr);
+       reg_state[CTX_PDP3_LDW+1] = lower_32_bits(ppgtt->pdp.page_directory[3]->daddr);
+       reg_state[CTX_PDP2_UDW+1] = upper_32_bits(ppgtt->pdp.page_directory[2]->daddr);
+       reg_state[CTX_PDP2_LDW+1] = lower_32_bits(ppgtt->pdp.page_directory[2]->daddr);
+       reg_state[CTX_PDP1_UDW+1] = upper_32_bits(ppgtt->pdp.page_directory[1]->daddr);
+       reg_state[CTX_PDP1_LDW+1] = lower_32_bits(ppgtt->pdp.page_directory[1]->daddr);
+       reg_state[CTX_PDP0_UDW+1] = upper_32_bits(ppgtt->pdp.page_directory[0]->daddr);
+       reg_state[CTX_PDP0_LDW+1] = lower_32_bits(ppgtt->pdp.page_directory[0]->daddr);
        if (ring->id == RCS) {
                reg_state[CTX_LRI_HEADER_2] = MI_LOAD_REGISTER_IMM(1);
-               reg_state[CTX_R_PWR_CLK_STATE] = 0x20c8;
-               reg_state[CTX_R_PWR_CLK_STATE+1] = 0;
+               reg_state[CTX_R_PWR_CLK_STATE] = GEN8_R_PWR_CLK_STATE;
+               reg_state[CTX_R_PWR_CLK_STATE+1] = make_rpcs(dev);
        }
  
        kunmap_atomic(reg_state);
@@@ -1950,3 -1990,38 +1992,38 @@@ error_unpin_ctx
        drm_gem_object_unreference(&ctx_obj->base);
        return ret;
  }
+ void intel_lr_context_reset(struct drm_device *dev,
+                       struct intel_context *ctx)
+ {
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct intel_engine_cs *ring;
+       int i;
+       for_each_ring(ring, dev_priv, i) {
+               struct drm_i915_gem_object *ctx_obj =
+                               ctx->engine[ring->id].state;
+               struct intel_ringbuffer *ringbuf =
+                               ctx->engine[ring->id].ringbuf;
+               uint32_t *reg_state;
+               struct page *page;
+               if (!ctx_obj)
+                       continue;
+               if (i915_gem_object_get_pages(ctx_obj)) {
+                       WARN(1, "Failed get_pages for context obj\n");
+                       continue;
+               }
+               page = i915_gem_object_get_page(ctx_obj, 1);
+               reg_state = kmap_atomic(page);
+               reg_state[CTX_RING_HEAD+1] = 0;
+               reg_state[CTX_RING_TAIL+1] = 0;
+               kunmap_atomic(reg_state);
+               ringbuf->head = 0;
+               ringbuf->tail = 0;
+       }
+ }
@@@ -2522,6 -2522,7 +2522,7 @@@ skl_allocate_pipe_ddb(struct drm_crtc *
        enum pipe pipe = intel_crtc->pipe;
        struct skl_ddb_entry *alloc = &ddb->pipe[pipe];
        uint16_t alloc_size, start, cursor_blocks;
+       uint16_t minimum[I915_MAX_PLANES];
        unsigned int total_data_rate;
        int plane;
  
        alloc_size -= cursor_blocks;
        alloc->end -= cursor_blocks;
  
+       /* 1. Allocate the mininum required blocks for each active plane */
+       for_each_plane(pipe, plane) {
+               const struct intel_plane_wm_parameters *p;
+               p = &params->plane[plane];
+               if (!p->enabled)
+                       continue;
+               minimum[plane] = 8;
+               alloc_size -= minimum[plane];
+       }
        /*
-        * Each active plane get a portion of the remaining space, in
-        * proportion to the amount of data they need to fetch from memory.
+        * 2. Distribute the remaining space in proportion to the amount of
+        * data each plane needs to fetch from memory.
         *
         * FIXME: we may not allocate every single block here.
         */
                 * promote the expression to 64 bits to avoid overflowing, the
                 * result is < available as data_rate / total_data_rate < 1
                 */
-               plane_blocks = div_u64((uint64_t)alloc_size * data_rate,
-                                      total_data_rate);
+               plane_blocks = minimum[plane];
+               plane_blocks += div_u64((uint64_t)alloc_size * data_rate,
+                                       total_data_rate);
  
                ddb->plane[pipe][plane].start = start;
                ddb->plane[pipe][plane].end = start + plane_blocks;
@@@ -2595,7 -2609,7 +2609,7 @@@ static uint32_t skl_wm_method1(uint32_
        if (latency == 0)
                return UINT_MAX;
  
-       wm_intermediate_val = latency * pixel_rate * bytes_per_pixel;
+       wm_intermediate_val = latency * pixel_rate * bytes_per_pixel / 512;
        ret = DIV_ROUND_UP(wm_intermediate_val, 1000);
  
        return ret;
  
  static uint32_t skl_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal,
                               uint32_t horiz_pixels, uint8_t bytes_per_pixel,
-                              uint32_t latency)
+                              uint64_t tiling, uint32_t latency)
  {
-       uint32_t ret, plane_bytes_per_line, wm_intermediate_val;
+       uint32_t ret;
+       uint32_t plane_bytes_per_line, plane_blocks_per_line;
+       uint32_t wm_intermediate_val;
  
        if (latency == 0)
                return UINT_MAX;
  
        plane_bytes_per_line = horiz_pixels * bytes_per_pixel;
+       if (tiling == I915_FORMAT_MOD_Y_TILED ||
+           tiling == I915_FORMAT_MOD_Yf_TILED) {
+               plane_bytes_per_line *= 4;
+               plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512);
+               plane_blocks_per_line /= 4;
+       } else {
+               plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512);
+       }
        wm_intermediate_val = latency * pixel_rate;
        ret = DIV_ROUND_UP(wm_intermediate_val, pipe_htotal * 1000) *
-                               plane_bytes_per_line;
+                               plane_blocks_per_line;
  
        return ret;
  }
@@@ -2662,6 -2688,7 +2688,7 @@@ static void skl_compute_wm_pipe_paramet
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
        enum pipe pipe = intel_crtc->pipe;
        struct drm_plane *plane;
+       struct drm_framebuffer *fb;
        int i = 1; /* Index for sprite planes start */
  
        p->active = intel_crtc_active(crtc);
                        crtc->primary->fb->bits_per_pixel / 8;
                p->plane[0].horiz_pixels = intel_crtc->config->pipe_src_w;
                p->plane[0].vert_pixels = intel_crtc->config->pipe_src_h;
+               p->plane[0].tiling = DRM_FORMAT_MOD_NONE;
+               fb = crtc->primary->state->fb;
+               /*
+                * Framebuffer can be NULL on plane disable, but it does not
+                * matter for watermarks if we assume no tiling in that case.
+                */
+               if (fb)
+                       p->plane[0].tiling = fb->modifier[0];
  
                p->cursor.enabled = true;
                p->cursor.bytes_per_pixel = 4;
        }
  }
  
- static bool skl_compute_plane_wm(struct skl_pipe_wm_parameters *p,
+ static bool skl_compute_plane_wm(const struct drm_i915_private *dev_priv,
+                                struct skl_pipe_wm_parameters *p,
                                 struct intel_plane_wm_parameters *p_params,
                                 uint16_t ddb_allocation,
-                                uint32_t mem_value,
+                                int level,
                                 uint16_t *out_blocks, /* out */
                                 uint8_t *out_lines /* out */)
  {
-       uint32_t method1, method2, plane_bytes_per_line, res_blocks, res_lines;
-       uint32_t result_bytes;
+       uint32_t latency = dev_priv->wm.skl_latency[level];
+       uint32_t method1, method2;
+       uint32_t plane_bytes_per_line, plane_blocks_per_line;
+       uint32_t res_blocks, res_lines;
+       uint32_t selected_result;
  
-       if (mem_value == 0 || !p->active || !p_params->enabled)
+       if (latency == 0 || !p->active || !p_params->enabled)
                return false;
  
        method1 = skl_wm_method1(p->pixel_rate,
                                 p_params->bytes_per_pixel,
-                                mem_value);
+                                latency);
        method2 = skl_wm_method2(p->pixel_rate,
                                 p->pipe_htotal,
                                 p_params->horiz_pixels,
                                 p_params->bytes_per_pixel,
-                                mem_value);
+                                p_params->tiling,
+                                latency);
  
        plane_bytes_per_line = p_params->horiz_pixels *
                                        p_params->bytes_per_pixel;
+       plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512);
  
-       /* For now xtile and linear */
-       if (((ddb_allocation * 512) / plane_bytes_per_line) >= 1)
-               result_bytes = min(method1, method2);
-       else
-               result_bytes = method1;
+       if (p_params->tiling == I915_FORMAT_MOD_Y_TILED ||
+           p_params->tiling == I915_FORMAT_MOD_Yf_TILED) {
+               uint32_t y_tile_minimum = plane_blocks_per_line * 4;
+               selected_result = max(method2, y_tile_minimum);
+       } else {
+               if ((ddb_allocation / plane_blocks_per_line) >= 1)
+                       selected_result = min(method1, method2);
+               else
+                       selected_result = method1;
+       }
  
-       res_blocks = DIV_ROUND_UP(result_bytes, 512) + 1;
-       res_lines = DIV_ROUND_UP(result_bytes, plane_bytes_per_line);
+       res_blocks = selected_result + 1;
+       res_lines = DIV_ROUND_UP(selected_result, plane_blocks_per_line);
  
-       if (res_blocks > ddb_allocation || res_lines > 31)
+       if (level >= 1 && level <= 7) {
+               if (p_params->tiling == I915_FORMAT_MOD_Y_TILED ||
+                   p_params->tiling == I915_FORMAT_MOD_Yf_TILED)
+                       res_lines += 4;
+               else
+                       res_blocks++;
+       }
+       if (res_blocks >= ddb_allocation || res_lines > 31)
                return false;
  
        *out_blocks = res_blocks;
@@@ -2744,23 -2798,24 +2798,24 @@@ static void skl_compute_wm_level(const 
                                 int num_planes,
                                 struct skl_wm_level *result)
  {
-       uint16_t latency = dev_priv->wm.skl_latency[level];
        uint16_t ddb_blocks;
        int i;
  
        for (i = 0; i < num_planes; i++) {
                ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][i]);
  
-               result->plane_en[i] = skl_compute_plane_wm(p, &p->plane[i],
+               result->plane_en[i] = skl_compute_plane_wm(dev_priv,
+                                               p, &p->plane[i],
                                                ddb_blocks,
-                                               latency,
+                                               level,
                                                &result->plane_res_b[i],
                                                &result->plane_res_l[i]);
        }
  
        ddb_blocks = skl_ddb_entry_size(&ddb->cursor[pipe]);
-       result->cursor_en = skl_compute_plane_wm(p, &p->cursor, ddb_blocks,
-                                                latency, &result->cursor_res_b,
+       result->cursor_en = skl_compute_plane_wm(dev_priv, p, &p->cursor,
+                                                ddb_blocks, level,
+                                                &result->cursor_res_b,
                                                 &result->cursor_res_l);
  }
  
@@@ -3153,12 -3208,20 +3208,20 @@@ skl_update_sprite_wm(struct drm_plane *
                     int pixel_size, bool enabled, bool scaled)
  {
        struct intel_plane *intel_plane = to_intel_plane(plane);
+       struct drm_framebuffer *fb = plane->state->fb;
  
        intel_plane->wm.enabled = enabled;
        intel_plane->wm.scaled = scaled;
        intel_plane->wm.horiz_pixels = sprite_width;
        intel_plane->wm.vert_pixels = sprite_height;
        intel_plane->wm.bytes_per_pixel = pixel_size;
+       intel_plane->wm.tiling = DRM_FORMAT_MOD_NONE;
+       /*
+        * Framebuffer can be NULL on plane disable, but it does not
+        * matter for watermarks if we assume no tiling in that case.
+        */
+       if (fb)
+               intel_plane->wm.tiling = fb->modifier[0];
  
        skl_update_wm(crtc);
  }
@@@ -4028,10 -4091,7 +4091,10 @@@ static void gen6_init_rps_frequencies(s
                                        &ddcc_status);
                if (0 == ret)
                        dev_priv->rps.efficient_freq =
 -                              (ddcc_status >> 8) & 0xff;
 +                              clamp_t(u8,
 +                                      ((ddcc_status >> 8) & 0xff),
 +                                      dev_priv->rps.min_freq,
 +                                      dev_priv->rps.max_freq);
        }
  
        /* Preserve min/max settings in case of re-init */
@@@ -1002,11 -1002,62 +1002,62 @@@ static int gen9_init_workarounds(struc
        return 0;
  }
  
+ static int skl_tune_iz_hashing(struct intel_engine_cs *ring)
+ {
+       struct drm_device *dev = ring->dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       u8 vals[3] = { 0, 0, 0 };
+       unsigned int i;
+       for (i = 0; i < 3; i++) {
+               u8 ss;
+               /*
+                * Only consider slices where one, and only one, subslice has 7
+                * EUs
+                */
+               if (hweight8(dev_priv->info.subslice_7eu[i]) != 1)
+                       continue;
+               /*
+                * subslice_7eu[i] != 0 (because of the check above) and
+                * ss_max == 4 (maximum number of subslices possible per slice)
+                *
+                * ->    0 <= ss <= 3;
+                */
+               ss = ffs(dev_priv->info.subslice_7eu[i]) - 1;
+               vals[i] = 3 - ss;
+       }
+       if (vals[0] == 0 && vals[1] == 0 && vals[2] == 0)
+               return 0;
+       /* Tune IZ hashing. See intel_device_info_runtime_init() */
+       WA_SET_FIELD_MASKED(GEN7_GT_MODE,
+                           GEN9_IZ_HASHING_MASK(2) |
+                           GEN9_IZ_HASHING_MASK(1) |
+                           GEN9_IZ_HASHING_MASK(0),
+                           GEN9_IZ_HASHING(2, vals[2]) |
+                           GEN9_IZ_HASHING(1, vals[1]) |
+                           GEN9_IZ_HASHING(0, vals[0]));
+       return 0;
+ }
  static int skl_init_workarounds(struct intel_engine_cs *ring)
  {
+       struct drm_device *dev = ring->dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
        gen9_init_workarounds(ring);
  
-       return 0;
+       /* WaDisablePowerCompilerClockGating:skl */
+       if (INTEL_REVID(dev) == SKL_REVID_B0)
+               WA_SET_BIT_MASKED(HIZ_CHICKEN,
+                                 BDW_HIZ_POWER_COMPILER_CLOCK_GATING_DISABLE);
+       return skl_tune_iz_hashing(ring);
  }
  
  int init_workarounds_ring(struct intel_engine_cs *ring)
@@@ -1690,7 -1741,7 +1741,7 @@@ gen8_ring_put_irq(struct intel_engine_c
  static int
  i965_dispatch_execbuffer(struct intel_engine_cs *ring,
                         u64 offset, u32 length,
-                        unsigned flags)
+                        unsigned dispatch_flags)
  {
        int ret;
  
        intel_ring_emit(ring,
                        MI_BATCH_BUFFER_START |
                        MI_BATCH_GTT |
-                       (flags & I915_DISPATCH_SECURE ? 0 : MI_BATCH_NON_SECURE_I965));
+                       (dispatch_flags & I915_DISPATCH_SECURE ?
+                        0 : MI_BATCH_NON_SECURE_I965));
        intel_ring_emit(ring, offset);
        intel_ring_advance(ring);
  
  #define I830_WA_SIZE max(I830_TLB_ENTRIES*4096, I830_BATCH_LIMIT)
  static int
  i830_dispatch_execbuffer(struct intel_engine_cs *ring,
-                               u64 offset, u32 len,
-                               unsigned flags)
+                        u64 offset, u32 len,
+                        unsigned dispatch_flags)
  {
        u32 cs_offset = ring->scratch.gtt_offset;
        int ret;
        intel_ring_emit(ring, MI_NOOP);
        intel_ring_advance(ring);
  
-       if ((flags & I915_DISPATCH_PINNED) == 0) {
+       if ((dispatch_flags & I915_DISPATCH_PINNED) == 0) {
                if (len > I830_BATCH_LIMIT)
                        return -ENOSPC;
  
                return ret;
  
        intel_ring_emit(ring, MI_BATCH_BUFFER);
-       intel_ring_emit(ring, offset | (flags & I915_DISPATCH_SECURE ? 0 : MI_BATCH_NON_SECURE));
+       intel_ring_emit(ring, offset | (dispatch_flags & I915_DISPATCH_SECURE ?
+                                       0 : MI_BATCH_NON_SECURE));
        intel_ring_emit(ring, offset + len - 8);
        intel_ring_emit(ring, MI_NOOP);
        intel_ring_advance(ring);
  static int
  i915_dispatch_execbuffer(struct intel_engine_cs *ring,
                         u64 offset, u32 len,
-                        unsigned flags)
+                        unsigned dispatch_flags)
  {
        int ret;
  
                return ret;
  
        intel_ring_emit(ring, MI_BATCH_BUFFER_START | MI_BATCH_GTT);
-       intel_ring_emit(ring, offset | (flags & I915_DISPATCH_SECURE ? 0 : MI_BATCH_NON_SECURE));
+       intel_ring_emit(ring, offset | (dispatch_flags & I915_DISPATCH_SECURE ?
+                                       0 : MI_BATCH_NON_SECURE));
        intel_ring_advance(ring);
  
        return 0;
@@@ -2176,6 -2230,7 +2230,7 @@@ intel_ring_alloc_request(struct intel_e
  
        kref_init(&request->ref);
        request->ring = ring;
+       request->ringbuf = ring->buffer;
        request->uniq = dev_private->request_uniq++;
  
        ret = i915_gem_get_seqno(ring->dev, &request->seqno);
@@@ -2319,14 -2374,6 +2374,14 @@@ static int gen6_bsd_ring_flush(struct i
        cmd = MI_FLUSH_DW;
        if (INTEL_INFO(ring->dev)->gen >= 8)
                cmd += 1;
 +
 +      /* We always require a command barrier so that subsequent
 +       * commands, such as breadcrumb interrupts, are strictly ordered
 +       * wrt the contents of the write cache being flushed to memory
 +       * (and thus being coherent from the CPU).
 +       */
 +      cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW;
 +
        /*
         * Bspec vol 1c.5 - video engine command streamer:
         * "If ENABLED, all TLBs will be invalidated once the flush
         * Post-Sync Operation field is a value of 1h or 3h."
         */
        if (invalidate & I915_GEM_GPU_DOMAINS)
 -              cmd |= MI_INVALIDATE_TLB | MI_INVALIDATE_BSD |
 -                      MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW;
 +              cmd |= MI_INVALIDATE_TLB | MI_INVALIDATE_BSD;
 +
        intel_ring_emit(ring, cmd);
        intel_ring_emit(ring, I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT);
        if (INTEL_INFO(ring->dev)->gen >= 8) {
  static int
  gen8_ring_dispatch_execbuffer(struct intel_engine_cs *ring,
                              u64 offset, u32 len,
-                             unsigned flags)
+                             unsigned dispatch_flags)
  {
-       bool ppgtt = USES_PPGTT(ring->dev) && !(flags & I915_DISPATCH_SECURE);
+       bool ppgtt = USES_PPGTT(ring->dev) &&
+                       !(dispatch_flags & I915_DISPATCH_SECURE);
        int ret;
  
        ret = intel_ring_begin(ring, 4);
  
  static int
  hsw_ring_dispatch_execbuffer(struct intel_engine_cs *ring,
-                             u64 offset, u32 len,
-                             unsigned flags)
+                            u64 offset, u32 len,
+                            unsigned dispatch_flags)
  {
        int ret;
  
  
        intel_ring_emit(ring,
                        MI_BATCH_BUFFER_START |
-                       (flags & I915_DISPATCH_SECURE ?
+                       (dispatch_flags & I915_DISPATCH_SECURE ?
                         0 : MI_BATCH_PPGTT_HSW | MI_BATCH_NON_SECURE_HSW));
        /* bit0-7 is the length on GEN6+ */
        intel_ring_emit(ring, offset);
  static int
  gen6_ring_dispatch_execbuffer(struct intel_engine_cs *ring,
                              u64 offset, u32 len,
-                             unsigned flags)
+                             unsigned dispatch_flags)
  {
        int ret;
  
  
        intel_ring_emit(ring,
                        MI_BATCH_BUFFER_START |
-                       (flags & I915_DISPATCH_SECURE ? 0 : MI_BATCH_NON_SECURE_I965));
+                       (dispatch_flags & I915_DISPATCH_SECURE ?
+                        0 : MI_BATCH_NON_SECURE_I965));
        /* bit0-7 is the length on GEN6+ */
        intel_ring_emit(ring, offset);
        intel_ring_advance(ring);
@@@ -2431,14 -2480,6 +2488,14 @@@ static int gen6_ring_flush(struct intel
        cmd = MI_FLUSH_DW;
        if (INTEL_INFO(ring->dev)->gen >= 8)
                cmd += 1;
 +
 +      /* We always require a command barrier so that subsequent
 +       * commands, such as breadcrumb interrupts, are strictly ordered
 +       * wrt the contents of the write cache being flushed to memory
 +       * (and thus being coherent from the CPU).
 +       */
 +      cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW;
 +
        /*
         * Bspec vol 1c.3 - blitter engine command streamer:
         * "If ENABLED, all TLBs will be invalidated once the flush
         * Post-Sync Operation field is a value of 1h or 3h."
         */
        if (invalidate & I915_GEM_DOMAIN_RENDER)
 -              cmd |= MI_INVALIDATE_TLB | MI_FLUSH_DW_STORE_INDEX |
 -                      MI_FLUSH_DW_OP_STOREDW;
 +              cmd |= MI_INVALIDATE_TLB;
        intel_ring_emit(ring, cmd);
        intel_ring_emit(ring, I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT);
        if (INTEL_INFO(ring->dev)->gen >= 8) {
@@@ -167,8 -167,7 +167,8 @@@ fw_domains_reset(struct drm_i915_privat
        struct intel_uncore_forcewake_domain *d;
        enum forcewake_domain_id id;
  
 -      WARN_ON(dev_priv->uncore.fw_domains == 0);
 +      if (dev_priv->uncore.fw_domains == 0)
 +              return;
  
        for_each_fw_domain_mask(d, fw_domains, dev_priv, id)
                fw_domain_reset(d);
@@@ -211,6 -210,13 +211,13 @@@ static void fw_domains_put_with_fifo(st
        gen6_gt_check_fifodbg(dev_priv);
  }
  
+ static inline u32 fifo_free_entries(struct drm_i915_private *dev_priv)
+ {
+       u32 count = __raw_i915_read32(dev_priv, GTFIFOCTL);
+       return count & GT_FIFO_FREE_ENTRIES_MASK;
+ }
  static int __gen6_gt_wait_for_fifo(struct drm_i915_private *dev_priv)
  {
        int ret = 0;
        /* On VLV, FIFO will be shared by both SW and HW.
         * So, we need to read the FREE_ENTRIES everytime */
        if (IS_VALLEYVIEW(dev_priv->dev))
-               dev_priv->uncore.fifo_count =
-                       __raw_i915_read32(dev_priv, GTFIFOCTL) &
-                                               GT_FIFO_FREE_ENTRIES_MASK;
+               dev_priv->uncore.fifo_count = fifo_free_entries(dev_priv);
  
        if (dev_priv->uncore.fifo_count < GT_FIFO_NUM_RESERVED_ENTRIES) {
                int loop = 500;
-               u32 fifo = __raw_i915_read32(dev_priv, GTFIFOCTL) & GT_FIFO_FREE_ENTRIES_MASK;
+               u32 fifo = fifo_free_entries(dev_priv);
                while (fifo <= GT_FIFO_NUM_RESERVED_ENTRIES && loop--) {
                        udelay(10);
-                       fifo = __raw_i915_read32(dev_priv, GTFIFOCTL) & GT_FIFO_FREE_ENTRIES_MASK;
+                       fifo = fifo_free_entries(dev_priv);
                }
                if (WARN_ON(loop < 0 && fifo <= GT_FIFO_NUM_RESERVED_ENTRIES))
                        ++ret;
@@@ -315,8 -320,7 +321,7 @@@ void intel_uncore_forcewake_reset(struc
  
                if (IS_GEN6(dev) || IS_GEN7(dev))
                        dev_priv->uncore.fifo_count =
-                               __raw_i915_read32(dev_priv, GTFIFOCTL) &
-                               GT_FIFO_FREE_ENTRIES_MASK;
+                               fifo_free_entries(dev_priv);
        }
  
        if (!restore)
@@@ -1027,9 -1031,6 +1032,9 @@@ static void intel_uncore_fw_domains_ini
  {
        struct drm_i915_private *dev_priv = dev->dev_private;
  
 +      if (INTEL_INFO(dev_priv->dev)->gen <= 5)
 +              return;
 +
        if (IS_GEN9(dev)) {
                dev_priv->uncore.funcs.force_wake_get = fw_domains_get;
                dev_priv->uncore.funcs.force_wake_put = fw_domains_put;
                fw_domain_init(dev_priv, FW_DOMAIN_ID_RENDER,
                               FORCEWAKE, FORCEWAKE_ACK);
        }
 +
 +      /* All future platforms are expected to require complex power gating */
 +      WARN_ON(dev_priv->uncore.fw_domains == 0);
  }
  
  void intel_uncore_init(struct drm_device *dev)
diff --combined include/drm/drmP.h
@@@ -104,9 -104,6 +104,9 @@@ struct dma_buf_attachment
   * PRIME: used in the prime code.
   *      This is the category used by the DRM_DEBUG_PRIME() macro.
   *
 + * ATOMIC: used in the atomic code.
 + *      This is the category used by the DRM_DEBUG_ATOMIC() macro.
 + *
   * Enabling verbose debug messages is done through the drm.debug parameter,
   * each category being enabled by a bit.
   *
  #define DRM_UT_DRIVER         0x02
  #define DRM_UT_KMS            0x04
  #define DRM_UT_PRIME          0x08
 +#define DRM_UT_ATOMIC         0x10
  
  extern __printf(2, 3)
  void drm_ut_debug_printk(const char *function_name,
@@@ -211,11 -207,6 +211,11 @@@ void drm_err(const char *format, ...)
                if (unlikely(drm_debug & DRM_UT_PRIME))                 \
                        drm_ut_debug_printk(__func__, fmt, ##args);     \
        } while (0)
 +#define DRM_DEBUG_ATOMIC(fmt, args...)                                        \
 +      do {                                                            \
 +              if (unlikely(drm_debug & DRM_UT_ATOMIC))                \
 +                      drm_ut_debug_printk(__func__, fmt, ##args);     \
 +      } while (0)
  
  /*@}*/
  
@@@ -931,6 -922,7 +931,7 @@@ extern void drm_crtc_wait_one_vblank(st
  extern void drm_vblank_off(struct drm_device *dev, int crtc);
  extern void drm_vblank_on(struct drm_device *dev, int crtc);
  extern void drm_crtc_vblank_off(struct drm_crtc *crtc);
+ extern void drm_crtc_vblank_reset(struct drm_crtc *crtc);
  extern void drm_crtc_vblank_on(struct drm_crtc *crtc);
  extern void drm_vblank_cleanup(struct drm_device *dev);
  
  #define DRM_FORMAT_NV24               fourcc_code('N', 'V', '2', '4') /* non-subsampled Cr:Cb plane */
  #define DRM_FORMAT_NV42               fourcc_code('N', 'V', '4', '2') /* non-subsampled Cb:Cr plane */
  
 -/* special NV12 tiled format */
 -#define DRM_FORMAT_NV12MT     fourcc_code('T', 'M', '1', '2') /* 2x2 subsampled Cr:Cb plane 64x32 macroblocks */
 -
  /*
   * 3 plane YCbCr
   * index 0: Y plane, [7:0] Y
   */
  #define I915_FORMAT_MOD_Y_TILED       fourcc_mod_code(INTEL, 2)
  
+ /*
+  * Intel Yf-tiling layout
+  *
+  * This is a tiled layout using 4Kb tiles in row-major layout.
+  * Within the tile pixels are laid out in 16 256 byte units / sub-tiles which
+  * are arranged in four groups (two wide, two high) with column-major layout.
+  * Each group therefore consits out of four 256 byte units, which are also laid
+  * out as 2x2 column-major.
+  * 256 byte units are made out of four 64 byte blocks of pixels, producing
+  * either a square block or a 2:1 unit.
+  * 64 byte blocks of pixels contain four pixel rows of 16 bytes, where the width
+  * in pixel depends on the pixel depth.
+  */
+ #define I915_FORMAT_MOD_Yf_TILED fourcc_mod_code(INTEL, 3)
  #endif /* DRM_FOURCC_H */