All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: airlied@linux.ie, daniel@ffwll.ch, alexander.deucher@amd.com,
	christian.koenig@amd.com, David1.Zhou@amd.com,
	maarten.lankhorst@linux.intel.com, patrik.r.jakobsson@gmail.com,
	robdclark@gmail.com, sean@poorly.run,
	benjamin.gaignard@linaro.org, vincent.abriou@st.com,
	yannick.fertre@st.com, philippe.cornu@st.com,
	mcoquelin.stm32@gmail.com, alexandre.torgue@st.com,
	eric@anholt.net, rodrigosiqueiramelo@gmail.com,
	hamohammed.sa@gmail.com, linux-graphics-maintainer@vmware.com,
	thellstrom@vmware.com, bskeggs@redhat.com,
	harry.wentland@amd.com, sunpeng.li@amd.com,
	jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com,
	rodrigo.vivi@intel.com
Cc: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org, linux-arm-msm@vger.kernel.org,
	freedreno@lists.freedesktop.org, nouveau@lists.freedesktop.org,
	Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 11/23] drm: Add get_vblank_timestamp() to struct drm_crtc_funcs
Date: Fri, 10 Jan 2020 10:21:15 +0100	[thread overview]
Message-ID: <20200110092127.27847-12-tzimmermann@suse.de> (raw)
In-Reply-To: <20200110092127.27847-1-tzimmermann@suse.de>

The callback get_vblank_timestamp() is currently located in struct
drm_driver, but really belongs into struct drm_crtc_funcs. Add an
equivalent there. Driver will be converted in separate patches.

The default implementation is drm_calc_vbltimestamp_from_scanoutpos().
The patch adds drm_crtc_calc_vbltimestamp_from_scanoutpos(), which is
an implementation for the CRTC callback.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_vblank.c             | 83 +++++++++++++++++++++---
 include/drm/drm_crtc.h                   | 41 ++++++++++++
 include/drm/drm_modeset_helper_vtables.h |  2 +-
 include/drm/drm_vblank.h                 |  4 ++
 4 files changed, 120 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index cbe8f3009df5..7cf436a4b908 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -333,7 +333,9 @@ u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc)
 	u64 vblank;
 	unsigned long flags;
 
-	WARN_ONCE(drm_debug_enabled(DRM_UT_VBL) && !dev->driver->get_vblank_timestamp,
+	WARN_ONCE(drm_debug_enabled(DRM_UT_VBL) &&
+		  !crtc->funcs->get_vblank_timestamp &&
+		  !dev->driver->get_vblank_timestamp,
 		  "This function requires support for accurate vblank timestamps.");
 
 	spin_lock_irqsave(&dev->vblank_time_lock, flags);
@@ -563,6 +565,50 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc,
 }
 EXPORT_SYMBOL(drm_calc_timestamping_constants);
 
+/**
+ * drm_crtc_calc_vbltimestamp_from_scanoutpos - precise vblank timestamp helper
+ * @crtc: CRTC whose vblank timestamp to retrieve
+ * @max_error: Desired maximum allowable error in timestamps (nanosecs)
+ *             On return contains true maximum error of timestamp
+ * @vblank_time: Pointer to time which should receive the timestamp
+ * @in_vblank_irq:
+ *     True when called from drm_crtc_handle_vblank().  Some drivers
+ *     need to apply some workarounds for gpu-specific vblank irq quirks
+ *     if flag is set.
+ *
+ * Implements calculation of exact vblank timestamps from given drm_display_mode
+ * timings and current video scanout position of a CRTC. This can be directly
+ * used as the &drm_crtc_funcs.get_vblank_timestamp implementation of a kms
+ * driver if &drm_crtc_helper_funcs.get_scanout_position is implemented.
+ *
+ * The current implementation only handles standard video modes. For double scan
+ * and interlaced modes the driver is supposed to adjust the hardware mode
+ * (taken from &drm_crtc_state.adjusted mode for atomic modeset drivers) to
+ * match the scanout position reported.
+ *
+ * Note that atomic drivers must call drm_calc_timestamping_constants() before
+ * enabling a CRTC. The atomic helpers already take care of that in
+ * drm_atomic_helper_update_legacy_modeset_state().
+ *
+ * Returns:
+ *
+ * Returns true on success, and false on failure, i.e. when no accurate
+ * timestamp could be acquired.
+ */
+bool drm_crtc_calc_vbltimestamp_from_scanoutpos(struct drm_crtc *crtc,
+						int *max_error,
+						ktime_t *vblank_time,
+						bool in_vblank_irq)
+{
+	struct drm_device *dev = crtc->dev;
+	unsigned int pipe = crtc->index;
+
+	return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
+						     vblank_time,
+						     in_vblank_irq);
+}
+EXPORT_SYMBOL(drm_crtc_calc_vbltimestamp_from_scanoutpos);
+
 /**
  * drm_calc_vbltimestamp_from_scanoutpos - precise vblank timestamp helper
  * @dev: DRM device
@@ -577,8 +623,8 @@ EXPORT_SYMBOL(drm_calc_timestamping_constants);
  *
  * Implements calculation of exact vblank timestamps from given drm_display_mode
  * timings and current video scanout position of a CRTC. This can be directly
- * used as the &drm_driver.get_vblank_timestamp implementation of a kms driver
- * if &drm_crtc_helper_funcs.get_scanout_position is implemented.
+ * used as the &drm_crtc_funcs.get_vblank_timestamp implementation of a kms
+ * driver if &drm_crtc_helper_funcs.get_scanout_position is implemented.
  *
  * The current implementation only handles standard video modes. For double scan
  * and interlaced modes the driver is supposed to adjust the hardware mode
@@ -733,15 +779,22 @@ static bool
 drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe,
 			  ktime_t *tvblank, bool in_vblank_irq)
 {
+	struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
 	bool ret = false;
 
 	/* Define requested maximum error on timestamps (nanoseconds). */
 	int max_error = (int) drm_timestamp_precision * 1000;
 
 	/* Query driver if possible and precision timestamping enabled. */
-	if (dev->driver->get_vblank_timestamp && (max_error > 0))
+	if (crtc->funcs->get_vblank_timestamp && (max_error > 0)) {
+		struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
+
+		ret = crtc->funcs->get_vblank_timestamp(crtc, &max_error,
+							tvblank, in_vblank_irq);
+	} else if (dev->driver->get_vblank_timestamp && (max_error > 0)) {
 		ret = dev->driver->get_vblank_timestamp(dev, pipe, &max_error,
 							tvblank, in_vblank_irq);
+	}
 
 	/* GPU high precision timestamp query unsupported or failed.
 	 * Return current monotonic/gettimeofday timestamp as best estimate.
@@ -1050,11 +1103,19 @@ EXPORT_SYMBOL(drm_crtc_vblank_get);
 
 static bool __vblank_disable_immediate(struct drm_device *dev, unsigned int pipe)
 {
+	struct drm_crtc *crtc;
+
 	if (!dev->vblank_disable_immediate)
 		return false;
-	if (!dev->driver->get_vblank_timestamp)
-		return false;
-	return true;
+
+	crtc = drm_crtc_from_index(dev, pipe);
+	if (crtc && crtc->funcs->get_vblank_timestamp)
+		return true;
+
+	if (dev->driver->get_vblank_timestamp)
+		return true;
+
+	return false;
 }
 
 static void drm_vblank_put(struct drm_device *dev, unsigned int pipe)
@@ -1733,9 +1794,11 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
 
 static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe)
 {
+	struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
 	struct drm_pending_vblank_event *e, *t;
 	ktime_t now;
 	u64 seq;
+	bool high_prec;
 
 	assert_spin_locked(&dev->event_lock);
 
@@ -1755,8 +1818,10 @@ static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe)
 		send_vblank_event(dev, e, seq, now);
 	}
 
-	trace_drm_vblank_event(pipe, seq, now,
-			dev->driver->get_vblank_timestamp != NULL);
+	high_prec = crtc->funcs->get_vblank_timestamp ||
+		    dev->driver->get_vblank_timestamp;
+
+	trace_drm_vblank_event(pipe, seq, now, high_prec);
 }
 
 /**
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 5e9b15a0e8c5..2caad975f415 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -867,6 +867,47 @@ struct drm_crtc_funcs {
 	 * new drivers as the replacement of &drm_driver.disable_vblank hook.
 	 */
 	void (*disable_vblank)(struct drm_crtc *crtc);
+
+	/**
+	 * @get_vblank_timestamp:
+	 *
+	 * Called by drm_get_last_vbltimestamp(). Should return a precise
+	 * timestamp when the most recent vblank interval ended or will end.
+	 *
+	 * Specifically, the timestamp in @vblank_time should correspond as
+	 * closely as possible to the time when the first video scanline of
+	 * the video frame after the end of vblank will start scanning out,
+	 * the time immediately after end of the vblank interval. If the
+	 * @crtc is currently inside vblank, this will be a time in the future.
+	 * If the @crtc is currently scanning out a frame, this will be the
+	 * past start time of the current scanout. This is meant to adhere
+	 * to the OpenML OML_sync_control extension specification.
+	 *
+	 * Parameters:
+	 *
+	 * crtc:
+	 *     CRTC for which timestamp should be returned.
+	 * max_error:
+	 *     Maximum allowable timestamp error in nanoseconds.
+	 *     Implementation should strive to provide timestamp
+	 *     with an error of at most max_error nanoseconds.
+	 *     Returns true upper bound on error for timestamp.
+	 * vblank_time:
+	 *     Target location for returned vblank timestamp.
+	 * in_vblank_irq:
+	 *     True when called from drm_crtc_handle_vblank().  Some drivers
+	 *     need to apply some workarounds for gpu-specific vblank irq quirks
+	 *     if flag is set.
+	 *
+	 * Returns:
+	 *
+	 * True on success, false on failure, which means the core should
+	 * fallback to a simple timestamp taken in drm_crtc_handle_vblank().
+	 */
+	bool (*get_vblank_timestamp)(struct drm_crtc *crtc,
+				     int *max_error,
+				     ktime_t *vblank_time,
+				     bool in_vblank_irq);
 };
 
 /**
diff --git a/include/drm/drm_modeset_helper_vtables.h b/include/drm/drm_modeset_helper_vtables.h
index e398512bfd5f..d735f7088a10 100644
--- a/include/drm/drm_modeset_helper_vtables.h
+++ b/include/drm/drm_modeset_helper_vtables.h
@@ -460,7 +460,7 @@ struct drm_crtc_helper_funcs {
 	 * optional accurate ktime_get() timestamp of when the position was
 	 * measured. Note that this is a helper callback which is only used
 	 * if a driver uses drm_calc_vbltimestamp_from_scanoutpos() for the
-	 * @drm_driver.get_vblank_timestamp callback.
+	 * @drm_crtc_funcs.get_vblank_timestamp callback.
 	 *
 	 * Parameters:
 	 *
diff --git a/include/drm/drm_vblank.h b/include/drm/drm_vblank.h
index c16c44052b3d..cdc567c83805 100644
--- a/include/drm/drm_vblank.h
+++ b/include/drm/drm_vblank.h
@@ -233,6 +233,10 @@ bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
 					   unsigned int pipe, int *max_error,
 					   ktime_t *vblank_time,
 					   bool in_vblank_irq);
+bool drm_crtc_calc_vbltimestamp_from_scanoutpos(struct drm_crtc *crtc,
+						int *max_error,
+						ktime_t *vblank_time,
+						bool in_vblank_irq);
 void drm_calc_timestamping_constants(struct drm_crtc *crtc,
 				     const struct drm_display_mode *mode);
 wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc);
-- 
2.24.1


WARNING: multiple messages have this Message-ID (diff)
From: Thomas Zimmermann <tzimmermann@suse.de>
To: airlied@linux.ie, daniel@ffwll.ch, alexander.deucher@amd.com,
	christian.koenig@amd.com, David1.Zhou@amd.com,
	maarten.lankhorst@linux.intel.com, patrik.r.jakobsson@gmail.com,
	robdclark@gmail.com, sean@poorly.run,
	benjamin.gaignard@linaro.org, vincent.abriou@st.com,
	yannick.fertre@st.com, philippe.cornu@st.com,
	mcoquelin.stm32@gmail.com, alexandre.torgue@st.com,
	eric@anholt.net, rodrigosiqueiramelo@gmail.com,
	hamohammed.sa@gmail.com, linux-graphics-maintainer@vmware.com,
	thellstrom@vmware.com, bskeggs@redhat.com,
	harry.wentland@amd.com, sunpeng.li@amd.com,
	jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com,
	rodrigo.vivi@intel.com
Cc: linux-arm-msm@vger.kernel.org, intel-gfx@lists.freedesktop.org,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	Thomas Zimmermann <tzimmermann@suse.de>,
	nouveau@lists.freedesktop.org, freedreno@lists.freedesktop.org
Subject: [PATCH 11/23] drm: Add get_vblank_timestamp() to struct drm_crtc_funcs
Date: Fri, 10 Jan 2020 10:21:15 +0100	[thread overview]
Message-ID: <20200110092127.27847-12-tzimmermann@suse.de> (raw)
In-Reply-To: <20200110092127.27847-1-tzimmermann@suse.de>

The callback get_vblank_timestamp() is currently located in struct
drm_driver, but really belongs into struct drm_crtc_funcs. Add an
equivalent there. Driver will be converted in separate patches.

The default implementation is drm_calc_vbltimestamp_from_scanoutpos().
The patch adds drm_crtc_calc_vbltimestamp_from_scanoutpos(), which is
an implementation for the CRTC callback.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_vblank.c             | 83 +++++++++++++++++++++---
 include/drm/drm_crtc.h                   | 41 ++++++++++++
 include/drm/drm_modeset_helper_vtables.h |  2 +-
 include/drm/drm_vblank.h                 |  4 ++
 4 files changed, 120 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index cbe8f3009df5..7cf436a4b908 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -333,7 +333,9 @@ u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc)
 	u64 vblank;
 	unsigned long flags;
 
-	WARN_ONCE(drm_debug_enabled(DRM_UT_VBL) && !dev->driver->get_vblank_timestamp,
+	WARN_ONCE(drm_debug_enabled(DRM_UT_VBL) &&
+		  !crtc->funcs->get_vblank_timestamp &&
+		  !dev->driver->get_vblank_timestamp,
 		  "This function requires support for accurate vblank timestamps.");
 
 	spin_lock_irqsave(&dev->vblank_time_lock, flags);
@@ -563,6 +565,50 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc,
 }
 EXPORT_SYMBOL(drm_calc_timestamping_constants);
 
+/**
+ * drm_crtc_calc_vbltimestamp_from_scanoutpos - precise vblank timestamp helper
+ * @crtc: CRTC whose vblank timestamp to retrieve
+ * @max_error: Desired maximum allowable error in timestamps (nanosecs)
+ *             On return contains true maximum error of timestamp
+ * @vblank_time: Pointer to time which should receive the timestamp
+ * @in_vblank_irq:
+ *     True when called from drm_crtc_handle_vblank().  Some drivers
+ *     need to apply some workarounds for gpu-specific vblank irq quirks
+ *     if flag is set.
+ *
+ * Implements calculation of exact vblank timestamps from given drm_display_mode
+ * timings and current video scanout position of a CRTC. This can be directly
+ * used as the &drm_crtc_funcs.get_vblank_timestamp implementation of a kms
+ * driver if &drm_crtc_helper_funcs.get_scanout_position is implemented.
+ *
+ * The current implementation only handles standard video modes. For double scan
+ * and interlaced modes the driver is supposed to adjust the hardware mode
+ * (taken from &drm_crtc_state.adjusted mode for atomic modeset drivers) to
+ * match the scanout position reported.
+ *
+ * Note that atomic drivers must call drm_calc_timestamping_constants() before
+ * enabling a CRTC. The atomic helpers already take care of that in
+ * drm_atomic_helper_update_legacy_modeset_state().
+ *
+ * Returns:
+ *
+ * Returns true on success, and false on failure, i.e. when no accurate
+ * timestamp could be acquired.
+ */
+bool drm_crtc_calc_vbltimestamp_from_scanoutpos(struct drm_crtc *crtc,
+						int *max_error,
+						ktime_t *vblank_time,
+						bool in_vblank_irq)
+{
+	struct drm_device *dev = crtc->dev;
+	unsigned int pipe = crtc->index;
+
+	return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
+						     vblank_time,
+						     in_vblank_irq);
+}
+EXPORT_SYMBOL(drm_crtc_calc_vbltimestamp_from_scanoutpos);
+
 /**
  * drm_calc_vbltimestamp_from_scanoutpos - precise vblank timestamp helper
  * @dev: DRM device
@@ -577,8 +623,8 @@ EXPORT_SYMBOL(drm_calc_timestamping_constants);
  *
  * Implements calculation of exact vblank timestamps from given drm_display_mode
  * timings and current video scanout position of a CRTC. This can be directly
- * used as the &drm_driver.get_vblank_timestamp implementation of a kms driver
- * if &drm_crtc_helper_funcs.get_scanout_position is implemented.
+ * used as the &drm_crtc_funcs.get_vblank_timestamp implementation of a kms
+ * driver if &drm_crtc_helper_funcs.get_scanout_position is implemented.
  *
  * The current implementation only handles standard video modes. For double scan
  * and interlaced modes the driver is supposed to adjust the hardware mode
@@ -733,15 +779,22 @@ static bool
 drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe,
 			  ktime_t *tvblank, bool in_vblank_irq)
 {
+	struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
 	bool ret = false;
 
 	/* Define requested maximum error on timestamps (nanoseconds). */
 	int max_error = (int) drm_timestamp_precision * 1000;
 
 	/* Query driver if possible and precision timestamping enabled. */
-	if (dev->driver->get_vblank_timestamp && (max_error > 0))
+	if (crtc->funcs->get_vblank_timestamp && (max_error > 0)) {
+		struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
+
+		ret = crtc->funcs->get_vblank_timestamp(crtc, &max_error,
+							tvblank, in_vblank_irq);
+	} else if (dev->driver->get_vblank_timestamp && (max_error > 0)) {
 		ret = dev->driver->get_vblank_timestamp(dev, pipe, &max_error,
 							tvblank, in_vblank_irq);
+	}
 
 	/* GPU high precision timestamp query unsupported or failed.
 	 * Return current monotonic/gettimeofday timestamp as best estimate.
@@ -1050,11 +1103,19 @@ EXPORT_SYMBOL(drm_crtc_vblank_get);
 
 static bool __vblank_disable_immediate(struct drm_device *dev, unsigned int pipe)
 {
+	struct drm_crtc *crtc;
+
 	if (!dev->vblank_disable_immediate)
 		return false;
-	if (!dev->driver->get_vblank_timestamp)
-		return false;
-	return true;
+
+	crtc = drm_crtc_from_index(dev, pipe);
+	if (crtc && crtc->funcs->get_vblank_timestamp)
+		return true;
+
+	if (dev->driver->get_vblank_timestamp)
+		return true;
+
+	return false;
 }
 
 static void drm_vblank_put(struct drm_device *dev, unsigned int pipe)
@@ -1733,9 +1794,11 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
 
 static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe)
 {
+	struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
 	struct drm_pending_vblank_event *e, *t;
 	ktime_t now;
 	u64 seq;
+	bool high_prec;
 
 	assert_spin_locked(&dev->event_lock);
 
@@ -1755,8 +1818,10 @@ static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe)
 		send_vblank_event(dev, e, seq, now);
 	}
 
-	trace_drm_vblank_event(pipe, seq, now,
-			dev->driver->get_vblank_timestamp != NULL);
+	high_prec = crtc->funcs->get_vblank_timestamp ||
+		    dev->driver->get_vblank_timestamp;
+
+	trace_drm_vblank_event(pipe, seq, now, high_prec);
 }
 
 /**
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 5e9b15a0e8c5..2caad975f415 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -867,6 +867,47 @@ struct drm_crtc_funcs {
 	 * new drivers as the replacement of &drm_driver.disable_vblank hook.
 	 */
 	void (*disable_vblank)(struct drm_crtc *crtc);
+
+	/**
+	 * @get_vblank_timestamp:
+	 *
+	 * Called by drm_get_last_vbltimestamp(). Should return a precise
+	 * timestamp when the most recent vblank interval ended or will end.
+	 *
+	 * Specifically, the timestamp in @vblank_time should correspond as
+	 * closely as possible to the time when the first video scanline of
+	 * the video frame after the end of vblank will start scanning out,
+	 * the time immediately after end of the vblank interval. If the
+	 * @crtc is currently inside vblank, this will be a time in the future.
+	 * If the @crtc is currently scanning out a frame, this will be the
+	 * past start time of the current scanout. This is meant to adhere
+	 * to the OpenML OML_sync_control extension specification.
+	 *
+	 * Parameters:
+	 *
+	 * crtc:
+	 *     CRTC for which timestamp should be returned.
+	 * max_error:
+	 *     Maximum allowable timestamp error in nanoseconds.
+	 *     Implementation should strive to provide timestamp
+	 *     with an error of at most max_error nanoseconds.
+	 *     Returns true upper bound on error for timestamp.
+	 * vblank_time:
+	 *     Target location for returned vblank timestamp.
+	 * in_vblank_irq:
+	 *     True when called from drm_crtc_handle_vblank().  Some drivers
+	 *     need to apply some workarounds for gpu-specific vblank irq quirks
+	 *     if flag is set.
+	 *
+	 * Returns:
+	 *
+	 * True on success, false on failure, which means the core should
+	 * fallback to a simple timestamp taken in drm_crtc_handle_vblank().
+	 */
+	bool (*get_vblank_timestamp)(struct drm_crtc *crtc,
+				     int *max_error,
+				     ktime_t *vblank_time,
+				     bool in_vblank_irq);
 };
 
 /**
diff --git a/include/drm/drm_modeset_helper_vtables.h b/include/drm/drm_modeset_helper_vtables.h
index e398512bfd5f..d735f7088a10 100644
--- a/include/drm/drm_modeset_helper_vtables.h
+++ b/include/drm/drm_modeset_helper_vtables.h
@@ -460,7 +460,7 @@ struct drm_crtc_helper_funcs {
 	 * optional accurate ktime_get() timestamp of when the position was
 	 * measured. Note that this is a helper callback which is only used
 	 * if a driver uses drm_calc_vbltimestamp_from_scanoutpos() for the
-	 * @drm_driver.get_vblank_timestamp callback.
+	 * @drm_crtc_funcs.get_vblank_timestamp callback.
 	 *
 	 * Parameters:
 	 *
diff --git a/include/drm/drm_vblank.h b/include/drm/drm_vblank.h
index c16c44052b3d..cdc567c83805 100644
--- a/include/drm/drm_vblank.h
+++ b/include/drm/drm_vblank.h
@@ -233,6 +233,10 @@ bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
 					   unsigned int pipe, int *max_error,
 					   ktime_t *vblank_time,
 					   bool in_vblank_irq);
+bool drm_crtc_calc_vbltimestamp_from_scanoutpos(struct drm_crtc *crtc,
+						int *max_error,
+						ktime_t *vblank_time,
+						bool in_vblank_irq);
 void drm_calc_timestamping_constants(struct drm_crtc *crtc,
 				     const struct drm_display_mode *mode);
 wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc);
-- 
2.24.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: Thomas Zimmermann <tzimmermann@suse.de>
To: airlied@linux.ie, daniel@ffwll.ch, alexander.deucher@amd.com,
	christian.koenig@amd.com, David1.Zhou@amd.com,
	maarten.lankhorst@linux.intel.com, patrik.r.jakobsson@gmail.com,
	robdclark@gmail.com, sean@poorly.run,
	benjamin.gaignard@linaro.org, vincent.abriou@st.com,
	yannick.fertre@st.com, philippe.cornu@st.com,
	mcoquelin.stm32@gmail.com, alexandre.torgue@st.com,
	eric@anholt.net, rodrigosiqueiramelo@gmail.com,
	hamohammed.sa@gmail.com, linux-graphics-maintainer@vmware.com,
	thellstrom@vmware.com, bskeggs@redhat.com,
	harry.wentland@amd.com, sunpeng.li@amd.com,
	jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com,
	rodrigo.vivi@intel.com
Cc: linux-arm-msm@vger.kernel.org, intel-gfx@lists.freedesktop.org,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	Thomas Zimmermann <tzimmermann@suse.de>,
	nouveau@lists.freedesktop.org, freedreno@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH 11/23] drm: Add get_vblank_timestamp() to struct drm_crtc_funcs
Date: Fri, 10 Jan 2020 10:21:15 +0100	[thread overview]
Message-ID: <20200110092127.27847-12-tzimmermann@suse.de> (raw)
In-Reply-To: <20200110092127.27847-1-tzimmermann@suse.de>

The callback get_vblank_timestamp() is currently located in struct
drm_driver, but really belongs into struct drm_crtc_funcs. Add an
equivalent there. Driver will be converted in separate patches.

The default implementation is drm_calc_vbltimestamp_from_scanoutpos().
The patch adds drm_crtc_calc_vbltimestamp_from_scanoutpos(), which is
an implementation for the CRTC callback.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_vblank.c             | 83 +++++++++++++++++++++---
 include/drm/drm_crtc.h                   | 41 ++++++++++++
 include/drm/drm_modeset_helper_vtables.h |  2 +-
 include/drm/drm_vblank.h                 |  4 ++
 4 files changed, 120 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index cbe8f3009df5..7cf436a4b908 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -333,7 +333,9 @@ u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc)
 	u64 vblank;
 	unsigned long flags;
 
-	WARN_ONCE(drm_debug_enabled(DRM_UT_VBL) && !dev->driver->get_vblank_timestamp,
+	WARN_ONCE(drm_debug_enabled(DRM_UT_VBL) &&
+		  !crtc->funcs->get_vblank_timestamp &&
+		  !dev->driver->get_vblank_timestamp,
 		  "This function requires support for accurate vblank timestamps.");
 
 	spin_lock_irqsave(&dev->vblank_time_lock, flags);
@@ -563,6 +565,50 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc,
 }
 EXPORT_SYMBOL(drm_calc_timestamping_constants);
 
+/**
+ * drm_crtc_calc_vbltimestamp_from_scanoutpos - precise vblank timestamp helper
+ * @crtc: CRTC whose vblank timestamp to retrieve
+ * @max_error: Desired maximum allowable error in timestamps (nanosecs)
+ *             On return contains true maximum error of timestamp
+ * @vblank_time: Pointer to time which should receive the timestamp
+ * @in_vblank_irq:
+ *     True when called from drm_crtc_handle_vblank().  Some drivers
+ *     need to apply some workarounds for gpu-specific vblank irq quirks
+ *     if flag is set.
+ *
+ * Implements calculation of exact vblank timestamps from given drm_display_mode
+ * timings and current video scanout position of a CRTC. This can be directly
+ * used as the &drm_crtc_funcs.get_vblank_timestamp implementation of a kms
+ * driver if &drm_crtc_helper_funcs.get_scanout_position is implemented.
+ *
+ * The current implementation only handles standard video modes. For double scan
+ * and interlaced modes the driver is supposed to adjust the hardware mode
+ * (taken from &drm_crtc_state.adjusted mode for atomic modeset drivers) to
+ * match the scanout position reported.
+ *
+ * Note that atomic drivers must call drm_calc_timestamping_constants() before
+ * enabling a CRTC. The atomic helpers already take care of that in
+ * drm_atomic_helper_update_legacy_modeset_state().
+ *
+ * Returns:
+ *
+ * Returns true on success, and false on failure, i.e. when no accurate
+ * timestamp could be acquired.
+ */
+bool drm_crtc_calc_vbltimestamp_from_scanoutpos(struct drm_crtc *crtc,
+						int *max_error,
+						ktime_t *vblank_time,
+						bool in_vblank_irq)
+{
+	struct drm_device *dev = crtc->dev;
+	unsigned int pipe = crtc->index;
+
+	return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
+						     vblank_time,
+						     in_vblank_irq);
+}
+EXPORT_SYMBOL(drm_crtc_calc_vbltimestamp_from_scanoutpos);
+
 /**
  * drm_calc_vbltimestamp_from_scanoutpos - precise vblank timestamp helper
  * @dev: DRM device
@@ -577,8 +623,8 @@ EXPORT_SYMBOL(drm_calc_timestamping_constants);
  *
  * Implements calculation of exact vblank timestamps from given drm_display_mode
  * timings and current video scanout position of a CRTC. This can be directly
- * used as the &drm_driver.get_vblank_timestamp implementation of a kms driver
- * if &drm_crtc_helper_funcs.get_scanout_position is implemented.
+ * used as the &drm_crtc_funcs.get_vblank_timestamp implementation of a kms
+ * driver if &drm_crtc_helper_funcs.get_scanout_position is implemented.
  *
  * The current implementation only handles standard video modes. For double scan
  * and interlaced modes the driver is supposed to adjust the hardware mode
@@ -733,15 +779,22 @@ static bool
 drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe,
 			  ktime_t *tvblank, bool in_vblank_irq)
 {
+	struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
 	bool ret = false;
 
 	/* Define requested maximum error on timestamps (nanoseconds). */
 	int max_error = (int) drm_timestamp_precision * 1000;
 
 	/* Query driver if possible and precision timestamping enabled. */
-	if (dev->driver->get_vblank_timestamp && (max_error > 0))
+	if (crtc->funcs->get_vblank_timestamp && (max_error > 0)) {
+		struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
+
+		ret = crtc->funcs->get_vblank_timestamp(crtc, &max_error,
+							tvblank, in_vblank_irq);
+	} else if (dev->driver->get_vblank_timestamp && (max_error > 0)) {
 		ret = dev->driver->get_vblank_timestamp(dev, pipe, &max_error,
 							tvblank, in_vblank_irq);
+	}
 
 	/* GPU high precision timestamp query unsupported or failed.
 	 * Return current monotonic/gettimeofday timestamp as best estimate.
@@ -1050,11 +1103,19 @@ EXPORT_SYMBOL(drm_crtc_vblank_get);
 
 static bool __vblank_disable_immediate(struct drm_device *dev, unsigned int pipe)
 {
+	struct drm_crtc *crtc;
+
 	if (!dev->vblank_disable_immediate)
 		return false;
-	if (!dev->driver->get_vblank_timestamp)
-		return false;
-	return true;
+
+	crtc = drm_crtc_from_index(dev, pipe);
+	if (crtc && crtc->funcs->get_vblank_timestamp)
+		return true;
+
+	if (dev->driver->get_vblank_timestamp)
+		return true;
+
+	return false;
 }
 
 static void drm_vblank_put(struct drm_device *dev, unsigned int pipe)
@@ -1733,9 +1794,11 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
 
 static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe)
 {
+	struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
 	struct drm_pending_vblank_event *e, *t;
 	ktime_t now;
 	u64 seq;
+	bool high_prec;
 
 	assert_spin_locked(&dev->event_lock);
 
@@ -1755,8 +1818,10 @@ static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe)
 		send_vblank_event(dev, e, seq, now);
 	}
 
-	trace_drm_vblank_event(pipe, seq, now,
-			dev->driver->get_vblank_timestamp != NULL);
+	high_prec = crtc->funcs->get_vblank_timestamp ||
+		    dev->driver->get_vblank_timestamp;
+
+	trace_drm_vblank_event(pipe, seq, now, high_prec);
 }
 
 /**
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 5e9b15a0e8c5..2caad975f415 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -867,6 +867,47 @@ struct drm_crtc_funcs {
 	 * new drivers as the replacement of &drm_driver.disable_vblank hook.
 	 */
 	void (*disable_vblank)(struct drm_crtc *crtc);
+
+	/**
+	 * @get_vblank_timestamp:
+	 *
+	 * Called by drm_get_last_vbltimestamp(). Should return a precise
+	 * timestamp when the most recent vblank interval ended or will end.
+	 *
+	 * Specifically, the timestamp in @vblank_time should correspond as
+	 * closely as possible to the time when the first video scanline of
+	 * the video frame after the end of vblank will start scanning out,
+	 * the time immediately after end of the vblank interval. If the
+	 * @crtc is currently inside vblank, this will be a time in the future.
+	 * If the @crtc is currently scanning out a frame, this will be the
+	 * past start time of the current scanout. This is meant to adhere
+	 * to the OpenML OML_sync_control extension specification.
+	 *
+	 * Parameters:
+	 *
+	 * crtc:
+	 *     CRTC for which timestamp should be returned.
+	 * max_error:
+	 *     Maximum allowable timestamp error in nanoseconds.
+	 *     Implementation should strive to provide timestamp
+	 *     with an error of at most max_error nanoseconds.
+	 *     Returns true upper bound on error for timestamp.
+	 * vblank_time:
+	 *     Target location for returned vblank timestamp.
+	 * in_vblank_irq:
+	 *     True when called from drm_crtc_handle_vblank().  Some drivers
+	 *     need to apply some workarounds for gpu-specific vblank irq quirks
+	 *     if flag is set.
+	 *
+	 * Returns:
+	 *
+	 * True on success, false on failure, which means the core should
+	 * fallback to a simple timestamp taken in drm_crtc_handle_vblank().
+	 */
+	bool (*get_vblank_timestamp)(struct drm_crtc *crtc,
+				     int *max_error,
+				     ktime_t *vblank_time,
+				     bool in_vblank_irq);
 };
 
 /**
diff --git a/include/drm/drm_modeset_helper_vtables.h b/include/drm/drm_modeset_helper_vtables.h
index e398512bfd5f..d735f7088a10 100644
--- a/include/drm/drm_modeset_helper_vtables.h
+++ b/include/drm/drm_modeset_helper_vtables.h
@@ -460,7 +460,7 @@ struct drm_crtc_helper_funcs {
 	 * optional accurate ktime_get() timestamp of when the position was
 	 * measured. Note that this is a helper callback which is only used
 	 * if a driver uses drm_calc_vbltimestamp_from_scanoutpos() for the
-	 * @drm_driver.get_vblank_timestamp callback.
+	 * @drm_crtc_funcs.get_vblank_timestamp callback.
 	 *
 	 * Parameters:
 	 *
diff --git a/include/drm/drm_vblank.h b/include/drm/drm_vblank.h
index c16c44052b3d..cdc567c83805 100644
--- a/include/drm/drm_vblank.h
+++ b/include/drm/drm_vblank.h
@@ -233,6 +233,10 @@ bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
 					   unsigned int pipe, int *max_error,
 					   ktime_t *vblank_time,
 					   bool in_vblank_irq);
+bool drm_crtc_calc_vbltimestamp_from_scanoutpos(struct drm_crtc *crtc,
+						int *max_error,
+						ktime_t *vblank_time,
+						bool in_vblank_irq);
 void drm_calc_timestamping_constants(struct drm_crtc *crtc,
 				     const struct drm_display_mode *mode);
 wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc);
-- 
2.24.1

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

WARNING: multiple messages have this Message-ID (diff)
From: Thomas Zimmermann <tzimmermann@suse.de>
To: airlied@linux.ie, daniel@ffwll.ch, alexander.deucher@amd.com,
	christian.koenig@amd.com, David1.Zhou@amd.com,
	maarten.lankhorst@linux.intel.com, patrik.r.jakobsson@gmail.com,
	robdclark@gmail.com, sean@poorly.run,
	benjamin.gaignard@linaro.org, vincent.abriou@st.com,
	yannick.fertre@st.com, philippe.cornu@st.com,
	mcoquelin.stm32@gmail.com, alexandre.torgue@st.com,
	eric@anholt.net, rodrigosiqueiramelo@gmail.com,
	hamohammed.sa@gmail.com, linux-graphics-maintainer@vmware.com,
	thellstrom@vmware.com, bskeggs@redhat.com,
	harry.wentland@amd.com, sunpeng.li@amd.com,
	jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com,
	rodrigo.vivi@intel.com
Cc: linux-arm-msm@vger.kernel.org, intel-gfx@lists.freedesktop.org,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	Thomas Zimmermann <tzimmermann@suse.de>,
	nouveau@lists.freedesktop.org, freedreno@lists.freedesktop.org
Subject: [PATCH 11/23] drm: Add get_vblank_timestamp() to struct drm_crtc_funcs
Date: Fri, 10 Jan 2020 10:21:15 +0100	[thread overview]
Message-ID: <20200110092127.27847-12-tzimmermann@suse.de> (raw)
In-Reply-To: <20200110092127.27847-1-tzimmermann@suse.de>

The callback get_vblank_timestamp() is currently located in struct
drm_driver, but really belongs into struct drm_crtc_funcs. Add an
equivalent there. Driver will be converted in separate patches.

The default implementation is drm_calc_vbltimestamp_from_scanoutpos().
The patch adds drm_crtc_calc_vbltimestamp_from_scanoutpos(), which is
an implementation for the CRTC callback.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_vblank.c             | 83 +++++++++++++++++++++---
 include/drm/drm_crtc.h                   | 41 ++++++++++++
 include/drm/drm_modeset_helper_vtables.h |  2 +-
 include/drm/drm_vblank.h                 |  4 ++
 4 files changed, 120 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index cbe8f3009df5..7cf436a4b908 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -333,7 +333,9 @@ u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc)
 	u64 vblank;
 	unsigned long flags;
 
-	WARN_ONCE(drm_debug_enabled(DRM_UT_VBL) && !dev->driver->get_vblank_timestamp,
+	WARN_ONCE(drm_debug_enabled(DRM_UT_VBL) &&
+		  !crtc->funcs->get_vblank_timestamp &&
+		  !dev->driver->get_vblank_timestamp,
 		  "This function requires support for accurate vblank timestamps.");
 
 	spin_lock_irqsave(&dev->vblank_time_lock, flags);
@@ -563,6 +565,50 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc,
 }
 EXPORT_SYMBOL(drm_calc_timestamping_constants);
 
+/**
+ * drm_crtc_calc_vbltimestamp_from_scanoutpos - precise vblank timestamp helper
+ * @crtc: CRTC whose vblank timestamp to retrieve
+ * @max_error: Desired maximum allowable error in timestamps (nanosecs)
+ *             On return contains true maximum error of timestamp
+ * @vblank_time: Pointer to time which should receive the timestamp
+ * @in_vblank_irq:
+ *     True when called from drm_crtc_handle_vblank().  Some drivers
+ *     need to apply some workarounds for gpu-specific vblank irq quirks
+ *     if flag is set.
+ *
+ * Implements calculation of exact vblank timestamps from given drm_display_mode
+ * timings and current video scanout position of a CRTC. This can be directly
+ * used as the &drm_crtc_funcs.get_vblank_timestamp implementation of a kms
+ * driver if &drm_crtc_helper_funcs.get_scanout_position is implemented.
+ *
+ * The current implementation only handles standard video modes. For double scan
+ * and interlaced modes the driver is supposed to adjust the hardware mode
+ * (taken from &drm_crtc_state.adjusted mode for atomic modeset drivers) to
+ * match the scanout position reported.
+ *
+ * Note that atomic drivers must call drm_calc_timestamping_constants() before
+ * enabling a CRTC. The atomic helpers already take care of that in
+ * drm_atomic_helper_update_legacy_modeset_state().
+ *
+ * Returns:
+ *
+ * Returns true on success, and false on failure, i.e. when no accurate
+ * timestamp could be acquired.
+ */
+bool drm_crtc_calc_vbltimestamp_from_scanoutpos(struct drm_crtc *crtc,
+						int *max_error,
+						ktime_t *vblank_time,
+						bool in_vblank_irq)
+{
+	struct drm_device *dev = crtc->dev;
+	unsigned int pipe = crtc->index;
+
+	return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
+						     vblank_time,
+						     in_vblank_irq);
+}
+EXPORT_SYMBOL(drm_crtc_calc_vbltimestamp_from_scanoutpos);
+
 /**
  * drm_calc_vbltimestamp_from_scanoutpos - precise vblank timestamp helper
  * @dev: DRM device
@@ -577,8 +623,8 @@ EXPORT_SYMBOL(drm_calc_timestamping_constants);
  *
  * Implements calculation of exact vblank timestamps from given drm_display_mode
  * timings and current video scanout position of a CRTC. This can be directly
- * used as the &drm_driver.get_vblank_timestamp implementation of a kms driver
- * if &drm_crtc_helper_funcs.get_scanout_position is implemented.
+ * used as the &drm_crtc_funcs.get_vblank_timestamp implementation of a kms
+ * driver if &drm_crtc_helper_funcs.get_scanout_position is implemented.
  *
  * The current implementation only handles standard video modes. For double scan
  * and interlaced modes the driver is supposed to adjust the hardware mode
@@ -733,15 +779,22 @@ static bool
 drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe,
 			  ktime_t *tvblank, bool in_vblank_irq)
 {
+	struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
 	bool ret = false;
 
 	/* Define requested maximum error on timestamps (nanoseconds). */
 	int max_error = (int) drm_timestamp_precision * 1000;
 
 	/* Query driver if possible and precision timestamping enabled. */
-	if (dev->driver->get_vblank_timestamp && (max_error > 0))
+	if (crtc->funcs->get_vblank_timestamp && (max_error > 0)) {
+		struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
+
+		ret = crtc->funcs->get_vblank_timestamp(crtc, &max_error,
+							tvblank, in_vblank_irq);
+	} else if (dev->driver->get_vblank_timestamp && (max_error > 0)) {
 		ret = dev->driver->get_vblank_timestamp(dev, pipe, &max_error,
 							tvblank, in_vblank_irq);
+	}
 
 	/* GPU high precision timestamp query unsupported or failed.
 	 * Return current monotonic/gettimeofday timestamp as best estimate.
@@ -1050,11 +1103,19 @@ EXPORT_SYMBOL(drm_crtc_vblank_get);
 
 static bool __vblank_disable_immediate(struct drm_device *dev, unsigned int pipe)
 {
+	struct drm_crtc *crtc;
+
 	if (!dev->vblank_disable_immediate)
 		return false;
-	if (!dev->driver->get_vblank_timestamp)
-		return false;
-	return true;
+
+	crtc = drm_crtc_from_index(dev, pipe);
+	if (crtc && crtc->funcs->get_vblank_timestamp)
+		return true;
+
+	if (dev->driver->get_vblank_timestamp)
+		return true;
+
+	return false;
 }
 
 static void drm_vblank_put(struct drm_device *dev, unsigned int pipe)
@@ -1733,9 +1794,11 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data,
 
 static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe)
 {
+	struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
 	struct drm_pending_vblank_event *e, *t;
 	ktime_t now;
 	u64 seq;
+	bool high_prec;
 
 	assert_spin_locked(&dev->event_lock);
 
@@ -1755,8 +1818,10 @@ static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe)
 		send_vblank_event(dev, e, seq, now);
 	}
 
-	trace_drm_vblank_event(pipe, seq, now,
-			dev->driver->get_vblank_timestamp != NULL);
+	high_prec = crtc->funcs->get_vblank_timestamp ||
+		    dev->driver->get_vblank_timestamp;
+
+	trace_drm_vblank_event(pipe, seq, now, high_prec);
 }
 
 /**
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 5e9b15a0e8c5..2caad975f415 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -867,6 +867,47 @@ struct drm_crtc_funcs {
 	 * new drivers as the replacement of &drm_driver.disable_vblank hook.
 	 */
 	void (*disable_vblank)(struct drm_crtc *crtc);
+
+	/**
+	 * @get_vblank_timestamp:
+	 *
+	 * Called by drm_get_last_vbltimestamp(). Should return a precise
+	 * timestamp when the most recent vblank interval ended or will end.
+	 *
+	 * Specifically, the timestamp in @vblank_time should correspond as
+	 * closely as possible to the time when the first video scanline of
+	 * the video frame after the end of vblank will start scanning out,
+	 * the time immediately after end of the vblank interval. If the
+	 * @crtc is currently inside vblank, this will be a time in the future.
+	 * If the @crtc is currently scanning out a frame, this will be the
+	 * past start time of the current scanout. This is meant to adhere
+	 * to the OpenML OML_sync_control extension specification.
+	 *
+	 * Parameters:
+	 *
+	 * crtc:
+	 *     CRTC for which timestamp should be returned.
+	 * max_error:
+	 *     Maximum allowable timestamp error in nanoseconds.
+	 *     Implementation should strive to provide timestamp
+	 *     with an error of at most max_error nanoseconds.
+	 *     Returns true upper bound on error for timestamp.
+	 * vblank_time:
+	 *     Target location for returned vblank timestamp.
+	 * in_vblank_irq:
+	 *     True when called from drm_crtc_handle_vblank().  Some drivers
+	 *     need to apply some workarounds for gpu-specific vblank irq quirks
+	 *     if flag is set.
+	 *
+	 * Returns:
+	 *
+	 * True on success, false on failure, which means the core should
+	 * fallback to a simple timestamp taken in drm_crtc_handle_vblank().
+	 */
+	bool (*get_vblank_timestamp)(struct drm_crtc *crtc,
+				     int *max_error,
+				     ktime_t *vblank_time,
+				     bool in_vblank_irq);
 };
 
 /**
diff --git a/include/drm/drm_modeset_helper_vtables.h b/include/drm/drm_modeset_helper_vtables.h
index e398512bfd5f..d735f7088a10 100644
--- a/include/drm/drm_modeset_helper_vtables.h
+++ b/include/drm/drm_modeset_helper_vtables.h
@@ -460,7 +460,7 @@ struct drm_crtc_helper_funcs {
 	 * optional accurate ktime_get() timestamp of when the position was
 	 * measured. Note that this is a helper callback which is only used
 	 * if a driver uses drm_calc_vbltimestamp_from_scanoutpos() for the
-	 * @drm_driver.get_vblank_timestamp callback.
+	 * @drm_crtc_funcs.get_vblank_timestamp callback.
 	 *
 	 * Parameters:
 	 *
diff --git a/include/drm/drm_vblank.h b/include/drm/drm_vblank.h
index c16c44052b3d..cdc567c83805 100644
--- a/include/drm/drm_vblank.h
+++ b/include/drm/drm_vblank.h
@@ -233,6 +233,10 @@ bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
 					   unsigned int pipe, int *max_error,
 					   ktime_t *vblank_time,
 					   bool in_vblank_irq);
+bool drm_crtc_calc_vbltimestamp_from_scanoutpos(struct drm_crtc *crtc,
+						int *max_error,
+						ktime_t *vblank_time,
+						bool in_vblank_irq);
 void drm_calc_timestamping_constants(struct drm_crtc *crtc,
 				     const struct drm_display_mode *mode);
 wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc);
-- 
2.24.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2020-01-10  9:21 UTC|newest]

Thread overview: 217+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-10  9:21 [PATCH 00/23] drm: Clean up VBLANK callbacks in struct drm_driver Thomas Zimmermann
2020-01-10  9:21 ` Thomas Zimmermann
2020-01-10  9:21 ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21 ` Thomas Zimmermann
2020-01-10  9:21 ` Thomas Zimmermann
2020-01-10  9:21 ` [PATCH 01/23] drm: Add get_scanout_position() to struct drm_crtc_helper_funcs Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10 10:24   ` Jani Nikula
2020-01-10 10:24     ` Jani Nikula
2020-01-10 10:24     ` [Intel-gfx] " Jani Nikula
2020-01-10 10:24     ` Jani Nikula
2020-01-10 10:24     ` Jani Nikula
2020-01-14 15:31   ` Yannick FERTRE
2020-01-14 15:31     ` Yannick FERTRE
2020-01-14 15:31     ` [Intel-gfx] " Yannick FERTRE
2020-01-14 15:31     ` Yannick FERTRE
2020-01-15  7:31     ` Thomas Zimmermann
2020-01-15  7:31       ` Thomas Zimmermann
2020-01-15  7:31       ` [Intel-gfx] " Thomas Zimmermann
2020-01-15  7:31       ` Thomas Zimmermann
2020-01-15  7:31       ` Thomas Zimmermann
2020-01-10  9:21 ` [PATCH 02/23] drm/amdgpu: Convert to struct drm_crtc_helper_funcs.get_scanout_position() Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-13 18:52   ` Alex Deucher
2020-01-13 18:52     ` Alex Deucher
2020-01-13 18:52     ` [Intel-gfx] " Alex Deucher
2020-01-13 18:52     ` Alex Deucher
2020-01-13 18:52     ` Alex Deucher
2020-01-14  7:46     ` Thomas Zimmermann
2020-01-14  7:46       ` Thomas Zimmermann
2020-01-14  7:46       ` [Intel-gfx] " Thomas Zimmermann
2020-01-14  7:46       ` Thomas Zimmermann
2020-01-14  7:46       ` Thomas Zimmermann
2020-01-15  9:41     ` Thomas Zimmermann
2020-01-15  9:41       ` Thomas Zimmermann
2020-01-15  9:41       ` [Intel-gfx] " Thomas Zimmermann
2020-01-15  9:41       ` Thomas Zimmermann
2020-01-15  9:41       ` Thomas Zimmermann
2020-01-15 16:35       ` Alex Deucher
2020-01-15 16:35         ` Alex Deucher
2020-01-15 16:35         ` [Intel-gfx] " Alex Deucher
2020-01-15 16:35         ` Alex Deucher
2020-01-15 16:35         ` Alex Deucher
2020-01-10  9:21 ` [PATCH 03/23] drm/i915: Don't use struct drm_driver.get_scanout_position() Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10 11:59   ` Jani Nikula
2020-01-10 11:59     ` Jani Nikula
2020-01-10 11:59     ` [Intel-gfx] " Jani Nikula
2020-01-10 11:59     ` Jani Nikula
2020-01-10 11:59     ` Jani Nikula
2020-01-10 12:04     ` Thomas Zimmermann
2020-01-10 12:04       ` Thomas Zimmermann
2020-01-10 12:04       ` [Intel-gfx] " Thomas Zimmermann
2020-01-10 12:04       ` Thomas Zimmermann
2020-01-10 12:04       ` Thomas Zimmermann
2020-01-10 13:56       ` Jani Nikula
2020-01-10 13:56         ` Jani Nikula
2020-01-10 13:56         ` [Intel-gfx] " Jani Nikula
2020-01-10 13:56         ` Jani Nikula
2020-01-10 13:56         ` Jani Nikula
2020-01-10 15:25         ` Ville Syrjälä
2020-01-10 15:25           ` Ville Syrjälä
2020-01-10 15:25           ` [Intel-gfx] " Ville Syrjälä
2020-01-10 15:25           ` Ville Syrjälä
2020-01-10 15:25           ` Ville Syrjälä
2020-01-10  9:21 ` [PATCH 04/23] drm/nouveau: Convert to struct drm_crtc_helper_funcs.get_scanout_position() Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21 ` [PATCH 05/23] drm/radeon: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-13 18:53   ` Alex Deucher
2020-01-13 18:53     ` Alex Deucher
2020-01-13 18:53     ` [Intel-gfx] " Alex Deucher
2020-01-13 18:53     ` Alex Deucher
2020-01-13 18:53     ` Alex Deucher
2020-01-10  9:21 ` [PATCH 06/23] drm/msm: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21 ` [PATCH 07/23] drm/vc4: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21 ` [PATCH 08/23] drm/stm: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-14 15:31   ` Yannick FERTRE
2020-01-14 15:31     ` Yannick FERTRE
2020-01-14 15:31     ` [Intel-gfx] " Yannick FERTRE
2020-01-14 15:31     ` Yannick FERTRE
2020-01-10  9:21 ` [PATCH 09/23] drm: Remove struct drm_driver.get_scanout_position() Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-14 15:32   ` Yannick FERTRE
2020-01-14 15:32     ` Yannick FERTRE
2020-01-14 15:32     ` [Intel-gfx] " Yannick FERTRE
2020-01-14 15:32     ` Yannick FERTRE
2020-01-10  9:21 ` [PATCH 10/23] drm: Evaluate struct drm_device.vblank_disable_immediate on each use Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21 ` Thomas Zimmermann [this message]
2020-01-10  9:21   ` [PATCH 11/23] drm: Add get_vblank_timestamp() to struct drm_crtc_funcs Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21 ` [PATCH 12/23] drm/amdgpu: Convert to CRTC VBLANK callbacks Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-13 19:00   ` Alex Deucher
2020-01-13 19:00     ` Alex Deucher
2020-01-13 19:00     ` [Intel-gfx] " Alex Deucher
2020-01-13 19:00     ` Alex Deucher
2020-01-13 19:00     ` Alex Deucher
2020-01-10  9:21 ` [PATCH 13/23] drm/gma500: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21 ` [PATCH 14/23] drm/i915: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21 ` [PATCH 15/23] drm/msm: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21 ` [PATCH 16/23] drm/nouveau: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21 ` [PATCH 17/23] drm/radeon: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-13 19:02   ` Alex Deucher
2020-01-13 19:02     ` Alex Deucher
2020-01-13 19:02     ` [Intel-gfx] " Alex Deucher
2020-01-13 19:02     ` Alex Deucher
2020-01-13 19:02     ` Alex Deucher
2020-01-10  9:21 ` [PATCH 18/23] drm/sti: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10 13:38   ` Benjamin Gaignard
2020-01-10 13:38     ` Benjamin Gaignard
2020-01-10 13:38     ` [Intel-gfx] " Benjamin Gaignard
2020-01-10 13:38     ` Benjamin Gaignard
2020-01-10 13:38     ` Benjamin Gaignard
2020-01-10  9:21 ` [PATCH 19/23] drm/stm: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-14 15:32   ` Yannick FERTRE
2020-01-14 15:32     ` Yannick FERTRE
2020-01-14 15:32     ` [Intel-gfx] " Yannick FERTRE
2020-01-14 15:32     ` Yannick FERTRE
2020-01-10  9:21 ` [PATCH 20/23] drm/vc4: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21 ` [PATCH 21/23] drm/vkms: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21 ` [PATCH 22/23] drm/vmwgfx: " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21 ` [PATCH 23/23] drm: Cleanup VBLANK callbacks in struct drm_driver Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-10  9:21   ` [Intel-gfx] " Thomas Zimmermann
2020-01-10  9:21   ` Thomas Zimmermann
2020-01-12 22:53   ` Daniel Vetter
2020-01-12 22:53     ` Daniel Vetter
2020-01-12 22:53     ` [Intel-gfx] " Daniel Vetter
2020-01-12 22:53     ` Daniel Vetter
2020-01-12 22:53     ` Daniel Vetter
2020-01-12 22:54     ` Daniel Vetter
2020-01-12 22:54       ` Daniel Vetter
2020-01-12 22:54       ` [Intel-gfx] " Daniel Vetter
2020-01-12 22:54       ` Daniel Vetter
2020-01-12 22:54       ` Daniel Vetter
2020-01-14 13:48     ` Thomas Zimmermann
2020-01-14 13:48       ` Thomas Zimmermann
2020-01-14 13:48       ` [Intel-gfx] " Thomas Zimmermann
2020-01-14 13:48       ` Thomas Zimmermann
2020-01-14 15:32   ` Yannick FERTRE
2020-01-14 15:32     ` Yannick FERTRE
2020-01-14 15:32     ` [Intel-gfx] " Yannick FERTRE
2020-01-14 15:32     ` Yannick FERTRE
2020-01-10  9:40 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm: Clean up " Patchwork
2020-01-10  9:49 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2020-01-10 10:09 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-01-13 12:57 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork
2020-01-14 18:09 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for drm: Clean up VBLANK callbacks in struct drm_driver (rev6) Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200110092127.27847-12-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=David1.Zhou@amd.com \
    --cc=airlied@linux.ie \
    --cc=alexander.deucher@amd.com \
    --cc=alexandre.torgue@st.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=benjamin.gaignard@linaro.org \
    --cc=bskeggs@redhat.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=eric@anholt.net \
    --cc=freedreno@lists.freedesktop.org \
    --cc=hamohammed.sa@gmail.com \
    --cc=harry.wentland@amd.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-graphics-maintainer@vmware.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=nouveau@lists.freedesktop.org \
    --cc=patrik.r.jakobsson@gmail.com \
    --cc=philippe.cornu@st.com \
    --cc=robdclark@gmail.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=rodrigosiqueiramelo@gmail.com \
    --cc=sean@poorly.run \
    --cc=sunpeng.li@amd.com \
    --cc=thellstrom@vmware.com \
    --cc=vincent.abriou@st.com \
    --cc=yannick.fertre@st.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.