Skip to contentSkip to conversation

drm: Move ->get_scanout_position() to struct drm_crtc_funcs

PATCH In review Thierry Reding 2 participants 2 messages Dec 16, 2014

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: Move ->get_scanout_position() to struct drm_crtc_funcs

From: Thierry Reding <[email protected]>

None of the drivers use this in legacy mode, so it can be converted to use struct drm_crtc * directly. While at it, also make the sole user of the callback, drm_calc_vbltimestamp_from_scanoutpos(), pass through the CRTC directly.

Cc Daniel Vetter <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Ben Skeggs <[email protected]>
Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>

---
Note: This is compile-tested only. It is a straightforward conversion so I wouldn't expect any fallout, but it'd certainly be best if this can be tested on all three drivers.

 drivers/gpu/drm/drm_irq.c                 | 34 +++++++++-------------
 drivers/gpu/drm/i915/i915_irq.c           | 15 +++++-----
 drivers/gpu/drm/i915/intel_display.c      |  1 +
 drivers/gpu/drm/i915/intel_drv.h          |  3 ++
 drivers/gpu/drm/nouveau/dispnv04/crtc.c   |  1 +
 drivers/gpu/drm/nouveau/nouveau_display.c | 25 ++++------------
 drivers/gpu/drm/nouveau/nouveau_display.h |  4 +--
 drivers/gpu/drm/nouveau/nouveau_drm.c     |  1 -
 drivers/gpu/drm/nouveau/nv50_display.c    |  1 +
 drivers/gpu/drm/radeon/radeon_display.c   | 39 ++++++++++++-------------
 drivers/gpu/drm/radeon/radeon_drv.c       |  1 -
 drivers/gpu/drm/radeon/radeon_kms.c       |  2 +-
 drivers/gpu/drm/radeon/radeon_mode.h      |  2 +-
 drivers/gpu/drm/radeon/radeon_pm.c        |  4 ++-
 include/drm/drmP.h                        | 47 -------------------------------
 include/drm/drm_crtc.h                    | 45 +++++++++++++++++++++++++++++
 16 files changed, 104 insertions(+), 121 deletions(-)
drivers/gpu/drm/drm_irq.c +14 -20
index 37b536c57cd2..18f1ccad7ee0 100644
@@ -161,14 +161,14 @@ EXPORT_SYMBOL(drm_calc_timestamping_constants);
  * DRM_VBLANKTIME_INVBL - Timestamp taken while scanout was in vblank interval.
  *
  */
-int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
-					  unsigned int pipe,
+int drm_calc_vbltimestamp_from_scanoutpos(struct drm_crtc *crtc,
 					  int *max_error,
 					  struct timeval *vblank_time,
 					  unsigned flags,
 					  const struct drm_crtc *refcrtc,
 					  const struct drm_display_mode *mode)
 {
+	const struct drm_crtc_funcs *funcs = crtc->funcs;
 	struct timeval tv_etime;
 	ktime_t stime, etime;
 	int vbl_status;
@@ -176,16 +176,9 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
 	int framedur_ns, linedur_ns, pixeldur_ns, delta_ns, duration_ns;
 	bool invbl;
 
-	if (pipe >= dev->num_crtcs) {
-		DRM_ERROR("Invalid crtc %u\n", pipe);
-		return -EINVAL;
-	}
-
 	/* Scanout position query not supported? Should not happen. */
-	if (!dev->driver->get_scanout_position) {
-		DRM_ERROR("Called from driver w/o get_scanout_position()!?\n");
-		return -EIO;
-	}
+	if (WARN_ON(funcs->get_scanout_position == NULL))
+		return -ENOSYS;
 
 	/* Durations of frames, lines, pixels in nanoseconds. */
 	framedur_ns = refcrtc->framedur_ns;
@@ -196,7 +189,8 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
 	 * Happens during initial modesetting of a crtc.
 	 */
 	if (framedur_ns == 0) {
-		DRM_DEBUG("crtc %u: Noop due to uninitialized mode.\n", pipe);
+		DRM_DEBUG("crtc %x: Noop due to uninitialized mode.\n",
+			  crtc->base.id);
 		return -EAGAIN;
 	}
 
@@ -212,13 +206,13 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
 		 * Get vertical and horizontal scanout position vpos, hpos,
 		 * and bounding timestamps stime, etime, pre/post query.
 		 */
-		vbl_status = dev->driver->get_scanout_position(dev, pipe, flags, &vpos,
-							       &hpos, &stime, &etime);
+		vbl_status = funcs->get_scanout_position(crtc, flags, &vpos,
+							 &hpos, &stime, &etime);
 
 		/* Return as no-op if scanout query unsupported or failed. */
 		if (!(vbl_status & DRM_SCANOUTPOS_VALID)) {
-			DRM_DEBUG("crtc %u : scanoutpos query failed [%d].\n",
-				  pipe, vbl_status);
+			DRM_DEBUG("crtc %x: scanoutpos query failed [%d].\n",
+				  crtc->base.id, vbl_status);
 			return -EIO;
 		}
 
@@ -232,8 +226,8 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
 
 	/* Noisy system timing? */
 	if (i == DRM_TIMESTAMP_MAXRETRIES) {
-		DRM_DEBUG("crtc %u: Noisy timestamp %d us > %d us [%d reps].\n",
-			  pipe, duration_ns/1000, *max_error/1000, i);
+		DRM_DEBUG("crtc %x: Noisy timestamp %d us > %d us [%d reps].\n",
+			  crtc->base.id, duration_ns/1000, *max_error/1000, i);
 	}
 
 	/* Return upper bound of timestamp precision error. */
@@ -266,8 +260,8 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
 		etime = ktime_sub_ns(etime, delta_ns);
 	*vblank_time = ktime_to_timeval(etime);
 
-	DRM_DEBUG("crtc %u : v %d p(%d,%d)@ %ld.%ld -> %ld.%ld [e %d us, %d rep]\n",
-		  pipe, (int)vbl_status, hpos, vpos,
+	DRM_DEBUG("crtc %x: v %d p(%d,%d)@ %ld.%ld -> %ld.%ld [e %d us, %d rep]\n",
+		  crtc->base.id, (int)vbl_status, hpos, vpos,
 		  (long)tv_etime.tv_sec, (long)tv_etime.tv_usec,
 		  (long)vblank_time->tv_sec, (long)vblank_time->tv_usec,
 		  duration_ns/1000, i);
drivers/gpu/drm/i915/i915_irq.c +7 -8
index 996c2931c499..bc6dc51abe95 100644
@@ -662,14 +662,15 @@ static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
 	return (position + crtc->scanline_offset) % vtotal;
 }
 
-static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
-				    unsigned int flags, int *vpos, int *hpos,
-				    ktime_t *stime, ktime_t *etime)
+int i915_get_crtc_scanoutpos(struct drm_crtc *crtc, unsigned int flags,
+			     int *vpos, int *hpos, ktime_t *stime,
+			     ktime_t *etime)
 {
+	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
+	enum pipe pipe = intel_crtc->pipe;
 	int position;
 	int vbl_start, vbl_end, hsync_start, htotal, vtotal;
 	bool in_vbl = true;
@@ -824,7 +825,7 @@ static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
 	}
 
 	/* Helper routine in DRM core does all the work: */
-	return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
+	return drm_calc_vbltimestamp_from_scanoutpos(crtc, max_error,
 						     vblank_time, flags,
 						     crtc,
 						     &to_intel_crtc(crtc)->config.adjusted_mode);
@@ -4360,10 +4361,8 @@ void intel_irq_init(struct drm_i915_private *dev_priv)
 	if (!IS_GEN2(dev_priv))
 		dev->vblank_disable_immediate = true;
 
-	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
+	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;
-	}
 
 	if (IS_CHERRYVIEW(dev_priv)) {
 		dev->driver->irq_handler = cherryview_irq_handler;
drivers/gpu/drm/i915/intel_display.c +1 -0
index 518815df51bd..e4e1119e6031 100644
@@ -11660,6 +11660,7 @@ static const struct drm_crtc_funcs intel_crtc_funcs = {
 	.set_config = intel_crtc_set_config,
 	.destroy = intel_crtc_destroy,
 	.page_flip = intel_crtc_page_flip,
+	.get_scanout_position = i915_get_crtc_scanoutpos,
 };
 
 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
drivers/gpu/drm/i915/intel_drv.h +3 -0
index 25fdbb16d4e0..4217faeb75e0 100644
@@ -805,6 +805,9 @@ static inline bool intel_irqs_enabled(struct drm_i915_private *dev_priv)
 	return dev_priv->pm.irqs_enabled;
 }
 
+int i915_get_crtc_scanoutpos(struct drm_crtc *crtc, unsigned int flags,
+			     int *vpos, int *hpos, ktime_t *stime,
+			     ktime_t *etime);
 int intel_get_crtc_scanline(struct intel_crtc *crtc);
 void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv);
 
drivers/gpu/drm/nouveau/dispnv04/crtc.c +1 -0
index 38402ade6835..9071ff9580d1 100644
@@ -1089,6 +1089,7 @@ static const struct drm_crtc_funcs nv04_crtc_funcs = {
 	.set_config = nouveau_crtc_set_config,
 	.page_flip = nouveau_crtc_page_flip,
 	.destroy = nv_crtc_destroy,
+	.get_scanout_position = nouveau_display_scanoutpos,
 };
 
 static const struct drm_crtc_helper_funcs nv04_crtc_helper_funcs = {
drivers/gpu/drm/nouveau/nouveau_display.c +5 -20
index 5d93902a91ab..da040508fdb2 100644
@@ -92,8 +92,9 @@ calc(int blanks, int blanke, int total, int line)
 }
 
 int
-nouveau_display_scanoutpos_head(struct drm_crtc *crtc, int *vpos, int *hpos,
-				ktime_t *stime, ktime_t *etime)
+nouveau_display_scanoutpos(struct drm_crtc *crtc, unsigned int flags,
+			   int *vpos, int *hpos, ktime_t *stime,
+			   ktime_t *etime)
 {
 	struct {
 		struct nv04_disp_mthd_v0 base;
@@ -131,22 +132,6 @@ nouveau_display_scanoutpos_head(struct drm_crtc *crtc, int *vpos, int *hpos,
 }
 
 int
-nouveau_display_scanoutpos(struct drm_device *dev, int head, unsigned int flags,
-			   int *vpos, int *hpos, ktime_t *stime, ktime_t *etime)
-{
-	struct drm_crtc *crtc;
-
-	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
-		if (nouveau_crtc(crtc)->index == head) {
-			return nouveau_display_scanoutpos_head(crtc, vpos, hpos,
-							       stime, etime);
-		}
-	}
-
-	return 0;
-}
-
-int
 nouveau_display_vblstamp(struct drm_device *dev, int head, int *max_error,
 			 struct timeval *time, unsigned flags)
 {
@@ -154,8 +139,8 @@ nouveau_display_vblstamp(struct drm_device *dev, int head, int *max_error,
 
 	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
 		if (nouveau_crtc(crtc)->index == head) {
-			return drm_calc_vbltimestamp_from_scanoutpos(dev,
-					head, max_error, time, flags, crtc,
+			return drm_calc_vbltimestamp_from_scanoutpos(crtc,
+					max_error, time, flags, crtc,
 					&crtc->hwmode);
 		}
 	}
drivers/gpu/drm/nouveau/nouveau_display.h +2 -2
index be3d5947c6be..e427034f0265 100644
@@ -67,8 +67,8 @@ int  nouveau_display_suspend(struct drm_device *dev, bool runtime);
 void nouveau_display_resume(struct drm_device *dev, bool runtime);
 int  nouveau_display_vblank_enable(struct drm_device *, int);
 void nouveau_display_vblank_disable(struct drm_device *, int);
-int  nouveau_display_scanoutpos(struct drm_device *, int, unsigned int,
-				int *, int *, ktime_t *, ktime_t *);
+int  nouveau_display_scanoutpos(struct drm_crtc *, unsigned int, int *, int *,
+				ktime_t *, ktime_t *);
 int  nouveau_display_vblstamp(struct drm_device *, int, int *,
 			      struct timeval *, unsigned);
 
drivers/gpu/drm/nouveau/nouveau_drm.c +0 -1
index 22d49438b136..b69c47a63bd9 100644
@@ -958,7 +958,6 @@ driver_stub = {
 	.get_vblank_counter = drm_vblank_count,
 	.enable_vblank = nouveau_display_vblank_enable,
 	.disable_vblank = nouveau_display_vblank_disable,
-	.get_scanout_position = nouveau_display_scanoutpos,
 	.get_vblank_timestamp = nouveau_display_vblstamp,
 
 	.ioctls = nouveau_ioctls,
drivers/gpu/drm/nouveau/nv50_display.c +1 -0
index 490b90866baf..18acbeea16bb 100644
@@ -1386,6 +1386,7 @@ static const struct drm_crtc_funcs nv50_crtc_func = {
 	.set_config = nouveau_crtc_set_config,
 	.destroy = nv50_crtc_destroy,
 	.page_flip = nouveau_crtc_page_flip,
+	.get_scanout_position = nouveau_display_scanoutpos,
 };
 
 static int
drivers/gpu/drm/radeon/radeon_display.c +20 -19
index 102116902a07..2d0f9be23112 100644
@@ -322,9 +322,9 @@ void radeon_crtc_handle_vblank(struct radeon_device *rdev, int crtc_id)
 	 * to complete in this vblank?
 	 */
 	if (update_pending &&
-	    (DRM_SCANOUTPOS_VALID & radeon_get_crtc_scanoutpos(rdev->ddev, crtc_id, 0,
+	    (DRM_SCANOUTPOS_VALID & radeon_crtc_get_scanoutpos(&radeon_crtc->base, 0,
 							       &vpos, &hpos, NULL, NULL)) &&
-	    ((vpos >= (99 * rdev->mode_info.crtcs[crtc_id]->base.hwmode.crtc_vdisplay)/100) ||
+	    ((vpos >= (99 * radeon_crtc->base.hwmode.crtc_vdisplay)/100) ||
 	     (vpos < 0 && !ASIC_IS_AVIVO(rdev)))) {
 		/* crtc didn't flip in this target vblank interval,
 		 * but flip is pending in crtc. Based on the current
@@ -641,6 +641,7 @@ static const struct drm_crtc_funcs radeon_crtc_funcs = {
 	.set_config = radeon_crtc_set_config,
 	.destroy = radeon_crtc_destroy,
 	.page_flip = radeon_crtc_page_flip,
+	.get_scanout_position = radeon_crtc_get_scanoutpos,
 };
 
 static void radeon_crtc_init(struct drm_device *dev, int index)
@@ -1758,7 +1759,6 @@ bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc,
  * Retrieve current video scanout position of crtc on a given gpu, and
  * an optional accurate timestamp of when query happened.
  *
- * \param dev Device to query.
  * \param crtc Crtc to query.
  * \param flags Flags from caller (DRM_CALLED_FROM_VBLIRQ or 0).
  * \param *vpos Location where vertical scanout position should be stored.
@@ -1782,14 +1782,15 @@ bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc,
  * unknown small number of scanlines wrt. real scanout position.
  *
  */
-int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc, unsigned int flags,
+int radeon_crtc_get_scanoutpos(struct drm_crtc *crtc, unsigned int flags,
 			       int *vpos, int *hpos, ktime_t *stime, ktime_t *etime)
 {
+	struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
 	u32 stat_crtc = 0, vbl = 0, position = 0;
 	int vbl_start, vbl_end, vtotal, ret = 0;
 	bool in_vbl = true;
 
-	struct radeon_device *rdev = dev->dev_private;
+	struct radeon_device *rdev = crtc->dev->dev_private;
 
 	/* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
 
@@ -1798,42 +1799,42 @@ int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc, unsigned int fl
 		*stime = ktime_get();
 
 	if (ASIC_IS_DCE4(rdev)) {
-		if (crtc == 0) {
+		if (radeon_crtc->crtc_id == 0) {
 			vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END +
 				     EVERGREEN_CRTC0_REGISTER_OFFSET);
 			position = RREG32(EVERGREEN_CRTC_STATUS_POSITION +
 					  EVERGREEN_CRTC0_REGISTER_OFFSET);
 			ret |= DRM_SCANOUTPOS_VALID;
 		}
-		if (crtc == 1) {
+		if (radeon_crtc->crtc_id == 1) {
 			vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END +
 				     EVERGREEN_CRTC1_REGISTER_OFFSET);
 			position = RREG32(EVERGREEN_CRTC_STATUS_POSITION +
 					  EVERGREEN_CRTC1_REGISTER_OFFSET);
 			ret |= DRM_SCANOUTPOS_VALID;
 		}
-		if (crtc == 2) {
+		if (radeon_crtc->crtc_id == 2) {
 			vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END +
 				     EVERGREEN_CRTC2_REGISTER_OFFSET);
 			position = RREG32(EVERGREEN_CRTC_STATUS_POSITION +
 					  EVERGREEN_CRTC2_REGISTER_OFFSET);
 			ret |= DRM_SCANOUTPOS_VALID;
 		}
-		if (crtc == 3) {
+		if (radeon_crtc->crtc_id == 3) {
 			vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END +
 				     EVERGREEN_CRTC3_REGISTER_OFFSET);
 			position = RREG32(EVERGREEN_CRTC_STATUS_POSITION +
 					  EVERGREEN_CRTC3_REGISTER_OFFSET);
 			ret |= DRM_SCANOUTPOS_VALID;
 		}
-		if (crtc == 4) {
+		if (radeon_crtc->crtc_id == 4) {
 			vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END +
 				     EVERGREEN_CRTC4_REGISTER_OFFSET);
 			position = RREG32(EVERGREEN_CRTC_STATUS_POSITION +
 					  EVERGREEN_CRTC4_REGISTER_OFFSET);
 			ret |= DRM_SCANOUTPOS_VALID;
 		}
-		if (crtc == 5) {
+		if (radeon_crtc->crtc_id == 5) {
 			vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END +
 				     EVERGREEN_CRTC5_REGISTER_OFFSET);
 			position = RREG32(EVERGREEN_CRTC_STATUS_POSITION +
@@ -1841,19 +1842,19 @@ int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc, unsigned int fl
 			ret |= DRM_SCANOUTPOS_VALID;
 		}
 	} else if (ASIC_IS_AVIVO(rdev)) {
-		if (crtc == 0) {
+		if (radeon_crtc->crtc_id == 0) {
 			vbl = RREG32(AVIVO_D1CRTC_V_BLANK_START_END);
 			position = RREG32(AVIVO_D1CRTC_STATUS_POSITION);
 			ret |= DRM_SCANOUTPOS_VALID;
 		}
-		if (crtc == 1) {
+		if (radeon_crtc->crtc_id == 1) {
 			vbl = RREG32(AVIVO_D2CRTC_V_BLANK_START_END);
 			position = RREG32(AVIVO_D2CRTC_STATUS_POSITION);
 			ret |= DRM_SCANOUTPOS_VALID;
 		}
 	} else {
 		/* Pre-AVIVO: Different encoding of scanout pos and vblank interval. */
-		if (crtc == 0) {
+		if (radeon_crtc->crtc_id == 0) {
 			/* Assume vbl_end == 0, get vbl_start from
 			 * upper 16 bits.
 			 */
@@ -1867,7 +1868,7 @@ int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc, unsigned int fl
 
 			ret |= DRM_SCANOUTPOS_VALID;
 		}
-		if (crtc == 1) {
+		if (radeon_crtc->crtc_id == 1) {
 			vbl = (RREG32(RADEON_CRTC2_V_TOTAL_DISP) &
 				RADEON_CRTC_V_DISP) >> RADEON_CRTC_V_DISP_SHIFT;
 			position = (RREG32(RADEON_CRTC2_VLINE_CRNT_VLINE) >> 16) & RADEON_CRTC_V_TOTAL;
@@ -1898,7 +1899,7 @@ int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc, unsigned int fl
 	}
 	else {
 		/* No: Fake something reasonable which gives at least ok results. */
-		vbl_start = rdev->mode_info.crtcs[crtc]->base.hwmode.crtc_vdisplay;
+		vbl_start = crtc->hwmode.crtc_vdisplay;
 		vbl_end = 0;
 	}
 
@@ -1914,7 +1915,7 @@ int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc, unsigned int fl
 
 	/* Inside "upper part" of vblank area? Apply corrective offset if so: */
 	if (in_vbl && (*vpos >= vbl_start)) {
-		vtotal = rdev->mode_info.crtcs[crtc]->base.hwmode.crtc_vtotal;
+		vtotal = crtc->hwmode.crtc_vtotal;
 		*vpos = *vpos - vtotal;
 	}
 
@@ -1936,8 +1937,8 @@ int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc, unsigned int fl
 	 * We only do this if DRM_CALLED_FROM_VBLIRQ.
 	 */
 	if ((flags & DRM_CALLED_FROM_VBLIRQ) && !in_vbl) {
-		vbl_start = rdev->mode_info.crtcs[crtc]->base.hwmode.crtc_vdisplay;
-		vtotal = rdev->mode_info.crtcs[crtc]->base.hwmode.crtc_vtotal;
+		vbl_start = crtc->hwmode.crtc_vdisplay;
+		vtotal = crtc->hwmode.crtc_vtotal;
 
 		if (vbl_start - *vpos < vtotal / 100) {
 			*vpos -= vtotal;
drivers/gpu/drm/radeon/radeon_drv.c +0 -1
index 4f50fb0e3d93..d1b0250dde48 100644
@@ -567,7 +567,6 @@ static struct drm_driver kms_driver = {
 	.enable_vblank = radeon_enable_vblank_kms,
 	.disable_vblank = radeon_disable_vblank_kms,
 	.get_vblank_timestamp = radeon_get_vblank_timestamp_kms,
-	.get_scanout_position = radeon_get_crtc_scanoutpos,
 #if defined(CONFIG_DEBUG_FS)
 	.debugfs_init = radeon_debugfs_init,
 	.debugfs_cleanup = radeon_debugfs_cleanup,
drivers/gpu/drm/radeon/radeon_kms.c +1 -1
index 3cf9c1fa6475..652f65b1080f 100644
@@ -804,7 +804,7 @@ int radeon_get_vblank_timestamp_kms(struct drm_device *dev, int crtc,
 		return -EINVAL;
 
 	/* Helper routine in DRM core does all the work: */
-	return drm_calc_vbltimestamp_from_scanoutpos(dev, crtc, max_error,
+	return drm_calc_vbltimestamp_from_scanoutpos(drmcrtc, max_error,
 						     vblank_time, flags,
 						     drmcrtc, &drmcrtc->hwmode);
 }
drivers/gpu/drm/radeon/radeon_mode.h +1 -1
index 390db897f322..3c9fa1353261 100644
@@ -820,7 +820,7 @@ extern int radeon_crtc_cursor_move(struct drm_crtc *crtc,
 				   int x, int y);
 extern void radeon_cursor_reset(struct drm_crtc *crtc);
 
-extern int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc,
+extern int radeon_crtc_get_scanoutpos(struct drm_crtc *crtc,
 				      unsigned int flags,
 				      int *vpos, int *hpos, ktime_t *stime,
 				      ktime_t *etime);
drivers/gpu/drm/radeon/radeon_pm.c +3 -1
index 32522cc940a1..aa9843b09ac8 100644
@@ -1553,8 +1553,10 @@ static bool radeon_pm_in_vbl(struct radeon_device *rdev)
 	 * otherwise return in_vbl == false.
 	 */
 	for (crtc = 0; (crtc < rdev->num_crtc) && in_vbl; crtc++) {
+		struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc];
+
 		if (rdev->pm.active_crtcs & (1 << crtc)) {
-			vbl_status = radeon_get_crtc_scanoutpos(rdev->ddev, crtc, 0, &vpos, &hpos, NULL, NULL);
+			vbl_status = radeon_crtc_get_scanoutpos(&radeon_crtc->base, 0, &vpos, &hpos, NULL, NULL);
 			if ((vbl_status & DRM_SCANOUTPOS_VALID) &&
 			    !(vbl_status & DRM_SCANOUTPOS_IN_VBLANK))
 				in_vbl = false;
include/drm/drmP.h +0 -47

65 lines not on this page · raw message

include/drm/drm_crtc.h +45 -0

69 lines not on this page · raw message

Signature · 6 lines
2.1.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 77 lines · Thierry Reding

From: Thierry Reding <[email protected]>

None of the drivers use this in legacy mode, so it can be converted to use struct drm_crtc * directly. While at it, also make the sole user of the callback, drm_calc_vbltimestamp_from_scanoutpos(), pass through the CRTC directly.

Cc Daniel Vetter <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Ben Skeggs <[email protected]>
Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>

---
Note: This is compile-tested only. It is a straightforward conversion so I wouldn't expect any fallout, but it'd certainly be best if this can be tested on all three drivers.

 drivers/gpu/drm/drm_irq.c                 | 34 +++++++++-------------
 drivers/gpu/drm/i915/i915_irq.c           | 15 +++++-----
 drivers/gpu/drm/i915/intel_display.c      |  1 +
 drivers/gpu/drm/i915/intel_drv.h          |  3 ++
 drivers/gpu/drm/nouveau/dispnv04/crtc.c   |  1 +
 drivers/gpu/drm/nouveau/nouveau_display.c | 25 ++++------------
 drivers/gpu/drm/nouveau/nouveau_display.h |  4 +--
 drivers/gpu/drm/nouveau/nouveau_drm.c     |  1 -
 drivers/gpu/drm/nouveau/nv50_display.c    |  1 +
 drivers/gpu/drm/radeon/radeon_display.c   | 39 ++++++++++++-------------
 drivers/gpu/drm/radeon/radeon_drv.c       |  1 -
 drivers/gpu/drm/radeon/radeon_kms.c       |  2 +-
 drivers/gpu/drm/radeon/radeon_mode.h      |  2 +-
 drivers/gpu/drm/radeon/radeon_pm.c        |  4 ++-
 include/drm/drmP.h                        | 47 -------------------------------
 include/drm/drm_crtc.h                    | 45 +++++++++++++++++++++++++++++
 16 files changed, 104 insertions(+), 121 deletions(-)
drivers/gpu/drm/drm_irq.c +4 -11
index 37b536c57cd2..18f1ccad7ee0 100644
@@ -161,14 +161,14 @@ EXPORT_SYMBOL(drm_calc_timestamping_constants);
  * DRM_VBLANKTIME_INVBL - Timestamp taken while scanout was in vblank interval.
  *
  */
-int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
-					  unsigned int pipe,
+int drm_calc_vbltimestamp_from_scanoutpos(struct drm_crtc *crtc,
 					  int *max_error,
 					  struct timeval *vblank_time,
 					  unsigned flags,
 					  const struct drm_crtc *refcrtc,
 					  const struct drm_display_mode *mode)
 {
+	const struct drm_crtc_funcs *funcs = crtc->funcs;
 	struct timeval tv_etime;
 	ktime_t stime, etime;
 	int vbl_status;
@@ -176,16 +176,9 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
 	int framedur_ns, linedur_ns, pixeldur_ns, delta_ns, duration_ns;
 	bool invbl;
 
-	if (pipe >= dev->num_crtcs) {
-		DRM_ERROR("Invalid crtc %u\n", pipe);
-		return -EINVAL;
-	}
-
 	/* Scanout position query not supported? Should not happen. */
-	if (!dev->driver->get_scanout_position) {
-		DRM_ERROR("Called from driver w/o get_scanout_position()!?\n");
-		return -EIO;
-	}
+	if (WARN_ON(funcs->get_scanout_position == NULL))
+		return -ENOSYS;
 
 	/* Durations of frames, lines, pixels in nanoseconds. */
 	framedur_ns = refcrtc->framedur_ns;

drivers/gpu/drm/drm_irq.c int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, · line 193

Quoted 6 lines
drivers/gpu/drm/drm_irq.c +2 -1
@@ -196,7 +189,8 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
 	 * Happens during initial modesetting of a crtc.
 	 */
 	if (framedur_ns == 0) {
-		DRM_DEBUG("crtc %u: Noop due to uninitialized mode.\n", pipe);
+		DRM_DEBUG("crtc %x: Noop due to uninitialized mode.\n",
+			  crtc->base.id);

I don't think we want the obj ID in hex.

And I must say I hate looking at obj IDs. You basically need to build some kind of obj ID to hw crtc cross reference every time you try to read a log. So keeping to drm_crtc_index() would better IMO. Or maybe even add crtc->name so each driver could provide its own name for the thing, but that would be a slightly bigger task.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx