drm/i915: Grab modeset locks for GPU rest on pre-ctg
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Mon, 24 Nov 2014 16:28:11 +0000 (18:28 +0200)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Wed, 3 Dec 2014 08:29:38 +0000 (09:29 +0100)
On gen4 and earlier the GPU reset also resets the display, so we should
protect against concurrent modeset operations. Grab all the modeset locks
around the entire GPU reset dance, remebering first ti dislogde any
pending page flip to make sure we don't deadlock. Any pageflip coming
in between these two steps should fail anyway due to reset_in_progress,
so this should be safe.

This fixes a lot of failed asserts in the modeset code when there's a
modeset racing with the reset. Naturally the asserts aren't happy when
the expected state has disappeared.

v2: Drop UMS checks, complete pending flips after the reset (Daniel)

Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
drivers/gpu/drm/i915/i915_drv.c
drivers/gpu/drm/i915/i915_irq.c
drivers/gpu/drm/i915/intel_display.c
drivers/gpu/drm/i915/intel_drv.h

index 5066fd105512dcf43eda4d0b8d59cb9ee0ba851d..1e9c136a874cf1741e09aecc33c6cea37e26e1d4 100644 (file)
@@ -880,25 +880,6 @@ int i915_reset(struct drm_device *dev)
                 */
                if (INTEL_INFO(dev)->gen > 5)
                        intel_reset_gt_powersave(dev);
-
-
-               if (IS_GEN3(dev) || (IS_GEN4(dev) && !IS_G4X(dev))) {
-                       intel_runtime_pm_disable_interrupts(dev_priv);
-                       intel_runtime_pm_enable_interrupts(dev_priv);
-
-                       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);
-
-                       drm_modeset_lock_all(dev);
-                       intel_modeset_setup_hw_state(dev, true);
-                       drm_modeset_unlock_all(dev);
-
-                       intel_hpd_init(dev_priv);
-               }
        } else {
                mutex_unlock(&dev->struct_mutex);
        }
index 85c15ba6e73585b66809c3d177060821fc00d1d0..c02648f32a769a8459993b3ce0ab0597e30be583 100644 (file)
@@ -2423,6 +2423,9 @@ static void i915_error_work_func(struct work_struct *work)
                 * simulated reset via debugs, so get an RPM reference.
                 */
                intel_runtime_pm_get(dev_priv);
+
+               intel_prepare_reset(dev);
+
                /*
                 * All state reset _must_ be completed before we update the
                 * reset counter, for otherwise waiters might miss the reset
@@ -2431,7 +2434,7 @@ static void i915_error_work_func(struct work_struct *work)
                 */
                ret = i915_reset(dev);
 
-               intel_display_handle_reset(dev);
+               intel_finish_reset(dev);
 
                intel_runtime_pm_put(dev_priv);
 
index 3218455a7ade03d893e66bba9228e8ca42f56b02..56664e63e10f8e0f62c8080b1f25e7cfc05e0ed7 100644 (file)
@@ -2765,25 +2765,10 @@ intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
        return 0;
 }
 
-void intel_display_handle_reset(struct drm_device *dev)
+static void intel_complete_page_flips(struct drm_device *dev)
 {
-       struct drm_i915_private *dev_priv = dev->dev_private;
        struct drm_crtc *crtc;
 
-       /*
-        * Flips in the rings have been nuked by the reset,
-        * so complete all pending flips so that user space
-        * will get its events and not get stuck.
-        *
-        * Also update the base address of all primary
-        * planes to the the last fb to make sure we're
-        * showing the correct fb after a reset.
-        *
-        * Need to make two loops over the crtcs so that we
-        * don't try to grab a crtc mutex before the
-        * pending_flip_queue really got woken up.
-        */
-
        for_each_crtc(dev, crtc) {
                struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
                enum plane plane = intel_crtc->plane;
@@ -2791,6 +2776,12 @@ void intel_display_handle_reset(struct drm_device *dev)
                intel_prepare_page_flip(dev, plane);
                intel_finish_page_flip_plane(dev, plane);
        }
+}
+
+static void intel_update_primary_planes(struct drm_device *dev)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct drm_crtc *crtc;
 
        for_each_crtc(dev, crtc) {
                struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
@@ -2810,6 +2801,67 @@ void intel_display_handle_reset(struct drm_device *dev)
        }
 }
 
+void intel_prepare_reset(struct drm_device *dev)
+{
+       /* no reset support for gen2 */
+       if (IS_GEN2(dev))
+               return;
+
+       /* reset doesn't touch the display */
+       if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
+               return;
+
+       drm_modeset_lock_all(dev);
+}
+
+void intel_finish_reset(struct drm_device *dev)
+{
+       struct drm_i915_private *dev_priv = to_i915(dev);
+
+       /*
+        * Flips in the rings will be nuked by the reset,
+        * so complete all pending flips so that user space
+        * will get its events and not get stuck.
+        */
+       intel_complete_page_flips(dev);
+
+       /* no reset support for gen2 */
+       if (IS_GEN2(dev))
+               return;
+
+       /* reset doesn't touch the display */
+       if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) {
+               /*
+                * Flips in the rings have been nuked by the reset,
+                * so update the base address of all primary
+                * planes to the the last fb to make sure we're
+                * showing the correct fb after a reset.
+                */
+               intel_update_primary_planes(dev);
+               return;
+       }
+
+       /*
+        * The display has been reset as well,
+        * so need a full re-initialization.
+        */
+       intel_runtime_pm_disable_interrupts(dev_priv);
+       intel_runtime_pm_enable_interrupts(dev_priv);
+
+       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);
+
+       intel_modeset_setup_hw_state(dev, true);
+
+       intel_hpd_init(dev_priv);
+
+       drm_modeset_unlock_all(dev);
+}
+
 static int
 intel_finish_fb(struct drm_framebuffer *old_fb)
 {
index f0a46ecf3f3a0a7cb53c56f15690f5ad6399ce68..25fdbb16d4e0defa47f660d2f2a940582b83608f 100644 (file)
@@ -958,7 +958,8 @@ unsigned long intel_gen4_compute_page_offset(int *x, int *y,
                                             unsigned int tiling_mode,
                                             unsigned int bpp,
                                             unsigned int pitch);
-void intel_display_handle_reset(struct drm_device *dev);
+void intel_prepare_reset(struct drm_device *dev);
+void intel_finish_reset(struct drm_device *dev);
 void hsw_enable_pc8(struct drm_i915_private *dev_priv);
 void hsw_disable_pc8(struct drm_i915_private *dev_priv);
 void intel_dp_get_m_n(struct intel_crtc *crtc,