public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: ville.syrjala@linux.intel.com
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 02/25] drm/i915: Add vblank notify mechanism
Date: Wed, 18 Jun 2014 21:53:48 +0200	[thread overview]
Message-ID: <20140618195348.GR5821@phenom.ffwll.local> (raw)
In-Reply-To: <1403114338-30513-3-git-send-email-ville.syrjala@linux.intel.com>

On Wed, Jun 18, 2014 at 08:58:35PM +0300, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> Add a vblank notify mechanism where you can ask for a callback when a
> specific frame counter value has been passed.
> 
> This could be used for various things like FBC, IPS, watermarks,
> and updating single buffered display registers from the interrupt
> handler (eg. gamma).
> 
> As gen2 doesn't have a hardware frame counter we use the software vblank
> counter drm core procvides. This is rather racy, but for something like
> FBC it doesn't matter too much. For gen2 we could just scheudle the FBC
> enable happen a frame later than on other gens. That should paper over
> the races sufficiently.
> 
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

Chris submitted a very similar patch for vblank work items, same review
still applies: This should be moved into drm_irq.c
-Daniel

> ---
>  drivers/gpu/drm/i915/i915_irq.c      |   8 +++
>  drivers/gpu/drm/i915/intel_display.c | 132 +++++++++++++++++++++++++++++++++++
>  drivers/gpu/drm/i915/intel_drv.h     |  16 +++++
>  3 files changed, 156 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
> index 218f011..a908a55 100644
> --- a/drivers/gpu/drm/i915/i915_irq.c
> +++ b/drivers/gpu/drm/i915/i915_irq.c
> @@ -1736,7 +1736,15 @@ static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
>  	if (!drm_handle_vblank(dev, pipe))
>  		return false;
>  
> +	if (!drm_core_check_feature(dev, DRIVER_MODESET))
> +		return true;
> +
>  	crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
> +
> +	spin_lock(&crtc->lock);
> +	intel_vblank_notify_check(crtc);
> +	spin_unlock(&crtc->lock);
> +
>  	wake_up(&crtc->vbl_wait);
>  
>  	return true;
> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index 5e8e711..be3ee69 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -11499,6 +11499,9 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
>  
>  	init_waitqueue_head(&intel_crtc->vbl_wait);
>  
> +	spin_lock_init(&intel_crtc->lock);
> +	INIT_LIST_HEAD(&intel_crtc->vblank_notify_list);
> +
>  	BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
>  	       dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
>  	dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
> @@ -13051,3 +13054,132 @@ intel_display_print_error_state(struct drm_i915_error_state_buf *m,
>  		err_printf(m, "  VSYNC: %08x\n", error->transcoder[i].vsync);
>  	}
>  }
> +
> +/* is a after b? */
> +static bool vbl_count_after_eq(struct drm_device *dev, u32 a, u32 b)
> +{
> +	u32 mask = dev->max_vblank_count;
> +
> +	/* now hardware counter on gen2 */
> +	if (mask == 0)
> +		mask = -1;
> +
> +	mask &= (mask >> 1);
> +
> +	return !((a - b) & mask);
> +}
> +
> +static void intel_vblank_notify_complete(struct intel_vblank_notify *notify)
> +{
> +	struct intel_crtc *crtc = notify->crtc;
> +	struct drm_device *dev = crtc->base.dev;
> +
> +	assert_spin_locked(&crtc->lock);
> +
> +	drm_vblank_put(dev, crtc->pipe);
> +	list_del(&notify->list);
> +	notify->crtc = NULL;
> +}
> +
> +void intel_vblank_notify_check(struct intel_crtc *crtc)
> +{
> +	struct drm_device *dev = crtc->base.dev;
> +	struct drm_vblank_crtc *vblank =
> +		&dev->vblank[drm_crtc_index(&crtc->base)];
> +	struct intel_vblank_notify *notify, *next;
> +	u32 vbl_count;
> +
> +	assert_spin_locked(&crtc->lock);
> +
> +	if (list_empty(&crtc->vblank_notify_list))
> +		return;
> +
> +	/* no hardware frame counter on gen2 */
> +	if (dev->max_vblank_count == 0)
> +		vbl_count = atomic_read(&vblank->count);
> +	else
> +		vbl_count = dev->driver->get_vblank_counter(dev, crtc->pipe);
> +
> +	list_for_each_entry_safe(notify, next, &crtc->vblank_notify_list, list) {
> +		if (!vbl_count_after_eq(dev, vbl_count, notify->vbl_count))
> +			continue;
> +
> +		intel_vblank_notify_complete(notify);
> +		notify->notify(notify);
> +	}
> +}
> +
> +int intel_vblank_notify_add(struct intel_crtc *crtc,
> +			    struct intel_vblank_notify *notify)
> +{
> +	struct drm_device *dev = crtc->base.dev;
> +	unsigned long irqflags;
> +	u32 vbl_count;
> +	int ret;
> +
> +	if (WARN_ON(notify->crtc))
> +		return -EINVAL;
> +
> +	ret = drm_vblank_get(dev, crtc->pipe);
> +	if (ret)
> +		return ret;
> +
> +	spin_lock_irqsave(&crtc->lock, irqflags);
> +
> +	notify->crtc = crtc;
> +	list_add(&notify->list, &crtc->vblank_notify_list);
> +
> +	/* no hardware frame counter on gen2 */
> +	if (dev->max_vblank_count == 0) {
> +		struct drm_vblank_crtc *vblank =
> +			&dev->vblank[drm_crtc_index(&crtc->base)];
> +
> +		vbl_count = atomic_read(&vblank->count);
> +	} else {
> +		vbl_count = dev->driver->get_vblank_counter(dev, crtc->pipe);
> +	}
> +
> +	if (vbl_count_after_eq(dev, vbl_count, notify->vbl_count)) {
> +		intel_vblank_notify_complete(notify);
> +		notify->notify(notify);
> +	}
> +
> +	spin_unlock_irqrestore(&crtc->lock, irqflags);
> +
> +	return 0;
> +}
> +
> +bool intel_vblank_notify_pending(struct intel_vblank_notify *notify)
> +{
> +	return notify->crtc != NULL;
> +}
> +
> +void intel_vblank_notify_cancel(struct intel_vblank_notify *notify)
> +{
> +	struct intel_crtc *crtc = ACCESS_ONCE(notify->crtc);
> +	unsigned long irqflags;
> +
> +	if (!crtc)
> +		return;
> +
> +	spin_lock_irqsave(&crtc->lock, irqflags);
> +	if (notify->crtc)
> +		intel_vblank_notify_complete(notify);
> +	spin_unlock_irqrestore(&crtc->lock, irqflags);
> +}
> +
> +u32 intel_crtc_vbl_count_rel_to_abs(struct intel_crtc *crtc, u32 rel)
> +{
> +	struct drm_device *dev = crtc->base.dev;
> +
> +	/* now hardware counter on gen2 */
> +	if (dev->max_vblank_count == 0) {
> +		struct drm_vblank_crtc *vblank =
> +			&dev->vblank[drm_crtc_index(&crtc->base)];
> +
> +		return atomic_read(&vblank->count) + rel;
> +	}
> +
> +	return (dev->driver->get_vblank_counter(dev, crtc->pipe) + rel) &
> +		dev->max_vblank_count;
> +}
> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> index ab5962b..c93626b 100644
> --- a/drivers/gpu/drm/i915/intel_drv.h
> +++ b/drivers/gpu/drm/i915/intel_drv.h
> @@ -358,6 +358,13 @@ struct intel_pipe_wm {
>  	bool sprites_scaled;
>  };
>  
> +struct intel_vblank_notify {
> +	void (*notify)(struct intel_vblank_notify *notify);
> +	struct intel_crtc *crtc;
> +	struct list_head list;
> +	u32 vbl_count;
> +};
> +
>  struct intel_mmio_flip {
>  	u32 seqno;
>  	u32 ring_id;
> @@ -417,6 +424,9 @@ struct intel_crtc {
>  
>  	int scanline_offset;
>  	struct intel_mmio_flip mmio_flip;
> +
> +	struct list_head vblank_notify_list;
> +	spinlock_t lock;
>  };
>  
>  struct intel_plane_wm_parameters {
> @@ -811,6 +821,12 @@ void intel_mode_from_pipe_config(struct drm_display_mode *mode,
>  				 struct intel_crtc_config *pipe_config);
>  int intel_format_to_fourcc(int format);
>  void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc);
> +int intel_vblank_notify_add(struct intel_crtc *crtc,
> +			    struct intel_vblank_notify *notify);
> +void intel_vblank_notify_cancel(struct intel_vblank_notify *notify);
> +bool intel_vblank_notify_pending(struct intel_vblank_notify *notify);
> +void intel_vblank_notify_check(struct intel_crtc *crtc);
> +u32 intel_crtc_vbl_count_rel_to_abs(struct intel_crtc *crtc, u32 rel);
>  
>  
>  /* intel_dp.c */
> -- 
> 1.8.5.5
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

  reply	other threads:[~2014-06-18 19:53 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-18 17:58 [PATCH 00/25] Fix FBC for real ville.syrjala
2014-06-18 17:58 ` [PATCH 01/25] drm/i915: Add ring_notify mechanism ville.syrjala
2014-06-18 20:06   ` Daniel Vetter
2014-06-18 17:58 ` [PATCH 02/25] drm/i915: Add vblank notify mechanism ville.syrjala
2014-06-18 19:53   ` Daniel Vetter [this message]
2014-06-18 17:58 ` [PATCH 03/25] drm/i915: Name the IPS bits ville.syrjala
2014-06-18 17:58 ` [PATCH 04/25] drm/i915: Use vblank notifier for IPS ville.syrjala
2014-06-18 17:58 ` [PATCH 05/25] drm/i915: Reogranize page flip code for fbc ville.syrjala
2014-06-18 17:58 ` [PATCH 06/25] drm/i915: Move ilk_pipe_pixel_rate() earlier to avoid forward declaration ville.syrjala
2014-06-18 17:58 ` [PATCH 07/25] drm/i915: Reorganize intel_update_fbc() ville.syrjala
2014-06-18 17:58 ` [PATCH 08/25] drm/i915: Check panel fitting state before enabling fbc ville.syrjala
2014-06-18 17:58 ` [PATCH 09/25] drm/i915: Reject fbc on g4x when sprites are enabled ville.syrjala
2014-06-18 17:58 ` [PATCH 10/25] drm/i915: Check pixel format for fbc ville.syrjala
2014-06-18 17:58 ` [PATCH 11/25] drm/i915: Remove dblscan flag from fbc1 check ville.syrjala
2014-06-18 17:58 ` [PATCH 12/25] drm/i915: Don't claim fbc as possible if the obj size exceeds stolen size ville.syrjala
2014-06-18 17:58 ` [PATCH 13/25] drm/i915: Use low level funciton to disable fbc at init/resume ville.syrjala
2014-06-18 17:58 ` [PATCH 14/25] drm/i915: Move fbc function prototypes got intel_drv.h ville.syrjala
2014-06-18 17:58 ` [PATCH 15/25] drm/i915: Move fbc state into dev_priv.fbc ville.syrjala
2014-06-18 17:58 ` [PATCH 16/25] drm/i915: Rewrite fbc ville.syrjala
2014-06-18 17:58 ` [PATCH 17/25] drm/i915: Reduce dmesg spam from FBC enable ville.syrjala
2014-06-18 17:58 ` [PATCH 18/25] drm/i915: Add i915_fbc_info debugfs file ville.syrjala
2014-06-18 17:58 ` [PATCH v6 19/25] drm/i915: Implement LRI based FBC tracking ville.syrjala
2014-06-18 17:58 ` [PATCH v3 20/25] drm/i915: Use LRI based FBC render tracking for ILK ville.syrjala
2014-06-18 17:58 ` [PATCH v2 21/25] drm/i915: Reorder i915_gem_execbuffer_move_to_gpu() and i915_switch_context() ville.syrjala
2014-06-18 17:58 ` [PATCH 22/25] drm/i915: Flush caches for scanout during cpu->gtt move ville.syrjala
2014-06-18 17:58 ` [PATCH v5 23/25] drm/i915: Nuke FBC from SW_FINISH ioctl ville.syrjala
2014-06-18 17:58 ` [PATCH 24/25] drm/i915: Pimp fbc render/blitter tracking ville.syrjala
2014-06-18 17:58 ` [PATCH 25/25] drm/i915: Enable fbc for ilk+ by default ville.syrjala
2014-06-18 20:03 ` [PATCH 00/25] Fix FBC for real Daniel Vetter
2014-06-19  7:23   ` Chris Wilson
2014-06-19  8:29   ` Ville Syrjälä

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=20140618195348.GR5821@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=ville.syrjala@linux.intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox