drm: Add drm_vblank_on()
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Wed, 19 Feb 2014 19:29:49 +0000 (21:29 +0200)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Tue, 20 May 2014 19:13:35 +0000 (21:13 +0200)
drm_vblank_off() will turn off vblank interrupts, but as long as the
refcount is elevated drm_vblank_get() will not re-enable them. This
is a problem is someone is holding a vblank reference while a modeset is
happening, and the driver requires vblank interrupt to work during that
time.

Add drm_vblank_on() as a counterpart to drm_vblank_off() which will
re-enabled vblank interrupts if the refcount is already elevated. This
will allow drivers to choose the specific places in the modeset sequence
at which vblank interrupts get disabled and enabled.

Testcase: igt/kms_flip/*-vs-suspend
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
[danvet: Add Testcase tag for the igt I've written.]
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
drivers/gpu/drm/drm_irq.c
drivers/gpu/drm/i915/intel_display.c
include/drm/drmP.h

index 13d671ed3421443ad341d73749bd176642a2995a..dd786d84daab9ccf5f3c13995c2144fdda557d29 100644 (file)
@@ -839,6 +839,41 @@ static void drm_update_vblank_count(struct drm_device *dev, int crtc)
        smp_mb__after_atomic_inc();
 }
 
+/**
+ * drm_vblank_enable - enable the vblank interrupt on a CRTC
+ * @dev: DRM device
+ * @crtc: CRTC in question
+ */
+static int drm_vblank_enable(struct drm_device *dev, int crtc)
+{
+       int ret = 0;
+
+       assert_spin_locked(&dev->vbl_lock);
+
+       spin_lock(&dev->vblank_time_lock);
+
+       if (!dev->vblank[crtc].enabled) {
+               /* Enable vblank irqs under vblank_time_lock protection.
+                * All vblank count & timestamp updates are held off
+                * until we are done reinitializing master counter and
+                * timestamps. Filtercode in drm_handle_vblank() will
+                * prevent double-accounting of same vblank interval.
+                */
+               ret = dev->driver->enable_vblank(dev, crtc);
+               DRM_DEBUG("enabling vblank on crtc %d, ret: %d\n", crtc, ret);
+               if (ret)
+                       atomic_dec(&dev->vblank[crtc].refcount);
+               else {
+                       dev->vblank[crtc].enabled = true;
+                       drm_update_vblank_count(dev, crtc);
+               }
+       }
+
+       spin_unlock(&dev->vblank_time_lock);
+
+       return ret;
+}
+
 /**
  * drm_vblank_get - get a reference count on vblank events
  * @dev: DRM device
@@ -858,25 +893,7 @@ int drm_vblank_get(struct drm_device *dev, int crtc)
        spin_lock_irqsave(&dev->vbl_lock, irqflags);
        /* Going from 0->1 means we have to enable interrupts again */
        if (atomic_add_return(1, &dev->vblank[crtc].refcount) == 1) {
-               spin_lock(&dev->vblank_time_lock);
-               if (!dev->vblank[crtc].enabled) {
-                       /* Enable vblank irqs under vblank_time_lock protection.
-                        * All vblank count & timestamp updates are held off
-                        * until we are done reinitializing master counter and
-                        * timestamps. Filtercode in drm_handle_vblank() will
-                        * prevent double-accounting of same vblank interval.
-                        */
-                       ret = dev->driver->enable_vblank(dev, crtc);
-                       DRM_DEBUG("enabling vblank on crtc %d, ret: %d\n",
-                                 crtc, ret);
-                       if (ret)
-                               atomic_dec(&dev->vblank[crtc].refcount);
-                       else {
-                               dev->vblank[crtc].enabled = true;
-                               drm_update_vblank_count(dev, crtc);
-                       }
-               }
-               spin_unlock(&dev->vblank_time_lock);
+               ret = drm_vblank_enable(dev, crtc);
        } else {
                if (!dev->vblank[crtc].enabled) {
                        atomic_dec(&dev->vblank[crtc].refcount);
@@ -945,6 +962,23 @@ void drm_vblank_off(struct drm_device *dev, int crtc)
 }
 EXPORT_SYMBOL(drm_vblank_off);
 
+/**
+ * drm_vblank_on - enable vblank events on a CRTC
+ * @dev: DRM device
+ * @crtc: CRTC in question
+ */
+void drm_vblank_on(struct drm_device *dev, int crtc)
+{
+       unsigned long irqflags;
+
+       spin_lock_irqsave(&dev->vbl_lock, irqflags);
+       /* re-enable interrupts if there's are users left */
+       if (atomic_read(&dev->vblank[crtc].refcount) != 0)
+               WARN_ON(drm_vblank_enable(dev, crtc));
+       spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
+}
+EXPORT_SYMBOL(drm_vblank_on);
+
 /**
  * drm_vblank_pre_modeset - account for vblanks across mode sets
  * @dev: DRM device
index 72b5c34d8ce7bee4388c92ddf2ae2f520336b7e1..313f29d1aae281837cc779c7686231d779cb54db 100644 (file)
@@ -3737,6 +3737,8 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
         * happening.
         */
        intel_wait_for_vblank(dev, intel_crtc->pipe);
+
+       drm_vblank_on(dev, pipe);
 }
 
 /* IPS only exists on ULT machines and is tied to pipe A. */
@@ -3828,6 +3830,8 @@ static void haswell_crtc_enable(struct drm_crtc *crtc)
         * to change the workaround. */
        haswell_mode_set_planes_workaround(intel_crtc);
        ilk_crtc_enable_planes(crtc);
+
+       drm_vblank_on(dev, pipe);
 }
 
 static void ironlake_pfit_disable(struct intel_crtc *crtc)
@@ -4351,6 +4355,8 @@ static void valleyview_crtc_enable(struct drm_crtc *crtc)
 
        for_each_encoder_on_crtc(dev, crtc, encoder)
                encoder->enable(encoder);
+
+       drm_vblank_on(dev, pipe);
 }
 
 static void i9xx_crtc_enable(struct drm_crtc *crtc)
@@ -4398,6 +4404,8 @@ static void i9xx_crtc_enable(struct drm_crtc *crtc)
 
        for_each_encoder_on_crtc(dev, crtc, encoder)
                encoder->enable(encoder);
+
+       drm_vblank_on(dev, pipe);
 }
 
 static void i9xx_pfit_disable(struct intel_crtc *crtc)
index 9d982d483f123ecfdb47d2f2762a7c6759f298eb..7339b2b00724bd5df8a5da74a052ddbc04355951 100644 (file)
@@ -1360,6 +1360,7 @@ extern bool drm_handle_vblank(struct drm_device *dev, int crtc);
 extern int drm_vblank_get(struct drm_device *dev, int crtc);
 extern void drm_vblank_put(struct drm_device *dev, int crtc);
 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_vblank_cleanup(struct drm_device *dev);
 extern u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
                                     struct timeval *tvblank, unsigned flags);