From: Ville Syrjälä <ville.syrj...@linux.intel.com>

Refactor the i915_get_crtc_scanoutpos() code a bit to make the
"negative values during vblank" adjustment optional. For most uses
the raw scanline number without such adjustments is easier to use.

v2: Rebase after vblank timestamp changes.
    Use intel_ prefix instead of i915_ as is more customary for
    display related functions.
    Include DRM_SCANOUTPOS_INVBL in the return value even w/o
    adjustments, for a bit of extra consistency.

Reviewed-by: Jesse Barnes <jbar...@virtuousgeek.org>
Signed-off-by: Ville Syrjälä <ville.syrj...@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_irq.c  | 46 +++++++++++++++++++++++++++++-----------
 drivers/gpu/drm/i915/intel_drv.h |  1 +
 2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index 6e1c2ff..da761a6a 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -675,7 +675,9 @@ static bool intel_pipe_in_vblank_locked(struct drm_device 
*dev, enum pipe pipe)
 }
 
 static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
-                            int *vpos, int *hpos, ktime_t *stime, ktime_t 
*etime)
+                                   int *vpos, int *hpos,
+                                   ktime_t *stime, ktime_t *etime,
+                                   bool adjust)
 {
        struct drm_i915_private *dev_priv = dev->dev_private;
        struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
@@ -756,16 +758,18 @@ static int i915_get_crtc_scanoutpos(struct drm_device 
*dev, int pipe,
 
        in_vbl = position >= vbl_start && position < vbl_end;
 
-       /*
-        * While in vblank, position will be negative
-        * counting up towards 0 at vbl_end. And outside
-        * vblank, position will be positive counting
-        * up since vbl_end.
-        */
-       if (position >= vbl_start)
-               position -= vbl_end;
-       else
-               position += vtotal - vbl_end;
+       if (adjust) {
+               /*
+                * While in vblank, position will be negative
+                * counting up towards 0 at vbl_end. And outside
+                * vblank, position will be positive counting
+                * up since vbl_end.
+                */
+               if (position >= vbl_start)
+                       position -= vbl_end;
+               else
+                       position += vtotal - vbl_end;
+       }
 
        if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
                *vpos = position;
@@ -782,6 +786,24 @@ static int i915_get_crtc_scanoutpos(struct drm_device 
*dev, int pipe,
        return ret;
 }
 
+static int i915_get_scanout_position(struct drm_device *dev, int pipe,
+                                    int *vpos, int *hpos,
+                                    ktime_t *stime, ktime_t *etime)
+{
+       return i915_get_crtc_scanoutpos(dev, pipe, vpos, hpos,
+                                       stime, etime, true);
+}
+
+int intel_get_crtc_scanline(struct drm_crtc *crtc)
+{
+       int vpos = 0, hpos = 0;
+
+       i915_get_crtc_scanoutpos(crtc->dev, to_intel_crtc(crtc)->pipe,
+                                &vpos, &hpos, NULL, NULL, false);
+
+       return vpos;
+}
+
 static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
                              int *max_error,
                              struct timeval *vblank_time,
@@ -3805,7 +3827,7 @@ void intel_irq_init(struct drm_device *dev)
 
        if (drm_core_check_feature(dev, DRIVER_MODESET)) {
                dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
-               dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
+               dev->driver->get_scanout_position = i915_get_scanout_position;
        }
 
        if (IS_VALLEYVIEW(dev)) {
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 2b72b1d..6df4b69 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -599,6 +599,7 @@ void snb_enable_pm_irq(struct drm_i915_private *dev_priv, 
uint32_t mask);
 void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask);
 void hsw_pc8_disable_interrupts(struct drm_device *dev);
 void hsw_pc8_restore_interrupts(struct drm_device *dev);
+int intel_get_crtc_scanline(struct drm_crtc *crtc);
 
 
 /* intel_crt.c */
-- 
1.8.3.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to