[RFC PATCH v2 1/5] drm: add vblank hooks to struct drm_crtc_funcs

Daniel Vetter daniel at ffwll.ch
Tue Jan 24 07:54:08 UTC 2017


On Sun, Jan 22, 2017 at 02:09:02PM +0800, Shawn Guo wrote:
> From: Shawn Guo <shawn.guo at linaro.org>
> 
> The vblank is mostly CRTC specific and implemented as part of CRTC
> driver.  Let's keep the vblank hooks struct drm_driver for legacy
> drivers, and add corresponding hooks in struct drm_crtc_funcs.  These
> hooks take struct drm_crtc pointer as argument, and will be called by
> core vblank handling code for MODESET drivers.
> 
> Signed-off-by: Shawn Guo <shawn.guo at linaro.org>

Looks great. Just a few tiny nits below.

Cheers, Daniel

> ---
>  drivers/gpu/drm/drm_irq.c | 53 +++++++++++++++++++++++++++++++++++++++++------
>  include/drm/drm_crtc.h    | 34 ++++++++++++++++++++++++++++++
>  include/drm/drm_drv.h     |  9 ++++++++
>  3 files changed, 90 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
> index 88c69e71102e..604a2acda9d6 100644
> --- a/drivers/gpu/drm/drm_irq.c
> +++ b/drivers/gpu/drm/drm_irq.c
> @@ -89,6 +89,19 @@ static void store_vblank(struct drm_device *dev, unsigned int pipe,
>  	write_sequnlock(&vblank->seqlock);
>  }
>  
> +static u32 __get_vblank_counter(struct drm_device *dev, unsigned int pipe)
> +{
> +	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
> +		struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
> +
> +		if (crtc->funcs->get_vblank_counter)
> +			return crtc->funcs->get_vblank_counter(crtc);
> +	}
> +
> +	/* fallback for legacy drivers */

Bikeshed: I'd drop these comments, it's kinda obvious what's going on.

> +	return dev->driver->get_vblank_counter(dev, pipe);

I think a great follow-up here would be to do

	if (dev->driver->get_vblank_counter)
		return dev->driver->get_vblank_counter(dev, pipe);
	
	return drm_vblank_no_hw_counter(dev,pipe);

here (i.e. making get_vblank_counter optional), and then removing
drm_vblank_no_hw_counter from all drivers. We might even want to unexport
it, and adjust the help-text to state that hw without a vblank counter
should leave this hook as NULL.

> +}
> +
>  /*
>   * Reset the stored timestamp for the current vblank count to correspond
>   * to the last vblank occurred.
> @@ -112,9 +125,9 @@ static void drm_reset_vblank_timestamp(struct drm_device *dev, unsigned int pipe
>  	 * when drm_vblank_enable() applies the diff
>  	 */
>  	do {
> -		cur_vblank = dev->driver->get_vblank_counter(dev, pipe);
> +		cur_vblank = __get_vblank_counter(dev, pipe);
>  		rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, 0);
> -	} while (cur_vblank != dev->driver->get_vblank_counter(dev, pipe) && --count > 0);
> +	} while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0);
>  
>  	/*
>  	 * Only reinitialize corresponding vblank timestamp if high-precision query
> @@ -168,9 +181,9 @@ static void drm_update_vblank_count(struct drm_device *dev, unsigned int pipe,
>  	 * corresponding vblank timestamp.
>  	 */
>  	do {
> -		cur_vblank = dev->driver->get_vblank_counter(dev, pipe);
> +		cur_vblank = __get_vblank_counter(dev, pipe);
>  		rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, flags);
> -	} while (cur_vblank != dev->driver->get_vblank_counter(dev, pipe) && --count > 0);
> +	} while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0);
>  
>  	if (dev->max_vblank_count != 0) {
>  		/* trust the hw counter when it's around */
> @@ -275,6 +288,21 @@ u32 drm_accurate_vblank_count(struct drm_crtc *crtc)
>  }
>  EXPORT_SYMBOL(drm_accurate_vblank_count);
>  
> +static void __disable_vblank(struct drm_device *dev, unsigned int pipe)
> +{
> +	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
> +		struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
> +
> +		if (crtc->funcs->disable_vblank) {
> +			crtc->funcs->disable_vblank(crtc);
> +			return;
> +		}
> +	}
> +
> +	/* fallback for legacy drivers */
> +	dev->driver->disable_vblank(dev, pipe);
> +}
> +
>  /*
>   * Disable vblank irq's on crtc, make sure that last vblank count
>   * of hardware and corresponding consistent software vblank counter
> @@ -298,7 +326,7 @@ static void vblank_disable_and_save(struct drm_device *dev, unsigned int pipe)
>  	 * hardware potentially runtime suspended.
>  	 */
>  	if (vblank->enabled) {
> -		dev->driver->disable_vblank(dev, pipe);
> +		__disable_vblank(dev, pipe);
>  		vblank->enabled = false;
>  	}
>  
> @@ -1054,6 +1082,19 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
>  }
>  EXPORT_SYMBOL(drm_crtc_send_vblank_event);
>  
> +static int __enable_vblank(struct drm_device *dev, unsigned int pipe)
> +{
> +	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
> +		struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
> +
> +		if (crtc->funcs->enable_vblank)
> +			return crtc->funcs->enable_vblank(crtc);
> +	}
> +
> +	/* fallback for legacy drivers */
> +	return dev->driver->enable_vblank(dev, pipe);
> +}
> +
>  /**
>   * drm_vblank_enable - enable the vblank interrupt on a CRTC
>   * @dev: DRM device
> @@ -1079,7 +1120,7 @@ static int drm_vblank_enable(struct drm_device *dev, unsigned int pipe)
>  		 * timestamps. Filtercode in drm_handle_vblank() will
>  		 * prevent double-accounting of same vblank interval.
>  		 */
> -		ret = dev->driver->enable_vblank(dev, pipe);
> +		ret = __enable_vblank(dev, pipe);
>  		DRM_DEBUG("enabling vblank on crtc %u, ret: %d\n", pipe, ret);
>  		if (ret)
>  			atomic_dec(&vblank->refcount);
> diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
> index 06c943d1e04c..8b2f7266eada 100644
> --- a/include/drm/drm_crtc.h
> +++ b/include/drm/drm_crtc.h
> @@ -600,6 +600,40 @@ struct drm_crtc_funcs {
>  	 */
>  	void (*atomic_print_state)(struct drm_printer *p,
>  				   const struct drm_crtc_state *state);
> +
> +	/**
> +	 * @get_vblank_counter:
> +	 *
> +	 * Driver callback for fetching a raw hardware vblank counter for the
> +	 * CRTC. It's meant to be used by new drivers as the replacement of
> +	 * &drm_driver.get_vblank_counter hook.


Compared to the kerneldoc in drm_drv.h it misses the paragraph about
wrap-around handling. Also this is missing the note about what to do if
you don't have a vblank counter, but I think making the hook optional like
I suggested above would be even better. If you do decided to make the hook
optional, then please state that in the kernel-doc here too.

> +	 *
> +	 * Returns:
> +	 *
> +	 * Raw vblank counter value.
> +	 */
> +	u32 (*get_vblank_counter)(struct drm_crtc *crtc);
> +
> +	/**
> +	 * @enable_vblank:
> +	 *
> +	 * Enable vblank interrupts for the CRTC. It's meant to be used by
> +	 * new drivers as the replacement of &drm_driver.enable_vblank hook.
> +	 *
> +	 * Returns:
> +	 *
> +	 * Zero on success, appropriate errno if the vblank interrupt cannot
> +	 * be enabled.
> +	 */
> +	int (*enable_vblank)(struct drm_crtc *crtc);
> +
> +	/**
> +	 * @disable_vblank:
> +	 *
> +	 * Disable vblank interrupts for the CRTC. It's meant to be used by
> +	 * new drivers as the replacement of &drm_driver.disable_vblank hook.
> +	 */
> +	void (*disable_vblank)(struct drm_crtc *crtc);
>  };
>  
>  /**
> diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
> index 34ece393c639..6c325baddc40 100644
> --- a/include/drm/drm_drv.h
> +++ b/include/drm/drm_drv.h
> @@ -123,6 +123,9 @@ struct drm_driver {
>  	 * drm_crtc_vblank_off() and drm_crtc_vblank_on() when disabling or
>  	 * enabling a CRTC.
>  	 *
> +	 * This is deprecated and should not be used by new drivers.
> +	 * Use &drm_crtc_funcs.get_vblank_counter instead.
> +	 *
>  	 * Returns:
>  	 *
>  	 * Raw vblank counter value.
> @@ -135,6 +138,9 @@ struct drm_driver {
>  	 * Enable vblank interrupts for the CRTC specified with the pipe
>  	 * argument.
>  	 *
> +	 * This is deprecated and should not be used by new drivers.
> +	 * Use &drm_crtc_funcs.enable_vblank instead.
> +	 *
>  	 * Returns:
>  	 *
>  	 * Zero on success, appropriate errno if the given @crtc's vblank
> @@ -147,6 +153,9 @@ struct drm_driver {
>  	 *
>  	 * Disable vblank interrupts for the CRTC specified with the pipe
>  	 * argument.
> +	 *
> +	 * This is deprecated and should not be used by new drivers.
> +	 * Use &drm_crtc_funcs.disable_vblank instead.
>  	 */
>  	void (*disable_vblank) (struct drm_device *dev, unsigned int pipe);
>  
> -- 
> 1.9.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the dri-devel mailing list