Commit d673c02c authored by Daniel Vetter's avatar Daniel Vetter

drm/vblank: Switch drm_driver->get_vblank_timestamp to return a bool

There's really no reason for anything more:
- Calling this while the crtc vblank stuff isn't set up is a driver
  bug. Those places alrready DRM_ERROR.
- Calling this when the crtc is off is either a driver bug (calling
  drm_crtc_handle_vblank at the wrong time) or a core bug (for
  anything else). Again, we DRM_ERROR.
- EINVAL is checked at higher levels already, and if we'd use struct
  drm_crtc * instead of (dev, pipe) it would be real obvious that
  those are again core bugs.

The only valid failure mode is crap hardware that couldn't sample a
useful timestamp, to ask the core to just grab a not-so-accurate
timestamp. Bool is perfectly fine for that.

v2: Also fix up the one caller, I lost that in the shuffling (Jani).

v3: Fixup commit message (Neil).

Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Mario Kleiner <mario.kleiner@tuebingen.mpg.de>
Cc: Eric Anholt <eric@anholt.net>
Cc: Rob Clark <robdclark@gmail.com>
Cc: linux-arm-msm@vger.kernel.org
Cc: freedreno@lists.freedesktop.org
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Reviewed-by: default avatarNeil Armstrong <narmstrong@baylibre.com>
Acked-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170509140329.24114-1-daniel.vetter@ffwll.ch
parent 315f0242
...@@ -1910,7 +1910,7 @@ int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon); ...@@ -1910,7 +1910,7 @@ int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe); u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe); int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe); void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe, bool amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
int *max_error, int *max_error,
struct timeval *vblank_time, struct timeval *vblank_time,
unsigned flags); unsigned flags);
......
...@@ -945,9 +945,9 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe) ...@@ -945,9 +945,9 @@ void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe)
* *
* Gets the timestamp on the requested crtc based on the * Gets the timestamp on the requested crtc based on the
* scanout position. (all asics). * scanout position. (all asics).
* Returns postive status flags on success, negative error on failure. * Returns true on success, false on failure.
*/ */
int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe, bool amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
int *max_error, int *max_error,
struct timeval *vblank_time, struct timeval *vblank_time,
unsigned flags) unsigned flags)
...@@ -957,7 +957,7 @@ int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe, ...@@ -957,7 +957,7 @@ int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
if (pipe >= dev->num_crtcs) { if (pipe >= dev->num_crtcs) {
DRM_ERROR("Invalid crtc %u\n", pipe); DRM_ERROR("Invalid crtc %u\n", pipe);
return -EINVAL; return false;
} }
/* Get associated drm_crtc: */ /* Get associated drm_crtc: */
...@@ -966,7 +966,7 @@ int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe, ...@@ -966,7 +966,7 @@ int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
/* This can occur on driver load if some component fails to /* This can occur on driver load if some component fails to
* initialize completely and driver is unloaded */ * initialize completely and driver is unloaded */
DRM_ERROR("Uninitialized crtc %d\n", pipe); DRM_ERROR("Uninitialized crtc %d\n", pipe);
return -EINVAL; return false;
} }
/* Helper routine in DRM core does all the work: */ /* Helper routine in DRM core does all the work: */
......
...@@ -724,21 +724,11 @@ EXPORT_SYMBOL(drm_calc_timestamping_constants); ...@@ -724,21 +724,11 @@ EXPORT_SYMBOL(drm_calc_timestamping_constants);
* active. Higher level code is expected to handle this. * active. Higher level code is expected to handle this.
* *
* Returns: * Returns:
* Negative value on error, failure or if not supported in current
* video mode:
*
* -EINVAL Invalid CRTC.
* -EAGAIN Temporary unavailable, e.g., called before initial modeset.
* -ENOTSUPP Function not supported in current display mode.
* -EIO Failed, e.g., due to failed scanout position query.
*
* Returns or'ed positive status flags on success:
*
* DRM_VBLANKTIME_SCANOUTPOS_METHOD - Signal this method used for timestamping.
* DRM_VBLANKTIME_INVBL - Timestamp taken while scanout was in vblank interval.
* *
* Returns true on success, and false on failure, i.e. when no accurate
* timestamp could be acquired.
*/ */
int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
unsigned int pipe, unsigned int pipe,
int *max_error, int *max_error,
struct timeval *vblank_time, struct timeval *vblank_time,
...@@ -748,19 +738,18 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, ...@@ -748,19 +738,18 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
struct timeval tv_etime; struct timeval tv_etime;
ktime_t stime, etime; ktime_t stime, etime;
unsigned int vbl_status; unsigned int vbl_status;
int ret = DRM_VBLANKTIME_SCANOUTPOS_METHOD;
int vpos, hpos, i; int vpos, hpos, i;
int delta_ns, duration_ns; int delta_ns, duration_ns;
if (pipe >= dev->num_crtcs) { if (pipe >= dev->num_crtcs) {
DRM_ERROR("Invalid crtc %u\n", pipe); DRM_ERROR("Invalid crtc %u\n", pipe);
return -EINVAL; return false;
} }
/* Scanout position query not supported? Should not happen. */ /* Scanout position query not supported? Should not happen. */
if (!dev->driver->get_scanout_position) { if (!dev->driver->get_scanout_position) {
DRM_ERROR("Called from driver w/o get_scanout_position()!?\n"); DRM_ERROR("Called from driver w/o get_scanout_position()!?\n");
return -EIO; return false;
} }
/* If mode timing undefined, just return as no-op: /* If mode timing undefined, just return as no-op:
...@@ -768,7 +757,7 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, ...@@ -768,7 +757,7 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
*/ */
if (mode->crtc_clock == 0) { if (mode->crtc_clock == 0) {
DRM_DEBUG("crtc %u: Noop due to uninitialized mode.\n", pipe); DRM_DEBUG("crtc %u: Noop due to uninitialized mode.\n", pipe);
return -EAGAIN; return false;
} }
/* Get current scanout position with system timestamp. /* Get current scanout position with system timestamp.
...@@ -792,7 +781,7 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, ...@@ -792,7 +781,7 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
if (!(vbl_status & DRM_SCANOUTPOS_VALID)) { if (!(vbl_status & DRM_SCANOUTPOS_VALID)) {
DRM_DEBUG("crtc %u : scanoutpos query failed [0x%x].\n", DRM_DEBUG("crtc %u : scanoutpos query failed [0x%x].\n",
pipe, vbl_status); pipe, vbl_status);
return -EIO; return false;
} }
/* Compute uncertainty in timestamp of scanout position query. */ /* Compute uncertainty in timestamp of scanout position query. */
...@@ -836,7 +825,7 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, ...@@ -836,7 +825,7 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
(long)vblank_time->tv_sec, (long)vblank_time->tv_usec, (long)vblank_time->tv_sec, (long)vblank_time->tv_usec,
duration_ns/1000, i); duration_ns/1000, i);
return ret; return true;
} }
EXPORT_SYMBOL(drm_calc_vbltimestamp_from_scanoutpos); EXPORT_SYMBOL(drm_calc_vbltimestamp_from_scanoutpos);
...@@ -872,25 +861,23 @@ static bool ...@@ -872,25 +861,23 @@ static bool
drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe, drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe,
struct timeval *tvblank, unsigned flags) struct timeval *tvblank, unsigned flags)
{ {
int ret; bool ret = false;
/* Define requested maximum error on timestamps (nanoseconds). */ /* Define requested maximum error on timestamps (nanoseconds). */
int max_error = (int) drm_timestamp_precision * 1000; int max_error = (int) drm_timestamp_precision * 1000;
/* Query driver if possible and precision timestamping enabled. */ /* Query driver if possible and precision timestamping enabled. */
if (dev->driver->get_vblank_timestamp && (max_error > 0)) { if (dev->driver->get_vblank_timestamp && (max_error > 0))
ret = dev->driver->get_vblank_timestamp(dev, pipe, &max_error, ret = dev->driver->get_vblank_timestamp(dev, pipe, &max_error,
tvblank, flags); tvblank, flags);
if (ret > 0)
return true;
}
/* GPU high precision timestamp query unsupported or failed. /* GPU high precision timestamp query unsupported or failed.
* Return current monotonic/gettimeofday timestamp as best estimate. * Return current monotonic/gettimeofday timestamp as best estimate.
*/ */
if (!ret)
*tvblank = get_drm_timestamp(); *tvblank = get_drm_timestamp();
return false; return ret;
} }
/** /**
......
...@@ -964,7 +964,7 @@ int intel_get_crtc_scanline(struct intel_crtc *crtc) ...@@ -964,7 +964,7 @@ int intel_get_crtc_scanline(struct intel_crtc *crtc)
return position; return position;
} }
static int i915_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe, static bool i915_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
int *max_error, int *max_error,
struct timeval *vblank_time, struct timeval *vblank_time,
unsigned flags) unsigned flags)
...@@ -974,19 +974,19 @@ static int i915_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe, ...@@ -974,19 +974,19 @@ static int i915_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
if (pipe >= INTEL_INFO(dev_priv)->num_pipes) { if (pipe >= INTEL_INFO(dev_priv)->num_pipes) {
DRM_ERROR("Invalid crtc %u\n", pipe); DRM_ERROR("Invalid crtc %u\n", pipe);
return -EINVAL; return false;
} }
/* Get drm_crtc to timestamp: */ /* Get drm_crtc to timestamp: */
crtc = intel_get_crtc_for_pipe(dev_priv, pipe); crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
if (crtc == NULL) { if (crtc == NULL) {
DRM_ERROR("Invalid crtc %u\n", pipe); DRM_ERROR("Invalid crtc %u\n", pipe);
return -EINVAL; return false;
} }
if (!crtc->base.hwmode.crtc_clock) { if (!crtc->base.hwmode.crtc_clock) {
DRM_DEBUG_KMS("crtc %u is disabled\n", pipe); DRM_DEBUG_KMS("crtc %u is disabled\n", pipe);
return -EBUSY; return false;
} }
/* Helper routine in DRM core does all the work: */ /* Helper routine in DRM core does all the work: */
......
...@@ -592,7 +592,7 @@ static int mdp5_get_scanoutpos(struct drm_device *dev, unsigned int pipe, ...@@ -592,7 +592,7 @@ static int mdp5_get_scanoutpos(struct drm_device *dev, unsigned int pipe,
return ret; return ret;
} }
static int mdp5_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe, static bool mdp5_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
int *max_error, int *max_error,
struct timeval *vblank_time, struct timeval *vblank_time,
unsigned flags) unsigned flags)
...@@ -602,13 +602,13 @@ static int mdp5_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe, ...@@ -602,13 +602,13 @@ static int mdp5_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
if (pipe < 0 || pipe >= priv->num_crtcs) { if (pipe < 0 || pipe >= priv->num_crtcs) {
DRM_ERROR("Invalid crtc %d\n", pipe); DRM_ERROR("Invalid crtc %d\n", pipe);
return -EINVAL; return false;
} }
crtc = priv->crtcs[pipe]; crtc = priv->crtcs[pipe];
if (!crtc) { if (!crtc) {
DRM_ERROR("Invalid crtc %d\n", pipe); DRM_ERROR("Invalid crtc %d\n", pipe);
return -EINVAL; return false;
} }
return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error, return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
......
...@@ -156,7 +156,7 @@ nouveau_display_scanoutpos(struct drm_device *dev, unsigned int pipe, ...@@ -156,7 +156,7 @@ nouveau_display_scanoutpos(struct drm_device *dev, unsigned int pipe,
return 0; return 0;
} }
int bool
nouveau_display_vblstamp(struct drm_device *dev, unsigned int pipe, nouveau_display_vblstamp(struct drm_device *dev, unsigned int pipe,
int *max_error, struct timeval *time, unsigned flags) int *max_error, struct timeval *time, unsigned flags)
{ {
...@@ -174,7 +174,7 @@ nouveau_display_vblstamp(struct drm_device *dev, unsigned int pipe, ...@@ -174,7 +174,7 @@ nouveau_display_vblstamp(struct drm_device *dev, unsigned int pipe,
} }
} }
return -EINVAL; return false;
} }
static void static void
......
...@@ -71,7 +71,7 @@ void nouveau_display_vblank_disable(struct drm_device *, unsigned int); ...@@ -71,7 +71,7 @@ void nouveau_display_vblank_disable(struct drm_device *, unsigned int);
int nouveau_display_scanoutpos(struct drm_device *, unsigned int, int nouveau_display_scanoutpos(struct drm_device *, unsigned int,
unsigned int, int *, int *, ktime_t *, unsigned int, int *, int *, ktime_t *,
ktime_t *, const struct drm_display_mode *); ktime_t *, const struct drm_display_mode *);
int nouveau_display_vblstamp(struct drm_device *, unsigned int, int *, bool nouveau_display_vblstamp(struct drm_device *, unsigned int, int *,
struct timeval *, unsigned); struct timeval *, unsigned);
int nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, int nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
......
...@@ -115,7 +115,7 @@ int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon); ...@@ -115,7 +115,7 @@ int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
u32 radeon_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe); u32 radeon_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
int radeon_enable_vblank_kms(struct drm_device *dev, unsigned int pipe); int radeon_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
void radeon_disable_vblank_kms(struct drm_device *dev, unsigned int pipe); void radeon_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
int radeon_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe, bool radeon_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
int *max_error, int *max_error,
struct timeval *vblank_time, struct timeval *vblank_time,
unsigned flags); unsigned flags);
......
...@@ -869,9 +869,9 @@ void radeon_disable_vblank_kms(struct drm_device *dev, int crtc) ...@@ -869,9 +869,9 @@ void radeon_disable_vblank_kms(struct drm_device *dev, int crtc)
* *
* Gets the timestamp on the requested crtc based on the * Gets the timestamp on the requested crtc based on the
* scanout position. (all asics). * scanout position. (all asics).
* Returns postive status flags on success, negative error on failure. * Returns true on success, false on failure.
*/ */
int radeon_get_vblank_timestamp_kms(struct drm_device *dev, int crtc, bool radeon_get_vblank_timestamp_kms(struct drm_device *dev, int crtc,
int *max_error, int *max_error,
struct timeval *vblank_time, struct timeval *vblank_time,
unsigned flags) unsigned flags)
...@@ -881,13 +881,13 @@ int radeon_get_vblank_timestamp_kms(struct drm_device *dev, int crtc, ...@@ -881,13 +881,13 @@ int radeon_get_vblank_timestamp_kms(struct drm_device *dev, int crtc,
if (crtc < 0 || crtc >= dev->num_crtcs) { if (crtc < 0 || crtc >= dev->num_crtcs) {
DRM_ERROR("Invalid crtc %d\n", crtc); DRM_ERROR("Invalid crtc %d\n", crtc);
return -EINVAL; return false;
} }
/* Get associated drm_crtc: */ /* Get associated drm_crtc: */
drmcrtc = &rdev->mode_info.crtcs[crtc]->base; drmcrtc = &rdev->mode_info.crtcs[crtc]->base;
if (!drmcrtc) if (!drmcrtc)
return -EINVAL; return false;
/* Helper routine in DRM core does all the work: */ /* 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(dev, crtc, max_error,
......
...@@ -270,7 +270,7 @@ int vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id, ...@@ -270,7 +270,7 @@ int vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id,
return ret; return ret;
} }
int vc4_crtc_get_vblank_timestamp(struct drm_device *dev, unsigned int crtc_id, bool vc4_crtc_get_vblank_timestamp(struct drm_device *dev, unsigned int crtc_id,
int *max_error, struct timeval *vblank_time, int *max_error, struct timeval *vblank_time,
unsigned flags) unsigned flags)
{ {
......
...@@ -493,7 +493,7 @@ int vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id, ...@@ -493,7 +493,7 @@ int vc4_crtc_get_scanoutpos(struct drm_device *dev, unsigned int crtc_id,
unsigned int flags, int *vpos, int *hpos, unsigned int flags, int *vpos, int *hpos,
ktime_t *stime, ktime_t *etime, ktime_t *stime, ktime_t *etime,
const struct drm_display_mode *mode); const struct drm_display_mode *mode);
int vc4_crtc_get_vblank_timestamp(struct drm_device *dev, unsigned int crtc_id, bool vc4_crtc_get_vblank_timestamp(struct drm_device *dev, unsigned int crtc_id,
int *max_error, struct timeval *vblank_time, int *max_error, struct timeval *vblank_time,
unsigned flags); unsigned flags);
......
...@@ -322,7 +322,6 @@ struct pci_controller; ...@@ -322,7 +322,6 @@ struct pci_controller;
/* Flags and return codes for get_vblank_timestamp() driver function. */ /* Flags and return codes for get_vblank_timestamp() driver function. */
#define DRM_CALLED_FROM_VBLIRQ 1 #define DRM_CALLED_FROM_VBLIRQ 1
#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
/* get_scanout_position() return flags */ /* get_scanout_position() return flags */
#define DRM_SCANOUTPOS_VALID (1 << 0) #define DRM_SCANOUTPOS_VALID (1 << 0)
......
...@@ -316,11 +316,10 @@ struct drm_driver { ...@@ -316,11 +316,10 @@ struct drm_driver {
* *
* Returns: * Returns:
* *
* Zero if timestamping isn't supported in current display mode or a * True on success, false on failure, which means the core should
* negative number on failure. A positive status code on success, * fallback to a simple timestamp taken in drm_crtc_handle_vblank().
* which describes how the vblank_time timestamp was computed.
*/ */
int (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe, bool (*get_vblank_timestamp) (struct drm_device *dev, unsigned int pipe,
int *max_error, int *max_error,
struct timeval *vblank_time, struct timeval *vblank_time,
unsigned flags); unsigned flags);
......
...@@ -153,7 +153,7 @@ void drm_crtc_vblank_on(struct drm_crtc *crtc); ...@@ -153,7 +153,7 @@ void drm_crtc_vblank_on(struct drm_crtc *crtc);
void drm_vblank_cleanup(struct drm_device *dev); void drm_vblank_cleanup(struct drm_device *dev);
u32 drm_accurate_vblank_count(struct drm_crtc *crtc); u32 drm_accurate_vblank_count(struct drm_crtc *crtc);
int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
unsigned int pipe, int *max_error, unsigned int pipe, int *max_error,
struct timeval *vblank_time, struct timeval *vblank_time,
unsigned flags, unsigned flags,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment